Browse Source
Also, fixes various references to the "VBNet" language string to use "VB" instead.newNR
51 changed files with 278 additions and 322 deletions
@ -0,0 +1,91 @@ |
|||||||
|
// 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 ICSharpCode.NRefactory.Utils; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
|
||||||
|
namespace ICSharpCode.SharpDevelop.Project |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Represents the registration of a project binding with the project service.
|
||||||
|
/// </summary>
|
||||||
|
public class ProjectBindingDescriptor |
||||||
|
{ |
||||||
|
readonly AddIn addIn; |
||||||
|
readonly string className; |
||||||
|
readonly string language; |
||||||
|
readonly Guid typeGuid; |
||||||
|
readonly string projectFileExtension; |
||||||
|
readonly string[] codeFileExtensions; |
||||||
|
IProjectBinding binding; |
||||||
|
|
||||||
|
public IProjectBinding Binding { |
||||||
|
get { |
||||||
|
if (binding != null) |
||||||
|
return binding; |
||||||
|
if (addIn == null) |
||||||
|
return null; |
||||||
|
return LazyInit.GetOrSet(ref binding, (IProjectBinding)addIn.CreateObject(className)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public string ProjectFileExtension { |
||||||
|
get { |
||||||
|
return projectFileExtension; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public Guid TypeGuid { |
||||||
|
get { |
||||||
|
return typeGuid; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public string Language { |
||||||
|
get { |
||||||
|
return language; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public string[] CodeFileExtensions { |
||||||
|
get { |
||||||
|
return codeFileExtensions; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public ProjectBindingDescriptor(IProjectBinding binding, string language, string projectFileExtension, Guid typeGuid, string[] codeFileExtensions) |
||||||
|
{ |
||||||
|
if (binding == null) |
||||||
|
throw new ArgumentNullException("binding"); |
||||||
|
if (language == null) |
||||||
|
throw new ArgumentNullException("language"); |
||||||
|
if (projectFileExtension == null) |
||||||
|
throw new ArgumentNullException("projectFileExtension"); |
||||||
|
if (codeFileExtensions == null) |
||||||
|
throw new ArgumentNullException("codeFileExtensions"); |
||||||
|
this.binding = binding; |
||||||
|
this.projectFileExtension = projectFileExtension; |
||||||
|
this.typeGuid = typeGuid; |
||||||
|
this.language = language; |
||||||
|
this.codeFileExtensions = codeFileExtensions; |
||||||
|
} |
||||||
|
|
||||||
|
public ProjectBindingDescriptor(Codon codon) |
||||||
|
{ |
||||||
|
if (codon == null) |
||||||
|
throw new ArgumentNullException("codon"); |
||||||
|
this.addIn = codon.AddIn; |
||||||
|
this.language = codon.Id; |
||||||
|
this.className = codon.Properties["class"]; |
||||||
|
this.projectFileExtension = codon.Properties["projectfileextension"]; |
||||||
|
if (string.IsNullOrEmpty(codon.Properties["supportedextensions"])) |
||||||
|
this.codeFileExtensions = new string[0]; |
||||||
|
else |
||||||
|
this.codeFileExtensions = codon.Properties["supportedextensions"].ToLowerInvariant().Split(';'); |
||||||
|
if (!string.IsNullOrEmpty(codon.Properties["guid"])) |
||||||
|
this.typeGuid = Guid.Parse(codon.Properties["guid"]); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,71 +0,0 @@ |
|||||||
// 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 ICSharpCode.SharpDevelop.Project; |
|
||||||
|
|
||||||
namespace ICSharpCode.SharpDevelop |
|
||||||
{ |
|
||||||
public class ProjectBindingDescriptor |
|
||||||
{ |
|
||||||
IProjectBinding binding = null; |
|
||||||
Codon codon; |
|
||||||
|
|
||||||
public IProjectBinding Binding { |
|
||||||
get { |
|
||||||
if (binding == null) { |
|
||||||
binding = (IProjectBinding)codon.AddIn.CreateObject(codon.Properties["class"]); |
|
||||||
if (binding != null) { |
|
||||||
if (binding.Language != this.Language) |
|
||||||
throw new InvalidOperationException("The Language property of the project binding must be equal to the id of the ProjectBinding codon!"); |
|
||||||
} |
|
||||||
} |
|
||||||
return binding; |
|
||||||
} |
|
||||||
} |
|
||||||
public Codon Codon { |
|
||||||
get { |
|
||||||
return codon; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public string ProjectFileExtension { |
|
||||||
get { |
|
||||||
return codon.Properties["projectfileextension"]; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public Guid Guid { |
|
||||||
get { |
|
||||||
return Guid.Parse(codon.Properties["guid"]); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public string Language { |
|
||||||
get { |
|
||||||
return codon.Id; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
string[] codeFileExtensions; |
|
||||||
|
|
||||||
public string[] CodeFileExtensions { |
|
||||||
get { |
|
||||||
if (codeFileExtensions == null) { |
|
||||||
if (codon.Properties["supportedextensions"].Length == 0) |
|
||||||
codeFileExtensions = new string[0]; |
|
||||||
else |
|
||||||
codeFileExtensions = codon.Properties["supportedextensions"].ToLowerInvariant().Split(';'); |
|
||||||
} |
|
||||||
return codeFileExtensions; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public ProjectBindingDescriptor(Codon codon) |
|
||||||
{ |
|
||||||
this.codon = codon; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,131 +0,0 @@ |
|||||||
// 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 ICSharpCode.SharpDevelop.Gui; |
|
||||||
using System; |
|
||||||
using System.Collections.Generic; |
|
||||||
using System.IO; |
|
||||||
using System.Xml; |
|
||||||
using ICSharpCode.Core; |
|
||||||
using ICSharpCode.SharpDevelop.Project; |
|
||||||
|
|
||||||
namespace ICSharpCode.SharpDevelop |
|
||||||
{ |
|
||||||
public static class ProjectBindingService |
|
||||||
{ |
|
||||||
static IList<ProjectBindingDescriptor> bindings; |
|
||||||
|
|
||||||
static ProjectBindingService() |
|
||||||
{ |
|
||||||
bindings = AddInTree.BuildItems<ProjectBindingDescriptor>("/SharpDevelop/Workbench/ProjectBindings", null, false); |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Overwrites the list of used bindings. Used for unit tests.
|
|
||||||
/// </summary>
|
|
||||||
public static void SetBindings(IList<ProjectBindingDescriptor> bindings) |
|
||||||
{ |
|
||||||
ProjectBindingService.bindings = bindings; |
|
||||||
} |
|
||||||
|
|
||||||
public static string GetProjectFileExtension(string languageName) |
|
||||||
{ |
|
||||||
ProjectBindingDescriptor descriptor = GetCodonPerLanguageName(languageName); |
|
||||||
return descriptor == null ? null : descriptor.ProjectFileExtension; |
|
||||||
} |
|
||||||
|
|
||||||
public static IProjectBinding GetBindingPerLanguageName(string languagename) |
|
||||||
{ |
|
||||||
ProjectBindingDescriptor descriptor = GetCodonPerLanguageName(languagename); |
|
||||||
return descriptor == null ? null : descriptor.Binding; |
|
||||||
} |
|
||||||
|
|
||||||
public static IProjectBinding GetBindingCodePerFileName(string filename) |
|
||||||
{ |
|
||||||
ProjectBindingDescriptor descriptor = GetCodonPerCodeFileName(filename); |
|
||||||
return descriptor == null ? null : descriptor.Binding; |
|
||||||
} |
|
||||||
|
|
||||||
public static IProjectBinding GetBindingPerProjectFile(string filename) |
|
||||||
{ |
|
||||||
ProjectBindingDescriptor descriptor = GetCodonPerProjectFile(filename); |
|
||||||
return descriptor == null ? null : descriptor.Binding; |
|
||||||
} |
|
||||||
|
|
||||||
public static ProjectBindingDescriptor GetCodonPerLanguageName(string languagename) |
|
||||||
{ |
|
||||||
foreach (ProjectBindingDescriptor binding in bindings) { |
|
||||||
if (binding.Language == languagename) { |
|
||||||
return binding; |
|
||||||
} |
|
||||||
} |
|
||||||
return null; |
|
||||||
} |
|
||||||
|
|
||||||
public static ProjectBindingDescriptor GetCodonPerCodeFileName(string filename) |
|
||||||
{ |
|
||||||
string extension = Path.GetExtension(filename).ToLowerInvariant(); |
|
||||||
foreach (ProjectBindingDescriptor binding in bindings) { |
|
||||||
if (Array.IndexOf(binding.CodeFileExtensions, extension) >= 0) { |
|
||||||
return binding; |
|
||||||
} |
|
||||||
} |
|
||||||
return null; |
|
||||||
} |
|
||||||
|
|
||||||
public static ProjectBindingDescriptor GetCodonPerProjectFile(string fileName) |
|
||||||
{ |
|
||||||
string ext = Path.GetExtension(fileName).ToUpperInvariant(); |
|
||||||
foreach (ProjectBindingDescriptor binding in bindings) { |
|
||||||
if (binding.ProjectFileExtension.ToUpperInvariant() == ext) { |
|
||||||
return binding; |
|
||||||
} |
|
||||||
} |
|
||||||
return null; |
|
||||||
} |
|
||||||
|
|
||||||
public static IProject LoadProject(ProjectLoadInformation loadInformation) |
|
||||||
{ |
|
||||||
if (loadInformation == null) |
|
||||||
throw new ArgumentNullException("loadInformation"); |
|
||||||
|
|
||||||
var location = loadInformation.FileName; |
|
||||||
string title = loadInformation.ProjectName; |
|
||||||
IProgressMonitor progressMonitor = loadInformation.ProgressMonitor; |
|
||||||
|
|
||||||
progressMonitor.CancellationToken.ThrowIfCancellationRequested(); |
|
||||||
|
|
||||||
IProjectBinding binding = ProjectBindingService.GetBindingPerProjectFile(location); |
|
||||||
IProject newProject; |
|
||||||
if (!(binding != null && binding.HandlingMissingProject) && !File.Exists(location)) { |
|
||||||
newProject = new MissingProject(loadInformation); |
|
||||||
} else { |
|
||||||
if (binding != null) { |
|
||||||
try { |
|
||||||
newProject = binding.LoadProject(loadInformation); |
|
||||||
} catch (ProjectLoadException ex) { |
|
||||||
LoggingService.Warn("Project load error", ex); |
|
||||||
progressMonitor.ShowingDialog = true; |
|
||||||
newProject = new UnknownProject(loadInformation, ex.Message, true); |
|
||||||
progressMonitor.ShowingDialog = false; |
|
||||||
} catch (UnauthorizedAccessException ex) { |
|
||||||
LoggingService.Warn("Project load error", ex); |
|
||||||
progressMonitor.ShowingDialog = true; |
|
||||||
newProject = new UnknownProject(loadInformation, ex.Message, true); |
|
||||||
progressMonitor.ShowingDialog = false; |
|
||||||
} |
|
||||||
} else { |
|
||||||
string ext = Path.GetExtension(location); |
|
||||||
if (".proj".Equals(ext, StringComparison.OrdinalIgnoreCase) |
|
||||||
|| ".build".Equals(ext, StringComparison.OrdinalIgnoreCase)) |
|
||||||
{ |
|
||||||
newProject = new MSBuildFileProject(loadInformation); |
|
||||||
} else { |
|
||||||
newProject = new UnknownProject(loadInformation); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
return newProject; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue