1 11 package org.eclipse.pde.internal.build.packager; 12 13 import java.util.Iterator ; 14 import java.util.List ; 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 packagingPropertiesLocation; 25 private String [] featureList; 26 private String [] rootFiles; 27 private String [] rootDirs; 28 private String outputFormat = "zip"; private String [] ignoredFeatures; 30 31 public PackagerBuildScriptGenerator() { 32 super(); 33 } 34 35 public PackagerBuildScriptGenerator(String 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)); 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 } 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 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 (exception.getStatus().getCode() == EXCEPTION_FEATURE_MISSING && !referencedFeatures[i].isOptional()) 102 throw exception; 103 } 104 } 105 } 106 107 public void setPropertyFile(String propertyFile) { 108 packagingPropertiesLocation = propertyFile; 109 } 110 111 public void setFeatureList(String features) { 112 featureList = Utils.getArrayFromString(features, ","); } 114 115 public void setRootFiles(String [] rootFiles) { 116 this.rootFiles = rootFiles; 117 } 118 119 public void setRootDirs(String [] rootDirs) { 120 this.rootDirs = rootDirs; 121 } 122 123 public void setOutput(String format) { this.outputFormat = format; 125 } 126 127 public void setIgnoredFeatures(String [] features) { 128 ignoredFeatures = features; 129 } 130 131 protected void collectElementToAssemble(IFeature featureToCollect) throws CoreException { 132 if (assemblyData == null) 133 return; 134 List correctConfigs = selectConfigs(featureToCollect); 135 for (Iterator iter = correctConfigs.iterator(); iter.hasNext();) { 138 Config config = (Config) iter.next(); 139 assemblyData.addFeature(config, feature); 140 } 141 } 142 } | Popular Tags |