7
// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining
10
// a copy of this software and associated documentation files (the
11
// "Software"), to deal in the Software without restriction, including
12
// without limitation the rights to use, copy, modify, merge, publish,
13
// distribute, sublicense, and/or sell copies of the Software, and to
14
// permit persons to whom the Software is furnished to do so, subject to
15
// the following conditions:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34
using System.Collections;
35
using System.Collections.Generic;
38
using MonoDevelop.Core;
39
using MonoDevelop.Projects;
40
using MonoDevelop.Projects.Text;
41
using MonoDevelop.Projects.Serialization;
42
using MonoDevelop.Core.Execution;
44
namespace MonoDevelop.Deployment
46
public static class DeployService
48
static List<FileCopyHandler> copiers;
49
static DeployDirectoryInfo[] directoryInfos;
50
static DeployPlatformInfo[] platformInfos;
52
public static string[] SupportedArchiveFormats = new string [] {
53
".tar", ".tar.gz", ".tar.bz2", ".zip"
56
static DeployService ()
58
AddinManager.ExtensionChanged += delegate (object s, ExtensionEventArgs args) {
59
if (args.PathChanged ("/MonoDevelop/DeployService/DeployDirectories"))
60
directoryInfos = null;
64
public static string CurrentPlatform {
65
get { return "Linux"; }
68
public static DeployProperties GetDeployProperties (ProjectFile file)
70
DeployProperties props = (DeployProperties) file.ExtendedProperties [typeof(DeployProperties)];
73
props = new DeployProperties (file);
74
file.ExtendedProperties [typeof(DeployProperties)] = props;
78
public static PackageBuilder[] GetSupportedPackageBuilders (CombineEntry entry)
80
object[] builders = AddinManager.GetExtensionObjects ("/MonoDevelop/DeployService/PackageBuilders", false);
81
ArrayList list = new ArrayList ();
82
foreach (PackageBuilder builder in builders) {
83
if (builder.CanBuild (entry)) {
84
PackageBuilder b = builder.Clone ();
85
b.InitializeSettings (entry);
90
return (PackageBuilder[]) list.ToArray (typeof(PackageBuilder));
93
public static PackageBuilder[] GetPackageBuilders ()
95
return (PackageBuilder[]) AddinManager.GetExtensionObjects ("/MonoDevelop/DeployService/PackageBuilders", typeof(PackageBuilder), false);
98
public static void Install (IProgressMonitor monitor, CombineEntry entry, string prefix, string appName)
100
InstallResolver res = new InstallResolver ();
101
res.Install (monitor, entry, appName, prefix);
104
public static void CreateArchive (IProgressMonitor mon, string folder, string targetFile)
106
string tf = Path.GetFileNameWithoutExtension (targetFile);
107
if (tf.EndsWith (".tar")) tf = Path.GetFileNameWithoutExtension (tf);
109
if (File.Exists (targetFile))
110
File.Delete (targetFile);
112
// Create the zip file
114
if (targetFile.EndsWith (".tar"))
115
pw = Runtime.ProcessService.StartProcess ("tar", "-cvf \"" + targetFile + "\" .", folder, mon.Log, mon.Log, null);
116
else if (targetFile.EndsWith (".tar.gz"))
117
pw = Runtime.ProcessService.StartProcess ("tar", "-cvzf \"" + targetFile + "\" .", folder, mon.Log, mon.Log, null);
118
else if (targetFile.EndsWith (".tar.bz2"))
119
pw = Runtime.ProcessService.StartProcess ("tar", "-cvjf \"" + targetFile + "\" .", folder, mon.Log, mon.Log, null);
120
else if (targetFile.EndsWith (".zip"))
121
pw = Runtime.ProcessService.StartProcess ("zip", "-r \"" + targetFile + "\" .", folder, mon.Log, mon.Log, null);
123
mon.Log.WriteLine ("Unsupported file format: " + Path.GetFileName (targetFile));
129
internal static string GetArchiveExtension (string fileName)
131
if (fileName.EndsWith (".tar.gz"))
133
else if (fileName.EndsWith (".tar.bz2"))
136
return Path.GetExtension (fileName);
139
public static FileCopyHandler[] GetFileCopyHandlers ()
142
return copiers.ToArray ();
145
internal static FileCopyHandler GetFileCopyHandler (string id)
147
foreach (FileCopyHandler handler in GetFileCopyHandlers ())
148
if (handler.Id == id)
154
public static void BuildPackage (IProgressMonitor mon, Package package)
156
BuildPackage (mon, package.PackageBuilder);
159
internal static void BuildPackage (IProgressMonitor mon, PackageBuilder builder)
161
DeployServiceExtension extensionChain = GetExtensionChain ();
162
extensionChain.BuildPackage (mon, builder);
165
public static DeployFileCollection GetDeployFiles (DeployContext ctx, CombineEntry[] entries)
167
DeployFileCollection col = new DeployFileCollection ();
168
foreach (CombineEntry e in entries) {
169
col.AddRange (GetDeployFiles (ctx, e));
174
public static DeployFileCollection GetDeployFiles (DeployContext ctx, CombineEntry entry)
176
ArrayList todel = new ArrayList ();
178
DeployFileCollection col = GetExtensionChain ().GetDeployFiles (ctx, entry);
179
foreach (DeployFile df in col) {
180
if (!ctx.IncludeFile (df)) {
185
if (df.ContainsPathReferences) {
186
string name = df.DisplayName;
187
df.SourcePath = ProcessFileTemplate (ctx, df.SourcePath);
188
df.DisplayName = name;
191
foreach (DeployFile df in todel) {
197
internal static DeployServiceExtension GetExtensionChain ()
199
DeployServiceExtension[] extensions = (DeployServiceExtension[]) AddinManager.GetExtensionObjects ("/MonoDevelop/DeployService/DeployServiceExtensions", typeof(DeployServiceExtension), false);
200
for (int n=0; n<extensions.Length - 1; n++)
201
extensions [n].Next = extensions [n+1];
202
return extensions [0];
205
internal static string GetDeployDirectory (DeployContext ctx, string folderId)
207
return GetExtensionChain ().ResolveDirectory (ctx, folderId);
210
public static DeployDirectoryInfo[] GetDeployDirectoryInfo ()
212
if (directoryInfos != null)
213
return directoryInfos;
215
ArrayList list = new ArrayList ();
216
foreach (DeployDirectoryNodeType dir in AddinManager.GetExtensionNodes ("/MonoDevelop/Deployment/DeployDirectories"))
217
list.Add (dir.GetDeployDirectoryInfo ());
219
return directoryInfos = (DeployDirectoryInfo[]) list.ToArray (typeof(DeployDirectoryInfo));
222
public static DeployPlatformInfo[] GetDeployPlatformInfo ()
224
if (platformInfos != null)
225
return platformInfos;
227
ArrayList list = new ArrayList ();
228
foreach (DeployPlatformNodeType dir in AddinManager.GetExtensionNodes ("/MonoDevelop/Deployment/DeployPlatforms"))
229
list.Add (dir.GetDeployPlatformInfo ());
231
return platformInfos = (DeployPlatformInfo[]) list.ToArray (typeof(DeployPlatformInfo));
234
internal static string ProcessFileTemplate (DeployContext ctx, string file)
236
TextFile tf = TextFile.ReadFile (file);
237
string text = tf.Text;
238
StringBuilder sb = new StringBuilder ();
240
int pos = text.IndexOf ('@');
242
int ep = text.IndexOf ('@', pos+1);
245
string tag = text.Substring (pos + 1, ep - pos - 1);
246
string dir = ctx.GetDirectory (tag);
248
sb.Append (text.Substring (lastPos, pos - lastPos));
252
pos = text.IndexOf ('@', ep+1);
254
sb.Append (text.Substring (lastPos, text.Length - lastPos));
255
string tmp = ctx.CreateTempFile ();
256
TextFile.WriteFile (tmp, sb.ToString (), tf.SourceEncoding);
260
static void InitCopiers ()
264
copiers = new List<FileCopyHandler> ();
265
AddinManager.RemoveExtensionNodeHandler ("/SharpDevelop/Workbench/DeployFileCopiers", OnCopierExtensionChanged);
268
static void OnCopierExtensionChanged (object s, ExtensionNodeEventArgs args)
270
if (args.Change == ExtensionChange.Add) {
271
copiers.Add (new FileCopyHandler ((IFileCopyHandler)args.ExtensionObject));
274
IFileCopyHandler h = (IFileCopyHandler)args.ExtensionObject;
275
foreach (FileCopyHandler c in copiers) {