Lines 45-50
Link Here
|
45 |
import org.netbeans.api.java.platform.JavaPlatform; |
45 |
import org.netbeans.api.java.platform.JavaPlatform; |
46 |
import org.netbeans.api.java.platform.JavaPlatformManager; |
46 |
import org.netbeans.api.java.platform.JavaPlatformManager; |
47 |
import org.netbeans.api.project.ProjectManager; |
47 |
import org.netbeans.api.project.ProjectManager; |
|
|
48 |
import org.netbeans.modules.apisupport.project.universe.TestModuleDependency; |
48 |
import org.netbeans.modules.apisupport.project.universe.ModuleEntry; |
49 |
import org.netbeans.modules.apisupport.project.universe.ModuleEntry; |
49 |
import org.netbeans.modules.apisupport.project.universe.ModuleList; |
50 |
import org.netbeans.modules.apisupport.project.universe.ModuleList; |
50 |
import org.netbeans.spi.project.support.ant.AntProjectEvent; |
51 |
import org.netbeans.spi.project.support.ant.AntProjectEvent; |
Lines 81-86
Link Here
|
81 |
/** See issue #69440 for more details. */ |
82 |
/** See issue #69440 for more details. */ |
82 |
private boolean runInAtomicAction; |
83 |
private boolean runInAtomicAction; |
83 |
|
84 |
|
|
|
85 |
static class TestClasspath { |
86 |
String compile; |
87 |
String runtime; |
88 |
String testCompile; |
89 |
String testRuntime; |
90 |
public TestClasspath() { |
91 |
compile = ""; |
92 |
runtime = ""; |
93 |
testCompile = ""; |
94 |
testRuntime = ""; |
95 |
} |
96 |
public String getCompileClasspath() { |
97 |
return compile + ":" + testCompile; |
98 |
} |
99 |
public String getRuntimeClasspath() { |
100 |
return runtime + ":" + testRuntime; |
101 |
} |
102 |
|
103 |
private static TestClasspath getOrEmpty(Map testsCPs, String testtype) { |
104 |
TestClasspath tcp = (TestClasspath) testsCPs.get(testtype); |
105 |
if (tcp == null ) { |
106 |
tcp = new TestClasspath(); |
107 |
} |
108 |
return tcp; |
109 |
} |
110 |
} |
84 |
public Evaluator(NbModuleProject project, NbModuleTypeProvider typeProvider) { |
111 |
public Evaluator(NbModuleProject project, NbModuleTypeProvider typeProvider) { |
85 |
this.project = project; |
112 |
this.project = project; |
86 |
this.typeProvider = typeProvider; |
113 |
this.typeProvider = typeProvider; |
Lines 303-308
Link Here
|
303 |
buildDefaults.put("cp.extra", ""); // NOI18N |
330 |
buildDefaults.put("cp.extra", ""); // NOI18N |
304 |
buildDefaults.put("cp", "${module.classpath}:${cp.extra}"); // NOI18N |
331 |
buildDefaults.put("cp", "${module.classpath}:${cp.extra}"); // NOI18N |
305 |
buildDefaults.put("run.cp", computeRuntimeModuleClasspath(ml) + ":${cp.extra}:${build.classes.dir}"); // NOI18N |
332 |
buildDefaults.put("run.cp", computeRuntimeModuleClasspath(ml) + ":${cp.extra}:${build.classes.dir}"); // NOI18N |
|
|
333 |
|
306 |
baseEval = PropertyUtils.sequentialPropertyEvaluator(predefs, (PropertyProvider[]) providers.toArray(new PropertyProvider[providers.size()])); |
334 |
baseEval = PropertyUtils.sequentialPropertyEvaluator(predefs, (PropertyProvider[]) providers.toArray(new PropertyProvider[providers.size()])); |
307 |
buildDefaults.put("test.unit.cp.extra", ""); // NOI18N |
335 |
buildDefaults.put("test.unit.cp.extra", ""); // NOI18N |
308 |
String testJars; // #68685 - follow Ant script |
336 |
String testJars; // #68685 - follow Ant script |
Lines 339-347
Link Here
|
339 |
"${netbeans.user}/modules/org-netbeans-modules-nbjunit.jar:" + // NOI18N, new for 6.0 |
367 |
"${netbeans.user}/modules/org-netbeans-modules-nbjunit.jar:" + // NOI18N, new for 6.0 |
340 |
"${netbeans.user}/modules/org-netbeans-modules-nbjunit-ide.jar"; // NOI18N, new for 6.0 |
368 |
"${netbeans.user}/modules/org-netbeans-modules-nbjunit-ide.jar"; // NOI18N, new for 6.0 |
341 |
} |
369 |
} |
342 |
buildDefaults.put("test.unit.cp", "${cp}:${cluster}/${module.jar}:" + testJars + ":${test.unit.cp.extra}"); // NOI18N |
370 |
Map/*<String,TestClassPath>*/ testsCPs = computeTestingClassPaths(ml,baseEval); |
|
|
371 |
TestClasspath tcp = TestClasspath.getOrEmpty(testsCPs,"unit"); |
372 |
|
373 |
buildDefaults.put("test.unit.cp", "${cp}:${cluster}/${module.jar}:" + testJars + ":${test.unit.cp.extra}:" + tcp.getCompileClasspath()); // NOI18N |
343 |
buildDefaults.put("test.unit.run.cp.extra", ""); // NOI18N |
374 |
buildDefaults.put("test.unit.run.cp.extra", ""); // NOI18N |
344 |
buildDefaults.put("test.unit.run.cp", "${test.unit.cp}:${build.test.unit.classes.dir}:${test.unit.run.cp.extra}"); // NOI18N |
375 |
buildDefaults.put("test.unit.run.cp", "${test.unit.cp}:${build.test.unit.classes.dir}:${test.unit.run.cp.extra}:"+ tcp.getRuntimeClasspath()); // NOI18N |
345 |
// #61085: need to treat qa-functional tests the same way... |
376 |
// #61085: need to treat qa-functional tests the same way... |
346 |
buildDefaults.put("test.qa-functional.cp.extra", ""); // NOI18N |
377 |
buildDefaults.put("test.qa-functional.cp.extra", ""); // NOI18N |
347 |
// No idea how XTest finds these, some weird magic, so no Ant script to match up to: |
378 |
// No idea how XTest finds these, some weird magic, so no Ant script to match up to: |
Lines 353-366
Link Here
|
353 |
if (jelly2NbJar != null) { |
384 |
if (jelly2NbJar != null) { |
354 |
buildDefaults.put("jelly2-nb.jar", jelly2NbJar); // NOI18N |
385 |
buildDefaults.put("jelly2-nb.jar", jelly2NbJar); // NOI18N |
355 |
} |
386 |
} |
|
|
387 |
tcp = TestClasspath.getOrEmpty(testsCPs,"qa-functional"); |
356 |
buildDefaults.put("test.qa-functional.cp", testJars + // NOI18N |
388 |
buildDefaults.put("test.qa-functional.cp", testJars + // NOI18N |
357 |
":${netbeans.home}/../testtools/modules/ext/nbjunit-ide.jar" + // NOI18N |
389 |
":${netbeans.home}/../testtools/modules/ext/nbjunit-ide.jar" + // NOI18N |
358 |
":${netbeans.user}/testtools/modules/ext/nbjunit.jar" + // NOI18N |
390 |
":${netbeans.user}/testtools/modules/ext/nbjunit.jar" + // NOI18N |
359 |
":${jemmy.jar}" + // NOI18N |
391 |
":${jemmy.jar}" + // NOI18N |
360 |
":${jelly2-nb.jar}" + // NOI18N |
392 |
":${jelly2-nb.jar}" + // NOI18N |
361 |
":${test.qa-functional.cp.extra}"); // NOI18N |
393 |
":${test.qa-functional.cp.extra}:" + |
|
|
394 |
tcp.compile + ":" + tcp.testCompile); // NOI18N |
362 |
buildDefaults.put("build.test.qa-functional.classes.dir", "build/test/qa-functional/classes"); // NOI18N |
395 |
buildDefaults.put("build.test.qa-functional.classes.dir", "build/test/qa-functional/classes"); // NOI18N |
363 |
buildDefaults.put("test.qa-functional.run.cp", "${test.qa-functional.cp}:${build.test.qa-functional.classes.dir}"); // NOI18N |
396 |
buildDefaults.put("test.qa-functional.run.cp", "${test.qa-functional.cp}:${build.test.qa-functional.classes.dir}" + ":" + tcp.runtime + ":" + tcp.testRuntime); // NOI18N |
364 |
providers.add(PropertyUtils.fixedPropertyProvider(buildDefaults)); |
397 |
providers.add(PropertyUtils.fixedPropertyProvider(buildDefaults)); |
365 |
} |
398 |
} |
366 |
// skip a bunch of properties irrelevant here - NBM stuff, etc. |
399 |
// skip a bunch of properties irrelevant here - NBM stuff, etc. |
Lines 618-622
Link Here
|
618 |
} |
651 |
} |
619 |
return cp.toString(); |
652 |
return cp.toString(); |
620 |
} |
653 |
} |
|
|
654 |
|
655 |
// |
656 |
/** parse classpath for tests from project.xml |
657 |
* @retun Map String testtype -> TestClasspath |
658 |
*/ |
659 |
private Map computeTestingClassPaths(ModuleList ml,PropertyEvaluator evaluator) { |
660 |
|
661 |
|
662 |
Map /*<String,String>*/ classpaths = new HashMap(); |
663 |
Map /*<String,Set<TestModuleDepency>>*/ testTypes = getTestDependencies(ml); |
664 |
|
665 |
String testDistDir = evaluator.getProperty("test.dist.dir"); // NOI18N |
666 |
if (testDistDir == null) { |
667 |
NbModuleTypeProvider.NbModuleType type = typeProvider.getModuleType(); |
668 |
if (type == NbModuleTypeProvider.NETBEANS_ORG) { |
669 |
// test.dist.dir = ${nb_all}/nbbuild/build/testdist |
670 |
String nball = evaluator.getProperty("nb_all"); // NOI18N |
671 |
testDistDir = nball + File.separatorChar + "nbbuild" + File.separatorChar + "build" + File.separatorChar + "testdist"; // NOI18N |
672 |
} else if ( type == NbModuleTypeProvider.SUITE_COMPONENT) { |
673 |
// test.dist.dir = ${suite.dir}/build/testdist |
674 |
String suiteDir = evaluator.getProperty("suite.dir"); // NOI18N |
675 |
testDistDir = suiteDir + File.separatorChar + "build" + File.separatorChar + "testdist"; // NOI18N |
676 |
} else { |
677 |
// standalone module |
678 |
// test.dist.dir = ${module.dir}/build/testdist |
679 |
String moduleDir = evaluator.getProperty("module.dir"); // NOI18N |
680 |
testDistDir = moduleDir + File.separatorChar + "build" + File.separatorChar + "testdist"; |
681 |
} |
682 |
} |
683 |
for (Iterator ttIt = testTypes.entrySet().iterator() ; ttIt.hasNext() ; ) { |
684 |
Map.Entry entry = (Map.Entry) ttIt.next(); |
685 |
String ttName = (String)entry.getKey(); |
686 |
Set ttModules = (Set)entry.getValue(); |
687 |
computeTestType(ttName,new File(testDistDir),ttModules,classpaths,ml); |
688 |
} |
689 |
return classpaths; |
690 |
} |
691 |
private Map /*<String,Set<TestModuleDepency>>*/getTestDependencies(ModuleList ml) { |
692 |
Element data = project.getHelper().getPrimaryConfigurationData(true); |
693 |
Element pp = Util.findElement(data, |
694 |
"test-dependencies", NbModuleProjectType.NAMESPACE_SHARED); // NOI18N |
621 |
|
695 |
|
|
|
696 |
|
697 |
Map/*<String,SortedSet<TestModuleDepency>>*/ testDeps = new HashMap(); |
698 |
|
699 |
if (pp != null) { |
700 |
for (Iterator depssIt = Util.findSubElements(pp).iterator(); depssIt.hasNext();) { |
701 |
Element depssEl = (Element) depssIt.next(); |
702 |
Element testTypeEl = Util.findElement(depssEl,"name",NbModuleProjectType.NAMESPACE_SHARED); |
703 |
String testType = null; |
704 |
if (testTypeEl != null) { |
705 |
testType = Util.findText(testTypeEl); |
706 |
} |
707 |
if (testType == null) { |
708 |
testType = TestModuleDependency.UNIT; // default variant |
709 |
} |
710 |
Set/*<TestModuleDependency>*/ directTestDeps = new HashSet(); |
711 |
|
712 |
testDeps.put(testType,directTestDeps); |
713 |
for (Iterator depsIt = Util.findSubElements(depssEl).iterator() ; depsIt.hasNext();) { |
714 |
Element el = (Element) depsIt.next(); |
715 |
if (el.getTagName().equals("test-dependency")) { |
716 |
// parse test dep |
717 |
boolean test = Util.findElement(el,"test",NbModuleProjectType.NAMESPACE_SHARED) != null; |
718 |
Element cnbEl = Util.findElement(el,"code-name-base",NbModuleProjectType.NAMESPACE_SHARED); |
719 |
|
720 |
String cnb = null; |
721 |
if (cnbEl != null) { |
722 |
cnb = Util.findText(cnbEl); |
723 |
} |
724 |
boolean recursive = Util.findElement(el,"recursive",NbModuleProjectType.NAMESPACE_SHARED) != null; |
725 |
boolean compile = Util.findElement(el,"compile-dependency",NbModuleProjectType.NAMESPACE_SHARED) != null; |
726 |
if (cnb != null) { |
727 |
ModuleEntry me = ml.getEntry(cnb); |
728 |
// [TOOD] show error module is |
729 |
if (me != null) { |
730 |
directTestDeps.add(new TestModuleDependency(me,test,recursive,compile)); |
731 |
} |
732 |
} |
733 |
} |
734 |
} |
735 |
} |
736 |
} |
737 |
return testDeps; |
738 |
} |
739 |
|
740 |
|
741 |
private void computeTestType(String ttName,File testDistDir, Set ttModules, Map/*<String,TestClasspath>*/ classpaths,ModuleList ml) { |
742 |
|
743 |
Set compileCnds = new HashSet(); |
744 |
Set runtimeCnds = new HashSet(); |
745 |
Set testCompileCnds = new HashSet(); |
746 |
Set testRuntimeCnds = new HashSet(); |
747 |
|
748 |
Set processedRecursive = new HashSet(); |
749 |
for (Iterator it = ttModules.iterator() ; it.hasNext();) { |
750 |
TestModuleDependency td = (TestModuleDependency) it.next(); |
751 |
String cnd = td.getModule().getCodeNameBase(); |
752 |
if (td.isTest()) { |
753 |
if (td.isCompile()) { |
754 |
testCompileCnds.add(cnd); |
755 |
} |
756 |
testRuntimeCnds.add(cnd); |
757 |
} |
758 |
if (td.isRecursive()) { |
759 |
// scan cp recursively |
760 |
processTestEntryRecursive(td,compileCnds,runtimeCnds,processedRecursive,ml); |
761 |
} else { |
762 |
runtimeCnds.add(cnd); |
763 |
if (td.isCompile()) { |
764 |
compileCnds.add(cnd); |
765 |
} |
766 |
} |
767 |
} |
768 |
TestClasspath testClasspath = new TestClasspath(); |
769 |
testClasspath.compile = mergePaths(compileCnds,false,ttName,testDistDir, ml); |
770 |
testClasspath.runtime = mergePaths(runtimeCnds,false,ttName,testDistDir,ml); |
771 |
testClasspath.testCompile = mergePaths(testCompileCnds,true,ttName,testDistDir,ml); |
772 |
testClasspath.testRuntime = mergePaths(testRuntimeCnds,true,ttName,testDistDir,ml); |
773 |
|
774 |
classpaths.put(ttName,testClasspath); |
775 |
} |
776 |
|
777 |
private void processTestEntryRecursive(TestModuleDependency td, |
778 |
Set compileCnds, |
779 |
Set runtimeCnds, |
780 |
Set processedRecursive, |
781 |
ModuleList ml) { |
782 |
Set/*<String>*/ unprocessed = new HashSet(); |
783 |
|
784 |
unprocessed.add(td.getModule().getCodeNameBase()); |
785 |
while (!unprocessed.isEmpty()) { // crude breadth-first search |
786 |
Iterator it = unprocessed.iterator(); |
787 |
String cnb = (String) it.next(); |
788 |
it.remove(); |
789 |
if (processedRecursive.add(cnb)) { |
790 |
ModuleEntry module = ml.getEntry(cnb); |
791 |
if (module == null) { |
792 |
Util.err.log(ErrorManager.WARNING, "Warning - could not find dependent module " + cnb + " for " + FileUtil.getFileDisplayName(project.getProjectDirectory())); |
793 |
continue; |
794 |
} |
795 |
if (!cnb.equals(project.getCodeNameBase())) { // build/classes for this is special |
796 |
runtimeCnds.add(cnb); |
797 |
if (td.isCompile()) { |
798 |
compileCnds.add(cnb); |
799 |
} |
800 |
} |
801 |
String[] newDeps = module.getRunDependencies(); |
802 |
unprocessed.addAll(Arrays.asList(newDeps)); |
803 |
} |
804 |
} |
805 |
} |
806 |
|
807 |
private String mergePaths(Set cnbs, boolean test,String testtype,File testDistDir,ModuleList ml) { |
808 |
StringBuffer cps = new StringBuffer(); |
809 |
for (Iterator it = cnbs.iterator() ; it.hasNext();) { |
810 |
String cnb = (String)it.next(); |
811 |
ModuleEntry module = (ModuleEntry)ml.getEntry(cnb); |
812 |
if (cps.length() > 0) { |
813 |
cps.append(":"); |
814 |
} |
815 |
if (test) { |
816 |
// we need to get cluster name |
817 |
File clusterDir = module.getClusterDirectory(); |
818 |
if (clusterDir != null) { |
819 |
String clusterName = clusterDir.getName(); |
820 |
char s = File.separatorChar; |
821 |
File jarFile = new File( |
822 |
testDistDir, testtype + s + clusterName + s + cnb.replace('.','-') + s + "tests.jar"); |
823 |
cps.append(jarFile.getPath()); |
824 |
} |
825 |
|
826 |
} else { |
827 |
cps.append(module.getJarLocation().getPath()); |
828 |
} |
829 |
} |
830 |
return cps.toString(); |
831 |
} |
832 |
|
622 |
} |
833 |
} |