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

SourcesZipPackageBuilder.cs « MonoDevelop.Deployment.Targets « MonoDevelop.Deployment « Deployment « addins « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c89a8c6c83c5794d6a629bf87a3fdb5bbd22a5ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174

using System;
using System.Collections.Generic;
using System.IO;
using ICSharpCode.SharpZipLib.Zip;
using MonoDevelop.Core;
using MonoDevelop.Core.ProgressMonitoring;
using MonoDevelop.Projects;
using MonoDevelop.Core.Serialization;
using MonoDevelop.Projects.MSBuild;

namespace MonoDevelop.Deployment.Targets
{
	public class SourcesZipPackageBuilder: PackageBuilder
	{
		[ProjectPathItemProperty]
		string targetFile;

		[ItemProperty]
		string format;
		
		MSBuildFileFormat fileFormat;
		
		public override string Description {
			get { return "Archive of Sources"; }
		}
		
		public override bool CanBuild (SolutionFolderItem entry)
		{
			return entry is SolutionFolder || entry is SolutionItem;
		}

		
		public MSBuildFileFormat FileFormat {
			get {
				if (fileFormat == null) {
					if (string.IsNullOrEmpty (format))
						return null;
					foreach (var f in MSBuildFileFormat.GetSupportedFormats ()) {
						if (f.GetType ().FullName == format) {
							fileFormat = f;
							break;
						}
					}
				}
				return fileFormat; 
			}
			set {
				fileFormat = value; 
				if (fileFormat == null)
					format = null;
				else
					format = fileFormat.GetType().FullName;
			}
		}
		
		public string TargetFile {
			get { return targetFile != null ? targetFile : string.Empty; }
			set { targetFile = value; }
		}
		
		protected override bool OnBuild (ProgressMonitor monitor, DeployContext ctx)
		{
			string sourceFile;
			SolutionFolderItem entry = RootSolutionItem;
			if (entry is SolutionFolder)
				sourceFile = entry.ParentSolution.FileName;
			else
				sourceFile = ((SolutionItem)entry).FileName;
			
			AggregatedProgressMonitor mon = new AggregatedProgressMonitor ();
			mon.AddFollowerMonitor (monitor, MonitorAction.WriteLog|MonitorAction.ReportError|MonitorAction.ReportWarning|MonitorAction.ReportSuccess);
			
			string tmpFolder = FileService.CreateTempDirectory ();
			
			try {
				string tf = Path.GetFileNameWithoutExtension (targetFile);
				if (tf.EndsWith (".tar")) tf = Path.GetFileNameWithoutExtension (tf);
				
				string folder = FileService.GetFullPath (Path.Combine (tmpFolder, tf));
				Directory.CreateDirectory (folder);
				
				// Export the project
				
				SolutionFolderItem[] ents = GetChildEntries ();
				string[] epaths = new string [ents.Length];
				for (int n=0; n<ents.Length; n++)
					epaths [n] = ents [n].ItemId;
				
				var r = Services.ProjectService.Export (mon, sourceFile, epaths, folder, FileFormat).Result;
				if (string.IsNullOrEmpty (r))
					return false;
				
				// Create the archive
				string td = Path.GetDirectoryName (targetFile);
				if (!Directory.Exists (td))
					Directory.CreateDirectory (td);
				DeployService.CreateArchive (mon, tmpFolder, targetFile);
			}
			finally {
				Directory.Delete (tmpFolder, true);
			}
			monitor.Log.WriteLine (GettextCatalog.GetString ("Created file: {0}", targetFile));
			return true;
		}
		
		public override void InitializeSettings (SolutionFolderItem entry)
		{
			targetFile = Path.Combine (entry.BaseDirectory, entry.Name) + ".tar.gz";
			if (entry.ParentSolution != null)
				fileFormat = entry.ParentSolution.FileFormat;
		}

		
		public override string Validate ()
		{
			if (string.IsNullOrEmpty (TargetFile))
				return GettextCatalog.GetString ("Target file name not provided.");
			if (fileFormat == null)
				return GettextCatalog.GetString ("File format not provided.");
			return null;
		}
		
		public override void CopyFrom (PackageBuilder other)
		{
			base.CopyFrom (other);
			SourcesZipPackageBuilder builder = (SourcesZipPackageBuilder) other;
			targetFile = builder.targetFile;
			format = builder.format;
			fileFormat = builder.fileFormat;
		}
		
		public override DeployContext CreateDeployContext ()
		{
			return null;
		}

		public override string DefaultName {
			get {
				if (FileFormat != null)
					return GettextCatalog.GetString ("MSBuild Sources");
				else
					return base.DefaultName;
			}
		}
		
		public override PackageBuilder[] CreateDefaultBuilders ()
		{
			List<PackageBuilder> list = new List<PackageBuilder> ();

			IMSBuildFileObject root = RootSolutionItem is SolutionItem ? (IMSBuildFileObject)RootSolutionItem : (IMSBuildFileObject) RootSolutionItem.ParentSolution;
			foreach (MSBuildFileFormat format in MSBuildFileFormat.GetSupportedFormats (root)) {
				SourcesZipPackageBuilder pb = (SourcesZipPackageBuilder) Clone ();
				pb.FileFormat = format;
				
				// The suffix for the archive will be the extension of the file format.
				// If there is no extension, use the whole file name.
				string fname = format.GetValidFormatName (RootSolutionItem, RootSolutionItem.ParentSolution.FileName);
				string suffix = Path.GetExtension (fname);
				if (suffix.Length > 0)
					suffix = suffix.Substring (1).ToLower (); // Remove the initial dot
				else
					suffix = Path.GetFileNameWithoutExtension (suffix).ToLower ();
				
				// Change the name in the target file
				string ext = DeployService.GetArchiveExtension (pb.TargetFile);
				string fn = TargetFile.Substring (0, TargetFile.Length - ext.Length);
				pb.TargetFile = fn + "-" + suffix + ext;
				list.Add (pb);
			}
			return list.ToArray ();
		}
	}
}