Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorMichael Hutchinson <m.j.hutchinson@gmail.com>2011-07-28 12:42:50 +0400
committerMichael Hutchinson <m.j.hutchinson@gmail.com>2011-07-28 16:49:54 +0400
commit5e603179aa96a00d329056208dc99202d443181e (patch)
tree9aa58df3228d705d0b6331c6b4690324c0e3eef4 /main
parentf4c3607e0c3bd266f1b13a0c18a8e75425c11e88 (diff)
[Project] Hacky API to migrate project subtypes
Diffstat (limited to 'main')
-rw-r--r--main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/DotNetProjectSubtypeNode.cs24
-rw-r--r--main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/MSBuildProjectHandler.cs28
2 files changed, 46 insertions, 6 deletions
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/DotNetProjectSubtypeNode.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/DotNetProjectSubtypeNode.cs
index 17d12e9615..cb7e595a00 100644
--- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/DotNetProjectSubtypeNode.cs
+++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/DotNetProjectSubtypeNode.cs
@@ -54,6 +54,9 @@ namespace MonoDevelop.Projects.Extensions
[NodeAttribute]
bool useXBuild = false;
+
+ [NodeAttribute]
+ string migrationHandler;
Type itemType;
@@ -86,10 +89,22 @@ namespace MonoDevelop.Projects.Extensions
}
}
+ public string Guid {
+ get { return guid; }
+ }
+
public bool UseXBuild {
get { return useXBuild; }
}
+ public bool IsMigration {
+ get { return migrationHandler != null; }
+ }
+
+ public IDotNetSubtypeMigrationHandler MigrationHandler {
+ get { return (IDotNetSubtypeMigrationHandler) Addin.CreateInstance (migrationHandler); }
+ }
+
public bool SupportsType (string guid)
{
return string.Compare (this.guid, guid, true) == 0;
@@ -102,7 +117,7 @@ namespace MonoDevelop.Projects.Extensions
public virtual bool CanHandleItem (SolutionEntityItem item)
{
- return Type.IsAssignableFrom (item.GetType ());
+ return !IsMigration && Type.IsAssignableFrom (item.GetType ());
}
public virtual bool CanHandleFile (string fileName, string typeGuid)
@@ -158,4 +173,9 @@ namespace MonoDevelop.Projects.Extensions
public bool IsAdd { get; private set; }
}
-}
+
+ public interface IDotNetSubtypeMigrationHandler
+ {
+ bool Migrate (MSBuildProject project, string fileName, string language);
+ }
+} \ No newline at end of file
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/MSBuildProjectHandler.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/MSBuildProjectHandler.cs
index 21b8cad8f4..1456c6a6c0 100644
--- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/MSBuildProjectHandler.cs
+++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/MSBuildProjectHandler.cs
@@ -261,7 +261,7 @@ namespace MonoDevelop.Projects.Formats.MSBuild
try {
timer.Trace ("Create item instance");
ProjectExtensionUtil.BeginLoadOperation ();
- Item = CreateSolutionItem (language, projectTypeGuids, itemType, itemClass);
+ Item = CreateSolutionItem (p, fileName, language, projectTypeGuids, itemType, itemClass);
Item.SetItemHandler (this);
MSBuildProjectService.SetId (Item, itemGuid);
@@ -285,10 +285,10 @@ namespace MonoDevelop.Projects.Formats.MSBuild
set { useXBuild = value; }
}
- SolutionItem CreateSolutionItem (string language, string typeGuids, string itemType, Type itemClass)
+ // All of the last 4 parameters are optional, but at least one must be provided.
+ SolutionItem CreateSolutionItem (MSBuildProject p, string fileName, string language, string typeGuids,
+ string itemType, Type itemClass)
{
- // All the parameters are optional, but at least one must be provided.
-
SolutionItem item = null;
if (!string.IsNullOrEmpty (typeGuids)) {
@@ -296,6 +296,26 @@ namespace MonoDevelop.Projects.Formats.MSBuild
if (st != null) {
item = st.CreateInstance (language);
useXBuild = useXBuild || st.UseXBuild;
+ if (st.IsMigration) {
+ if (!st.MigrationHandler.Migrate (p, fileName, language))
+ throw new Exception ("Could not migrate project");
+
+ var oldSt = st;
+ st = MSBuildProjectService.GetItemSubtypeNodes ()
+ .Where (t => t.CanHandleItem ((SolutionEntityItem)item)).Last ();
+ for (int i = 0; i < subtypeGuids.Count; i++) {
+ if (string.Equals (subtypeGuids[i], oldSt.Guid, StringComparison.OrdinalIgnoreCase)) {
+ subtypeGuids[i] = st.Guid;
+ oldSt = null;
+ break;
+ }
+ }
+ if (oldSt != null)
+ throw new Exception ("Unable to correct flavor GUID");
+ p.GetGlobalPropertyGroup ().SetPropertyValue ("ProjectTypeGuids", string.Join (";", SubtypeGuids));
+ fileContent = p.Save ();
+ MonoDevelop.Projects.Text.TextFile.WriteFile (fileName, fileContent, "UTF-8");
+ }
st.UpdateImports ((SolutionEntityItem)item, targetImports);
} else
throw new UnknownSolutionItemTypeException (typeGuids);