1 13 package org.eclipse.pde.internal.build; 14 15 import java.io.File ; 16 import java.util.*; 17 import org.eclipse.core.runtime.*; 18 import org.eclipse.osgi.service.resolver.BundleDescription; 19 import org.eclipse.pde.build.Constants; 20 import org.eclipse.pde.internal.build.ant.*; 21 import org.eclipse.pde.internal.build.builder.ModelBuildScriptGenerator; 22 import org.eclipse.update.core.IFeature; 23 import org.eclipse.update.core.PluginEntry; 24 25 29 public class AssembleConfigScriptGenerator extends AbstractScriptGenerator { 30 protected String directory; protected String featureId; 32 protected Config configInfo; 33 protected IFeature[] features; protected IFeature[] allFeatures; protected BundleDescription[] plugins; 36 protected String filename; 37 protected Collection rootFileProviders; 38 protected Properties pluginsPostProcessingSteps; 39 protected Properties featuresPostProcessingSteps; 40 protected ArrayList addedByPermissions = new ArrayList(); 42 private static final String PROPERTY_SOURCE = "source"; private static final String PROPERTY_ELEMENT_NAME = "elementName"; 45 private static final String UPDATEJAR = "updateJar"; private static final String FLAT = "flat"; 48 private static final byte BUNDLE = 0; 49 private static final byte FEATURE = 1; 50 51 protected static final String FOLDER = "folder"; protected static final String FILE = "file"; protected String PROPERTY_ECLIPSE_PLUGINS = "eclipse.plugins"; protected String PROPERTY_ECLIPSE_FEATURES = "eclipse.features"; private boolean signJars; 56 private boolean generateJnlp; 57 58 private String archiveFormat; 59 private boolean groupConfigs = false; 60 private String product; 61 private ProductFile productFile = null; 62 63 public AssembleConfigScriptGenerator() { 64 super(); 65 } 66 67 public void initialize(String directoryName, String feature, Config configurationInformation, Collection elementList, Collection featureList, Collection allFeaturesList, Collection rootProviders) throws CoreException { 68 this.directory = directoryName; 69 this.featureId = feature; 70 this.configInfo = configurationInformation; 71 this.rootFileProviders = rootProviders != null ? rootProviders : new ArrayList(0); 72 73 this.features = new IFeature[featureList.size()]; 74 featureList.toArray(this.features); 75 76 this.allFeatures = new IFeature[allFeaturesList.size()]; 77 allFeaturesList.toArray(this.allFeatures); 78 79 this.plugins = new BundleDescription[elementList.size()]; 80 this.plugins = (BundleDescription[]) elementList.toArray(this.plugins); 81 82 openScript(directoryName, getTargetName() + ".xml"); loadPostProcessingSteps(); 84 } 85 86 private void loadProduct() { 87 if (product == null || product.startsWith("${")) { productFile = null; 89 return; 90 } 91 String productPath = findFile(product, false); 92 if (productPath == null) 93 productPath = product; 94 File f = new File (productPath); 95 if (f.exists() && f.isFile()) { 96 try { 97 productFile = new ProductFile(productPath, configInfo.getOs()); 98 } catch (CoreException e) { 99 } 101 } else { 102 } 104 } 105 106 private String computeIconsList() { 107 String result = Utils.getPropertyFormat(PROPERTY_LAUNCHER_ICONS); 108 if (productFile == null) 109 return result; 110 String [] icons = productFile.getIcons(); 111 for (int i = 0; i < icons.length; i++) { 112 String location = findFile(icons[i], true); 113 if (location != null) 114 result += ", " + Utils.getPropertyFormat(PROPERTY_BASEDIR) + '/' + location; else { 116 result += ", " + Utils.getPropertyFormat(PROPERTY_BUILD_DIRECTORY) + '/' + DEFAULT_PLUGIN_LOCATION + '/' + icons[i]; result += ", " + Utils.getPropertyFormat(PROPERTY_BUILD_DIRECTORY) + '/' + DEFAULT_FEATURE_LOCATION + '/' + icons[i]; } 119 } 120 return result; 121 } 122 123 private void loadPostProcessingSteps() { 124 try { 125 pluginsPostProcessingSteps = readProperties(AbstractScriptGenerator.getWorkingDirectory(), DEFAULT_PLUGINS_POSTPROCESSINGSTEPS_FILENAME_DESCRIPTOR, IStatus.INFO); 126 featuresPostProcessingSteps = readProperties(AbstractScriptGenerator.getWorkingDirectory(), DEFAULT_FEATURES_POSTPROCESSINGSTEPS_FILENAME_DESCRIPTOR, IStatus.INFO); 127 } catch (CoreException e) { 128 } 130 } 131 132 public void generate() { 133 loadProduct(); 134 generatePrologue(); 135 generateInitializationSteps(); 136 generateGatherBinPartsCalls(); 137 if (embeddedSource) 138 generateGatherSourceCalls(); 139 generatePostProcessingSteps(); 140 generateBrandingCalls(); 141 generateArchivingSteps(); 142 generateEpilogue(); 143 } 144 145 148 private void generateBrandingCalls() { 149 String install = Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + configInfo.toStringReplacingAny(".", ANY_STRING) + '/' + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER); script.printBrandTask(install, computeIconsList(), Utils.getPropertyFormat(PROPERTY_LAUNCHER_NAME), Utils.getPropertyFormat(PROPERTY_OS)); 151 } 152 153 private void generateArchivingSteps() { 154 if (FORMAT_FOLDER.equalsIgnoreCase(archiveFormat)) { 155 generateMoveRootFiles(); 156 return; 157 } 158 159 if (FORMAT_ZIP.equalsIgnoreCase(archiveFormat)) { 160 generateZipTarget(); 161 return; 162 } 163 164 if (FORMAT_ANTZIP.equalsIgnoreCase(archiveFormat)) { 165 generateAntZipTarget(); 166 return; 167 } 168 169 if (FORMAT_ANTTAR.equalsIgnoreCase(archiveFormat)) { 170 generateAntTarTarget(); 171 return; 172 } 173 174 if (FORMAT_TAR.equalsIgnoreCase(archiveFormat)) { 175 generateTarGZTasks(true); 176 return; 177 } 178 } 179 180 private void generateMoveRootFiles() { 181 if (rootFileProviders.size() == 0) 182 return; 183 184 for (Iterator iter = rootFileProviders.iterator(); iter.hasNext();) { 185 Properties featureProperties = null; 186 try { 187 featureProperties = AbstractScriptGenerator.readProperties(new Path(((IFeature) iter.next()).getURL().getFile()).removeLastSegments(1).toOSString(), PROPERTIES_FILE, IStatus.OK); 188 Utils.generatePermissions(featureProperties, configInfo, PROPERTY_ECLIPSE_BASE, script); 189 } catch (CoreException e) { 190 } 192 } 193 194 if (Platform.getOS().equals("win32")) { FileSet[] rootFiles = new FileSet[1]; 196 rootFiles[0] = new FileSet(Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + configInfo.toStringReplacingAny(".", ANY_STRING) + '/' + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER), null, "**/**", null, null, null, null); script.printMoveTask(Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE), rootFiles, false); 198 script.printDeleteTask(Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + configInfo.toStringReplacingAny(".", ANY_STRING), null, null); } else { 200 List params = new ArrayList(3); 201 params.add("-R"); params.add("."); params.add('\'' + Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '\''); 204 String rootFileFolder = Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + configInfo.toStringReplacingAny(".", ANY_STRING); script.printExecTask("cp", rootFileFolder + '/' + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER), params, null); script.printDeleteTask(rootFileFolder, null, null); 207 } 208 } 209 210 protected void generateGatherSourceCalls() { 211 Map properties = new HashMap(1); 212 properties.put(PROPERTY_DESTINATION_TEMP_FOLDER, Utils.getPropertyFormat(PROPERTY_ECLIPSE_PLUGINS)); 213 214 for (int i = 0; i < plugins.length; i++) { 215 BundleDescription plugin = plugins[i]; 216 String placeToGather = getLocation(plugin); 217 218 script.printAntTask(DEFAULT_BUILD_SCRIPT_FILENAME, Utils.makeRelative(new Path(placeToGather), new Path(workingDirectory)).toOSString(), TARGET_GATHER_SOURCES, null, null, properties); 219 220 Properties bundleProperties = (Properties) plugin.getUserObject(); 221 if (bundleProperties.get(WITH_DOT) == Boolean.TRUE) { 223 String targetLocation = Utils.getPropertyFormat(PROPERTY_ECLIPSE_PLUGINS) + '/' +ModelBuildScriptGenerator.getNormalizedName(plugin); 224 String targetLocationSrc = targetLocation + "/src"; 226 script.println("<unzip dest=\"" + AntScript.getEscaped(targetLocationSrc) + "\">"); script.println("\t<fileset dir=\"" + AntScript.getEscaped(targetLocation) + "\" includes=\"**/*src.zip\" casesensitive=\"false\"/>"); script.println("</unzip>"); 231 script.printDeleteTask(null, null, new FileSet[] {new FileSet(targetLocation, null, "**/*src.zip", null, null, null, "false")}); } 234 } 235 236 properties = new HashMap(1); 237 properties.put(PROPERTY_FEATURE_BASE, Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE)); 238 for (int i = 0; i < features.length; i++) { 239 IFeature feature = features[i]; 240 String placeToGather = feature.getURL().getPath(); 241 int j = placeToGather.lastIndexOf(Constants.FEATURE_FILENAME_DESCRIPTOR); 242 if (j != -1) 243 placeToGather = placeToGather.substring(0, j); 244 script.printAntTask(DEFAULT_BUILD_SCRIPT_FILENAME, Utils.makeRelative(new Path(placeToGather), new Path(workingDirectory)).toOSString(), TARGET_GATHER_SOURCES, null, null, properties); 245 } 246 } 247 248 protected void generatePackagingTargets() { 249 String fileName = Utils.getPropertyFormat(PROPERTY_SOURCE) + '/' + Utils.getPropertyFormat(PROPERTY_ELEMENT_NAME); 250 String fileExists = Utils.getPropertyFormat(PROPERTY_SOURCE) + '/' + Utils.getPropertyFormat(PROPERTY_ELEMENT_NAME) + "_exists"; 252 script.printComment("Beginning of the jarUp task"); script.printTargetDeclaration(TARGET_JARUP, null, null, null, Messages.assemble_jarUp); 254 script.printAvailableTask(fileExists, fileName); 255 Map params = new HashMap(2); 256 params.put(PROPERTY_SOURCE, Utils.getPropertyFormat(PROPERTY_SOURCE)); 257 params.put(PROPERTY_ELEMENT_NAME, Utils.getPropertyFormat(PROPERTY_ELEMENT_NAME)); 258 script.printAntCallTask(TARGET_JARING, true, params); 259 script.printTargetEnd(); 260 261 script.printTargetDeclaration(TARGET_JARING, null, fileExists, null, null); 262 script.printJarTask(fileName + ".jar", fileName, null, "merge"); script.printDeleteTask(fileName, null, null); 264 265 script.printTargetEnd(); 266 script.printComment("End of the jarUp task"); 268 script.printComment("Beginning of the jar signing target"); script.printTargetDeclaration(TARGET_JARSIGNING, null, null, null, Messages.sign_Jar); 270 if (generateJnlp) 271 script.printProperty(PROPERTY_UNSIGN, "true"); script.println("<eclipse.jarProcessor sign=\"" + Utils.getPropertyFormat(PROPERTY_SIGN) + "\" pack=\"" + Utils.getPropertyFormat(PROPERTY_PACK)+ "\" unsign=\"" + Utils.getPropertyFormat(PROPERTY_UNSIGN) + "\" jar=\"" + fileName + ".jar" + "\" alias=\"" + Utils.getPropertyFormat(PROPERTY_SIGN_ALIAS) + "\" keystore=\"" + Utils.getPropertyFormat(PROPERTY_SIGN_KEYSTORE) + "\" storepass=\"" + Utils.getPropertyFormat(PROPERTY_SIGN_STOREPASS) + "\"/>"); script.printTargetEnd(); 274 script.printComment("End of the jarUp task"); } 276 277 protected void generateGZipTarget(boolean assembling) { 278 script.printTargetDeclaration(TARGET_GZIP_RESULTS, null, null, assembling ? PROPERTY_RUN_PACKAGER : null, null); 280 script.println("<move file=\"" + Utils.getPropertyFormat(PROPERTY_ARCHIVE_FULLPATH) + "\" tofile=\"" + Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP) + '/' 283 + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER) + "/tmp.tar\"/>"); script.printGZip(Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP) + '/' + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER) + "/tmp.tar", Utils.getPropertyFormat(PROPERTY_ARCHIVE_FULLPATH)); 286 script.printTargetEnd(); 287 } 288 289 protected void generatePrologue() { 290 script.printProjectDeclaration("Assemble " + featureId, TARGET_MAIN, null); script.printProperty(PROPERTY_ARCHIVE_NAME, computeArchiveName()); 292 script.printProperty(PROPERTY_OS, configInfo.getOs()); 293 script.printProperty(PROPERTY_WS, configInfo.getWs()); 294 script.printProperty(PROPERTY_ARCH, configInfo.getArch()); 295 script.printProperty(PROPERTY_SIGN, (signJars ? Boolean.TRUE : Boolean.FALSE).toString()); 296 script.printProperty(PROPERTY_ASSEMBLY_TMP, Utils.getPropertyFormat(PROPERTY_BUILD_DIRECTORY) + "/tmp"); script.printProperty(PROPERTY_ECLIPSE_BASE, Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP) + '/' + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER)); 298 script.printProperty(PROPERTY_ECLIPSE_PLUGINS, Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + DEFAULT_PLUGIN_LOCATION); 299 script.printProperty(PROPERTY_ECLIPSE_FEATURES, Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + DEFAULT_FEATURE_LOCATION); 300 script.printProperty(PROPERTY_ARCHIVE_FULLPATH, Utils.getPropertyFormat(PROPERTY_BASEDIR) + '/' + Utils.getPropertyFormat(PROPERTY_BUILD_LABEL) + '/' + Utils.getPropertyFormat(PROPERTY_ARCHIVE_NAME)); 301 if (productFile != null && productFile.getLauncherName() != null) 302 script.printProperty(PROPERTY_LAUNCHER_NAME, productFile.getLauncherName()); 303 script.printProperty(PROPERTY_TAR_ARGS, ""); generatePackagingTargets(); 305 script.printTargetDeclaration(TARGET_MAIN, null, null, null, null); 306 } 307 308 private void generateInitializationSteps() { 309 if (BundleHelper.getDefault().isDebugging()) { 310 script.printEchoTask("basedir : " + Utils.getPropertyFormat(PROPERTY_BASEDIR)); script.printEchoTask("assemblyTempDir : " + Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP)); script.printEchoTask("eclipse.base : " + Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE)); script.printEchoTask("collectingFolder : " + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER)); script.printEchoTask("archivePrefix : " + Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX)); } 316 317 script.println("<condition property=\"" + PROPERTY_PLUGIN_ARCHIVE_PREFIX + "\" value=\"" + DEFAULT_PLUGIN_LOCATION + "\">"); script.println("\t<equals arg1=\"" + Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX) + "\" arg2=\"\" trim=\"true\"/>"); script.println("</condition>"); script.printProperty(PROPERTY_PLUGIN_ARCHIVE_PREFIX, Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX) + '/' + DEFAULT_PLUGIN_LOCATION); 321 322 script.println(); 323 script.println("<condition property=\"" + PROPERTY_FEATURE_ARCHIVE_PREFIX + "\" value=\"" + DEFAULT_FEATURE_LOCATION + "\">"); script.println("\t<equals arg1=\"" + Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX) + "\" arg2=\"\" trim=\"true\"/>"); script.println("</condition>"); script.printProperty(PROPERTY_FEATURE_ARCHIVE_PREFIX, Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX) + '/' + DEFAULT_FEATURE_LOCATION); 327 328 script.println(); 329 330 script.printDirName(PROPERTY_ARCHIVE_PARENT, Utils.getPropertyFormat(PROPERTY_ARCHIVE_FULLPATH)); 331 script.printMkdirTask(Utils.getPropertyFormat(PROPERTY_ARCHIVE_PARENT)); 332 script.printMkdirTask(Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP)); 333 script.printMkdirTask(Utils.getPropertyFormat(PROPERTY_BUILD_LABEL)); 334 } 335 336 protected void generatePostProcessingSteps() { 337 for (int i = 0; i < plugins.length; i++) { 338 BundleDescription plugin = plugins[i]; 339 generatePostProcessingSteps(plugin.getSymbolicName(), plugin.getVersion().toString(), (String ) getFinalShape(plugin)[1], BUNDLE); 340 } 341 342 for (int i = 0; i < features.length; i++) { 343 IFeature feature = features[i]; 344 generatePostProcessingSteps(feature.getVersionedIdentifier().getIdentifier(), feature.getVersionedIdentifier().getVersion().toString(), (String ) getFinalShape(feature)[1], FEATURE); 345 } 346 } 347 348 protected void generateGatherBinPartsCalls() { 349 Map properties = new HashMap(1); 350 properties.put(PROPERTY_DESTINATION_TEMP_FOLDER, Utils.getPropertyFormat(PROPERTY_ECLIPSE_PLUGINS)); 351 for (int i = 0; i < plugins.length; i++) { 352 BundleDescription plugin = plugins[i]; 353 String placeToGather = getLocation(plugin); 354 script.printAntTask(DEFAULT_BUILD_SCRIPT_FILENAME, Utils.makeRelative(new Path(placeToGather), new Path(workingDirectory)).toOSString(), TARGET_GATHER_BIN_PARTS, null, null, properties); 355 } 356 357 properties = new HashMap(1); 358 properties.put(PROPERTY_FEATURE_BASE, Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE)); 359 for (int i = 0; i < features.length; i++) { 360 IFeature feature = features[i]; 361 String placeToGather = feature.getURL().getPath(); 362 int j = placeToGather.lastIndexOf(Constants.FEATURE_FILENAME_DESCRIPTOR); 363 if (j != -1) 364 placeToGather = placeToGather.substring(0, j); 365 script.printAntTask(DEFAULT_BUILD_SCRIPT_FILENAME, Utils.makeRelative(new Path(placeToGather), new Path(workingDirectory)).toOSString(), TARGET_GATHER_BIN_PARTS, null, null, properties); 366 } 367 368 properties = new HashMap(1); 370 properties.put(PROPERTY_FEATURE_BASE, Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE)); 371 for (Iterator iter = rootFileProviders.iterator(); iter.hasNext();) { 372 IFeature feature = (IFeature) iter.next(); 373 String placeToGather = feature.getURL().getPath(); 374 int j = placeToGather.lastIndexOf(Constants.FEATURE_FILENAME_DESCRIPTOR); 375 if (j != -1) 376 placeToGather = placeToGather.substring(0, j); 377 script.printAntTask(DEFAULT_BUILD_SCRIPT_FILENAME, Utils.makeRelative(new Path(placeToGather), new Path(workingDirectory)).toOSString(), TARGET_GATHER_BIN_PARTS, null, null, properties); 378 } 379 } 380 381 private void generateSignJarCall(String name, String version, byte type) { 382 if (!signJars) 383 return; 384 Map properties = new HashMap(2); 385 properties.put(PROPERTY_SOURCE, type == BUNDLE ? Utils.getPropertyFormat(PROPERTY_ECLIPSE_PLUGINS) : Utils.getPropertyFormat(PROPERTY_ECLIPSE_FEATURES)); 386 properties.put(PROPERTY_ELEMENT_NAME, name + '_' + version); 387 script.printAntCallTask(TARGET_JARSIGNING, true, properties); 388 } 389 390 private void generatePostProcessingSteps(String name, String version, String style, byte type) { 392 if (FOLDER.equalsIgnoreCase(style)) 393 return; 394 if (FILE.equalsIgnoreCase(style)) { 395 generateJarUpCall(name, version, type); 396 generateSignJarCall(name, version, type); 397 generateJNLPCall(name, version, type); 398 return; 399 } 400 } 401 402 private void generateJNLPCall(String name, String version, byte type) { 403 if (generateJnlp == false) 404 return; 405 if (type != FEATURE) 406 return; 407 408 String dir = type == BUNDLE ? Utils.getPropertyFormat(PROPERTY_ECLIPSE_PLUGINS) : Utils.getPropertyFormat(PROPERTY_ECLIPSE_FEATURES); 409 String location = dir + '/' + name + '_' + version + ".jar"; script.println("<eclipse.jnlpGenerator feature=\"" + AntScript.getEscaped(location) + "\" codebase=\"" + Utils.getPropertyFormat(PROPERTY_JNLP_CODEBASE) + "\" j2se=\"" + Utils.getPropertyFormat(PROPERTY_JNLP_J2SE) + "\" locale=\"" + Utils.getPropertyFormat(PROPERTY_JNLP_LOCALE) + "\" generateOfflineAllowed=\"" + Utils.getPropertyFormat(PROPERTY_JNLP_GENOFFLINE) + "\" configInfo=\"" + Utils.getPropertyFormat(PROPERTY_JNLP_CONFIGS) + "\"/>"); } 412 413 private boolean getUnpackClause(BundleDescription bundle) { 414 Set entries = (Set) ((Properties)bundle.getUserObject()).get(PLUGIN_ENTRY); 415 return ((PluginEntry) entries.iterator().next()).isUnpack(); 416 } 417 418 protected Object [] getFinalShape(BundleDescription bundle) { 419 String style = getUnpackClause(bundle) ? FLAT : UPDATEJAR; 420 return getFinalShape(bundle.getSymbolicName(), bundle.getVersion().toString(), style, BUNDLE); 421 } 422 423 protected Object [] getFinalShape(IFeature feature) { 424 return getFinalShape(feature.getVersionedIdentifier().getIdentifier(), feature.getVersionedIdentifier().getVersion().toString(), FLAT, FEATURE); 425 } 426 427 protected Object [] getFinalShape(String name, String version, String initialShape, byte type) { 428 String style = initialShape; 429 style = getShapeOverride(name, type, style); 430 431 if (FLAT.equalsIgnoreCase(style)) { 432 return new Object [] {name + '_' + version, FOLDER}; 434 } 435 if (UPDATEJAR.equalsIgnoreCase(style)) { 436 return new Object [] {name + '_' + version + ".jar", FILE}; } 438 return new Object [] {name + '_' + version, FOLDER}; 439 } 440 441 private String getShapeOverride(String name, byte type, String initialStyle) { 442 String result = initialStyle; 443 Properties currentProperties = type == BUNDLE ? pluginsPostProcessingSteps : featuresPostProcessingSteps; 444 if (currentProperties.size() > 0) { 445 String styleFromFile = currentProperties.getProperty(name); 446 if (styleFromFile == null) 447 styleFromFile = currentProperties.getProperty(DEFAULT_FINAL_SHAPE); 448 result = styleFromFile; 449 } 450 if (forceUpdateJarFormat) 451 result = UPDATEJAR; 452 return result; 453 } 454 455 private void generateJarUpCall(String name, String version, byte type) { 456 Map properties = new HashMap(2); 457 properties.put(PROPERTY_SOURCE, type == BUNDLE ? Utils.getPropertyFormat(PROPERTY_ECLIPSE_PLUGINS) : Utils.getPropertyFormat(PROPERTY_ECLIPSE_FEATURES)); 458 properties.put(PROPERTY_ELEMENT_NAME, name + '_' + version); 459 script.printAntCallTask(TARGET_JARUP, true, properties); 460 } 461 462 private void generateEpilogue() { 463 if (!FORMAT_FOLDER.equalsIgnoreCase(archiveFormat)) 464 script.printDeleteTask(Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP), null, null); 465 script.printTargetEnd(); 466 if (FORMAT_TAR.equalsIgnoreCase(archiveFormat)) 467 generateGZipTarget(true); 468 script.printProjectEnd(); 469 script.close(); 470 script = null; 471 } 472 473 public String getTargetName() { 474 return DEFAULT_ASSEMBLE_NAME + (featureId.equals("") ? "" : ('.' + featureId)) + (configInfo.equals(Config.genericConfig()) ? "" : ('.' + configInfo.toStringReplacingAny(".", ANY_STRING))); } 476 477 private void generateZipTarget() { 478 final int parameterSize = 15; 479 List parameters = new ArrayList(parameterSize + 1); 480 for (int i = 0; i < plugins.length; i++) { 481 parameters.add(Utils.getPropertyFormat(PROPERTY_PLUGIN_ARCHIVE_PREFIX) + '/' + (String ) getFinalShape(plugins[i])[0]); 482 if (i % parameterSize == 0) { 483 createZipExecCommand(parameters); 484 parameters.clear(); 485 } 486 } 487 if (!parameters.isEmpty()) { 488 createZipExecCommand(parameters); 489 parameters.clear(); 490 } 491 492 if (!parameters.isEmpty()) { 493 createZipExecCommand(parameters); 494 parameters.clear(); 495 } 496 497 for (int i = 0; i < features.length; i++) { 498 parameters.add(Utils.getPropertyFormat(PROPERTY_FEATURE_ARCHIVE_PREFIX) + '/' + (String ) getFinalShape(features[i])[0]); 499 if (i % parameterSize == 0) { 500 createZipExecCommand(parameters); 501 parameters.clear(); 502 } 503 } 504 if (!parameters.isEmpty()) { 505 createZipExecCommand(parameters); 506 parameters.clear(); 507 } 508 509 createZipRootFileCommand(); 510 } 511 512 515 private void createZipRootFileCommand() { 516 if (rootFileProviders.size() == 0) 517 return; 518 519 List parameters = new ArrayList(1); 520 parameters.add("-r -q ${zipargs} '" + Utils.getPropertyFormat(PROPERTY_ARCHIVE_FULLPATH) + "' . "); script.printExecTask("zip", Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + configInfo.toStringReplacingAny(".", ANY_STRING), parameters, null); } 523 524 private void createZipExecCommand(List parameters) { 525 parameters.add(0, "-r -q " + Utils.getPropertyFormat(PROPERTY_ZIP_ARGS) + " '" + Utils.getPropertyFormat(PROPERTY_ARCHIVE_FULLPATH) + '\''); script.printExecTask("zip", Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP), parameters, null); } 528 529 protected String computeArchiveName() { 530 String extension = (FORMAT_TAR.equalsIgnoreCase(archiveFormat) || FORMAT_ANTTAR.equalsIgnoreCase(archiveFormat)) ? ".tar.gz" : ".zip"; return featureId + "-" + Utils.getPropertyFormat(PROPERTY_BUILD_ID_PARAM) + (configInfo.equals(Config.genericConfig()) ? "" : ("-" + configInfo.toStringReplacingAny(".", ANY_STRING))) + extension; } 533 534 public void generateTarGZTasks(boolean assembling) { 535 List parameters = new ArrayList(2); 538 if (rootFileProviders.size() > 0) { 539 parameters.add("-r '" + Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP) + '/' + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER) + '/' + configInfo.toStringReplacingAny(".", ANY_STRING) + '/' + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER) + "' '" + Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP) + '\''); script.printExecTask("cp", Utils.getPropertyFormat(PROPERTY_BASEDIR), parameters, null); 542 parameters.clear(); 543 parameters.add("-rf '" + Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP) + '/' + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER) + '/' + configInfo.toStringReplacingAny(".", ANY_STRING) + '\''); script.printExecTask("rm", Utils.getPropertyFormat(PROPERTY_BASEDIR), parameters, null); } 546 parameters.clear(); 547 String tarArgs = assembling ? "-cvf '" : "-rvf '"; parameters.add(Utils.getPropertyFormat(PROPERTY_TAR_ARGS) + tarArgs + Utils.getPropertyFormat(PROPERTY_ARCHIVE_FULLPATH) + "' " + Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX) + ' '); script.printExecTask("tar", Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP), parameters, null); 551 script.printAntCallTask(TARGET_GZIP_RESULTS, true, null ); 552 553 List args = new ArrayList(2); 554 args.add("-rf"); args.add('\'' + Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP) + '\''); 556 script.printExecTask("rm", null, args, null); } 558 559 protected void generateAntZipTarget() { 561 FileSet[] filesPlugins = new FileSet[plugins.length]; 562 for (int i = 0; i < plugins.length; i++) { 563 Object [] shape = getFinalShape(plugins[i]); 564 filesPlugins[i] = new ZipFileSet(Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + DEFAULT_PLUGIN_LOCATION + '/' + (String ) shape[0], shape[1] == FILE, null, null, null, null, null, Utils.getPropertyFormat(PROPERTY_PLUGIN_ARCHIVE_PREFIX) + '/' + (String ) shape[0], null, null); 565 } 566 if (plugins.length != 0) 567 script.printZipTask(Utils.getPropertyFormat(PROPERTY_ARCHIVE_FULLPATH), null, false, true, filesPlugins); 568 569 FileSet[] filesFeatures = new FileSet[features.length]; 570 for (int i = 0; i < features.length; i++) { 571 Object [] shape = getFinalShape(features[i]); 572 filesFeatures[i] = new ZipFileSet(Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + DEFAULT_FEATURE_LOCATION + '/' + (String ) shape[0], shape[1] == FILE, null, null, null, null, null, Utils.getPropertyFormat(PROPERTY_FEATURE_ARCHIVE_PREFIX) + '/' + (String ) shape[0], null, null); 573 } 574 if (features.length != 0) 575 script.printZipTask(Utils.getPropertyFormat(PROPERTY_ARCHIVE_FULLPATH), null, false, true, filesFeatures); 576 577 if (rootFileProviders.size() == 0) 578 return; 579 580 if (groupConfigs) { 581 List allConfigs = getConfigInfos(); 582 FileSet[] rootFiles = new FileSet[allConfigs.size()]; 583 int i = 0; 584 for (Iterator iter = allConfigs.iterator(); iter.hasNext();) { 585 Config elt = (Config) iter.next(); 586 rootFiles[i++] = new ZipFileSet(Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + elt.toStringReplacingAny(".", ANY_STRING), false, null, "**/**", null, null, null, elt.toStringReplacingAny(".", ANY_STRING), null, null); } 588 script.printZipTask(Utils.getPropertyFormat(PROPERTY_ARCHIVE_FULLPATH), null, false, true, rootFiles); 589 } else { 590 FileSet[] permissionSets = generatePermissions(true); 591 FileSet[] rootFiles = new FileSet[permissionSets.length + 1]; 592 String toExcludeFromArchive = Utils.getStringFromCollection(this.addedByPermissions, ","); System.arraycopy(permissionSets, 0, rootFiles, 1, permissionSets.length); 594 rootFiles[0] = new ZipFileSet(Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + configInfo.toStringReplacingAny(".", ANY_STRING) + '/' + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER), false, null, "**/**", null, toExcludeFromArchive, null, Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX), null, null); script.printZipTask(Utils.getPropertyFormat(PROPERTY_ARCHIVE_FULLPATH), null, false, true, rootFiles); 596 } 597 } 598 599 protected FileSet[] generatePermissions(boolean zip) { 600 String configInfix = configInfo.toString("."); String prefixPermissions = ROOT_PREFIX + configInfix + '.' + PERMISSIONS + '.'; 602 String commonPermissions = ROOT_PREFIX + PERMISSIONS + '.'; 603 ArrayList fileSets = new ArrayList(); 604 605 for (Iterator iter = rootFileProviders.iterator(); iter.hasNext();) { 606 Properties featureProperties = null; 607 try { 608 featureProperties = AbstractScriptGenerator.readProperties(new Path(((IFeature) iter.next()).getURL().getFile()).removeLastSegments(1).toOSString(), PROPERTIES_FILE, IStatus.OK); 609 } catch (CoreException e) { 610 return new FileSet[0]; 611 } 612 613 for (Iterator iter2 = featureProperties.entrySet().iterator(); iter2.hasNext();) { 614 Map.Entry permission = (Map.Entry) iter2.next(); 615 String instruction = (String ) permission.getKey(); 616 String parameters = (String ) permission.getValue(); 617 String [] values = Utils.getArrayFromString(parameters); 618 for (int i = 0; i < values.length; i++) { 619 boolean isFile = ! values[i].endsWith("/"); String prefix = Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + configInfo.toStringReplacingAny(".", ANY_STRING) + '/' + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER); if (instruction.startsWith(prefixPermissions)) { 622 addedByPermissions.add(values[i]); 623 if (zip) 624 fileSets.add(new ZipFileSet(prefix + (isFile ? '/' + values[i] : ""), isFile, null, isFile ? null : values[i] + "/**", null, null, null, Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX) + (isFile ? '/' + values[i] : ""), null, instruction.substring(prefixPermissions.length()))); else 626 fileSets.add(new TarFileSet(prefix + (isFile ? '/' + values[i] : ""), isFile, null, isFile ? null : values[i] + "/**", null, null, null, Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX) + (isFile ? '/' + values[i] : ""), null, instruction.substring(prefixPermissions.length()))); continue; 628 } 629 if (instruction.startsWith(commonPermissions)) { 630 addedByPermissions.add(values[i]); 631 if (zip) 632 fileSets.add(new ZipFileSet(prefix + (isFile ? '/' + values[i] : ""), isFile, null, isFile ? null : values[i] + "/**", null, null, null, Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX) + (isFile ? '/' + values[i] : ""), null, instruction.substring(commonPermissions.length()))); else 634 fileSets.add(new TarFileSet(prefix + (isFile ? '/' + values[i] : ""), isFile, null, isFile ? null : values[i] + "/**", null, null, null, Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX) + (isFile ? '/' + values[i] : ""), null, instruction.substring(commonPermissions.length()))); continue; 636 } 637 } 638 } 639 } 640 return (FileSet[]) fileSets.toArray(new FileSet[fileSets.size()]); 641 } 642 643 private void generateAntTarTarget() { 645 FileSet[] filesPlugins = new FileSet[plugins.length]; 646 for (int i = 0; i < plugins.length; i++) { 647 Object [] shape = getFinalShape(plugins[i]); 648 filesPlugins[i] = new TarFileSet(Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + DEFAULT_PLUGIN_LOCATION + '/' + (String ) shape[0], shape[1] == FILE, null, null, null, null, null, Utils.getPropertyFormat(PROPERTY_PLUGIN_ARCHIVE_PREFIX) + '/' + (String ) shape[0], null, null); 649 } 650 if (plugins.length != 0) 651 script.printTarTask(Utils.getPropertyFormat(PROPERTY_ARCHIVE_FULLPATH), null, false, true, filesPlugins); 652 653 FileSet[] filesFeatures = new FileSet[features.length]; 654 for (int i = 0; i < features.length; i++) { 655 Object [] shape = getFinalShape(features[i]); 656 filesFeatures[i] = new TarFileSet(Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + DEFAULT_FEATURE_LOCATION + '/' + (String ) shape[0], shape[1] == FILE, null, null, null, null, null, Utils.getPropertyFormat(PROPERTY_FEATURE_ARCHIVE_PREFIX) + '/' + (String ) shape[0], null, null); 657 } 658 if (features.length != 0) 659 script.printTarTask(Utils.getPropertyFormat(PROPERTY_ARCHIVE_FULLPATH), null, false, true, filesFeatures); 660 661 if (rootFileProviders.size() == 0) 662 return; 663 664 FileSet[] permissionSets = generatePermissions(false); 665 FileSet[] rootFiles = new FileSet[permissionSets.length + 1]; 666 System.arraycopy(permissionSets, 0, rootFiles, 1, permissionSets.length); 667 rootFiles[0] = new TarFileSet(Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + configInfo.toStringReplacingAny(".", ANY_STRING) + '/' + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER), false, null, "**/**", null, null, null, Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX), null, null); script.printTarTask(Utils.getPropertyFormat(PROPERTY_ARCHIVE_FULLPATH), null, false, true, rootFiles); 669 } 670 671 public void setGenerateJnlp(boolean value) { 672 generateJnlp = value; 673 } 674 675 public void setSignJars(boolean value) { 676 signJars = value; 677 } 678 679 public void setProduct(String value) { 680 product = value; 681 } 682 683 public void setArchiveFormat(String archiveFormat) { 684 this.archiveFormat = archiveFormat; 685 } 686 687 public void setGroupConfigs(boolean group) { 688 groupConfigs = group; 689 } 690 } 691 | Popular Tags |