~ubuntu-branches/ubuntu/gutsy/monodevelop/gutsy

« back to all changes in this revision

Viewing changes to Extras/Deployment/MonoDevelop.Deployment/MonoDevelop.Deployment/DeployService.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2007-07-16 13:29:54 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20070716132954-pzjpp1tbvotxw30v
Tags: 0.14+dfsg-1ubuntu1
* Sync with Debian, remaining changes:
  + debian/control:
    - Build depend on firefox-dev, depend on firefox.
    - Adjust Maintainer field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// DeployService.cs
 
3
//
 
4
// Author:
 
5
//   Lluis Sanchez Gual
 
6
//
 
7
// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
 
8
//
 
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:
 
16
// 
 
17
// The above copyright notice and this permission notice shall be
 
18
// included in all copies or substantial portions of the Software.
 
19
// 
 
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.
 
27
//
 
28
 
 
29
 
 
30
using System;
 
31
using System.Text;
 
32
using System.IO;
 
33
using System.Xml;
 
34
using System.Collections;
 
35
using System.Collections.Generic;
 
36
using Mono.Addins;
 
37
 
 
38
using MonoDevelop.Core;
 
39
using MonoDevelop.Projects;
 
40
using MonoDevelop.Projects.Text;
 
41
using MonoDevelop.Projects.Serialization;
 
42
using MonoDevelop.Core.Execution;
 
43
 
 
44
namespace MonoDevelop.Deployment
 
45
{
 
46
        public static class DeployService
 
47
        {
 
48
                static List<FileCopyHandler> copiers;
 
49
                static DeployDirectoryInfo[] directoryInfos;
 
50
                static DeployPlatformInfo[] platformInfos;
 
51
                
 
52
                public static string[] SupportedArchiveFormats = new string [] {
 
53
                        ".tar", ".tar.gz", ".tar.bz2", ".zip"
 
54
                };
 
55
                
 
56
                static DeployService ()
 
57
                {
 
58
                        AddinManager.ExtensionChanged += delegate (object s, ExtensionEventArgs args) {
 
59
                                if (args.PathChanged ("/MonoDevelop/DeployService/DeployDirectories"))
 
60
                                        directoryInfos = null;
 
61
                        };
 
62
                }
 
63
                
 
64
                public static string CurrentPlatform {
 
65
                        get { return "Linux"; }
 
66
                }
 
67
                
 
68
                public static DeployProperties GetDeployProperties (ProjectFile file)
 
69
                {
 
70
                        DeployProperties props = (DeployProperties) file.ExtendedProperties [typeof(DeployProperties)];
 
71
                        if (props != null)
 
72
                                return props;
 
73
                        props = new DeployProperties (file);
 
74
                        file.ExtendedProperties [typeof(DeployProperties)] = props;
 
75
                        return props;
 
76
                }
 
77
                
 
78
                public static PackageBuilder[] GetSupportedPackageBuilders (CombineEntry entry)
 
79
                {
 
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);
 
86
                                        list.Add (b);
 
87
                                }
 
88
                        }
 
89
 
 
90
                        return (PackageBuilder[]) list.ToArray (typeof(PackageBuilder));
 
91
                }
 
92
                
 
93
                public static PackageBuilder[] GetPackageBuilders ()
 
94
                {
 
95
                        return (PackageBuilder[]) AddinManager.GetExtensionObjects ("/MonoDevelop/DeployService/PackageBuilders", typeof(PackageBuilder), false);
 
96
                }
 
97
                
 
98
                public static void Install (IProgressMonitor monitor, CombineEntry entry, string prefix, string appName)
 
99
                {
 
100
                        InstallResolver res = new InstallResolver ();
 
101
                        res.Install (monitor, entry, appName, prefix);
 
102
                }
 
103
                
 
104
                public static void CreateArchive (IProgressMonitor mon, string folder, string targetFile)
 
105
                {
 
106
                        string tf = Path.GetFileNameWithoutExtension (targetFile);
 
107
                        if (tf.EndsWith (".tar")) tf = Path.GetFileNameWithoutExtension (tf);
 
108
                        
 
109
                        if (File.Exists (targetFile))
 
110
                                File.Delete (targetFile);
 
111
                                         
 
112
                        // Create the zip file
 
113
                        ProcessWrapper pw;
 
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);
 
122
                        else {
 
123
                                mon.Log.WriteLine ("Unsupported file format: " + Path.GetFileName (targetFile));
 
124
                                return;
 
125
                        }
 
126
                        pw.WaitForOutput ();
 
127
                }
 
128
                
 
129
                internal static string GetArchiveExtension (string fileName)
 
130
                {
 
131
                        if (fileName.EndsWith (".tar.gz"))
 
132
                                return ".tar.gz";
 
133
                        else if (fileName.EndsWith (".tar.bz2"))
 
134
                                return ".tar.bz2";
 
135
                        else
 
136
                                return Path.GetExtension (fileName);
 
137
                }
 
138
                
 
139
                public static FileCopyHandler[] GetFileCopyHandlers ()
 
140
                {
 
141
                        InitCopiers ();
 
142
                        return copiers.ToArray ();
 
143
                }
 
144
                
 
145
                internal static FileCopyHandler GetFileCopyHandler (string id)
 
146
                {
 
147
                        foreach (FileCopyHandler handler in GetFileCopyHandlers ())
 
148
                                if (handler.Id == id)
 
149
                                        return handler;
 
150
 
 
151
                        return null;
 
152
                }
 
153
                
 
154
                public static void BuildPackage (IProgressMonitor mon, Package package)
 
155
                {
 
156
                        BuildPackage (mon, package.PackageBuilder);
 
157
                }
 
158
                
 
159
                internal static void BuildPackage (IProgressMonitor mon, PackageBuilder builder)
 
