KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > exports > PluginExportJob


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

11 package org.eclipse.pde.internal.ui.wizards.exports;
12
13 import java.io.*;
14 import java.lang.reflect.*;
15
16 import org.eclipse.core.runtime.*;
17 import org.eclipse.pde.core.plugin.*;
18 import org.eclipse.pde.internal.core.*;
19
20
21 public class PluginExportJob extends FeatureExportJob {
22
23     private String JavaDoc fFeatureLocation;
24
25     public PluginExportJob(
26         int exportType,
27         boolean exportSource,
28         String JavaDoc destination,
29         String JavaDoc zipFileName,
30         Object JavaDoc[] items) {
31         super(exportType, exportSource, destination, zipFileName, items);
32     }
33
34     /* (non-Javadoc)
35      * @see org.eclipse.pde.internal.ui.wizards.exports.FeatureExportJob#doExports(org.eclipse.core.runtime.IProgressMonitor)
36      */

37     protected void doExports(IProgressMonitor monitor)
38             throws InvocationTargetException, CoreException {
39         try {
40             // create a feature to contain all plug-ins
41
String JavaDoc featureID = "org.eclipse.pde.container.feature"; //$NON-NLS-1$
42
fFeatureLocation = fBuildTempLocation + File.separator + featureID;
43             createFeature(featureID, fFeatureLocation);
44             createBuildPropertiesFile(fFeatureLocation);
45             doExport(featureID, null, fFeatureLocation, TargetPlatform.getOS(), TargetPlatform.getWS(), TargetPlatform.getOSArch(), monitor);
46         } catch (IOException e) {
47         } finally {
48             for (int i = 0; i < fItems.length; i++) {
49                 if (fItems[i] instanceof IPluginModelBase)
50                     deleteBuildFiles((IPluginModelBase)fItems[i]);
51             }
52             cleanup(new SubProgressMonitor(monitor, 1));
53             monitor.done();
54         }
55     }
56     
57     private void createFeature(String JavaDoc featureID, String JavaDoc featureLocation)
58             throws IOException {
59         File file = new File(featureLocation);
60         if (!file.exists() || !file.isDirectory())
61             file.mkdirs();
62         File featureXML = new File(file, "feature.xml"); //$NON-NLS-1$
63
PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(featureXML), "UTF-8"), true); //$NON-NLS-1$
64
writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); //$NON-NLS-1$
65
writer.println("<feature id=\"" + featureID+ "\" version=\"1.0\">"); //$NON-NLS-1$ //$NON-NLS-2$
66
for (int i = 0; i < fItems.length; i++) {
67             if (fItems[i] instanceof IPluginModelBase) {
68                 IPluginBase plugin = ((IPluginModelBase) fItems[i])
69                         .getPluginBase();
70                 writer.println("<plugin id=\"" + plugin.getId()+ "\" version=\"0.0.0\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
71
}
72         }
73         writer.println("</feature>"); //$NON-NLS-1$
74
writer.close();
75     }
76     
77     /* (non-Javadoc)
78      * @see org.eclipse.pde.internal.ui.wizards.exports.FeatureExportJob#getPaths()
79      */

80     protected String JavaDoc[] getPaths() throws CoreException {
81         String JavaDoc[] paths = super.getPaths();
82         String JavaDoc[] all = new String JavaDoc[paths.length + 1];
83         all[0] = fFeatureLocation + File.separator + "feature.xml"; //$NON-NLS-1$
84
System.arraycopy(paths, 0, all, 1, paths.length);
85         return all;
86     }
87     
88     private void createBuildPropertiesFile(String JavaDoc featureLocation) {
89         File file = new File(featureLocation);
90         if (!file.exists() || !file.isDirectory())
91             file.mkdirs();
92         File build = new File(file, "build.properties"); //$NON-NLS-1$
93
try {
94             build.createNewFile();
95         } catch (IOException e) {
96         }
97     }
98
99 }
100
Popular Tags