1 11 package org.eclipse.pde.internal.build; 12 13 import java.io.*; 14 import java.util.*; 15 import org.eclipse.ant.core.AntRunner; 16 import org.eclipse.core.runtime.*; 17 import org.eclipse.osgi.util.NLS; 18 import org.eclipse.pde.build.Constants; 19 import org.eclipse.pde.build.IFetchFactory; 20 import org.eclipse.pde.internal.build.ant.AntScript; 21 import org.eclipse.pde.internal.build.fetch.CVSFetchTaskFactory; 22 import org.eclipse.update.core.*; 23 import org.eclipse.update.internal.core.FeatureExecutableFactory; 24 import org.osgi.framework.Version; 25 26 30 public class FetchScriptGenerator extends AbstractScriptGenerator { 31 private static final String FETCH_TASK_FACTORY = "internal.factory"; private static final String MATCHED_VERSION = "internal.matchedVersion"; 34 protected boolean recursiveGeneration = true; 36 37 protected Properties directoryFile; 39 protected String directoryLocation; 40 protected SortedMap directory; 41 42 protected String cvsPassFileLocation; 44 45 protected boolean fetchChildren = true; 46 47 protected Properties fetchTags = null; 48 49 protected String element; 51 protected Version elementVersion; 52 53 protected IFeature feature; 55 protected Map mapInfos; 57 protected Properties featureProperties; 59 protected List mkdirLocations = new ArrayList(5); 61 protected Properties repositoryPluginTags = new Properties(); 63 protected Properties repositoryFeatureTags = new Properties(); 64 65 private FetchTaskFactoriesRegistry fetchTaskFactories; 67 private Set encounteredTypeOfRepo = new HashSet(); 69 70 public static final String FEATURE_ONLY = "featureOnly"; public static final String FEATURE_AND_PLUGINS = "featureAndPlugins"; public static final String FEATURES_RECURSIVELY = "featuresRecursively"; public static final String FETCH_FILE_PREFIX = "fetch_"; 75 private String scriptName; 76 77 public FetchScriptGenerator() { 78 super(); 79 } 80 81 public FetchScriptGenerator(String element) { 82 setElement(element); 83 } 84 85 public void setElement(String element) { 86 Object [] split = splitElement(element); 87 this.element = (String ) split[0]; 88 this.elementVersion = (Version) split[1]; 89 } 90 91 private Object [] splitElement(String elt) { 92 int comma = elt.indexOf(','); 93 if (comma == -1) { 94 return new Object [] {elt, Version.emptyVersion}; 95 } 96 return new Object [] {elt.substring(0, comma), new Version(elt.substring(comma + 1))}; 97 } 98 99 private void initializeFactories() { 100 fetchTaskFactories = new FetchTaskFactoriesRegistry(); 101 } 102 103 106 public void generate() throws CoreException { 107 initializeFactories(); 108 mapInfos = processMapFileEntry(element, elementVersion); 109 if (mapInfos == null) { 110 IStatus warning = new Status(IStatus.WARNING, PI_PDEBUILD, WARNING_ELEMENT_NOT_FETCHED, NLS.bind(Messages.error_fetchingFailed, element), null); 111 BundleHelper.getDefault().getLog().log(warning); 112 return; 113 } 114 115 scriptName = FETCH_FILE_PREFIX + mapInfos.get(IFetchFactory.KEY_ELEMENT_NAME) + ".xml"; openScript(workingDirectory, scriptName); 117 try { 118 generateFetchScript(); 119 } finally { 120 closeScript(); 121 } 122 123 if (recursiveGeneration && mapInfos.get(IFetchFactory.KEY_ELEMENT_TYPE).equals(IFetchFactory.ELEMENT_TYPE_FEATURE)) 124 generateFetchFilesForIncludedFeatures(); 125 126 saveRepositoryTags(); 127 } 128 129 private void saveRepositoryTags(Properties properties, String fileName) throws CoreException { 130 try { 131 InputStream input = new BufferedInputStream(new FileInputStream(workingDirectory + '/' + fileName)); 132 try { 133 properties.load(input); 134 } finally { 135 input.close(); 136 } 137 } catch (IOException e) { 138 } 140 141 try { 142 OutputStream os = new BufferedOutputStream(new FileOutputStream(workingDirectory + '/' + fileName)); 143 try { 144 properties.store(os, null); 145 } finally { 146 os.close(); 147 } 148 } catch (IOException e) { 149 String message = NLS.bind(Messages.exception_writingFile, workingDirectory + '/' + fileName); 150 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, null)); 151 } 152 } 153 154 private void saveRepositoryTags() throws CoreException { 155 saveRepositoryTags(repositoryPluginTags, DEFAULT_PLUGIN_REPOTAG_FILENAME_DESCRIPTOR); 156 saveRepositoryTags(repositoryFeatureTags, DEFAULT_FEATURE_REPOTAG_FILENAME_DESCRIPTOR); 157 } 158 159 162 private void generateFetchFilesForIncludedFeatures() throws CoreException { 163 IIncludedFeatureReference[] referencedFeatures = ((Feature) feature).getFeatureIncluded(); 164 for (int i = 0; i < referencedFeatures.length; i++) { 165 String featureId = referencedFeatures[i].getVersionedIdentifier().getIdentifier(); 166 if (featureProperties.containsKey(GENERATION_SOURCE_FEATURE_PREFIX + featureId)) 167 continue; 168 169 FetchScriptGenerator generator = new FetchScriptGenerator("feature@" + featureId + ',' + referencedFeatures[i].getVersionedIdentifier().getVersion().toString()); generator.setDirectoryLocation(directoryLocation); 171 generator.setFetchChildren(fetchChildren); 172 generator.setCvsPassFileLocation(cvsPassFileLocation); 173 generator.setRecursiveGeneration(recursiveGeneration); 174 generator.setFetchTag(fetchTags); 175 generator.setDirectory(directory); 176 generator.setDirectoryFile(directoryFile); 177 generator.setBuildSiteFactory(siteFactory); 178 generator.repositoryPluginTags = repositoryPluginTags; 179 generator.generate(); 180 } 181 } 182 183 188 protected void generateFetchScript() throws CoreException { 189 generatePrologue(); 190 generateFetchTarget(); 191 generateFetchElementTarget(); 192 if (mapInfos.get(IFetchFactory.KEY_ELEMENT_TYPE).equals(IFetchFactory.ELEMENT_TYPE_FEATURE)) { 193 generateFetchPluginsTarget(); 194 generateFetchRecusivelyTarget(); 195 } 196 generateAdditionalTargets(); 197 generateEpilogue(); 198 } 199 200 protected void generateFetchTarget() { 201 script.println(); 205 script.printTargetDeclaration(TARGET_FETCH, null, null, null, null); 206 if (!mapInfos.get(IFetchFactory.KEY_ELEMENT_NAME).equals(IPDEBuildConstants.CONTAINER_FEATURE)) 208 script.printAntCallTask(TARGET_FETCH_ELEMENT, true, null); 209 if (mapInfos.get(IFetchFactory.KEY_ELEMENT_TYPE).equals(IFetchFactory.ELEMENT_TYPE_FEATURE)) { 210 script.printAntCallTask(TARGET_FETCH_PLUGINS, true, null); 211 script.printAntCallTask(TARGET_FETCH_RECURSIVELY, true, null); 212 } 213 script.printTargetEnd(); 214 } 215 216 protected void generateFetchElementTarget() { 217 if (mapInfos.get(IFetchFactory.KEY_ELEMENT_NAME).equals(IPDEBuildConstants.CONTAINER_FEATURE)) 219 return; 220 script.printTargetDeclaration(TARGET_FETCH_ELEMENT, null, FEATURE_ONLY, null, null); 221 try { 222 generateFetchEntry(element, elementVersion, false); 223 } catch (CoreException e) { 224 IStatus status = new Status(IStatus.ERROR, PI_PDEBUILD, WARNING_ELEMENT_NOT_FETCHED, NLS.bind(Messages.error_fetchingFailed, element), null); 225 BundleHelper.getDefault().getLog().log(status); 226 } 227 script.printTargetEnd(); 228 } 229 230 protected void generateFetchPluginsTarget() throws CoreException { 231 script.printTargetDeclaration(TARGET_FETCH_PLUGINS, null, FEATURE_AND_PLUGINS, null, null); 232 retrieveFeature((String ) mapInfos.get(IFetchFactory.KEY_ELEMENT_NAME), (String ) mapInfos.get(IFetchFactory.KEY_ELEMENT_TYPE), mapInfos); 233 generateChildrenFetchScript(); 234 script.printTargetEnd(); 235 } 236 237 244 private Map processMapFileEntry(String entry, Version version) throws CoreException { 245 Map entryInfos = new HashMap(5); 246 247 int index = entry.indexOf('@'); 249 String type = entry.substring(0, index); 250 String currentElement = entry.substring(index + 1); 251 252 Object [] match = getRepositoryInfo(entry, version); 254 String repositoryInfo = match == null ? null : (String ) match[0]; 255 if (repositoryInfo == null) { 256 if (IPDEBuildConstants.CONTAINER_FEATURE.equals(currentElement)) { 257 entryInfos.put(IFetchFactory.KEY_ELEMENT_TYPE, type); 258 entryInfos.put(IFetchFactory.KEY_ELEMENT_NAME, currentElement); 259 return entryInfos; 260 } 261 String message = NLS.bind(Messages.error_missingDirectoryEntry, Version.emptyVersion.equals(version) ? entry : entry + ',' + version.toString()); 262 BundleHelper.getDefault().getLog().log(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_ENTRY_MISSING, message, null)); 263 return null; 264 } 265 266 int idx = repositoryInfo.indexOf(','); 268 if (idx == -1) { 269 String message = NLS.bind(Messages.error_incorrectDirectoryEntry, currentElement); 270 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_ENTRY_MISSING, message, null)); 271 } 272 String repoIdentifier = repositoryInfo.substring(0, idx).trim(); 273 274 IFetchFactory fetchTaskFactory = null; 276 String repoSpecificSegment = null; 277 if (!fetchTaskFactories.getFactoryIds().contains(repoIdentifier)) { 279 repoIdentifier = CVSFetchTaskFactory.ID; 280 repoSpecificSegment = repositoryInfo; 281 } else { 282 repoSpecificSegment = repositoryInfo.substring(idx + 1, repositoryInfo.length()); } 284 285 fetchTaskFactory = fetchTaskFactories.getFactory(repoIdentifier); 286 if (fetchTaskFactory == null) { 287 String message = NLS.bind(Messages.error_noCorrespondingFactory, currentElement); 288 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_ENTRY_MISSING, message, null)); 289 } 290 291 encounteredTypeOfRepo.add(fetchTaskFactory); 292 entryInfos.put(IFetchFactory.KEY_ELEMENT_TYPE, type); 294 entryInfos.put(IFetchFactory.KEY_ELEMENT_NAME, currentElement); 295 296 fetchTaskFactory.parseMapFileEntry(repoSpecificSegment, fetchTags, entryInfos); 298 299 entryInfos.put(FETCH_TASK_FACTORY, fetchTaskFactory); 301 302 entryInfos.put(MATCHED_VERSION, match[1]); 304 return entryInfos; 305 } 306 307 protected void generateFetchRecusivelyTarget() throws CoreException { 308 script.printTargetDeclaration(TARGET_FETCH_RECURSIVELY, null, FEATURES_RECURSIVELY, null, null); 309 310 IIncludedFeatureReference[] compiledFeatures = ((Feature) feature).getFeatureIncluded(); 311 for (int i = 0; i < compiledFeatures.length; i++) { 312 String featureId = compiledFeatures[i].getVersionedIdentifier().getIdentifier(); 313 if (featureProperties.containsKey(GENERATION_SOURCE_FEATURE_PREFIX + featureId)) { 314 String [] extraElementsToFetch = Utils.getArrayFromString(featureProperties.getProperty(GENERATION_SOURCE_FEATURE_PREFIX + featureId), ","); for (int j = 1; j < extraElementsToFetch.length; j++) { 316 Object [] infos = Utils.parseExtraBundlesString(extraElementsToFetch[j], false); 317 generateFetchEntry((String ) infos[0], (Version) infos[1], false); 318 } 319 continue; 320 } 321 322 if (getRepositoryInfo(IFetchFactory.ELEMENT_TYPE_FEATURE + '@' + featureId, new Version(compiledFeatures[i].getVersionedIdentifier().getVersion().toString())) != null) 324 script.printAntTask(Utils.getPropertyFormat(PROPERTY_BUILD_DIRECTORY) + '/' + FETCH_FILE_PREFIX + featureId + ".xml", null, TARGET_FETCH, null, null, null); else if (getSite(false).findFeature(featureId, null, false) == null) { 326 String message = NLS.bind(Messages.error_cannotFetchNorFindFeature, featureId); 327 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_FEATURE_MISSING, message, null)); 328 } 329 } 330 script.printTargetEnd(); 331 } 332 333 protected boolean generateFetchEntry(String entry, Version version, boolean manifestFileOnly) throws CoreException { 334 Map mapFileEntry = mapInfos; 335 if (!entry.equals(element)) { 336 mapFileEntry = processMapFileEntry(entry, version); 337 if (mapFileEntry == null) 338 return false; 339 } 340 341 IFetchFactory factory = (IFetchFactory) mapFileEntry.get(FETCH_TASK_FACTORY); 342 String elementToFetch = (String ) mapFileEntry.get(IFetchFactory.KEY_ELEMENT_NAME); 343 String type = (String ) mapFileEntry.get(IFetchFactory.KEY_ELEMENT_TYPE); 344 if (!manifestFileOnly) 345 factory.generateRetrieveElementCall(mapFileEntry, computeFinalLocation(type, elementToFetch, (Version) mapFileEntry.get(MATCHED_VERSION)), script); 346 else { 347 String [] files; 348 if (type.equals(IFetchFactory.ELEMENT_TYPE_FEATURE)) { 349 files = new String [] {Constants.FEATURE_FILENAME_DESCRIPTOR}; 350 } else if (type.equals(IFetchFactory.ELEMENT_TYPE_PLUGIN)) { 351 files = new String [] {Constants.PLUGIN_FILENAME_DESCRIPTOR, Constants.BUNDLE_FILENAME_DESCRIPTOR}; 352 } else if (type.equals(IFetchFactory.ELEMENT_TYPE_FRAGMENT)) { 353 files = new String [] {Constants.FRAGMENT_FILENAME_DESCRIPTOR, Constants.BUNDLE_FILENAME_DESCRIPTOR}; 354 } else if (type.equals(IFetchFactory.ELEMENT_TYPE_BUNDLE)) { 355 files = new String [] {Constants.BUNDLE_FILENAME_DESCRIPTOR}; 356 } else { 357 files = new String [0]; 358 } 359 factory.generateRetrieveFilesCall(mapFileEntry, computeFinalLocation(type, elementToFetch, (Version) mapFileEntry.get(MATCHED_VERSION)), files, script); 360 } 361 362 Properties tags = null; 364 if (type.equals(IFetchFactory.ELEMENT_TYPE_FEATURE)) 365 tags = repositoryFeatureTags; 366 else 367 tags = repositoryPluginTags; 368 if (mapFileEntry.get(IFetchFactory.KEY_ELEMENT_TAG) != null) 369 tags.put(elementToFetch + ',' + new Version(version.getMajor(), version.getMinor(), version.getMicro()), mapFileEntry.get(IFetchFactory.KEY_ELEMENT_TAG)); 370 371 return true; 372 } 373 374 380 protected void generateMkdirs(String location) { 381 if (mkdirLocations.contains(location)) 382 return; 383 mkdirLocations.add(location); 384 script.printMkdirTask(location); 385 } 386 387 391 protected void generateChildrenFetchScript() throws CoreException { 392 IPluginEntry[] allChildren = feature.getRawPluginEntries(); 393 IPluginEntry[] compiledChildren = feature.getPluginEntries(); 394 395 for (int i = 0; i < allChildren.length; i++) { 396 String elementId = allChildren[i].getVersionedIdentifier().getIdentifier(); 397 Version versionId = new Version(allChildren[i].getVersionedIdentifier().getVersion().toString()); 398 if (featureProperties.containsKey(GENERATION_SOURCE_PLUGIN_PREFIX + elementId)) { 400 String [] extraElementsToFetch = Utils.getArrayFromString(featureProperties.getProperty(GENERATION_SOURCE_PLUGIN_PREFIX + elementId), ","); for (int j = 1; j < extraElementsToFetch.length; j++) { 402 Object [] infos = Utils.parseExtraBundlesString(extraElementsToFetch[j], false); 403 generateFetchEntry((String ) infos[0], (Version) infos[1], false); 404 } 405 continue; 406 } 407 408 boolean generated = true; 409 if (allChildren[i].isFragment()) 410 generated = generateFetchEntry(IFetchFactory.ELEMENT_TYPE_FRAGMENT + '@' + elementId, versionId, !Utils.isIn(compiledChildren, allChildren[i])); 411 else 412 generated = generateFetchEntry(IFetchFactory.ELEMENT_TYPE_PLUGIN + '@' + elementId, versionId, !Utils.isIn(compiledChildren, allChildren[i])); 413 if (generated == false) 414 generateFetchEntry(IFetchFactory.ELEMENT_TYPE_BUNDLE + '@' + elementId, versionId, !Utils.isIn(compiledChildren, allChildren[i])); 415 } 416 } 417 418 428 protected void retrieveFeature(String elementName, String elementType, Map elementInfos) throws CoreException { 429 File root = new File(workingDirectory); 432 433 if (elementName.equals(IPDEBuildConstants.CONTAINER_FEATURE)) { 435 FeatureExecutableFactory factory = new FeatureExecutableFactory(); 436 File featuresFolder = new File(root, DEFAULT_FEATURE_LOCATION); 437 File featureLocation = new File(featuresFolder, elementName); 438 try { 439 feature = factory.createFeature(featureLocation.toURL(), null, null); 440 featureProperties = new Properties(); 441 InputStream featureStream = new BufferedInputStream(new FileInputStream(new File(featureLocation, PROPERTIES_FILE))); 442 featureProperties.load(featureStream); 443 featureStream.close(); 444 return; 445 } catch (Exception e) { 446 String message = NLS.bind(Messages.exception_missingFeature, elementName); 447 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_FEATURE_MISSING, message, e)); 448 } 449 } 450 451 File target = new File(root, DEFAULT_RETRIEVE_FILENAME_DESCRIPTOR); 452 IPath destination = new Path(root.getAbsolutePath()).append("tempFeature/"); try { 454 AntScript retrieve = new AntScript(new BufferedOutputStream(new FileOutputStream(target))); 455 try { 456 retrieve.printProjectDeclaration("RetrieveFeature", "main", "."); retrieve.printTargetDeclaration(TARGET_MAIN, null, null, null, null); 458 459 String [] files = new String [] {Constants.FEATURE_FILENAME_DESCRIPTOR, PROPERTIES_FILE}; 460 IFetchFactory factory = (IFetchFactory) elementInfos.get(FETCH_TASK_FACTORY); 461 factory.generateRetrieveFilesCall(elementInfos, destination, files, retrieve); 462 463 retrieve.printTargetEnd(); 464 retrieve.printProjectEnd(); 465 } finally { 466 retrieve.close(); 467 } 468 } catch (IOException e) { 469 String message = NLS.bind(Messages.exception_writeScript, target); 470 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_SCRIPT, message, e)); 471 } 472 473 try { 476 AntRunner runner = new AntRunner(); 477 runner.setBuildFileLocation(target.getAbsolutePath()); 478 Map retrieveProp = new HashMap(); 479 retrieveProp.put("fetch.failonerror", "true"); runner.addUserProperties(retrieveProp); 481 runner.addBuildLogger("org.eclipse.pde.internal.build.tasks.SimpleBuildLogger"); 485 runner.run(); 486 } catch (Exception e) { 487 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_FEATURE_MISSING, NLS.bind(Messages.error_retrieveFailed, elementName), e)); 488 } 489 490 try { 491 FeatureExecutableFactory factory = new FeatureExecutableFactory(); 492 File featureFolder = new File(destination.toString()); 493 feature = factory.createFeature(featureFolder.toURL(), null, null); 494 495 target.delete(); 497 498 featureProperties = new Properties(); 499 InputStream featureStream = new BufferedInputStream(new FileInputStream(new File(featureFolder, PROPERTIES_FILE))); 500 featureProperties.load(featureStream); 501 featureStream.close(); 502 clear(featureFolder); 503 if (feature == null) { 504 String message = NLS.bind(Messages.exception_missingFeature, elementName); 505 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_FEATURE_MISSING, message, null)); 506 } 507 } catch (Exception e) { 508 String message = NLS.bind(Messages.error_fetchingFeature, elementName); 509 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_FEATURE_MISSING, message, e)); 510 } 511 } 512 513 522 public static boolean clear(File root) { 523 boolean result = true; 524 if (root.isDirectory()) { 525 String [] list = root.list(); 526 if (list != null) 529 for (int i = 0; i < list.length; i++) 530 result &= clear(new java.io.File (root, list[i])); 531 } 532 try { 533 if (root.exists()) 534 result &= root.delete(); 535 } catch (Exception e) { 536 result = false; 538 } 539 return result; 540 } 541 542 protected IPath computeFinalLocation(String type, String elementName, Version version) { 543 IPath location = new Path(Utils.getPropertyFormat(PROPERTY_BUILD_DIRECTORY)); 544 if (type.equals(IFetchFactory.ELEMENT_TYPE_FEATURE)) 545 location = location.append(DEFAULT_FEATURE_LOCATION); 546 else 547 location = location.append(DEFAULT_PLUGIN_LOCATION); 548 return location.append(elementName + (version.equals(Version.emptyVersion) ? "" : '_' + version.toString())); } 550 551 558 protected Object [] getRepositoryInfo(String elementName, Version version) throws CoreException { 568 if (directoryFile == null) { 570 directoryFile = readProperties(directoryLocation, "", IStatus.ERROR); } 572 573 String result = null; 574 Version matchedVersion = null; 575 if (Version.emptyVersion.equals(version)) { 577 result = (String ) directoryFile.get(elementName); 578 matchedVersion = Version.emptyVersion; 579 } else { 580 result = (String ) directoryFile.get(elementName + ',' + version.getMajor() + '.' + version.getMinor() + '.' + version.getMicro()); 581 matchedVersion = new Version(version.getMajor(), version.getMinor(), version.getMicro()); 582 if (result == null) { 583 result = (String ) directoryFile.get(elementName); matchedVersion = Version.emptyVersion; 585 if (result != null && version.getQualifier().endsWith(IBuildPropertiesConstants.PROPERTY_QUALIFIER)) { 586 String message = NLS.bind(Messages.warning_fallBackVersion, elementName + ',' + version.toString(), elementName); 587 BundleHelper.getDefault().getLog().log(new Status(IStatus.WARNING, PI_PDEBUILD, EXCEPTION_ENTRY_MISSING, message, null)); 588 } 589 } 590 } 591 if (result != null) 592 return new Object [] {result, matchedVersion}; 593 594 initializeSortedDirectory(); 596 SortedMap candidates = directory.subMap(new MapFileEntry(elementName, Version.emptyVersion), new MapFileEntry(elementName, versionMax)); 598 if (candidates.size() == 0) 599 return null; 600 601 Map.Entry bestMatch = null; 602 for (Iterator iterator = candidates.entrySet().iterator(); iterator.hasNext();) { 603 Map.Entry entry = (Map.Entry) iterator.next(); 604 MapFileEntry aCandidate = (MapFileEntry) entry.getKey(); 605 if (aCandidate.v.equals(version)) 607 return new String [] {(String ) entry.getValue(), version.toString()}; 608 609 if (bestMatch != null) { 610 if (((MapFileEntry) bestMatch.getKey()).v.compareTo(((MapFileEntry) entry.getKey()).v) < 1) { 611 bestMatch = entry; 612 } 613 } else { 614 bestMatch = entry; 615 } 616 } 617 if (!Version.emptyVersion.equals(version)) return null; 619 return new Object [] {(String ) bestMatch.getValue(), ((MapFileEntry) bestMatch.getKey()).v}; 620 } 621 622 private static final Version versionMax = new Version(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE); 623 624 private void initializeSortedDirectory() { 625 if (directory != null) 626 return; 627 directory = new TreeMap(); 628 for (Iterator iter = directoryFile.entrySet().iterator(); iter.hasNext();) { 629 Map.Entry entry = (Map.Entry) iter.next(); 630 String [] entryInfo = Utils.getArrayFromString((String ) entry.getKey()); 631 if (entryInfo.length == 0) 632 continue; 633 directory.put(new MapFileEntry(entryInfo[0], entryInfo.length == 2 ? new Version(entryInfo[1]) : Version.emptyVersion), entry.getValue()); 634 } 635 } 636 637 public class MapFileEntry implements Comparable { 638 String id; 639 Version v; 640 641 public MapFileEntry(String id, Version v) { 642 this.id = id; 643 this.v = v; 644 } 645 646 public int compareTo(Object o) { 647 if (o instanceof MapFileEntry) { 648 MapFileEntry entry = (MapFileEntry) o; 649 int result = id.compareTo(entry.id); 650 if (result != 0) 651 return result; 652 return v.compareTo(entry.v); 653 } 654 return -1; 655 } 656 657 public boolean equals(Object o) { 658 if (o instanceof MapFileEntry) { 659 MapFileEntry entry = (MapFileEntry) o; 660 return id.equals(entry.id) && v.equals(entry.v); 661 } 662 return false; 663 } 664 } 665 666 669 protected void generatePrologue() { 670 script.println(); 671 script.printComment("Fetch script for " + element); script.println(); 673 script.printProjectDeclaration("FetchScript", TARGET_FETCH, null); script.printProperty(PROPERTY_QUIET, "true"); } 676 677 680 protected void generateEpilogue() { 681 script.println(); 682 script.printProjectEnd(); 683 } 684 685 688 private void generateAdditionalTargets() { 689 for (Iterator iter = encounteredTypeOfRepo.iterator(); iter.hasNext();) { 690 ((IFetchFactory) iter.next()).addTargets(script); 691 } 692 } 693 694 699 public void setDirectoryLocation(String directoryLocation) { 700 this.directoryLocation = directoryLocation; 701 } 702 703 708 public void setFetchChildren(boolean fetchChildren) { 709 this.fetchChildren = fetchChildren; 710 } 711 712 719 public void setFetchTag(Properties value) { 720 fetchTags = value; 721 } 722 723 730 public void setFetchTagAsString(String value) { 731 fetchTags = new Properties(); 732 String [] entries = Utils.getArrayFromString(value); 733 if (entries.length == 1 && (entries[0].indexOf('=') == -1)) { 735 fetchTags.put(CVSFetchTaskFactory.OVERRIDE_TAG, entries[0]); 736 return; 737 } 738 for (int i = 0; i < entries.length; i++) { 739 String [] valueForRepo = Utils.getArrayFromString(entries[i], "="); if (valueForRepo == null || valueForRepo.length != 2) 741 throw new IllegalArgumentException ("FetchTag " + entries[i]); fetchTags.put(valueForRepo[0], valueForRepo[1]); 743 } 744 } 745 746 751 public void setCvsPassFileLocation(String cvsPassFileLocation) { 752 this.cvsPassFileLocation = cvsPassFileLocation; 753 } 754 755 public void setRecursiveGeneration(boolean recursiveGeneration) { 756 this.recursiveGeneration = recursiveGeneration; 757 } 758 759 private void setDirectory(SortedMap dir) { 760 directory = dir; 761 } 762 763 private void setDirectoryFile(Properties dir) { 764 directoryFile = dir; 765 } 766 } 767 | Popular Tags |