KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > build > packager > PackagerBuildScriptGenerator


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 - Initial API and implementation
10  **********************************************************************/

11 package org.eclipse.pde.internal.build.packager;
12
13 import java.util.Iterator JavaDoc;
14 import java.util.List JavaDoc;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.pde.internal.build.*;
17 import org.eclipse.pde.internal.build.builder.FeatureBuildScriptGenerator;
18 import org.eclipse.update.core.IFeature;
19 import org.eclipse.update.core.IIncludedFeatureReference;
20 import org.eclipse.update.core.model.IncludedFeatureReferenceModel;
21
22 public class PackagerBuildScriptGenerator extends FeatureBuildScriptGenerator {
23     boolean zipWithEclipse = false;
24     private String JavaDoc packagingPropertiesLocation;
25     private String JavaDoc[] featureList;
26     private String JavaDoc[] rootFiles;
27     private String JavaDoc[] rootDirs;
28     private String JavaDoc outputFormat = "zip"; //$NON-NLS-1$
29
private String JavaDoc[] ignoredFeatures;
30
31     public PackagerBuildScriptGenerator() {
32         super();
33     }
34
35     public PackagerBuildScriptGenerator(String JavaDoc featureId, AssemblyInformation assemblageInformation) throws CoreException {
36         super(featureId, null, assemblageInformation);
37     }
38
39     public void run() throws CoreException {
40         AssemblyInformation assemblageInformation = new AssemblyInformation();
41
42         for (int i = 0; i < featureList.length; i++) {
43             FeatureBuildScriptGenerator generator = new PackagerBuildScriptGenerator(featureList[i], assemblageInformation);
44             generator.setGenerateIncludedFeatures(true);
45             generator.setAnalyseChildren(true);
46             generator.setSourceFeatureGeneration(false);
47             generator.setBinaryFeatureGeneration(true);
48             generator.setScriptGeneration(false);
49             generator.setPluginPath(pluginPath);
50             generator.setBuildSiteFactory(siteFactory);
51             generator.setDevEntries(devEntries);
52             generator.setCompiledElements(getCompiledElements());
53             generator.setBuildingOSGi(isBuildingOSGi());
54             setFeature(featureList[i]);
55             generator.generate();
56         }
57
58         removeIgnoredFeatures(assemblageInformation);
59         PackagingConfigScriptGenerator configAssembler = new PackagingConfigScriptGenerator();
60         Config config = (Config) getConfigInfos().get(0);
61         configAssembler.initialize(workingDirectory, DEFAULT_ASSEMBLE_FILENAME, "", config, assemblageInformation.getPlugins(config), assemblageInformation.getFeatures(config), assemblageInformation.getRootFileProviders(config)); //$NON-NLS-1$ //Here the last arg is true because we do not have the root info while packaging
62
configAssembler.setPackagingPropertiesLocation(packagingPropertiesLocation);
63         configAssembler.rootFiles(rootFiles);
64         configAssembler.rootDirs(rootDirs);
65         configAssembler.setOutput(outputFormat);
66         configAssembler.generate();
67
68     }
69
70     private void removeIgnoredFeatures(AssemblyInformation toAssemble) {
71         if (ignoredFeatures == null)
72             return;
73         for (int i = 0; i < ignoredFeatures.length; i++) {
74             try {
75                 toAssemble.removeFeature((Config) getConfigInfos().get(0), getSite(false).findFeature(ignoredFeatures[i], null, true));
76             } catch (CoreException e) {
77                 //Ignore
78
}
79         }
80     }
81
82     protected void generateIncludedFeatureBuildFile() throws CoreException {
83         IIncludedFeatureReference[] referencedFeatures = feature.getIncludedFeatureReferences();
84         for (int i = 0; i < referencedFeatures.length; i++) {
85             String JavaDoc featureId = ((IncludedFeatureReferenceModel) referencedFeatures[i]).getFeatureIdentifier();
86             FeatureBuildScriptGenerator generator = new PackagerBuildScriptGenerator(featureId, assemblyData);
87             generator.setGenerateIncludedFeatures(true);
88             generator.setAnalyseChildren(true);
89             generator.setSourceFeatureGeneration(false);
90             generator.setBinaryFeatureGeneration(true);
91             generator.setScriptGeneration(false);
92             generator.setPluginPath(pluginPath);
93             generator.setBuildSiteFactory(siteFactory);
94             generator.setDevEntries(devEntries);
95             generator.setCompiledElements(getCompiledElements());
96             generator.setBuildingOSGi(isBuildingOSGi());
97             try {
98                 generator.generate();
99             } catch (CoreException exception) {
100                 //If the referenced feature is not optional, there is a real problem and the exception is re-thrown.
101
if (exception.getStatus().getCode() == EXCEPTION_FEATURE_MISSING && !referencedFeatures[i].isOptional())
102                     throw exception;
103             }
104         }
105     }
106
107     public void setPropertyFile(String JavaDoc propertyFile) {
108         packagingPropertiesLocation = propertyFile;
109     }
110
111     public void setFeatureList(String JavaDoc features) {
112         featureList = Utils.getArrayFromString(features, ","); //$NON-NLS-1$
113
}
114
115     public void setRootFiles(String JavaDoc[] rootFiles) {
116         this.rootFiles = rootFiles;
117     }
118
119     public void setRootDirs(String JavaDoc[] rootDirs) {
120         this.rootDirs = rootDirs;
121     }
122
123     public void setOutput(String JavaDoc format) { //TODO To rename
124
this.outputFormat = format;
125     }
126
127     public void setIgnoredFeatures(String JavaDoc[] features) {
128         ignoredFeatures = features;
129     }
130
131     protected void collectElementToAssemble(IFeature featureToCollect) throws CoreException {
132         if (assemblyData == null)
133             return;
134         List JavaDoc correctConfigs = selectConfigs(featureToCollect);
135         // Here, we could sort if the feature is a common one or not by
136
// comparing the size of correctConfigs
137
for (Iterator JavaDoc iter = correctConfigs.iterator(); iter.hasNext();) {
138             Config config = (Config) iter.next();
139             assemblyData.addFeature(config, feature);
140         }
141     }
142 }
Popular Tags