1 12 package org.eclipse.update.internal.provisional; 13 14 import java.io.File ; 15 import java.io.FileInputStream ; 16 import java.io.FileNotFoundException ; 17 import java.io.FileOutputStream ; 18 import java.io.IOException ; 19 import java.io.InputStream ; 20 import java.io.OutputStream ; 21 import java.io.PrintStream ; 22 import java.util.ArrayList ; 23 import java.util.Enumeration ; 24 import java.util.HashMap ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.Map ; 28 import java.util.Properties ; 29 import java.util.jar.JarFile ; 30 import java.util.jar.JarOutputStream ; 31 import java.util.zip.ZipEntry ; 32 33 import org.eclipse.core.runtime.CoreException; 34 import org.eclipse.core.runtime.IPlatformRunnable; 35 import org.eclipse.core.runtime.IStatus; 36 import org.eclipse.core.runtime.Platform; 37 import org.eclipse.core.runtime.Status; 38 import org.eclipse.osgi.util.NLS; 39 import org.eclipse.update.core.IIncludedFeatureReference; 40 import org.eclipse.update.core.IncludedFeatureReference; 41 import org.eclipse.update.core.model.DefaultSiteParser; 42 import org.eclipse.update.core.model.FeatureModel; 43 import org.eclipse.update.core.model.FeatureModelFactory; 44 import org.eclipse.update.core.model.FeatureReferenceModel; 45 import org.eclipse.update.core.model.ImportModel; 46 import org.eclipse.update.core.model.PluginEntryModel; 47 import org.eclipse.update.core.model.SiteModel; 48 import org.eclipse.update.core.model.URLEntryModel; 49 import org.eclipse.update.internal.core.ExtendedSiteURLFactory; 50 import org.eclipse.update.internal.core.Messages; 51 import org.eclipse.update.internal.core.UpdateManagerUtils; 52 import org.eclipse.update.internal.jarprocessor.JarProcessor; 53 import org.eclipse.update.internal.jarprocessor.JarProcessorExecutor; 54 import org.eclipse.update.internal.jarprocessor.Main; 55 import org.xml.sax.SAXException ; 56 57 72 public class SiteOptimizerApplication implements IPlatformRunnable { 73 public final static Integer EXIT_ERROR = new Integer (1); 74 75 public final static String JAR_PROCESSOR = "-jarProcessor"; 77 public final static String DIGEST_BUILDER = "-digestBuilder"; 79 public final static String INPUT = "input"; 81 public final static String OUTPUT_DIR = "-outputDir"; 83 public final static String VERBOSE = "-verbose"; 85 public final static String JAR_PROCESSOR_PACK = "-pack"; 87 public final static String JAR_PROCESSOR_UNPACK = "-unpack"; 89 public final static String JAR_PROCESSOR_REPACK = "-repack"; 91 public final static String JAR_PROCESSOR_SIGN = "-sign"; 93 public final static String JAR_PROCESSOR_PROCESS_ALL = "-processAll"; 95 public final static String SITE_XML = "-siteXML"; 97 public final static String SITE_ATTRIBUTES_FILE = "siteAttributes.txt"; 99 public final static String DIGEST_OUTPUT_DIR = "-digestOutputDir"; 101 106 107 115 private Map parseCmdLine(String [] args) { 116 Map cmds = new HashMap (); 117 for (int i = 0; i < args.length; i++) { 118 if (i == args.length - 1 && !args[i].startsWith("-")) { cmds.put(INPUT, args[i]); 120 } else { 121 String key = args[i]; 122 String val = null; 123 if (i < args.length - 2 && !args[i + 1].startsWith("-")) { val = args[++i]; 125 } 126 127 if (key.startsWith(SITE_XML)) { 128 val = key.substring(key.indexOf("=") + 1); cmds.put(SITE_XML, val); 132 } else if (key.startsWith(DIGEST_OUTPUT_DIR)) { 133 val = key.substring(key.indexOf("=") + 1); cmds.put(DIGEST_OUTPUT_DIR, val); 136 } else { 137 138 cmds.put(key, val); 140 } 141 } 142 } 143 return cmds; 144 } 145 146 private boolean runJarProcessor(Map params) { 147 Main.Options options = new Main.Options(); 148 options.pack = params.containsKey(JAR_PROCESSOR_PACK); 149 options.unpack = params.containsKey(JAR_PROCESSOR_UNPACK); 150 options.repack = params.containsKey(JAR_PROCESSOR_REPACK); 151 options.processAll = params.containsKey(JAR_PROCESSOR_PROCESS_ALL); 152 options.verbose = params.containsKey(VERBOSE); 153 options.signCommand = (String ) params.get(JAR_PROCESSOR_SIGN); 154 options.outputDir = (String ) params.get(OUTPUT_DIR); 155 156 String problem = null; 157 158 String input = (String ) params.get(INPUT); 159 if (input == null) 160 problem = Messages.SiteOptimizer_inputNotSpecified; 161 else { 162 File inputFile = new File (input); 163 if (inputFile.exists()) 164 options.input = inputFile; 165 else 166 problem = NLS.bind(Messages.SiteOptimizer_inputFileNotFound, 167 new String [] { input }); 168 } 169 170 if (options.unpack) { 171 if (!JarProcessor.canPerformUnpack()) { 172 problem = Messages.JarProcessor_unpackNotFound; 173 } else if (options.pack || options.repack 174 || options.signCommand != null) { 175 problem = Messages.JarProcessor_noPackUnpack; 176 } 177 } else if ((options.pack || options.repack) 178 && !JarProcessor.canPerformPack()) { 179 problem = Messages.JarProcessor_packNotFound; 180 } 181 182 if (problem != null) { 183 System.out.println(problem); 184 return false; 185 } 186 187 new JarProcessorExecutor().runJarProcessor(options); 188 return true; 189 } 190 191 private boolean runDigestBuilder(Map params) { 192 193 List featureList = getFeatureList(params); 194 195 if ((featureList == null) || featureList.isEmpty()) { 196 System.out.println("no features to process"); return false; 198 } 199 Map perFeatureLocales = new HashMap (); 200 Map availableLocales = getAvailableLocales(featureList, 201 perFeatureLocales); 202 try { 203 openInputStremas(availableLocales); 204 } catch (IOException e1) { 205 e1.printStackTrace(); 206 System.out.println("Can not create file in output direcotry"); return false; 208 } 209 210 for(int i = 0; i < featureList.size(); i++) { 211 212 String featureJarFileName = (String ) featureList.get(i); 213 214 if (featureJarFileName.endsWith("jar")) { System.out.println("Processing... " + featureJarFileName); } else { 217 System.out.println("Skipping... " + featureJarFileName); continue; 219 } 220 221 JarFile featureJar = null; 222 try { 223 featureJar = new JarFile (featureJarFileName); 224 } catch (IOException e) { 225 System.out.println("Problem with openning jar: " + featureJarFileName); 227 e.printStackTrace(); 228 return false; 229 } 230 FeatureModelFactory fmf = new FeatureModelFactory(); 231 232 try { 233 ZipEntry featureXMLEntry = featureJar.getEntry("feature.xml"); Map featureProperties = loadProperties(featureJar, 235 featureJarFileName, perFeatureLocales); 236 237 FeatureModel featureModel = fmf.parseFeature(featureJar 238 .getInputStream(featureXMLEntry)); 239 240 featureList = addFeaturesToList( (String ) params.get(SITE_XML), featureList, featureModel.getFeatureIncluded(), availableLocales, perFeatureLocales); 241 242 Iterator availableLocalesIterator = availableLocales.values() 243 .iterator(); 244 while (availableLocalesIterator.hasNext()) { 245 ((AvailableLocale) availableLocalesIterator.next()) 246 .writeFeatureDigests(featureModel, 247 featureProperties); 248 } 249 250 } catch (SAXException e) { 251 e.printStackTrace(); 252 return false; 253 } catch (IOException e) { 254 e.printStackTrace(); 255 return false; 256 } catch (CoreException e) { 257 e.printStackTrace(); 258 return false; 259 } 260 } 261 Iterator availableLocalesIterator = availableLocales.values() 262 .iterator(); 263 String outputDirectory = (String ) params.get(DIGEST_OUTPUT_DIR); 264 265 outputDirectory = outputDirectory.substring(outputDirectory 266 .indexOf("=") + 1); if (!outputDirectory.endsWith(File.separator)) { 268 outputDirectory = outputDirectory + File.separator; 269 } 270 while (availableLocalesIterator.hasNext()) { 271 try { 272 ((AvailableLocale) availableLocalesIterator.next()) 273 .finishDigest(outputDirectory); 274 } catch (IOException e) { 275 System.out.println("Can not write in digest output directory: " + outputDirectory); 277 e.printStackTrace(); 278 return false; 279 } 280 } 281 System.out.println("Done"); return true; 283 } 284 285 private List addFeaturesToList( String siteXML, List featureList, IIncludedFeatureReference[] iIncludedFeatureReferences, Map availableLocales, Map perFeatureLocales ) throws CoreException { 286 287 String directoryName = (new File (siteXML)).getParent(); 288 if (!directoryName.endsWith(File.separator)) { 289 directoryName = directoryName + File.separator; 290 } 291 directoryName = directoryName + "features" + File.separator; 293 for (int i = 0; i < iIncludedFeatureReferences.length; i++) { 294 String featureURL = directoryName + iIncludedFeatureReferences[i].getVersionedIdentifier() + ".jar"; if (!(isFeatureAlreadyInList(featureList, featureURL))) { 296 try { 297 System.out.println("Extracting locales from inlcuded feature " + featureURL); processLocalesInJar(availableLocales, featureURL, perFeatureLocales, true); 299 } catch (IOException e) { 300 if (iIncludedFeatureReferences[i].isOptional()) 301 continue; 302 System.out.println("Error while extracting locales from inlcuded feature " + featureURL); e.printStackTrace(); 304 throw new CoreException( new Status( IStatus.ERROR, "", IStatus.OK, "Error while extracting locales from inlcuded feature " + featureURL, e)); } 306 featureList.add(featureURL); 307 } 308 } 309 310 return featureList; 311 } 312 313 private boolean isFeatureAlreadyInList(List featureList, String featureURL) { 314 for (int i = 0; i < featureList.size(); i++) { 315 String currentFeatureURL = (String )featureList.get(i); 316 if (currentFeatureURL.equals(featureURL)) { 317 return true; 318 } 319 } 320 return false; 321 } 322 323 private Map loadProperties(JarFile featureJar, String featureJarFileName, 324 Map perFeatureLocales) { 325 Iterator it = ((List ) perFeatureLocales.get(featureJarFileName)) 328 .iterator(); 329 Map result = new HashMap (); 330 while (it.hasNext()) { 331 String propertyFileName = (String ) it.next(); 332 333 ZipEntry featurePropertiesEntry = featureJar 334 .getEntry(propertyFileName); 335 Properties featureProperties = new Properties (); 336 if (featurePropertiesEntry != null) { 337 try { 338 featureProperties.load(featureJar 339 .getInputStream(featurePropertiesEntry)); 340 String localeString = null; 341 if (propertyFileName.endsWith("feature.properties")) { localeString = ""; } else { 344 localeString = propertyFileName.substring(8, 345 propertyFileName.indexOf('.')); 346 } 347 result.put(localeString, featureProperties); 348 } catch (IOException e) { 349 e.printStackTrace(); 350 } 351 } 352 } 353 return result; 354 } 355 356 private void openInputStremas(Map availableLocales) throws IOException { 357 Iterator locales = availableLocales.values().iterator(); 358 while (locales.hasNext()) { 359 AvailableLocale availableLocale = (AvailableLocale) locales.next(); 360 availableLocale.openLocalizedOutputStream(); 361 } 362 } 363 364 private Map getAvailableLocales(List featureList, Map perFeatureLocales) { 365 Iterator features = featureList.iterator(); 366 Map locales = new HashMap (); 367 while (features.hasNext()) { 368 String feature = (String ) features.next(); 369 try { 370 System.out.println("Extracting locales from " + feature); processLocalesInJar(locales, feature, perFeatureLocales, false); 372 } catch (IOException e) { 373 System.out.println("Error while extracting locales from " + feature); 375 e.printStackTrace(); 376 return null; 377 } 378 } 379 return locales; 380 } 381 382 private void processLocalesInJar(Map locales, String feature, 383 Map perFeatureLocales, boolean ignoreNewLocales) throws IOException { 384 385 JarFile jar = new JarFile (feature); 386 Enumeration files = jar.entries(); 388 389 List localesTemp = new ArrayList (); 390 perFeatureLocales.put(feature, localesTemp); 391 392 while (files.hasMoreElements()) { 393 ZipEntry file = (ZipEntry ) files.nextElement(); 394 String localeString = null; 395 String name = file.getName(); 396 if (name.startsWith("feature") && name.endsWith(".properties")) { localesTemp.add(name); 400 if (name.endsWith("feature.properties")) { localeString = ""; } else { 404 localeString = name.substring(8, name.indexOf('.')); 405 } 406 if ( !ignoreNewLocales && !locales.containsKey(localeString)) { 408 locales.put(localeString, new AvailableLocale(localeString)); 409 } 410 if (locales.containsKey(localeString)) { 411 AvailableLocale currentLocale = (AvailableLocale) locales.get(localeString); 412 currentLocale.addFeatures(feature); 413 } 414 } 415 } 416 417 } 418 419 private List getFeatureList(Map params) { 420 if (params.containsKey(SITE_XML) 421 && (fileExists((String ) params.get(SITE_XML)))) { 422 return getFeatureListFromSiteXML((String ) params.get(SITE_XML)); 423 } else if (params.containsKey(INPUT) 424 && isDirectory((String ) params 425 .get(SiteOptimizerApplication.INPUT))) { 426 return getFeatureListFromDirectory((String ) params.get(INPUT)); 427 } 428 return null; 429 } 430 431 private boolean fileExists(String fileName) { 432 File file = new File (fileName); 434 if ((file != null) && file.exists()) 435 return true; 436 return false; 437 } 438 439 private List getFeatureListFromDirectory(String directoryName) { 440 List featuresURLs = new ArrayList (); 441 File directory = new File (directoryName); 442 String [] featureJarFileNames = directory.list(); 443 for (int i = 0; i < featureJarFileNames.length; i++) { 444 featuresURLs.add(directoryName + File.separator 445 + featureJarFileNames[i]); 446 } 447 return featuresURLs; 448 } 449 450 private boolean isDirectory(String fileName) { 451 452 File directory = new File (fileName); 453 if ((directory != null) && directory.exists() 454 && directory.isDirectory()) 455 return true; 456 return false; 457 } 458 459 private List getFeatureListFromSiteXML(String siteXML) { 460 461 List featuresURLs = new ArrayList (); 462 String directoryName = (new File (siteXML)).getParent(); 463 if (!directoryName.endsWith(File.separator)) { 464 directoryName = directoryName + File.separator; 465 } 466 467 DefaultSiteParser siteParser = new DefaultSiteParser(); 468 siteParser.init(new ExtendedSiteURLFactory()); 469 470 try { 471 SiteModel site = siteParser.parse(new FileInputStream (siteXML)); 472 if(site.getFeatureReferenceModels().length > 0) { 473 site.getFeatureReferenceModels()[0].getURLString(); 474 FeatureReferenceModel[] featureReferenceModel = site 475 .getFeatureReferenceModels(); 476 for (int i = 0; i < featureReferenceModel.length; i++) { 477 featuresURLs.add(directoryName 478 + featureReferenceModel[i].getURLString()); 479 } 480 } 481 return featuresURLs; 482 } catch (FileNotFoundException e) { 483 System.out.println("File not found: " + e.getMessage()); e.printStackTrace(); 485 } catch (SAXException e) { 486 System.out.println("Parsing problem: " + e.getMessage()); e.printStackTrace(); 488 } catch (IOException e) { 489 System.out.println("Problem while parsing: " + e.getMessage()); e.printStackTrace(); 491 } 492 return null; 493 } 494 495 500 public Object run(Object args) throws Exception { 501 Platform.endSplash(); 502 if (args == null) 503 return EXIT_ERROR; 504 if (args instanceof String []) { 505 Map params = parseCmdLine((String []) args); 506 if (params.containsKey(JAR_PROCESSOR)) { 507 if (!runJarProcessor(params)) 508 return EXIT_ERROR; 509 } 510 511 if (params.containsKey(DIGEST_BUILDER)) { 512 if (!runDigestBuilder(params)) 513 return EXIT_ERROR; 514 } 515 } 516 return IPlatformRunnable.EXIT_OK; 517 } 518 519 private class AvailableLocale { 520 521 private String PREFIX = "temp"; 523 private String locale; 524 525 private Map features = new HashMap (); 526 527 private PrintStream localizedPrintStream; 528 529 private File tempDigestDirectory; 530 531 public Map availableLocales; 532 533 public Map getAvailableLocales() { 534 return availableLocales; 535 } 536 537 public void finishDigest(String outputDirectory) throws IOException { 538 localizedPrintStream.println("</digest>"); if (localizedPrintStream != null) { 540 localizedPrintStream.close(); 541 } 542 543 File digest = new File (outputDirectory + File.separator + "digest" + (locale == null || locale.equals("") ? "" : "_"+locale) + ".zip"); System.out.println(digest.getAbsolutePath()); 546 System.out.println(digest.getName()); 547 if (digest.exists()) { 548 digest.delete(); 549 } 550 digest.createNewFile(); 551 OutputStream os = new FileOutputStream (digest); 552 JarOutputStream jos = new JarOutputStream (os); 553 jos.putNextEntry(new ZipEntry ("digest.xml")); InputStream is = new FileInputStream (tempDigestDirectory); 555 byte[] b = new byte[4096]; 556 int bytesRead = 0; 557 do { 558 bytesRead = is.read(b); 559 if (bytesRead > 0) { 560 jos.write(b, 0, bytesRead); 561 } 562 } while (bytesRead > 0); 563 564 jos.closeEntry(); 565 jos.close(); 566 os.close(); 567 is.close(); 568 tempDigestDirectory.delete(); 569 570 } 571 572 public void setAvailableLocales(Map availableLocales) { 573 this.availableLocales = availableLocales; 574 } 575 576 public AvailableLocale(String locale) { 577 this.locale = locale; 578 } 579 580 public Map getFeatures() { 581 return features; 582 } 583 584 public void addFeatures(String feature) { 585 features.put(feature, feature); 586 } 587 588 public String getLocale() { 589 return locale; 590 } 591 592 public PrintStream getLocalizedPrintStream() { 593 return localizedPrintStream; 594 } 595 596 public void openLocalizedOutputStream() throws IOException { 597 tempDigestDirectory = File.createTempFile(PREFIX, null); 598 FileOutputStream fstream = new FileOutputStream (tempDigestDirectory); 599 localizedPrintStream = new PrintStream (fstream); 600 localizedPrintStream 601 .println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <digest>"); tempDigestDirectory.deleteOnExit(); 603 } 604 605 public int hashCode() { 606 return locale.hashCode(); 607 } 608 609 public boolean equals(Object obj) { 610 611 if (this == obj) 612 return true; 613 if (obj == null) 614 return false; 615 if (getClass() != obj.getClass()) 616 return false; 617 final AvailableLocale other = (AvailableLocale) obj; 618 if (locale == null) { 619 if (other.locale != null) 620 return false; 621 } else if (!locale.equals(other.locale)) 622 return false; 623 return true; 624 } 625 626 public void writeFeatureDigests(FeatureModel featureModel, 627 Map featureProperties) { 628 629 if (this.locale.equals("")) { writeFeatureDigest(localizedPrintStream, featureModel, 631 (Properties ) featureProperties.get("")); return; 633 } 634 Properties temp = new Properties (); 635 if (locale.indexOf("_") < 0) { temp = combineProperties( 637 (Properties ) featureProperties.get(""), (Properties ) featureProperties.get(locale), temp); 639 writeFeatureDigest(localizedPrintStream, featureModel, temp); 640 } else { 641 temp = combineProperties((Properties ) featureProperties 642 .get(locale.substring(locale.indexOf("_") + 1)), (Properties ) featureProperties.get(locale), temp); 644 writeFeatureDigest(localizedPrintStream, featureModel, temp); 645 } 646 647 } 648 649 private Properties combineProperties(Properties properties, 650 Properties properties2, Properties properties3) { 651 return new CombinedProperties(properties3, properties2, properties); 652 653 } 654 655 } 656 657 public static void writeFeatureDigest(PrintStream digest, 658 FeatureModel featureModel, Properties featureProperties) { 659 660 String label = null; 661 String provider = null; 662 String description = null; 663 String license = null; 664 String copyright = null; 665 666 if ((featureProperties != null) 667 && featureModel.getLabel().startsWith("%")) { label = featureProperties.getProperty(featureModel.getLabel() 669 .substring(1)); 670 } else { 671 label = featureModel.getLabel(); 672 } 673 if ((featureProperties != null) 674 && (featureModel.getDescriptionModel() != null) 675 && featureModel.getDescriptionModel().getAnnotation() 676 .startsWith("%")) { description = featureProperties.getProperty(featureModel 679 .getDescriptionModel().getAnnotation().substring(1)); 680 } else { 681 URLEntryModel descriptionModel = featureModel.getDescriptionModel(); 682 if( descriptionModel == null ) 683 description = ""; 684 else 685 description = descriptionModel.getAnnotation(); 686 } 687 String pvalue = featureModel.getProvider(); 688 if ((featureProperties != null) 689 && pvalue!=null && pvalue.startsWith("%")) { provider = featureProperties.getProperty(featureModel.getProvider() 691 .substring(1)); 692 } else { 693 provider = pvalue; 694 } 695 if (provider==null) provider = ""; 696 697 if (((featureProperties != null) && featureModel.getCopyrightModel() != null) 698 && featureModel.getCopyrightModel().getAnnotation().startsWith( 699 "%")) { copyright = featureProperties.getProperty(featureModel 701 .getCopyrightModel().getAnnotation().substring(1)); 702 } else { 703 if (featureModel.getCopyrightModel() != null) { 704 copyright = featureModel.getCopyrightModel().getAnnotation(); 705 } else { 706 copyright = null; 707 } 708 } 709 710 if ((featureProperties != null) 711 && (featureModel.getLicenseModel() != null) 712 && featureModel.getLicenseModel().getAnnotation().startsWith( 713 "%")) { license = featureProperties.getProperty(featureModel 715 .getLicenseModel().getAnnotation().substring(1)); 716 } else { 717 license = featureModel.getLicenseModel().getAnnotation(); 718 } 719 720 digest.print("<feature "); digest.print("label=\"" + label + "\" "); digest.print("provider-name=\"" + provider + "\" "); digest.print("id=\"" + featureModel.getFeatureIdentifier() + "\" "); digest.print("version=\"" + featureModel.getFeatureVersion() + "\" "); if (featureModel.getOS() != null) 726 digest.print("os=\"" + featureModel.getOS() + "\" "); if (featureModel.getNL() != null) 728 digest.print("nl=\"" + featureModel.getNL() + "\" "); if (featureModel.getWS() != null) 730 digest.print("ws=\"" + featureModel.getWS() + "\" "); if (featureModel.getOSArch() != null) 732 digest.print("arch=\"" + featureModel.getOSArch() + "\" "); if (featureModel.isExclusive()) 734 digest.print("exclusive=\"" + featureModel.isExclusive() + "\" "); 736 if (((featureModel.getImportModels() == null) || (featureModel 737 .getImportModels().length == 0)) 738 && ((featureModel.getDescriptionModel() == null) 739 || (featureModel.getDescriptionModel().getAnnotation() == null) || (featureModel 740 .getDescriptionModel().getAnnotation().trim().length() == 0)) 741 && ((featureModel.getCopyrightModel() == null) 742 || (featureModel.getCopyrightModel().getAnnotation() == null) || (featureModel 743 .getCopyrightModel().getAnnotation().trim().length() == 0)) 744 && ((featureModel.getLicenseModel() == null) 745 || (featureModel.getLicenseModel().getAnnotation() == null) || (featureModel 746 .getLicenseModel().getAnnotation().trim().length() == 0)) 747 && ((featureModel.getFeatureIncluded() == null) || (featureModel 748 .getFeatureIncluded().length == 0))){ 749 digest.println("/> "); } else { 751 digest.println("> "); if (featureModel.getImportModels().length > 0) { 753 754 digest.println("\t<requires> "); ImportModel[] imports = featureModel.getImportModels(); 756 for (int j = 0; j < imports.length; j++) { 757 digest.print("\t\t<import "); if (imports[j].isFeatureImport()) { 759 digest.print("feature=\""); } else { 761 digest.print("plugin=\""); } 763 digest.print(imports[j].getIdentifier() + "\" "); digest.print("version=\""); digest.print(imports[j].getVersion() + "\" "); digest.print("match=\""); digest.print(imports[j].getMatchingRuleName() + "\" "); if (imports[j].isPatch()) { 769 digest.print("patch=\"true\" "); } 771 digest.println(" />"); } 773 774 digest.println("\t</requires>"); 776 } 777 778 if ((featureModel.getDescriptionModel() != null) 779 && (featureModel.getDescriptionModel().getAnnotation() != null) 780 && (featureModel.getDescriptionModel().getAnnotation() 781 .trim().length() != 0)) { 782 digest.println("\t<description>"); digest.println("\t\t" + UpdateManagerUtils.getWritableXMLString(description)); digest.println("\t</description>"); } 786 787 if (featureModel.getCopyrightModel() != null) { 788 if (featureModel.getCopyrightModel().getAnnotation() != null) { 789 digest.println("\t<copyright>"); digest.println("\t\t" + UpdateManagerUtils.getWritableXMLString(copyright)); digest.println("\t</copyright>"); } 797 } 798 799 if ((featureModel.getLicenseModel() != null) 800 && (featureModel.getLicenseModel().getAnnotation() != null) 801 && (featureModel.getLicenseModel().getAnnotation() 802 .trim().length() != 0)) { 803 digest.println("\t<license>"); digest.println("\t\t" + UpdateManagerUtils.getWritableXMLString(license)); digest.println("\t</license>"); } 807 808 PluginEntryModel[] plugins = featureModel.getPluginEntryModels(); 809 if ((plugins != null) && (plugins.length != 0)) { 810 for (int i = 0; i < plugins.length; i++) { 811 digest.print("\t<plugin "); digest.print("id=\"" + plugins[i].getPluginIdentifier() + "\" "); digest.print("version=\"" + plugins[i].getPluginVersion() + "\" "); if (plugins[i].getOS() != null) 817 digest.print("os=\"" + plugins[i].getOS() + "\" "); if (plugins[i].getNL() != null) 819 digest.print("nl=\"" + plugins[i].getNL() + "\" "); if (plugins[i].getWS() != null) 821 digest.print("ws=\"" + plugins[i].getWS() + "\" "); if (plugins[i].getOSArch() != null) 823 digest 824 .print("arch=\"" + plugins[i].getOSArch() + "\" "); if (plugins[i].getDownloadSize() > 0) 827 digest.print("download-size=\"" + plugins[i].getDownloadSize() + "\" "); if (plugins[i].getInstallSize() > 0) 830 digest.print("install-size=\"" + plugins[i].getInstallSize() + "\" "); if (!plugins[i].isUnpack()) 833 digest.print("unpack=\"" + plugins[i].isUnpack() + "\" "); 836 digest.println("/> "); } 838 } 839 840 IIncludedFeatureReference[] inlcudedFeatures = featureModel.getFeatureIncluded(); 841 842 if ((inlcudedFeatures != null) && (inlcudedFeatures.length != 0)) { 843 for (int i = 0; i < inlcudedFeatures.length; i++) { 844 try { 845 digest.print("\t<includes "); 847 digest.print("id=\"" + inlcudedFeatures[i].getVersionedIdentifier().getIdentifier() + "\" "); digest.print("version=\"" + inlcudedFeatures[i].getVersionedIdentifier().getVersion() + "\" "); if (inlcudedFeatures[i].getOS() != null) 850 digest.print("os=\"" + inlcudedFeatures[i].getOS() + "\" "); if (inlcudedFeatures[i].getNL() != null) 852 digest.print("nl=\"" + inlcudedFeatures[i].getNL() + "\" "); if (inlcudedFeatures[i].getWS() != null) 854 digest.print("ws=\"" + inlcudedFeatures[i].getWS() + "\" "); if (inlcudedFeatures[i].getOSArch() != null) 856 digest.print("arch=\"" + inlcudedFeatures[i].getOSArch() + "\" "); if ( (inlcudedFeatures[i] instanceof IncludedFeatureReference) && (((IncludedFeatureReference)inlcudedFeatures[i]).getLabel() != null)) 858 digest.print("name=\"" + inlcudedFeatures[i].getName() + "\" "); if (inlcudedFeatures[i].isOptional()) 860 digest.print("optional=\"true\""); digest.print("search-location=\"" + inlcudedFeatures[i].getSearchLocation() + "\" "); 863 digest.println("/> "); } catch (CoreException e) { 865 e.printStackTrace(); 867 } 868 } 869 } 870 digest.println("</feature>"); } 872 } 873 874 private class CombinedProperties extends Properties { 875 876 private Properties properties1; 877 878 private Properties properties2; 879 880 private Properties properties3; 881 882 public CombinedProperties(Properties properties1, 883 Properties properties2, Properties properties3) { 884 this.properties1 = properties1; 885 this.properties2 = properties2; 886 this.properties3 = properties3; 887 } 888 889 892 private static final long serialVersionUID = 1L; 893 894 public String getProperty(String key) { 895 String result = null; 896 if (properties3 != null && properties3.containsKey(key)) 897 result = properties3.getProperty(key); 898 if (properties2 != null && properties2.containsKey(key)) 899 result = properties2.getProperty(key); 900 if (properties1 != null && properties1.containsKey(key)) 901 result = properties1.getProperty(key); 902 return result; 903 } 904 905 } 906 907 } 908 | Popular Tags |