160
                {
 
161
                        DeployServiceExtension extensionChain = GetExtensionChain ();
 
162
                        extensionChain.BuildPackage (mon, builder);
 
163
                }
 
164
                
 
165
                public static DeployFileCollection GetDeployFiles (DeployContext ctx, CombineEntry[] entries)
 
166
                {
 
167
                        DeployFileCollection col = new DeployFileCollection ();
 
168
                        foreach (CombineEntry e in entries) {
 
169
                                col.AddRange (GetDeployFiles (ctx, e));
 
170
                        }
 
171
                        return col;
 
172
                }
 
173
                
 
174
                public static DeployFileCollection GetDeployFiles (DeployContext ctx, CombineEntry entry)
 
175
                {
 
176
                        ArrayList todel = new ArrayList ();
 
177
                        
 
178
                        DeployFileCollection col = GetExtensionChain ().GetDeployFiles (ctx, entry);
 
179
                        foreach (DeployFile df in col) {
 
180
                                if (!ctx.IncludeFile (df)) {
 
181
                                        todel.Add (df);
 
182
                                        continue;
 
183
                                }
 
184
                                df.SetContext (ctx);
 
185
                                if (df.ContainsPathReferences) {
 
186
                                        string name = df.DisplayName;
 
187
                                        df.SourcePath = ProcessFileTemplate (ctx, df.SourcePath);
 
188
                                        df.DisplayName = name;
 
189
                                }
 
190
                        }
 
191
                        foreach (DeployFile df in todel) {
 
192
                                col.Remove (df);
 
193
                        }
 
194
                        return col;
 
195
                }
 
196
                
 
197
                internal static DeployServiceExtension GetExtensionChain ()
 
198
                {
 
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];
 
203
                }
 
204
                
 
205
                internal static string GetDeployDirectory (DeployContext ctx, string folderId)
 
206
                {
 
207
                        return GetExtensionChain ().ResolveDirectory (ctx, folderId);
 
208
                }
 
209
                
 
210
                public static DeployDirectoryInfo[] GetDeployDirectoryInfo ()
 
211
                {
 
212
                        if (directoryInfos != null)
 
213
                                return directoryInfos;
 
214
                        
 
215
                        ArrayList list = new ArrayList ();
 
216
                        foreach (DeployDirectoryNodeType dir in AddinManager.GetExtensionNodes ("/MonoDevelop/Deployment/DeployDirectories"))
 
217
                                list.Add (dir.GetDeployDirectoryInfo ());
 
218
                        
 
219
                        return directoryInfos = (DeployDirectoryInfo[]) list.ToArray (typeof(DeployDirectoryInfo));
 
220
                }
 
221
                
 
222
                public static DeployPlatformInfo[] GetDeployPlatformInfo ()
 
223
                {
 
224
                        if (platformInfos != null)
 
225
                                return platformInfos;
 
226
                        
 
227
                        ArrayList list = new ArrayList ();
 
228
                        foreach (DeployPlatformNodeType dir in AddinManager.GetExtensionNodes ("/MonoDevelop/Deployment/DeployPlatforms"))
 
229
                                list.Add (dir.GetDeployPlatformInfo ());
 
230
                        
 
231
                        return platformInfos = (DeployPlatformInfo[]) list.ToArray (typeof(DeployPlatformInfo));
 
232
                }
 
233
                
 
234
                internal static string ProcessFileTemplate (DeployContext ctx, string file)
 
235
                {
 
236
                        TextFile tf = TextFile.ReadFile (file);
 
237
                        string text = tf.Text;
 
238
                        StringBuilder sb = new StringBuilder ();
 
239
                        int lastPos = 0;
 
240
                        int pos = text.IndexOf ('@');
 
241
                        while (pos != -1) {
 
242
                                int ep = text.IndexOf ('@', pos+1);
 
243
                                if (ep == -1)
 
244
                                        break;
 
245
                                string tag = text.Substring (pos + 1, ep - pos - 1);
 
246
                                string dir = ctx.GetDirectory (tag);
 
247
                                if (dir != null) {
 
248
                                        sb.Append (text.Substring (lastPos, pos - lastPos));
 
249
                                        sb.Append (dir);
 
250
                                        lastPos = ep + 1;
 
251
                                }
 
252
                                pos = text.IndexOf ('@', ep+1);
 
253
                        }
 
254
                        sb.Append (text.Substring (lastPos, text.Length - lastPos));
 
255
                        string tmp = ctx.CreateTempFile ();
 
256
                        TextFile.WriteFile (tmp, sb.ToString (), tf.SourceEncoding);
 
257
                        return tmp;
 
258
                }
 
259
                
 
260
                static void InitCopiers ()
 
261
                {
 
262
                        if (copiers != null)
 
263
                                return;
 
264
                        copiers = new List<FileCopyHandler> ();
 
265
                        AddinManager.RemoveExtensionNodeHandler ("/SharpDevelop/Workbench/DeployFileCopiers", OnCopierExtensionChanged);
 
266
                }
 
267
                
 
268
                static void OnCopierExtensionChanged (object s, ExtensionNodeEventArgs args)
 
269
                {
 
270
                        if (args.Change == ExtensionChange.Add) {
 
271
                                copiers.Add (new FileCopyHandler ((IFileCopyHandler)args.ExtensionObject));
 
272
                        }
 
273
                        else {
 
274
                                IFileCopyHandler h = (IFileCopyHandler)args.ExtensionObject;
 
275
                                foreach (FileCopyHandler c in copiers) {
 
276
                                        if (c.Id == h.Id) {
 
277
                                                copiers.Remove (c);
 
278
                                                break;
 
279
                                        }
 
280
                                }
 
281
                        }
 
282
                }
 
283
        }
 
284
}