[Monodevelop-patches-list] r2208 - in trunk/MonoDevelop/Extras: . MonoDeveloperExtensions

commit-watcher at mono-cvs.ximian.com commit-watcher at mono-cvs.ximian.com
Mon Jan 31 15:27:22 EST 2005


Author: lluis
Date: 2005-01-31 15:27:22 -0500 (Mon, 31 Jan 2005)
New Revision: 2208

Added:
   trunk/MonoDevelop/Extras/MonoDeveloperExtensions/
   trunk/MonoDevelop/Extras/MonoDeveloperExtensions/AssemblyInfo.cs
   trunk/MonoDevelop/Extras/MonoDeveloperExtensions/Commands.cs
   trunk/MonoDevelop/Extras/MonoDeveloperExtensions/Makefile.am
   trunk/MonoDevelop/Extras/MonoDeveloperExtensions/MonoCombine.cs
   trunk/MonoDevelop/Extras/MonoDeveloperExtensions/MonoDeveloperExtensions.addin.xml
   trunk/MonoDevelop/Extras/MonoDeveloperExtensions/MonoMakefile.cs
   trunk/MonoDevelop/Extras/MonoDeveloperExtensions/MonoMakefileFormat.cs
   trunk/MonoDevelop/Extras/MonoDeveloperExtensions/MonoProject.cs
   trunk/MonoDevelop/Extras/MonoDeveloperExtensions/MonoProjectConfiguration.cs
Log:
New addin that provides an IFileFormat that can parse Mono Makefiles.


