public ExportSolutionDialog (IMSBuildFileObject item, MSBuildFileFormat selectedFormat)
		{
			this.Build();
			
			labelNewFormat.Text = GetFormatText (item.FileFormat);
			
			formats = MSBuildFileFormat.GetSupportedFormats (item).ToArray ();
			foreach (var format in formats) {
				comboFormat.AppendText (GetFormatText (format));
			}

			int sel = Array.IndexOf (formats, selectedFormat);
			if (sel == -1) sel = 0;
			comboFormat.Active = sel;
			
			if (formats.Length < 2) {
				table.Remove (newFormatLabel);
				newFormatLabel.Destroy ();
				newFormatLabel = null;
				table.Remove (comboFormat);
				comboFormat.Destroy ();
				comboFormat = null;
			}
			
			//auto height
			folderEntry.WidthRequest = 380;
			Resize (1, 1);
			
			folderEntry.Path = item.ItemDirectory;
			UpdateControls ();
		}
		public bool CanReadFile (string file, MSBuildFileFormat format)
		{
			if (String.Compare (Path.GetExtension (file), ".sln", StringComparison.OrdinalIgnoreCase) == 0) {
				string version = SlnFile.GetFileVersion (file);
				return format.SupportsSlnVersion (version);
			}
			return false;
		}
		public override Task<SolutionItem> LoadSolutionItem (ProgressMonitor monitor, SolutionLoadContext ctx, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid)
		{
			return Task.Run (() => {
				foreach (var f in MSBuildFileFormat.GetSupportedFormats ()) {
					if (f.CanReadFile (fileName, typeof(SolutionItem)))
						return MSBuildProjectService.LoadItem (monitor, fileName, f, typeGuid, itemGuid, ctx);
				}
				throw new NotSupportedException ();
			});
		}
		internal protected override bool OnGetSupportsFormat (MSBuildFileFormat format)
		{
			int version;

			if (!format.Id.StartsWith ("MSBuild", StringComparison.Ordinal))
				return false;

			if (!int.TryParse (format.Id.Substring ("MSBuild".Length), out version))
				return false;

			return version >= 10;
		}
		public SourcesZipEditorWidget (PackageBuilder target, MSBuildFileFormat selectedFormat)
		{
			this.Build();
			this.target = (SourcesZipPackageBuilder) target;
			loading = true;
			
			if (target.RootSolutionItem is SolutionFolder)
				formats = MSBuildFileFormat.GetSupportedFormats (target.Solution).ToArray ();
			else
				formats = MSBuildFileFormat.GetSupportedFormats ((SolutionItem)target.RootSolutionItem).ToArray ();
			
			if (selectedFormat == null) selectedFormat = this.target.FileFormat;
			if (selectedFormat == null)
				selectedFormat = formats [0];
			
			int sel = 0;
			for (int n=0; n<formats.Length; n++) {
				comboFormat.AppendText (formats[n].Name);
				if (formats[n].Name == selectedFormat.Name)
					sel = n;
			}

			comboFormat.Active = sel;
			this.target.FileFormat = formats [sel];
			
			string[] archiveFormats = DeployService.SupportedArchiveFormats;
			int zel = 1;
			for (int n=0; n<archiveFormats.Length; n++) {
				comboZip.AppendText (archiveFormats [n]);
				if (this.target.TargetFile.EndsWith (archiveFormats [n]))
					zel = n;
			}
			
			if (!string.IsNullOrEmpty (this.target.TargetFile)) {
				string ext = archiveFormats [zel];
				folderEntry.Path = System.IO.Path.GetDirectoryName (this.target.TargetFile);
				entryZip.Text = System.IO.Path.GetFileName (this.target.TargetFile.Substring (0, this.target.TargetFile.Length - ext.Length));
				comboZip.Active = zel;
			}
			loading = false;
		}
Exemplo n.º 6
0
 public SlnFileFormat(MSBuildFileFormat format)
 {
     this.format = format;
 }
Exemplo n.º 7
0
		public async Task<string> Export (ProgressMonitor monitor, string rootSourceFile, string[] includedChildIds, string targetPath, MSBuildFileFormat format)
		{
			IMSBuildFileObject obj = null;
			
			if (IsWorkspaceItemFile (rootSourceFile)) {
				obj = (await ReadWorkspaceItem (monitor, rootSourceFile)) as IMSBuildFileObject;
			} else if (IsSolutionItemFile (rootSourceFile)) {
				obj = await ReadSolutionItem (monitor, rootSourceFile);
			}
			if (obj == null)
				throw new InvalidOperationException ("File is not a solution or project.");
			using (obj) {
				return await Export (monitor, obj, includedChildIds, targetPath, format);
			}
		}
