1 19 20 package org.netbeans.modules.apisupport.project.universe; 21 22 import java.io.File ; 23 import java.io.FileInputStream ; 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.util.ArrayList ; 27 import java.util.Collections ; 28 import java.util.HashMap ; 29 import java.util.HashSet ; 30 import java.util.Iterator ; 31 import java.util.List ; 32 import java.util.Map ; 33 import java.util.Properties ; 34 import java.util.Set ; 35 import java.util.StringTokenizer ; 36 import java.util.regex.Pattern ; 37 import org.netbeans.api.project.ProjectManager; 38 import org.netbeans.modules.apisupport.project.ManifestManager; 39 import org.netbeans.modules.apisupport.project.NbModuleProjectType; 40 import org.netbeans.modules.apisupport.project.ProjectXMLManager; 41 import org.netbeans.modules.apisupport.project.Util; 42 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 43 import org.netbeans.spi.project.support.ant.PropertyProvider; 44 import org.netbeans.spi.project.support.ant.PropertyUtils; 45 import org.openide.ErrorManager; 46 import org.openide.util.Mutex; 47 import org.openide.util.MutexException; 48 import org.openide.util.NbCollections; 49 import org.openide.xml.XMLUtil; 50 import org.w3c.dom.Document ; 51 import org.w3c.dom.Element ; 52 import org.xml.sax.InputSource ; 53 import org.xml.sax.SAXException ; 54 55 59 public final class ModuleList { 60 61 62 static long timeSpentInXmlParsing; 63 static int xmlFilesParsed; 64 static int directoriesChecked; 65 static int jarsOpened; 66 67 public static final String DEST_DIR_IN_NETBEANS_ORG = "nbbuild" + File.separatorChar + "netbeans"; 69 public static final int DEPTH_NB_ALL = 3; 70 71 74 private static final Map <File ,ModuleList> sourceLists = new HashMap (); 75 78 private static final Map <File ,ModuleList> binaryLists = new HashMap (); 79 82 private static final Map <File ,Map <String ,String >> clusterPropertiesFiles = new HashMap (); 83 88 private static final Map <File ,Map <String ,String >> clusterLocations = new HashMap (); 89 90 91 private static final Map <File ,Set <ModuleEntry>> knownEntries = new HashMap (); 92 93 104 public static ModuleList getModuleList(File basedir) throws IOException { 105 return getModuleList(basedir, null); 106 } 107 108 119 public static ModuleList getModuleList(final File basedir, final File customNbDestDir) throws IOException { 120 try { 121 return (ModuleList) ProjectManager.mutex().readAccess(new Mutex.ExceptionAction() { public Object run() throws IOException { 123 synchronized (binaryLists) { timeSpentInXmlParsing = 0L; 125 xmlFilesParsed = 0; 126 directoriesChecked = 0; 127 jarsOpened = 0; 128 Element data = parseData(basedir); 129 if (data == null) { 130 throw new IOException ("Not an NBM project in " + basedir); } 132 boolean suiteComponent = Util.findElement(data, "suite-component", NbModuleProjectType.NAMESPACE_SHARED) != null; boolean standalone = Util.findElement(data, "standalone", NbModuleProjectType.NAMESPACE_SHARED) != null; assert !(suiteComponent && standalone) : basedir; 135 if (suiteComponent) { 136 PropertyEvaluator eval = parseProperties(basedir, null, true, false, "irrelevant"); String suiteS = eval.getProperty("suite.dir"); 138 if (suiteS == null) { 139 throw new IOException ("No suite.dir defined from " + basedir); } 141 File suite = PropertyUtils.resolveFile(basedir, suiteS); 142 return findOrCreateModuleListFromSuite(suite, customNbDestDir); 143 } else if (standalone) { 144 return findOrCreateModuleListFromStandaloneModule(basedir, customNbDestDir); 145 } else { 146 File nbroot = findNetBeansOrg(basedir); 148 if (nbroot == null) { 149 throw new IOException ("Could not find netbeans.org CVS root from " + basedir + "; note that 3rd-level modules (a/b/c) are permitted at the maximum"); } 151 return findOrCreateModuleListFromNetBeansOrgSources(nbroot); 152 } 153 } 154 } 155 }); 156 } catch (MutexException e) { 157 throw (IOException ) e.getException(); 158 } 159 } 160 161 165 public static boolean existKnownEntries() { 166 synchronized (knownEntries) { 167 return !knownEntries.isEmpty(); 168 } 169 } 170 171 177 public static Set <ModuleEntry> getKnownEntries(File file) { 178 synchronized (knownEntries) { 179 Set <ModuleEntry> entries = (Set ) knownEntries.get(file); 180 if (entries != null) { 181 return new HashSet (entries); 182 } else { 183 return Collections.EMPTY_SET; 184 } 185 } 186 } 187 188 private static void registerEntry(ModuleEntry entry, Set <File > files) { 189 synchronized (knownEntries) { 190 Iterator it = files.iterator(); 191 while (it.hasNext()) { 192 File f = (File ) it.next(); 193 Set <ModuleEntry> entries = (Set ) knownEntries.get(f); 194 if (entries == null) { 195 entries = new HashSet (); 196 knownEntries.put(f, entries); 197 } 198 entries.add(entry); 199 } 200 } 201 } 202 203 static ModuleList findOrCreateModuleListFromNetBeansOrgSources(File root) throws IOException { 204 ModuleList list = (ModuleList) sourceLists.get(root); 205 if (list == null) { 206 list = createModuleListFromNetBeansOrgSources(root); 207 sourceLists.put(root, list); 208 } 209 return list; 210 } 211 212 private static ModuleList createModuleListFromNetBeansOrgSources(File root) throws IOException { 213 Util.err.log("ModuleList.createModuleListFromSources: " + root); 214 File nbdestdir = new File (root, DEST_DIR_IN_NETBEANS_ORG); 215 Map <String ,ModuleEntry> entries = new HashMap (); 216 scanNetBeansOrgStableSources(entries, root, nbdestdir); 217 return new ModuleList(entries, root, true); 218 } 219 220 224 private static void scanNetBeansOrgStableSources(Map <String ,ModuleEntry> entries, File root, File nbdestdir) throws IOException { 225 Map <String ,String > clusterProps = getClusterProperties(root); 226 String clusterList = (String ) clusterProps.get("clusters.list"); if (clusterList == null) { 230 throw new IOException ("No ${nb.clusters.list} found in " + root); } 232 StringTokenizer tok = new StringTokenizer (clusterList, ", "); while (tok.hasMoreTokens()) { 234 String clusterName = tok.nextToken(); 235 String moduleList = (String ) clusterProps.get(clusterName); 236 if (moduleList == null) { 237 throw new IOException ("No ${" + clusterName + "} found in " + root); } 239 StringTokenizer tok2 = new StringTokenizer (moduleList, ", "); while (tok2.hasMoreTokens()) { 241 String module = tok2.nextToken(); 242 scanPossibleProject(new File (root, module.replace('/', File.separatorChar)), entries, false, false, root, nbdestdir, module, true); 243 } 244 } 245 } 246 247 public static final Set <String > EXCLUDED_DIR_NAMES = new HashSet (); 248 static { 249 EXCLUDED_DIR_NAMES.add("CVS"); EXCLUDED_DIR_NAMES.add("nbproject"); EXCLUDED_DIR_NAMES.add("www"); EXCLUDED_DIR_NAMES.add("test"); EXCLUDED_DIR_NAMES.add("build"); EXCLUDED_DIR_NAMES.add("src"); EXCLUDED_DIR_NAMES.add("org"); } 257 private static void doScanNetBeansOrgSources(Map <String ,ModuleEntry> entries, File dir, int depth, 258 File root, File nbdestdir, String pathPrefix, boolean warnReDuplicates) { 259 File [] kids = dir.listFiles(); 260 if (kids == null) { 261 return; 262 } 263 for (int i = 0; i < kids.length; i++) { 264 if (!kids[i].isDirectory()) { 265 continue; 266 } 267 String name = kids[i].getName(); 268 if (EXCLUDED_DIR_NAMES.contains(name)) { 269 continue; 271 } 272 String newPathPrefix = (pathPrefix != null) ? pathPrefix + "/" + name : name; try { 274 scanPossibleProject(kids[i], entries, false, false, root, nbdestdir, newPathPrefix, warnReDuplicates); 275 } catch (IOException e) { 276 Util.err.annotate(e, ErrorManager.UNKNOWN, "Malformed project metadata in " + kids[i] + ", skipping...", null, null, null); Util.err.notify(ErrorManager.INFORMATIONAL, e); 279 } 280 if (depth > 1) { 281 doScanNetBeansOrgSources(entries, kids[i], depth - 1, root, nbdestdir, newPathPrefix, warnReDuplicates); 282 } 283 } 284 } 285 286 private static void scanPossibleProject(File basedir, Map <String ,ModuleEntry> entries, 287 boolean suiteComponent, boolean standalone, File root, File nbdestdir, String path, boolean warnReDuplicates) throws IOException { 288 directoriesChecked++; 289 Element data = parseData(basedir); 290 if (data == null) { 291 return; 292 } 293 assert root != null ^ (standalone || suiteComponent); 294 assert path != null ^ (standalone || suiteComponent); 295 String cnb = Util.findText(Util.findElement(data, "code-name-base", NbModuleProjectType.NAMESPACE_SHARED)); PropertyEvaluator eval = parseProperties(basedir, root, suiteComponent, standalone, cnb); 297 String module = eval.getProperty("module.jar"); StringBuffer cpextra = new StringBuffer (); 300 Iterator <Element > exts = Util.findSubElements(data).iterator(); 301 while (exts.hasNext()) { 302 Element ext = (Element ) exts.next(); 303 if (!ext.getLocalName().equals("class-path-extension")) { continue; 305 } 306 Element binaryOrigin = Util.findElement(ext, "binary-origin", NbModuleProjectType.NAMESPACE_SHARED); String text; 308 if (binaryOrigin != null) { 309 text = Util.findText(binaryOrigin); 310 } else { 311 Element runtimeRelativePath = Util.findElement(ext, "runtime-relative-path", NbModuleProjectType.NAMESPACE_SHARED); assert runtimeRelativePath != null : "Malformed <class-path-extension> in " + basedir; 313 String reltext = Util.findText(runtimeRelativePath); 314 text = "${cluster}/${module.jar.dir}/" + reltext; } 317 String evaluated = eval.evaluate(text); 318 if (evaluated == null) { 319 continue; 320 } 321 File binary = PropertyUtils.resolveFile(basedir, evaluated); 322 cpextra.append(':'); 323 cpextra.append(binary.getAbsolutePath()); 324 } 325 File manifest = new File (basedir, "manifest.mf"); ManifestManager mm = (manifest.isFile() ? 327 ManifestManager.getInstance(manifest, false) : ManifestManager.NULL_INSTANCE); 328 File clusterDir = PropertyUtils.resolveFile(basedir, eval.evaluate("${cluster}")); ModuleEntry entry; 330 ManifestManager.PackageExport[] publicPackages = ProjectXMLManager.findPublicPackages(data); 331 String [] friends = ProjectXMLManager.findFriends(data); 332 if (!suiteComponent && !standalone) { 333 entry = new NetBeansOrgEntry(root, cnb, path, clusterDir, module, cpextra.toString(), 334 mm.getReleaseVersion(), mm.getProvidedTokens(), 335 publicPackages, friends, mm.isDeprecated()); 336 } else { 337 entry = new ExternalEntry(basedir, cnb, clusterDir, PropertyUtils.resolveFile(clusterDir, module), 338 cpextra.toString(), nbdestdir, mm.getReleaseVersion(), 339 mm.getProvidedTokens(), publicPackages, friends, mm.isDeprecated()); 340 } 341 if (entries.containsKey(cnb)) { 342 if (warnReDuplicates) { 343 Util.err.log(ErrorManager.WARNING, "Warning: two modules found with the same code name base (" + cnb + "): " + entries.get(cnb) + " and " + entry); 344 } 345 } else { 346 entries.put(cnb, entry); 347 } 348 registerEntry(entry, findSourceNBMFiles(entry, eval)); 349 } 350 351 359 private static Set <File > findSourceNBMFiles(ModuleEntry entry, PropertyEvaluator eval) throws IOException { 360 Set <File > files = new HashSet (); 361 files.add(entry.getJarLocation()); 362 File cluster = entry.getClusterDirectory(); 363 String cnbd = entry.getCodeNameBase().replace('.', '-'); 364 String [] STANDARD_FILES = { 365 "update_tracking/*.xml", "config/Modules/*.xml", "config/ModuleAutoDeps/*.xml", "ant/nblib/*.jar", "modules/docs/*.jar", }; 371 for (int i = 0; i < STANDARD_FILES.length; i++) { 372 int x = STANDARD_FILES[i].indexOf('*'); 373 findSourceNBMFilesMaybeAdd(files, cluster, STANDARD_FILES[i].substring(0, x) + cnbd + STANDARD_FILES[i].substring(x + 1)); 374 } 375 String emf = eval.getProperty("extra.module.files"); if (emf != null) { 377 String [] entries = emf.split(" *, *"); for (int i = 0; i < entries.length; i++) { 379 String pattern = entries[i]; 380 if (pattern.endsWith("/")) { pattern += "**"; } 384 if (pattern.indexOf('*') == -1) { 385 findSourceNBMFilesMaybeAdd(files, cluster, pattern); 387 } else { 388 String regex = "\\Q" + pattern.replaceAll("\\*\\*", "__DBLASTERISK__"). replaceAll("\\*", "\\\\E[^/]*\\\\Q"). replaceAll("__DBLASTERISK__", "\\\\E.*\\\\Q") + "\\E"; Pattern regexp = Pattern.compile(regex); 394 String [] clusterFiles = scanDirForFiles(cluster); 395 for (int j = 0; j < clusterFiles.length; j++) { 396 if (regexp.matcher(clusterFiles[j]).matches()) { 397 findSourceNBMFilesMaybeAdd(files, cluster, clusterFiles[j]); 398 } 399 } 400 } 401 } 402 } 403 File src = entry.getSourceLocation(); 404 assert src != null && src.isDirectory() : entry; 405 File releaseDir = new File (src, "release"); if (releaseDir.isDirectory()) { 408 String [] releaseFiles = scanDirForFiles(releaseDir); 409 for (int i = 0; i < releaseFiles.length; i++) { 410 findSourceNBMFilesMaybeAdd(files, cluster, releaseFiles[i]); 411 } 412 } 413 return files; 414 } 415 private static void findSourceNBMFilesMaybeAdd(Set <File > files, File cluster, String path) { 416 File f = new File (cluster, path.replace('/', File.separatorChar)); 417 files.add(f); 418 } 419 private static final Map <File ,String []> DIR_SCAN_CACHE = new HashMap (); 420 private static String [] scanDirForFiles(File dir) { 421 String [] files = DIR_SCAN_CACHE.get(dir); 422 if (files == null) { 423 List <String > l = new ArrayList (250); 424 doScanDirForFiles(dir, l, ""); 425 files = l.toArray(new String [l.size()]); 426 } 427 return files; 428 } 429 private static void doScanDirForFiles(File d, List <String > files, String prefix) { 430 directoriesChecked++; 431 File [] kids = d.listFiles(); 432 if (kids != null) { 433 for (int i = 0; i < kids.length; i++) { 434 File f = kids[i]; 435 if (f.isFile()) { 436 files.add(prefix + f.getName()); 437 } else if (f.isDirectory()) { 438 doScanDirForFiles(f, files, prefix + f.getName() + '/'); 439 } 440 } 441 } 442 } 443 444 public static ModuleList findOrCreateModuleListFromSuite( 445 File root, File customNbDestDir) throws IOException { 446 PropertyEvaluator eval = parseSuiteProperties(root); 447 File nbdestdir; 448 if (customNbDestDir == null) { 449 String nbdestdirS = eval.getProperty("netbeans.dest.dir"); if (nbdestdirS == null) { 451 throw new IOException ("No netbeans.dest.dir defined in " + root); } 453 nbdestdir = PropertyUtils.resolveFile(root, nbdestdirS); 454 } else { 455 nbdestdir = customNbDestDir; 456 } 457 return merge(new ModuleList[] { 458 findOrCreateModuleListFromSuiteWithoutBinaries(root, nbdestdir, eval), 459 findOrCreateModuleListFromBinaries(nbdestdir), 460 }, root); 461 } 462 463 private static ModuleList findOrCreateModuleListFromSuiteWithoutBinaries(File root, File nbdestdir, PropertyEvaluator eval) throws IOException { 464 ModuleList sources = (ModuleList) sourceLists.get(root); 465 if (sources == null) { 466 Map <String ,ModuleEntry> entries = new HashMap (); 467 File [] modules = findModulesInSuite(root, eval); 468 for (int i = 0; i < modules.length; i++) { 469 try { 470 scanPossibleProject(modules[i], entries, true, false, null, nbdestdir, null, true); 471 } catch (IOException e) { 472 Util.err.annotate(e, ErrorManager.UNKNOWN, "Malformed project metadata in " + modules[i] + ", skipping...", null, null, null); Util.err.notify(ErrorManager.INFORMATIONAL, e); 474 } 475 } 476 sources = new ModuleList(entries, root, false); 477 sourceLists.put(root, sources); 478 } 479 return sources; 480 } 481 482 static ModuleList findOrCreateModuleListFromSuiteWithoutBinaries(File root) throws IOException { 483 PropertyEvaluator eval = parseSuiteProperties(root); 484 String nbdestdirS = eval.getProperty("netbeans.dest.dir"); if (nbdestdirS == null) { 486 throw new IOException ("No netbeans.dest.dir defined in " + root); } 488 File nbdestdir = PropertyUtils.resolveFile(root, nbdestdirS); 489 return findOrCreateModuleListFromSuiteWithoutBinaries(root, nbdestdir, eval); 490 } 491 492 private static PropertyEvaluator parseSuiteProperties(File root) throws IOException { 493 Map <String ,String > predefs = new HashMap (System.getProperties()); 494 predefs.put("basedir", root.getAbsolutePath()); PropertyProvider predefsProvider = PropertyUtils.fixedPropertyProvider(predefs); 496 List <PropertyProvider> providers = new ArrayList (); 497 providers.add(loadPropertiesFile(new File (root, "nbproject" + File.separatorChar + "private" + File.separatorChar + "platform-private.properties"))); providers.add(loadPropertiesFile(new File (root, "nbproject" + File.separatorChar + "platform.properties"))); PropertyEvaluator eval = PropertyUtils.sequentialPropertyEvaluator(predefsProvider, (PropertyProvider[]) providers.toArray(new PropertyProvider[providers.size()])); 500 String buildS = eval.getProperty("user.properties.file"); if (buildS != null) { 502 providers.add(loadPropertiesFile(PropertyUtils.resolveFile(root, buildS))); 503 } else { 504 providers.add(PropertyUtils.globalPropertyProvider()); 506 } 507 providers.add(loadPropertiesFile(new File (root, "nbproject" + File.separatorChar + "private" + File.separatorChar + "private.properties"))); providers.add(loadPropertiesFile(new File (root, "nbproject" + File.separatorChar + "project.properties"))); eval = PropertyUtils.sequentialPropertyEvaluator(predefsProvider, (PropertyProvider[]) providers.toArray(new PropertyProvider[providers.size()])); 510 String platformS = eval.getProperty("nbplatform.active"); if (platformS != null) { 512 providers.add(PropertyUtils.fixedPropertyProvider(Collections.singletonMap("netbeans.dest.dir", "${nbplatform." + platformS + ".netbeans.dest.dir}"))); } 514 return PropertyUtils.sequentialPropertyEvaluator(predefsProvider, (PropertyProvider[]) providers.toArray(new PropertyProvider[providers.size()])); 515 } 516 517 static File [] findModulesInSuite(File root) throws IOException { 518 return findModulesInSuite(root, parseSuiteProperties(root)); 519 } 520 521 private static File [] findModulesInSuite(File root, PropertyEvaluator eval) throws IOException { 522 String modulesS = eval.getProperty("modules"); if (modulesS == null) { 524 modulesS = ""; } 526 String [] modulesA = PropertyUtils.tokenizePath(modulesS); 527 File [] modules = new File [modulesA.length]; 528 for (int i = 0; i < modulesA.length; i++) { 529 modules[i] = PropertyUtils.resolveFile(root, modulesA[i]); 530 } 531 return modules; 532 } 533 534 private static ModuleList findOrCreateModuleListFromStandaloneModule( 535 File basedir, File customNbDestDir) throws IOException { 536 PropertyEvaluator eval = parseProperties(basedir, null, false, true, "irrelevant"); File nbdestdir; 538 if (customNbDestDir == null) { 539 String nbdestdirS = eval.getProperty("netbeans.dest.dir"); if (nbdestdirS == null) { 541 throw new IOException ("No netbeans.dest.dir defined in " + basedir); } 543 if (nbdestdirS.indexOf("${") != -1) { throw new IOException ("Unevaluated properties in " + nbdestdirS + " from " + basedir + "; probably means platform definitions not loaded correctly"); } 546 nbdestdir = PropertyUtils.resolveFile(basedir, nbdestdirS); 547 } else { 548 nbdestdir = customNbDestDir; 549 } 550 ModuleList binaries = findOrCreateModuleListFromBinaries(nbdestdir); 551 ModuleList sources = (ModuleList) sourceLists.get(basedir); 552 if (sources == null) { 553 Map <String ,ModuleEntry> entries = new HashMap (); 554 scanPossibleProject(basedir, entries, false, true, null, nbdestdir, null, true); 555 if (entries.isEmpty()) { 556 throw new IOException ("No module in " + basedir); } 558 sources = new ModuleList(entries, basedir, false); 559 sourceLists.put(basedir, sources); 560 } 561 return merge(new ModuleList[] {sources, binaries}, basedir); 562 } 563 564 static ModuleList findOrCreateModuleListFromBinaries(File root) throws IOException { 565 ModuleList list = (ModuleList) binaryLists.get(root); 566 if (list == null) { 567 list = createModuleListFromBinaries(root); 568 binaryLists.put(root, list); 569 } 570 return list; 571 } 572 573 private static final String [] MODULE_DIRS = { 574 "modules", "modules/eager", "modules/autoload", "lib", "core", }; 580 private static ModuleList createModuleListFromBinaries(File root) throws IOException { 581 Util.err.log("ModuleList.createModuleListFromBinaries: " + root); 582 Map <String ,ModuleEntry> entries = new HashMap (); 584 File [] clusters = root.listFiles(); 585 if (clusters == null) { 586 throw new IOException ("Cannot examine dir " + root); } 588 for (int i = 0; i < clusters.length; i++) { 589 for (int j = 0; j < MODULE_DIRS.length; j++) { 590 File dir = new File (clusters[i], MODULE_DIRS[j].replace('/', File.separatorChar)); 591 if (!dir.isDirectory()) { 592 continue; 593 } 594 File [] jars = dir.listFiles(); 595 if (jars == null) { 596 throw new IOException ("Cannot examine dir " + dir); } 598 for (int k = 0; k < jars.length; k++) { 599 File m = jars[k]; 600 if (!m.getName().endsWith(".jar")) { continue; 602 } 603 jarsOpened++; 604 ManifestManager mm = ManifestManager.getInstanceFromJAR(m); 605 String codenamebase = mm.getCodeNameBase(); 606 if (codenamebase == null) { 607 continue; 608 } 609 String cp = mm.getClassPath(); 610 File [] exts; 611 if (cp == null) { 612 exts = new File [0]; 613 } else { 614 String [] pieces = cp.trim().split(" +"); exts = new File [pieces.length]; 616 for (int l = 0; l < pieces.length; l++) { 617 exts[l] = new File (dir, pieces[l].replace('/', File.separatorChar)); 618 } 619 } 620 ModuleEntry entry = new BinaryEntry(codenamebase, m, exts, root, clusters[i], 621 mm.getReleaseVersion(), mm.getSpecificationVersion(), mm.getProvidedTokens(), 622 mm.getPublicPackages(), mm.getFriends(), mm.isDeprecated(), mm.getModuleDependencies()); 623 if (entries.containsKey(codenamebase)) { 624 Util.err.log(ErrorManager.WARNING, "Warning: two modules found with the same code name base (" + codenamebase + "): " + entries.get(codenamebase) + " and " + entry); 625 } else { 626 entries.put(codenamebase, entry); 627 } 628 registerEntry(entry, findBinaryNBMFiles(clusters[i], codenamebase, m)); 629 } 630 } 631 } 632 return new ModuleList(entries, root, false); 633 } 634 635 641 private static Set <File > findBinaryNBMFiles(File cluster, String cnb, File jar) throws IOException { 642 Set <File > files = new HashSet (); 643 files.add(jar); 644 File tracking = new File (new File (cluster, "update_tracking"), cnb.replace('.', '-') + ".xml"); if (tracking.isFile()) { 646 files.add(tracking); 647 Document doc; 648 try { 649 xmlFilesParsed++; 650 timeSpentInXmlParsing -= System.currentTimeMillis(); 651 doc = XMLUtil.parse(new InputSource (tracking.toURI().toString()), false, false, null, null); 652 timeSpentInXmlParsing += System.currentTimeMillis(); 653 } catch (SAXException e) { 654 throw (IOException ) new IOException (e.toString()).initCause(e); 655 } 656 Iterator it = Util.findSubElements(doc.getDocumentElement()).iterator(); 657 while (it.hasNext()) { 658 Element moduleVersion = (Element ) it.next(); 659 if (moduleVersion.getTagName().equals("module_version") && moduleVersion.getAttribute("last").equals("true")) { Iterator it2 = Util.findSubElements(moduleVersion).iterator(); 661 while (it2.hasNext()) { 662 Element fileEl = (Element ) it2.next(); 663 if (fileEl.getTagName().equals("file")) { String name = fileEl.getAttribute("name"); File f = new File (cluster, name.replace('/', File.separatorChar)); 666 if (f.isFile()) { 667 files.add(f); 668 } 669 } 670 } 671 } 672 } 673 } 674 return files; 675 } 676 677 private static final String PROJECT_XML = "nbproject" + File.separatorChar + "project.xml"; 683 static Element parseData(File basedir) throws IOException { 684 File projectXml = new File (basedir, PROJECT_XML); 685 if (!projectXml.exists() || !projectXml.isFile()) { 688 return null; 689 } 690 Document doc; 691 try { 692 xmlFilesParsed++; 693 timeSpentInXmlParsing -= System.currentTimeMillis(); 694 doc = XMLUtil.parse(new InputSource (projectXml.toURI().toString()), false, true, null, null); 695 timeSpentInXmlParsing += System.currentTimeMillis(); 696 } catch (SAXException e) { 697 throw (IOException ) new IOException (projectXml + ": " + e.toString()).initCause(e); } 699 Element docel = doc.getDocumentElement(); 700 Element type = Util.findElement(docel, "type", "http://www.netbeans.org/ns/project/1"); if (!Util.findText(type).equals("org.netbeans.modules.apisupport.project")) { return null; 703 } 704 Element cfg = Util.findElement(docel, "configuration", "http://www.netbeans.org/ns/project/1"); Element data = Util.findElement(cfg, "data", NbModuleProjectType.NAMESPACE_SHARED); if (data != null) { 707 return data; 708 } else { 709 data = Util.findElement(cfg, "data", NbModuleProjectType.NAMESPACE_SHARED_2); if (data != null) { 711 return Util.translateXML(data, NbModuleProjectType.NAMESPACE_SHARED); 712 } else { 713 return null; 714 } 715 } 716 } 717 718 732 static PropertyEvaluator parseProperties(File basedir, File root, boolean suiteComponent, boolean standalone, String cnb) throws IOException { 733 assert !(suiteComponent && standalone) : basedir; 734 Map <String ,String > predefs = new HashMap (System.getProperties()); 735 predefs.put("basedir", basedir.getAbsolutePath()); PropertyProvider predefsProvider = PropertyUtils.fixedPropertyProvider(predefs); 737 List <PropertyProvider> providers = new ArrayList (); 738 if (suiteComponent) { 739 providers.add(loadPropertiesFile(new File (basedir, "nbproject" + File.separatorChar + "private" + File.separatorChar + "suite-private.properties"))); providers.add(loadPropertiesFile(new File (basedir, "nbproject" + File.separatorChar + "suite.properties"))); PropertyEvaluator eval = PropertyUtils.sequentialPropertyEvaluator(predefsProvider, (PropertyProvider[]) providers.toArray(new PropertyProvider[providers.size()])); 742 String suiteS = eval.getProperty("suite.dir"); if (suiteS != null) { 744 File suite = PropertyUtils.resolveFile(basedir, suiteS); 745 providers.add(loadPropertiesFile(new File (suite, "nbproject" + File.separatorChar + "private" + File.separatorChar + "platform-private.properties"))); providers.add(loadPropertiesFile(new File (suite, "nbproject" + File.separatorChar + "platform.properties"))); } 748 } else if (standalone) { 749 providers.add(loadPropertiesFile(new File (basedir, "nbproject" + File.separatorChar + "private" + File.separatorChar + "platform-private.properties"))); providers.add(loadPropertiesFile(new File (basedir, "nbproject" + File.separatorChar + "platform.properties"))); } 752 if (suiteComponent || standalone) { 753 PropertyEvaluator eval = PropertyUtils.sequentialPropertyEvaluator(predefsProvider, (PropertyProvider[]) providers.toArray(new PropertyProvider[providers.size()])); 754 String buildS = eval.getProperty("user.properties.file"); if (buildS != null) { 756 providers.add(loadPropertiesFile(PropertyUtils.resolveFile(basedir, buildS))); 757 } else { 758 providers.add(PropertyUtils.globalPropertyProvider()); 759 } 760 eval = PropertyUtils.sequentialPropertyEvaluator(predefsProvider, (PropertyProvider[]) providers.toArray(new PropertyProvider[providers.size()])); 761 String platformS = eval.getProperty("nbplatform.active"); if (platformS != null) { 763 providers.add(PropertyUtils.fixedPropertyProvider(Collections.singletonMap("netbeans.dest.dir", "${nbplatform." + platformS + ".netbeans.dest.dir}"))); } 765 } 766 providers.add(loadPropertiesFile(new File (basedir, "nbproject" + File.separatorChar + "private" + File.separatorChar + "private.properties"))); providers.add(loadPropertiesFile(new File (basedir, "nbproject" + File.separatorChar + "project.properties"))); Map <String ,String > defaults = new HashMap (); 771 boolean isNetBeansOrg = !suiteComponent && !standalone; 772 if (isNetBeansOrg) { 773 defaults.put("nb_all", root.getAbsolutePath()); defaults.put("netbeans.dest.dir", new File (root, DEST_DIR_IN_NETBEANS_ORG).getAbsolutePath()); } 776 defaults.put("code.name.base.dashes", cnb.replace('.', '-')); defaults.put("module.jar.dir", "modules"); defaults.put("module.jar.basename", "${code.name.base.dashes}.jar"); defaults.put("module.jar", "${module.jar.dir}/${module.jar.basename}"); providers.add(PropertyUtils.fixedPropertyProvider(defaults)); 781 if (suiteComponent) { 782 defaults.put("cluster", "${suite.dir}/build/cluster"); } else if (standalone) { 784 defaults.put("cluster", "build/cluster"); } else { 786 String cluster = findClusterLocation(basedir, root); 788 if (cluster == null) { 789 cluster = "extra"; } 791 defaults.put("cluster", "${netbeans.dest.dir}/" + cluster); } 793 return PropertyUtils.sequentialPropertyEvaluator(predefsProvider, (PropertyProvider[]) providers.toArray(new PropertyProvider[providers.size()])); 794 } 795 796 private static PropertyProvider loadPropertiesFile(File f) throws IOException { 797 if (!f.isFile()) { 798 return PropertyUtils.fixedPropertyProvider(Collections.EMPTY_MAP); 799 } 800 Properties p = new Properties (); 801 InputStream is = new FileInputStream (f); 802 try { 803 p.load(is); 804 } finally { 805 is.close(); 806 } 807 return PropertyUtils.fixedPropertyProvider(NbCollections.checkedMapByFilter(p, String .class, String .class, true)); 808 } 809 810 813 public static void refresh() { 814 sourceLists.clear(); 815 binaryLists.clear(); 816 } 818 819 823 public static void refreshSuiteModuleList(File suiteDir) { 824 sourceLists.remove(suiteDir); 825 } 826 827 830 public static boolean isNetBeansOrg(File dir) { 831 return new File (dir, "nbbuild").isDirectory() && new File (dir, "openide").isDirectory(); } 834 835 838 public static File findNetBeansOrg(File basedir) { 839 File f = basedir; 840 for (int i = 0; i < DEPTH_NB_ALL; i++) { 841 f = f.getParentFile(); 842 if (f == null) { 843 return null; 844 } 845 if (isNetBeansOrg(f)) { 846 return f; 847 } 848 } 849 return null; 851 } 852 853 private static Map <String ,String > getClusterProperties(File nbroot) throws IOException { 854 Map <String ,String > clusterDefs = (Map ) clusterPropertiesFiles.get(nbroot); 855 if (clusterDefs == null) { 856 PropertyProvider pp = loadPropertiesFile(new File (nbroot, "nbbuild" + File.separatorChar + "cluster.properties")); PropertyEvaluator clusterEval = PropertyUtils.sequentialPropertyEvaluator( 858 PropertyUtils.fixedPropertyProvider(Collections.EMPTY_MAP), 859 new PropertyProvider[] { 860 pp, 861 }); 862 clusterDefs = clusterEval.getProperties(); 863 if (clusterDefs == null) { 864 clusterDefs = Collections.EMPTY_MAP; 866 } 867 } 868 return clusterDefs; 869 } 870 871 876 private static String findClusterLocation(File basedir, File nbroot) throws IOException { 877 String path = PropertyUtils.relativizeFile(nbroot, basedir); 878 assert path.indexOf("..") == -1 : path; 879 Map <String ,String > clusterLocationsHere = (Map ) clusterLocations.get(nbroot); 880 if (clusterLocationsHere == null) { 881 clusterLocationsHere = new HashMap (); 882 Map <String ,String > clusterDefs = getClusterProperties(nbroot); 883 Iterator it = clusterDefs.entrySet().iterator(); 884 while (it.hasNext()) { 885 Map.Entry entry = (Map.Entry )it.next(); 886 String key = (String )entry.getKey(); 887 String clusterDir = (String ) clusterDefs.get(key + ".dir"); if (clusterDir == null) { 889 continue; 892 } 893 String val = (String ) entry.getValue(); 894 StringTokenizer tok = new StringTokenizer (val, ", "); while (tok.hasMoreTokens()) { 896 String p = tok.nextToken(); 897 clusterLocationsHere.put(p, clusterDir); 898 } 899 } 900 clusterLocations.put(nbroot, clusterLocationsHere); 901 } 902 return (String ) clusterLocationsHere.get(path); 903 } 904 905 907 908 private Map <String ,ModuleEntry> entries; 909 910 911 private final File home; 912 913 914 private boolean lazyNetBeansOrgList; 915 916 private ModuleList(Map <String ,ModuleEntry> entries, File home, boolean lazyNetBeansOrgList) { 917 this.entries = entries; 918 this.home = home; 919 this.lazyNetBeansOrgList = lazyNetBeansOrgList; 920 } 921 922 public String toString() { 923 return "ModuleList[" + home + "]" + (lazyNetBeansOrgList ? "[lazy]" : "") + entries.values(); } 925 926 930 private static ModuleList merge(ModuleList[] lists, File home) { 931 Map <String ,ModuleEntry> entries = new HashMap (); 932 for (int i = 0; i < lists.length; i++) { 933 lists[i].maybeRescanNetBeansOrgSources(); 934 Iterator it = lists[i].entries.entrySet().iterator(); 935 while (it.hasNext()) { 936 Map.Entry entry = (Map.Entry ) it.next(); 937 String cnb = (String ) entry.getKey(); 938 if (!entries.containsKey(cnb)) { 939 entries.put(cnb, (ModuleEntry) entry.getValue()); 940 } 941 } 942 } 943 return new ModuleList(entries, home, false); 944 } 945 946 private void maybeRescanNetBeansOrgSources() { 947 if (lazyNetBeansOrgList) { 948 lazyNetBeansOrgList = false; 949 File nbdestdir = new File (home, DEST_DIR_IN_NETBEANS_ORG); 950 Map <String ,ModuleEntry> _entries = new HashMap (entries); doScanNetBeansOrgSources(_entries, home, DEPTH_NB_ALL, home, nbdestdir, null, false); 952 entries = _entries; 953 } 954 } 955 956 961 public ModuleEntry getEntry(String codeNameBase) { 962 ModuleEntry e = (ModuleEntry) entries.get(codeNameBase); 963 if (e != null) { 964 return e; 965 } else { 966 maybeRescanNetBeansOrgSources(); 967 return (ModuleEntry) entries.get(codeNameBase); 968 } 969 } 970 971 975 public Set <ModuleEntry> getAllEntries() { 976 maybeRescanNetBeansOrgSources(); 977 return new HashSet (entries.values()); 978 } 979 980 989 public Set <ModuleEntry> getAllEntriesSoft() { 990 return new HashSet (entries.values()); 991 } 992 993 public static LocalizedBundleInfo loadBundleInfo(File projectDir) { 994 LocalizedBundleInfo bundleInfo = Util.findLocalizedBundleInfo(projectDir); 995 return bundleInfo == null ? LocalizedBundleInfo.EMPTY : bundleInfo; 996 } 997 998 } 999 | Popular Tags |