Added: trunk/MonoDevelop/Extras/MonoDeveloperExtensions/AssemblyInfo.cs
===================================================================
--- trunk/MonoDevelop/Extras/MonoDeveloperExtensions/AssemblyInfo.cs	2005-01-31 20:21:16 UTC (rev 2207)
+++ trunk/MonoDevelop/Extras/MonoDeveloperExtensions/AssemblyInfo.cs	2005-01-31 20:27:22 UTC (rev 2208)
@@ -0,0 +1,60 @@
+//
+// AssemblyInfo.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.Reflection;
+using System.Runtime.CompilerServices;
+
+// Information about this assembly is defined by the following
+// attributes.
+//
+// change them to the information which is associated with the assembly
+// you compile.
+
+[assembly: AssemblyTitle("MonoDeveloperExtensions")]
+[assembly: AssemblyDescription("MonoDeveloperExtensions addin for MonoDevelop")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("MonoDevelop")]
+[assembly: AssemblyProduct("MonoDeveloperExtensions")]
+[assembly: AssemblyCopyright("Copyright (C) 2005 Novell, Inc")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// The assembly version has following format :
+//
+// Major.Minor.Build.Revision
+//
+// You can specify all values by your own or you can build default build and revision
+// numbers with the '*' character (the default):
+
+[assembly: AssemblyVersion("0.0.0.*")]
+
+// The following attributes specify the key for the sign of your assembly. See the
+// .NET Framework documentation for more information about signing.
+// This is not required, if you don't want signing let these attributes like they're.
+[assembly: AssemblyDelaySign(false)]
+[assembly: AssemblyKeyFile("")]

Added: trunk/MonoDevelop/Extras/MonoDeveloperExtensions/Commands.cs
===================================================================
--- trunk/MonoDevelop/Extras/MonoDeveloperExtensions/Commands.cs	2005-01-31 20:21:16 UTC (rev 2207)
+++ trunk/MonoDevelop/Extras/MonoDeveloperExtensions/Commands.cs	2005-01-31 20:27:22 UTC (rev 2208)
@@ -0,0 +1,54 @@
+//
+// Commands.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 MonoDevelop.Internal.Project;
+using MonoDevelop.Services;
+using MonoDevelop.Core.AddIns.Codons;
+
+namespace MonoDeveloper
+{	
+	class InstallCommand: AbstractMenuCommand
+	{
+		public override void Run()
+		{
+			MonoProject p = Runtime.ProjectService.CurrentSelectedProject as MonoProject;
+			if (p != null) {
+				Runtime.DispatchService.BackgroundDispatch (new StatefulMessageHandler (Install), p);
+			}
+		}
+		
+		void Install (object prj)
+		{
+			MonoProject p = prj as MonoProject;
+			using (IProgressMonitor monitor = Runtime.TaskService.GetBuildProgressMonitor ()) {
+				p.Install (monitor);
+			}
+		}
+	}
+}

Added: trunk/MonoDevelop/Extras/MonoDeveloperExtensions/Makefile.am
===================================================================
--- trunk/MonoDevelop/Extras/MonoDeveloperExtensions/Makefile.am	2005-01-31 20:21:16 UTC (rev 2207)
+++ trunk/MonoDevelop/Extras/MonoDeveloperExtensions/Makefile.am	2005-01-31 20:27:22 UTC (rev 2208)
@@ -0,0 +1,45 @@
+FILES = \
+AssemblyInfo.cs \
+MonoCombine.cs \
+MonoMakefile.cs \
+MonoMakefileFormat.cs \
+MonoProject.cs \
+Commands.cs \
+MonoProjectConfiguration.cs
+
+build_sources = $(addprefix $(srcdir)/, $(FILES))
+
+REFS = /r:$(top_builddir)/build/bin/MonoDevelop.Core.dll \
+       /r:$(top_builddir)/build/bin/MonoDevelop.Base.dll \
+       $(GTK_SHARP_LIBS) \
+       $(GLADE_SHARP_LIBS) \
+       $(GCONF_SHARP_LIBS) \
+       $(GTKSOURCEVIEW_SHARP_LIBS)
+
+ADDIN = MonoDeveloperExtensions.addin.xml
+
+ADDIN_BUILD = $(top_builddir)/build/AddIns/MonoDeveloperExtensions
+
+DLL = MonoDeveloperExtensions.dll
+
+DLL_BUILD = $(top_builddir)/build/AddIns/MonoDeveloperExtensions
+
+all: $(DLL_BUILD)/$(DLL) $(ADDIN_BUILD)/$(ADDIN)
+
+$(ADDIN_BUILD)/$(ADDIN): $(srcdir)/$(ADDIN)
+	mkdir -p $(ADDIN_BUILD)
+	cp $(srcdir)/$(ADDIN) $(ADDIN_BUILD)/$(ADDIN)
+
+$(DLL): $(build_sources) $(srcdir)/$(GLADEFILE)
+	mcs -target:library -out:$(DLL) $(build_sources) $(REFS)
+
+$(DLL_BUILD)/$(DLL): $(srcdir)/$(DLL)
+	mkdir -p $(DLL_BUILD)
+	cp $(srcdir)/$(DLL) $(DLL_BUILD)/$(DLL)
+
+CLEANFILES=$(DLL) $(DLL_BUILD)/$(DLL) $(ADDIN_BUILD)/$(ADDIN)
+
+EXTRADIST=$(FILES)
+
+MonoDeveloperExtensionsdir = $(libdir)/monodevelop/AddIns/MonoDeveloperExtensions
+MonoDeveloperExtensions_DATA = $(DLL_BUILD)/$(DLL) $(ADDIN_BUILD)/$(ADDIN)

Added: trunk/MonoDevelop/Extras/MonoDeveloperExtensions/MonoCombine.cs
===================================================================
--- trunk/MonoDevelop/Extras/MonoDeveloperExtensions/MonoCombine.cs	2005-01-31 20:21:16 UTC (rev 2207)
+++ trunk/MonoDevelop/Extras/MonoDeveloperExtensions/MonoCombine.cs	2005-01-31 20:27:22 UTC (rev 2208)
@@ -0,0 +1,40 @@
+//
+// MonoCombine.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 MonoDevelop.Internal.Project;
+
+namespace MonoDeveloper
+{	
+	class MonoCombine: Combine
+	{
+		public override void GenerateMakefiles (Combine parentCombine)
+		{
+		}
+	}
+}

Added: trunk/MonoDevelop/Extras/MonoDeveloperExtensions/MonoDeveloperExtensions.addin.xml
===================================================================
--- trunk/MonoDevelop/Extras/MonoDeveloperExtensions/MonoDeveloperExtensions.addin.xml	2005-01-31 20:21:16 UTC (rev 2207)
+++ trunk/MonoDevelop/Extras/MonoDeveloperExtensions/MonoDeveloperExtensions.addin.xml	2005-01-31 20:27:22 UTC (rev 2208)
@@ -0,0 +1,35 @@
+<AddIn name        = "MonoDeveloperExtensions"
+       author      = "Lluis Sanchez Gual"
+       copyright   = "(c) 2005 Novell, Inc."
+       url         = "http://www.monodevelop.com"
+       description = "MonoDevelop extensions for Mono developers"
+       version     = "0.0.1">
+    
+    <Runtime>
+        <Import assembly="MonoDeveloperExtensions.dll"/>
+    </Runtime>
+
+	<Extension path = "/SharpDevelop/Workbench/ProjectFileFormats">
+		<FileFormat id = "MonoMakefile"
+						class = "MonoDeveloper.MonoMakefileFormat" />
+	</Extension>
+	
+  <Extension path = "/SharpDevelop/Workbench/ProjectOptions/ConfigurationProperties">
+    <Conditional activeproject = "MonoMakefile">
+		<DialogPanel id = "MonoMakefileOptionsPanel"
+					 _label = "Output"
+					 class = "MonoDevelop.Gui.Dialogs.OptionPanels.OutputOptionsPanel"/>
+    </Conditional>
+  </Extension>
+  
+	<Extension path = "/SharpDevelop/Views/ProjectBrowser/ContextMenu/ProjectBrowserNode">
+		<Conditional activeproject="MonoMakefile" action="Exclude">
+			<MenuItem id = "Install"
+					  insertafter = "RebuildProject"
+					  insertbefore = "BuildGroupSeparator"
+					  _label = "Install" 
+					  class = "MonoDeveloper.InstallCommand"/>
+		</Conditional>
+	</Extension>
+</AddIn>
+

Added: trunk/MonoDevelop/Extras/MonoDeveloperExtensions/MonoMakefile.cs
===================================================================
--- trunk/MonoDevelop/Extras/MonoDeveloperExtensions/MonoMakefile.cs	2005-01-31 20:21:16 UTC (rev 2207)
+++ trunk/MonoDevelop/Extras/MonoDeveloperExtensions/MonoMakefile.cs	2005-01-31 20:27:22 UTC (rev 2208)
@@ -0,0 +1,82 @@
+//
+// MonoMakefile.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.IO;
+using MonoDevelop.Services;
+using System.Text.RegularExpressions;
+using MonoDevelop.Internal.Project;
+
+namespace MonoDeveloper
+{
+	class MonoMakefile
+	{
+		string content;
+		string multilineMatch = @"(((?<content>.*)(?<!\\)\n)|((?<content>.*?)\\\n(\t(?<content>.*?)\\\n)*\t(?<content>.*?)(?<!\\)\n))";
+		string fileName;
+		
+		public MonoMakefile (string file)
+		{
+			this.fileName = file;
+			StreamReader sr = new StreamReader (file);
+			content = sr.ReadToEnd ();
+			sr.Close ();
+		}
+		
+		public string FileName {
+			get { return fileName; }
+		}
+		
+		public string Content {
+			get { return content; }
+		}
+		
+		public string GetVariable (string var)
+		{
+			Regex varExp = new Regex(@"[.|\n]*^" + var + @"(?<sep>\s*:?=\s*)" + multilineMatch, RegexOptions.Multiline);
+			return GetValue (var, varExp);
+		}
+		
+		public string GetTarget (string var)
+		{
+			Regex targetExp = new Regex(@"[.|\n]*^" + var + @"(?<sep>\s*:\s*)" + multilineMatch + @"\t" + multilineMatch, RegexOptions.Multiline);
+			return GetValue (var, targetExp);
+		}
+		
+		string GetValue (string var, Regex exp)
+		{
+			Match match = exp.Match (content);
+			if (!match.Success) return null;
+			string value = "";
+			foreach (Capture c in match.Groups["content"].Captures)
+				value += c.Value;
+			return value;
+		}
+	}
+}

Added: trunk/MonoDevelop/Extras/MonoDeveloperExtensions/MonoMakefileFormat.cs
===================================================================
--- trunk/MonoDevelop/Extras/MonoDeveloperExtensions/MonoMakefileFormat.cs	2005-01-31 20:21:16 UTC (rev 2207)
+++ trunk/MonoDevelop/Extras/MonoDeveloperExtensions/MonoMakefileFormat.cs	2005-01-31 20:27:22 UTC (rev 2208)
@@ -0,0 +1,113 @@
+//
+// 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.IO;
+using MonoDevelop.Services;
+using System.Text.RegularExpressions;
+using MonoDevelop.Internal.Project;
+
+namespace MonoDeveloper
+{
+	public class MonoMakefileFormat: IFileFormat
+	{
+		public string Name {
+			get { return "Mono Makefile"; }
+		}
+		
+		public string GetValidFormatName (string fileName)
+		{
+			return "Makefile";
+		}
+		
+		public bool CanReadFile (string file)
+		{
+			if (Path.GetFileName (file) != "Makefile") return false;
+			MonoMakefile mkfile = new MonoMakefile (file);
+			if (mkfile.Content.IndexOf ("build/rules.make") == -1) return false;
+			
+			if (mkfile.GetVariable ("LIBRARY") != null) return true;
+			if (mkfile.GetVariable ("PROGRAM") != null) return true;
+			string subdirs = mkfile.GetVariable ("SUBDIRS");
+			if (subdirs != null && subdirs.Trim (' ','\t') != "")
+				return true;
+			
+			return false;
+		}
+		
+		public bool CanWriteFile (object obj)
+		{
+			return (obj is Project) || (obj is Combine);
+		}
+		
+		public void WriteFile (string file, object node, IProgressMonitor monitor)
+		{
+		}
+		
+		public object ReadFile (string fileName, IProgressMonitor monitor)
+		{
+			string basePath = Path.GetDirectoryName (fileName);
+			MonoMakefile mkfile = new MonoMakefile (fileName);
+			string aname = mkfile.GetVariable ("LIBRARY");
+			if (aname == null) aname = mkfile.GetVariable ("PROGRAM");
+			
+			if (aname != null) {
+				// It is a project
+				monitor.BeginTask ("Loading '" + fileName + "'", 0);
+				MonoProject project = new MonoProject (mkfile);
+				monitor.EndTask ();
+				return project;
+			} else {
+				string subdirs = mkfile.GetVariable ("SUBDIRS");
+				if (subdirs != null && (subdirs = subdirs.Trim (' ','\t')) != "")
+				{
+					Combine combine = new MonoCombine ();
+					combine.FileName = fileName;
+					combine.Name = Path.GetFileName (basePath);
+					subdirs = subdirs.Replace ('\t',' ');
+					string[] dirs = subdirs.Split (' ');
+					
+					monitor.BeginTask ("Loading '" + fileName + "'", dirs.Length);
+					foreach (string dir in dirs) {
+						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))
+							combine.AddEntry (mfile, monitor);
+					}
+					monitor.EndTask ();
+					return combine;
+				}
+			}
+			return null;
+		}
+	}
+}