Exemplo n.º 8
0
		async Task<string> Export (ProgressMonitor monitor, IMSBuildFileObject obj, string[] includedChildIds, string targetPath, MSBuildFileFormat format)
		{
			string rootSourceFile = obj.FileName;
			string sourcePath = Path.GetFullPath (Path.GetDirectoryName (rootSourceFile));
			targetPath = Path.GetFullPath (targetPath);
			
			if (sourcePath != targetPath) {
				if (!CopyFiles (monitor, obj, obj.GetItemFiles (true), targetPath, true))
					return null;
				
				string newFile = Path.Combine (targetPath, Path.GetFileName (rootSourceFile));
				if (IsWorkspaceItemFile (rootSourceFile))
					obj = (Solution) await ReadWorkspaceItem (monitor, newFile);
				else
					obj = await ReadSolutionItem (monitor, newFile);
				
				using (obj) {
					var oldFiles = obj.GetItemFiles (true).ToList ();
					ExcludeEntries (obj, includedChildIds);
					if (format != null)
						obj.ConvertToFormat (format);
					await obj.SaveAsync (monitor);
					var newFiles = obj.GetItemFiles (true);
					var resolvedTargetPath = new FilePath (targetPath).ResolveLinks ().FullPath;

					foreach (FilePath f in newFiles) {
						if (!f.IsChildPathOf (resolvedTargetPath)) {
							if (obj is Solution)
								monitor.ReportError (GettextCatalog.GetString ("The solution '{0}' is referencing the file '{1}' which is located outside the root solution directory.", obj.Name, f.FileName), null);
							else
								monitor.ReportError (GettextCatalog.GetString ("The project '{0}' is referencing the file '{1}' which is located outside the project directory.", obj.Name, f.FileName), null);
						}
						oldFiles.Remove (f);
					}
	
					// Remove old files
					foreach (FilePath file in oldFiles) {
						if (File.Exists (file)) {
							File.Delete (file);
						
							// Exclude empty directories
							FilePath dir = file.ParentDirectory;
							if (Directory.GetFiles (dir).Length == 0 && Directory.GetDirectories (dir).Length == 0) {
								try {
									Directory.Delete (dir);
								} catch (Exception ex) {
									monitor.ReportError (null, ex);
								}
							}
						}
					}
					return obj.FileName;
				}
			}
			else {
				using (obj) {
					ExcludeEntries (obj, includedChildIds);
					if (format != null)
						obj.ConvertToFormat (format);
					await obj.SaveAsync (monitor);
					return obj.FileName;
				}
			}
		}
Exemplo n.º 9
0
		public Task<SolutionItem> ReadSolutionItem (ProgressMonitor monitor, string file, MSBuildFileFormat format, string typeGuid = null, string itemGuid = null, SolutionLoadContext ctx = null)
		{
			return Runtime.RunInMainThread (async delegate {
				if (!File.Exists (file))
					throw new IOException (GettextCatalog.GetString ("File not found: {0}", file));
				file = Path.GetFullPath (file);
				using (Counters.ReadSolutionItem.BeginTiming ("Read project " + file)) {
					file = GetTargetFile (file);
					var r = GetObjectReaderForFile (file, typeof(SolutionItem));
					if (r == null)
						throw new UnknownSolutionItemTypeException ();
					SolutionItem loadedItem = await r.LoadSolutionItem (monitor, ctx, file, format, typeGuid, itemGuid);
					if (loadedItem != null)
						loadedItem.NeedsReload = false;
					return loadedItem;
				}
			});
		}
Exemplo n.º 10
0
		public Task<string> Export (ProgressMonitor monitor, string rootSourceFile, string targetPath, MSBuildFileFormat format)
		{
			rootSourceFile = GetTargetFile (rootSourceFile);
			return Export (monitor, rootSourceFile, null, targetPath, format);
		}
		static string GetFormatText (MSBuildFileFormat format)
		{
			if (!string.IsNullOrEmpty (format.ProductDescription))
				return string.Format ("{0} ({1})", format.Name, format.ProductDescription);
			return format.Name;
		}
		public override void CopyFrom (PackageBuilder other)
		{
			base.CopyFrom (other);
			SourcesZipPackageBuilder builder = (SourcesZipPackageBuilder) other;
			targetFile = builder.targetFile;
			format = builder.format;
			fileFormat = builder.fileFormat;
		}
