01: /*******************************************************************************
02: * Copyright (c) 2006, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.core.exports;
11:
12: import java.io.File;
13: import java.io.FileOutputStream;
14: import java.io.IOException;
15: import java.lang.reflect.InvocationTargetException;
16: import java.util.Properties;
17:
18: import org.eclipse.core.runtime.CoreException;
19: import org.eclipse.core.runtime.IProgressMonitor;
20: import org.eclipse.core.runtime.SubProgressMonitor;
21: import org.eclipse.pde.core.IModel;
22: import org.eclipse.pde.core.plugin.TargetPlatform;
23: import org.eclipse.pde.internal.core.PDECore;
24:
25: public abstract class FeatureBasedExportOperation extends
26: FeatureExportOperation {
27:
28: protected String fFeatureLocation;
29:
30: public FeatureBasedExportOperation(FeatureExportInfo info) {
31: super (info);
32: }
33:
34: public void run(IProgressMonitor monitor) throws CoreException {
35: try {
36: createDestination();
37: monitor.beginTask("", 10); //$NON-NLS-1$
38: // create a feature to contain all plug-ins
39: String featureID = "org.eclipse.pde.container.feature"; //$NON-NLS-1$
40: fFeatureLocation = fBuildTempLocation + File.separator
41: + featureID;
42: String[] config = new String[] { TargetPlatform.getOS(),
43: TargetPlatform.getWS(), TargetPlatform.getOSArch(),
44: TargetPlatform.getNL() };
45: createFeature(featureID, fFeatureLocation, config, false);
46: createBuildPropertiesFile(fFeatureLocation);
47: if (fInfo.useJarFormat)
48: createPostProcessingFiles();
49: doExport(featureID, null, fFeatureLocation, TargetPlatform
50: .getOS(), TargetPlatform.getWS(), TargetPlatform
51: .getOSArch(), new SubProgressMonitor(monitor, 7));
52: } catch (IOException e) {
53: } catch (InvocationTargetException e) {
54: throwCoreException(e);
55: } finally {
56: for (int i = 0; i < fInfo.items.length; i++) {
57: if (fInfo.items[i] instanceof IModel)
58: deleteBuildFiles(fInfo.items[i]);
59: }
60: cleanup(null, new SubProgressMonitor(monitor, 3));
61: monitor.done();
62: }
63: }
64:
65: protected abstract void createPostProcessingFiles();
66:
67: protected String[] getPaths() {
68: String[] paths = super .getPaths();
69: String[] all = new String[paths.length + 1];
70: all[0] = fFeatureLocation + File.separator + "feature.xml"; //$NON-NLS-1$
71: System.arraycopy(paths, 0, all, 1, paths.length);
72: return all;
73: }
74:
75: private void createBuildPropertiesFile(String featureLocation) {
76: File file = new File(featureLocation);
77: if (!file.exists() || !file.isDirectory())
78: file.mkdirs();
79: Properties prop = new Properties();
80: prop.put("pde", "marker"); //$NON-NLS-1$ //$NON-NLS-2$
81: save(new File(file, "build.properties"), prop, "Marker File"); //$NON-NLS-1$ //$NON-NLS-2$
82: }
83:
84: private void save(File file, Properties properties, String header) {
85: try {
86: FileOutputStream stream = new FileOutputStream(file);
87: properties.store(stream, header);
88: stream.flush();
89: stream.close();
90: } catch (IOException e) {
91: PDECore.logException(e);
92: }
93: }
94:
95: }
|