Added: trunk/MonoDevelop/Extras/MonoDeveloperExtensions/MonoProject.cs
===================================================================
--- trunk/MonoDevelop/Extras/MonoDeveloperExtensions/MonoProject.cs	2005-01-31 20:21:16 UTC (rev 2207)
+++ trunk/MonoDevelop/Extras/MonoDeveloperExtensions/MonoProject.cs	2005-01-31 20:27:22 UTC (rev 2208)
@@ -0,0 +1,291 @@
+//
+// MonoProject.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.IO;
+using MonoDevelop.Services;
+using System.Text.RegularExpressions;
+using MonoDevelop.Internal.Project;
+using System.CodeDom.Compiler;
+
+namespace MonoDeveloper
+{
+	public class MonoProject: Project
+	{
+		string outFile;
+		ArrayList refNames = new ArrayList ();
+		bool loading;
+		
+		public override string ProjectType {
+			get { return "MonoMakefile"; }
+		}
+		
+		internal MonoProject (MonoMakefile mkfile)
+		{
+			Read (mkfile);
+		}
+		
+		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;
+			}
+			
+			Name = Path.GetFileNameWithoutExtension (aname);
+			outFile = Path.Combine (basePath, aname);
+			FileName = mkfile.FileName;
+			
+			// Parse projects
+			string sources = outFile + ".sources";
+			StreamReader sr = new StreamReader (sources);
+			string line;
+			while ((line = sr.ReadLine ()) != null) {
+				line = line.Trim (' ','\t');
+				if (line != "") ProjectFiles.Add (new ProjectFile (Path.Combine (basePath, line)));
+			}
+			
+			sr.Close ();
+			
+			ArrayList files = new ArrayList ();
+			FindFiles (basePath, "ChangeLog", files);
+			foreach (string file in files)
+				ProjectFiles.Add (new ProjectFile (file, BuildAction.Exclude));
+			
+			// 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);
+			
+			MonoProjectConfiguration conf = new MonoProjectConfiguration (".NET 1.1", "default");
+			conf.OutputDirectory = basePath;
+			conf.AssemblyPathTemplate = targetAssembly;
+			Configurations.Add (conf);
+			
+			conf = new MonoProjectConfiguration (".NET 2.0", "net_2_0");
+			conf.OutputDirectory = basePath;
+			conf.AssemblyPathTemplate = targetAssembly;
+			Configurations.Add (conf);
+			
+			Console.WriteLine ("{0} {1}", aname, GetOutputFileName ());
+			loading = false;
+			Runtime.ProjectService.CombineOpened += new CombineEventHandler (CombineOpened);
+		}
+		
+		void FindFiles (string path, string name, ArrayList files)
+		{
+			files.AddRange (Directory.GetFiles (path, name));
+			foreach (string sd in Directory.GetDirectories (path))
+				FindFiles (sd, name, files);
+		}
+		
+		static Regex regexError = new Regex (@"^(\s*(?<file>.*)\((?<line>\d*)(,(?<column>\d*))?\)\s+)*(?<level>\w+)\s*(?<number>.*):\s(?<message>.*)",
+				RegexOptions.Compiled | RegexOptions.ExplicitCapture);
+				
+		protected override ICompilerResult DoBuild (IProgressMonitor monitor)
+		{
+			MonoProjectConfiguration conf = (MonoProjectConfiguration) ActiveConfiguration;
+			
+			StringWriter output = new StringWriter ();
+			LogTextWriter tw = new LogTextWriter ();
+			tw.ChainWriter (output);
+			tw.ChainWriter (monitor.Log);
+			
+			ProcessWrapper proc = Runtime.ProcessService.StartProcess ("make", "PROFILE=" + conf.Profile, conf.OutputDirectory, tw, tw, null);
+			proc.WaitForOutput ();
+			
+			CompilerResults cr = new CompilerResults (null);			
+			string[] lines = output.ToString().Split ('\n');
+			foreach (string line in lines) {
+				CompilerError err = CreateErrorFromString (line);
+				if (err != null) cr.Errors.Add (err);
+			}
+			
+			return new DefaultCompilerResult (cr, output.ToString());
+		}
+		
+		private CompilerError 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;
+
+			CompilerError error = new CompilerError();
+
+			Match match=regexError.Match(error_string);
+			if (!match.Success) return null;
+			if (String.Empty != match.Result("${file}"))
+				error.FileName = Path.Combine (BaseDirectory, match.Result("${file}"));
+			if (String.Empty != match.Result("${line}"))
+				error.Line=Int32.Parse(match.Result("${line}"));
+			if (String.Empty != match.Result("${column}"))
+				error.Column = Int32.Parse(match.Result("${column}"));
+			if (match.Result("${level}") == "warning")
+				error.IsWarning = true;
+			error.ErrorNumber = match.Result ("${number}");
+			error.ErrorText = match.Result ("${message}");
+			return error;
+		}
+		
+		public void Install (IProgressMonitor monitor)
+		{
+			MonoProjectConfiguration conf = (MonoProjectConfiguration) ActiveConfiguration;
+			monitor.BeginTask ("Installing: " + Name + " - " + conf.Name, 1);
+			ProcessWrapper proc = Runtime.ProcessService.StartProcess ("make", "install PROFILE=" + conf.Profile, conf.OutputDirectory, monitor.Log, monitor.Log, null);
+			proc.WaitForOutput ();
+			monitor.EndTask ();
+		}
+		
+		public override void Debug (IProgressMonitor monitor)
+		{
+		}
+		
+		public override string GetOutputFileName ()
+		{
+			MonoProjectConfiguration conf = (MonoProjectConfiguration) ActiveConfiguration;
+			return conf.GetAssemblyPath ();
+		}
+		
+		public void CombineOpened (object sender, CombineEventArgs args)
+		{
+			foreach (string pref in refNames) {
+				Project p = Runtime.ProjectService.GetProject (pref);
+				if (p != null) ProjectReferences.Add (new ProjectReference (p));
+			}
+		}
+		
+		protected override void OnFileAddedToProject (ProjectFileEventArgs e)
+		{
+			base.OnFileAddedToProject (e);
+			if (loading) return;
+			
+			if (e.ProjectFile.BuildAction != BuildAction.Compile)
+				return;
+
+			StreamReader sr = null;
+			StreamWriter sw = null;
+			
+			try {
+				sr = new StreamReader (outFile + ".sources");
+				sw = new StreamWriter (outFile + ".sources.new");
+
+				string newFile = GetRelativeChildPath (e.ProjectFile.Name);
+				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");
+		}
+		
+		protected override void OnFileRemovedFromProject (ProjectFileEventArgs e)
+		{
+			base.OnFileRemovedFromProject (e);
+			if (loading) return;
+			
+			if (e.ProjectFile.BuildAction != BuildAction.Compile)
+				return;
+
+			StreamReader sr = null;
+			StreamWriter sw = null;
+			
+			try {
+				sr = new StreamReader (outFile + ".sources");
+				sw = new StreamWriter (outFile + ".sources.new");
+
+				string oldFile = GetRelativeChildPath (e.ProjectFile.Name);
+				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);
+				}
+			} finally {
+				if (sr != null) sr.Close ();
+				if (sw != null) sw.Close ();
+			}
+			File.Delete (outFile + ".sources");
+			File.Move (outFile + ".sources.new", outFile + ".sources");
+		}
+		
+		public override void GenerateMakefiles (Combine parentCombine)
+		{
+		}
+		
+		public override void Dispose ()
+		{
+			base.Dispose ();
+			Runtime.ProjectService.CombineOpened -= new CombineEventHandler (CombineOpened);
+		}
+	}
+}

