1 12 package org.eclipse.pde.internal.build.builder; 13 14 import java.io.*; 15 import java.net.URL ; 16 import java.util.*; 17 import java.util.jar.Attributes ; 18 import java.util.jar.Manifest ; 19 import org.eclipse.core.runtime.*; 20 import org.eclipse.osgi.service.resolver.BundleDescription; 21 import org.eclipse.osgi.util.NLS; 22 import org.eclipse.pde.build.Constants; 23 import org.eclipse.pde.internal.build.*; 24 import org.eclipse.pde.internal.build.ant.AntScript; 25 import org.eclipse.pde.internal.build.ant.FileSet; 26 import org.eclipse.pde.internal.build.site.BuildTimeFeature; 27 import org.eclipse.pde.internal.build.site.PDEState; 28 import org.eclipse.update.core.*; 29 import org.eclipse.update.core.model.IncludedFeatureReferenceModel; 30 import org.eclipse.update.core.model.URLEntryModel; 31 import org.osgi.framework.Version; 32 33 36 public class FeatureBuildScriptGenerator extends AbstractBuildScriptGenerator { 37 private static final String COMMENT_START_TAG = "<!--"; private static final String COMMENT_END_TAG = "-->"; private static final String FEATURE_START_TAG = "<feature"; private static final String PLUGIN_START_TAG = "<plugin"; private static final String FRAGMENT_START_TAG = "<fragment"; private static final String VERSION = "version"; private static final String PLUGIN_VERSION = "plugin-version"; 45 private static final String BASE_64_ENCODING = "-0123456789_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 48 private static final int QUALIFIER_SUFFIX_VERSION = 1; 49 50 55 protected boolean analyseIncludedFeatures = false; 56 60 protected boolean analysePlugins = true; 61 62 protected boolean sourceFeatureGeneration = false; 63 64 protected boolean binaryFeature = true; 65 66 private boolean scriptGeneration = true; 67 68 70 protected String featureIdentifier; 71 protected String searchedVersion; 72 73 protected IFeature feature; 74 75 protected String featureFullName; 76 protected String featureFolderName; 77 protected String featureRootLocation; 78 protected String featureTempFolder; 79 protected Feature sourceFeature; 80 protected PluginEntry sourcePlugin; 81 protected String sourceFeatureFullName; 82 protected String sourceFeatureFullNameVersionned; 83 protected SourceFeatureInformation sourceToGather; 84 protected boolean sourcePluginOnly = false; 85 private String [] extraPlugins = new String [0]; 86 private boolean generateJnlp = false; 87 private boolean signJars = false; 88 private boolean generateVersionSuffix = false; 89 90 private List computedElements = null; 92 private String customFeatureCallbacks = null; 93 private String customCallbacksBuildpath = null; 94 private String customCallbacksFailOnError = null; 95 private String customCallbacksInheritAll = null; 96 private String product = null; 97 private static final String TEMPLATE = "data"; 99 public FeatureBuildScriptGenerator() { 100 super(); 101 } 102 103 106 public FeatureBuildScriptGenerator(String featureId, String versionId, AssemblyInformation informationGathering) throws CoreException { 107 if (featureId == null) { 108 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_FEATURE_MISSING, Messages.error_missingFeatureId, null)); 109 } 110 this.featureIdentifier = featureId; 111 this.searchedVersion = versionId; 112 assemblyData = informationGathering; 113 } 114 115 121 protected List computeElements() throws CoreException { 122 if (computedElements != null) 123 return computedElements; 124 125 computedElements = new ArrayList(5); 126 IPluginEntry[] pluginList = feature.getPluginEntries(); 127 for (int i = 0; i < pluginList.length; i++) { 128 IPluginEntry entry = pluginList[i]; 129 VersionedIdentifier identifier = entry.getVersionedIdentifier(); 130 BundleDescription model; 131 if (selectConfigs(entry).size() == 0) 132 continue; 133 134 String versionRequested = identifier.getVersion().toString(); 135 model = getSite(false).getRegistry().getResolvedBundle(identifier.getIdentifier(), versionRequested); 136 if ((model == null || Utils.isBinary(model)) && getBuildProperties().containsKey(GENERATION_SOURCE_PLUGIN_PREFIX + identifier.getIdentifier())) { 138 generateEmbeddedSource(identifier.getIdentifier()); 139 model = getSite(false).getRegistry().getResolvedBundle(identifier.getIdentifier(), versionRequested); 140 } 141 if (model == null) { 142 String message = NLS.bind(Messages.exception_missingPlugin, entry.getVersionedIdentifier()); 143 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_PLUGIN_MISSING, message, null)); 144 } 145 146 associateModelAndEntry(model, entry); 147 148 computedElements.add(model); 149 collectElementToAssemble(pluginList[i]); 150 collectSourcePlugins(pluginList[i], model); 151 } 152 return computedElements; 153 } 154 155 private void associateModelAndEntry(BundleDescription model, IPluginEntry entry) { 156 Properties bundleProperties = ((Properties) model.getUserObject()); 157 if (bundleProperties == null) { 158 bundleProperties = new Properties(); 159 model.setUserObject(bundleProperties); 160 } 161 Set entries = (Set) bundleProperties.get(PLUGIN_ENTRY); 162 if (entries == null) { 163 entries = new HashSet(); 164 bundleProperties.put(PLUGIN_ENTRY, entries); 165 } 166 entries.add(entry); 167 } 168 169 private void generateEmbeddedSource(String pluginId) throws CoreException { 170 if (sourceFeatureGeneration) 171 return; 172 FeatureBuildScriptGenerator featureGenerator = new FeatureBuildScriptGenerator(Utils.getArrayFromString(getBuildProperties().getProperty(GENERATION_SOURCE_PLUGIN_PREFIX + pluginId))[0], null, assemblyData); 173 featureGenerator.setGenerateIncludedFeatures(false); 174 featureGenerator.setAnalyseChildren(analysePlugins); 175 featureGenerator.setSourceFeatureId(pluginId); 176 featureGenerator.setSourceFeatureGeneration(true); 177 featureGenerator.setExtraPlugins(Utils.getArrayFromString(getBuildProperties().getProperty(GENERATION_SOURCE_PLUGIN_PREFIX + pluginId))); 178 featureGenerator.setBinaryFeatureGeneration(false); 179 featureGenerator.setScriptGeneration(false); 180 featureGenerator.setPluginPath(pluginPath); 181 featureGenerator.setBuildSiteFactory(siteFactory); 182 featureGenerator.setDevEntries(devEntries); 183 featureGenerator.setCompiledElements(getCompiledElements()); 184 featureGenerator.setSourceToGather(sourceToGather); 185 featureGenerator.setSourcePluginOnly(true); 186 featureGenerator.setBuildingOSGi(isBuildingOSGi()); 187 featureGenerator.includePlatformIndependent(isPlatformIndependentIncluded()); 188 featureGenerator.setIgnoreMissingPropertiesFile(isIgnoreMissingPropertiesFile()); 189 featureGenerator.setGenerateVersionSuffix(generateVersionSuffix); 190 featureGenerator.generate(); 191 } 192 193 public void setSourcePluginOnly(boolean b) { 194 sourcePluginOnly = b; 195 } 196 197 private void collectSourcePlugins(IPluginEntry pluginEntry, BundleDescription model) { 198 if (!sourceFeatureGeneration) 199 return; 200 try { 202 if (AbstractScriptGenerator.readProperties(model.getLocation(), PROPERTIES_FILE, IStatus.OK) == MissingProperties.getInstance()) 203 return; 204 } catch (CoreException e) { 205 return; 206 } 207 if (pluginEntry.getOS() == null && pluginEntry.getWS() == null && pluginEntry.getOSArch() == null) { 210 sourceToGather.addElementEntry(Config.genericConfig(), model); 211 return; 212 } 213 List correctConfigs = selectConfigs(pluginEntry); 215 for (Iterator iter = correctConfigs.iterator(); iter.hasNext();) { 216 sourceToGather.addElementEntry((Config) iter.next(), model); 217 } 218 } 219 220 227 public void setAnalyseChildren(boolean generate) { 228 analysePlugins = generate; 229 } 230 231 234 public void generate() throws CoreException { 235 String message; 236 if (workingDirectory == null) { 237 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_BUILDDIRECTORY_LOCATION_MISSING, Messages.error_missingInstallLocation, null)); 238 } 239 initializeVariables(); 240 241 boolean custom = TRUE.equalsIgnoreCase((String ) getBuildProperties().get(PROPERTY_CUSTOM)); 244 File customBuildFile = null; 245 if (custom) { 246 customBuildFile = new File(featureRootLocation, DEFAULT_BUILD_SCRIPT_FILENAME); 247 if (!customBuildFile.exists()) { 248 message = NLS.bind(Messages.error_missingCustomBuildFile, customBuildFile); 249 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_SCRIPT, message, null)); 250 } 251 252 scriptGeneration = false; 254 255 256 List configs = getConfigInfos(); 257 for (Iterator iter = configs.iterator(); iter.hasNext();) { 258 assemblyData.addRootFileProvider((Config) iter.next(), feature); 259 } 260 } 261 if (analyseIncludedFeatures) 262 generateIncludedFeatureBuildFile(); 263 if (sourceFeatureGeneration) 264 generateSourceFeature(); 265 if (analysePlugins) 266 generateChildrenScripts(); 267 if (sourceFeatureGeneration) { 268 addSourceFragmentsToFeature(); 269 writeSourceFeature(); 270 } 271 if (!sourcePluginOnly) 272 collectElementToAssemble(feature); 273 274 if (sourceFeatureGeneration) 276 generateSourceFeatureScripts(); 277 278 if (custom) { 279 try { 282 updateVersion(customBuildFile, PROPERTY_FEATURE_VERSION_SUFFIX, feature.getVersionedIdentifier().getVersion().toString()); 283 } catch (IOException e) { 284 message = NLS.bind(Messages.exception_writeScript, customBuildFile); 285 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_SCRIPT, message, e)); 286 } 287 } 288 289 if (scriptGeneration) { 290 openScript(featureRootLocation, DEFAULT_BUILD_SCRIPT_FILENAME); 291 try { 292 generateBuildScript(); 293 } finally { 294 closeScript(); 295 } 296 } 297 } 298 299 protected void generateIncludedFeatureBuildFile() throws CoreException { 300 IIncludedFeatureReference[] referencedFeatures = feature.getIncludedFeatureReferences(); 301 for (int i = 0; i < referencedFeatures.length; i++) { 302 String featureId = ((IncludedFeatureReferenceModel) referencedFeatures[i]).getFeatureIdentifier(); 303 String featureVersion = ((IncludedFeatureReferenceModel) referencedFeatures[i]).getFeatureVersion(); 304 boolean doSourceFeatureGeneration = getBuildProperties().containsKey(GENERATION_SOURCE_FEATURE_PREFIX + featureId); 307 FeatureBuildScriptGenerator generator = new FeatureBuildScriptGenerator(doSourceFeatureGeneration == true ? Utils.getArrayFromString(getBuildProperties().getProperty(GENERATION_SOURCE_FEATURE_PREFIX + featureId))[0] : featureId, featureVersion, assemblyData); 308 generator.setGenerateIncludedFeatures(doSourceFeatureGeneration ? false : true); 310 generator.setAnalyseChildren(analysePlugins); 311 generator.setSourceFeatureGeneration(doSourceFeatureGeneration); 312 generator.setBinaryFeatureGeneration(!doSourceFeatureGeneration); 313 generator.setScriptGeneration(doSourceFeatureGeneration ? false : true); 315 if (doSourceFeatureGeneration) { 316 generator.setSourceFeatureId(featureId); 317 generator.setExtraPlugins(Utils.getArrayFromString(getBuildProperties().getProperty(GENERATION_SOURCE_FEATURE_PREFIX + featureId))); 318 } 319 generator.setPluginPath(pluginPath); 320 generator.setBuildSiteFactory(siteFactory); 321 generator.setDevEntries(devEntries); 322 generator.setCompiledElements(getCompiledElements()); 323 generator.setSourceToGather(new SourceFeatureInformation()); 324 generator.setBuildingOSGi(isBuildingOSGi()); 325 generator.includePlatformIndependent(isPlatformIndependentIncluded()); 326 generator.setIgnoreMissingPropertiesFile(isIgnoreMissingPropertiesFile()); 327 generator.setGenerateVersionSuffix(generateVersionSuffix); 328 try { 329 generator.generate(); 330 } catch (CoreException exception) { 331 absorbExceptionIfOptionalFeature(referencedFeatures[i], exception); 332 } 333 } 334 } 335 336 private void absorbExceptionIfOptionalFeature(IIncludedFeatureReference feature, CoreException toAbsorb) throws CoreException { 337 if (toAbsorb.getStatus().getCode() != EXCEPTION_FEATURE_MISSING || (toAbsorb.getStatus().getCode() == EXCEPTION_FEATURE_MISSING && !feature.isOptional())) 338 throw toAbsorb; 339 } 340 341 protected void setExtraPlugins(String [] plugins) { 342 extraPlugins = plugins; 343 } 344 345 350 private void generateBuildScript() throws CoreException { 351 if (BundleHelper.getDefault().isDebugging()) 352 System.out.println("Generating feature " + featureFullName); generatePrologue(); 354 generateAllPluginsTarget(); 355 generateAllFeaturesTarget(); 356 generateUpdateFeatureFile(); 357 generateAllChildrenTarget(); 358 generateChildrenTarget(); 359 generateBuildJarsTarget(); 360 generateBuildZipsTarget(); 361 generateBuildUpdateJarTarget(); 362 generateGatherBinPartsTarget(); 363 generateZipDistributionWholeTarget(); 364 generateZipSourcesTarget(); 365 generateZipLogsTarget(); 366 generateCleanTarget(); 367 generateRefreshTarget(); 368 generateGatherSourcesTarget(); 369 generateGatherLogsTarget(); 370 generateEpilogue(); 371 } 372 373 377 private void generateGatherSourcesTarget() { 378 script.printTargetDeclaration(TARGET_GATHER_SOURCES, null, null, null, null); 379 Map params = new HashMap(2); 380 params.put(PROPERTY_DESTINATION_TEMP_FOLDER, Utils.getPropertyFormat(PROPERTY_FEATURE_TEMP_FOLDER) + '/' + DEFAULT_PLUGIN_LOCATION + '/' + sourceFeatureFullNameVersionned + '/' + "src"); params.put(PROPERTY_TARGET, TARGET_GATHER_SOURCES); 382 script.printAntCallTask(TARGET_CHILDREN, true, params); 383 script.printTargetEnd(); 384 } 385 386 390 private void generateGatherLogsTarget() { 391 script.println(); 392 script.printTargetDeclaration(TARGET_GATHER_LOGS, TARGET_INIT, null, null, null); 393 script.printMkdirTask(featureTempFolder); 394 Map params = new HashMap(1); 395 params.put(PROPERTY_TARGET, TARGET_GATHER_LOGS); 396 params.put(PROPERTY_DESTINATION_TEMP_FOLDER, new Path(featureTempFolder).append(DEFAULT_PLUGIN_LOCATION).toString()); 397 script.printAntCallTask(TARGET_ALL_CHILDREN, false, params); script.printTargetEnd(); 399 } 400 401 private void generateUpdateFeatureFile() { 402 script.printTargetDeclaration(TARGET_UPDATE_FEATURE_FILE, TARGET_INIT, null, null, null); 403 script.printTargetEnd(); 404 } 405 406 411 private void generateBuildZipsTarget() throws CoreException { 412 StringBuffer zips = new StringBuffer (); 413 Properties props = getBuildProperties(); 414 for (Iterator iterator = props.entrySet().iterator(); iterator.hasNext();) { 415 Map.Entry entry = (Map.Entry) iterator.next(); 416 String key = (String ) entry.getKey(); 417 if (key.startsWith(PROPERTY_SOURCE_PREFIX) && key.endsWith(PROPERTY_ZIP_SUFFIX)) { 418 String zipName = key.substring(PROPERTY_SOURCE_PREFIX.length()); 419 zips.append(','); 420 zips.append(zipName); 421 generateZipIndividualTarget(zipName, (String ) entry.getValue()); 422 } 423 } 424 script.println(); 425 script.printTargetDeclaration(TARGET_BUILD_ZIPS, TARGET_INIT + zips.toString(), null, null, null); 426 Map params = new HashMap(2); 427 params.put(PROPERTY_TARGET, TARGET_BUILD_ZIPS); 428 script.printAntCallTask(TARGET_ALL_CHILDREN, true, params); 429 script.printTargetEnd(); 430 } 431 432 438 private void generateZipIndividualTarget(String zipName, String source) { 439 script.println(); 440 script.printTargetDeclaration(zipName, TARGET_INIT, null, null, null); 441 script.printZipTask(Utils.getPropertyFormat(PROPERTY_BASEDIR) + '/' + zipName, Utils.getPropertyFormat(PROPERTY_BASEDIR) + '/' + source, false, false, null); 442 script.printTargetEnd(); 443 } 444 445 448 private void generateCleanTarget() { 449 script.println(); 450 script.printTargetDeclaration(TARGET_CLEAN, TARGET_INIT, null, null, NLS.bind(Messages.build_feature_clean, featureIdentifier)); 451 script.printDeleteTask(null, Utils.getPropertyFormat(PROPERTY_FEATURE_DESTINATION) + '/' + featureFullName + ".jar", null); script.printDeleteTask(null, Utils.getPropertyFormat(PROPERTY_FEATURE_DESTINATION) + '/' + featureFullName + ".bin.dist.zip", null); script.printDeleteTask(null, Utils.getPropertyFormat(PROPERTY_FEATURE_DESTINATION) + '/' + featureFullName + ".log.zip", null); script.printDeleteTask(null, Utils.getPropertyFormat(PROPERTY_FEATURE_DESTINATION) + '/' + featureFullName + ".src.zip", null); script.printDeleteTask(featureTempFolder, null, null); 456 Map params = new HashMap(2); 457 params.put(PROPERTY_TARGET, TARGET_CLEAN); 458 script.printAntCallTask(TARGET_ALL_CHILDREN, true, params); 459 script.printTargetEnd(); 460 } 461 462 465 private void generateZipLogsTarget() { 466 script.println(); 467 script.printTargetDeclaration(TARGET_ZIP_LOGS, TARGET_INIT, null, null, null); 468 script.printDeleteTask(featureTempFolder, null, null); 469 script.printMkdirTask(featureTempFolder); 470 Map params = new HashMap(1); 471 params.put(PROPERTY_INCLUDE_CHILDREN, "true"); params.put(PROPERTY_TARGET, TARGET_GATHER_LOGS); 473 params.put(PROPERTY_DESTINATION_TEMP_FOLDER, new Path(featureTempFolder).append(DEFAULT_PLUGIN_LOCATION).toString()); 474 script.printAntCallTask(TARGET_ALL_CHILDREN, false, params); IPath destination = new Path(Utils.getPropertyFormat(PROPERTY_FEATURE_DESTINATION)).append(featureFullName + ".log.zip"); script.printZipTask(destination.toString(), featureTempFolder, true, false, null); 477 script.printDeleteTask(featureTempFolder, null, null); 478 script.printTargetEnd(); 479 } 480 481 484 protected void generateZipSourcesTarget() { 485 script.println(); 486 script.printTargetDeclaration(TARGET_ZIP_SOURCES, TARGET_INIT, null, null, null); 487 script.printDeleteTask(featureTempFolder, null, null); 488 script.printMkdirTask(featureTempFolder); 489 Map params = new HashMap(1); 490 params.put(PROPERTY_INCLUDE_CHILDREN, "true"); params.put(PROPERTY_TARGET, TARGET_GATHER_SOURCES); 492 params.put(PROPERTY_DESTINATION_TEMP_FOLDER, featureTempFolder + '/' + DEFAULT_PLUGIN_LOCATION + '/' + sourceFeatureFullNameVersionned + '/' + "src"); script.printAntCallTask(TARGET_ALL_CHILDREN, true, params); 494 script.printZipTask(Utils.getPropertyFormat(PROPERTY_FEATURE_DESTINATION) + '/' + featureFullName + ".src.zip", featureTempFolder, true, false, null); script.printDeleteTask(featureTempFolder, null, null); 496 script.printTargetEnd(); 497 } 498 499 504 private void generateGatherBinPartsTarget() throws CoreException { 505 String include = (String ) getBuildProperties().get(PROPERTY_BIN_INCLUDES); 506 String exclude = (String ) getBuildProperties().get(PROPERTY_BIN_EXCLUDES); 507 String root = Utils.getPropertyFormat(PROPERTY_FEATURE_BASE) + '/' + featureFolderName; 508 509 script.println(); 510 script.printTargetDeclaration(TARGET_GATHER_BIN_PARTS, TARGET_INIT, PROPERTY_FEATURE_BASE, null, null); 511 if (include != null) 512 script.printMkdirTask(root); 513 514 Map callbackParams = null; 515 if (customFeatureCallbacks != null) { 516 callbackParams = new HashMap(1); 517 callbackParams.put(PROPERTY_DESTINATION_TEMP_FOLDER, new Path(Utils.getPropertyFormat(PROPERTY_FEATURE_BASE)).append(DEFAULT_PLUGIN_LOCATION).toString()); 518 callbackParams.put(PROPERTY_FEATURE_DIRECTORY, root); 519 script.printSubantTask(Utils.getPropertyFormat(PROPERTY_CUSTOM_BUILD_CALLBACKS), PROPERTY_PRE + TARGET_GATHER_BIN_PARTS, customCallbacksBuildpath, customCallbacksFailOnError, customCallbacksInheritAll, callbackParams, null); 520 } 521 522 Map params = new HashMap(1); 523 params.put(PROPERTY_TARGET, TARGET_GATHER_BIN_PARTS); 524 params.put(PROPERTY_DESTINATION_TEMP_FOLDER, new Path(Utils.getPropertyFormat(PROPERTY_FEATURE_BASE)).append(DEFAULT_PLUGIN_LOCATION).toString()); 525 script.printAntCallTask(TARGET_CHILDREN, true, params); 526 527 if (include != null) { 528 if (include != null || exclude != null) { 529 FileSet fileSet = new FileSet(Utils.getPropertyFormat(PROPERTY_BASEDIR), null, include, null, exclude, null, null); 530 script.printCopyTask(null, root, new FileSet[] {fileSet}, true, false); 531 } 532 String featureVersionInfo = ""; IIncludedFeatureReference[] includedFeatures = feature.getRawIncludedFeatureReferences(); 536 for (int i = 0; i < includedFeatures.length; i++) { 537 String versionRequested = includedFeatures[i].getVersionedIdentifier().getVersion().toString(); 538 IFeature includedFeature = null; 539 try { 540 includedFeature = getSite(false).findFeature(includedFeatures[i].getVersionedIdentifier().getIdentifier(), versionRequested, true); 541 } catch (CoreException e) { 542 absorbExceptionIfOptionalFeature(includedFeatures[i], e); 543 continue; 544 } 545 VersionedIdentifier includedFeatureVersionId = includedFeature.getVersionedIdentifier(); 546 if (needsReplacement(versionRequested)) 547 featureVersionInfo += (includedFeatureVersionId.getIdentifier() + ':' + extract3Segments(versionRequested) + ',' + includedFeatureVersionId.getVersion().toString() + ','); 548 } 549 String pluginVersionInfo = ""; IPluginEntry[] pluginsIncluded = feature.getRawPluginEntries(); 552 for (int i = 0; i < pluginsIncluded.length; i++) { 553 VersionedIdentifier identifier = pluginsIncluded[i].getVersionedIdentifier(); 554 BundleDescription model; 555 String versionRequested = identifier.getVersion().toString(); 557 String entryIdentifier = identifier.getIdentifier(); 558 model = getSite(false).getRegistry().getResolvedBundle(entryIdentifier, versionRequested); 559 if (model != null) { 560 if (needsReplacement(versionRequested)) 561 pluginVersionInfo += (entryIdentifier + ':' + extract3Segments(versionRequested) + ',' + model.getVersion() + ','); 562 } 563 } 564 script.println("<eclipse.idReplacer featureFilePath=\"" + AntScript.getEscaped(root) + '/' + Constants.FEATURE_FILENAME_DESCRIPTOR + "\" selfVersion=\"" + feature.getVersionedIdentifier().getVersion() + "\" featureIds=\"" + featureVersionInfo + "\" pluginIds=\"" + pluginVersionInfo + "\"/>"); } 566 generateRootFilesAndPermissionsCalls(); 567 if (customFeatureCallbacks != null) { 568 script.printSubantTask(Utils.getPropertyFormat(PROPERTY_CUSTOM_BUILD_CALLBACKS), PROPERTY_POST + TARGET_GATHER_BIN_PARTS, customCallbacksBuildpath, customCallbacksFailOnError, customCallbacksInheritAll, callbackParams, null); 569 } 570 script.printTargetEnd(); 571 generateRootFilesAndPermissions(); 572 } 573 574 private boolean needsReplacement(String s) { 575 if (s.equalsIgnoreCase(GENERIC_VERSION_NUMBER) || s.endsWith(PROPERTY_QUALIFIER)) 576 return true; 577 return false; 578 } 579 580 private Version extract3Segments(String s) { 581 Version tmp = new Version(s); 582 return new Version(tmp.getMajor(), tmp.getMinor(), tmp.getMicro()); 583 } 584 585 588 private void generateRootFilesAndPermissionsCalls() { 589 script.printAntCallTask(TARGET_ROOTFILES_PREFIX + Utils.getPropertyFormat(PROPERTY_OS) + '_' + Utils.getPropertyFormat(PROPERTY_WS) + '_' + Utils.getPropertyFormat(PROPERTY_ARCH), true, null); 590 } 591 592 595 private void generateRootFilesAndPermissions() throws CoreException { 596 if (product != null && !havePDEUIState()) { 597 ProductGenerator generator = new ProductGenerator(); 598 generator.setProduct(product); 599 generator.setBuildSiteFactory(siteFactory); 600 generator.setBuildProperties(getBuildProperties()); 601 generator.setRoot(featureRootLocation); 602 generator.setWorkingDirectory(getWorkingDirectory()); 603 try { 604 generator.generate(); 605 } catch (CoreException e) { 606 } 609 } 610 for (Iterator iter = getConfigInfos().iterator(); iter.hasNext();) { 611 Config aConfig = (Config) iter.next(); 612 script.printTargetDeclaration(TARGET_ROOTFILES_PREFIX + aConfig.toString("_"), null, null, null, null); generateCopyRootFiles(aConfig); 614 Utils.generatePermissions(getBuildProperties(), aConfig, PROPERTY_FEATURE_BASE, script); 615 script.printTargetEnd(); 616 } 617 script.printTargetDeclaration(TARGET_ROOTFILES_PREFIX + "group_group_group", null, null, null, null); for (Iterator iter = getConfigInfos().iterator(); iter.hasNext();) { 619 Config aConfig = (Config) iter.next(); 620 script.printAntCallTask(TARGET_ROOTFILES_PREFIX + aConfig.toString("_"), true, null); } 622 script.printTargetEnd(); 623 } 624 625 private void generateCopyRootFiles(Config aConfig) throws CoreException { 626 Properties properties = getBuildProperties(); 627 Map foldersToCopy = new HashMap(2); 628 629 630 String baseList = getBuildProperties().getProperty(ROOT, ""); String fileList = getBuildProperties().getProperty(ROOT_PREFIX + aConfig.toString("."), ""); fileList = (fileList.length() == 0 ? "" : fileList + ',') + baseList; if (fileList.length() > 0) 634 foldersToCopy.put("", fileList); 636 637 String configPrefix = ROOT_PREFIX + aConfig.toString(".") + FOLDER_INFIX; for (Iterator it = properties.keySet().iterator(); it.hasNext();) { 639 String key = (String ) it.next(); 640 String folder = null; 641 if (key.startsWith(ROOT_FOLDER_PREFIX)) { 642 folder = key.substring(ROOT_FOLDER_PREFIX.length(), key.length()); 643 } else if (key.startsWith(configPrefix)) { 644 folder = key.substring(configPrefix.length(), key.length()); 645 } 646 if (folder != null) { 647 String value = properties.getProperty(key); 648 if (foldersToCopy.containsKey(folder)) { 649 String set = (String ) foldersToCopy.get(folder); 650 set += "," + value; foldersToCopy.put(folder, set); 652 } else { 653 foldersToCopy.put(folder, value); 654 } 655 } 656 } 657 658 if (foldersToCopy.isEmpty()) 659 return; 660 661 String configName = aConfig.toStringReplacingAny(".", ANY_STRING); String shouldOverwrite = properties.getProperty(PROPERTY_OVERWRITE_ROOTFILES, "true"); boolean overwrite = Boolean.valueOf(shouldOverwrite).booleanValue(); 664 665 assemblyData.addRootFileProvider(aConfig, feature); 666 667 Object [] folders = foldersToCopy.keySet().toArray(); 668 for (int i = 0; i < folders.length; i++) { 669 String folder = (String ) folders[i]; 670 fileList = (String ) foldersToCopy.get(folder); 671 String [] files = Utils.getArrayFromString(fileList, ","); FileSet[] fileSet = new FileSet[files.length]; 673 for (int j = 0; j < files.length; j++) { 674 String file = files[j]; 675 String fromDir = Utils.getPropertyFormat(PROPERTY_BASEDIR) + '/'; 676 if (file.startsWith("absolute:")) { file = file.substring(9); 678 fromDir = ""; } 680 if (file.startsWith("file:")) { IPath target = new Path(file.substring(5)); 682 fileSet[j] = new FileSet(fromDir + target.removeLastSegments(1), null, target.lastSegment(), null, null, null, null); 683 } else { 684 fileSet[j] = new FileSet(fromDir + file, null, "**", null, null, null, null); } 686 } 687 script.printMkdirTask(Utils.getPropertyFormat(PROPERTY_FEATURE_BASE) + '/' + configName + '/' + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER) + '/' + folder); 688 script.printCopyTask(null, Utils.getPropertyFormat(PROPERTY_FEATURE_BASE) + '/' + configName + '/' + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER) + '/' + folder, fileSet, true, overwrite); 689 } 690 } 691 692 695 private void generateBuildUpdateJarTarget() { 696 script.println(); 697 script.printTargetDeclaration(TARGET_BUILD_UPDATE_JAR, TARGET_INIT, null, null, NLS.bind(Messages.build_feature_buildUpdateJar, featureIdentifier)); 698 Map params = new HashMap(1); 699 params.put(PROPERTY_TARGET, TARGET_BUILD_UPDATE_JAR); 700 script.printAntCallTask(TARGET_ALL_CHILDREN, true, params); 701 script.printProperty(PROPERTY_FEATURE_BASE, featureTempFolder); 702 script.printDeleteTask(featureTempFolder, null, null); 703 script.printMkdirTask(featureTempFolder); 704 params.clear(); 705 params.put(PROPERTY_FEATURE_BASE, featureTempFolder); 706 params.put(PROPERTY_OS, feature.getOS() == null ? Config.ANY : feature.getOS()); 707 params.put(PROPERTY_WS, feature.getWS() == null ? Config.ANY : feature.getWS()); 708 params.put(PROPERTY_ARCH, feature.getOSArch() == null ? Config.ANY : feature.getOSArch()); 709 params.put(PROPERTY_NL, feature.getNL() == null ? Config.ANY : feature.getNL()); 710 script.printAntCallTask(TARGET_GATHER_BIN_PARTS, false, params); 715 String jar = Utils.getPropertyFormat(PROPERTY_FEATURE_DESTINATION) + '/' + featureFullName + ".jar"; script.printJarTask(jar, featureTempFolder + '/' + featureFolderName, null); 717 script.printDeleteTask(featureTempFolder, null, null); 718 if (generateJnlp) 719 script.println("<eclipse.jnlpGenerator feature=\"" + AntScript.getEscaped(jar) + "\" codebase=\"" + Utils.getPropertyFormat(IXMLConstants.PROPERTY_JNLP_CODEBASE) + "\" j2se=\"" + Utils.getPropertyFormat(IXMLConstants.PROPERTY_JNLP_J2SE) + "\" locale=\"" + Utils.getPropertyFormat(IXMLConstants.PROPERTY_JNLP_LOCALE) + "\" generateOfflineAllowed=\"" + Utils.getPropertyFormat(PROPERTY_JNLP_GENOFFLINE) + "\" configInfo=\"" + Utils.getPropertyFormat(PROPERTY_JNLP_CONFIGS) + "\"/>"); if (signJars) { 721 if (generateJnlp) { 722 script.printProperty(PROPERTY_UNSIGN, "true"); } 724 script.println("<eclipse.jarProcessor sign=\"" + Utils.getPropertyFormat(PROPERTY_SIGN) + "\" pack=\"" + Utils.getPropertyFormat(PROPERTY_PACK)+ "\" unsign=\"" + Utils.getPropertyFormat(PROPERTY_UNSIGN) + "\" jar=\"" + AntScript.getEscaped(jar) + "\" alias=\"" + Utils.getPropertyFormat(PROPERTY_SIGN_ALIAS) + "\" keystore=\"" + Utils.getPropertyFormat(PROPERTY_SIGN_KEYSTORE) + "\" storepass=\"" + Utils.getPropertyFormat(PROPERTY_SIGN_STOREPASS) + "\"/>"); } 726 script.printTargetEnd(); 727 } 728 729 733 protected void generateZipDistributionWholeTarget() { 734 script.println(); 735 script.printTargetDeclaration(TARGET_ZIP_DISTRIBUTION, TARGET_INIT, null, null, NLS.bind(Messages.build_feature_zips, featureIdentifier)); 736 script.printDeleteTask(featureTempFolder, null, null); 737 script.printMkdirTask(featureTempFolder); 738 Map params = new HashMap(1); 739 params.put(PROPERTY_FEATURE_BASE, featureTempFolder); 740 params.put(PROPERTY_INCLUDE_CHILDREN, TRUE); 741 params.put(PROPERTY_OS, feature.getOS() == null ? Config.ANY : feature.getOS()); 742 params.put(PROPERTY_WS, feature.getWS() == null ? Config.ANY : feature.getWS()); 743 params.put(PROPERTY_ARCH, feature.getOSArch() == null ? Config.ANY : feature.getOSArch()); 744 params.put(PROPERTY_NL, feature.getNL() == null ? Config.ANY : feature.getNL()); 745 script.printAntCallTask(TARGET_GATHER_BIN_PARTS, true, params); 746 script.printZipTask(Utils.getPropertyFormat(PROPERTY_FEATURE_DESTINATION) + '/' + featureFullName + ".bin.dist.zip", featureTempFolder, false, false, null); script.printDeleteTask(featureTempFolder, null, null); 748 script.printTargetEnd(); 749 } 750 751 754 private void generateAllChildrenTarget() { 755 StringBuffer depends = new StringBuffer (); 756 depends.append(TARGET_INIT); 757 depends.append(','); 758 depends.append(TARGET_ALL_FEATURES); 759 depends.append(','); 760 depends.append(TARGET_ALL_PLUGINS); 761 depends.append(','); 762 depends.append(TARGET_UPDATE_FEATURE_FILE); 763 script.println(); 764 script.printTargetDeclaration(TARGET_ALL_CHILDREN, depends.toString(), null, null, null); 765 script.printTargetEnd(); 766 } 767 768 775 protected void generateAllPluginsTarget() throws CoreException { 776 List plugins = computeElements(); 777 plugins = Utils.extractPlugins(getSite(false).getRegistry().getSortedBundles(), plugins); 778 script.println(); 779 script.printTargetDeclaration(TARGET_ALL_PLUGINS, TARGET_INIT, null, null, null); 780 Set writtenCalls = new HashSet(plugins.size()); 781 for (Iterator iter = plugins.iterator(); iter.hasNext();) { 782 BundleDescription current = (BundleDescription) iter.next(); 783 Properties bundleProperties = (Properties) current.getUserObject(); 785 if (bundleProperties == null || bundleProperties.get(IS_COMPILED) == null || bundleProperties.get(IS_COMPILED) == Boolean.FALSE) 786 continue; 787 if (writtenCalls.contains(current)) 789 continue; 790 writtenCalls.add(current); 791 IPluginEntry[] entries = Utils.getPluginEntry(feature, current.getSymbolicName(), false); for (int j = 0; j < entries.length; j++) { 793 List list = selectConfigs(entries[j]); 794 if (list.size() == 0) 795 continue; 796 Map params = null; 797 Config aMatchingConfig = (Config) list.get(0); 798 params = new HashMap(3); 799 if (!aMatchingConfig.getOs().equals(Config.ANY)) 800 params.put(PROPERTY_OS, aMatchingConfig.getOs()); 801 if (!aMatchingConfig.getWs().equals(Config.ANY)) 802 params.put(PROPERTY_WS, aMatchingConfig.getWs()); 803 if (!aMatchingConfig.getArch().equals(Config.ANY)) 804 params.put(PROPERTY_ARCH, aMatchingConfig.getArch()); 805 IPath location = Utils.makeRelative(new Path(getLocation(current)), new Path(featureRootLocation)); 806 script.printAntTask(DEFAULT_BUILD_SCRIPT_FILENAME, location.toString(), Utils.getPropertyFormat(PROPERTY_TARGET), null, null, params); 807 } 808 } 809 script.printTargetEnd(); 810 } 811 812 private void generateAllFeaturesTarget() throws CoreException { 813 script.printTargetDeclaration(TARGET_ALL_FEATURES, TARGET_INIT, null, null, null); 814 if (analyseIncludedFeatures) { 815 IIncludedFeatureReference[] features = feature.getIncludedFeatureReferences(); 816 for (int i = 0; i < features.length; i++) { 817 String featureId = features[i].getVersionedIdentifier().getIdentifier(); 818 String versionId = features[i].getVersionedIdentifier().getVersion().toString(); 819 IFeature includedFeature = getSite(false).findFeature(featureId, versionId, false); 820 if (includedFeature == null) { 821 if (features[i].isOptional()) 822 continue; 823 String message = NLS.bind(Messages.exception_missingFeature, featureId + ' ' + versionId); 824 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_FEATURE_MISSING, message, null)); 825 } 826 if (includedFeature instanceof BuildTimeFeature) { 827 if (((BuildTimeFeature) includedFeature).isBinary()) 828 continue; 829 } 830 831 String includedFeatureDirectory = includedFeature.getURL().getPath(); 832 int j = includedFeatureDirectory.lastIndexOf(Constants.FEATURE_FILENAME_DESCRIPTOR); 833 if (j != -1) 834 includedFeatureDirectory = includedFeatureDirectory.substring(0, j); 835 IPath location; 836 location = Utils.makeRelative(new Path(includedFeatureDirectory), new Path(featureRootLocation)); 837 script.printAntTask(DEFAULT_BUILD_SCRIPT_FILENAME, location.toString(), Utils.getPropertyFormat(PROPERTY_TARGET), null, null, null); 838 } 839 } 840 script.printTargetEnd(); 841 } 842 843 846 private void generateEpilogue() { 847 script.println(); 848 script.printProjectEnd(); 849 } 850 851 854 private void generatePrologue() { 855 script.printProjectDeclaration(feature.getVersionedIdentifier().getIdentifier(), TARGET_BUILD_UPDATE_JAR, "."); script.println(); 857 script.printTargetDeclaration(TARGET_INIT, null, null, null, null); 858 script.printProperty(PROPERTY_FEATURE_TEMP_FOLDER, Utils.getPropertyFormat(PROPERTY_BASEDIR) + '/' + PROPERTY_FEATURE_TEMP_FOLDER); 859 script.printProperty(PROPERTY_FEATURE_DESTINATION, Utils.getPropertyFormat(PROPERTY_BASEDIR)); 860 if (customFeatureCallbacks != null) { 861 script.printAvailableTask(PROPERTY_CUSTOM_BUILD_CALLBACKS, customCallbacksBuildpath + '/' + customFeatureCallbacks, customFeatureCallbacks); 862 } 863 script.printTargetEnd(); 864 } 865 866 869 private void generateChildrenScripts() throws CoreException { 870 List plugins = computeElements(); 871 String suffix = generateFeatureVersionSuffix((BuildTimeFeature) feature); 872 if (suffix != null) { 873 PluginVersionIdentifier versionId = feature.getVersionedIdentifier().getVersion(); 874 String qualifier = versionId.getQualifierComponent(); 875 qualifier = qualifier.substring(0, ((BuildTimeFeature) feature).getContextQualifierLength()); 876 qualifier = qualifier + '-' + suffix; 877 versionId = new PluginVersionIdentifier(versionId.getMajorComponent(), versionId.getMinorComponent(), versionId.getServiceComponent(), qualifier); 878 String newVersion = versionId.toString(); 879 ((BuildTimeFeature) feature).setFeatureVersion(newVersion); 880 initializeFeatureNames(); } 882 generateModels(Utils.extractPlugins(getSite(false).getRegistry().getSortedBundles(), plugins)); 883 } 884 885 private static char base64Character(int number) { 888 if (number < 0 || number > 63) { 889 return ' '; 890 } 891 return BASE_64_ENCODING.charAt(number); 892 } 893 894 private static String lengthPrefixBase64(long number) { 916 int length = 7; 917 for (int i = 0; i < 7; ++i) { 918 if (number < (1L << ((i * 6) + 3))) { 919 length = i; 920 break; 921 } 922 } 923 StringBuffer result = new StringBuffer (length + 1); 924 result.append(base64Character((length << 3) + (int) ((number >> (6 * length)) & 0x7))); 925 while (--length >= 0) { 926 result.append(base64Character((int) ((number >> (6 * length)) & 0x3f))); 927 } 928 return result.toString(); 929 } 930 931 private static int charValue(char c) { 932 int index = BASE_64_ENCODING.indexOf(c); 933 return index + 1; 938 } 939 940 private static void appendEncodedCharacter(StringBuffer buffer, int c) { 941 while (c > 62) { 942 buffer.append('z'); 943 c -= 63; 944 } 945 buffer.append(base64Character(c)); 946 } 947 948 private static int getIntProperty(String property, int defaultValue) { 949 int result = defaultValue; 950 if (property != null) { 951 try { 952 result = Integer.parseInt(property); 953 if (result < 1) { 954 result = defaultValue; 956 } 957 } catch (NumberFormatException e) { 958 } 960 } 961 return result; 962 } 963 964 private String generateFeatureVersionSuffix(BuildTimeFeature buildFeature) throws CoreException { 965 if (!generateVersionSuffix || buildFeature.getContextQualifierLength() == -1) { 966 return null; } 968 969 Properties properties = getBuildProperties(); 970 int significantDigits = getIntProperty((String ) properties.get(PROPERTY_SIGNIFICANT_VERSION_DIGITS), -1); 971 if (significantDigits == -1) 972 significantDigits = getIntProperty(AbstractScriptGenerator.getImmutableAntProperty(PROPERTY_SIGNIFICANT_VERSION_DIGITS), Integer.MAX_VALUE); 973 int maxGeneratedLength = getIntProperty((String ) properties.get(PROPERTY_GENERATED_VERSION_LENGTH), -1); 974 if (maxGeneratedLength == -1) 975 maxGeneratedLength = getIntProperty(AbstractScriptGenerator.getImmutableAntProperty(PROPERTY_GENERATED_VERSION_LENGTH), 28); 976 977 long majorSum = 0L; 978 long minorSum = 0L; 979 long serviceSum = 0L; 980 981 majorSum += QUALIFIER_SUFFIX_VERSION; 985 986 IIncludedFeatureReference[] referencedFeatures = buildFeature.getIncludedFeatureReferences(); 987 IPluginEntry[] pluginList = buildFeature.getRawPluginEntries(); 988 int numElements = pluginList.length + referencedFeatures.length; 989 if (numElements == 0) { 990 return null; 992 } 993 String [] qualifiers = new String [numElements]; 994 int idx = -1; 995 996 for (int i = 0; i < referencedFeatures.length; i++) { 999 BuildTimeFeature refFeature = (BuildTimeFeature) getSite(false).findFeature(referencedFeatures[i].getVersionedIdentifier().getIdentifier(), null, false); 1000 if (refFeature == null) { 1001 qualifiers[++idx] = ""; continue; 1003 } 1004 PluginVersionIdentifier version = refFeature.getVersionedIdentifier().getVersion(); 1005 majorSum += version.getMajorComponent(); 1006 minorSum += version.getMinorComponent(); 1007 serviceSum += version.getServiceComponent(); 1008 int contextLength = refFeature.getContextQualifierLength(); 1009 ++contextLength; String qualifier = version.getQualifierComponent(); 1011 if (qualifier.length() > contextLength) { 1018 qualifiers[++idx] = qualifier.substring(contextLength); 1020 } else { 1021 qualifiers[++idx] = qualifier; 1023 } 1024 } 1025 1026 1029 for (int i = 0; i < pluginList.length; i++) { 1030 IPluginEntry entry = pluginList[i]; 1031 VersionedIdentifier identifier = entry.getVersionedIdentifier(); 1032 String versionRequested = identifier.getVersion().toString(); 1033 BundleDescription model = getSite(false).getRegistry().getBundle(identifier.getIdentifier(), versionRequested, false); 1034 Version version = null; 1035 if (model != null) { 1036 version = model.getVersion(); 1037 } else { 1038 if (versionRequested.endsWith(PROPERTY_QUALIFIER)) { 1039 int resultingLength = versionRequested.length() - PROPERTY_QUALIFIER.length(); 1040 if (versionRequested.charAt(resultingLength - 1) == '.') 1041 resultingLength--; 1042 versionRequested = versionRequested.substring(0, resultingLength); 1043 } 1044 version = new Version(versionRequested); 1045 } 1046 1047 majorSum += version.getMajor(); 1048 minorSum += version.getMinor(); 1049 serviceSum += version.getMicro(); 1050 qualifiers[++idx] = version.getQualifier(); 1051 } 1052 1053 int longestQualifier = 0; 1056 for (int i = 0; i < numElements; ++i) { 1057 if (qualifiers[i].length() > significantDigits) { 1058 qualifiers[i] = qualifiers[i].substring(0, significantDigits); 1059 } 1060 if (qualifiers[i].length() > longestQualifier) { 1061 longestQualifier = qualifiers[i].length(); 1062 } 1063 } 1064 1065 StringBuffer result = new StringBuffer (); 1066 1067 result.append(lengthPrefixBase64(majorSum)); 1069 result.append(lengthPrefixBase64(minorSum)); 1070 result.append(lengthPrefixBase64(serviceSum)); 1071 1072 if (longestQualifier > 0) { 1073 int[] qualifierSums = new int[longestQualifier]; 1075 for (int i = 0; i < numElements; ++i) { 1076 for (int j = 0; j < qualifiers[i].length(); ++j) { 1077 qualifierSums[j] += charValue(qualifiers[i].charAt(j)); 1078 } 1079 } 1080 int carry = 0; 1082 for (int k = longestQualifier - 1; k >= 1; --k) { 1083 qualifierSums[k] += carry; 1084 carry = qualifierSums[k] / 65; 1085 qualifierSums[k] = qualifierSums[k] % 65; 1086 } 1087 qualifierSums[0] += carry; 1088 1089 result.append(lengthPrefixBase64(qualifierSums[0])); 1092 for (int m = 1; m < longestQualifier; ++m) { 1093 appendEncodedCharacter(result, qualifierSums[m]); 1094 } 1095 } 1096 while (result.length() > 0 && result.charAt(result.length() - 1) == '-') { 1100 result.deleteCharAt(result.length() - 1); 1101 } 1102 1103 if (maxGeneratedLength > result.length()) { 1105 return result.toString(); 1106 } 1107 return result.substring(0, maxGeneratedLength); 1108 } 1109 1110 1114 private void generateModels(List models) throws CoreException { 1115 if (scriptGeneration == false) 1116 return; 1117 if (binaryFeature == false || models.isEmpty()) 1118 return; 1119 1120 Set generatedScripts = new HashSet(models.size()); 1121 for (Iterator iterator = models.iterator(); iterator.hasNext();) { 1122 BundleDescription model = (BundleDescription) iterator.next(); 1123 if (generatedScripts.contains(model)) 1124 continue; 1125 generatedScripts.add(model); 1126 1127 Set matchingEntries = (Set) ((Properties) model.getUserObject()).get(PLUGIN_ENTRY); 1131 if (matchingEntries.isEmpty()) 1132 return; 1133 1134 Iterator entryIter = matchingEntries.iterator(); 1135 IPluginEntry correspondingEntry = (IPluginEntry) entryIter.next(); 1136 List list = selectConfigs(correspondingEntry); 1137 if (list.size() == 0) 1138 continue; 1139 1140 ModelBuildScriptGenerator generator = new ModelBuildScriptGenerator(); 1141 generator.setBuildSiteFactory(siteFactory); 1142 generator.setCompiledElements(getCompiledElements()); 1143 generator.setIgnoreMissingPropertiesFile(isIgnoreMissingPropertiesFile()); 1144 generator.setModel(model); generator.setFeatureGenerator(this); 1146 generator.setPluginPath(getPluginPath()); 1147 generator.setBuildingOSGi(isBuildingOSGi()); 1148 generator.setDevEntries(devEntries); 1149 generator.includePlatformIndependent(isPlatformIndependentIncluded()); 1150 generator.setSignJars(signJars); 1151 generator.setAssociatedEntry(correspondingEntry); 1152 generator.generate(); 1153 } 1154 1155 } 1156 1157 1163 public void setFeature(String featureID) throws CoreException { 1164 if (featureID == null) { 1165 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_FEATURE_MISSING, Messages.error_missingFeatureId, null)); 1166 } 1167 this.featureIdentifier = featureID; 1168 } 1169 1170 public static String getNormalizedName(IFeature feature) { 1171 return feature.getVersionedIdentifier().toString(); 1172 } 1173 1174 private void initializeVariables() throws CoreException { 1175 feature = getSite(false).findFeature(featureIdentifier, searchedVersion, true); 1176 1177 if (featureRootLocation == null) { 1178 featureRootLocation = feature.getURL().getPath(); 1179 int i = featureRootLocation.lastIndexOf(Constants.FEATURE_FILENAME_DESCRIPTOR); 1180 if (i != -1) 1181 featureRootLocation = featureRootLocation.substring(0, i); 1182 } 1183 initializeFeatureNames(); 1184 1185 if (feature instanceof BuildTimeFeature) { 1186 if (getBuildProperties() == MissingProperties.getInstance() || AbstractScriptGenerator.getPropertyAsBoolean(IBuildPropertiesConstants.PROPERTY_PACKAGER_MODE)) { 1187 BuildTimeFeature buildFeature = (BuildTimeFeature) feature; 1188 scriptGeneration = false; 1189 buildFeature.setBinary(true); 1190 } 1191 } 1192 1193 Properties properties = getBuildProperties(); 1194 customFeatureCallbacks = properties.getProperty(PROPERTY_CUSTOM_BUILD_CALLBACKS); 1195 if (TRUE.equalsIgnoreCase(customFeatureCallbacks)) 1196 customFeatureCallbacks = DEFAULT_CUSTOM_BUILD_CALLBACKS_FILE; 1197 else if (FALSE.equalsIgnoreCase(customFeatureCallbacks)) 1198 customFeatureCallbacks = null; 1199 customCallbacksBuildpath = properties.getProperty(PROPERTY_CUSTOM_CALLBACKS_BUILDPATH, "."); customCallbacksFailOnError = properties.getProperty(PROPERTY_CUSTOM_CALLBACKS_FAILONERROR, FALSE); 1201 customCallbacksInheritAll = properties.getProperty(PROPERTY_CUSTOM_CALLBACKS_INHERITALL); 1202 } 1203 1204 private void initializeFeatureNames() throws CoreException { 1205 featureFullName = getNormalizedName(feature); 1206 featureFolderName = DEFAULT_FEATURE_LOCATION + '/' + featureFullName; 1207 sourceFeatureFullName = computeSourceFeatureName(feature, false); 1208 sourceFeatureFullNameVersionned = computeSourceFeatureName(feature, true); 1209 featureTempFolder = Utils.getPropertyFormat(PROPERTY_FEATURE_TEMP_FOLDER); 1210 } 1211 1212 public void setSourceFeatureId(String id) { 1213 sourceFeatureFullName = id; 1214 } 1215 1216 private String computeSourceFeatureName(IFeature featureForName, boolean withNumber) throws CoreException { 1217 String sourceFeatureName = getBuildProperties().getProperty(PROPERTY_SOURCE_FEATURE_NAME); 1218 if (sourceFeatureName == null) 1219 sourceFeatureName = sourceFeatureFullName; 1220 if (sourceFeatureName == null) 1221 sourceFeatureName = featureForName.getVersionedIdentifier().getIdentifier() + ".source"; return sourceFeatureName + (withNumber ? "_" + featureForName.getVersionedIdentifier().getVersion().toString() : ""); } 1224 1225 1234 protected Properties getBuildProperties() throws CoreException { 1235 if (buildProperties == null) 1236 buildProperties = readProperties(featureRootLocation, PROPERTIES_FILE, isIgnoreMissingPropertiesFile() ? IStatus.OK : IStatus.WARNING); 1237 return buildProperties; 1238 } 1239 1240 1245 private void generateChildrenTarget() { 1246 script.println(); 1247 script.printTargetDeclaration(TARGET_CHILDREN, null, PROPERTY_INCLUDE_CHILDREN, null, null); 1248 script.printAntCallTask(TARGET_ALL_CHILDREN, true, null); 1249 script.printTargetEnd(); 1250 } 1251 1252 1255 private void generateBuildJarsTarget() { 1256 script.println(); 1257 script.printTargetDeclaration(TARGET_BUILD_JARS, TARGET_INIT, null, null, NLS.bind(Messages.build_feature_buildJars, featureIdentifier)); 1258 Map params = new HashMap(1); 1259 params.put(PROPERTY_TARGET, TARGET_BUILD_JARS); 1260 script.printAntCallTask(TARGET_ALL_CHILDREN, true, params); 1261 script.printTargetEnd(); 1262 script.println(); 1263 script.printTargetDeclaration(TARGET_BUILD_SOURCES, TARGET_INIT, null, null, null); 1264 params.clear(); 1265 params.put(PROPERTY_TARGET, TARGET_BUILD_SOURCES); 1266 script.printAntCallTask(TARGET_ALL_CHILDREN, true, params); 1267 script.printTargetEnd(); 1268 } 1269 1270 1273 private void generateRefreshTarget() { 1274 script.println(); 1275 script.printTargetDeclaration(TARGET_REFRESH, TARGET_INIT, PROPERTY_ECLIPSE_RUNNING, null, NLS.bind(Messages.build_feature_refresh, featureIdentifier)); 1276 script.printConvertPathTask(new Path(featureRootLocation).removeLastSegments(0).toOSString().replace('\\', '/'), PROPERTY_RESOURCE_PATH, false); 1277 script.printRefreshLocalTask(Utils.getPropertyFormat(PROPERTY_RESOURCE_PATH), "infinite"); Map params = new HashMap(2); 1279 params.put(PROPERTY_TARGET, TARGET_REFRESH); 1280 script.printAntCallTask(TARGET_ALL_CHILDREN, true, params); 1281 script.printTargetEnd(); 1282 } 1283 1284 public void setGenerateIncludedFeatures(boolean recursiveGeneration) { 1285 analyseIncludedFeatures = recursiveGeneration; 1286 } 1287 1288 protected void collectElementToAssemble(IFeature featureToCollect) throws CoreException { 1289 if (assemblyData == null) 1290 return; 1291 1292 1293 if (featureToCollect instanceof BuildTimeFeature && ((BuildTimeFeature) featureToCollect).isBinary()) { 1294 basicCollectElementToAssemble(featureToCollect); 1295 return; 1296 } 1297 1298 if (getBuildProperties().get(PROPERTY_BIN_INCLUDES) == null || sourceFeatureGeneration) 1300 return; 1301 1302 basicCollectElementToAssemble(featureToCollect); 1303 } 1304 1305 private void basicCollectElementToAssemble(IFeature featureToCollect) { 1306 if (assemblyData == null) 1307 return; 1308 List correctConfigs = selectConfigs(featureToCollect); 1309 for (Iterator iter = correctConfigs.iterator(); iter.hasNext();) { 1312 Config config = (Config) iter.next(); 1313 assemblyData.addFeature(config, feature); 1314 } 1315 } 1316 1317 1320 private void generateSourceFeature() throws CoreException { 1321 Feature featureExample = (Feature) feature; 1322 sourceFeature = createSourceFeature(featureExample); 1323 associateExtraPluginsAndFeatures(); 1324 if (isBuildingOSGi()) 1325 sourcePlugin = create30SourcePlugin(); 1326 else 1327 sourcePlugin = createSourcePlugin(); 1328 1329 generateSourceFragment(); 1330 } 1331 1332 private void generateSourceFragment() throws CoreException { 1333 Map fragments = sourceToGather.getElementEntries(); 1334 for (Iterator iter = fragments.entrySet().iterator(); iter.hasNext();) { 1335 Map.Entry fragmentInfo = (Map.Entry) iter.next(); 1336 Config configInfo = (Config) fragmentInfo.getKey(); 1337 if (configInfo.equals(Config.genericConfig())) 1338 continue; 1339 PluginEntry sourceFragment = new PluginEntry(); 1340 String sourceFragmentId = sourceFeature.getFeatureIdentifier() + "." + configInfo.toString("."); sourceFragment.setPluginIdentifier(sourceFragmentId); 1342 sourceFragment.setPluginVersion(sourceFeature.getFeatureVersion()); 1343 sourceFragment.setOS(configInfo.getOs()); 1344 sourceFragment.setWS(configInfo.getWs()); 1345 sourceFragment.setArch(configInfo.getArch()); 1346 sourceFragment.isFragment(true); 1347 if (isBuildingOSGi()) 1349 create30SourceFragment(sourceFragment, sourcePlugin); 1350 else 1351 createSourceFragment(sourceFragment, sourcePlugin); 1352 } 1353 } 1354 1355 private void addSourceFragmentsToFeature() { 1357 Map fragments = sourceToGather.getElementEntries(); 1358 for (Iterator iter = fragments.entrySet().iterator(); iter.hasNext();) { 1359 Map.Entry fragmentInfo = (Map.Entry) iter.next(); 1360 Config configInfo = (Config) fragmentInfo.getKey(); 1361 if (configInfo.equals(Config.genericConfig())) 1362 continue; 1363 Set sourceList = (Set) fragmentInfo.getValue(); 1364 if (sourceList.size() == 0) 1365 continue; 1366 PluginEntry sourceFragment = new PluginEntry(); 1367 String sourceFragmentId = sourceFeature.getFeatureIdentifier() + "." + configInfo.toString("."); sourceFragment.setPluginIdentifier(sourceFragmentId); 1369 sourceFragment.setPluginVersion(sourceFeature.getFeatureVersion()); 1370 sourceFragment.setOS(configInfo.getOs()); 1371 sourceFragment.setWS(configInfo.getWs()); 1372 sourceFragment.setArch(configInfo.getArch()); 1373 sourceFragment.isFragment(true); 1374 sourceFeature.addPluginEntryModel(sourceFragment); 1375 } 1377 } 1378 1379 private void generateSourceFeatureScripts() throws CoreException { 1380 FeatureBuildScriptGenerator sourceScriptGenerator = new FeatureBuildScriptGenerator(sourceFeatureFullName, sourceFeature.getFeatureVersion(), assemblyData); 1381 sourceScriptGenerator.setGenerateIncludedFeatures(true); 1382 sourceScriptGenerator.setAnalyseChildren(true); 1383 sourceScriptGenerator.setSourceToGather(sourceToGather); 1384 sourceScriptGenerator.setBinaryFeatureGeneration(true); 1385 sourceScriptGenerator.setSourceFeatureGeneration(false); 1386 sourceScriptGenerator.setScriptGeneration(true); 1387 sourceScriptGenerator.setPluginPath(pluginPath); 1388 sourceScriptGenerator.setBuildSiteFactory(siteFactory); 1389 sourceScriptGenerator.setDevEntries(devEntries); 1390 sourceScriptGenerator.setCompiledElements(getCompiledElements()); 1391 sourceScriptGenerator.setSourcePluginOnly(sourcePluginOnly); 1392 sourceScriptGenerator.setBuildingOSGi(isBuildingOSGi()); 1393 sourceScriptGenerator.includePlatformIndependent(isPlatformIndependentIncluded()); 1394 sourceScriptGenerator.setIgnoreMissingPropertiesFile(isIgnoreMissingPropertiesFile()); 1395 sourceScriptGenerator.setGenerateVersionSuffix(generateVersionSuffix); 1396 sourceScriptGenerator.generate(); 1397 } 1398 1399 private void associateExtraPluginsAndFeatures() throws CoreException { 1401 for (int i = 1; i < extraPlugins.length; i++) { 1402 BundleDescription model; 1403 if (extraPlugins[i].startsWith("feature@")) { String id = extraPlugins[i].substring(8); 1406 IncludedFeatureReference include = new IncludedFeatureReference(); 1407 include.setFeatureIdentifier(id); 1408 include.setFeatureVersion(GENERIC_VERSION_NUMBER); 1409 sourceFeature.addIncludedFeatureReferenceModel(include); 1410 } else { 1411 Object [] items = Utils.parseExtraBundlesString(extraPlugins[i], true); 1412 model = getSite(false).getRegistry().getResolvedBundle((String ) items[0], ((Version) items[1]).toString()); 1413 if (model == null) { 1414 String message = NLS.bind(Messages.exception_missingPlugin, extraPlugins[i]); 1415 BundleHelper.getDefault().getLog().log(new Status(IStatus.WARNING, extraPlugins[i], EXCEPTION_PLUGIN_MISSING, message, null)); 1416 continue; 1417 } 1418 PluginEntry entry = new PluginEntry(); 1419 entry.setPluginIdentifier(model.getSymbolicName()); 1420 entry.setPluginVersion(model.getVersion().toString()); 1421 entry.setUnpack(((Boolean ) items[2]).booleanValue()); 1422 sourceFeature.addPluginEntryModel(entry); 1423 } 1424 } 1425 } 1426 1427 private PluginEntry create30SourcePlugin() throws CoreException { 1428 PluginEntry result = new PluginEntry(); 1430 String sourcePluginId = sourceFeature.getFeatureIdentifier(); 1431 result.setPluginIdentifier(sourcePluginId); 1432 result.setPluginVersion(sourceFeature.getFeatureVersion()); 1433 sourceFeature.addPluginEntryModel(result); 1434 IPath sourcePluginDirURL = new Path(workingDirectory + '/' + DEFAULT_PLUGIN_LOCATION + '/' + getSourcePluginName(result, false)); 1436 File sourcePluginDir = sourcePluginDirURL.toFile(); 1437 new File(sourcePluginDir, "META-INF").mkdirs(); 1439 StringBuffer buffer; 1441 Path templateManifest = new Path(TEMPLATE + "/30/plugin/" + Constants.BUNDLE_FILENAME_DESCRIPTOR); URL templateManifestURL = BundleHelper.getDefault().find(templateManifest); 1443 if (templateManifestURL == null) { 1444 IStatus status = new Status(IStatus.WARNING, PI_PDEBUILD, IPDEBuildConstants.EXCEPTION_READING_FILE, NLS.bind(Messages.error_readingDirectory, templateManifest), null); 1445 BundleHelper.getDefault().getLog().log(status); 1446 return null; 1447 } 1448 try { 1449 buffer = readFile(templateManifestURL.openStream()); 1450 } catch (IOException e1) { 1451 String message = NLS.bind(Messages.exception_readingFile, templateManifestURL.toExternalForm()); 1452 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_READING_FILE, message, e1)); 1453 } 1454 int beginId = scan(buffer, 0, REPLACED_PLUGIN_ID); 1455 buffer.replace(beginId, beginId + REPLACED_PLUGIN_ID.length(), result.getPluginIdentifier()); 1456 beginId = scan(buffer, beginId, REPLACED_PLUGIN_VERSION); 1458 buffer.replace(beginId, beginId + REPLACED_PLUGIN_VERSION.length(), result.getPluginVersion()); 1459 try { 1460 Utils.transferStreams(new ByteArrayInputStream(buffer.toString().getBytes()), new FileOutputStream(sourcePluginDirURL.append(Constants.BUNDLE_FILENAME_DESCRIPTOR).toOSString())); 1461 } catch (IOException e1) { 1462 String message = NLS.bind(Messages.exception_writingFile, templateManifestURL.toExternalForm()); 1463 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_READING_FILE, message, e1)); 1464 } 1465 1466 try { 1468 InputStream pluginXML = BundleHelper.getDefault().getBundle().getEntry(TEMPLATE + "/30/plugin/plugin.xml").openStream(); Utils.transferStreams(pluginXML, new FileOutputStream(sourcePluginDirURL.append(Constants.PLUGIN_FILENAME_DESCRIPTOR).toOSString())); 1470 } catch (IOException e1) { 1471 String message = NLS.bind(Messages.exception_readingFile, TEMPLATE + "/30/plugin/plugin.xml"); throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, e1)); 1473 } 1474 1475 Collection copiedFiles = Utils.copyFiles(featureRootLocation + '/' + "sourceTemplatePlugin", sourcePluginDir.getAbsolutePath()); if (copiedFiles.contains(Constants.BUNDLE_FILENAME_DESCRIPTOR)) { 1478 replaceManifestValue(sourcePluginDirURL.append(Constants.BUNDLE_FILENAME_DESCRIPTOR).toOSString(), org.osgi.framework.Constants.BUNDLE_VERSION, result.getPluginVersion()); } 1481 1482 File buildProperty = sourcePluginDirURL.append(PROPERTIES_FILE).toFile(); 1484 if (!buildProperty.exists()) { 1485 copiedFiles.add(Constants.PLUGIN_FILENAME_DESCRIPTOR); copiedFiles.add("src/**/*.zip"); copiedFiles.add(Constants.BUNDLE_FILENAME_DESCRIPTOR); Properties sourceBuildProperties = new Properties(); 1489 sourceBuildProperties.put(PROPERTY_BIN_INCLUDES, Utils.getStringFromCollection(copiedFiles, ",")); sourceBuildProperties.put(SOURCE_PLUGIN_ATTRIBUTE, "true"); try { 1492 OutputStream buildFile = new BufferedOutputStream(new FileOutputStream(buildProperty)); 1493 try { 1494 sourceBuildProperties.store(buildFile, null); 1495 } finally { 1496 buildFile.close(); 1497 } 1498 } catch (FileNotFoundException e) { 1499 String message = NLS.bind(Messages.exception_writingFile, buildProperty.getAbsolutePath()); 1500 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, e)); 1501 } catch (IOException e) { 1502 String message = NLS.bind(Messages.exception_writingFile, buildProperty.getAbsolutePath()); 1503 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, e)); 1504 } 1505 } 1506 1507 PDEState state = getSite(false).getRegistry(); 1508 BundleDescription oldBundle = state.getResolvedBundle(result.getPluginIdentifier()); 1509 if (oldBundle != null) 1510 state.getState().removeBundle(oldBundle); 1511 state.addBundle(sourcePluginDir); 1512 1513 return result; 1514 } 1515 1516 1519 private PluginEntry createSourcePlugin() throws CoreException { 1520 PluginEntry result = new PluginEntry(); 1522 String sourcePluginId = sourceFeature.getFeatureIdentifier(); 1523 result.setPluginIdentifier(sourcePluginId); 1524 result.setPluginVersion(sourceFeature.getFeatureVersion()); 1525 sourceFeature.addPluginEntryModel(result); 1526 IPath sourcePluginDirURL = new Path(workingDirectory + '/' + DEFAULT_PLUGIN_LOCATION + '/' + getSourcePluginName(result, false)); 1528 File sourcePluginDir = sourcePluginDirURL.toFile(); 1529 sourcePluginDir.mkdirs(); 1530 1531 StringBuffer buffer; 1533 Path templatePluginXML = new Path(TEMPLATE + "/21/plugin/" + Constants.PLUGIN_FILENAME_DESCRIPTOR); URL templatePluginURL = BundleHelper.getDefault().find(templatePluginXML); 1535 if (templatePluginURL == null) { 1536 IStatus status = new Status(IStatus.WARNING, PI_PDEBUILD, IPDEBuildConstants.EXCEPTION_READING_FILE, NLS.bind(Messages.error_readingDirectory, templatePluginXML), null); 1537 BundleHelper.getDefault().getLog().log(status); 1538 return null; 1539 } 1540 try { 1541 buffer = readFile(templatePluginURL.openStream()); 1542 } catch (IOException e1) { 1543 String message = NLS.bind(Messages.exception_readingFile, templatePluginURL.toExternalForm()); 1544 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_READING_FILE, message, e1)); 1545 } 1546 int beginId = scan(buffer, 0, REPLACED_PLUGIN_ID); 1547 buffer.replace(beginId, beginId + REPLACED_PLUGIN_ID.length(), result.getPluginIdentifier()); 1548 beginId = scan(buffer, beginId, REPLACED_PLUGIN_VERSION); 1550 buffer.replace(beginId, beginId + REPLACED_PLUGIN_VERSION.length(), result.getPluginVersion()); 1551 try { 1552 Utils.transferStreams(new ByteArrayInputStream(buffer.toString().getBytes()), new FileOutputStream(sourcePluginDirURL.append(Constants.PLUGIN_FILENAME_DESCRIPTOR).toOSString())); 1553 } catch (IOException e1) { 1554 String message = NLS.bind(Messages.exception_writingFile, templatePluginURL.toExternalForm()); 1555 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_READING_FILE, message, e1)); 1556 } 1557 Collection copiedFiles = Utils.copyFiles(featureRootLocation + '/' + "sourceTemplatePlugin", sourcePluginDir.getAbsolutePath()); if (copiedFiles.contains(Constants.PLUGIN_FILENAME_DESCRIPTOR)) { 1559 replaceXMLAttribute(sourcePluginDirURL.append(Constants.PLUGIN_FILENAME_DESCRIPTOR).toOSString(), PLUGIN_START_TAG, VERSION, result.getPluginVersion()); 1560 } 1561 File buildProperty = sourcePluginDirURL.append(PROPERTIES_FILE).toFile(); 1563 if (!buildProperty.exists()) { 1564 copiedFiles.add(Constants.PLUGIN_FILENAME_DESCRIPTOR); copiedFiles.add("src/**/*.zip"); Properties sourceBuildProperties = new Properties(); 1567 sourceBuildProperties.put(PROPERTY_BIN_INCLUDES, Utils.getStringFromCollection(copiedFiles, ",")); sourceBuildProperties.put(SOURCE_PLUGIN_ATTRIBUTE, "true"); try { 1570 OutputStream buildFile = new BufferedOutputStream(new FileOutputStream(buildProperty)); 1571 try { 1572 sourceBuildProperties.store(buildFile, null); 1573 } finally { 1574 buildFile.close(); 1575 } 1576 } catch (FileNotFoundException e) { 1577 String message = NLS.bind(Messages.exception_writingFile, buildProperty.getAbsolutePath()); 1578 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, e)); 1579 } catch (IOException e) { 1580 String message = NLS.bind(Messages.exception_writingFile, buildProperty.getAbsolutePath()); 1581 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, e)); 1582 } 1583 } 1584 PDEState state = getSite(false).getRegistry(); 1585 BundleDescription oldBundle = state.getResolvedBundle(result.getPluginIdentifier()); 1586 if (oldBundle != null) 1587 state.getState().removeBundle(oldBundle); 1588 state.addBundle(sourcePluginDir); 1589 return result; 1590 } 1591 1592 private void create30SourceFragment(PluginEntry fragment, PluginEntry plugin) throws CoreException { 1593 Path sourceFragmentDirURL = new Path(workingDirectory + '/' + DEFAULT_PLUGIN_LOCATION + '/' + getSourcePluginName(fragment, false)); 1595 File sourceFragmentDir = new File(sourceFragmentDirURL.toOSString()); 1596 new File(sourceFragmentDir, "META-INF").mkdirs(); try { 1598 Path fragmentPath = new Path(TEMPLATE + "/30/fragment/" + Constants.BUNDLE_FILENAME_DESCRIPTOR); URL templateLocation = BundleHelper.getDefault().find(fragmentPath); 1601 if (templateLocation == null) { 1602 IStatus status = new Status(IStatus.WARNING, PI_PDEBUILD, IPDEBuildConstants.EXCEPTION_READING_FILE, NLS.bind(Messages.error_readingDirectory, fragmentPath), null); 1603 BundleHelper.getDefault().getLog().log(status); 1604 return; 1605 } 1606 1607 try { 1609 InputStream fragmentXML = BundleHelper.getDefault().getBundle().getEntry(TEMPLATE + "/30/fragment/fragment.xml").openStream(); Utils.transferStreams(fragmentXML, new FileOutputStream(sourceFragmentDirURL.append(Constants.FRAGMENT_FILENAME_DESCRIPTOR).toOSString())); 1611 } catch (IOException e1) { 1612 String message = NLS.bind(Messages.exception_readingFile, TEMPLATE + "/30/fragment/fragment.xml"); throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, e1)); 1614 } 1615 1616 StringBuffer buffer = readFile(templateLocation.openStream()); 1617 int beginId = scan(buffer, 0, REPLACED_FRAGMENT_ID); 1619 buffer.replace(beginId, beginId + REPLACED_FRAGMENT_ID.length(), fragment.getPluginIdentifier()); 1620 beginId = scan(buffer, beginId, REPLACED_FRAGMENT_VERSION); 1622 buffer.replace(beginId, beginId + REPLACED_FRAGMENT_VERSION.length(), fragment.getPluginVersion()); 1623 beginId = scan(buffer, beginId, REPLACED_PLUGIN_ID); 1625 buffer.replace(beginId, beginId + REPLACED_PLUGIN_ID.length(), plugin.getPluginIdentifier()); 1626 BundleDescription effectivePlugin = getSite(false).getRegistry().getResolvedBundle(plugin.getVersionedIdentifier().getIdentifier(), plugin.getPluginVersion()); 1628 beginId = scan(buffer, beginId, REPLACED_PLUGIN_VERSION); 1629 buffer.replace(beginId, beginId + REPLACED_PLUGIN_VERSION.length(), effectivePlugin.getVersion().toString()); 1630 beginId = scan(buffer, beginId, REPLACED_PLATFORM_FILTER); 1632 buffer.replace(beginId, beginId + REPLACED_PLATFORM_FILTER.length(), "(& (osgi.ws=" + fragment.getWS() + ") (osgi.os=" + fragment.getOS() + ") (osgi.arch=" + fragment.getOSArch() + "))"); 1633 1634 Utils.transferStreams(new ByteArrayInputStream(buffer.toString().getBytes()), new FileOutputStream(sourceFragmentDirURL.append(Constants.BUNDLE_FILENAME_DESCRIPTOR).toOSString())); 1635 Collection copiedFiles = Utils.copyFiles(featureRootLocation + '/' + "sourceTemplateFragment", sourceFragmentDir.getAbsolutePath()); if (copiedFiles.contains(Constants.BUNDLE_FILENAME_DESCRIPTOR)) { 1637 replaceManifestValue(sourceFragmentDirURL.append(Constants.BUNDLE_FILENAME_DESCRIPTOR).toOSString(), org.osgi.framework.Constants.BUNDLE_VERSION, fragment.getPluginVersion()); 1639 String host = plugin.getPluginIdentifier() + ';' + org.osgi.framework.Constants.BUNDLE_VERSION + '=' + effectivePlugin.getVersion().toString(); 1640 replaceManifestValue(sourceFragmentDirURL.append(Constants.BUNDLE_FILENAME_DESCRIPTOR).toOSString(), org.osgi.framework.Constants.FRAGMENT_HOST, host); 1641 } 1642 File buildProperty = sourceFragmentDirURL.append(PROPERTIES_FILE).toFile(); 1643 if (!buildProperty.exists()) { copiedFiles.add(Constants.FRAGMENT_FILENAME_DESCRIPTOR); copiedFiles.add("src/**"); copiedFiles.add(Constants.BUNDLE_FILENAME_DESCRIPTOR); 1647 Properties sourceBuildProperties = new Properties(); 1648 sourceBuildProperties.put(PROPERTY_BIN_INCLUDES, Utils.getStringFromCollection(copiedFiles, ",")); sourceBuildProperties.put("sourcePlugin", "true"); try { 1651 OutputStream buildFile = new BufferedOutputStream(new FileOutputStream(buildProperty)); 1652 try { 1653 sourceBuildProperties.store(buildFile, null); 1654 } finally { 1655 buildFile.close(); 1656 } 1657 } catch (FileNotFoundException e) { 1658 String message = NLS.bind(Messages.exception_writingFile, buildProperty.getAbsolutePath()); 1659 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, e)); 1660 } catch (IOException e) { 1661 String message = NLS.bind(Messages.exception_writingFile, buildProperty.getAbsolutePath()); 1662 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, e)); 1663 } 1664 } 1665 } catch (IOException e) { 1666 String message = NLS.bind(Messages.exception_writingFile, sourceFragmentDir.getName()); 1667 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, null)); 1668 } 1669 PDEState state = getSite(false).getRegistry(); 1670 BundleDescription oldBundle = state.getResolvedBundle(fragment.getPluginIdentifier()); 1671 if (oldBundle != null) 1672 state.getState().removeBundle(oldBundle); 1673 state.addBundle(sourceFragmentDir); 1674 } 1675 1676 private void createSourceFragment(PluginEntry fragment, PluginEntry plugin) throws CoreException { 1677 Path sourceFragmentDirURL = new Path(workingDirectory + '/' + DEFAULT_PLUGIN_LOCATION + '/' + getSourcePluginName(fragment, false)); 1679 File sourceFragmentDir = new File(sourceFragmentDirURL.toOSString()); 1680 sourceFragmentDir.mkdirs(); 1681 try { 1682 Path fragmentPath = new Path(TEMPLATE + "/21/fragment/" + Constants.FRAGMENT_FILENAME_DESCRIPTOR); URL templateLocation = BundleHelper.getDefault().find(fragmentPath); 1685 if (templateLocation == null) { 1686 IStatus status = new Status(IStatus.WARNING, PI_PDEBUILD, IPDEBuildConstants.EXCEPTION_READING_FILE, NLS.bind(Messages.error_readingDirectory, fragmentPath), null); 1687 BundleHelper.getDefault().getLog().log(status); 1688 return; 1689 } 1690 1691 StringBuffer buffer = readFile(templateLocation.openStream()); 1692 int beginId = scan(buffer, 0, REPLACED_FRAGMENT_ID); 1694 buffer.replace(beginId, beginId + REPLACED_FRAGMENT_ID.length(), fragment.getPluginIdentifier()); 1695 beginId = scan(buffer, beginId, REPLACED_FRAGMENT_VERSION); 1697 buffer.replace(beginId, beginId + REPLACED_FRAGMENT_VERSION.length(), fragment.getPluginVersion()); 1698 beginId = scan(buffer, beginId, REPLACED_PLUGIN_ID); 1700 buffer.replace(beginId, beginId + REPLACED_PLUGIN_ID.length(), plugin.getPluginIdentifier()); 1701 beginId = scan(buffer, beginId, REPLACED_PLUGIN_VERSION); 1703 buffer.replace(beginId, beginId + REPLACED_PLUGIN_VERSION.length(), plugin.getPluginVersion()); 1704 Utils.transferStreams(new ByteArrayInputStream(buffer.toString().getBytes()), new FileOutputStream(sourceFragmentDirURL.append(Constants.FRAGMENT_FILENAME_DESCRIPTOR).toOSString())); 1705 Collection copiedFiles = Utils.copyFiles(featureRootLocation + '/' + "sourceTemplateFragment", sourceFragmentDir.getAbsolutePath()); if (copiedFiles.contains(Constants.FRAGMENT_FILENAME_DESCRIPTOR)) { 1707 replaceXMLAttribute(sourceFragmentDirURL.append(Constants.FRAGMENT_FILENAME_DESCRIPTOR).toOSString(), FRAGMENT_START_TAG, VERSION, fragment.getPluginVersion()); 1708 replaceXMLAttribute(sourceFragmentDirURL.append(Constants.FRAGMENT_FILENAME_DESCRIPTOR).toOSString(), FRAGMENT_START_TAG, PLUGIN_VERSION, plugin.getPluginVersion()); 1709 } 1710 File buildProperty = sourceFragmentDirURL.append(PROPERTIES_FILE).toFile(); 1711 if (!buildProperty.exists()) { copiedFiles.add(Constants.FRAGMENT_FILENAME_DESCRIPTOR); copiedFiles.add("src/**"); Properties sourceBuildProperties = new Properties(); 1715 sourceBuildProperties.put(PROPERTY_BIN_INCLUDES, Utils.getStringFromCollection(copiedFiles, ",")); sourceBuildProperties.put("sourcePlugin", "true"); try { 1718 OutputStream buildFile = new BufferedOutputStream(new FileOutputStream(buildProperty)); 1719 try { 1720 sourceBuildProperties.store(buildFile, null); 1721 } finally { 1722 buildFile.close(); 1723 } 1724 } catch (FileNotFoundException e) { 1725 String message = NLS.bind(Messages.exception_writingFile, buildProperty.getAbsolutePath()); 1726 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, e)); 1727 } catch (IOException e) { 1728 String message = NLS.bind(Messages.exception_writingFile, buildProperty.getAbsolutePath()); 1729 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, e)); 1730 } 1731 } 1732 } catch (IOException e) { 1733 String message = NLS.bind(Messages.exception_writingFile, sourceFragmentDir.getName()); 1734 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, null)); 1735 } 1736 PDEState state = getSite(false).getRegistry(); 1737 BundleDescription oldBundle = state.getResolvedBundle(fragment.getPluginIdentifier()); 1738 if (oldBundle != null) 1739 state.getState().removeBundle(oldBundle); 1740 state.addBundle(sourceFragmentDir); 1741 } 1742 1743 public String getSourcePluginName(PluginEntry plugin, boolean versionSuffix) { 1744 return plugin.getPluginIdentifier() + (versionSuffix ? "_" + plugin.getPluginVersion() : ""); } 1746 1747 public void setFeatureRootLocation(String featureLocation) { 1748 this.featureRootLocation = featureLocation; 1749 } 1750 1751 1756 public void setSourceToGather(SourceFeatureInformation sourceToGather) { 1757 this.sourceToGather = sourceToGather; 1758 } 1759 1760 1766 public void setSourceFeatureGeneration(boolean sourceFeatureGeneration) { 1767 this.sourceFeatureGeneration = sourceFeatureGeneration; 1768 } 1769 1770 1776 public void setBinaryFeatureGeneration(boolean binaryFeatureGeneration) { 1777 this.binaryFeature = binaryFeatureGeneration; 1778 } 1779 1780 1786 public void setScriptGeneration(boolean scriptGeneration) { 1787 this.scriptGeneration = scriptGeneration; 1788 } 1789 1790 1795 public boolean isSourceFeatureGeneration() { 1796 return sourceFeatureGeneration; 1797 } 1798 1799 1804 public void setGenerateJnlp(boolean value) { 1805 generateJnlp = value; 1806 } 1807 1808 1813 public void setSignJars(boolean value) { 1814 signJars = value; 1815 } 1816 1817 1822 public void setGenerateVersionSuffix(boolean value) { 1823 generateVersionSuffix = value; 1824 } 1825 1826 1830 public void setProduct(String product) { 1831 this.product = product; 1832 } 1833 1834 protected void collectElementToAssemble(IPluginEntry entryToCollect) throws CoreException { 1835 if (assemblyData == null || sourceFeatureGeneration) 1836 return; 1837 List correctConfigs = selectConfigs(entryToCollect); 1838 String versionRequested = entryToCollect.getVersionedIdentifier().getVersion().toString(); 1839 BundleDescription effectivePlugin = null; 1840 effectivePlugin = getSite(false).getRegistry().getResolvedBundle(entryToCollect.getVersionedIdentifier().getIdentifier(), versionRequested); 1841 for (Iterator iter = correctConfigs.iterator(); iter.hasNext();) { 1842 assemblyData.addPlugin((Config) iter.next(), effectivePlugin); 1843 } 1844 } 1845 1846 private Feature createSourceFeature(Feature featureExample) throws CoreException { 1848 BuildTimeFeature result = new BuildTimeFeature(); 1849 result.setFeatureIdentifier(computeSourceFeatureName(featureExample, false)); 1850 result.setFeatureVersion(featureExample.getVersionedIdentifier().getVersion().toString()); 1851 result.setLabel(featureExample.getLabelNonLocalized()); 1852 result.setProvider(featureExample.getProviderNonLocalized()); 1853 result.setImageURLString(featureExample.getImageURLString()); 1854 result.setInstallHandlerModel(featureExample.getInstallHandlerModel()); 1855 result.setDescriptionModel(featureExample.getDescriptionModel()); 1856 result.setCopyrightModel(featureExample.getCopyrightModel()); 1857 result.setLicenseModel(featureExample.getLicenseModel()); 1858 result.setUpdateSiteEntryModel(featureExample.getUpdateSiteEntryModel()); 1859 URLEntryModel[] siteEntries = featureExample.getDiscoverySiteEntryModels(); 1860 result.setDiscoverySiteEntryModels((siteEntries == null || siteEntries.length == 0) ? null : siteEntries); 1861 result.setOS(featureExample.getOS()); 1862 result.setArch(featureExample.getOSArch()); 1863 result.setWS(featureExample.getWS()); 1864 int contextLength = featureExample instanceof BuildTimeFeature ? ((BuildTimeFeature) featureExample).getContextQualifierLength() : -1; 1865 result.setContextQualifierLength(contextLength); 1866 return result; 1867 } 1868 1869 private void writeSourceFeature() throws CoreException { 1870 String sourceFeatureDir = workingDirectory + '/' + DEFAULT_FEATURE_LOCATION + '/' + sourceFeatureFullName; 1871 File sourceDir = new File(sourceFeatureDir); 1872 sourceDir.mkdirs(); 1873 File file = new File(sourceFeatureDir + '/' + Constants.FEATURE_FILENAME_DESCRIPTOR); 1875 try { 1876 SourceFeatureWriter writer = new SourceFeatureWriter(new BufferedOutputStream(new FileOutputStream(file)), sourceFeature, this); 1877 try { 1878 writer.printFeature(); 1879 } finally { 1880 writer.close(); 1881 } 1882 } catch (IOException e) { 1883 String message = NLS.bind(Messages.error_creatingFeature, sourceFeature.getFeatureIdentifier()); 1884 throw new CoreException(new Status(IStatus.OK, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, e)); 1885 } 1886 Collection copiedFiles = Utils.copyFiles(featureRootLocation + '/' + "sourceTemplateFeature", sourceFeatureDir); if (copiedFiles.contains(Constants.FEATURE_FILENAME_DESCRIPTOR)) { 1888 replaceXMLAttribute(sourceFeatureDir + '/' + Constants.FEATURE_FILENAME_DESCRIPTOR, FEATURE_START_TAG, VERSION, sourceFeature.getFeatureVersion()); 1890 } 1891 File buildProperty = new File(sourceFeatureDir + '/' + PROPERTIES_FILE); 1892 if (buildProperty.exists()) { getSite(false).addFeatureReferenceModel(sourceDir); 1894 return; 1895 } 1896 copiedFiles.add(Constants.FEATURE_FILENAME_DESCRIPTOR); Properties sourceBuildProperties = new Properties(); 1898 sourceBuildProperties.put(PROPERTY_BIN_INCLUDES, Utils.getStringFromCollection(copiedFiles, ",")); OutputStream output = null; 1900 try { 1901 output = new BufferedOutputStream(new FileOutputStream(buildProperty)); 1902 try { 1903 sourceBuildProperties.store(output, null); 1904 } finally { 1905 output.close(); 1906 } 1907 } catch (FileNotFoundException e) { 1908 String message = NLS.bind(Messages.exception_writingFile, buildProperty.getAbsolutePath()); 1909 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, e)); 1910 } catch (IOException e) { 1911 String message = NLS.bind(Messages.exception_writingFile, buildProperty.getAbsolutePath()); 1912 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, e)); 1913 } 1914 getSite(false).addFeatureReferenceModel(sourceDir); 1915 } 1916 1917 private void replaceManifestValue(String location, String attribute, String newVersion) { 1918 Manifest manifest = null; 1919 try { 1920 InputStream is = new BufferedInputStream(new FileInputStream(location)); 1921 try { 1922 manifest = new Manifest (is); 1923 } finally { 1924 is.close(); 1925 } 1926 } catch (IOException e) { 1927 return; 1928 } 1929 1930 manifest.getMainAttributes().put(new Attributes.Name (attribute), newVersion); 1931 1932 OutputStream os = null; 1933 try { 1934 os = new BufferedOutputStream(new FileOutputStream(location)); 1935 try { 1936 manifest.write(os); 1937 } finally { 1938 os.close(); 1939 } 1940 } catch (IOException e1) { 1941 } 1943 } 1944 1945 private void replaceXMLAttribute(String location, String tag, String attr, String newValue) { 1946 File featureFile = new File(location); 1947 if (!featureFile.exists()) 1948 return; 1949 1950 StringBuffer buffer = null; 1951 try { 1952 buffer = readFile(featureFile); 1953 } catch (IOException e) { 1954 return; 1955 } 1956 1957 int startComment = scan(buffer, 0, COMMENT_START_TAG); 1958 int endComment = startComment > -1 ? scan(buffer, startComment, COMMENT_END_TAG) : -1; 1959 int startTag = scan(buffer, 0, tag); 1960 while (startComment != -1 && startTag > startComment && startTag < endComment) { 1961 startTag = scan(buffer, endComment, tag); 1962 startComment = scan(buffer, endComment, COMMENT_START_TAG); 1963 endComment = startComment > -1 ? scan(buffer, startComment, COMMENT_END_TAG) : -1; 1964 } 1965 if (startTag == -1) 1966 return; 1967 int endTag = scan(buffer, startTag, ">"); boolean attrFound = false; 1969 while (!attrFound) { 1970 int startAttributeWord = scan(buffer, startTag, attr); 1971 if (startAttributeWord == -1 || startAttributeWord > endTag) 1972 return; 1973 if (!Character.isWhitespace(buffer.charAt(startAttributeWord - 1))) { 1974 startTag = startAttributeWord + attr.length(); 1975 continue; 1976 } 1977 int endAttributeWord = startAttributeWord + attr.length(); 1979 while (Character.isWhitespace(buffer.charAt(endAttributeWord)) && endAttributeWord < endTag) { 1980 endAttributeWord++; 1981 } 1982 if (endAttributeWord > endTag) { return; 1984 } 1985 1986 if (buffer.charAt(endAttributeWord) != '=') { 1987 startTag = endAttributeWord; 1988 continue; 1989 } 1990 1991 int startVersionId = scan(buffer, startAttributeWord + 1, "\""); int endVersionId = scan(buffer, startVersionId + 1, "\""); buffer.replace(startVersionId + 1, endVersionId, newValue); 1994 attrFound = true; 1995 } 1996 if (attrFound) { 1997 try { 1998 Utils.transferStreams(new ByteArrayInputStream(buffer.toString().getBytes()), new FileOutputStream(featureFile)); 1999 } catch (IOException e) { 2000 } 2002 } 2003 } 2004 2005} | Popular Tags |