001: /*******************************************************************************
002: * Copyright (c) 2006, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.core.exports;
011:
012: import java.io.BufferedReader;
013: import java.io.File;
014: import java.io.FileOutputStream;
015: import java.io.FileReader;
016: import java.io.FileWriter;
017: import java.io.IOException;
018: import java.io.InputStream;
019: import java.io.PrintWriter;
020: import java.lang.reflect.InvocationTargetException;
021: import java.net.URL;
022: import java.util.Dictionary;
023: import java.util.HashMap;
024: import java.util.HashSet;
025: import java.util.Hashtable;
026: import java.util.Properties;
027: import java.util.Set;
028: import java.util.StringTokenizer;
029:
030: import javax.xml.parsers.DocumentBuilderFactory;
031: import javax.xml.parsers.FactoryConfigurationError;
032: import javax.xml.parsers.ParserConfigurationException;
033:
034: import org.eclipse.ant.core.AntRunner;
035: import org.eclipse.core.resources.IResource;
036: import org.eclipse.core.runtime.CoreException;
037: import org.eclipse.core.runtime.IPath;
038: import org.eclipse.core.runtime.IProgressMonitor;
039: import org.eclipse.core.runtime.Path;
040: import org.eclipse.core.runtime.Platform;
041: import org.eclipse.core.runtime.SubProgressMonitor;
042: import org.eclipse.jdt.launching.ExecutionArguments;
043: import org.eclipse.osgi.service.resolver.BundleDescription;
044: import org.eclipse.osgi.service.resolver.HostSpecification;
045: import org.eclipse.osgi.service.resolver.State;
046: import org.eclipse.pde.core.plugin.IPluginModelBase;
047: import org.eclipse.pde.core.plugin.PluginRegistry;
048: import org.eclipse.pde.core.plugin.TargetPlatform;
049: import org.eclipse.pde.internal.build.BuildScriptGenerator;
050: import org.eclipse.pde.internal.build.IBuildPropertiesConstants;
051: import org.eclipse.pde.internal.build.IXMLConstants;
052: import org.eclipse.pde.internal.core.PDECore;
053: import org.eclipse.pde.internal.core.TargetPlatformHelper;
054: import org.eclipse.pde.internal.core.XMLPrintHandler;
055: import org.eclipse.pde.internal.core.iproduct.IArgumentsInfo;
056: import org.eclipse.pde.internal.core.iproduct.IConfigurationFileInfo;
057: import org.eclipse.pde.internal.core.iproduct.IJREInfo;
058: import org.eclipse.pde.internal.core.iproduct.ILauncherInfo;
059: import org.eclipse.pde.internal.core.iproduct.IProduct;
060: import org.eclipse.pde.internal.core.iproduct.ISplashInfo;
061: import org.eclipse.pde.internal.core.util.CoreUtility;
062: import org.osgi.framework.BundleContext;
063: import org.osgi.framework.InvalidSyntaxException;
064: import org.w3c.dom.Document;
065: import org.w3c.dom.Element;
066:
067: public class ProductExportOperation extends FeatureExportOperation {
068:
069: private String fFeatureLocation;
070: private String fRoot;
071: private IProduct fProduct;
072:
073: public ProductExportOperation(FeatureExportInfo info,
074: IProduct product, String root) {
075: super (info);
076: fProduct = product;
077: fRoot = root;
078: }
079:
080: public void run(IProgressMonitor monitor) throws CoreException {
081: String[][] configurations = fInfo.targets;
082: if (configurations == null)
083: configurations = new String[][] { { TargetPlatform.getOS(),
084: TargetPlatform.getWS(), TargetPlatform.getOSArch(),
085: TargetPlatform.getNL() } };
086: monitor.beginTask("", 10 * configurations.length); //$NON-NLS-1$
087: for (int i = 0; i < configurations.length; i++) {
088: try {
089: String[] config = configurations[i];
090: if (config[0].equals("macosx") && fInfo.targets == null) //$NON-NLS-1$
091: createMacScript(config, new SubProgressMonitor(
092: monitor, 1));
093: // create a feature to wrap all plug-ins and features
094: String featureID = "org.eclipse.pde.container.feature"; //$NON-NLS-1$
095: fFeatureLocation = fBuildTempLocation + File.separator
096: + featureID;
097:
098: createFeature(featureID, fFeatureLocation, config, true);
099: createBuildPropertiesFile(fFeatureLocation, config);
100: createConfigIniFile(config);
101: createEclipseProductFile();
102: createLauncherIniFile(config[0]);
103: doExport(featureID, null, fFeatureLocation, config[0],
104: config[1], config[2], new SubProgressMonitor(
105: monitor, 8));
106: } catch (IOException e) {
107: } catch (InvocationTargetException 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
114: : configurations[i], new SubProgressMonitor(
115: monitor, 1));
116: }
117: }
118: monitor.done();
119: }
120:
121: private File getCustomIniFile() {
122: IConfigurationFileInfo info = fProduct
123: .getConfigurationFileInfo();
124: if (info != null && info.getUse().equals("custom")) { //$NON-NLS-1$
125: String path = getExpandedPath(info.getPath());
126: if (path != null) {
127: File file = new File(path);
128: if (file.exists() && file.isFile())
129: return file;
130: }
131: }
132: return null;
133: }
134:
135: /*
136: * (non-Javadoc)
137: *
138: * @see org.eclipse.pde.internal.ui.wizards.exports.FeatureExportJob#getPaths()
139: */
140: protected String[] getPaths() {
141: String[] paths = super .getPaths();
142: String[] all = new String[paths.length + 1];
143: all[0] = fFeatureLocation + File.separator + "feature.xml"; //$NON-NLS-1$
144: System.arraycopy(paths, 0, all, 1, paths.length);
145: return all;
146: }
147:
148: private void createBuildPropertiesFile(String featureLocation,
149: String[] config) {
150: File file = new File(featureLocation);
151: if (!file.exists() || !file.isDirectory())
152: file.mkdirs();
153:
154: boolean hasLaunchers = PDECore.getDefault()
155: .getFeatureModelManager().getDeltaPackFeature() != null;
156: Properties properties = new Properties();
157: properties.put(IBuildPropertiesConstants.ROOT,
158: getRootFileLocations(hasLaunchers)); //To copy a folder
159: if (!hasLaunchers) {
160: properties.put("root.permissions.755", getLauncherName()); //$NON-NLS-1$
161: if (TargetPlatform.getWS().equals("motif") && TargetPlatform.getOS().equals("linux")) { //$NON-NLS-1$ //$NON-NLS-2$
162: properties
163: .put(
164: "root.linux.motif.x86.permissions.755", "libXm.so.2"); //$NON-NLS-1$ //$NON-NLS-2$
165: } else if (TargetPlatform.getOS().equals("macosx")) { //$NON-NLS-1$
166: properties
167: .put("root.macosx.carbon.ppc.permissions.755", //$NON-NLS-1$
168: "${launcherName}.app/Contents/MacOS/${launcherName}"); //$NON-NLS-1$
169: }
170: }
171:
172: IJREInfo jreInfo = fProduct.getJREInfo();
173: String vm = jreInfo != null ? jreInfo.getJVMLocation(config[0])
174: : null;
175: if (vm != null) {
176: properties.put("root." + config[0] + //$NON-NLS-1$
177: "." + config[1] + //$NON-NLS-1$
178: "." + config[2] + //$NON-NLS-1$
179: ".folder.jre", //$NON-NLS-1$
180: "absolute:" + vm); //$NON-NLS-1$
181: String perms = (String) properties
182: .get("root.permissions.755"); //$NON-NLS-1$
183: if (perms != null) {
184: StringBuffer buffer = new StringBuffer(perms);
185: buffer.append(","); //$NON-NLS-1$
186: buffer.append("jre/bin/java"); //$NON-NLS-1$
187: properties.put(
188: "root.permissions.755", buffer.toString()); //$NON-NLS-1$
189: }
190: }
191:
192: save(
193: new File(file, "build.properties"), properties, "Build Configuration"); //$NON-NLS-1$ //$NON-NLS-2$
194: }
195:
196: private String getRootFileLocations(boolean hasLaunchers) {
197: StringBuffer buffer = new StringBuffer();
198:
199: File homeDir = new File(TargetPlatform.getLocation());
200: if (!hasLaunchers) {
201: if (homeDir.exists() && homeDir.isDirectory()) {
202: buffer.append("absolute:file:"); //$NON-NLS-1$
203: buffer
204: .append(new File(homeDir, "startup.jar").getAbsolutePath()); //$NON-NLS-1$
205: if (!TargetPlatform.getOS().equals("macosx")) { //$NON-NLS-1$
206: File file = new File(homeDir, "eclipse"); //$NON-NLS-1$
207: if (file.exists()) {
208: buffer.append(",absolute:file:"); //$NON-NLS-1$
209: buffer.append(file.getAbsolutePath());
210: }
211: file = new File(homeDir, "eclipse.exe"); //$NON-NLS-1$
212: if (file.exists()) {
213: buffer.append(",absolute:file:"); //$NON-NLS-1$
214: buffer.append(file.getAbsolutePath());
215: }
216: file = new File(homeDir, "libXm.so.2"); //$NON-NLS-1$
217: if (file.exists()) {
218: buffer.append(",absolute:file:"); //$NON-NLS-1$
219: buffer.append(file.getAbsolutePath());
220: }
221: }
222: }
223: }
224: // add content of temp folder (.eclipseproduct, configuration/config.ini)
225: if (buffer.length() > 0)
226: buffer.append(","); //$NON-NLS-1$
227: buffer.append("/temp/"); //$NON-NLS-1$
228:
229: return buffer.toString();
230: }
231:
232: private void createEclipseProductFile() {
233: File dir = new File(fFeatureLocation, "temp"); //$NON-NLS-1$
234: if (!dir.exists() || !dir.isDirectory())
235: dir.mkdirs();
236: Properties properties = new Properties();
237: IPluginModelBase model = PluginRegistry
238: .findModel(getBrandingPlugin());
239: if (model != null)
240: properties
241: .put(
242: "name", model.getResourceString(fProduct.getName())); //$NON-NLS-1$
243: else
244: properties.put("name", fProduct.getName()); //$NON-NLS-1$
245: properties.put("id", fProduct.getId()); //$NON-NLS-1$
246: if (model != null)
247: properties.put(
248: "version", model.getPluginBase().getVersion()); //$NON-NLS-1$
249: save(
250: new File(dir, ".eclipseproduct"), properties, "Eclipse Product File"); //$NON-NLS-1$ //$NON-NLS-2$
251: }
252:
253: private void createLauncherIniFile(String os) {
254: String programArgs = getProgramArguments(os);
255: String vmArgs = getVMArguments(os);
256:
257: if (programArgs.length() == 0 && vmArgs.length() == 0)
258: return;
259:
260: File dir = new File(fFeatureLocation, "temp"); //$NON-NLS-1$
261: // need to place launcher.ini file in special directory for MacOSX (bug 164762)
262: if (Platform.OS_MACOSX.equals(os)) {
263: dir = new File(dir, "Eclipse.app/Contents/MacOS"); //$NON-NLS-1$
264: }
265: if (!dir.exists() || !dir.isDirectory())
266: dir.mkdirs();
267:
268: String lineDelimiter = Platform.OS_WIN32.equals(os) ? "\r\n" : "\n"; //$NON-NLS-1$ //$NON-NLS-2$
269:
270: PrintWriter writer = null;
271: try {
272: writer = new PrintWriter(new FileWriter(new File(dir,
273: getLauncherName() + ".ini"))); //$NON-NLS-1$
274: ExecutionArguments args = new ExecutionArguments(vmArgs,
275: programArgs);
276:
277: // add program arguments
278: String[] array = args.getProgramArgumentsArray();
279: for (int i = 0; i < array.length; i++) {
280: writer.print(array[i]);
281: writer.print(lineDelimiter);
282: }
283:
284: // add VM arguments
285: array = args.getVMArgumentsArray();
286: if (array.length > 0) {
287: writer.print("-vmargs"); //$NON-NLS-1$
288: writer.print(lineDelimiter);
289: for (int i = 0; i < array.length; i++) {
290: writer.print(array[i]);
291: writer.print(lineDelimiter);
292: }
293: }
294: } catch (IOException e) {
295: } finally {
296: if (writer != null) {
297: writer.close();
298: }
299: }
300: }
301:
302: private String getProgramArguments(String os) {
303: IArgumentsInfo info = fProduct.getLauncherArguments();
304: return info != null ? CoreUtility.normalize(info
305: .getCompleteProgramArguments(os)) : "";//$NON-NLS-1$
306: }
307:
308: private String getVMArguments(String os) {
309: IArgumentsInfo info = fProduct.getLauncherArguments();
310: return (info != null) ? CoreUtility.normalize(info
311: .getCompleteVMArguments(os)) : ""; //$NON-NLS-1$
312: }
313:
314: private void createConfigIniFile(String[] config) {
315: File dir = new File(fFeatureLocation, "temp/configuration"); //$NON-NLS-1$
316: if (!dir.exists() || !dir.isDirectory())
317: dir.mkdirs();
318:
319: PrintWriter writer = null;
320:
321: File custom = getCustomIniFile();
322: if (custom != null) {
323: String path = getExpandedPath(fProduct
324: .getConfigurationFileInfo().getPath());
325: BufferedReader in = null;
326: try {
327: in = new BufferedReader(new FileReader(path));
328: writer = new PrintWriter(new FileWriter(new File(dir,
329: "config.ini"))); //$NON-NLS-1$
330: String line;
331: while ((line = in.readLine()) != null) {
332: writer.println(line);
333: }
334: } catch (IOException e) {
335: } finally {
336: try {
337: if (in != null)
338: in.close();
339: if (writer != null)
340: writer.close();
341: } catch (IOException e) {
342: }
343: }
344: return;
345: }
346: try {
347: writer = new PrintWriter(new FileWriter(new File(dir,
348: "config.ini"))); //$NON-NLS-1$
349: String location = getSplashLocation(config[0], config[1],
350: config[2]);
351: writer.println("#Product Runtime Configuration File"); //$NON-NLS-1$
352: writer.println();
353: if (location != null)
354: writer.println("osgi.splashPath=" + location); //$NON-NLS-1$
355: writer.println("eclipse.product=" + fProduct.getId()); //$NON-NLS-1$
356: writer
357: .println("osgi.bundles=" + getPluginList(config, TargetPlatform.getBundleList())); //$NON-NLS-1$
358: writer.println("osgi.bundles.defaultStartLevel=4"); //$NON-NLS-1$
359: } catch (IOException e) {
360: } finally {
361: if (writer != null)
362: writer.close();
363: }
364: }
365:
366: private String getSplashLocation(String os, String ws, String arch) {
367: ISplashInfo info = fProduct.getSplashInfo();
368: String plugin = null;
369: if (info != null) {
370: plugin = info.getLocation();
371: }
372: if (plugin == null || plugin.trim().length() == 0)
373: plugin = getBrandingPlugin();
374:
375: if (plugin == null)
376: return null;
377:
378: StringBuffer buffer = new StringBuffer(
379: "platform:/base/plugins/"); //$NON-NLS-1$
380: buffer.append(plugin.trim());
381:
382: State state = getState(os, ws, arch);
383: BundleDescription bundle = state.getBundle(plugin, null);
384: if (bundle != null) {
385: BundleDescription[] fragments = bundle.getFragments();
386: for (int i = 0; i < fragments.length; i++) {
387: String id = fragments[i].getSymbolicName();
388: if (fProduct.containsPlugin(id)) {
389: buffer.append(",platform:/base/plugins/"); //$NON-NLS-1$
390: buffer.append(id);
391: }
392: }
393: }
394: return buffer.toString();
395: }
396:
397: private String getBrandingPlugin() {
398: int dot = fProduct.getId().lastIndexOf('.');
399: return (dot != -1) ? fProduct.getId().substring(0, dot) : null;
400: }
401:
402: private String getPluginList(String[] config, String bundleList) {
403: if (fProduct.useFeatures())
404: return bundleList;
405:
406: StringBuffer buffer = new StringBuffer();
407:
408: // include only bundles that are actually in this product configuration
409: Set initialBundleSet = new HashSet();
410: StringTokenizer tokenizer = new StringTokenizer(bundleList, ","); //$NON-NLS-1$
411: while (tokenizer.hasMoreTokens()) {
412: String token = tokenizer.nextToken();
413: int index = token.indexOf('@');
414: String id = index != -1 ? token.substring(0, index) : token;
415: if (fProduct.containsPlugin(id)) {
416: if (buffer.length() > 0)
417: buffer.append(',');
418: buffer.append(id);
419: if (index != -1 && index < token.length() - 1)
420: buffer.append(token.substring(index));
421: initialBundleSet.add(id);
422: }
423: }
424:
425: if (!fProduct.containsPlugin("org.eclipse.update.configurator")) { //$NON-NLS-1$
426: initialBundleSet.add("org.eclipse.osgi"); //$NON-NLS-1$
427:
428: Dictionary environment = new Hashtable(4);
429: environment.put("osgi.os", config[0]); //$NON-NLS-1$
430: environment.put("osgi.ws", config[1]); //$NON-NLS-1$
431: environment.put("osgi.arch", config[2]); //$NON-NLS-1$
432: environment.put("osgi.nl", config[3]); //$NON-NLS-1$
433:
434: BundleContext context = PDECore.getDefault()
435: .getBundleContext();
436: for (int i = 0; i < fInfo.items.length; i++) {
437: BundleDescription bundle = (BundleDescription) fInfo.items[i];
438: String filterSpec = bundle.getPlatformFilter();
439: try {
440: if (filterSpec == null
441: || context.createFilter(filterSpec).match(
442: environment)) {
443: String id = ((BundleDescription) fInfo.items[i])
444: .getSymbolicName();
445: if (!initialBundleSet.contains(id)) {
446: if (buffer.length() > 0)
447: buffer.append(","); //$NON-NLS-1$
448: buffer.append(id);
449: }
450: }
451: } catch (InvalidSyntaxException e) {
452: }
453: }
454: }
455: return buffer.toString();
456: }
457:
458: protected HashMap createAntBuildProperties(String os, String ws,
459: String arch) {
460: HashMap properties = super .createAntBuildProperties(os, ws,
461: arch);
462: properties.put(IXMLConstants.PROPERTY_LAUNCHER_NAME,
463: getLauncherName());
464:
465: ILauncherInfo info = fProduct.getLauncherInfo();
466: if (info != null) {
467: String images = null;
468: if (os.equals("win32")) { //$NON-NLS-1$
469: images = getWin32Images(info);
470: } else if (os.equals("solaris")) { //$NON-NLS-1$
471: images = getSolarisImages(info);
472: } else if (os.equals("linux")) { //$NON-NLS-1$
473: images = getExpandedPath(info
474: .getIconPath(ILauncherInfo.LINUX_ICON));
475: } else if (os.equals("macosx")) { //$NON-NLS-1$
476: images = getExpandedPath(info
477: .getIconPath(ILauncherInfo.MACOSX_ICON));
478: }
479: if (images != null && images.length() > 0)
480: properties.put(IXMLConstants.PROPERTY_LAUNCHER_ICONS,
481: images);
482: }
483:
484: fAntBuildProperties.put(
485: IXMLConstants.PROPERTY_COLLECTING_FOLDER, fRoot);
486: fAntBuildProperties.put(IXMLConstants.PROPERTY_ARCHIVE_PREFIX,
487: fRoot);
488: return properties;
489: }
490:
491: private String getLauncherName() {
492: ILauncherInfo info = fProduct.getLauncherInfo();
493: if (info != null) {
494: String name = info.getLauncherName();
495: if (name != null && name.length() > 0) {
496: name = name.trim();
497: if (name.endsWith(".exe")) //$NON-NLS-1$
498: name = name.substring(0, name.length() - 4);
499: return name;
500: }
501: }
502: return "eclipse"; //$NON-NLS-1$
503: }
504:
505: private String getWin32Images(ILauncherInfo info) {
506: StringBuffer buffer = new StringBuffer();
507: if (info.usesWinIcoFile()) {
508: append(buffer, info.getIconPath(ILauncherInfo.P_ICO_PATH));
509: } else {
510: append(buffer, info.getIconPath(ILauncherInfo.WIN32_16_LOW));
511: append(buffer, info
512: .getIconPath(ILauncherInfo.WIN32_16_HIGH));
513: append(buffer, info
514: .getIconPath(ILauncherInfo.WIN32_32_HIGH));
515: append(buffer, info.getIconPath(ILauncherInfo.WIN32_32_LOW));
516: append(buffer, info
517: .getIconPath(ILauncherInfo.WIN32_48_HIGH));
518: append(buffer, info.getIconPath(ILauncherInfo.WIN32_48_LOW));
519: }
520: return buffer.length() > 0 ? buffer.toString() : null;
521: }
522:
523: private String getSolarisImages(ILauncherInfo info) {
524: StringBuffer buffer = new StringBuffer();
525: append(buffer, info.getIconPath(ILauncherInfo.SOLARIS_LARGE));
526: append(buffer, info.getIconPath(ILauncherInfo.SOLARIS_MEDIUM));
527: append(buffer, info.getIconPath(ILauncherInfo.SOLARIS_SMALL));
528: append(buffer, info.getIconPath(ILauncherInfo.SOLARIS_TINY));
529: return buffer.length() > 0 ? buffer.toString() : null;
530: }
531:
532: private void append(StringBuffer buffer, String path) {
533: path = getExpandedPath(path);
534: if (path != null) {
535: if (buffer.length() > 0)
536: buffer.append(","); //$NON-NLS-1$
537: buffer.append(path);
538: }
539: }
540:
541: private String getExpandedPath(String path) {
542: if (path == null || path.length() == 0)
543: return null;
544: IResource resource = PDECore.getWorkspace().getRoot()
545: .findMember(new Path(path));
546: if (resource != null) {
547: IPath fullPath = resource.getLocation();
548: return fullPath == null ? null : fullPath.toOSString();
549: }
550: return null;
551: }
552:
553: private void save(File file, Properties properties, String header) {
554: try {
555: FileOutputStream stream = new FileOutputStream(file);
556: properties.store(stream, header);
557: stream.flush();
558: stream.close();
559: } catch (IOException e) {
560: PDECore.logException(e);
561: }
562: }
563:
564: protected void setupGenerator(BuildScriptGenerator generator,
565: String featureID, String versionId, String os, String ws,
566: String arch, String featureLocation) throws CoreException {
567: super .setupGenerator(generator, featureID, versionId, os, ws,
568: arch, featureLocation);
569: if (fProduct != null)
570: generator.setProduct(fProduct.getModel()
571: .getInstallLocation());
572: }
573:
574: private void createMacScript(String[] config,
575: IProgressMonitor monitor) {
576: String entryName = TargetPlatformHelper.getTargetVersion() >= 3.3 ? "macosx/Info.plist" //$NON-NLS-1$
577: : "macosx/Info.plist.32"; //$NON-NLS-1$
578: URL url = PDECore.getDefault().getBundle().getEntry(entryName); //$NON-NLS-1$
579: if (url == null)
580: return;
581:
582: File scriptFile = null;
583: File plist = null;
584: InputStream in = null;
585: String location = PDECore.getDefault().getStateLocation()
586: .toOSString();
587: try {
588: in = url.openStream();
589: File dir = new File(location, "Eclipse.app/Contents"); //$NON-NLS-1$
590: dir.mkdirs();
591: plist = new File(dir, "Info.plist"); //$NON-NLS-1$
592: CoreUtility.readFile(in, plist);
593: scriptFile = createScriptFile("macbuild.xml"); //$NON-NLS-1$
594: DocumentBuilderFactory factory = DocumentBuilderFactory
595: .newInstance();
596: Document doc = factory.newDocumentBuilder().newDocument();
597:
598: Element root = doc.createElement("project"); //$NON-NLS-1$
599: root.setAttribute("name", "project"); //$NON-NLS-1$ //$NON-NLS-2$
600: root.setAttribute("default", "default"); //$NON-NLS-1$ //$NON-NLS-2$
601: doc.appendChild(root);
602:
603: Element property = doc.createElement("property"); //$NON-NLS-1$
604: property.setAttribute("name", "eclipse.base"); //$NON-NLS-1$ //$NON-NLS-2$
605: property.setAttribute(
606: "value", "${assemblyTempDir}/${collectingFolder}"); //$NON-NLS-1$ //$NON-NLS-2$
607: root.appendChild(property);
608:
609: Element target = doc.createElement("target"); //$NON-NLS-1$
610: target.setAttribute("name", "default"); //$NON-NLS-1$ //$NON-NLS-2$
611: root.appendChild(target);
612:
613: Element copy = doc.createElement("copy"); //$NON-NLS-1$
614: StringBuffer toDir = new StringBuffer("${eclipse.base}/"); //$NON-NLS-1$
615: toDir.append(config[0]);
616: toDir.append("."); //$NON-NLS-1$
617: toDir.append(config[1]);
618: toDir.append("."); //$NON-NLS-1$
619: toDir.append(config[2]);
620: toDir.append("/${collectingFolder}"); //$NON-NLS-1$
621: copy.setAttribute("todir", toDir.toString()); //$NON-NLS-1$
622: copy.setAttribute("failonerror", "false"); //$NON-NLS-1$ //$NON-NLS-2$
623: copy.setAttribute("overwrite", "true"); //$NON-NLS-1$ //$NON-NLS-2$
624: target.appendChild(copy);
625:
626: Element fileset = doc.createElement("fileset"); //$NON-NLS-1$
627: fileset.setAttribute("dir", "${installFolder}"); //$NON-NLS-1$ //$NON-NLS-2$
628: fileset.setAttribute(
629: "includes", "Eclipse.app/Contents/MacOS/eclipse"); //$NON-NLS-1$ //$NON-NLS-2$
630: copy.appendChild(fileset);
631:
632: fileset = doc.createElement("fileset"); //$NON-NLS-1$
633: fileset.setAttribute("dir", "${template}"); //$NON-NLS-1$ //$NON-NLS-2$
634: fileset.setAttribute(
635: "includes", "Eclipse.app/Contents/Info.plist"); //$NON-NLS-1$ //$NON-NLS-2$
636: copy.appendChild(fileset);
637:
638: XMLPrintHandler.writeFile(doc, scriptFile);
639:
640: AntRunner runner = new AntRunner();
641: HashMap map = new HashMap();
642: if (!fInfo.toDirectory) {
643: String filename = fInfo.zipFileName;
644: map.put(IXMLConstants.PROPERTY_ARCHIVE_FULLPATH,
645: fInfo.destinationDirectory + File.separator
646: + filename);
647: } else {
648: map.put(IXMLConstants.PROPERTY_ASSEMBLY_TMP,
649: fInfo.destinationDirectory);
650: }
651: map.put(IXMLConstants.PROPERTY_COLLECTING_FOLDER, fRoot);
652: map.put("installFolder", TargetPlatform.getLocation()); //$NON-NLS-1$
653: map.put("template", location); //$NON-NLS-1$
654: runner.addUserProperties(map);
655: runner.setBuildFileLocation(scriptFile.getAbsolutePath());
656: runner.setExecutionTargets(new String[] { "default" }); //$NON-NLS-1$
657: runner.run(new SubProgressMonitor(monitor, 1));
658: } catch (FactoryConfigurationError e) {
659: } catch (ParserConfigurationException e) {
660: } catch (CoreException e) {
661: } catch (IOException e) {
662: } finally {
663: try {
664: if (in != null)
665: in.close();
666: } catch (IOException e) {
667: }
668: CoreUtility
669: .deleteContent(new File(location, "Eclipse.app")); //$NON-NLS-1$
670: if (scriptFile != null && scriptFile.exists())
671: scriptFile.delete();
672: monitor.done();
673: }
674: }
675:
676: protected void setAdditionalAttributes(Element plugin,
677: BundleDescription bundle) {
678: // always make sure launcher fragments are flat; or else you will have launching problems
679: HostSpecification host = bundle.getHost();
680: boolean unpack = (host != null && host.getName().equals(
681: "org.eclipse.equinox.launcher")) //$NON-NLS-1$
682: ? true
683: : CoreUtility.guessUnpack(bundle);
684: plugin.setAttribute("unpack", Boolean.toString(unpack)); //$NON-NLS-1$
685: }
686:
687: }
|