Added: trunk/MonoDevelop/Extras/MonoDeveloperExtensions/MonoProjectConfiguration.cs
===================================================================
--- trunk/MonoDevelop/Extras/MonoDeveloperExtensions/MonoProjectConfiguration.cs	2005-01-31 20:21:16 UTC (rev 2207)
+++ trunk/MonoDevelop/Extras/MonoDeveloperExtensions/MonoProjectConfiguration.cs	2005-01-31 20:27:22 UTC (rev 2208)
@@ -0,0 +1,63 @@
+//
+// MonoProjectConfiguration.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.IO;
+using MonoDevelop.Services;
+using System.Text.RegularExpressions;
+using MonoDevelop.Internal.Project;
+
+namespace MonoDeveloper
+{
+	class MonoProjectConfiguration: AbstractProjectConfiguration
+	{
+		string profile;
+		string assemblyPath;
+		
+		public MonoProjectConfiguration (string name, string profile)
+		{
+			Name = name;
+			this.profile = profile;
+		}
+		
+		public string Profile {
+			get { return profile; }
+		}
+		
+		public string AssemblyPathTemplate {
+			get { return assemblyPath; }
+			set { assemblyPath = value; }
+		}
+		
+		public string GetAssemblyPath ()
+		{
+			return assemblyPath.Replace ("$(PROFILE)", profile);
+		}
+	}
+}




More information about the Monodevelop-patches-list mailing list