KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > exports > ProductExportOperation


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.core.exports;
12
13 import java.io.BufferedReader JavaDoc;
14 import java.io.File JavaDoc;
15 import java.io.FileOutputStream JavaDoc;
16 import java.io.FileReader JavaDoc;
17 import java.io.FileWriter JavaDoc;
18 import java.io.IOException JavaDoc;
19 import java.io.InputStream JavaDoc;
20 import java.io.PrintWriter JavaDoc;
21 import java.lang.reflect.InvocationTargetException JavaDoc;
22 import java.net.URL JavaDoc;
23 import java.util.Dictionary JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.Hashtable JavaDoc;
27 import java.util.Properties JavaDoc;
28 import java.util.Set JavaDoc;
29 import java.util.StringTokenizer JavaDoc;
30
31 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
32 import javax.xml.parsers.FactoryConfigurationError JavaDoc;
33 import javax.xml.parsers.ParserConfigurationException JavaDoc;
34
35 import org.eclipse.ant.core.AntRunner;
36 import org.eclipse.core.resources.IResource;
37 import org.eclipse.core.runtime.CoreException;
38 import org.eclipse.core.runtime.IPath;
39 import org.eclipse.core.runtime.IProgressMonitor;
40 import org.eclipse.core.runtime.Path;
41 import org.eclipse.core.runtime.Platform;
42 import org.eclipse.core.runtime.SubProgressMonitor;
43 import org.eclipse.jdt.launching.ExecutionArguments;
44 import org.eclipse.osgi.service.resolver.BundleDescription;
45 import org.eclipse.osgi.service.resolver.HostSpecification;
46 import org.eclipse.osgi.service.resolver.State;
47 import org.eclipse.pde.core.plugin.IPluginModelBase;
48 import org.eclipse.pde.core.plugin.PluginRegistry;
49 import org.eclipse.pde.core.plugin.TargetPlatform;
50 import org.eclipse.pde.internal.build.BuildScriptGenerator;
51 import org.eclipse.pde.internal.build.IBuildPropertiesConstants;
52 import org.eclipse.pde.internal.build.IXMLConstants;
53 import org.eclipse.pde.internal.core.PDECore;
54 import org.eclipse.pde.internal.core.TargetPlatformHelper;
55 import org.eclipse.pde.internal.core.XMLPrintHandler;
56 import org.eclipse.pde.internal.core.iproduct.IArgumentsInfo;
57 import org.eclipse.pde.internal.core.iproduct.IConfigurationFileInfo;
58 import org.eclipse.pde.internal.core.iproduct.IJREInfo;
59 import org.eclipse.pde.internal.core.iproduct.ILauncherInfo;
60 import org.eclipse.pde.internal.core.iproduct.IProduct;
61 import org.eclipse.pde.internal.core.iproduct.ISplashInfo;
62 import org.eclipse.pde.internal.core.util.CoreUtility;
63 import org.osgi.framework.BundleContext;
64 import org.osgi.framework.InvalidSyntaxException;
65 import org.w3c.dom.Document JavaDoc;
66 import org.w3c.dom.Element JavaDoc;
67
68 public class ProductExportOperation extends FeatureExportOperation {
69
70     private String JavaDoc fFeatureLocation;
71     private String JavaDoc fRoot;
72     private IProduct fProduct;
73
74     public ProductExportOperation(FeatureExportInfo info, IProduct product, String JavaDoc root) {
75         super(info);
76         fProduct = product;
77         fRoot = root;
78     }
79
80     public void run(IProgressMonitor monitor) throws CoreException {
81         String JavaDoc[][] configurations = fInfo.targets;
82         if (configurations == null)
83             configurations = new String JavaDoc[][] { {TargetPlatform.getOS(), TargetPlatform.getWS(), TargetPlatform.getOSArch(), TargetPlatform.getNL() } };
84         monitor.beginTask("", 10 * configurations.length); //$NON-NLS-1$
85
for (int i = 0; i < configurations.length; i++) {
86             try {
87                 String JavaDoc[] config = configurations[i];
88                 if (config[0].equals("macosx") && fInfo.targets == null) //$NON-NLS-1$
89
createMacScript(config, new SubProgressMonitor(monitor, 1));
90                 // create a feature to wrap all plug-ins and features
91
String JavaDoc featureID = "org.eclipse.pde.container.feature"; //$NON-NLS-1$
92
fFeatureLocation = fBuildTempLocation + File.separator + featureID;
93                 
94                 createFeature(featureID, fFeatureLocation, config, true);
95                 createBuildPropertiesFile(fFeatureLocation, config);
96                 createConfigIniFile(config);
97                 createEclipseProductFile();
98                 createLauncherIniFile(config[0]);
99                 doExport(featureID,
100                         null,
101                         fFeatureLocation,
102                         config[0],
103                         config[1],
104                         config[2],
105                         new SubProgressMonitor(monitor, 8));
106             } catch (IOException JavaDoc e) {
107             } catch (InvocationTargetException JavaDoc e) {
108                 throwCoreException(e);
109             } finally {
110                 for (int j = 0; j < fInfo.items.length; j++) {
111                     deleteBuildFiles(fInfo.items[j]);
112                 }
113                 cleanup(fInfo.targets == null ? null : configurations[i], new SubProgressMonitor(monitor, 1));
114             }
115         }
116         monitor.done();
117     }
118
119     private File JavaDoc getCustomIniFile() {
120         IConfigurationFileInfo info = fProduct.getConfigurationFileInfo();
121         if (info != null && info.getUse().equals("custom")) { //$NON-NLS-1$
122
String JavaDoc path = getExpandedPath(info.getPath());
123             if (path != null) {
124                 File JavaDoc file = new File JavaDoc(path);
125                 if (file.exists() && file.isFile())
126                     return file;
127             }
128         }
129         return null;
130     }
131
132     /*
133      * (non-Javadoc)
134      *
135      * @see org.eclipse.pde.internal.ui.wizards.exports.FeatureExportJob#getPaths()
136      */

137     protected String JavaDoc[] getPaths() {
138         String JavaDoc[] paths = super.getPaths();
139         String JavaDoc[] all = new String JavaDoc[paths.length + 1];
140         all[0] = fFeatureLocation + File.separator + "feature.xml"; //$NON-NLS-1$
141
System.arraycopy(paths, 0, all, 1, paths.length);
142         return all;
143     }
144
145     private void createBuildPropertiesFile(String JavaDoc featureLocation, String JavaDoc[] config) {
146         File JavaDoc file = new File JavaDoc(featureLocation);
147         if (!file.exists() || !file.isDirectory())
148             file.mkdirs();
149
150         boolean hasLaunchers = PDECore.getDefault().getFeatureModelManager().getDeltaPackFeature() != null;
151         Properties JavaDoc properties = new Properties JavaDoc();
152         properties.put(IBuildPropertiesConstants.ROOT, getRootFileLocations(hasLaunchers)); //To copy a folder
153
if (!hasLaunchers) {
154             properties.put("root.permissions.755", getLauncherName()); //$NON-NLS-1$
155
if (TargetPlatform.getWS().equals("motif") && TargetPlatform.getOS().equals("linux")) { //$NON-NLS-1$ //$NON-NLS-2$
156
properties.put("root.linux.motif.x86.permissions.755", "libXm.so.2"); //$NON-NLS-1$ //$NON-NLS-2$
157
} else if (TargetPlatform.getOS().equals("macosx")) { //$NON-NLS-1$
158
properties.put(
159                         "root.macosx.carbon.ppc.permissions.755" , //$NON-NLS-1$
160
"${launcherName}.app/Contents/MacOS/${launcherName}"); //$NON-NLS-1$
161
}
162         }
163
164         IJREInfo jreInfo = fProduct.getJREInfo();
165         String JavaDoc vm = jreInfo != null ? jreInfo.getJVMLocation(config[0]) : null;
166         if(vm != null) {
167             properties.put("root."+config[0]+ //$NON-NLS-1$
168
"."+config[1]+ //$NON-NLS-1$
169
"."+config[2]+ //$NON-NLS-1$
170
".folder.jre", //$NON-NLS-1$
171
"absolute:" + vm); //$NON-NLS-1$
172
String JavaDoc perms = (String JavaDoc) properties.get("root.permissions.755"); //$NON-NLS-1$
173
if(perms != null) {
174                 StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(perms);
175                 buffer.append(","); //$NON-NLS-1$
176
buffer.append("jre/bin/java"); //$NON-NLS-1$
177
properties.put("root.permissions.755", buffer.toString()); //$NON-NLS-1$
178
}
179         }
180
181         save(new File JavaDoc(file, "build.properties"), properties, "Build Configuration"); //$NON-NLS-1$ //$NON-NLS-2$
182
}
183
184     private String JavaDoc getRootFileLocations(boolean hasLaunchers) {
185         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
186
187         File JavaDoc homeDir = new File JavaDoc(TargetPlatform.getLocation());
188         if (!hasLaunchers) {
189             if (homeDir.exists() && homeDir.isDirectory()) {
190                 buffer.append("absolute:file:"); //$NON-NLS-1$
191
buffer.append(new File JavaDoc(homeDir, "startup.jar").getAbsolutePath()); //$NON-NLS-1$
192
if (!TargetPlatform.getOS().equals("macosx")) { //$NON-NLS-1$
193
File JavaDoc file = new File JavaDoc(homeDir, "eclipse"); //$NON-NLS-1$
194
if (file.exists()) {
195                         buffer.append(",absolute:file:"); //$NON-NLS-1$
196
buffer.append(file.getAbsolutePath());
197                     }
198                     file = new File JavaDoc(homeDir, "eclipse.exe"); //$NON-NLS-1$
199
if (file.exists()) {
200                         buffer.append(",absolute:file:"); //$NON-NLS-1$
201
buffer.append(file.getAbsolutePath());
202                     }
203                     file = new File JavaDoc(homeDir, "libXm.so.2"); //$NON-NLS-1$
204
if (file.exists()) {
205                         buffer.append(",absolute:file:"); //$NON-NLS-1$
206
buffer.append(file.getAbsolutePath());
207                     }
208                 }
209             }
210         }
211         // add content of temp folder (.eclipseproduct, configuration/config.ini)
212
if (buffer.length() > 0)
213             buffer.append(","); //$NON-NLS-1$
214
buffer.append("/temp/"); //$NON-NLS-1$
215

216         return buffer.toString();
217     }
218     
219     private void createEclipseProductFile() {
220         File JavaDoc dir = new File JavaDoc(fFeatureLocation, "temp"); //$NON-NLS-1$
221
if (!dir.exists() || !dir.isDirectory())
222             dir.mkdirs();
223         Properties JavaDoc properties = new Properties JavaDoc();
224         IPluginModelBase model = PluginRegistry.findModel(getBrandingPlugin());
225         if (model != null)
226             properties.put("name", model.getResourceString(fProduct.getName())); //$NON-NLS-1$
227
else
228             properties.put("name", fProduct.getName()); //$NON-NLS-1$
229
properties.put("id", fProduct.getId()); //$NON-NLS-1$
230
if (model != null)
231             properties.put("version", model.getPluginBase().getVersion()); //$NON-NLS-1$
232
save(new File JavaDoc(dir, ".eclipseproduct"), properties, "Eclipse Product File"); //$NON-NLS-1$ //$NON-NLS-2$
233
}
234
235     private void createLauncherIniFile(String JavaDoc os) {
236         String JavaDoc programArgs = getProgramArguments(os);
237         String JavaDoc vmArgs = getVMArguments(os);
238
239         if (programArgs.length() == 0 && vmArgs.length() == 0)
240             return;
241
242         File JavaDoc dir = new File JavaDoc(fFeatureLocation, "temp"); //$NON-NLS-1$
243
// need to place launcher.ini file in special directory for MacOSX (bug 164762)
244
if (Platform.OS_MACOSX.equals(os)) {
245             dir = new File JavaDoc(dir, "Eclipse.app/Contents/MacOS"); //$NON-NLS-1$
246
}
247         if (!dir.exists() || !dir.isDirectory())
248             dir.mkdirs();
249
250         String JavaDoc lineDelimiter = Platform.OS_WIN32.equals(os)?"\r\n":"\n"; //$NON-NLS-1$ //$NON-NLS-2$
251

252         PrintWriter JavaDoc writer = null;
253         try {
254             writer = new PrintWriter JavaDoc(new FileWriter JavaDoc(new File JavaDoc(dir, getLauncherName() + ".ini"))); //$NON-NLS-1$
255
ExecutionArguments args = new ExecutionArguments(vmArgs, programArgs);
256             
257             // add program arguments
258
String JavaDoc[] array = args.getProgramArgumentsArray();
259             for (int i = 0; i < array.length; i++) {
260                 writer.print(array[i]);
261                 writer.print(lineDelimiter);
262             }
263             
264             // add VM arguments
265
array = args.getVMArgumentsArray();
266             if (array.length > 0) {
267                 writer.print("-vmargs"); //$NON-NLS-1$
268
writer.print(lineDelimiter);
269                 for (int i = 0; i < array.length; i++) {
270                     writer.print(array[i]);
271                     writer.print(lineDelimiter);
272                 }
273             }
274         } catch (IOException JavaDoc e) {
275         } finally {
276             if (writer != null) {
277                 writer.close();
278             }
279         }
280     }
281
282     private String JavaDoc getProgramArguments(String JavaDoc os) {
283         IArgumentsInfo info = fProduct.getLauncherArguments();
284         return info != null ? CoreUtility.normalize(info.getCompleteProgramArguments(os)) : "";//$NON-NLS-1$
285
}
286
287     private String JavaDoc getVMArguments(String JavaDoc os) {
288         IArgumentsInfo info = fProduct.getLauncherArguments();
289         return (info != null) ? CoreUtility.normalize(info.getCompleteVMArguments(os)) : ""; //$NON-NLS-1$
290
}
291
292
293     private void createConfigIniFile(String JavaDoc[] config) {
294         File JavaDoc dir = new File JavaDoc(fFeatureLocation, "temp/configuration"); //$NON-NLS-1$
295
if (!dir.exists() || !dir.isDirectory())
296             dir.mkdirs();
297
298         PrintWriter JavaDoc writer = null;
299
300         File JavaDoc custom = getCustomIniFile();
301         if (custom != null) {
302             String JavaDoc path = getExpandedPath(fProduct.getConfigurationFileInfo().getPath());
303             BufferedReader JavaDoc in = null;
304             try {
305                 in = new BufferedReader JavaDoc(new FileReader JavaDoc(path));
306                 writer = new PrintWriter JavaDoc(new FileWriter JavaDoc(new File JavaDoc(dir, "config.ini"))); //$NON-NLS-1$
307
String JavaDoc line;
308                 while ((line = in.readLine()) != null) {
309                     writer.println(line);
310                 }
311             } catch (IOException JavaDoc e) {
312             } finally {
313                 try {
314                     if (in != null)
315                         in.close();
316                     if (writer != null)
317                         writer.close();
318                 } catch (IOException JavaDoc e) {
319                 }
320             }
321             return;
322         }
323         try {
324             writer = new PrintWriter JavaDoc(new FileWriter JavaDoc(new File JavaDoc(dir, "config.ini"))); //$NON-NLS-1$
325
String JavaDoc location = getSplashLocation(config[0], config[1], config[2]);
326             writer.println("#Product Runtime Configuration File"); //$NON-NLS-1$
327
writer.println();
328             if (location != null)
329                 writer.println("osgi.splashPath=" + location); //$NON-NLS-1$
330
writer.println("eclipse.product=" + fProduct.getId()); //$NON-NLS-1$
331
writer.println("osgi.bundles=" + getPluginList(config, TargetPlatform.getBundleList())); //$NON-NLS-1$
332
writer.println("osgi.bundles.defaultStartLevel=4"); //$NON-NLS-1$
333
} catch (IOException JavaDoc e) {
334         } finally {
335             if (writer != null)
336                 writer.close();
337         }
338     }
339
340     private String JavaDoc getSplashLocation(String JavaDoc os, String JavaDoc ws, String JavaDoc arch) {
341         ISplashInfo info = fProduct.getSplashInfo();
342         String JavaDoc plugin = null;
343         if (info != null) {
344             plugin = info.getLocation();
345         }
346         if (plugin == null || plugin.trim().length() == 0)
347             plugin = getBrandingPlugin();
348
349         if (plugin == null)
350             return null;
351
352         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("platform:/base/plugins/"); //$NON-NLS-1$
353
buffer.append(plugin.trim());
354
355         State state = getState(os, ws, arch);
356         BundleDescription bundle = state.getBundle(plugin, null);
357         if (bundle != null) {
358             BundleDescription[] fragments = bundle.getFragments();
359             for (int i = 0; i < fragments.length; i++) {
360                 String JavaDoc id = fragments[i].getSymbolicName();
361                 if (fProduct.containsPlugin(id)) {
362                     buffer.append(",platform:/base/plugins/"); //$NON-NLS-1$
363
buffer.append(id);
364                 }
365             }
366         }
367         return buffer.toString();
368     }
369
370     private String JavaDoc getBrandingPlugin() {
371         int dot = fProduct.getId().lastIndexOf('.');
372         return (dot != -1) ? fProduct.getId().substring(0, dot) : null;
373     }
374
375     private String JavaDoc getPluginList(String JavaDoc[] config, String JavaDoc bundleList) {
376         if (fProduct.useFeatures())
377             return bundleList;
378
379         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
380
381         // include only bundles that are actually in this product configuration
382
Set JavaDoc initialBundleSet = new HashSet JavaDoc();
383         StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(bundleList, ","); //$NON-NLS-1$
384
while (tokenizer.hasMoreTokens()) {
385             String JavaDoc token = tokenizer.nextToken();
386             int index = token.indexOf('@');
387             String JavaDoc id = index != -1 ? token.substring(0, index) : token;
388             if (fProduct.containsPlugin(id)) {
389                 if (buffer.length() > 0)
390                     buffer.append(',');
391                 buffer.append(id);
392                 if (index != -1 && index < token.length() -1)
393                     buffer.append(token.substring(index));
394                 initialBundleSet.add(id);
395             }
396         }
397
398         if (!fProduct.containsPlugin("org.eclipse.update.configurator")) { //$NON-NLS-1$
399
initialBundleSet.add("org.eclipse.osgi"); //$NON-NLS-1$
400

401             Dictionary JavaDoc environment = new Hashtable JavaDoc(4);
402             environment.put("osgi.os", config[0]); //$NON-NLS-1$
403
environment.put("osgi.ws", config[1]); //$NON-NLS-1$
404
environment.put("osgi.arch", config[2]); //$NON-NLS-1$
405
environment.put("osgi.nl", config[3]); //$NON-NLS-1$
406

407             BundleContext context = PDECore.getDefault().getBundleContext();
408             for (int i = 0; i < fInfo.items.length; i++) {
409                 BundleDescription bundle = (BundleDescription)fInfo.items[i];
410                 String JavaDoc filterSpec = bundle.getPlatformFilter();
411                 try {
412                     if (filterSpec == null|| context.createFilter(filterSpec).match(environment)) {
413                         String JavaDoc id = ((BundleDescription)fInfo.items[i]).getSymbolicName();
414                         if (!initialBundleSet.contains(id)) {
415                             if (buffer.length() > 0)
416                                 buffer.append(","); //$NON-NLS-1$
417
buffer.append(id);
418                         }
419                     }
420                 } catch (InvalidSyntaxException e) {
421                 }
422             }
423         }
424         return buffer.toString();
425     }
426
427     protected HashMap JavaDoc createAntBuildProperties(String JavaDoc os, String JavaDoc ws, String JavaDoc arch) {
428         HashMap JavaDoc properties = super.createAntBuildProperties(os, ws, arch);
429         properties.put(IXMLConstants.PROPERTY_LAUNCHER_NAME, getLauncherName());
430
431         ILauncherInfo info = fProduct.getLauncherInfo();
432         if (info != null) {
433             String JavaDoc images = null;
434             if (os.equals("win32")) { //$NON-NLS-1$
435
images = getWin32Images(info);
436             } else if (os.equals("solaris")) { //$NON-NLS-1$
437
images = getSolarisImages(info);
438             } else if (os.equals("linux")) { //$NON-NLS-1$
439
images = getExpandedPath(info.getIconPath(ILauncherInfo.LINUX_ICON));
440             } else if (os.equals("macosx")) { //$NON-NLS-1$
441
images = getExpandedPath(info.getIconPath(ILauncherInfo.MACOSX_ICON));
442             }
443             if (images != null && images.length() > 0)
444                 properties.put(IXMLConstants.PROPERTY_LAUNCHER_ICONS, images);
445         }
446
447         fAntBuildProperties.put(IXMLConstants.PROPERTY_COLLECTING_FOLDER, fRoot);
448         fAntBuildProperties.put(IXMLConstants.PROPERTY_ARCHIVE_PREFIX, fRoot);
449         return properties;
450     }
451
452     private String JavaDoc getLauncherName() {
453         ILauncherInfo info = fProduct.getLauncherInfo();
454         if (info != null) {
455             String JavaDoc name = info.getLauncherName();
456             if (name != null && name.length() > 0) {
457                 name = name.trim();
458                 if (name.endsWith(".exe")) //$NON-NLS-1$
459
name = name.substring(0, name.length() - 4);
460                 return name;
461             }
462         }
463         return "eclipse"; //$NON-NLS-1$
464
}
465
466     private String JavaDoc getWin32Images(ILauncherInfo info) {
467         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
468         if (info.usesWinIcoFile()) {
469             append(buffer, info.getIconPath(ILauncherInfo.P_ICO_PATH));
470         } else {
471             append(buffer, info.getIconPath(ILauncherInfo.WIN32_16_LOW));
472             append(buffer, info.getIconPath(ILauncherInfo.WIN32_16_HIGH));
473             append(buffer, info.getIconPath(ILauncherInfo.WIN32_32_HIGH));
474             append(buffer, info.getIconPath(ILauncherInfo.WIN32_32_LOW));
475             append(buffer, info.getIconPath(ILauncherInfo.WIN32_48_HIGH));
476             append(buffer, info.getIconPath(ILauncherInfo.WIN32_48_LOW));
477         }
478         return buffer.length() > 0 ? buffer.toString() : null;
479     }
480
481     private String JavaDoc getSolarisImages(ILauncherInfo info) {
482         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
483         append(buffer, info.getIconPath(ILauncherInfo.SOLARIS_LARGE));
484         append(buffer, info.getIconPath(ILauncherInfo.SOLARIS_MEDIUM));
485         append(buffer, info.getIconPath(ILauncherInfo.SOLARIS_SMALL));
486         append(buffer, info.getIconPath(ILauncherInfo.SOLARIS_TINY));
487         return buffer.length() > 0 ? buffer.toString() : null;
488     }
489
490     private void append(StringBuffer JavaDoc buffer, String JavaDoc path) {
491         path = getExpandedPath(path);
492         if (path != null) {
493             if (buffer.length() > 0)
494                 buffer.append(","); //$NON-NLS-1$
495
buffer.append(path);
496         }
497     }
498
499     private String JavaDoc getExpandedPath(String JavaDoc path) {
500         if (path == null || path.length() == 0)
501             return null;
502         IResource resource = PDECore.getWorkspace().getRoot().findMember(new Path(path));
503         if (resource != null) {
504             IPath fullPath = resource.getLocation();
505             return fullPath == null ? null : fullPath.toOSString();
506         }
507         return null;
508     }
509
510     private void save(File JavaDoc file, Properties JavaDoc properties, String JavaDoc header) {
511         try {
512             FileOutputStream JavaDoc stream = new FileOutputStream JavaDoc(file);
513             properties.store(stream, header);
514             stream.flush();
515             stream.close();
516         } catch (IOException JavaDoc e) {
517             PDECore.logException(e);
518         }
519     }
520
521     protected void setupGenerator(BuildScriptGenerator generator, String JavaDoc featureID, String JavaDoc versionId, String JavaDoc os, String JavaDoc ws, String JavaDoc arch, String JavaDoc featureLocation) throws CoreException {
522         super.setupGenerator(generator, featureID, versionId, os, ws, arch, featureLocation);
523         if (fProduct != null)
524             generator.setProduct(fProduct.getModel().getInstallLocation());
525     }
526
527     private void createMacScript(String JavaDoc[] config, IProgressMonitor monitor) {
528         String JavaDoc entryName = TargetPlatformHelper.getTargetVersion() >= 3.3
529                                 ? "macosx/Info.plist" //$NON-NLS-1$
530
: "macosx/Info.plist.32"; //$NON-NLS-1$
531
URL JavaDoc url = PDECore.getDefault().getBundle().getEntry(entryName); //$NON-NLS-1$
532
if (url == null)
533             return;
534
535         File JavaDoc scriptFile = null;
536         File JavaDoc plist = null;
537         InputStream JavaDoc in = null;
538         String JavaDoc location = PDECore.getDefault().getStateLocation().toOSString();
539         try {
540             in = url.openStream();
541             File JavaDoc dir = new File JavaDoc(location, "Eclipse.app/Contents"); //$NON-NLS-1$
542
dir.mkdirs();
543             plist = new File JavaDoc(dir, "Info.plist"); //$NON-NLS-1$
544
CoreUtility.readFile(in, plist);
545             scriptFile = createScriptFile("macbuild.xml"); //$NON-NLS-1$
546
DocumentBuilderFactory JavaDoc factory = DocumentBuilderFactory.newInstance();
547             Document JavaDoc doc = factory.newDocumentBuilder().newDocument();
548
549             Element JavaDoc root = doc.createElement("project"); //$NON-NLS-1$
550
root.setAttribute("name", "project"); //$NON-NLS-1$ //$NON-NLS-2$
551
root.setAttribute("default", "default"); //$NON-NLS-1$ //$NON-NLS-2$
552
doc.appendChild(root);
553
554             Element JavaDoc property = doc.createElement("property"); //$NON-NLS-1$
555
property.setAttribute("name", "eclipse.base"); //$NON-NLS-1$ //$NON-NLS-2$
556
property.setAttribute("value", "${assemblyTempDir}/${collectingFolder}"); //$NON-NLS-1$ //$NON-NLS-2$
557
root.appendChild(property);
558
559             Element JavaDoc target = doc.createElement("target"); //$NON-NLS-1$
560
target.setAttribute("name", "default"); //$NON-NLS-1$ //$NON-NLS-2$
561
root.appendChild(target);
562
563             Element JavaDoc copy = doc.createElement("copy"); //$NON-NLS-1$
564
StringBuffer JavaDoc toDir = new StringBuffer JavaDoc("${eclipse.base}/"); //$NON-NLS-1$
565
toDir.append(config[0]);
566             toDir.append("."); //$NON-NLS-1$
567
toDir.append(config[1]);
568             toDir.append("."); //$NON-NLS-1$
569
toDir.append(config[2]);
570             toDir.append("/${collectingFolder}"); //$NON-NLS-1$
571
copy.setAttribute("todir", toDir.toString()); //$NON-NLS-1$
572
copy.setAttribute("failonerror", "false"); //$NON-NLS-1$ //$NON-NLS-2$
573
copy.setAttribute("overwrite", "true"); //$NON-NLS-1$ //$NON-NLS-2$
574
target.appendChild(copy);
575
576             Element JavaDoc fileset = doc.createElement("fileset"); //$NON-NLS-1$
577
fileset.setAttribute("dir", "${installFolder}"); //$NON-NLS-1$ //$NON-NLS-2$
578
fileset.setAttribute("includes", "Eclipse.app/Contents/MacOS/eclipse"); //$NON-NLS-1$ //$NON-NLS-2$
579
copy.appendChild(fileset);
580
581             fileset = doc.createElement("fileset"); //$NON-NLS-1$
582
fileset.setAttribute("dir", "${template}"); //$NON-NLS-1$ //$NON-NLS-2$
583
fileset.setAttribute("includes", "Eclipse.app/Contents/Info.plist"); //$NON-NLS-1$ //$NON-NLS-2$
584
copy.appendChild(fileset);
585
586             XMLPrintHandler.writeFile(doc, scriptFile);
587
588             AntRunner runner = new AntRunner();
589             HashMap JavaDoc map = new HashMap JavaDoc();
590             if (!fInfo.toDirectory) {
591                 String JavaDoc filename = fInfo.zipFileName;
592                 map.put(IXMLConstants.PROPERTY_ARCHIVE_FULLPATH, fInfo.destinationDirectory + File.separator + filename);
593             } else {
594                 map.put(IXMLConstants.PROPERTY_ASSEMBLY_TMP, fInfo.destinationDirectory);
595             }
596             map.put(IXMLConstants.PROPERTY_COLLECTING_FOLDER, fRoot);
597             map.put("installFolder", TargetPlatform.getLocation()); //$NON-NLS-1$
598
map.put("template", location); //$NON-NLS-1$
599
runner.addUserProperties(map);
600             runner.setBuildFileLocation(scriptFile.getAbsolutePath());
601             runner.setExecutionTargets(new String JavaDoc[] {"default"}); //$NON-NLS-1$
602
runner.run(new SubProgressMonitor(monitor, 1));
603         } catch (FactoryConfigurationError JavaDoc e) {
604         } catch (ParserConfigurationException JavaDoc e) {
605         } catch (CoreException e) {
606         } catch (IOException JavaDoc e) {
607         } finally {
608             try {
609                 if (in != null)
610                     in.close();
611             } catch (IOException JavaDoc e) {
612             }
613             CoreUtility.deleteContent(new File JavaDoc(location, "Eclipse.app")); //$NON-NLS-1$
614
if (scriptFile != null && scriptFile.exists())
615                 scriptFile.delete();
616             monitor.done();
617         }
618     }
619
620     protected void setAdditionalAttributes(Element JavaDoc plugin, BundleDescription bundle) {
621         // always make sure launcher fragments are flat; or else you will have launching problems
622
HostSpecification host = bundle.getHost();
623         boolean unpack = (host != null && host.getName().equals("org.eclipse.equinox.launcher")) //$NON-NLS-1$
624
? true : CoreUtility.guessUnpack(bundle);
625         plugin.setAttribute("unpack", Boolean.toString(unpack)); //$NON-NLS-1$
626
}
627
628
629 }
630  
Popular Tags