Exemplo n.º 13
0
		public SlnFileFormat (MSBuildFileFormat format)
		{
			this.format = format;
		}
		public static async Task TestCreateLoadSaveConsoleProject (MSBuildFileFormat fileFormat)
		{
			Solution sol = CreateConsoleSolution ("TestCreateLoadSaveConsoleProject");
			sol.ConvertToFormat (fileFormat);
			
			await sol.SaveAsync (Util.GetMonitor ());
			string solFile = sol.FileName;
			
			sol = (Solution) await Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solFile);
			CheckConsoleProject (sol);

			// Save over existing file
			await sol.SaveAsync (Util.GetMonitor ());
			sol = (Solution) await Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solFile);
			CheckConsoleProject (sol);
		}
		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));
		}
Exemplo n.º 16
0
 public string GetValidFormatName(object obj, string fileName, MSBuildFileFormat format)
 {
     return(Path.ChangeExtension(fileName, ".sln"));
 }
Exemplo n.º 17
0
		internal protected virtual void OnSetFormat (MSBuildFileFormat value)
		{
			next.OnSetFormat (value);
		}
		public static async Task TestLoadSaveResources (MSBuildFileFormat fileFormat)
		{
			string solFile = Util.GetSampleProject ("resources-tester", "ResourcesTester.sln");
			Solution sol = (Solution) await Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solFile);
			sol.ConvertToFormat (fileFormat);
			ProjectTests.CheckResourcesSolution (sol);
			
			await sol.SaveAsync (Util.GetMonitor ());
			solFile = sol.FileName;
			
			sol = (Solution) await Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solFile);
			ProjectTests.CheckResourcesSolution (sol);
			
			DotNetProject p = (DotNetProject) sol.Items [0];
			string f = Path.Combine (p.BaseDirectory, "Bitmap1.bmp");
			ProjectFile pf = p.Files.GetFile (f);
			pf.ResourceId = "SomeBitmap.bmp";
			await sol.SaveAsync (Util.GetMonitor ());
			
			sol = (Solution) await Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solFile);
			p = (DotNetProject) sol.Items [0];
			f = Path.Combine (p.BaseDirectory, "Bitmap1.bmp");
			pf = p.Files.GetFile (f);
			Assert.AreEqual ("SomeBitmap.bmp", pf.ResourceId);
		}
		public override Task<SolutionItem> LoadSolutionItem (ProgressMonitor monitor, SolutionLoadContext ctx, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid)
		{
			return Task<SolutionItem>.Factory.StartNew (delegate {
				CompiledAssemblyProject p = new CompiledAssemblyProject ();
				p.LoadFrom (fileName);
				return p;
			});
		}
		public virtual Task<SolutionItem> LoadSolutionItem (ProgressMonitor monitor, SolutionLoadContext ctx, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid)
		{
			throw new NotSupportedException ();
		}
		public async void Export (IMSBuildFileObject item, MSBuildFileFormat format)
		{
			ExportSolutionDialog dlg = new ExportSolutionDialog (item, format);
			
			try {
				if (MessageService.RunCustomDialog (dlg) == (int) Gtk.ResponseType.Ok) {
					using (ProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetToolOutputProgressMonitor (true)) {
						await Services.ProjectService.Export (monitor, item.FileName, dlg.TargetFolder, dlg.Format);
					}
				}
			} finally {
				dlg.Destroy ();
				dlg.Dispose ();
			}
		}
		public static async Task TestLoadSaveSolutionFolders (MSBuildFileFormat fileFormat)
		{
			List<string> ids = new List<string> ();
			
			Solution sol = new Solution ();
			sol.ConvertToFormat (fileFormat);
			string dir = Util.CreateTmpDir ("solution-folders-" + fileFormat.Name);
			sol.FileName = Path.Combine (dir, "TestSolutionFolders");
			sol.Name = "TheSolution";
			
			var p1 = Services.ProjectService.CreateDotNetProject ("C#");
			p1.FileName = Path.Combine (dir, "p1");
			sol.RootFolder.Items.Add (p1);
			string idp1 = p1.ItemId;
			Assert.IsFalse (string.IsNullOrEmpty (idp1));
			Assert.IsFalse (ids.Contains (idp1));
			ids.Add (idp1);

			SolutionFolder f1 = new SolutionFolder ();
			f1.Name = "f1";
			sol.RootFolder.Items.Add (f1);
			string idf1 = f1.ItemId;
			Assert.IsFalse (string.IsNullOrEmpty (idf1));
			Assert.IsFalse (ids.Contains (idf1));
			ids.Add (idf1);
			
			var p2 = Services.ProjectService.CreateDotNetProject ("C#");
			p2.FileName = Path.Combine (dir, "p2");
			f1.Items.Add (p2);
			string idp2 = p2.ItemId;
			Assert.IsFalse (string.IsNullOrEmpty (idp2));
			Assert.IsFalse (ids.Contains (idp2));
			ids.Add (idp2);

			SolutionFolder f2 = new SolutionFolder ();
			f2.Name = "f2";
			f1.Items.Add (f2);
			string idf2 = f2.ItemId;
			Assert.IsFalse (string.IsNullOrEmpty (idf2));
			Assert.IsFalse (ids.Contains (idf2));
			ids.Add (idf2);
			
			var p3 = Services.ProjectService.CreateDotNetProject ("C#");
			p3.FileName = Path.Combine (dir, "p3");
			f2.Items.Add (p3);
			string idp3 = p3.ItemId;
			Assert.IsFalse (string.IsNullOrEmpty (idp3));
			Assert.IsFalse (ids.Contains (idp3));
			ids.Add (idp3);
			
			var p4 = Services.ProjectService.CreateDotNetProject ("C#");
			p4.FileName = Path.Combine (dir, "p4");
			f2.Items.Add (p4);
			string idp4 = p4.ItemId;
			Assert.IsFalse (string.IsNullOrEmpty (idp4));
			Assert.IsFalse (ids.Contains (idp4));
			ids.Add (idp4);
			
			await sol.SaveAsync (Util.GetMonitor ());
			
			Solution sol2 = (Solution) await Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), sol.FileName);
			Assert.AreEqual (4, sol2.Items.Count);
			Assert.AreEqual (2, sol2.RootFolder.Items.Count);
			Assert.AreEqual (typeof(CSharpProject), sol2.RootFolder.Items [0].GetType ());
			Assert.AreEqual (typeof(SolutionFolder), sol2.RootFolder.Items [1].GetType ());
			Assert.AreEqual ("p1", sol2.RootFolder.Items [0].Name);
			Assert.AreEqual ("f1", sol2.RootFolder.Items [1].Name);
			Assert.AreEqual (idp1, sol2.RootFolder.Items [0].ItemId, "idp1");
			Assert.AreEqual (idf1, sol2.RootFolder.Items [1].ItemId, "idf1");
			
			f1 = (SolutionFolder) sol2.RootFolder.Items [1];
			Assert.AreEqual (2, f1.Items.Count);
			Assert.AreEqual (typeof(CSharpProject), f1.Items [0].GetType ());
			Assert.AreEqual (typeof(SolutionFolder), f1.Items [1].GetType ());
			Assert.AreEqual ("p2", f1.Items [0].Name);
			Assert.AreEqual ("f2", f1.Items [1].Name);
			Assert.AreEqual (idp2, f1.Items [0].ItemId, "idp2");
			Assert.AreEqual (idf2, f1.Items [1].ItemId, "idf2");
			
			f2 = (SolutionFolder) f1.Items [1];
			Assert.AreEqual (2, f2.Items.Count);
			Assert.AreEqual (typeof(CSharpProject), f2.Items [0].GetType ());
			Assert.AreEqual (typeof(CSharpProject), f2.Items [1].GetType ());
			Assert.AreEqual ("p3", f2.Items [0].Name);
			Assert.AreEqual ("p4", f2.Items [1].Name);
			Assert.AreEqual (idp3, f2.Items [0].ItemId, "idp4");
			Assert.AreEqual (idp4, f2.Items [1].ItemId, "idp4");
		}
		public static async Task CheckGenericItemProject (MSBuildFileFormat format)
		{
			Solution sol = new Solution ();
			sol.ConvertToFormat (format);
			string dir = Util.CreateTmpDir ("generic-item-" + format.Name);
			sol.FileName = Path.Combine (dir, "TestGenericItem");
			sol.Name = "TheItem";

			MonoDevelop.Projects.MSBuild.MSBuildProjectService.RegisterGenericProjectType ("GenericItem", typeof(GenericItem));
			
			GenericItem it = new GenericItem ();
			it.SomeValue = "hi";
			
			sol.RootFolder.Items.Add (it);
			it.FileName = Path.Combine (dir, "TheItem");
			it.Name = "TheItem";
			
			await sol.SaveAsync (Util.GetMonitor ());
			
			Solution sol2 = (Solution) await Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), sol.FileName);
			Assert.AreEqual (1, sol2.Items.Count);
			Assert.IsInstanceOf<GenericItem> (sol2.Items [0]);
			
			it = (GenericItem) sol2.Items [0];
			Assert.AreEqual ("hi", it.SomeValue);
		}
