179 changed files with 6840 additions and 325 deletions
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.Core; |
||||
using NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public class FileConflictResolver : ServiceWithWorkbenchOwner, IFileConflictResolver |
||||
{ |
||||
IPackageManagementWorkbench workbench; |
||||
|
||||
public FileConflictResolver() |
||||
: this(new PackageManagementWorkbench()) |
||||
{ |
||||
} |
||||
|
||||
public FileConflictResolver(IPackageManagementWorkbench workbench) |
||||
{ |
||||
this.workbench = workbench; |
||||
} |
||||
|
||||
public FileConflictResolution ResolveFileConflict(string message) |
||||
{ |
||||
if (workbench.InvokeRequired) { |
||||
return workbench.SafeThreadFunction(() => ResolveFileConflict(message)); |
||||
} else { |
||||
var viewModel = new FileConflictViewModel(message); |
||||
FileConflictView view = CreateFileConflictView(viewModel); |
||||
view.ShowDialog(); |
||||
return viewModel.GetResolution(); |
||||
} |
||||
} |
||||
|
||||
FileConflictView CreateFileConflictView(FileConflictViewModel viewModel) |
||||
{ |
||||
var view = new FileConflictView(); |
||||
view.ViewModel = viewModel; |
||||
view.Owner = Owner; |
||||
return view; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,63 @@
@@ -0,0 +1,63 @@
|
||||
<Window |
||||
x:Class="ICSharpCode.PackageManagement.FileConflictView" |
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:core="http://icsharpcode.net/sharpdevelop/core" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
Title="File Conflict" |
||||
FocusManager.FocusedElement="{Binding ElementName=NoButton}" |
||||
WindowStartupLocation="CenterOwner" |
||||
Style="{x:Static core:GlobalStyles.DialogWindowStyle}" |
||||
MinHeight="150" |
||||
Height="150" |
||||
MinWidth="400" |
||||
Width="200"> |
||||
|
||||
<Window.Resources> |
||||
<Style TargetType="Button" BasedOn="{x:Static core:GlobalStyles.ButtonStyle}"/> |
||||
</Window.Resources> |
||||
|
||||
<Grid> |
||||
<Grid.ColumnDefinitions> |
||||
<ColumnDefinition Width="*"/> |
||||
<ColumnDefinition Width="Auto"/> |
||||
<ColumnDefinition Width="Auto"/> |
||||
<ColumnDefinition Width="Auto"/> |
||||
<ColumnDefinition Width="Auto"/> |
||||
</Grid.ColumnDefinitions> |
||||
<Grid.RowDefinitions> |
||||
<RowDefinition Height="*"/> |
||||
<RowDefinition Height="Auto"/> |
||||
</Grid.RowDefinitions> |
||||
<TextBlock |
||||
Margin="5" |
||||
Text="{Binding Message}" |
||||
Grid.ColumnSpan="5" |
||||
TextWrapping="Wrap"/> |
||||
<Button |
||||
Margin="4" |
||||
Grid.Row="1" |
||||
Grid.Column="1" |
||||
Command="{Binding YesCommand}" |
||||
Content="Yes"/> |
||||
<Button |
||||
Margin="4" |
||||
Grid.Row="1" |
||||
Grid.Column="2" |
||||
Command="{Binding YesToAllCommand}" |
||||
Content="Yes to All"/> |
||||
<Button |
||||
x:Name="NoButton" |
||||
Margin="4" |
||||
Grid.Row="1" |
||||
Grid.Column="3" |
||||
IsDefault="True" |
||||
Command="{Binding NoCommand}" |
||||
Content="No"/> |
||||
<Button |
||||
Margin="4" |
||||
Grid.Row="1" |
||||
Grid.Column="4" |
||||
Command="{Binding NoToAllCommand}" |
||||
Content="No to All"/> |
||||
</Grid> |
||||
</Window> |
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Windows; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public partial class FileConflictView : Window |
||||
{ |
||||
FileConflictViewModel viewModel; |
||||
|
||||
public FileConflictView() |
||||
{ |
||||
InitializeComponent(); |
||||
} |
||||
|
||||
public FileConflictViewModel ViewModel { |
||||
get { return viewModel; } |
||||
set { |
||||
viewModel = value; |
||||
viewModel.Close += CloseView; |
||||
DataContext = viewModel; |
||||
} |
||||
} |
||||
|
||||
void CloseView(object sender, EventArgs e) |
||||
{ |
||||
DialogResult = true; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,48 @@
@@ -0,0 +1,48 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Windows.Input; |
||||
using NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public class FileConflictViewModel |
||||
{ |
||||
FileConflictResolution resolution = FileConflictResolution.Ignore; |
||||
|
||||
public FileConflictViewModel(string message) |
||||
{ |
||||
this.Message = message; |
||||
CreateCommands(); |
||||
} |
||||
|
||||
void CreateCommands() |
||||
{ |
||||
YesCommand = new DelegateCommand(param => UpdateResolution(FileConflictResolution.Overwrite)); |
||||
YesToAllCommand = new DelegateCommand(param => UpdateResolution(FileConflictResolution.OverwriteAll)); |
||||
NoCommand = new DelegateCommand(param => UpdateResolution(FileConflictResolution.Ignore)); |
||||
NoToAllCommand = new DelegateCommand(param => UpdateResolution(FileConflictResolution.IgnoreAll)); |
||||
} |
||||
|
||||
void UpdateResolution(FileConflictResolution resolution) |
||||
{ |
||||
this.resolution = resolution; |
||||
Close(this, new EventArgs()); |
||||
} |
||||
|
||||
public event EventHandler Close; |
||||
|
||||
public ICommand YesCommand { get; private set; } |
||||
public ICommand YesToAllCommand { get; private set; } |
||||
public ICommand NoCommand { get; private set; } |
||||
public ICommand NoToAllCommand { get; private set; } |
||||
|
||||
public string Message { get; private set; } |
||||
|
||||
public FileConflictResolution GetResolution() |
||||
{ |
||||
return resolution; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,15 @@
@@ -0,0 +1,15 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.PackageManagement.Scripting; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public interface IPackageAction |
||||
{ |
||||
void Execute(); |
||||
bool HasPackageScriptsToRun(); |
||||
IPackageScriptRunner PackageScriptRunner { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public interface IPackageViewModelParent |
||||
{ |
||||
bool IncludePrerelease { get; } |
||||
} |
||||
} |
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public interface IUpdatePackageSettings |
||||
{ |
||||
bool UpdateDependencies { get; set; } |
||||
bool AllowPrereleaseVersions { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public interface IUpdatePackagesAction : IPackageAction, IUpdatePackageSettings |
||||
{ |
||||
IEnumerable<PackageOperation> Operations { get; } |
||||
ILogger Logger { get; set; } |
||||
|
||||
void AddPackages(IEnumerable<IPackageFromRepository> packages); |
||||
void AddOperations(IEnumerable<PackageOperation> operations); |
||||
} |
||||
} |
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public class ParentPackagesOperationEventArgs : EventArgs |
||||
{ |
||||
public ParentPackagesOperationEventArgs(IEnumerable<IPackage> packages) |
||||
{ |
||||
this.Packages = packages; |
||||
} |
||||
|
||||
public IEnumerable<IPackage> Packages { get; private set; } |
||||
} |
||||
} |
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Linq; |
||||
using Microsoft.Build.Construction; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public static class ProjectRootElementExtensions |
||||
{ |
||||
public static ProjectImportElement FindImport(this ProjectRootElement rootElement, string importedProjectFile) |
||||
{ |
||||
return rootElement |
||||
.Imports |
||||
.FirstOrDefault(import => String.Equals(import.Project, importedProjectFile, StringComparison.OrdinalIgnoreCase)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public class ReducedPackageOperations |
||||
{ |
||||
IPackageOperationResolver resolver; |
||||
IList<PackageOperation> operations; |
||||
IEnumerable<IPackage> packages; |
||||
|
||||
public ReducedPackageOperations(IPackageOperationResolver resolver, IEnumerable<IPackage> packages) |
||||
{ |
||||
this.resolver = resolver; |
||||
this.packages = packages; |
||||
this.operations = new List<PackageOperation>(); |
||||
} |
||||
|
||||
public IEnumerable<PackageOperation> Operations { |
||||
get { return operations; } |
||||
} |
||||
|
||||
public void Reduce() |
||||
{ |
||||
foreach (IPackage package in packages) { |
||||
if (!InstallOperationExists(package)) { |
||||
operations.AddRange(resolver.ResolveOperations(package)); |
||||
} |
||||
} |
||||
|
||||
operations = operations.Reduce(); |
||||
} |
||||
|
||||
bool InstallOperationExists(IPackage package) |
||||
{ |
||||
var installOperation = new PackageOperation(package, PackageAction.Install); |
||||
return operations.Any(operation => IsMatch(installOperation, operation)); |
||||
} |
||||
|
||||
bool IsMatch(PackageOperation x, PackageOperation y) |
||||
{ |
||||
return (x.Package.Id == y.Package.Id) && |
||||
(x.Package.Version == y.Package.Version) && |
||||
(x.Action == y.Action); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public class ResolveFileConflictEventArgs : EventArgs |
||||
{ |
||||
public ResolveFileConflictEventArgs(string message) |
||||
{ |
||||
this.Message = message; |
||||
this.Resolution = FileConflictResolution.Ignore; |
||||
} |
||||
|
||||
public string Message { get; private set; } |
||||
public FileConflictResolution Resolution { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public class ConsoleHostFileConflictResolver : IConsoleHostFileConflictResolver |
||||
{ |
||||
IPackageManagementEvents packageEvents; |
||||
FileConflictResolution conflictResolution; |
||||
|
||||
public ConsoleHostFileConflictResolver( |
||||
IPackageManagementEvents packageEvents, |
||||
FileConflictAction fileConflictAction) |
||||
{ |
||||
this.packageEvents = packageEvents; |
||||
|
||||
conflictResolution = GetFileConflictResolution(fileConflictAction); |
||||
packageEvents.ResolveFileConflict += ResolveFileConflict; |
||||
} |
||||
|
||||
void ResolveFileConflict(object sender, ResolveFileConflictEventArgs e) |
||||
{ |
||||
e.Resolution = conflictResolution; |
||||
} |
||||
|
||||
FileConflictResolution GetFileConflictResolution(FileConflictAction fileConflictAction) |
||||
{ |
||||
switch (fileConflictAction) { |
||||
case FileConflictAction.Overwrite: |
||||
return FileConflictResolution.Overwrite; |
||||
default: |
||||
return FileConflictResolution.Ignore; |
||||
} |
||||
} |
||||
|
||||
public void Dispose() |
||||
{ |
||||
packageEvents.ResolveFileConflict -= ResolveFileConflict; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public enum FileConflictAction |
||||
{ |
||||
None, |
||||
Overwrite, |
||||
Ignore |
||||
} |
||||
} |
@ -0,0 +1,96 @@
@@ -0,0 +1,96 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using Microsoft.Build.Evaluation; |
||||
using NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public class GlobalMSBuildProjectCollection : IGlobalMSBuildProjectCollection |
||||
{ |
||||
class GlobalAndInternalProject |
||||
{ |
||||
public Project GlobalMSBuildProject; |
||||
public MSBuildBasedProject SharpDevelopMSBuildProject; |
||||
public int GlobalMSBuildProjectImportsCount; |
||||
|
||||
public bool HasGlobalMSBuildProjectImportsChanged() |
||||
{ |
||||
return GlobalMSBuildProjectImportsCount != GlobalMSBuildProject.Xml.Imports.Count; |
||||
} |
||||
} |
||||
|
||||
List<GlobalAndInternalProject> projects = new List<GlobalAndInternalProject>(); |
||||
|
||||
PackageManagementLogger logger = new PackageManagementLogger( |
||||
new ThreadSafePackageManagementEvents(PackageManagementServices.PackageManagementEvents)); |
||||
|
||||
public void AddProject(IPackageManagementProject packageManagementProject) |
||||
{ |
||||
AddProject(packageManagementProject.ConvertToDTEProject().MSBuildProject); |
||||
} |
||||
|
||||
void AddProject(MSBuildBasedProject sharpDevelopProject) |
||||
{ |
||||
Project globalProject = GetGlobalProjectCollection().LoadProject(sharpDevelopProject.FileName); |
||||
|
||||
projects.Add(new GlobalAndInternalProject { |
||||
GlobalMSBuildProject = globalProject, |
||||
SharpDevelopMSBuildProject = sharpDevelopProject, |
||||
GlobalMSBuildProjectImportsCount = globalProject.Xml.Imports.Count |
||||
}); |
||||
} |
||||
|
||||
ProjectCollection GetGlobalProjectCollection() |
||||
{ |
||||
return ProjectCollection.GlobalProjectCollection; |
||||
} |
||||
|
||||
public void Dispose() |
||||
{ |
||||
foreach (GlobalAndInternalProject msbuildProjects in projects) { |
||||
UpdateImports(msbuildProjects); |
||||
GetGlobalProjectCollection().UnloadProject(msbuildProjects.GlobalMSBuildProject); |
||||
} |
||||
} |
||||
|
||||
void UpdateImports(GlobalAndInternalProject msbuildProjects) |
||||
{ |
||||
if (!msbuildProjects.HasGlobalMSBuildProjectImportsChanged()) { |
||||
return; |
||||
} |
||||
|
||||
LogProjectImportsChanged(msbuildProjects.SharpDevelopMSBuildProject); |
||||
|
||||
var importsMerger = new MSBuildProjectImportsMerger( |
||||
msbuildProjects.GlobalMSBuildProject, |
||||
msbuildProjects.SharpDevelopMSBuildProject); |
||||
|
||||
importsMerger.Merge(); |
||||
|
||||
LogProjectImportMergeResult(msbuildProjects.SharpDevelopMSBuildProject, importsMerger.Result); |
||||
} |
||||
|
||||
void LogProjectImportsChanged(MSBuildBasedProject project) |
||||
{ |
||||
logger.Log( |
||||
MessageLevel.Info, |
||||
"Project imports have been modified outside SharpDevelop for project '{0}'.", |
||||
project.Name); |
||||
} |
||||
|
||||
void LogProjectImportMergeResult(MSBuildBasedProject project, MSBuildProjectImportsMergeResult result) |
||||
{ |
||||
logger.Log( |
||||
MessageLevel.Info, |
||||
"Project import merge result for project '{0}':\r\n{1}", |
||||
project.Name, |
||||
result); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,11 @@
@@ -0,0 +1,11 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public interface IConsoleHostFileConflictResolver : IDisposable |
||||
{ |
||||
} |
||||
} |
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public interface IGlobalMSBuildProjectCollection : IDisposable |
||||
{ |
||||
void AddProject(IPackageManagementProject project); |
||||
} |
||||
} |
@ -0,0 +1,56 @@
@@ -0,0 +1,56 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using ICSharpCode.SharpDevelop; |
||||
using Microsoft.Build.Construction; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public class MSBuildProjectImportsMergeResult |
||||
{ |
||||
List<string> projectImportsAdded = new List<string>(); |
||||
List<string> projectImportsRemoved = new List<string>(); |
||||
|
||||
public MSBuildProjectImportsMergeResult() |
||||
{ |
||||
} |
||||
|
||||
public IEnumerable<string> ProjectImportsAdded { |
||||
get { return projectImportsAdded; } |
||||
} |
||||
|
||||
public IEnumerable<string> ProjectImportsRemoved { |
||||
get { return projectImportsRemoved; } |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return String.Format( |
||||
"Imports added: {0}\r\nImports removed: {1}", |
||||
ImportsToString(projectImportsAdded), |
||||
ImportsToString(projectImportsRemoved)); |
||||
} |
||||
|
||||
static string ImportsToString(IEnumerable<string> imports) |
||||
{ |
||||
if (!imports.Any()) { |
||||
return String.Empty; |
||||
} |
||||
|
||||
return String.Join(",\r\n", imports.Select(import => String.Format("'{0}'", import))); |
||||
} |
||||
|
||||
public void AddProjectImportsRemoved(IEnumerable<ProjectImportElement> imports) |
||||
{ |
||||
imports.ForEach(import => projectImportsRemoved.Add(import.Project)); |
||||
} |
||||
|
||||
public void AddProjectImportsAdded(IEnumerable<ProjectImportElement> imports) |
||||
{ |
||||
imports.ForEach(import => projectImportsAdded.Add(import.Project)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,87 @@
@@ -0,0 +1,87 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using Microsoft.Build.Construction; |
||||
using Microsoft.Build.Evaluation; |
||||
using NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public class MSBuildProjectImportsMerger |
||||
{ |
||||
IPackageManagementProjectService projectService; |
||||
Project msbuildProject; |
||||
MSBuildBasedProject sharpDevelopProject; |
||||
MSBuildProjectImportsMergeResult result = new MSBuildProjectImportsMergeResult(); |
||||
|
||||
public MSBuildProjectImportsMerger(Project msbuildProject, MSBuildBasedProject sharpDevelopProject) |
||||
: this(msbuildProject, sharpDevelopProject, new PackageManagementProjectService()) |
||||
{ |
||||
} |
||||
|
||||
public MSBuildProjectImportsMerger( |
||||
Project msbuildProject, |
||||
MSBuildBasedProject sharpDevelopProject, |
||||
IPackageManagementProjectService projectService) |
||||
{ |
||||
this.msbuildProject = msbuildProject; |
||||
this.sharpDevelopProject = sharpDevelopProject; |
||||
this.projectService = projectService; |
||||
} |
||||
|
||||
public MSBuildProjectImportsMergeResult Result { |
||||
get { return result; } |
||||
} |
||||
|
||||
public void Merge() |
||||
{ |
||||
int msbuildProjectImportCount = msbuildProject.Xml.Imports.Count; |
||||
int sharpDevelopProjectImportCount = sharpDevelopProject.MSBuildProjectFile.Imports.Count; |
||||
if (msbuildProjectImportCount > sharpDevelopProjectImportCount) { |
||||
AddNewImports(); |
||||
} else if (msbuildProjectImportCount < sharpDevelopProjectImportCount) { |
||||
RemoveMissingImports(); |
||||
} |
||||
} |
||||
|
||||
void RemoveMissingImports() |
||||
{ |
||||
var importsToRemove = new List<ProjectImportElement>(); |
||||
foreach (ProjectImportElement import in sharpDevelopProject.MSBuildProjectFile.Imports) { |
||||
if (msbuildProject.Xml.FindImport(import.Project) == null) { |
||||
importsToRemove.Add(import); |
||||
} |
||||
} |
||||
|
||||
foreach (ProjectImportElement importToRemove in importsToRemove) { |
||||
sharpDevelopProject.MSBuildProjectFile.RemoveChild(importToRemove); |
||||
} |
||||
|
||||
result.AddProjectImportsRemoved(importsToRemove); |
||||
|
||||
projectService.Save(sharpDevelopProject); |
||||
} |
||||
|
||||
void AddNewImports() |
||||
{ |
||||
var importsToAdd = new List<ProjectImportElement>(); |
||||
foreach (ProjectImportElement import in msbuildProject.Xml.Imports) { |
||||
if (!sharpDevelopProject.ImportExists(import.Project)) { |
||||
importsToAdd.Add(import); |
||||
} |
||||
} |
||||
|
||||
foreach (ProjectImportElement importToAdd in importsToAdd) { |
||||
sharpDevelopProject.AddImportIfMissing(importToAdd.Project, ProjectImportLocation.Bottom); |
||||
} |
||||
|
||||
result.AddProjectImportsAdded(importsToAdd); |
||||
|
||||
projectService.Save(sharpDevelopProject); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public class NullGlobalMSBuildProjectCollection : IGlobalMSBuildProjectCollection |
||||
{ |
||||
public void AddProject(IPackageManagementProject project) |
||||
{ |
||||
} |
||||
|
||||
public void Dispose() |
||||
{ |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,168 @@
@@ -0,0 +1,168 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
using NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public class RunAllProjectPackageScriptsAction : IDisposable |
||||
{ |
||||
IPackageScriptRunner scriptRunner; |
||||
List<IPackageManagementProject> projects; |
||||
IPackageScriptFactory scriptFactory; |
||||
IGlobalMSBuildProjectCollection projectCollection; |
||||
|
||||
List<EventHandler<PackageOperationEventArgs>> packageInstalledHandlers = |
||||
new List<EventHandler<PackageOperationEventArgs>>(); |
||||
|
||||
List<EventHandler<PackageOperationEventArgs>> packageReferenceAddedHandlers = |
||||
new List<EventHandler<PackageOperationEventArgs>>(); |
||||
|
||||
List<EventHandler<PackageOperationEventArgs>> packageReferenceRemovedHandlers = |
||||
new List<EventHandler<PackageOperationEventArgs>>(); |
||||
|
||||
public RunAllProjectPackageScriptsAction( |
||||
IPackageScriptRunner scriptRunner, |
||||
IEnumerable<IPackageManagementProject> projects) |
||||
: this(scriptRunner, projects, new PackageScriptFactory(), new GlobalMSBuildProjectCollection()) |
||||
{ |
||||
} |
||||
|
||||
public RunAllProjectPackageScriptsAction( |
||||
IPackageScriptRunner scriptRunner, |
||||
IEnumerable<IPackageManagementProject> projects, |
||||
IPackageScriptFactory scriptFactory, |
||||
IGlobalMSBuildProjectCollection projectCollection) |
||||
{ |
||||
this.scriptRunner = scriptRunner; |
||||
this.projects = projects.ToList(); |
||||
this.scriptFactory = scriptFactory; |
||||
this.projectCollection = projectCollection; |
||||
|
||||
AddProjectsToGlobalCollection(); |
||||
RegisterEvents(); |
||||
} |
||||
|
||||
public void Dispose() |
||||
{ |
||||
IsDisposed = true; |
||||
UnregisterEvents(); |
||||
projectCollection.Dispose(); |
||||
} |
||||
|
||||
public bool IsDisposed { get; private set; } |
||||
|
||||
void AddProjectsToGlobalCollection() |
||||
{ |
||||
foreach (IPackageManagementProject project in projects) { |
||||
projectCollection.AddProject(project); |
||||
} |
||||
} |
||||
|
||||
void RegisterEvents() |
||||
{ |
||||
foreach (IPackageManagementProject project in projects) { |
||||
RegisterPackageInstalledEvent(project); |
||||
RegisterPackageReferenceAddedEvent(project); |
||||
RegisterPackageReferenceRemovedEvent(project); |
||||
} |
||||
} |
||||
|
||||
void RegisterPackageInstalledEvent(IPackageManagementProject project) |
||||
{ |
||||
EventHandler<PackageOperationEventArgs> installHandler = |
||||
(_, e) => PackageInstalled(project, e); |
||||
packageInstalledHandlers.Add(installHandler); |
||||
project.PackageInstalled += installHandler; |
||||
} |
||||
|
||||
void RegisterPackageReferenceAddedEvent(IPackageManagementProject project) |
||||
{ |
||||
EventHandler<PackageOperationEventArgs> referenceAddedHandler = |
||||
(_, e) => PackageReferenceAdded(project, e); |
||||
packageReferenceAddedHandlers.Add(referenceAddedHandler); |
||||
project.PackageReferenceAdded += referenceAddedHandler; |
||||
} |
||||
|
||||
void RegisterPackageReferenceRemovedEvent(IPackageManagementProject project) |
||||
{ |
||||
EventHandler<PackageOperationEventArgs> referenceRemovedHandler = |
||||
(_, e) => PackageReferenceRemoved(project, e); |
||||
packageReferenceRemovedHandlers.Add(referenceRemovedHandler); |
||||
project.PackageReferenceRemoved += referenceRemovedHandler; |
||||
} |
||||
|
||||
void UnregisterEvents() |
||||
{ |
||||
foreach (IPackageManagementProject project in projects) { |
||||
UnregisterPackageInstalledEvent(project); |
||||
UnregisterPackageReferenceAddedEvent(project); |
||||
UnregisterPackageReferenceRemovedEvent(project); |
||||
} |
||||
} |
||||
|
||||
void UnregisterPackageInstalledEvent(IPackageManagementProject project) |
||||
{ |
||||
EventHandler<PackageOperationEventArgs> handler = packageInstalledHandlers.First(); |
||||
packageInstalledHandlers.Remove(handler); |
||||
project.PackageInstalled -= handler; |
||||
} |
||||
|
||||
void UnregisterPackageReferenceAddedEvent(IPackageManagementProject project) |
||||
{ |
||||
EventHandler<PackageOperationEventArgs> handler = packageReferenceAddedHandlers.First(); |
||||
packageReferenceAddedHandlers.Remove(handler); |
||||
project.PackageReferenceAdded -= handler; |
||||
} |
||||
|
||||
void UnregisterPackageReferenceRemovedEvent(IPackageManagementProject project) |
||||
{ |
||||
EventHandler<PackageOperationEventArgs> handler = packageReferenceRemovedHandlers.First(); |
||||
packageReferenceRemovedHandlers.Remove(handler); |
||||
project.PackageReferenceRemoved -= handler; |
||||
} |
||||
|
||||
void PackageInstalled(IPackageManagementProject project, PackageOperationEventArgs e) |
||||
{ |
||||
RunInitScript(project, e); |
||||
} |
||||
|
||||
void PackageReferenceAdded(IPackageManagementProject project, PackageOperationEventArgs e) |
||||
{ |
||||
RunInstallScript(project, e); |
||||
} |
||||
|
||||
void PackageReferenceRemoved(IPackageManagementProject project, PackageOperationEventArgs e) |
||||
{ |
||||
RunUninstallScript(project, e); |
||||
} |
||||
|
||||
void RunInitScript(IPackageManagementProject project, PackageOperationEventArgs e) |
||||
{ |
||||
IPackageScript script = scriptFactory.CreatePackageInitializeScript(e.Package, e.InstallPath); |
||||
RunScript(project, script); |
||||
} |
||||
|
||||
void RunScript(IPackageManagementProject project, IPackageScript script) |
||||
{ |
||||
script.Project = project; |
||||
scriptRunner.Run(script); |
||||
} |
||||
|
||||
void RunInstallScript(IPackageManagementProject project, PackageOperationEventArgs e) |
||||
{ |
||||
IPackageScript script = scriptFactory.CreatePackageInstallScript(e.Package, e.InstallPath); |
||||
RunScript(project, script); |
||||
} |
||||
|
||||
void RunUninstallScript(IPackageManagementProject project, PackageOperationEventArgs e) |
||||
{ |
||||
IPackageScript script = scriptFactory.CreatePackageUninstallScript(e.Package, e.InstallPath); |
||||
RunScript(project, script); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Windows; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public class ServiceWithWorkbenchOwner |
||||
{ |
||||
Window owner; |
||||
|
||||
public Window Owner { |
||||
get { |
||||
if (owner == null) { |
||||
owner = WorkbenchSingleton.MainWindow; |
||||
} |
||||
return owner; |
||||
} |
||||
set { owner = value; } |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Net; |
||||
using NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public class SharpDevelopCredentialProvider : ICredentialProvider |
||||
{ |
||||
public ICredentials GetCredentials(Uri uri, IWebProxy proxy, CredentialType credentialType, bool retrying) |
||||
{ |
||||
return null; |
||||
} |
||||
} |
||||
} |
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue