diff options
author | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-04-22 22:01:52 +0300 |
---|---|---|
committer | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-04-22 22:01:52 +0300 |
commit | b91054f1b963a893b70c2a8467f932a644a60d68 (patch) | |
tree | 4fe1381914555cb90fedc4277ec4752b7f53aa84 /main/src/addins/MonoDeveloperExtensions | |
parent | c47bd9005efca0a0ed3362250f541f8aaabac4ba (diff) |
Fix MonoDevelopExtensions add-in
Fixed this add-in by using the new api for customizing project and
solution serialization.
Diffstat (limited to 'main/src/addins/MonoDeveloperExtensions')
-rw-r--r-- | main/src/addins/MonoDeveloperExtensions/Commands.cs | 2 | ||||
-rw-r--r-- | main/src/addins/MonoDeveloperExtensions/MonoDeveloperExtensions.addin.xml | 5 | ||||
-rw-r--r-- | main/src/addins/MonoDeveloperExtensions/MonoDeveloperExtensions.csproj | 6 | ||||
-rw-r--r-- | main/src/addins/MonoDeveloperExtensions/MonoMakefile.cs | 2 | ||||
-rw-r--r-- | main/src/addins/MonoDeveloperExtensions/MonoMakefileFormat.cs | 194 | ||||
-rw-r--r-- | main/src/addins/MonoDeveloperExtensions/MonoMakefileProjectExtension.cs (renamed from main/src/addins/MonoDeveloperExtensions/MakefileProject.cs) | 118 | ||||
-rw-r--r-- | main/src/addins/MonoDeveloperExtensions/MonoMakefileProjectReader.cs | 143 | ||||
-rw-r--r-- | main/src/addins/MonoDeveloperExtensions/MonoMakefileSolutionExtension.cs | 41 | ||||
-rw-r--r-- | main/src/addins/MonoDeveloperExtensions/MonoSolutionItemHandler.cs | 348 | ||||
-rw-r--r-- | main/src/addins/MonoDeveloperExtensions/NUnit/MonoTestProvider.cs | 15 |
10 files changed, 232 insertions, 642 deletions
diff --git a/main/src/addins/MonoDeveloperExtensions/Commands.cs b/main/src/addins/MonoDeveloperExtensions/Commands.cs index 8cab36b704..a5293c8af5 100644 --- a/main/src/addins/MonoDeveloperExtensions/Commands.cs +++ b/main/src/addins/MonoDeveloperExtensions/Commands.cs @@ -50,7 +50,7 @@ namespace MonoDeveloper protected override void Update (CommandInfo info) { - info.Visible = IdeApp.ProjectOperations.CurrentSelectedItem is MakefileProject; + info.Visible = IdeApp.ProjectOperations.CurrentSelectedItem is MonoMakefileProjectExtension; } void Install (object prj) diff --git a/main/src/addins/MonoDeveloperExtensions/MonoDeveloperExtensions.addin.xml b/main/src/addins/MonoDeveloperExtensions/MonoDeveloperExtensions.addin.xml index f8288a171a..96813bd4dc 100644 --- a/main/src/addins/MonoDeveloperExtensions/MonoDeveloperExtensions.addin.xml +++ b/main/src/addins/MonoDeveloperExtensions/MonoDeveloperExtensions.addin.xml @@ -1,8 +1,7 @@ <ExtensionModel> - <Extension path = "/MonoDevelop/ProjectModel/FileFormats"> - <FileFormat id = "MonoMakefile" name="Mono Makefile" - class = "MonoDeveloper.MonoMakefileFormat" /> + <Extension path = "/MonoDevelop/ProjectModel/WorkspaceObjectReaders"> + <Class class = "MonoDeveloper.MonoMakefileProjectReader" /> </Extension> <Extension path = "/MonoDevelop/ProjectModel/Gui/ItemOptionPanels"> diff --git a/main/src/addins/MonoDeveloperExtensions/MonoDeveloperExtensions.csproj b/main/src/addins/MonoDeveloperExtensions/MonoDeveloperExtensions.csproj index 17c7f36e9b..92f57f4f76 100644 --- a/main/src/addins/MonoDeveloperExtensions/MonoDeveloperExtensions.csproj +++ b/main/src/addins/MonoDeveloperExtensions/MonoDeveloperExtensions.csproj @@ -75,11 +75,11 @@ <ItemGroup> <Compile Include="AssemblyInfo.cs" /> <Compile Include="MonoMakefile.cs" /> - <Compile Include="MonoMakefileFormat.cs" /> <Compile Include="Commands.cs" /> - <Compile Include="MonoSolutionItemHandler.cs" /> <Compile Include="AddinInfo.cs" /> - <Compile Include="MakefileProject.cs" /> + <Compile Include="MonoMakefileSolutionExtension.cs" /> + <Compile Include="MonoMakefileProjectExtension.cs" /> + <Compile Include="MonoMakefileProjectReader.cs" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="MonoDeveloperExtensions.addin.xml"> diff --git a/main/src/addins/MonoDeveloperExtensions/MonoMakefile.cs b/main/src/addins/MonoDeveloperExtensions/MonoMakefile.cs index 8168d90acb..672a5ef378 100644 --- a/main/src/addins/MonoDeveloperExtensions/MonoMakefile.cs +++ b/main/src/addins/MonoDeveloperExtensions/MonoMakefile.cs @@ -41,6 +41,8 @@ namespace MonoDeveloper string multilineMatch = @"(((?<content>.*)(?<!\\)\n)|((?<content>.*?)\\\n(\t(?<content>.*?)\\\n)*\t(?<content>.*?)(?<!\\)\n))"; string fileName; + public static string[] MonoConfigurations = { "default", "net_4_0" }; + public MonoMakefile (string file) { this.fileName = file; diff --git a/main/src/addins/MonoDeveloperExtensions/MonoMakefileFormat.cs b/main/src/addins/MonoDeveloperExtensions/MonoMakefileFormat.cs deleted file mode 100644 index dc53d9e136..0000000000 --- a/main/src/addins/MonoDeveloperExtensions/MonoMakefileFormat.cs +++ /dev/null @@ -1,194 +0,0 @@ -// -// MonoMakefileFormat.cs -// -// Author: -// Lluis Sanchez Gual -// -// Copyright (C) 2005 Novell, Inc (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Text; -using MonoDevelop.Core; -using System.Text.RegularExpressions; -using MonoDevelop.Projects; -using MonoDevelop.Projects.Extensions; -using System.Threading.Tasks; - -namespace MonoDeveloper -{ - public class MonoMakefileFormat - { - public static readonly string[] Configurations = new string [] { - "default", "net_2_0" - }; - - public string Name { - get { return "Mono Makefile"; } - }
-
- public FilePath GetValidFormatName (object obj, FilePath fileName) - { - return fileName.ParentDirectory.Combine ("Makefile"); - }
-
- public bool CanReadFile (FilePath file, Type expectedType) - { - if (file.FileName != "Makefile") return false; - MonoMakefile mkfile = new MonoMakefile (file); - if (mkfile.Content.IndexOf ("build/rules.make") == -1) return false; - - if (mkfile.GetVariable ("LIBRARY") != null) return expectedType.IsAssignableFrom (typeof(DotNetProject)); - if (mkfile.GetVariable ("PROGRAM") != null) return expectedType.IsAssignableFrom (typeof(DotNetProject)); - string subdirs = mkfile.GetVariable ("SUBDIRS"); - if (subdirs != null && subdirs.Trim (' ','\t') != "") - return expectedType.IsAssignableFrom (typeof(Solution)) || expectedType.IsAssignableFrom (typeof(SolutionFolder)); - - return false; - } - - public bool CanWriteFile (object obj) - { - return (obj is SolutionFolder) || (obj is MakefileProject); - }
-
- public Task WriteFile (FilePath file, object node, ProgressMonitor monitor) - { - return Task.FromResult (0); - }
-
- public List<FilePath> GetItemFiles (object obj) - {
- List<FilePath> col = new List<FilePath> (); - var mp = obj as MakefileProject; - if (mp != null) { - if (File.Exists (mp.SourcesFile)) { - col.Add (mp.FileName); - col.Add (mp.SourcesFile); - } - } - return col; - }
-
- public Task<object> ReadFile (FilePath fileName, Type expectedType, ProgressMonitor monitor) - { - return ReadFile (fileName, false, monitor); - }
-
- public Task<object> ReadFile (FilePath fileName, bool hasParentSolution, ProgressMonitor monitor) - { - return Task<object>.Factory.StartNew (delegate { - FilePath basePath = fileName.ParentDirectory; - MonoMakefile mkfile = new MonoMakefile (fileName); - string aname = mkfile.GetVariable ("LIBRARY"); - if (aname == null) - aname = mkfile.GetVariable ("PROGRAM"); - - try { - if (aname != null) { - // It is a project - monitor.BeginTask ("Loading '" + fileName + "'", 0); - MakefileProject project = new MakefileProject ("C#"); - project.Name = Path.GetFileName (basePath); - project.Read (mkfile); - monitor.EndTask (); - return project; - } else { - string subdirs; - StringBuilder subdirsBuilder = new StringBuilder (); - subdirsBuilder.Append (mkfile.GetVariable ("common_dirs")); - if (subdirsBuilder.Length != 0) { - subdirsBuilder.Append ("\t"); - subdirsBuilder.Append (mkfile.GetVariable ("net_2_0_dirs")); - } - if (subdirsBuilder.Length == 0) - subdirsBuilder.Append (mkfile.GetVariable ("SUBDIRS")); - - subdirs = subdirsBuilder.ToString (); - if (subdirs != null && (subdirs = subdirs.Trim (' ', '\t')) != "") { - object retObject; - SolutionFolder folder; - if (!hasParentSolution) { - Solution sol = new Solution (); - sol.FileName = fileName; - folder = sol.RootFolder; - retObject = sol; - - foreach (string conf in MonoMakefileFormat.Configurations) { - SolutionConfiguration sc = new SolutionConfiguration (conf); - sol.Configurations.Add (sc); - } - } else { - folder = new SolutionFolder (); - folder.Name = Path.GetFileName (Path.GetDirectoryName (fileName)); - retObject = folder; - } - - subdirs = subdirs.Replace ('\t', ' '); - string[] dirs = subdirs.Split (' '); - - monitor.BeginTask ("Loading '" + fileName + "'", dirs.Length); - Hashtable added = new Hashtable (); - foreach (string dir in dirs) { - if (added.Contains (dir)) - continue; - added.Add (dir, dir); - monitor.Step (1); - if (dir == null) - continue; - string tdir = dir.Trim (); - if (tdir == "") - continue; - string mfile = Path.Combine (Path.Combine (basePath, tdir), "Makefile"); - if (File.Exists (mfile) && CanReadFile (mfile, typeof(SolutionFolderItem))) { - SolutionFolderItem it = (SolutionFolderItem)ReadFile (mfile, true, monitor).Result; - folder.Items.Add (it); - } - } - monitor.EndTask (); - return retObject; - } - } - } finally { - } - return null; - }); - } - - public bool SupportsMixedFormats { - get { return false; } - } - - public IEnumerable<string> GetCompatibilityWarnings (object obj) - { - yield break; - } - - public bool SupportsFramework (MonoDevelop.Core.Assemblies.TargetFramework framework) - { - return true; - } - } -} diff --git a/main/src/addins/MonoDeveloperExtensions/MakefileProject.cs b/main/src/addins/MonoDeveloperExtensions/MonoMakefileProjectExtension.cs index d48001bfad..a696fc5ac5 100644 --- a/main/src/addins/MonoDeveloperExtensions/MakefileProject.cs +++ b/main/src/addins/MonoDeveloperExtensions/MonoMakefileProjectExtension.cs @@ -37,79 +37,33 @@ using System.CodeDom.Compiler; namespace MonoDeveloper { - public class MakefileProject: WorkspaceObject + public class MonoMakefileProjectExtension: DotNetProjectExtension { - string name; - FilePath file; - - public MakefileProject (string lang) - { - } - - public new string Name { - get { return name; } - set { name = value; } - } - - public FilePath FileName { - get { return file; } - set { file = value; } - } - - #region implemented abstract members of WorkspaceObject - - protected override string OnGetName () - { - return name; - } - - protected override string OnGetItemDirectory () - { - return file.ParentDirectory; - } - - protected override string OnGetBaseDirectory () - { - return file.ParentDirectory; - } - - #endregion - - - DotNetProject project; string outFile; ArrayList refNames = new ArrayList (); bool loading; string testFileBase; object unitTest; - public MakefileProject (DotNetProject project) + public MonoMakefileProjectExtension () { - this.project = project; - project.FileAddedToProject += OnFileAddedToProject; - project.FileRemovedFromProject += OnFileRemovedFromProject; - project.FileRenamedInProject += OnFileRenamedInProject; } - public string SourcesFile { - get { return outFile + ".sources"; } - } - - public bool SyncFileName { - get { return false; } + protected override void Initialize () + { + base.Initialize (); + Project.FileAddedToProject += OnFileAddedToProject; + Project.FileRemovedFromProject += OnFileRemovedFromProject; + Project.FileRenamedInProject += OnFileRenamedInProject; } - public string ItemId { - get { - if (project.ParentSolution != null) - return project.ParentSolution.GetRelativeChildPath (project.FileName); - else - return project.Name; - } + public string SourcesFile { + get { return outFile + ".sources"; } } - public Task Save (MonoDevelop.Core.ProgressMonitor monitor) + protected override Task OnSave (ProgressMonitor monitor) { + // Nothing to do, changes are saved directly to the backing file return Task.FromResult (0); } @@ -134,7 +88,7 @@ namespace MonoDeveloper } outFile = Path.Combine (basePath, aname); - project.FileName = mkfile.FileName; + Project.FileName = mkfile.FileName; ArrayList checkedFolders = new ArrayList (); @@ -146,14 +100,14 @@ namespace MonoDeveloper line = line.Trim (' ','\t'); if (line != "") { string fname = Path.Combine (basePath, line); - project.Files.Add (new ProjectFile (fname)); + Project.Files.Add (new ProjectFile (fname)); string dir = Path.GetDirectoryName (fname); if (!checkedFolders.Contains (dir)) { checkedFolders.Add (dir); fname = Path.Combine (dir, "ChangeLog"); if (File.Exists (fname)) - project.Files.Add (new ProjectFile (fname, BuildAction.Content)); + Project.Files.Add (new ProjectFile (fname, BuildAction.Content)); } } } @@ -182,24 +136,24 @@ namespace MonoDeveloper testFileBase = Path.Combine (basePath, tname); } - foreach (string sconf in MonoMakefileFormat.Configurations) { + foreach (string sconf in MonoMakefile.MonoConfigurations) { DotNetProjectConfiguration conf = new DotNetProjectConfiguration (sconf); - conf.CompilationParameters = project.LanguageBinding.CreateCompilationParameters (null); + conf.CompilationParameters = Project.LanguageBinding.CreateCompilationParameters (null); conf.OutputDirectory = basePath; conf.OutputAssembly = Path.GetFileName (targetAssembly); - project.Configurations.Add (conf); + Project.Configurations.Add (conf); } loading = false; IdeApp.Workspace.SolutionLoaded += CombineOpened; } - public void CombineOpened (object sender, SolutionEventArgs args) + void CombineOpened (object sender, SolutionEventArgs args) { - if (args.Solution == project.ParentSolution) { + if (args.Solution == Project.ParentSolution) { foreach (string pref in refNames) { - Project p = project.ParentSolution.FindProjectByName (pref); - if (p != null) project.References.Add (new ProjectReference (p)); + Project p = Project.ParentSolution.FindProjectByName (pref); + if (p != null) Project.References.Add (new ProjectReference (p)); } } } @@ -207,14 +161,14 @@ namespace MonoDeveloper static Regex regexError = new Regex (@"^(\s*(?<file>.*)\((?<line>\d*)(,(?<column>\d*[\+]*))?\)(:|)\s+)*(?<level>\w+)\s*(?<number>.*):\s(?<message>.*)", RegexOptions.Compiled | RegexOptions.ExplicitCapture); - public Task<BuildResult> RunTarget (MonoDevelop.Core.ProgressMonitor monitor, string target, ConfigurationSelector configuration) + protected override Task<BuildResult> OnRunTarget (ProgressMonitor monitor, string target, ConfigurationSelector configuration) { if (target == ProjectService.BuildTarget) target = "all"; else if (target == ProjectService.CleanTarget) target = "clean"; - DotNetProjectConfiguration conf = (DotNetProjectConfiguration) project.GetConfiguration (configuration); + DotNetProjectConfiguration conf = (DotNetProjectConfiguration) Project.GetConfiguration (configuration); return Task<BuildResult>.Factory.StartNew (delegate { using (var output = new StringWriter ()) { @@ -265,7 +219,7 @@ namespace MonoDeveloper return null; if (String.Empty != match.Result("${file}")) - error.FileName = Path.Combine (project.BaseDirectory, match.Result("${file}")); + error.FileName = Path.Combine (Project.BaseDirectory, match.Result("${file}")); if (String.Empty != match.Result("${line}")) error.Line=Int32.Parse(match.Result("${line}")); if (String.Empty != match.Result("${column}")) @@ -320,7 +274,7 @@ namespace MonoDeveloper sr = new StreamReader (outFile + ".sources"); sw = new StreamWriter (outFile + ".sources.new"); - string newFile = project.GetRelativeChildPath (sourceFile); + string newFile = Project.GetRelativeChildPath (sourceFile); if (newFile.StartsWith ("./")) newFile = newFile.Substring (2); string line; @@ -352,7 +306,7 @@ namespace MonoDeveloper sr = new StreamReader (outFile + ".sources"); sw = new StreamWriter (outFile + ".sources.new"); - string oldFile = project.GetRelativeChildPath (sourceFile); + string oldFile = Project.GetRelativeChildPath (sourceFile); if (oldFile.StartsWith ("./")) oldFile = oldFile.Substring (2); string line; @@ -374,16 +328,13 @@ namespace MonoDeveloper return found; } - public void Dispose () + public override void Dispose () { - project.FileAddedToProject -= OnFileAddedToProject; - project.FileRemovedFromProject -= OnFileRemovedFromProject; - project.FileRenamedInProject -= OnFileRenamedInProject; + Project.FileAddedToProject -= OnFileAddedToProject; + Project.FileRemovedFromProject -= OnFileRemovedFromProject; + Project.FileRenamedInProject -= OnFileRenamedInProject; IdeApp.Workspace.SolutionLoaded -= CombineOpened; - } - - public void OnModified (string hint) - { + base.Dispose (); } public string GetTestFileBase () @@ -395,11 +346,6 @@ namespace MonoDeveloper get { return unitTest; } set { unitTest = value; } } - - public object GetService (Type t) - { - return null; - } } } diff --git a/main/src/addins/MonoDeveloperExtensions/MonoMakefileProjectReader.cs b/main/src/addins/MonoDeveloperExtensions/MonoMakefileProjectReader.cs new file mode 100644 index 0000000000..8e0ab40f3f --- /dev/null +++ b/main/src/addins/MonoDeveloperExtensions/MonoMakefileProjectReader.cs @@ -0,0 +1,143 @@ +// +// MonoMakeFileProjectServiceExtension.cs +// +// Author: +// Lluis Sanchez Gual <lluis@xamarin.com> +// +// Copyright (c) 2015 Xamarin, Inc (http://www.xamarin.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; +using MonoDevelop.Projects; +using MonoDevelop.Core; +using System.Threading.Tasks; +using MonoDevelop.Projects.Formats.MSBuild; +using System.IO; +using System.Text; +using System.Collections.Generic; + +namespace MonoDeveloper +{ + public class MonoMakefileProjectReader: WorkspaceObjectReader + { + public override bool CanRead (FilePath file, Type expectedType) + { + if (file.FileName != "Makefile") return false; + MonoMakefile mkfile = new MonoMakefile (file); + if (mkfile.Content.IndexOf ("build/rules.make") == -1) return false; + + if (mkfile.GetVariable ("LIBRARY") != null) return expectedType.IsAssignableFrom (typeof(DotNetProject)); + if (mkfile.GetVariable ("PROGRAM") != null) return expectedType.IsAssignableFrom (typeof(DotNetProject)); + string subdirs = mkfile.GetVariable ("SUBDIRS"); + if (subdirs != null && subdirs.Trim (' ','\t') != "") + return expectedType.IsAssignableFrom (typeof(Solution)) || expectedType.IsAssignableFrom (typeof(SolutionFolder)); + + return false; + } + + public override Task<SolutionItem> LoadSolutionItem (ProgressMonitor monitor, SolutionLoadContext ctx, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid) + { + return Task.Run (() => (SolutionItem) ReadFile (fileName, false, monitor)); + } + + public override Task<WorkspaceItem> LoadWorkspaceItem (ProgressMonitor monitor, string fileName) + { + return Task.Run (() => (WorkspaceItem) ReadFile (fileName, false, monitor)); + } + + public object ReadFile (FilePath fileName, bool hasParentSolution, ProgressMonitor monitor) + { + FilePath basePath = fileName.ParentDirectory; + MonoMakefile mkfile = new MonoMakefile (fileName); + string aname = mkfile.GetVariable ("LIBRARY"); + if (aname == null) + aname = mkfile.GetVariable ("PROGRAM"); + + if (!string.IsNullOrEmpty (aname)) { + monitor.BeginTask ("Loading '" + fileName + "'", 0); + var project = Services.ProjectService.CreateProject ("C#"); + project.FileName = fileName; + + var ext = new MonoMakefileProjectExtension (); + project.AttachExtension (ext); + ext.Read (mkfile); + + monitor.EndTask (); + return project; + } + + string subdirs; + StringBuilder subdirsBuilder = new StringBuilder (); + subdirsBuilder.Append (mkfile.GetVariable ("common_dirs")); + if (subdirsBuilder.Length != 0) { + subdirsBuilder.Append ("\t"); + subdirsBuilder.Append (mkfile.GetVariable ("net_2_0_dirs")); + } + if (subdirsBuilder.Length == 0) + subdirsBuilder.Append (mkfile.GetVariable ("SUBDIRS")); + + subdirs = subdirsBuilder.ToString (); + if (subdirs != null && (subdirs = subdirs.Trim (' ', '\t')) != "") { + object retObject; + SolutionFolder folder; + if (!hasParentSolution) { + Solution sol = new Solution (); + sol.AttachExtension (new MonoMakefileSolutionExtension ()); + sol.FileName = fileName; + folder = sol.RootFolder; + retObject = sol; + + foreach (string conf in MonoMakefile.MonoConfigurations) { + SolutionConfiguration sc = new SolutionConfiguration (conf); + sol.Configurations.Add (sc); + } + } else { + folder = new SolutionFolder (); + folder.Name = Path.GetFileName (Path.GetDirectoryName (fileName)); + retObject = folder; + } + + subdirs = subdirs.Replace ('\t', ' '); + string[] dirs = subdirs.Split (' '); + + monitor.BeginTask ("Loading '" + fileName + "'", dirs.Length); + HashSet<string> added = new HashSet<string> (); + foreach (string dir in dirs) { + if (!added.Add (dir)) + continue; + monitor.Step (1); + if (dir == null) + continue; + string tdir = dir.Trim (); + if (tdir == "") + continue; + string mfile = Path.Combine (Path.Combine (basePath, tdir), "Makefile"); + if (File.Exists (mfile) && CanRead (mfile, typeof(SolutionItem))) { + SolutionFolderItem it = (SolutionFolderItem) ReadFile (mfile, true, monitor); + folder.Items.Add (it); + } + } + monitor.EndTask (); + return retObject; + } + return null; + } + } +} + diff --git a/main/src/addins/MonoDeveloperExtensions/MonoMakefileSolutionExtension.cs b/main/src/addins/MonoDeveloperExtensions/MonoMakefileSolutionExtension.cs new file mode 100644 index 0000000000..a09cd12563 --- /dev/null +++ b/main/src/addins/MonoDeveloperExtensions/MonoMakefileSolutionExtension.cs @@ -0,0 +1,41 @@ +// +// MonoMakefileSolutionExtension.cs +// +// Author: +// Lluis Sanchez Gual <lluis@xamarin.com> +// +// Copyright (c) 2015 Xamarin, Inc (http://www.xamarin.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; +using MonoDevelop.Projects; +using System.Threading.Tasks; + +namespace MonoDeveloper +{ + public class MonoMakefileSolutionExtension: SolutionExtension + { + protected override Task Save (MonoDevelop.Core.ProgressMonitor monitor) + { + // Saving is not supported, don't do anything. + return Task.FromResult (0); + } + } +} + diff --git a/main/src/addins/MonoDeveloperExtensions/MonoSolutionItemHandler.cs b/main/src/addins/MonoDeveloperExtensions/MonoSolutionItemHandler.cs deleted file mode 100644 index aef9538385..0000000000 --- a/main/src/addins/MonoDeveloperExtensions/MonoSolutionItemHandler.cs +++ /dev/null @@ -1,348 +0,0 @@ -// MonoSolutionItemHandler.cs -// -// Author: -// Lluis Sanchez Gual <lluis@novell.com> -// -// Copyright (c) 2008 Novell, Inc (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// -// - -using System; -using System.CodeDom.Compiler; -using System.Collections; -using System.IO; -using System.Text.RegularExpressions; -using MonoDevelop.Core; -using MonoDevelop.Core.Execution; -using MonoDevelop.Core.ProgressMonitoring; -using MonoDevelop.Ide; -using MonoDevelop.Projects; -using MonoDevelop.Projects.Extensions; -using System.Threading.Tasks; - -namespace MonoDeveloper -{ - public class MonoSolutionItemHandler - { - DotNetProject project; - string outFile; - ArrayList refNames = new ArrayList (); - bool loading; - string testFileBase; - object unitTest; - - public MonoSolutionItemHandler (DotNetProject project) - { - this.project = project; - project.FileAddedToProject += OnFileAddedToProject; - project.FileRemovedFromProject += OnFileRemovedFromProject; - project.FileRenamedInProject += OnFileRenamedInProject; - } - - public string SourcesFile { - get { return outFile + ".sources"; } - } - - public bool SyncFileName { - get { return false; } - } - - public string ItemId { - get { - if (project.ParentSolution != null) - return project.ParentSolution.GetRelativeChildPath (project.FileName); - else - return project.Name; - } - } - - public Task Save (MonoDevelop.Core.ProgressMonitor monitor) - { - return Task.FromResult (0); - } - - internal void Read (MonoMakefile mkfile) - { - loading = true; - - string basePath = Path.GetDirectoryName (mkfile.FileName); - string aname; - - string targetAssembly = mkfile.GetVariable ("LIBRARY"); - if (targetAssembly == null) { - targetAssembly = mkfile.GetVariable ("PROGRAM"); - if (Path.GetDirectoryName (targetAssembly) == "") - targetAssembly = Path.Combine (basePath, targetAssembly); - aname = Path.GetFileName (targetAssembly); - } else { - aname = Path.GetFileName (targetAssembly); - string targetName = mkfile.GetVariable ("LIBRARY_NAME"); - if (targetName != null) targetAssembly = targetName; - targetAssembly = "$(topdir)/class/lib/$(PROFILE)/" + targetAssembly; - } - - outFile = Path.Combine (basePath, aname); - project.FileName = mkfile.FileName; - - ArrayList checkedFolders = new ArrayList (); - - // Parse projects - string sources = outFile + ".sources"; - StreamReader sr = new StreamReader (sources); - string line; - while ((line = sr.ReadLine ()) != null) { - line = line.Trim (' ','\t'); - if (line != "") { - string fname = Path.Combine (basePath, line); - project.Files.Add (new ProjectFile (fname)); - - string dir = Path.GetDirectoryName (fname); - if (!checkedFolders.Contains (dir)) { - checkedFolders.Add (dir); - fname = Path.Combine (dir, "ChangeLog"); - if (File.Exists (fname)) - project.Files.Add (new ProjectFile (fname, BuildAction.Content)); - } - } - } - - sr.Close (); - - // Project references - string refs = mkfile.GetVariable ("LIB_MCS_FLAGS"); - if (refs == null || refs == "") refs = mkfile.GetVariable ("LOCAL_MCS_FLAGS"); - - if (refs != null && refs != "") { - Regex var = new Regex(@"(.*?/r:(?<ref>.*?)(( |\t)|$).*?)*"); - Match match = var.Match (refs); - if (match.Success) { - foreach (Capture c in match.Groups["ref"].Captures) - refNames.Add (Path.GetFileNameWithoutExtension (c.Value)); - } - } - - int i = basePath.LastIndexOf ("/mcs/", basePath.Length - 2); - string topdir = basePath.Substring (0, i + 4); - targetAssembly = targetAssembly.Replace ("$(topdir)", topdir); - - if (mkfile.GetVariable ("NO_TEST") != "yes") { - string tname = Path.GetFileNameWithoutExtension (aname) + "_test_"; - testFileBase = Path.Combine (basePath, tname); - } - - foreach (string sconf in MonoMakefileFormat.Configurations) { - DotNetProjectConfiguration conf = new DotNetProjectConfiguration (sconf); - conf.CompilationParameters = project.LanguageBinding.CreateCompilationParameters (null); - conf.OutputDirectory = basePath; - conf.OutputAssembly = Path.GetFileName (targetAssembly); - project.Configurations.Add (conf); - } - - loading = false; - IdeApp.Workspace.SolutionLoaded += CombineOpened; - } - - public void CombineOpened (object sender, SolutionEventArgs args) - { - if (args.Solution == project.ParentSolution) { - foreach (string pref in refNames) { - Project p = project.ParentSolution.FindProjectByName (pref); - if (p != null) project.References.Add (new ProjectReference (p)); - } - } - } - - public Task<BuildResult> RunTarget (MonoDevelop.Core.ProgressMonitor monitor, string target, ConfigurationSelector configuration) - { - if (target == ProjectService.BuildTarget) - target = "all"; - else if (target == ProjectService.CleanTarget) - target = "clean"; - - DotNetProjectConfiguration conf = (DotNetProjectConfiguration) project.GetConfiguration (configuration); - - return Task<BuildResult>.Factory.StartNew (delegate { - using (var output = new StringWriter ()) { - using (var tw = new LogTextWriter ()) { - tw.ChainWriter (output); - tw.ChainWriter (monitor.Log); - - using (ProcessWrapper proc = Runtime.ProcessService.StartProcess ("make", "PROFILE=" + conf.Id + " " + target, conf.OutputDirectory, monitor.Log, tw, null)) - proc.WaitForOutput (); - - tw.UnchainWriter (output); - tw.UnchainWriter (monitor.Log); - - var result = new BuildResult (output.ToString (), 1, 0); - - string[] lines = result.CompilerOutput.Split ('\n'); - foreach (string line in lines) { - var err = CreateErrorFromString (line); - if (err != null) - result.Append (err); - } - - return result; - } - } - }); - } - - private BuildError CreateErrorFromString (string error_string) - { - // When IncludeDebugInformation is true, prevents the debug symbols stats from braeking this. - if (error_string.StartsWith ("WROTE SYMFILE") || - error_string.StartsWith ("make[") || - error_string.StartsWith ("OffsetTable") || - error_string.StartsWith ("Compilation succeeded") || - error_string.StartsWith ("Compilation failed")) - return null; - - return BuildError.FromMSBuildErrorFormat (error_string); - } - - void OnFileAddedToProject (object s, ProjectFileEventArgs args) - { - if (loading) return; - - foreach (ProjectFileEventInfo e in args) { - if (e.ProjectFile.BuildAction != BuildAction.Compile) - continue; - AddSourceFile (e.ProjectFile.Name); - } - } - - void OnFileRemovedFromProject (object s, ProjectFileEventArgs args) - { - if (loading) return; - - foreach (ProjectFileEventInfo e in args) { - if (e.ProjectFile.BuildAction != BuildAction.Compile) - continue; - - RemoveSourceFile (e.ProjectFile.Name); - } - } - - void OnFileRenamedInProject (object s, ProjectFileRenamedEventArgs args) - { - if (loading) return; - - foreach (ProjectFileRenamedEventInfo e in args) { - if (e.ProjectFile.BuildAction != BuildAction.Compile) - continue; - - if (RemoveSourceFile (e.OldName)) - AddSourceFile (e.NewName); - } - } - - void AddSourceFile (string sourceFile) - { - StreamReader sr = null; - StreamWriter sw = null; - - try { - sr = new StreamReader (outFile + ".sources"); - sw = new StreamWriter (outFile + ".sources.new"); - - string newFile = project.GetRelativeChildPath (sourceFile); - if (newFile.StartsWith ("./")) newFile = newFile.Substring (2); - - string line; - while ((line = sr.ReadLine ()) != null) { - string file = line.Trim (' ','\t'); - if (newFile != null && (file == "" || string.Compare (file, newFile) > 0)) { - sw.WriteLine (newFile); - newFile = null; - } - sw.WriteLine (line); - } - if (newFile != null) - sw.WriteLine (newFile); - } finally { - if (sr != null) sr.Close (); - if (sw != null) sw.Close (); - } - File.Delete (outFile + ".sources"); - File.Move (outFile + ".sources.new", outFile + ".sources"); - } - - bool RemoveSourceFile (string sourceFile) - { - StreamReader sr = null; - StreamWriter sw = null; - bool found = false; - - try { - sr = new StreamReader (outFile + ".sources"); - sw = new StreamWriter (outFile + ".sources.new"); - - string oldFile = project.GetRelativeChildPath (sourceFile); - if (oldFile.StartsWith ("./")) oldFile = oldFile.Substring (2); - - string line; - while ((line = sr.ReadLine ()) != null) { - string file = line.Trim (' ','\t'); - if (oldFile != file) - sw.WriteLine (line); - else - found = true; - } - } finally { - if (sr != null) sr.Close (); - if (sw != null) sw.Close (); - } - if (found) { - File.Delete (outFile + ".sources"); - File.Move (outFile + ".sources.new", outFile + ".sources"); - } - return found; - } - - public void Dispose () - { - project.FileAddedToProject -= OnFileAddedToProject; - project.FileRemovedFromProject -= OnFileRemovedFromProject; - project.FileRenamedInProject -= OnFileRenamedInProject; - IdeApp.Workspace.SolutionLoaded -= CombineOpened; - } - - public void OnModified (string hint) - { - } - - public string GetTestFileBase () - { - return testFileBase; - } - - public object UnitTest { - get { return unitTest; } - set { unitTest = value; } - } - - public object GetService (Type t) - { - return null; - } - } -} diff --git a/main/src/addins/MonoDeveloperExtensions/NUnit/MonoTestProvider.cs b/main/src/addins/MonoDeveloperExtensions/NUnit/MonoTestProvider.cs index 8d38969172..f35069200e 100644 --- a/main/src/addins/MonoDeveloperExtensions/NUnit/MonoTestProvider.cs +++ b/main/src/addins/MonoDeveloperExtensions/NUnit/MonoTestProvider.cs @@ -38,13 +38,14 @@ namespace MonoDeveloper { public UnitTest CreateUnitTest (WorkspaceObject entry) { - if (entry is MakefileProject) { - var project = (MakefileProject) entry; - if (project.UnitTest != null) - return (UnitTest) project.UnitTest; - string testFileBase = project.GetTestFileBase (); + var ext = entry.GetService<MonoMakefileProjectExtension> (); + if (ext != null) { + var project = (DotNetProject) entry; + if (ext.UnitTest != null) + return (UnitTest) ext.UnitTest; + string testFileBase = ext.GetTestFileBase (); UnitTest testSuite = new MonoTestSuite (project, project.Name, testFileBase); - project.UnitTest = testSuite; + ext.UnitTest = testSuite; return testSuite; } return null; @@ -60,7 +61,7 @@ namespace MonoDeveloper { string basePath; - public MonoTestSuite (MakefileProject p, string name, string basePath): base (name, p) + public MonoTestSuite (DotNetProject p, string name, string basePath): base (name, p) { this.basePath = basePath; } |