Exemplo n.º 24
0
 public bool CanWriteFile(object obj, MSBuildFileFormat format)
 {
     return(obj is Solution);
 }
		public override void InitializeSettings (SolutionFolderItem entry)
		{
			targetFile = Path.Combine (entry.BaseDirectory, entry.Name) + ".tar.gz";
			if (entry.ParentSolution != null)
				fileFormat = entry.ParentSolution.FileFormat;
		}
Exemplo n.º 26
0
		public string GetValidFormatName (object obj, string fileName, MSBuildFileFormat format)
		{
			return Path.ChangeExtension (fileName, ".sln");
		}
Exemplo n.º 27
0
		static void SetClosestSupportedTargetFramework (MSBuildFileFormat format, DotNetProject project)
		{
			// If the solution format can't write this project due to an unsupported framework, try finding the
			// closest valid framework. DOn't worry about whether it's installed, that's up to the user to correct.
			TargetFramework curFx = project.TargetFramework;
			var candidates = Runtime.SystemAssemblyService.GetTargetFrameworks ()
				.Where (fx =>
					//only frameworks with the same ID, else version comparisons are meaningless
					fx.Id.Identifier == curFx.Id.Identifier &&
					//don't consider profiles, only full frameworks
					fx.Id.Profile == null &&
					//and the project and format must support the framework
					project.SupportsFramework (fx) && format.SupportsFramework (fx))
					//FIXME: string comparisons aren't a valid way to compare profiles, but it works w/released .NET versions
				.OrderBy (fx => fx.Id.Version)
				.ToList ();

			TargetFramework newFx =
				candidates.FirstOrDefault (fx => string.CompareOrdinal (fx.Id.Version, curFx.Id.Version) > 0)
				 ?? candidates.LastOrDefault ();

			if (newFx != null)
				project.TargetFramework = newFx;
		}
