KickJava   Java API By Example, From Geeks To Geeks.

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


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.File JavaDoc;
14 import java.io.FileOutputStream JavaDoc;
15 import java.io.IOException JavaDoc;
16 import java.lang.reflect.InvocationTargetException JavaDoc;
17 import java.util.Properties JavaDoc;
18
19 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.core.runtime.IProgressMonitor;
21 import org.eclipse.core.runtime.SubProgressMonitor;
22 import org.eclipse.pde.core.IModel;
23 import org.eclipse.pde.core.plugin.TargetPlatform;
24 import org.eclipse.pde.internal.core.PDECore;
25 public abstract class FeatureBasedExportOperation extends FeatureExportOperation {
26
27     protected String JavaDoc fFeatureLocation;
28
29     public FeatureBasedExportOperation(FeatureExportInfo info) {
30         super(info);
31     }
32
33     public void run(IProgressMonitor monitor) throws CoreException {
34         try {
35             createDestination();
36             monitor.beginTask("", 10); //$NON-NLS-1$
37
// create a feature to contain all plug-ins
38
String JavaDoc featureID = "org.eclipse.pde.container.feature"; //$NON-NLS-1$
39
fFeatureLocation = fBuildTempLocation + File.separator + featureID;
40             String JavaDoc[] config = new String JavaDoc[] {TargetPlatform.getOS(), TargetPlatform.getWS(), TargetPlatform.getOSArch(), TargetPlatform.getNL() };
41             createFeature(featureID, fFeatureLocation, config, false);
42             createBuildPropertiesFile(fFeatureLocation);
43             if (fInfo.useJarFormat)
44                 createPostProcessingFiles();
45             doExport(featureID, null, fFeatureLocation, TargetPlatform.getOS(), TargetPlatform.getWS(), TargetPlatform.getOSArch(),
46                     new SubProgressMonitor(monitor, 7));
47         } catch (IOException JavaDoc e) {
48         } catch (InvocationTargetException JavaDoc e) {
49             throwCoreException(e);
50         } finally {
51             for (int i = 0; i < fInfo.items.length; i++) {
52                 if (fInfo.items[i] instanceof IModel)
53                     deleteBuildFiles(fInfo.items[i]);
54             }
55             cleanup(null, new SubProgressMonitor(monitor, 3));
56             monitor.done();
57         }
58     }
59     
60     protected abstract void createPostProcessingFiles();
61
62     protected String JavaDoc[] getPaths() {
63         String JavaDoc[] paths = super.getPaths();
64         String JavaDoc[] all = new String JavaDoc[paths.length + 1];
65         all[0] = fFeatureLocation + File.separator + "feature.xml"; //$NON-NLS-1$
66
System.arraycopy(paths, 0, all, 1, paths.length);
67         return all;
68     }
69     
70     private void createBuildPropertiesFile(String JavaDoc featureLocation) {
71         File JavaDoc file = new File JavaDoc(featureLocation);
72         if (!file.exists() || !file.isDirectory())
73             file.mkdirs();
74         Properties JavaDoc prop = new Properties JavaDoc();
75         prop.put("pde", "marker"); //$NON-NLS-1$ //$NON-NLS-2$
76
save(new File JavaDoc(file, "build.properties"),prop, "Marker File"); //$NON-NLS-1$ //$NON-NLS-2$
77
}
78     
79     private void save(File JavaDoc file, Properties JavaDoc properties, String JavaDoc header) {
80         try {
81             FileOutputStream JavaDoc stream = new FileOutputStream JavaDoc(file);
82             properties.store(stream, header);
83             stream.flush();
84             stream.close();
85         } catch (IOException JavaDoc e) {
86             PDECore.logException(e);
87         }
88     }
89
90 }
91
Popular Tags