1 19 20 package org.netbeans.modules.apisupport.project; 21 22 import org.netbeans.modules.apisupport.project.spi.NbModuleProvider; 23 import java.beans.PropertyChangeEvent ; 24 import java.beans.PropertyChangeListener ; 25 import java.beans.PropertyChangeSupport ; 26 import java.io.File ; 27 import java.io.IOException ; 28 import java.net.URI ; 29 import java.net.URL ; 30 import java.util.ArrayList ; 31 import java.util.Arrays ; 32 import java.util.Collection ; 33 import java.util.Collections ; 34 import java.util.HashMap ; 35 import java.util.HashSet ; 36 import java.util.Iterator ; 37 import java.util.List ; 38 import java.util.Map ; 39 import java.util.Set ; 40 import java.util.TreeMap ; 41 import java.util.regex.Matcher ; 42 import java.util.regex.Pattern ; 43 import javax.swing.event.ChangeEvent ; 44 import javax.swing.event.ChangeListener ; 45 import org.netbeans.api.java.classpath.ClassPath; 46 import org.netbeans.api.java.platform.JavaPlatform; 47 import org.netbeans.api.java.platform.JavaPlatformManager; 48 import org.netbeans.api.project.ProjectManager; 49 import org.netbeans.modules.apisupport.project.universe.TestModuleDependency; 50 import org.netbeans.modules.apisupport.project.universe.ModuleEntry; 51 import org.netbeans.modules.apisupport.project.universe.ModuleList; 52 import org.netbeans.spi.project.support.ant.AntProjectEvent; 53 import org.netbeans.spi.project.support.ant.AntProjectHelper; 54 import org.netbeans.spi.project.support.ant.AntProjectListener; 55 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 56 import org.netbeans.spi.project.support.ant.PropertyProvider; 57 import org.netbeans.spi.project.support.ant.PropertyUtils; 58 import org.openide.ErrorManager; 59 import org.openide.filesystems.FileObject; 60 import org.openide.filesystems.FileUtil; 61 import org.openide.modules.InstalledFileLocator; 62 import org.openide.util.Mutex; 63 import org.openide.util.RequestProcessor; 64 import org.openide.util.WeakListeners; 65 import org.w3c.dom.Element ; 66 67 74 final class Evaluator implements PropertyEvaluator, PropertyChangeListener , AntProjectListener { 75 76 private final NbModuleProject project; 77 private final NbModuleProvider typeProvider; 78 private final PropertyChangeSupport pcs = new PropertyChangeSupport (this); 79 80 private PropertyEvaluator delegate; 81 private boolean loadedModuleList = false; 82 83 84 private boolean runInAtomicAction; 85 86 private static class TestClasspath { 87 88 private final String compile; 89 private final String runtime; 90 private final String testCompile; 91 private final String testRuntime; 92 93 public TestClasspath(String compile,String runtime,String testCompile,String testRuntime) { 94 this.compile = compile; 95 this.runtime = runtime; 96 this.testCompile = testCompile; 97 this.testRuntime = testRuntime; 98 } 99 100 public String getCompileClasspath() { 101 return compile + ':' + testCompile; 102 } 103 104 public String getRuntimeClasspath() { 105 return runtime + ':' + testRuntime; 106 } 107 108 private static TestClasspath getOrEmpty(Map testsCPs, String testtype) { 109 TestClasspath tcp = (TestClasspath) testsCPs.get(testtype); 110 if (tcp == null ) { 111 tcp = new TestClasspath("", "", "", ""); } 114 return tcp; 115 } 116 } 117 118 public Evaluator(NbModuleProject project, NbModuleProvider typeProvider) { 119 this.project = project; 120 this.typeProvider = typeProvider; 121 delegate = createEvaluator(null); 122 delegate.addPropertyChangeListener(this); 123 project.getHelper().addAntProjectListener(this); 124 } 125 126 public String getProperty(String prop) { 127 PropertyEvaluator eval = delegatingEvaluator(false); 128 assert eval != this; 129 String v = eval.getProperty(prop); 130 if ((v == null && isModuleListDependentProperty(prop)) || isModuleListDependentValue(v)) { 131 return delegatingEvaluator(true).getProperty(prop); 132 } else { 133 return v; 134 } 135 } 136 137 public String evaluate(String text) { 138 String v = delegatingEvaluator(false).evaluate(text); 139 if (isModuleListDependentValue(v)) { 140 return delegatingEvaluator(true).evaluate(text); 141 } else { 142 return v; 143 } 144 } 145 146 public Map getProperties() { 147 return delegatingEvaluator(true).getProperties(); 148 } 149 150 private boolean isModuleListDependentProperty(String p) { 151 return p.equals("module.classpath") || p.equals("cp") || p.endsWith(".cp") || p.endsWith(".cp.extra") || p.equals("cluster") || (p.endsWith(".dir") && p.lastIndexOf('.', p.length() - 5) == -1); } 157 158 private static final Pattern ANT_PROP_REGEX = Pattern.compile("\\$\\{([a-zA-Z0-9._-]+)\\}"); private boolean isModuleListDependentValue(String v) { 160 if (v == null) { 161 return false; 162 } 163 Matcher m = ANT_PROP_REGEX.matcher(v); 164 while (m.find()) { 165 if (isModuleListDependentProperty(m.group(1))) { 166 return true; 167 } 168 } 169 return false; 170 } 171 172 public void addPropertyChangeListener(PropertyChangeListener listener) { 173 pcs.addPropertyChangeListener(listener); 174 } 175 176 public void removePropertyChangeListener(PropertyChangeListener listener) { 177 pcs.removePropertyChangeListener(listener); 178 } 179 180 private PropertyEvaluator delegatingEvaluator(boolean reset) { 181 if (reset && !loadedModuleList) { 182 reset(); 183 if (Util.err.isLoggable(ErrorManager.INFORMATIONAL)) { 184 Util.err.log("Needed to reset evaluator in " + project + "due to use of module-list-dependent property; now cp=" + delegate.getProperty("cp")); 185 } 186 } 187 return delegate; 188 } 189 190 private void reset() { 191 loadedModuleList = true; 192 delegate.removePropertyChangeListener(this); 193 try { 194 delegate = createEvaluator(project.getModuleList()); 195 } catch (IOException e) { 196 Util.err.notify(ErrorManager.INFORMATIONAL, e); 197 } 199 delegate.addPropertyChangeListener(this); 200 pcs.firePropertyChange(null, null, null); 201 } 202 203 public void propertyChange(PropertyChangeEvent evt) { 204 if ("netbeans.dest.dir".equals(evt.getPropertyName()) || evt.getPropertyName() == null) { 205 reset(); 207 } else { 208 Util.err.log("Refiring property change from delegate in " + evt.getPropertyName() + " for " + project); 209 pcs.firePropertyChange(evt.getPropertyName(), evt.getOldValue(), evt.getNewValue()); 210 } 211 } 212 213 public void configurationXmlChanged(AntProjectEvent ev) { 214 if (!runInAtomicAction && ev.getPath().equals(AntProjectHelper.PROJECT_XML_PATH)) { 215 reset(); 216 } 217 } 218 219 public void propertiesChanged(AntProjectEvent ev) { 220 221 } 222 223 224 public void setRunInAtomicAction(boolean runInAtomicAction) { 225 assert ProjectManager.mutex().isWriteAccess(); 226 this.runInAtomicAction = runInAtomicAction; 227 } 228 229 public void removeListeners() { 230 project.getHelper().removeAntProjectListener(this); 231 delegate.removePropertyChangeListener(this); 232 } 233 234 239 private PropertyEvaluator createEvaluator(ModuleList ml) { 240 PropertyProvider predefs = project.getHelper().getStockPropertyPreprovider(); 242 Map <String ,String > stock = new HashMap (); 243 File dir = project.getProjectDirectoryFile(); 244 NbModuleProvider.NbModuleType type = typeProvider.getModuleType(); 245 File nbroot; 246 if (type == NbModuleProvider.NETBEANS_ORG) { 247 nbroot = ModuleList.findNetBeansOrg(dir); 248 assert nbroot != null : "netbeans.org-type module not in a complete netbeans.org source root " + dir; 249 stock.put("nb_all", nbroot.getAbsolutePath()); stock.put("netbeans.dest.dir", new File (nbroot, ModuleList.DEST_DIR_IN_NETBEANS_ORG).getAbsolutePath()); } else { 253 nbroot = null; 254 } 255 if (ml != null) { 256 Iterator it = ml.getAllEntriesSoft().iterator(); 258 while (it.hasNext()) { 259 ModuleEntry e = (ModuleEntry) it.next(); 260 String nborgPath = e.getNetBeansOrgPath(); 261 if (nborgPath != null) { 262 stock.put((nborgPath + ".dir").intern(), e.getClusterDirectory().getAbsolutePath().intern()); } 265 } 266 ModuleEntry thisEntry = ml.getEntry(project.getCodeNameBase()); 267 if (thisEntry != null) { assert nbroot == null ^ thisEntry.getNetBeansOrgPath() != null : thisEntry; 269 File clusterDir = thisEntry.getClusterDirectory(); 270 stock.put("cluster", clusterDir.getAbsolutePath()); } 272 } 273 List <PropertyProvider> providers = new ArrayList (); 274 providers.add(PropertyUtils.fixedPropertyProvider(stock)); 275 if (type == NbModuleProvider.SUITE_COMPONENT) { 277 providers.add(project.getHelper().getPropertyProvider("nbproject/private/suite-private.properties")); providers.add(project.getHelper().getPropertyProvider("nbproject/suite.properties")); PropertyEvaluator baseEval = PropertyUtils.sequentialPropertyEvaluator(predefs, (PropertyProvider[]) providers.toArray(new PropertyProvider[providers.size()])); 280 String suiteDirS = baseEval.getProperty("suite.dir"); if (suiteDirS != null) { 282 File suiteDir = PropertyUtils.resolveFile(dir, suiteDirS); 283 providers.add(PropertyUtils.propertiesFilePropertyProvider(new File (suiteDir, "nbproject" + File.separatorChar + "private" + File.separatorChar + "platform-private.properties"))); providers.add(PropertyUtils.propertiesFilePropertyProvider(new File (suiteDir, "nbproject" + File.separatorChar + "platform.properties"))); } 286 } else if (type == NbModuleProvider.STANDALONE) { 287 providers.add(project.getHelper().getPropertyProvider("nbproject/private/platform-private.properties")); providers.add(project.getHelper().getPropertyProvider("nbproject/platform.properties")); } 290 if (type == NbModuleProvider.SUITE_COMPONENT || type == NbModuleProvider.STANDALONE) { 291 PropertyEvaluator baseEval = PropertyUtils.sequentialPropertyEvaluator(predefs, (PropertyProvider[]) providers.toArray(new PropertyProvider[providers.size()])); 292 providers.add(new Util.UserPropertiesFileProvider(baseEval, dir)); 293 baseEval = PropertyUtils.sequentialPropertyEvaluator(predefs, (PropertyProvider[]) providers.toArray(new PropertyProvider[providers.size()])); 294 class DestDirProvider extends Util.ComputedPropertyProvider { 295 public DestDirProvider(PropertyEvaluator eval) { 296 super(eval); 297 } 298 protected Map <String ,String > getProperties(Map <String ,String > inputPropertyValues) { 299 String platformS = (String ) inputPropertyValues.get("nbplatform.active"); if (platformS != null) { 301 return Collections.singletonMap("netbeans.dest.dir", "${nbplatform." + platformS + ".netbeans.dest.dir}"); } else { 303 return Collections.EMPTY_MAP; 304 } 305 } 306 protected Set inputProperties() { 307 return Collections.singleton("nbplatform.active"); } 309 } 310 providers.add(new DestDirProvider(baseEval)); 311 } 312 if (type == NbModuleProvider.NETBEANS_ORG) { 313 File nbbuild = new File (nbroot, "nbbuild"); providers.add(PropertyUtils.propertiesFilePropertyProvider(new File (nbbuild, "user.build.properties"))); providers.add(PropertyUtils.propertiesFilePropertyProvider(new File (nbbuild, "site.build.properties"))); } 318 PropertyEvaluator baseEval = PropertyUtils.sequentialPropertyEvaluator(predefs, (PropertyProvider[]) providers.toArray(new PropertyProvider[providers.size()])); 319 providers.add(new NbJdkProvider(baseEval)); 320 providers.add(project.getHelper().getPropertyProvider(AntProjectHelper.PRIVATE_PROPERTIES_PATH)); 321 providers.add(project.getHelper().getPropertyProvider(AntProjectHelper.PROJECT_PROPERTIES_PATH)); 322 Map <String ,String > defaults = new HashMap (); 323 defaults.put("code.name.base.dashes", project.getCodeNameBase().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}"); defaults.put("manifest.mf", "manifest.mf"); defaults.put("src.dir", "src"); defaults.put("build.classes.dir", "build/classes"); defaults.put("test.unit.src.dir", "test/unit/src"); defaults.put("test.qa-functional.src.dir", "test/qa-functional/src"); defaults.put("test.qa-performance.src.dir", "test/qa-performance/src"); defaults.put("build.test.unit.classes.dir", "build/test/unit/classes"); defaults.put("javac.source", "1.4"); defaults.put("test.user.dir", new File (dir, "build/testuserdir").getAbsolutePath()); providers.add(PropertyUtils.fixedPropertyProvider(defaults)); 337 if (ml != null) { 338 providers.add(PropertyUtils.fixedPropertyProvider(Collections.singletonMap("module.classpath", computeModuleClasspath(ml)))); Map <String ,String > buildDefaults = new HashMap (); 340 buildDefaults.put("cp.extra", ""); buildDefaults.put("cp", "${module.classpath}:${cp.extra}"); buildDefaults.put("run.cp", computeRuntimeModuleClasspath(ml) + ":${cp.extra}:${build.classes.dir}"); 344 baseEval = PropertyUtils.sequentialPropertyEvaluator(predefs, (PropertyProvider[]) providers.toArray(new PropertyProvider[providers.size()])); 345 buildDefaults.put("test.unit.cp.extra", ""); String testJars; if (type == NbModuleProvider.NETBEANS_ORG) { 348 buildDefaults.put("xtest.home", "${nb_all}/xtest"); testJars = 351 "${xtest.home}/lib/junit.jar:" + "${xtest.home}/lib/nbjunit.jar:" + "${xtest.home}/lib/nbjunit-ide.jar:" + "${xtest.home}/lib/insanelib.jar"; } else { 356 testJars = 358 "${test.unit.lib.cp}:" + "${netbeans.dest.dir}/ide6/modules/ext/junit-3.8.1.jar:" + "${netbeans.dest.dir}/ide8/modules/ext/junit-3.8.2.jar:" + "${netbeans.dest.dir}/testtools/modules/ext/nbjunit.jar:" + "${netbeans.dest.dir}/testtools/modules/ext/insanelib.jar:" + "${netbeans.dest.dir}/testtools/modules/org-netbeans-modules-nbjunit.jar:" + "${netbeans.dest.dir}/testtools/modules/org-netbeans-modules-nbjunit-ide.jar:" + "${netbeans.home}/../ide6/modules/ext/junit-3.8.1.jar:" + "${netbeans.home}/../ide8/modules/ext/junit-3.8.2.jar:" + "${netbeans.home}/../testtools/modules/ext/nbjunit.jar:" + "${netbeans.home}/../testtools/modules/ext/insanelib.jar:" + "${netbeans.home}/../testtools/modules/org-netbeans-modules-nbjunit.jar:" + "${netbeans.home}/../testtools/modules/org-netbeans-modules-nbjunit-ide.jar:" + "${netbeans.user}/modules/ext/nbjunit.jar:" + "${netbeans.user}/modules/ext/insanelib.jar:" + "${netbeans.dest.dir}/../../xtest/lib/junit.jar:" + "${netbeans.dest.dir}/../../xtest/lib/nbjunit.jar:" + "${netbeans.dest.dir}/../../xtest/lib/insanelib.jar:" + "${netbeans.user}/modules/org-netbeans-modules-nbjunit.jar:" + "${netbeans.user}/modules/org-netbeans-modules-nbjunit-ide.jar"; } 380 Map <String ,TestClasspath> testsCPs = computeTestingClassPaths(ml,baseEval); 381 TestClasspath tcp = TestClasspath.getOrEmpty(testsCPs, "unit"); 383 buildDefaults.put("test.unit.cp", "${cp}:${cluster}/${module.jar}:" + testJars + ":${test.unit.cp.extra}:" + tcp.getCompileClasspath()); buildDefaults.put("test.unit.run.cp.extra", ""); buildDefaults.put("test.unit.run.cp", "${test.unit.cp}:${build.test.unit.classes.dir}:${test.unit.run.cp.extra}:"+ tcp.getRuntimeClasspath()); buildDefaults.put("test.qa-functional.cp.extra", ""); String jemmyJar = findJemmyJar(baseEval); 390 if (jemmyJar != null) { 391 buildDefaults.put("jemmy.jar", jemmyJar); } 393 String jelly2NbJar = findJelly2NbJar(baseEval); 394 if (jelly2NbJar != null) { 395 buildDefaults.put("jelly2-nb.jar", jelly2NbJar); } 397 tcp = TestClasspath.getOrEmpty(testsCPs, "qa-functional"); buildDefaults.put("test.qa-functional.cp", testJars + ":${netbeans.home}/../testtools/modules/ext/nbjunit-ide.jar" + ":${netbeans.user}/testtools/modules/ext/nbjunit.jar" + ":${jemmy.jar}" + ":${jelly2-nb.jar}" + ":${test.qa-functional.cp.extra}:" + tcp.compile + ':' + tcp.testCompile); 405 buildDefaults.put("build.test.qa-functional.classes.dir", "build/test/qa-functional/classes"); buildDefaults.put("test.qa-functional.run.cp", "${test.qa-functional.cp}:${build.test.qa-functional.classes.dir}" + ':' + tcp.runtime + ':' + tcp.testRuntime); providers.add(PropertyUtils.fixedPropertyProvider(buildDefaults)); 408 } 409 return PropertyUtils.sequentialPropertyEvaluator(predefs, (PropertyProvider[]) providers.toArray(new PropertyProvider[providers.size()])); 411 } 412 413 private final class NbJdkProvider implements PropertyProvider, PropertyChangeListener { 415 private final PropertyEvaluator eval; 416 private final List <ChangeListener > listeners = new ArrayList (); 417 private final PropertyChangeListener weakListener = WeakListeners.propertyChange(this, null); 418 419 public NbJdkProvider(PropertyEvaluator eval) { 420 this.eval = eval; 421 eval.addPropertyChangeListener(weakListener); 422 JavaPlatformManager.getDefault().addPropertyChangeListener(weakListener); 423 } 424 425 public final Map <String ,String > getProperties() { 426 Map <String ,String > props = new HashMap (); 427 String home = eval.getProperty("nbjdk.home"); if (home == null) { 429 String active = eval.getProperty("nbjdk.active"); if (active != null && !active.equals("default")) { home = eval.getProperty("platforms." + active + ".home"); if (home != null) { 433 props.put("nbjdk.home", home); } 435 } 436 } 437 if (home == null) { 438 JavaPlatform platform = JavaPlatformManager.getDefault().getDefaultPlatform(); 439 if (platform != null) { 440 Collection <FileObject> installs = platform.getInstallFolders(); 441 if (installs.size() == 1) { 442 home = FileUtil.toFile((FileObject) installs.iterator().next()).getAbsolutePath(); 443 } 444 } 445 } 446 String bootcp = null; 447 if (home != null) { 448 FileObject homeFO = FileUtil.toFileObject(new File (home)); 449 if (homeFO != null) { 450 JavaPlatform[] platforms = JavaPlatformManager.getDefault().getInstalledPlatforms(); 451 for (int i = 0; i < platforms.length; i++) { 452 if (new HashSet (platforms[i].getInstallFolders()).equals(Collections.singleton(homeFO))) { 453 StringBuffer bootcpSB = new StringBuffer (); 455 ClassPath boot = platforms[i].getBootstrapLibraries(); 456 boot.removePropertyChangeListener(weakListener); 457 boot.addPropertyChangeListener(weakListener); 458 Iterator <ClassPath.Entry> entries = boot.entries().iterator(); 459 while (entries.hasNext()) { 460 ClassPath.Entry entry = (ClassPath.Entry) entries.next(); 461 URL u = entry.getURL(); 462 if (u.toExternalForm().endsWith("!/")) { URL nested = FileUtil.getArchiveFile(u); 464 if (nested != null) { 465 u = nested; 466 } 467 } 468 if ("file".equals(u.getProtocol())) { File f = new File (URI.create(u.toExternalForm())); 470 if (bootcpSB.length() > 0) { 471 bootcpSB.append(File.pathSeparatorChar); 472 } 473 bootcpSB.append(f.getAbsolutePath()); 474 } 475 } 476 bootcp = bootcpSB.toString(); 477 break; 478 } 479 } 480 } 481 if (bootcp == null) { 482 bootcp = "${nbjdk.home}/jre/lib/rt.jar".replace('/', File.separatorChar); } 484 } 485 if (bootcp == null) { 486 bootcp = "${sun.boot.class.path}"; } 489 props.put("nbjdk.bootclasspath", bootcp); if (home != null) { 491 props.put("tools.jar", home + "/lib/tools.jar".replace('/', File.separatorChar)); } 493 if (Util.err.isLoggable(ErrorManager.INFORMATIONAL)) { 494 Map <String ,String > _props = new TreeMap (eval.getProperties()); 495 Iterator it = _props.entrySet().iterator(); 496 while (it.hasNext()) { 497 String k = (String ) ((Map.Entry ) it.next()).getKey(); 498 if (!k.startsWith("nbjdk.") && !k.startsWith("platforms.")) { it.remove(); 500 } 501 } 502 _props.putAll(props); 503 Util.err.log("JDK-related properties of " + project + ": " + _props); 504 } 505 return props; 506 } 507 508 public final void addChangeListener(ChangeListener l) { 509 synchronized (listeners) { 510 listeners.add(l); 511 } 512 } 513 514 public final void removeChangeListener(ChangeListener l) { 515 synchronized (listeners) { 516 listeners.remove(l); 517 } 518 } 519 520 public final void propertyChange(PropertyChangeEvent evt) { 521 String p = evt.getPropertyName(); 522 if (p != null && !p.startsWith("nbjdk.") && !p.startsWith("platforms.") && !p.equals(ClassPath.PROP_ENTRIES) && !p.equals(JavaPlatformManager.PROP_INSTALLED_PLATFORMS)) { 524 return; 525 } 526 final ChangeEvent ev = new ChangeEvent (this); 527 final Iterator it; 528 synchronized (listeners) { 529 if (listeners.isEmpty()) { 530 return; 531 } 532 it = new HashSet (listeners).iterator(); 533 } 534 final Mutex.Action action = new Mutex.Action() { 535 public Object run() { 536 while (it.hasNext()) { 537 ((ChangeListener ) it.next()).stateChanged(ev); 538 } 539 return null; 540 } 541 }; 542 if (ProjectManager.mutex().isWriteAccess()) { 544 ProjectManager.mutex().readAccess(action); 545 } else if (ProjectManager.mutex().isReadAccess()) { 546 action.run(); 547 } else { 548 RequestProcessor.getDefault().post(new Runnable () { 549 public void run() { 550 ProjectManager.mutex().readAccess(action); 551 } 552 }); 553 } 554 } 555 556 } 557 558 561 private String findJemmyJar(PropertyEvaluator eval) { 562 File f = project.getNbrootFile("jemmy/builds/jemmy.jar", eval); if(f == null) { 564 f = InstalledFileLocator.getDefault().locate( 566 "modules/ext/jemmy.jar", "org.netbeans.modules.jemmy", false); } 568 if (f != null) { 569 return f.getAbsolutePath(); 570 } else { 571 return null; 572 } 573 } 574 575 578 private String findJelly2NbJar(PropertyEvaluator eval) { 579 File f = project.getNbrootFile("jellytools/builds/jelly2-nb.jar", eval); if(f == null) { 581 f = InstalledFileLocator.getDefault().locate( 583 "modules/ext/jelly2-nb.jar", "org.netbeans.modules.jellytools", false); } 585 if (f != null) { 586 return f.getAbsolutePath(); 587 } else { 588 return null; 589 } 590 } 591 592 595 private String computeModuleClasspath(ModuleList ml) { 596 Element data = project.getPrimaryConfigurationData(); 597 Element moduleDependencies = Util.findElement(data, 598 "module-dependencies", NbModuleProjectType.NAMESPACE_SHARED); List <Element > deps = Util.findSubElements(moduleDependencies); 600 Iterator it = deps.iterator(); 601 StringBuffer cp = new StringBuffer (); 602 while (it.hasNext()) { 603 Element dep = (Element )it.next(); 604 if (Util.findElement(dep, "compile-dependency", NbModuleProjectType.NAMESPACE_SHARED) == null) { 606 continue; 607 } 608 Element cnbEl = Util.findElement(dep, "code-name-base", NbModuleProjectType.NAMESPACE_SHARED); 610 String cnb = Util.findText(cnbEl); 611 ModuleEntry module = ml.getEntry(cnb); 612 if (module == null) { 613 Util.err.log(ErrorManager.WARNING, "Warning - could not find dependent module " + cnb + " for " + FileUtil.getFileDisplayName(project.getProjectDirectory())); 614 continue; 615 } 616 File moduleJar = module.getJarLocation(); 617 if (cp.length() > 0) { 618 cp.append(File.pathSeparatorChar); 619 } 620 cp.append(moduleJar.getAbsolutePath()); 621 cp.append(module.getClassPathExtensions()); 622 } 623 ModuleEntry myself = ml.getEntry(project.getCodeNameBase()); 624 if (myself == null) { 625 return ""; 627 } 628 cp.append(myself.getClassPathExtensions()); 629 return cp.toString(); 630 } 631 632 636 private String computeRuntimeModuleClasspath(ModuleList ml) { 637 Set <String > unprocessed = new HashSet (); 638 unprocessed.add(project.getCodeNameBase()); 639 Set <String > processed = new HashSet (); 640 StringBuffer cp = new StringBuffer (); 641 while (!unprocessed.isEmpty()) { Iterator it = unprocessed.iterator(); 643 String cnb = (String ) it.next(); 644 it.remove(); 645 if (processed.add(cnb)) { 646 ModuleEntry module = ml.getEntry(cnb); 647 if (module == null) { 648 Util.err.log(ErrorManager.WARNING, "Warning - could not find dependent module " + cnb + " for " + FileUtil.getFileDisplayName(project.getProjectDirectory())); 649 continue; 650 } 651 if (!cnb.equals(project.getCodeNameBase())) { if (cp.length() > 0) { 653 cp.append(File.pathSeparatorChar); 654 } 655 cp.append(module.getJarLocation().getAbsolutePath()); 656 cp.append(module.getClassPathExtensions()); 657 } 658 String [] newDeps = module.getRunDependencies(); 659 unprocessed.addAll(Arrays.asList(newDeps)); 660 } 661 } 662 ModuleEntry myself = ml.getEntry(project.getCodeNameBase()); 663 if (myself != null) { 664 cp.append(myself.getClassPathExtensions()); 666 } 667 return cp.toString(); 668 } 669 670 675 private Map computeTestingClassPaths(ModuleList ml, PropertyEvaluator evaluator) { 676 Map <String , TestClasspath> classpaths = new HashMap (); 677 ProjectXMLManager pxm = new ProjectXMLManager(project); 678 Map <String , Set <TestModuleDependency>> testTypes = pxm.getTestDependencies(ml); 679 680 String testDistDir = evaluator.getProperty("test.dist.dir"); if (testDistDir == null) { 682 NbModuleProvider.NbModuleType type = typeProvider.getModuleType(); 683 if (type == NbModuleProvider.NETBEANS_ORG) { 684 String nball = evaluator.getProperty("nb_all"); testDistDir = nball + File.separatorChar + "nbbuild" + File.separatorChar + "build" + File.separatorChar + "testdist"; } else if ( type == NbModuleProvider.SUITE_COMPONENT) { 688 String suiteDir = evaluator.getProperty("suite.dir"); testDistDir = suiteDir + File.separatorChar + "build" + File.separatorChar + "testdist"; } else { 692 String moduleDir = evaluator.getProperty("module.dir"); testDistDir = moduleDir + File.separatorChar + "build" + File.separatorChar + "testdist"; } 697 } 698 for (Iterator ttIt = testTypes.entrySet().iterator(); ttIt.hasNext(); ) { 699 Map.Entry entry = (Map.Entry ) ttIt.next(); 700 String ttName = (String ) entry.getKey(); 701 Set ttModules = (Set ) entry.getValue(); 702 computeTestType(ttName,new File (testDistDir),ttModules,classpaths,ml); 703 } 704 return classpaths; 705 } 706 707 private void computeTestType(String ttName,File testDistDir, Set ttModules, Map <String ,TestClasspath> classpaths,ModuleList ml) { 708 709 Set compileCnds = new HashSet (); 710 Set runtimeCnds = new HashSet (); 711 Set testCompileCnds = new HashSet (); 712 Set testRuntimeCnds = new HashSet (); 713 714 Set processedRecursive = new HashSet (); 715 for (Iterator it = ttModules.iterator() ; it.hasNext();) { 716 TestModuleDependency td = (TestModuleDependency) it.next(); 717 String cnd = td.getModule().getCodeNameBase(); 718 if (td.isTest()) { 719 if (td.isCompile()) { 720 testCompileCnds.add(cnd); 721 } 722 testRuntimeCnds.add(cnd); 723 } 724 if (td.isRecursive()) { 725 processTestEntryRecursive(td,compileCnds,runtimeCnds,processedRecursive,ml); 727 } else { 728 runtimeCnds.add(cnd); 729 if (td.isCompile()) { 730 compileCnds.add(cnd); 731 } 732 } 733 } 734 TestClasspath testClasspath = new TestClasspath(mergePaths(compileCnds,false,ttName,testDistDir, ml), 735 mergePaths(runtimeCnds,false,ttName,testDistDir,ml), 736 mergePaths(testCompileCnds,true,ttName,testDistDir,ml), 737 mergePaths(testRuntimeCnds,true,ttName,testDistDir,ml)); 738 739 classpaths.put(ttName,testClasspath); 740 } 741 742 private void processTestEntryRecursive(TestModuleDependency td, 743 Set compileCnds, 744 Set runtimeCnds, 745 Set processedRecursive, 746 ModuleList ml) { 747 Set <String > unprocessed = new HashSet (); 748 749 unprocessed.add(td.getModule().getCodeNameBase()); 750 while (!unprocessed.isEmpty()) { Iterator it = unprocessed.iterator(); 752 String cnb = (String ) it.next(); 753 it.remove(); 754 if (processedRecursive.add(cnb)) { 755 ModuleEntry module = ml.getEntry(cnb); 756 if (module == null) { 757 Util.err.log(ErrorManager.WARNING, "Warning - could not find dependent module " + cnb + " for " + FileUtil.getFileDisplayName(project.getProjectDirectory())); 758 continue; 759 } 760 if (!cnb.equals(project.getCodeNameBase())) { runtimeCnds.add(cnb); 762 if (td.isCompile()) { 763 compileCnds.add(cnb); 764 } 765 } 766 String [] newDeps = module.getRunDependencies(); 767 unprocessed.addAll(Arrays.asList(newDeps)); 768 } 769 } 770 } 771 772 private String mergePaths(Set cnbs, boolean test,String testtype,File testDistDir,ModuleList ml) { 773 StringBuffer cps = new StringBuffer (); 774 for (Iterator it = cnbs.iterator() ; it.hasNext();) { 775 String cnb = (String )it.next(); 776 ModuleEntry module = (ModuleEntry)ml.getEntry(cnb); 777 if (cps.length() > 0) { 778 cps.append(':'); 779 } 780 if (test) { 781 File clusterDir = module.getClusterDirectory(); 783 if (clusterDir != null) { 784 String clusterName = clusterDir.getName(); 785 char s = File.separatorChar; 786 File jarFile = new File ( 787 testDistDir, testtype + s + clusterName + s + cnb.replace('.','-') + s + "tests.jar"); cps.append(jarFile.getPath()); 789 } 790 791 } else { 792 cps.append(module.getJarLocation().getPath()); 793 } 794 } 795 return cps.toString(); 796 } 797 798 } 799 | Popular Tags |