Exemplo n.º 28
0
		public bool CanWriteFile (object obj, MSBuildFileFormat format)
		{
			return obj is Solution;
		}
		internal protected virtual void OnSetFormat (MSBuildFileFormat format)
		{
			next.OnSetFormat (format);
		}
		/// <summary>
		/// Loads a solution item
		/// </summary>
		/// <returns>The item.</returns>
		/// <param name="monitor">Progress monitor</param>
		/// <param name="fileName">File path to the item file</param>
		/// <param name="expectedFormat">File format that the project should have</param>
		/// <param name="typeGuid">Optional item type GUID. If not provided, the type is guessed from the file extension.</param>
		/// <param name="itemGuid">Optional item Id</param>
		/// <param name="ctx">Optional solution context</param>
		public async static Task<SolutionItem> LoadItem (ProgressMonitor monitor, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid, SolutionLoadContext ctx)
		{
			SolutionItem item = null;

			// Find an extension node that can handle this item type
			var node = GetItemTypeNodes ().FirstOrDefault (n => n.CanHandleFile (fileName, typeGuid));

			if (node != null) {
				item = await node.CreateSolutionItem (monitor, ctx, fileName);
				if (item == null)
					return null;
			}

			if (item == null) {
				// If it is a known unsupported project, load it as UnknownProject
				item = CreateUnknownSolutionItem (monitor, fileName, typeGuid, typeGuid, ctx);
				if (item == null)
					return null;
			}

			item.EnsureInitialized ();

			item.BeginLoad ();
			ctx.LoadCompleted += delegate {
				item.EndLoad ();
				item.NotifyItemReady ();
			};

			await item.LoadAsync (monitor, fileName, expectedFormat);
			return item;
		}
		internal protected virtual bool OnGetSupportsFormat (MSBuildFileFormat format)
		{
			return next.OnGetSupportsFormat (format);
		}