1 11 package org.eclipse.pde.internal.core.exports; 12 13 import java.io.File ; 14 import java.io.FileOutputStream ; 15 import java.io.IOException ; 16 import java.lang.reflect.InvocationTargetException ; 17 import java.net.MalformedURLException ; 18 import java.net.URL ; 19 import java.util.Dictionary ; 20 import java.util.HashMap ; 21 import java.util.Hashtable ; 22 import java.util.List ; 23 import java.util.ListIterator ; 24 import java.util.Map ; 25 import java.util.Properties ; 26 27 import javax.xml.parsers.DocumentBuilderFactory ; 28 import javax.xml.parsers.FactoryConfigurationError ; 29 import javax.xml.parsers.ParserConfigurationException ; 30 31 import org.eclipse.ant.core.AntCorePlugin; 32 import org.eclipse.ant.core.AntCorePreferences; 33 import org.eclipse.ant.core.AntRunner; 34 import org.eclipse.ant.core.IAntClasspathEntry; 35 import org.eclipse.ant.core.Property; 36 import org.eclipse.core.resources.IFile; 37 import org.eclipse.core.resources.IWorkspaceRunnable; 38 import org.eclipse.core.runtime.CoreException; 39 import org.eclipse.core.runtime.IPath; 40 import org.eclipse.core.runtime.IProgressMonitor; 41 import org.eclipse.core.runtime.IStatus; 42 import org.eclipse.core.runtime.OperationCanceledException; 43 import org.eclipse.core.runtime.Path; 44 import org.eclipse.core.runtime.Platform; 45 import org.eclipse.core.runtime.Preferences; 46 import org.eclipse.core.runtime.Status; 47 import org.eclipse.core.runtime.SubProgressMonitor; 48 import org.eclipse.jdt.core.JavaCore; 49 import org.eclipse.jdt.launching.JavaRuntime; 50 import org.eclipse.jdt.launching.environments.IExecutionEnvironment; 51 import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager; 52 import org.eclipse.osgi.service.resolver.BundleDescription; 53 import org.eclipse.osgi.service.resolver.State; 54 import org.eclipse.pde.core.IModel; 55 import org.eclipse.pde.core.build.IBuild; 56 import org.eclipse.pde.core.build.IBuildEntry; 57 import org.eclipse.pde.core.build.IBuildModel; 58 import org.eclipse.pde.core.plugin.IPluginModelBase; 59 import org.eclipse.pde.core.plugin.PluginRegistry; 60 import org.eclipse.pde.core.plugin.TargetPlatform; 61 import org.eclipse.pde.internal.build.AbstractScriptGenerator; 62 import org.eclipse.pde.internal.build.BuildScriptGenerator; 63 import org.eclipse.pde.internal.build.IXMLConstants; 64 import org.eclipse.pde.internal.build.site.QualifierReplacer; 65 import org.eclipse.pde.internal.core.ClasspathHelper; 66 import org.eclipse.pde.internal.core.PDECore; 67 import org.eclipse.pde.internal.core.PDECoreMessages; 68 import org.eclipse.pde.internal.core.TargetPlatformHelper; 69 import org.eclipse.pde.internal.core.XMLPrintHandler; 70 import org.eclipse.pde.internal.core.build.WorkspaceBuildModel; 71 import org.eclipse.pde.internal.core.feature.FeatureChild; 72 import org.eclipse.pde.internal.core.ifeature.IFeature; 73 import org.eclipse.pde.internal.core.ifeature.IFeatureChild; 74 import org.eclipse.pde.internal.core.ifeature.IFeatureModel; 75 import org.eclipse.pde.internal.core.ifeature.IFeaturePlugin; 76 import org.eclipse.pde.internal.core.util.CoreUtility; 77 import org.osgi.framework.InvalidSyntaxException; 78 import org.w3c.dom.DOMException ; 79 import org.w3c.dom.Document ; 80 import org.w3c.dom.Element ; 81 82 import com.ibm.icu.util.Calendar; 83 84 public class FeatureExportOperation implements IWorkspaceRunnable { 85 86 private static boolean fHasErrors; 88 89 protected String fBuildTempLocation; 91 private String fDevProperties; 92 93 protected HashMap fAntBuildProperties; 94 95 protected State fStateCopy; 96 97 protected static String FEATURE_POST_PROCESSING = "features.postProcessingSteps.properties"; protected static String PLUGIN_POST_PROCESSING = "plugins.postProcessingSteps.properties"; 100 public static String getDate() { 101 final String empty = ""; int monthNbr = Calendar.getInstance().get(Calendar.MONTH) + 1; 103 String month = (monthNbr < 10 ? "0" : empty) + monthNbr; 105 int dayNbr = Calendar.getInstance().get(Calendar.DAY_OF_MONTH); 106 String day = (dayNbr < 10 ? "0" : empty) + dayNbr; 108 int hourNbr = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); 109 String hour = (hourNbr < 10 ? "0" : empty) + hourNbr; 111 int minuteNbr = Calendar.getInstance().get(Calendar.MINUTE); 112 String minute = (minuteNbr < 10 ? "0" : empty) + minuteNbr; 114 return empty + Calendar.getInstance().get(Calendar.YEAR) + month + day + hour + minute; 115 } 116 117 protected FeatureExportInfo fInfo; 118 119 public FeatureExportOperation(FeatureExportInfo info) { 120 fInfo = info; 121 String qualifier = info.qualifier; 122 if (qualifier == null) 123 qualifier = getDate(); 124 QualifierReplacer.setGlobalQualifier(qualifier); 125 fBuildTempLocation = PDECore.getDefault().getStateLocation().append("temp").toString(); } 127 128 public void run(IProgressMonitor monitor) throws CoreException { 129 try { 130 createDestination(); 131 String [][] configurations = fInfo.targets; 132 if (configurations == null) 133 configurations = new String [][] { null }; 134 135 monitor.beginTask("", configurations.length * fInfo.items.length * 10); for (int i = 0; i < configurations.length; i++) { 137 for (int j = 0; j < fInfo.items.length; j++) { 138 if (monitor.isCanceled()) 139 throw new OperationCanceledException(); 140 try { 141 doExport((IFeatureModel) fInfo.items[j], configurations[i], new SubProgressMonitor(monitor, 9)); 142 } finally { 143 cleanup(configurations[i], new SubProgressMonitor(monitor, 1)); 144 } 145 } 146 } 147 } catch (InvocationTargetException e) { 148 throwCoreException(e); 149 } 150 monitor.done(); 151 } 152 153 protected void throwCoreException(InvocationTargetException e) throws CoreException { 154 String message = e.getTargetException().getMessage(); 155 if (message != null && message.length() > 0) { 156 throw new CoreException(new Status( 157 IStatus.ERROR, 158 PDECore.PLUGIN_ID, 159 IStatus.ERROR, 160 message, 161 null)); 162 } 163 } 164 165 private void createDestination(String os, String ws, String arch) throws InvocationTargetException { 166 if (!fInfo.toDirectory) 167 return; 168 File file = new File (fInfo.destinationDirectory, os + '.' + ws + '.' + arch); 169 if (!file.exists() || !file.isDirectory()) { 170 if (!file.mkdirs()) 171 throw new InvocationTargetException (new Exception (PDECoreMessages.ExportWizard_badDirectory)); 172 } 173 } 174 175 private void doExport(IFeatureModel model, String os, String ws, String arch, IProgressMonitor monitor) throws CoreException, InvocationTargetException { 176 try { 177 String location = model.getInstallLocation(); 178 if (fInfo.useJarFormat) { 179 createPostProcessingFile(new File (location, FEATURE_POST_PROCESSING)); 180 createPostProcessingFile(new File (location, PLUGIN_POST_PROCESSING)); 181 } 182 IFeature feature = model.getFeature(); 183 doExport(feature.getId(), feature.getVersion(), location, os, ws, arch, monitor); 184 } finally { 185 deleteBuildFiles(model); 186 } 187 } 188 189 protected void createPostProcessingFile(File file) { 190 FileOutputStream stream = null; 191 try { 192 stream = new FileOutputStream (file); 193 Properties prop = new Properties (); 194 prop.put("*", "updateJar"); prop.store(stream, ""); stream.flush(); 197 } catch (IOException e) { 198 } finally { 199 try { 200 if (stream != null) 201 stream.close(); 202 } catch (IOException e) { 203 } 204 } 205 } 206 207 protected void doExport(String featureID, String version, String featureLocation, String os, String ws, String arch, IProgressMonitor monitor) throws CoreException, InvocationTargetException { 208 fHasErrors = false; 209 monitor.beginTask("", 9); monitor.setTaskName(PDECoreMessages.FeatureExportJob_taskName); 211 try { 212 HashMap properties = createAntBuildProperties(os, ws, arch); 213 BuildScriptGenerator generator = new BuildScriptGenerator(); 214 setupGenerator(generator, featureID, version, os, ws, arch, featureLocation); 215 generator.generate(); 216 monitor.worked(1); 217 runScript(getBuildScriptName(featureLocation), getBuildExecutionTargets(), properties, new SubProgressMonitor(monitor, 2)); 218 runScript(getAssemblyScriptName(featureID, os, ws, arch, featureLocation), new String [] {"main"}, properties, new SubProgressMonitor(monitor, 2)); 220 runScript(getPackagerScriptName(featureID, os, ws, arch, featureLocation), null, properties, new SubProgressMonitor(monitor, 2)); 221 properties.put("destination.temp.folder", fBuildTempLocation + "/pde.logs"); runScript(getBuildScriptName(featureLocation), new String [] {"gather.logs"}, properties, new SubProgressMonitor(monitor, 2)); } finally { 224 monitor.done(); 225 } 226 } 227 228 public void deleteBuildFiles(Object object) throws CoreException { 229 IModel model = null; 230 if (object instanceof BundleDescription) { 231 model = PluginRegistry.findModel((BundleDescription)object); 232 } else if (object instanceof IModel){ 233 model = (IModel)object; 234 } 235 236 if (model == null) 237 return; 238 239 if (model.getUnderlyingResource() != null && !isCustomBuild(model)) { 240 String directory = (model instanceof IFeatureModel) ? ((IFeatureModel) model).getInstallLocation() : ((IPluginModelBase) model).getInstallLocation(); 241 File dir = new File (directory); 242 File [] children = dir.listFiles(); 243 if (children != null) { 244 for (int i = 0; i < children.length; i++) { 245 if (!children[i].isDirectory()) { 246 String filename = children[i].getName(); 247 if (filename.equals("build.xml") || (filename.startsWith("javaCompiler.") && filename.endsWith(".args")) || (filename.startsWith("assemble.") && filename.endsWith(".xml")) || (filename.startsWith("package.") && filename.endsWith(".xml")) || filename.equals(FEATURE_POST_PROCESSING) 252 || filename.equals(PLUGIN_POST_PROCESSING)) { 253 children[i].delete(); 254 } 255 } else if (children[i].getName().equals("temp.folder")) { CoreUtility.deleteContent(children[i]); 257 } 258 } 259 } 260 } 261 262 if (model instanceof IFeatureModel) { 263 IFeature feature = ((IFeatureModel) model).getFeature(); 264 IFeatureChild[] children = feature.getIncludedFeatures(); 265 for (int i = 0; i < children.length; i++) { 266 IFeature ref = ((FeatureChild) children[i]).getReferencedFeature(); 267 if (ref != null) { 268 deleteBuildFiles(ref.getModel()); 269 } 270 } 271 272 IFeaturePlugin[] plugins = feature.getPlugins(); 273 for (int i = 0; i < plugins.length; i++) { 274 IPluginModelBase plugin = PluginRegistry.findModel(plugins[i].getId()); 275 if (plugin != null) { 276 deleteBuildFiles(plugin); 277 } 278 } 279 } 280 } 281 282 private String getBuildScriptName(String featureLocation) { 283 return featureLocation + IPath.SEPARATOR + "build.xml"; } 285 286 protected String getAssemblyScriptName(String featureID, String os, String ws, String arch, String featureLocation) { 287 return featureLocation + IPath.SEPARATOR + "assemble." + featureID + "." + os + "." + ws + "." + arch + ".xml"; } 292 293 private String [] getBuildExecutionTargets() { 294 if (fInfo.exportSource) 295 return new String [] {"build.jars", "build.sources"}; return new String [] {"build.jars"}; } 298 299 protected void runScript(String location, String [] targets, Map properties, IProgressMonitor monitor) throws InvocationTargetException , CoreException { 300 AntRunner runner = new AntRunner(); 301 runner.addUserProperties(properties); 302 runner.setAntHome(location); 303 runner.setBuildFileLocation(location); 304 runner.addBuildListener("org.eclipse.pde.internal.core.ant.ExportBuildListener"); runner.setExecutionTargets(targets); 306 if (fInfo.signingInfo != null) { 307 AntCorePreferences preferences = AntCorePlugin.getPlugin().getPreferences(); 308 IAntClasspathEntry entry = preferences.getToolsJarEntry(); 309 if (entry != null) { 310 IAntClasspathEntry[] classpath = preferences.getAntHomeClasspathEntries(); 311 URL [] urls = new URL [classpath.length + 2]; 312 for (int i = 0; i < classpath.length; i++) { 313 urls[i] = classpath[i].getEntryURL(); 314 } 315 IPath path = new Path(entry.getEntryURL().toString()).removeLastSegments(2); 316 path = path.append("bin"); try { 318 urls[classpath.length] = new URL (path.toString()); 319 } catch (MalformedURLException e) { 320 urls[classpath.length] = entry.getEntryURL(); 321 } finally { 322 urls[classpath.length + 1] = entry.getEntryURL(); 323 } 324 runner.setCustomClasspath(urls); 325 } 326 } 327 runner.run(monitor); 328 } 329 330 protected String getPackagerScriptName(String featureID, String os, String ws, String arch, String featureLocation) { 331 return featureLocation + IPath.SEPARATOR + "package." + featureID + "." + os + "." + ws + "." + arch + ".xml"; } 336 337 protected HashMap createAntBuildProperties(String os, String ws, String arch) { 338 if (fAntBuildProperties == null) { 339 fAntBuildProperties = new HashMap (15); 340 341 List defaultProperties= AntCorePlugin.getPlugin().getPreferences().getDefaultProperties(); 342 ListIterator li = defaultProperties.listIterator(); 343 while (li.hasNext()) { 344 Property prop = (Property)li.next(); 345 fAntBuildProperties.put(prop.getName(), prop.getValue()); 346 } 347 348 if (fInfo.signingInfo != null) { 349 fAntBuildProperties.put("sign.alias", fInfo.signingInfo[0]); fAntBuildProperties.put("sign.keystore", fInfo.signingInfo[1]); fAntBuildProperties.put("sign.storepass", fInfo.signingInfo[2]); } 353 if (fInfo.jnlpInfo != null) { 354 fAntBuildProperties.put("jnlp.codebase", fInfo.jnlpInfo[0]); fAntBuildProperties.put("jnlp.j2se", fInfo.jnlpInfo[1]); } 357 358 fAntBuildProperties.put(IXMLConstants.PROPERTY_BUILD_TEMP, fBuildTempLocation + "/destination"); fAntBuildProperties.put(IXMLConstants.PROPERTY_FEATURE_TEMP_FOLDER, fBuildTempLocation + "/destination"); fAntBuildProperties.put(IXMLConstants.PROPERTY_INCLUDE_CHILDREN, "true"); fAntBuildProperties.put("eclipse.running", "true"); fAntBuildProperties.put(IXMLConstants.PROPERTY_BASE_OS, os); 363 fAntBuildProperties.put(IXMLConstants.PROPERTY_BASE_WS, ws); 364 fAntBuildProperties.put(IXMLConstants.PROPERTY_BASE_ARCH, arch); 365 fAntBuildProperties.put(IXMLConstants.PROPERTY_BASE_NL, TargetPlatform.getNL()); 366 fAntBuildProperties.put(IXMLConstants.PROPERTY_BOOTCLASSPATH, BuildUtilities.getBootClasspath()); 367 IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); 368 IExecutionEnvironment[] envs = manager.getExecutionEnvironments(); 369 for (int i = 0; i < envs.length; i++) { 370 String id = envs[i].getId(); 371 if (id != null) 372 fAntBuildProperties.put(id, BuildUtilities.getBootClasspath(id)); 373 } 374 fAntBuildProperties.put(IXMLConstants.PROPERTY_JAVAC_FAIL_ON_ERROR, "false"); fAntBuildProperties.put(IXMLConstants.PROPERTY_JAVAC_DEBUG_INFO, "on"); fAntBuildProperties.put(IXMLConstants.PROPERTY_JAVAC_VERBOSE, "false"); 378 Preferences pref = JavaCore.getPlugin().getPluginPreferences(); 379 String source = pref.getString(JavaCore.COMPILER_SOURCE); 380 fAntBuildProperties.put(IXMLConstants.PROPERTY_JAVAC_SOURCE, source); 381 String target = pref.getString(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM); 382 fAntBuildProperties.put(IXMLConstants.PROPERTY_JAVAC_TARGET, target); 383 384 fAntBuildProperties.put(IXMLConstants.PROPERTY_BUILD_DIRECTORY, fBuildTempLocation + "/assemblyLocation"); fAntBuildProperties.put(IXMLConstants.PROPERTY_BUILD_LABEL, "."); fAntBuildProperties.put(IXMLConstants.PROPERTY_COLLECTING_FOLDER, "."); String prefix = Platform.getOS().equals("macosx") ? "." : ""; fAntBuildProperties.put(IXMLConstants.PROPERTY_ARCHIVE_PREFIX, prefix); 390 391 if (!fInfo.toDirectory) { 392 String filename = fInfo.zipFileName; 393 if (fInfo.targets != null) { 394 int i = filename.lastIndexOf('.'); 395 filename = filename.substring(0, i) + '.' + os + '.' + ws + '.' + arch + filename.substring(i); 396 } 397 fAntBuildProperties.put(IXMLConstants.PROPERTY_ARCHIVE_FULLPATH, fInfo.destinationDirectory + File.separator + filename); 398 } else { 399 String dir = fInfo.destinationDirectory; 400 if (fInfo.targets != null) 401 dir += File.separatorChar + os + '.' + ws + '.' + arch; 402 fAntBuildProperties.put(IXMLConstants.PROPERTY_ASSEMBLY_TMP, dir); 403 } 404 fAntBuildProperties.put(IXMLConstants.PROPERTY_TAR_ARGS, ""); } 406 return fAntBuildProperties; 407 } 408 409 private String getOS(IFeature feature) { 410 String os = feature.getOS(); 411 if (os == null || os.trim().length() == 0 || os.indexOf(',') != -1 || os.equals("*")) return TargetPlatform.getOS(); 413 return os; 414 } 415 416 private String getWS(IFeature feature) { 417 String ws = feature.getWS(); 418 if (ws == null || ws.trim().length() == 0 || ws.indexOf(',') != -1 || ws.equals("*")) return TargetPlatform.getWS(); 420 return ws; 421 } 422 423 private String getOSArch(IFeature feature) { 424 String arch = feature.getArch(); 425 if (arch == null || arch.trim().length() == 0 || arch.indexOf(',') != -1 || arch.equals("*")) return TargetPlatform.getOSArch(); 427 return arch; 428 } 429 430 protected void createDestination() throws InvocationTargetException { 431 File file = new File (fInfo.destinationDirectory); 432 if (!file.exists() || !file.isDirectory()) { 433 if (!file.mkdirs()) 434 throw new InvocationTargetException (new Exception (PDECoreMessages.ExportWizard_badDirectory)); 435 } 436 } 437 438 protected void doExport(IFeatureModel model, String [] config, IProgressMonitor monitor) throws CoreException, InvocationTargetException { 439 if (config == null) { 440 IFeature feature = model.getFeature(); 441 doExport(model, getOS(feature), getWS(feature), getOSArch(feature), monitor); 442 } else { 443 createDestination(config[0], config[1], config[2]); 444 doExport(model, config[0], config[1], config[2], monitor); 445 } 446 } 447 448 protected void setupGenerator(BuildScriptGenerator generator, String featureID, String versionId, String os, String ws, String arch, String featureLocation) throws CoreException { 449 generator.setBuildingOSGi(true); 450 generator.setChildren(true); 451 generator.setWorkingDirectory(featureLocation); 452 generator.setDevEntries(getDevProperties()); 453 generator.setElements(new String [] {"feature@" + featureID + (versionId == null ? "" : ":" + versionId)}); generator.setPluginPath(getPaths()); 455 generator.setReportResolutionErrors(false); 456 generator.setIgnoreMissingPropertiesFile(true); 457 generator.setSignJars(fInfo.signingInfo != null); 458 generator.setGenerateJnlp(fInfo.jnlpInfo != null); 459 String config = os + ',' + ws + ',' + arch; 460 AbstractScriptGenerator.setConfigInfo(config); String format; 462 if (fInfo.toDirectory) 463 format = config + '-' + IXMLConstants.FORMAT_FOLDER; 464 else 465 format = config + '-' + IXMLConstants.FORMAT_ANTZIP; 466 generator.setArchivesFormat(format); 467 generator.setPDEState(getState(os, ws, arch)); 468 generator.setNextId(TargetPlatformHelper.getPDEState().getNextId()); 469 generator.setStateExtraData(TargetPlatformHelper.getBundleClasspaths(TargetPlatformHelper.getPDEState()), TargetPlatformHelper.getPatchMap(TargetPlatformHelper.getPDEState())); 470 AbstractScriptGenerator.setForceUpdateJar(false); 471 AbstractScriptGenerator.setEmbeddedSource(fInfo.exportSource); 472 } 473 474 protected State getState(String os, String ws, String arch) { 475 State main = TargetPlatformHelper.getState(); 476 if (os.equals(TargetPlatform.getOS()) 477 && ws.equals(TargetPlatform.getWS()) 478 && arch.equals(TargetPlatform.getOSArch())) { 479 return main; 480 } 481 if (fStateCopy == null) { 482 copyState(main); 483 } 484 485 Dictionary [] dictionaries = fStateCopy.getPlatformProperties(); 486 for (int i = 0; i < dictionaries.length; i++) { 487 Dictionary properties = dictionaries[i]; 488 properties.put("osgi.os", os); properties.put("osgi.ws", ws); properties.put("osgi.arch", arch); } 492 fStateCopy.resolve(false); 493 return fStateCopy; 494 } 495 496 protected void copyState(State state) { 497 fStateCopy = state.getFactory().createState(state); 498 fStateCopy.setResolver(Platform.getPlatformAdmin().getResolver()); 499 fStateCopy.setPlatformProperties(state.getPlatformProperties()); 500 } 501 502 private String getDevProperties() { 503 if (fDevProperties == null) { 504 fDevProperties = ClasspathHelper.getDevEntriesProperties(fBuildTempLocation + "/dev.properties", false); } 506 return fDevProperties; 507 } 508 509 510 protected boolean isCustomBuild(IModel model) throws CoreException { 511 IBuildModel buildModel = null; 512 IFile buildFile = model.getUnderlyingResource().getProject().getFile("build.properties"); if (buildFile.exists()) { 514 buildModel = new WorkspaceBuildModel(buildFile); 515 buildModel.load(); 516 } 517 if (buildModel != null) { 518 IBuild build = buildModel.getBuild(); 519 if (build == null) 520 return false; 521 IBuildEntry entry = build.getEntry("custom"); if (entry != null) { 523 String [] tokens = entry.getTokens(); 524 for (int i = 0; i < tokens.length; i++) { 525 if (tokens[i].equals("true")) return true; 527 } 528 } 529 } 530 return false; 531 } 532 533 protected String [] getPaths() { 534 return TargetPlatformHelper.getFeaturePaths(); 535 } 536 537 protected void cleanup(String [] config, IProgressMonitor monitor) { 538 monitor.beginTask("", 2); fDevProperties = null; 541 fAntBuildProperties = null; 542 543 File scriptFile = null; 544 try { 545 scriptFile = createScriptFile("zip.xml"); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 547 Document doc = factory.newDocumentBuilder().newDocument(); 548 549 Element root = doc.createElement("project"); root.setAttribute("name", "temp"); root.setAttribute("default", "clean"); root.setAttribute("basedir", "."); doc.appendChild(root); 554 555 Element target = doc.createElement("target"); target.setAttribute("name", "clean"); Element child = doc.createElement("delete"); child.setAttribute("dir", fBuildTempLocation); target.appendChild(child); 560 root.appendChild(target); 561 562 if (fHasErrors) { 563 target = doc.createElement("target"); target.setAttribute("name", "zip.logs"); child = doc.createElement("zip"); child.setAttribute("zipfile", fInfo.destinationDirectory + logName(config)); child.setAttribute("basedir", fBuildTempLocation + "/pde.logs"); target.appendChild(child); 569 root.appendChild(target); 570 } 571 XMLPrintHandler.writeFile(doc, scriptFile); 572 573 String [] targets = fHasErrors 574 ? new String [] {"zip.logs", "clean"} : new String [] {"clean"}; AntRunner runner = new AntRunner(); 577 runner.setBuildFileLocation(scriptFile.getAbsolutePath()); 578 runner.setExecutionTargets(targets); 579 runner.run(new SubProgressMonitor(monitor, 1)); 580 } catch (FactoryConfigurationError e) { 581 } catch (ParserConfigurationException e) { 582 } catch (CoreException e) { 583 } catch (IOException e) { 584 } finally { 585 if (scriptFile != null && scriptFile.exists()) 586 scriptFile.delete(); 587 monitor.done(); 588 } 589 } 590 591 protected File createScriptFile(String filename) throws IOException { 592 String path = PDECore.getDefault().getStateLocation().toOSString(); 593 File zip = new File (path, filename); 594 if (zip.exists()) { 595 zip.delete(); 596 zip.createNewFile(); 597 } 598 return zip; 599 } 600 601 private String logName(String [] config) { 602 if (config == null) 603 return "/logs.zip"; return "/logs." + config[0] + '.' + config[1] + '.' + config[2] + ".zip"; } 606 607 protected void createFeature(String featureID, String featureLocation, String [] config, boolean includeLauncher) throws IOException { 608 File file = new File (featureLocation); 609 if (!file.exists() || !file.isDirectory()) 610 file.mkdirs(); 611 612 try { 613 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 614 Document doc = factory.newDocumentBuilder().newDocument(); 615 Element root = doc.createElement("feature"); root.setAttribute("id", featureID); root.setAttribute("version", "1.0"); doc.appendChild(root); 619 620 if (includeLauncher) { 621 IFeatureModel model = PDECore.getDefault().getFeatureModelManager().getDeltaPackFeature(); 622 if (model != null) { 623 IFeature feature = model.getFeature(); 624 Element includes = doc.createElement("includes"); includes.setAttribute("id", feature.getId()); includes.setAttribute("version", feature.getVersion()); root.appendChild(includes); 628 } 629 } 630 Dictionary environment = new Hashtable (4); 631 environment.put("osgi.os", config[0]); environment.put("osgi.ws", config[1]); environment.put("osgi.arch", config[2]); environment.put("osgi.nl", config[3]); 636 for (int i = 0; i < fInfo.items.length; i++) { 637 if (fInfo.items[i] instanceof IFeatureModel) { 638 IFeature feature = ((IFeatureModel) fInfo.items[i]).getFeature(); 639 Element includes = doc.createElement("includes"); includes.setAttribute("id", feature.getId()); includes.setAttribute("version", feature.getVersion()); root.appendChild(includes); 643 } else { 644 BundleDescription bundle = null; 645 if (fInfo.items[i] instanceof IPluginModelBase) { 646 bundle = ((IPluginModelBase)fInfo.items[i]).getBundleDescription(); 647 } 648 if (bundle == null) { 649 if (fInfo.items[i] instanceof BundleDescription) 650 bundle = (BundleDescription)fInfo.items[i]; 651 } 652 if (bundle == null) 653 continue; 654 if (shouldAddPlugin(bundle, environment)) { 655 Element plugin = doc.createElement("plugin"); plugin.setAttribute("id", bundle.getSymbolicName()); plugin.setAttribute("version", bundle.getVersion().toString()); setAdditionalAttributes(plugin, bundle); 659 root.appendChild(plugin); 660 } 661 } 662 } 663 XMLPrintHandler.writeFile(doc, new File (file, "feature.xml")); } catch (DOMException e1) { 665 } catch (FactoryConfigurationError e1) { 666 } catch (ParserConfigurationException e1) { 667 } 668 } 669 670 protected void setAdditionalAttributes(Element plugin, BundleDescription bundle){ 671 } 672 673 public boolean hasErrors() { 674 return fHasErrors; 675 } 676 677 public static void errorFound() { 678 fHasErrors = true; 679 } 680 681 protected boolean shouldAddPlugin(BundleDescription bundle, Dictionary environment) { 682 String filterSpec = bundle.getPlatformFilter(); 683 try { 684 return (filterSpec == null|| PDECore.getDefault().getBundleContext().createFilter(filterSpec).match(environment)); 685 } catch (InvalidSyntaxException e) { 686 } 687 return false; 688 } 689 } 690 | Popular Tags |