diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/Bundle.properties b/apisupport.project/src/org/netbeans/modules/apisupport/project/Bundle.properties --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/Bundle.properties +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/Bundle.properties @@ -48,10 +48,7 @@ # NbModuleProject LBL_source_packages=Source Packages LBL_unit_test_packages=Unit Test Packages -LBL_functional_test_packages=Functional Test Packages -LBL_performance_test_packages=Performance Test Packages -# {0} - folder name -LBL_unknown_test_packages={0} Test Packages +LBL_qa-functional_test_packages=Functional Test Packages LBL_javahelp_packages=JavaHelp # {0} - project directory NbModuleProject.too_new=This version of the IDE is too old to read metadata in {0}. diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/Evaluator.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/Evaluator.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/Evaluator.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/Evaluator.java @@ -58,6 +58,7 @@ import java.util.Map; import java.util.Set; import java.util.TreeMap; +import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.event.ChangeListener; @@ -77,7 +78,6 @@ import org.openide.ErrorManager; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; -import org.openide.modules.InstalledFileLocator; import org.openide.util.ChangeSupport; import org.openide.util.Mutex; import org.openide.util.RequestProcessor; @@ -367,12 +367,15 @@ defaults.put("manifest.mf", "manifest.mf"); // NOI18N defaults.put("src.dir", "src"); // NOI18N defaults.put("build.classes.dir", "build/classes"); // NOI18N - defaults.put("test.unit.src.dir", "test/unit/src"); // NOI18N - defaults.put("test.qa-functional.src.dir", "test/qa-functional/src"); // NOI18N - defaults.put("test.qa-performance.src.dir", "test/qa-performance/src"); // NOI18N - defaults.put("build.test.unit.classes.dir", "build/test/unit/classes"); // NOI18N defaults.put("javac.source", "1.4"); // NOI18N defaults.put("test.user.dir", new File(dir, "build/testuserdir").getAbsolutePath()); // NOI18N + Set testTypes = new HashSet(Arrays.asList(NbModuleProject.COMMON_TEST_TYPES)); + // XXX would be good to add in any other types defined in project.xml + for (String testType : testTypes) { + defaults.put("test." + testType + ".src.dir", "test/" + testType + "/src"); // NOI18N + defaults.put("test." + testType + ".data.dir", "test/" + testType + "/data"); // NOI18N + defaults.put("build.test." + testType + ".classes.dir", "build/test/" + testType + "/classes"); // NOI18N + } providers.add(PropertyUtils.fixedPropertyProvider(defaults)); if (ml != null) { providers.add(PropertyUtils.fixedPropertyProvider(Collections.singletonMap("module.classpath", computeModuleClasspath(ml)))); // NOI18N @@ -382,70 +385,17 @@ buildDefaults.put("run.cp", computeRuntimeModuleClasspath(ml) + ":${cp.extra}:${build.classes.dir}"); // NOI18N baseEval = PropertyUtils.sequentialPropertyEvaluator(predefs, providers.toArray(new PropertyProvider[providers.size()])); - buildDefaults.put("test.unit.cp.extra", ""); // NOI18N - String testJars; // #68685 - follow Ant script - if (type == NbModuleProvider.NETBEANS_ORG) { - // Cf. nbbuild/templates/projectized.xml#test-lib-init - buildDefaults.put("xtest.home", "${nb_all}/xtest"); // NOI18N - testJars = - "${xtest.home}/lib/junit.jar:" + // NOI18N - "${xtest.home}/lib/nbjunit.jar:" + // NOI18N - "${xtest.home}/lib/nbjunit-ide.jar:" + // NOI18N - "${xtest.home}/lib/insanelib.jar"; // NOI18N - } else { - // Cf. apisupport/harness/release/build.xml#test-lib-init - testJars = - "${test.unit.lib.cp}:" + // NOI18N - // XXX this is ugly, try to look for the JAR using wildcards instead - "${netbeans.dest.dir}/ide6/modules/ext/junit-3.8.1.jar:" + // NOI18N - "${netbeans.dest.dir}/java2/modules/ext/junit-3.8.2.jar:" + // NOI18N - "${netbeans.dest.dir}/java2/modules/ext/junit-4.1.jar:" + // NOI18N - "${netbeans.dest.dir}/testtools/modules/ext/nbjunit.jar:" + // NOI18N - "${netbeans.dest.dir}/testtools/modules/ext/insanelib.jar:" + // NOI18N - "${netbeans.dest.dir}/testtools/modules/org-netbeans-modules-nbjunit.jar:" + // NOI18N, new for 6.0 - "${netbeans.dest.dir}/testtools/modules/org-netbeans-modules-nbjunit-ide.jar:" + // NOI18N, new for 6.0 - "${netbeans.home}/../ide6/modules/ext/junit-3.8.1.jar:" + // NOI18N - "${netbeans.home}/../java2/modules/ext/junit-3.8.2.jar:" + // NOI18N - "${netbeans.home}/../java2/modules/ext/junit-4.1.jar:" + // NOI18N - "${netbeans.home}/../testtools/modules/ext/nbjunit.jar:" + // NOI18N - "${netbeans.home}/../testtools/modules/ext/insanelib.jar:" + // NOI18N - "${netbeans.home}/../testtools/modules/org-netbeans-modules-nbjunit.jar:" + // NOI18N, new for 6.0 - "${netbeans.home}/../testtools/modules/org-netbeans-modules-nbjunit-ide.jar:" + // NOI18N, new for 6.0 - "${netbeans.user}/modules/ext/nbjunit.jar:" + // NOI18N - "${netbeans.user}/modules/ext/insanelib.jar:" + // NOI18N - "${netbeans.dest.dir}/../../xtest/lib/junit.jar:" + // NOI18N - "${netbeans.dest.dir}/../../xtest/lib/nbjunit.jar:" + // NOI18N - "${netbeans.dest.dir}/../../xtest/lib/insanelib.jar:" + // NOI18N - "${netbeans.user}/modules/org-netbeans-modules-nbjunit.jar:" + // NOI18N, new for 6.0 - "${netbeans.user}/modules/org-netbeans-modules-nbjunit-ide.jar"; // NOI18N, new for 6.0 + + Map testsCPs = computeTestingClassPaths(ml, baseEval, testTypes); + testTypes.addAll(testsCPs.keySet()); + for (String testType : testTypes) { + buildDefaults.put("test." + testType + ".cp.extra", ""); // NOI18N + TestClasspath tcp = TestClasspath.getOrEmpty(testsCPs, testType); + buildDefaults.put("test." + testType + ".cp", "${cp}:${cluster}/${module.jar}:${test." + testType + ".cp.extra}:" + tcp.getCompileClasspath()); // NOI18N + buildDefaults.put("test." + testType + ".run.cp.extra", ""); // NOI18N + buildDefaults.put("test." + testType + ".run.cp", "${test." + testType + ".cp}:${build.test." + testType + ".classes.dir}:${test." + testType + ".run.cp.extra}:" + tcp.getRuntimeClasspath()); // NOI18N } - Map testsCPs = computeTestingClassPaths(ml,baseEval); - TestClasspath tcp = TestClasspath.getOrEmpty(testsCPs, "unit"); // NOI18N - - buildDefaults.put("test.unit.cp", "${cp}:${cluster}/${module.jar}:" + testJars + ":${test.unit.cp.extra}:" + tcp.getCompileClasspath()); // NOI18N - buildDefaults.put("test.unit.run.cp.extra", ""); // NOI18N - buildDefaults.put("test.unit.run.cp", "${test.unit.cp}:${build.test.unit.classes.dir}:${test.unit.run.cp.extra}:"+ tcp.getRuntimeClasspath()); // NOI18N - // #61085: need to treat qa-functional tests the same way... - buildDefaults.put("test.qa-functional.cp.extra", ""); // NOI18N - // No idea how XTest finds these, some weird magic, so no Ant script to match up to: - String jemmyJar = findJemmyJar(baseEval); - if (jemmyJar != null) { - buildDefaults.put("jemmy.jar", jemmyJar); // NOI18N - } - String jelly2NbJar = findJelly2NbJar(baseEval); - if (jelly2NbJar != null) { - buildDefaults.put("jelly2-nb.jar", jelly2NbJar); // NOI18N - } - tcp = TestClasspath.getOrEmpty(testsCPs, "qa-functional"); // NOI18N - buildDefaults.put("test.qa-functional.cp", testJars + // NOI18N - ":${netbeans.home}/../testtools/modules/ext/nbjunit-ide.jar" + // NOI18N - ":${netbeans.user}/testtools/modules/ext/nbjunit.jar" + // NOI18N - ":${jemmy.jar}" + // NOI18N - ":${jelly2-nb.jar}" + // NOI18N - ":${test.qa-functional.cp.extra}:" + // NOI18N - tcp.compile + ':' + tcp.testCompile); - buildDefaults.put("build.test.qa-functional.classes.dir", "build/test/qa-functional/classes"); // NOI18N - buildDefaults.put("test.qa-functional.run.cp", "${test.qa-functional.cp}:${build.test.qa-functional.classes.dir}" + ':' + tcp.runtime + ':' + tcp.testRuntime); // NOI18N + providers.add(PropertyUtils.fixedPropertyProvider(buildDefaults)); } // skip a bunch of properties irrelevant here - NBM stuff, etc. @@ -572,40 +522,6 @@ } /** - * Get an Ant location for the root of jemmy.jar. - */ - private String findJemmyJar(PropertyEvaluator eval) { - File f = project.getNbrootFile("jemmy/builds/jemmy.jar", eval); // NOI18N - if(f == null) { - // try to find jemmy.jar installed by Jemmy module - f = InstalledFileLocator.getDefault().locate( - "modules/ext/jemmy.jar", "org.netbeans.modules.jemmy", false); // NOI18N - } - if (f != null) { - return f.getAbsolutePath(); - } else { - return null; - } - } - - /** - * Get an Ant location for the root of jemmy.jar. - */ - private String findJelly2NbJar(PropertyEvaluator eval) { - File f = project.getNbrootFile("jellytools/builds/jelly2-nb.jar", eval); // NOI18N - if(f == null) { - // try to find jelly2-nb.jar installed by Jellytools module - f = InstalledFileLocator.getDefault().locate( - "modules/ext/jelly2-nb.jar", "org.netbeans.modules.jellytools", false); // NOI18N - } - if (f != null) { - return f.getAbsolutePath(); - } else { - return null; - } - } - - /** * Should be similar to impl in ParseProjectXml. */ private String computeModuleClasspath(ModuleList ml) { @@ -686,10 +602,10 @@ * to the {@link TestClasspath test classpath} according to the content in * the project's metadata (project.xml). */ - private Map computeTestingClassPaths(ModuleList ml, PropertyEvaluator evaluator) { + private Map computeTestingClassPaths(ModuleList ml, PropertyEvaluator evaluator, Set extraTestTypes) { Map classpaths = new HashMap(); ProjectXMLManager pxm = new ProjectXMLManager(project); - Map> testTypes = pxm.getTestDependencies(ml); + Map> testDependencies = pxm.getTestDependencies(ml); String testDistDir = evaluator.getProperty("test.dist.dir"); // NOI18N if (testDistDir == null) { @@ -709,42 +625,109 @@ testDistDir = moduleDir + File.separatorChar + "build" + File.separatorChar + "testdist"; // NOI18N } } - for (Map.Entry> entry : testTypes.entrySet()) { + for (Map.Entry> entry : testDependencies.entrySet()) { computeTestType(entry.getKey(), new File(testDistDir), entry.getValue(), classpaths, ml); + } + for (String testType : extraTestTypes) { + if (!testDependencies.containsKey(testType)) { + // No declared dependencies of this type, so will definitely need to add in compatibility libraries. + computeTestType(testType, new File(testDistDir), Collections.emptySet(), classpaths, ml); + } } return classpaths; } private void computeTestType(String ttName, File testDistDir, Set ttModules, Map classpaths, ModuleList ml) { - - Set compileCnds = new HashSet(); - Set runtimeCnds = new HashSet(); - Set testCompileCnds = new HashSet(); - Set testRuntimeCnds = new HashSet(); + Set compileCnbs = new HashSet(); + Set runtimeCnbs = new HashSet(); + Set testCompileCnbs = new HashSet(); + Set testRuntimeCnbs = new HashSet(); Set processedRecursive = new HashSet(); + boolean fullySpecified = false; for (TestModuleDependency td : ttModules) { - String cnd = td.getModule().getCodeNameBase(); + String cnb = td.getModule().getCodeNameBase(); + fullySpecified |= cnb.equals("org.netbeans.libs.junit4"); if (td.isTest()) { if (td.isCompile()) { - testCompileCnds.add(cnd); + testCompileCnbs.add(cnb); } - testRuntimeCnds.add(cnd); + testRuntimeCnbs.add(cnb); } if (td.isRecursive()) { // scan cp recursively - processTestEntryRecursive(td,compileCnds,runtimeCnds,processedRecursive,ml); + processTestEntryRecursive(td,compileCnbs,runtimeCnbs,processedRecursive,ml); } else { - runtimeCnds.add(cnd); + runtimeCnbs.add(cnb); if (td.isCompile()) { - compileCnds.add(cnd); + compileCnbs.add(cnb); } } } - TestClasspath testClasspath = new TestClasspath(mergePaths(compileCnds,false,ttName,testDistDir, ml), - mergePaths(runtimeCnds,false,ttName,testDistDir,ml), - mergePaths(testCompileCnds,true,ttName,testDistDir,ml), - mergePaths(testRuntimeCnds,true,ttName,testDistDir,ml)); + + StringBuilder extra = new StringBuilder(); + if (!fullySpecified) { + // Old module which failed to specify all its test dependencies. + if (ml.getEntry("org.netbeans.libs.junit4") == null) { + // Old platform. For compatibility, compute a basic unit test lib classpath. + String[] testLibJars = { + "${nb_all}/xtest/lib/insanelib.jar", // NOI18N + "${nb_all}/xtest/lib/junit.jar", // NOI18N + "${nb_all}/xtest/lib/nbjunit-ide.jar", // NOI18N + "${nb_all}/xtest/lib/nbjunit.jar", // NOI18N + "${netbeans.dest.dir}/../../xtest/lib/insanelib.jar", // NOI18N + "${netbeans.dest.dir}/../../xtest/lib/junit.jar", // NOI18N + "${netbeans.dest.dir}/../../xtest/lib/nbjunit.jar", // NOI18N + "${netbeans.dest.dir}/ide6/modules/ext/junit-3.8.1.jar", // NOI18N + "${netbeans.dest.dir}/java2/modules/ext/junit-3.8.2.jar", // NOI18N + "${netbeans.dest.dir}/java2/modules/ext/junit-4.1.jar", // NOI18N + "${netbeans.dest.dir}/testtools/modules/ext/insanelib.jar", // NOI18N + "${netbeans.dest.dir}/testtools/modules/ext/nbjunit.jar", // NOI18N + "${netbeans.dest.dir}/testtools/modules/org-netbeans-modules-nbjunit-ide.jar", // NOI18N + "${netbeans.dest.dir}/testtools/modules/org-netbeans-modules-nbjunit.jar", // NOI18N + "${netbeans.home}/../ide6/modules/ext/junit-3.8.1.jar", // NOI18N + "${netbeans.home}/../java2/modules/ext/junit-3.8.2.jar", // NOI18N + "${netbeans.home}/../java2/modules/ext/junit-4.1.jar", // NOI18N + "${netbeans.home}/../testtools/modules/ext/insanelib.jar", // NOI18N + "${netbeans.home}/../testtools/modules/ext/nbjunit.jar", // NOI18N + "${netbeans.home}/../testtools/modules/org-netbeans-modules-nbjunit-ide.jar", // NOI18N + "${netbeans.home}/../testtools/modules/org-netbeans-modules-nbjunit.jar", // NOI18N + "${netbeans.user}/modules/ext/insanelib.jar", // NOI18N + "${netbeans.user}/modules/ext/nbjunit.jar", // NOI18N + "${netbeans.user}/modules/org-netbeans-modules-nbjunit-ide.jar", // NOI18N + "${netbeans.user}/modules/org-netbeans-modules-nbjunit.jar", // NOI18N + }; + for (String jar : testLibJars) { + extra.append(":"); + extra.append(jar); + } + if (ttName.startsWith("qa-")) { + extra.append(":${nb_all}/jemmy/builds/jemmy.jar:${nb_all}/jellytools/builds/jelly2-nb.jar"); + } + } else { + // Basic dependencies many tests use: + for (String library : new String[] {"org.netbeans.libs.junit4", "org.netbeans.modules.nbjunit", "org.netbeans.insane"}) { + compileCnbs.add(library); + runtimeCnbs.add(library); + } + if (ttName.startsWith("qa-")) { + // ProjectSupport moved from the old nbjunit.ide: + testCompileCnbs.add("org.netbeans.modules.java.j2seproject"); + testRuntimeCnbs.add("org.netbeans.modules.java.j2seproject"); + // Common GUI testing tools: + for (String library : new String[] {"org.netbeans.modules.jemmy", "org.netbeans.modules.jellytools"}) { + compileCnbs.add(library); + runtimeCnbs.add(library); + } + } + } + } + + TestClasspath testClasspath = new TestClasspath( + mergePaths(compileCnbs,false,ttName,testDistDir, ml) + extra, + mergePaths(runtimeCnbs,false,ttName,testDistDir,ml) + extra, + mergePaths(testCompileCnbs,true,ttName,testDistDir,ml), + mergePaths(testRuntimeCnbs,true,ttName,testDistDir,ml)); classpaths.put(ttName,testClasspath); } @@ -779,10 +762,17 @@ } } + private static final Set warnedModules = Collections.synchronizedSet(new HashSet()); private String mergePaths(Set cnbs, boolean test,String testtype,File testDistDir,ModuleList ml) { StringBuffer cps = new StringBuffer(); for (String cnb : cnbs) { ModuleEntry module = ml.getEntry(cnb); + if (module == null) { + if (warnedModules.add(cnb)) { + Logger.getLogger(Evaluator.class.getName()).warning("Cannot find test module dependency: " + cnb); + } + continue; + } if (cps.length() > 0) { cps.append(':'); } @@ -795,10 +785,17 @@ File jarFile = new File( testDistDir, testtype + s + clusterName + s + cnb.replace('.','-') + s + "tests.jar"); // NOI18N cps.append(jarFile.getPath()); + // See ParseProjectXml: + if (!testtype.equals("unit")) { + cps.append(':'); + jarFile = new File(testDistDir, "unit" + s + clusterName + s + cnb.replace('.', '-') + s + "tests.jar"); // NOI18N + cps.append(jarFile.getPath()); + } } } else { cps.append(module.getJarLocation().getPath()); + cps.append(module.getClassPathExtensions()); // #105621 } } return cps.toString(); diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/NbModuleProject.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/NbModuleProject.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/NbModuleProject.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/NbModuleProject.java @@ -48,10 +48,11 @@ import java.io.IOException; import java.net.URI; import java.net.URL; +import java.util.ArrayList; import java.util.Arrays; -import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.WeakHashMap; import java.util.jar.Manifest; @@ -131,6 +132,7 @@ Utilities.loadImage(NB_PROJECT_ICON_PATH)); public static final String SOURCES_TYPE_JAVAHELP = "javahelp"; // NOI18N + static final String[] COMMON_TEST_TYPES = {"unit", "qa-functional"}; // NOI18N private final AntProjectHelper helper; private final Evaluator eval; @@ -159,54 +161,30 @@ throw new IOException("netbeans.org-type module not in a complete netbeans.org source root: " + this); // NOI18N } eval = new Evaluator(this, typeProvider); - FileBuiltQueryImplementation fileBuilt; // XXX could add globs for other package roots too - if (supportsUnitTests()) { - fileBuilt = helper.createGlobFileBuiltQuery(eval, new String[] { - "${src.dir}/*.java", // NOI18N - "${test.unit.src.dir}/*.java", // NOI18N - }, new String[] { - "${build.classes.dir}/*.class", // NOI18N - "${build.test.unit.classes.dir}/*.class", // NOI18N - }); - } else { - fileBuilt = helper.createGlobFileBuiltQuery(eval, new String[] { - "${src.dir}/*.java", // NOI18N - }, new String[] { - "${build.classes.dir}/*.class", // NOI18N - }); + List from = new ArrayList(); + List to = new ArrayList(); + from.add("${src.dir}/*.java"); // NOI18N + to.add("${build.classes.dir}/*.class"); // NOI18N + for (String type : supportedTestTypes()) { + from.add("${test." + type + ".src.dir}/*.java"); // NOI18N + to.add("${build.test." + type + ".classes.dir}/*.class"); // NOI18N } + FileBuiltQueryImplementation fileBuilt = helper.createGlobFileBuiltQuery( + eval,from.toArray(new String[0]), to.toArray(new String[0])); final SourcesHelper sourcesHelper = new SourcesHelper(helper, eval); // Temp build dir is always internal; NBM build products go elsewhere, but // difficult to predict statically exactly what they are! // XXX would be good to mark at least the module JAR as owned by this project // (currently FOQ/SH do not support that) sourcesHelper.addPrincipalSourceRoot("${src.dir}", NbBundle.getMessage(NbModuleProject.class, "LBL_source_packages"), null, null); // #56457 - sourcesHelper.addPrincipalSourceRoot("${test.unit.src.dir}", NbBundle.getMessage(NbModuleProject.class, "LBL_unit_test_packages"), null, null); // #68727 + for (String type : supportedTestTypes()) { + sourcesHelper.addPrincipalSourceRoot("${test." + type + ".src.dir}", NbBundle.getMessage(NbModuleProject.class, "LBL_" + type + "_test_packages"), null, null); // #68727 + } sourcesHelper.addTypedSourceRoot("${src.dir}", JavaProjectConstants.SOURCES_TYPE_JAVA, NbBundle.getMessage(NbModuleProject.class, "LBL_source_packages"), null, null); // XXX other principal source roots, as needed... - sourcesHelper.addTypedSourceRoot("${test.unit.src.dir}", JavaProjectConstants.SOURCES_TYPE_JAVA, NbBundle.getMessage(NbModuleProject.class, "LBL_unit_test_packages"), null, null); - sourcesHelper.addTypedSourceRoot("${test.qa-functional.src.dir}", JavaProjectConstants.SOURCES_TYPE_JAVA, NbBundle.getMessage(NbModuleProject.class, "LBL_functional_test_packages"), null, null); - sourcesHelper.addTypedSourceRoot("${test.qa-performance.src.dir}", JavaProjectConstants.SOURCES_TYPE_JAVA, NbBundle.getMessage(NbModuleProject.class, "LBL_performance_test_packages"), null, null); - // #42332: also any other misc. test dirs (just add source roots, no CP etc. for now) - FileObject testDir = helper.getProjectDirectory().getFileObject("test"); // NOI18N - if (testDir != null) { - Enumeration kids = testDir.getChildren(false); - while (kids.hasMoreElements()) { - FileObject testSubdir = (FileObject) kids.nextElement(); - if (!testSubdir.isFolder()) { - continue; - } - String name = testSubdir.getNameExt(); - if (testDir.getFileObject("build-" + name + ".xml") == null) { // NOI18N - continue; - } - if (name.equals("unit") || name.equals("qa-functional") || name.equals("qa-performance")) { // NOI18N - // Already handled specially. - continue; - } - sourcesHelper.addTypedSourceRoot("test/" + name + "/src", JavaProjectConstants.SOURCES_TYPE_JAVA, NbBundle.getMessage(NbModuleProject.class, "LBL_unknown_test_packages", name), null, null); - } + for (String type : supportedTestTypes()) { + sourcesHelper.addTypedSourceRoot("${test." + type + ".src.dir}", JavaProjectConstants.SOURCES_TYPE_JAVA, NbBundle.getMessage(NbModuleProject.class, "LBL_" + type + "_test_packages"), null, null); } if (helper.resolveFileObject("javahelp/manifest.mf") == null) { // NOI18N // Special hack for core - ignore core/javahelp @@ -380,16 +358,8 @@ return getDir("src.dir"); // NOI18N } - public FileObject getTestSourceDirectory() { - return getDir("test.unit.src.dir"); // NOI18N - } - - public FileObject getFunctionalTestSourceDirectory() { - return getDir("test.qa-functional.src.dir"); // NOI18N - } - - public FileObject getPerformanceTestSourceDirectory() { - return getDir("test.qa-performance.src.dir"); // NOI18N + public FileObject getTestSourceDirectory(String type) { + return getDir("test." + type + ".src.dir"); // NOI18N } public File getClassesDirectory() { @@ -397,8 +367,8 @@ return helper.resolveFile(classesDir); } - public File getTestClassesDirectory() { - String testClassesDir = evaluator().getProperty("build.test.unit.classes.dir"); // NOI18N + public File getTestClassesDirectory(String type) { + String testClassesDir = evaluator().getProperty("build.test." + type + ".classes.dir"); // NOI18N return helper.resolveFile(testClassesDir); } @@ -619,8 +589,15 @@ return pubPkgs != null && !Util.findSubElements(pubPkgs).isEmpty(); } - public boolean supportsUnitTests() { - return getTestSourceDirectory() != null; + public List supportedTestTypes() { + List types = new ArrayList(); + for (String type : COMMON_TEST_TYPES) { + if (getTestSourceDirectory(type) != null && !Boolean.parseBoolean(evaluator().getProperty("disable." + type + ".tests"))) { + types.add(type); + } + } + // XXX could look for others in project.xml, in which case fix Evaluator to use that + return types; } /** diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/ClassPathProviderImpl.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/ClassPathProviderImpl.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/ClassPathProviderImpl.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/ClassPathProviderImpl.java @@ -103,11 +103,11 @@ return boot; } FileObject srcDir = project.getSourceDirectory(); - FileObject testSrcDir = project.getTestSourceDirectory(); - FileObject funcTestSrcDir = project.getFunctionalTestSourceDirectory(); + FileObject testSrcDir = project.getTestSourceDirectory("unit"); + FileObject funcTestSrcDir = project.getTestSourceDirectory("qa-functional"); File dir = project.getClassesDirectory(); FileObject classesDir = dir == null ? null : FileUtil.toFileObject(FileUtil.normalizeFile(dir)); - dir = project.getTestClassesDirectory(); + dir = project.getTestClassesDirectory("unit"); FileObject testClassesDir = dir == null ? null : FileUtil.toFileObject(FileUtil.normalizeFile(dir)); File moduleJar = project.getModuleJarLocation(); if (srcDir != null && (FileUtil.isParentOf(srcDir, file) || file == srcDir)) { @@ -131,15 +131,16 @@ } } else if (testSrcDir != null && (FileUtil.isParentOf(testSrcDir, file) || file == testSrcDir)) { // Unit tests. + // XXX refactor to use project.supportedTestTypes if (type.equals(ClassPath.COMPILE)) { if (testCompile == null) { - testCompile = ClassPathFactory.createClassPath(createTestCompileClasspath()); + testCompile = ClassPathFactory.createClassPath(createTestCompileClasspath("unit")); Util.err.log("compile-time classpath for tests in " + project + ": " + testCompile); } return testCompile; } else if (type.equals(ClassPath.EXECUTE)) { if (testExecute == null) { - testExecute = ClassPathFactory.createClassPath(createTestExecuteClasspath()); + testExecute = ClassPathFactory.createClassPath(createTestExecuteClasspath("unit")); Util.err.log("runtime classpath for tests in " + project + ": " + testExecute); } return testExecute; @@ -159,13 +160,13 @@ } else if (type.equals(ClassPath.COMPILE)) { // See #42331. if (funcTestCompile == null) { - funcTestCompile = ClassPathFactory.createClassPath(createFuncTestCompileClasspath()); + funcTestCompile = ClassPathFactory.createClassPath(createTestCompileClasspath("qa-functional")); Util.err.log("compile-time classpath for func tests in " + project + ": " + funcTestCompile); } return funcTestCompile; } else if (type.equals(ClassPath.EXECUTE)) { if (funcTestExecute == null) { - funcTestExecute = ClassPathFactory.createClassPath(createFuncTestExecuteClasspath()); + funcTestExecute = ClassPathFactory.createClassPath(createTestExecuteClasspath("qa-functional")); } return funcTestExecute; } @@ -184,7 +185,7 @@ } else if (testClassesDir != null && (testClassesDir.equals(file) || FileUtil.isParentOf(testClassesDir,file))) { if (ClassPath.EXECUTE.equals(type)) { if (testExecute == null) { - testExecute = ClassPathFactory.createClassPath(createTestExecuteClasspath()); + testExecute = ClassPathFactory.createClassPath(createTestExecuteClasspath("unit")); Util.err.log("runtime classpath for tests in " + project + ": " + testExecute); } return testExecute; @@ -240,20 +241,12 @@ } } - private ClassPathImplementation createTestCompileClasspath() { - return createPathFromProperty("test.unit.cp"); // NOI18N + private ClassPathImplementation createTestCompileClasspath(String testType) { + return createPathFromProperty("test." + testType + ".cp"); // NOI18N } - private ClassPathImplementation createTestExecuteClasspath() { - return createPathFromProperty("test.unit.run.cp"); // NOI18N - } - - private ClassPathImplementation createFuncTestCompileClasspath() { - return createPathFromProperty("test.qa-functional.cp"); // NOI18N - } - - private ClassPathImplementation createFuncTestExecuteClasspath() { - return createPathFromProperty("test.qa-functional.run.cp"); // NOI18N + private ClassPathImplementation createTestExecuteClasspath(String testType) { + return createPathFromProperty("test." + testType + ".run.cp"); // NOI18N } private ClassPathImplementation createExecuteClasspath() { @@ -352,11 +345,12 @@ if (srcDir != null) { paths.add(findClassPath(srcDir, ClassPath.COMPILE)); } - FileObject testSrcDir = project.getTestSourceDirectory(); + // XXX refactor to use project.supportedTestTypes + FileObject testSrcDir = project.getTestSourceDirectory("unit"); if (testSrcDir != null) { paths.add(findClassPath(testSrcDir, ClassPath.COMPILE)); } - FileObject funcTestSrcDir = project.getFunctionalTestSourceDirectory(); + FileObject funcTestSrcDir = project.getTestSourceDirectory("qa-functional"); if (funcTestSrcDir != null) { paths.add(findClassPath(funcTestSrcDir, ClassPath.COMPILE)); } @@ -367,11 +361,11 @@ if (srcDir != null) { paths.add(findClassPath(srcDir, ClassPath.EXECUTE)); } - FileObject testSrcDir = project.getTestSourceDirectory(); + FileObject testSrcDir = project.getTestSourceDirectory("unit"); if (testSrcDir != null) { paths.add(findClassPath(testSrcDir, ClassPath.EXECUTE)); } - FileObject funcTestSrcDir = project.getFunctionalTestSourceDirectory(); + FileObject funcTestSrcDir = project.getTestSourceDirectory("qa-functional"); if (funcTestSrcDir != null) { paths.add(findClassPath(funcTestSrcDir, ClassPath.EXECUTE)); } @@ -382,11 +376,11 @@ if (srcDir != null) { paths.add(findClassPath(srcDir, ClassPath.SOURCE)); } - FileObject testSrcDir = project.getTestSourceDirectory(); + FileObject testSrcDir = project.getTestSourceDirectory("unit"); if (testSrcDir != null) { paths.add(findClassPath(testSrcDir, ClassPath.SOURCE)); } - FileObject funcTestSrcDir = project.getFunctionalTestSourceDirectory(); + FileObject funcTestSrcDir = project.getTestSourceDirectory("qa-functional"); if (funcTestSrcDir != null) { paths.add(findClassPath(funcTestSrcDir, ClassPath.SOURCE)); } diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/GlobalJavadocForBinaryImpl.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/GlobalJavadocForBinaryImpl.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/GlobalJavadocForBinaryImpl.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/GlobalJavadocForBinaryImpl.java @@ -88,13 +88,9 @@ Util.err.log(binaryRoot + " is not an archive file."); // NOI18N return null; } - if (jar.toExternalForm().endsWith("/xtest/lib/junit.jar")) { // NOI18N - // #68685 hack - associate reasonable Javadoc with XTest's version of junit + if (jar.toExternalForm().endsWith("/modules/ext/junit-4.1.jar") || jar.toExternalForm().endsWith("/external/junit-4.1.jar")) { // NOI18N + // #68685 hack - associate reasonable Javadoc with JUnit 4.1 (currently we only bundle 3.x Javadoc) File f = InstalledFileLocator.getDefault().locate("modules/ext/junit-3.8.2.jar", "org.netbeans.modules.junit", false); // NOI18N - if (f == null) { - // For compat with NB 5.0. - f = InstalledFileLocator.getDefault().locate("modules/ext/junit-3.8.1.jar", "org.netbeans.modules.junit", false); // NOI18N - } if (f != null) { return JavadocForBinaryQuery.findJavadoc(FileUtil.getArchiveRoot(f.toURI().toURL())); } diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/SourceForBinaryImpl.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/SourceForBinaryImpl.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/SourceForBinaryImpl.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/SourceForBinaryImpl.java @@ -64,7 +64,7 @@ private final NbModuleProject project; private URL classesUrl; - private URL testClassesUrl; + private final Map testClassesUrl = new HashMap(); private Map cache = new HashMap(); public SourceForBinaryImpl(NbModuleProject project) { @@ -85,8 +85,7 @@ // maybe tests.jar in testdistribution TestEntry entry = TestEntry.get(binaryJarF); if (entry != null && project.getCodeNameBase().equals(entry.getCodeNameBase())) { - srcDir = ( entry.isUnit() ) ? project.getTestSourceDirectory() : - project.getFunctionalTestSourceDirectory(); + srcDir = project.getTestSourceDirectory(entry.getTestType()); } } if (srcDir != null) { @@ -99,12 +98,17 @@ if (srcDir != null) { res = new Result(srcDir); } - } else if (binaryRoot.equals(getTestClassesUrl())) { - FileObject testSrcDir = project.getTestSourceDirectory(); - if (testSrcDir != null) { - res = new Result(testSrcDir); + } else { + for (String testType : project.supportedTestTypes()) { + if (binaryRoot.equals(getTestClassesUrl(testType))) { + FileObject testSrcDir = project.getTestSourceDirectory(testType); + if (testSrcDir != null) { + res = new Result(testSrcDir); + break; + } + } } - } else { + if (res == null) { // Check extra compilation units. ECUS: for (Map.Entry entry : project.getExtraCompilationUnits().entrySet()) { for (Element kid : Util.findSubElements(entry.getValue())) { @@ -125,6 +129,7 @@ } } } + } } if (res != null) { cache.put(binaryRoot,res); @@ -141,12 +146,12 @@ return classesUrl; } - private URL getTestClassesUrl() { - if (testClassesUrl == null && project.supportsUnitTests()) { - File testClassesDir = project.getTestClassesDirectory(); - testClassesUrl = FileUtil.urlForArchiveOrDir(testClassesDir); + private URL getTestClassesUrl(String testType) { + if (!testClassesUrl.containsKey(testType) && project.supportedTestTypes().contains(testType)) { + File testClassesDir = project.getTestClassesDirectory(testType); + testClassesUrl.put(testType, FileUtil.urlForArchiveOrDir(testClassesDir)); } - return testClassesUrl; + return testClassesUrl.get(testType); } diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/Bundle.properties b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/Bundle.properties --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/Bundle.properties +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/Bundle.properties @@ -87,6 +87,7 @@ LBL_important_files=Important Files LBL_libraries=Libraries LBL_unit_test_libraries=Unit Test Libraries +LBL_qa-functional_test_libraries=Functional Test Libraries LBL_module_manifest=Module Manifest LBL_arch_desc=Architecture Description LBL_api_changes=API Changes @@ -120,7 +121,8 @@ CTL_test=Include also tests of module CTL_compile=Compile-time dependency CTL_recursive=Include dependencies recursively -CTL_AddTestDependency=Add Unit Test Dependency +CTL_AddTestDependency_unit=Add Unit Test Dependency +CTL_AddTestDependency_qa-functional=Add Functional Test Dependency # SuiteActions SUITE_ACTION_build=Build All @@ -178,3 +180,6 @@ TITLE_IconDialog=Select Icon LBL_IconInfo=Selected icon [size]: Templates/Licenses/license-cddl-netbeans-sun.txt=NetBeans CDDL + +TestDataDirsNodeFactory.unit_test_data=Unit Test Data +TestDataDirsNodeFactory.qa-functional_test_data=Functional Test Data diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/LibrariesNodeFactory.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/LibrariesNodeFactory.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/LibrariesNodeFactory.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/LibrariesNodeFactory.java @@ -78,8 +78,8 @@ public List keys() { List toRet = new ArrayList(); toRet.add(LibrariesNode.LIBRARIES_NAME); - if(resolveFileObjectFromProperty("test.unit.src.dir") != null) { //NOI18N - toRet.add(UnitTestLibrariesNode.UNIT_TEST_LIBRARIES_NAME); + for (String testType : project.supportedTestTypes()) { + toRet.add(testType); } return toRet; } @@ -101,10 +101,9 @@ public Node node(String key) { if (key == LibrariesNode.LIBRARIES_NAME) { return new LibrariesNode(project); - } else if (key == UnitTestLibrariesNode.UNIT_TEST_LIBRARIES_NAME) { - return new UnitTestLibrariesNode(project); + } else { + return new UnitTestLibrariesNode(key, project); } - throw new AssertionError("Unknown key: " + key); } public void addNotify() { diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/ModuleActions.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/ModuleActions.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/ModuleActions.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/ModuleActions.java @@ -105,7 +105,7 @@ } actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_DEBUG, NbBundle.getMessage(ModuleActions.class, "ACTION_debug"), null)); addFromLayers(actions, "Projects/Profiler_Actions_temporary"); //NOI18N - if (project.supportsUnitTests()) { + if (!project.supportedTestTypes().isEmpty()) { actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_TEST, NbBundle.getMessage(ModuleActions.class, "ACTION_test"), null)); } actions.add(null); @@ -174,23 +174,17 @@ globalCommands.put(ActionProvider.COMMAND_RUN, new String[] {"reload"}); // NOI18N globalCommands.put("profile", new String[] {"profile"}); // NOI18N globalCommands.put(JavaProjectConstants.COMMAND_JAVADOC, new String[] {"javadoc-nb"}); // NOI18N - if (project.supportsUnitTests()) { + if (!project.supportedTestTypes().isEmpty()) { globalCommands.put(ActionProvider.COMMAND_TEST, new String[] {"test"}); // NOI18N } supportedActionsSet.addAll(globalCommands.keySet()); supportedActionsSet.add(ActionProvider.COMMAND_COMPILE_SINGLE); supportedActionsSet.add(JavaProjectConstants.COMMAND_DEBUG_FIX); // #47012 - if (project.supportsUnitTests()) { + if (!project.supportedTestTypes().isEmpty()) { supportedActionsSet.add(ActionProvider.COMMAND_TEST_SINGLE); supportedActionsSet.add(ActionProvider.COMMAND_DEBUG_TEST_SINGLE); supportedActionsSet.add(ActionProvider.COMMAND_RUN_SINGLE); supportedActionsSet.add(ActionProvider.COMMAND_DEBUG_SINGLE); - } - if (project.getFunctionalTestSourceDirectory() != null) { - supportedActionsSet.add(ActionProvider.COMMAND_RUN_SINGLE); - } - if (project.getPerformanceTestSourceDirectory() != null) { - supportedActionsSet.add(ActionProvider.COMMAND_RUN_SINGLE); } supportedActionsSet.add(ActionProvider.COMMAND_RENAME); supportedActionsSet.add(ActionProvider.COMMAND_MOVE); @@ -207,10 +201,6 @@ return project.getProjectDirectory().getFileObject(GeneratedFilesHelper.BUILD_XML_PATH); } - private static FileObject findTestBuildXml(NbModuleProject project) { - return project.getProjectDirectory().getFileObject("test/build.xml"); // NOI18N - } - private static FileObject findMasterBuildXml(NbModuleProject project) { return project.getNbrootFileObject("nbbuild/build.xml"); // NOI18N } @@ -221,38 +211,31 @@ ActionProvider.COMMAND_MOVE.equals(command) || ActionProvider.COMMAND_COPY.equals(command)) { return true; + } else if (findBuildXml(project) == null) { + // All other actions require a build script. + return false; } else if (command.equals(COMMAND_COMPILE_SINGLE)) { - return findBuildXml(project) != null && - (findSources(context) != null || findTestSources(context, false) != null); + return findSources(context) != null || findTestSources(context, false) != null; } else if (command.equals(COMMAND_TEST_SINGLE)) { - return findBuildXml(project) != null && findTestSourcesForSources(context) != null; + return findTestSourcesForSources(context) != null; } else if (command.equals(COMMAND_DEBUG_TEST_SINGLE)) { - FileObject[] files = findTestSourcesForSources(context); - return findBuildXml(project) != null && files != null && files.length == 1; + TestSources testSources = findTestSourcesForSources(context); + return testSources != null && testSources.sources.length == 1; } else if (command.equals(COMMAND_RUN_SINGLE)) { - FileObject[] files = findFunctionalTestSources(context); - if (files != null && files.length == 1 && findTestBuildXml(project) != null) { + return findTestSources(context, false) != null; + } else if (command.equals(COMMAND_DEBUG_SINGLE)) { + TestSources testSources = findTestSources(context, false); + return testSources != null && testSources.sources.length == 1; + } else if (command.equals(JavaProjectConstants.COMMAND_DEBUG_FIX)) { + FileObject[] files = findSources(context); + if (files != null && files.length == 1) { return true; } - files = findPerformanceTestSources(context); - if (files != null && files.length == 1 && findTestBuildXml(project) != null) { - return true; - } - files = findTestSources(context, false); - return files != null; - } else if (command.equals(COMMAND_DEBUG_SINGLE)) { - FileObject[] files = findTestSources(context, false); - return files != null && files.length == 1; - } else if (command.equals(JavaProjectConstants.COMMAND_DEBUG_FIX)) { - FileObject[] files = findSources(context); - if (files != null && files.length == 1 && findBuildXml(project) != null) { - return true; - } - files = findTestSources(context, false); - return files != null && files.length == 1 && findBuildXml(project) != null; + TestSources testSources = findTestSources(context, false); + return testSources != null && testSources.sources.length == 1; } else { // other actions are global - return findBuildXml(project) != null; + return true; } } @@ -270,26 +253,40 @@ } } - private FileObject[] findTestSources(Lookup context, boolean checkInSrcDir) { - FileObject testSrcDir = project.getTestSourceDirectory(); - if (testSrcDir != null) { - FileObject[] files = ActionUtils.findSelectedFiles(context, testSrcDir, ".java", true); // NOI18N - if (files != null) { - return files; + static class TestSources { + final FileObject[] sources; + final String testType; + final FileObject sourceDirectory; + public TestSources(FileObject[] sources, String testType, FileObject sourceDirectory) { + assert sources != null; + assert sourceDirectory != null; + this.sources = sources; + this.testType = testType; + this.sourceDirectory = sourceDirectory; + } + } + private TestSources findTestSources(Lookup context, boolean checkInSrcDir) { + for (String testType : project.supportedTestTypes()) { + FileObject testSrcDir = project.getTestSourceDirectory(testType); + if (testSrcDir != null) { + FileObject[] files = ActionUtils.findSelectedFiles(context, testSrcDir, ".java", true); // NOI18N + if (files != null) { + return new TestSources(files, testType, testSrcDir); + } } } - //System.err.println("fTS: testSrcDir=" + testSrcDir + " checkInSrcDir=" + checkInSrcDir + " context=" + context); - if (checkInSrcDir && testSrcDir != null) { + if (checkInSrcDir) { FileObject srcDir = project.getSourceDirectory(); + FileObject testSrcDir = project.getTestSourceDirectory("unit"); // NOI18N //System.err.println(" srcDir=" + srcDir); - if (srcDir != null) { + if (srcDir != null && testSrcDir != null) { FileObject[] files = ActionUtils.findSelectedFiles(context, srcDir, ".java", true); // NOI18N //System.err.println(" files=" + files); if (files != null) { FileObject[] files2 = ActionUtils.regexpMapFiles(files, srcDir, SRCDIRJAVA, testSrcDir, SUBST, true); //System.err.println(" files2=" + files2); if (files2 != null) { - return files2; + return new TestSources(files2, "unit", testSrcDir); // NOI18N } } } @@ -299,31 +296,20 @@ /** Find tests corresponding to selected sources. */ - private FileObject[] findTestSourcesForSources(Lookup context) { + private TestSources findTestSourcesForSources(Lookup context) { + String testType = "unit"; // NOI18N FileObject[] sourceFiles = findSources(context); if (sourceFiles == null) { return null; } - FileObject testSrcDir = project.getTestSourceDirectory(); - FileObject srcDir = project.getSourceDirectory(); - return ActionUtils.regexpMapFiles(sourceFiles, srcDir, SRCDIRJAVA, testSrcDir, SUBST, true); - } - - private FileObject[] findFunctionalTestSources(Lookup context) { - FileObject srcDir = project.getFunctionalTestSourceDirectory(); - if (srcDir != null) { - FileObject[] files = ActionUtils.findSelectedFiles(context, srcDir, ".java", true); // NOI18N - return files; - } else { + FileObject testSrcDir = project.getTestSourceDirectory(testType); + if (testSrcDir == null) { return null; } - } - - private FileObject[] findPerformanceTestSources(Lookup context) { - FileObject srcDir = project.getPerformanceTestSourceDirectory(); - if (srcDir != null) { - FileObject[] files = ActionUtils.findSelectedFiles(context, srcDir, ".java", true); // NOI18N - return files; + FileObject srcDir = project.getSourceDirectory(); + FileObject[] matches = ActionUtils.regexpMapFiles(sourceFiles, srcDir, SRCDIRJAVA, testSrcDir, SUBST, true); + if (matches != null) { + return new TestSources(matches, testType,testSrcDir); } else { return null; } @@ -354,53 +340,31 @@ if (!verifySufficientlyNewHarness(project)) { return; } - Properties p; + Properties p = new Properties(); String[] targetNames; - FileObject buildScript = null; if (command.equals(COMMAND_COMPILE_SINGLE)) { FileObject[] files = findSources(context); - p = new Properties(); if (files != null) { p.setProperty("javac.includes", ActionUtils.antIncludesList(files, project.getSourceDirectory())); // NOI18N targetNames = new String[] {"compile-single"}; // NOI18N } else { - files = findTestSources(context, false); - p.setProperty("javac.includes", ActionUtils.antIncludesList(files, project.getTestSourceDirectory())); // NOI18N + TestSources testSources = findTestSources(context, false); + p.setProperty("javac.includes", ActionUtils.antIncludesList(testSources.sources, testSources.sourceDirectory)); // NOI18N + p.setProperty("test.type", testSources.testType); targetNames = new String[] {"compile-test-single"}; // NOI18N } } else if (command.equals(COMMAND_TEST_SINGLE)) { - p = new Properties(); - FileObject[] files = findTestSourcesForSources(context); - targetNames = setupTestSingle(p, files); + TestSources testSources = findTestSourcesForSources(context); + targetNames = setupTestSingle(p, testSources); } else if (command.equals(COMMAND_DEBUG_TEST_SINGLE)) { - p = new Properties(); - FileObject[] files = findTestSourcesForSources(context); - targetNames = setupDebugTestSingle(p, files); + TestSources testSources = findTestSourcesForSources(context); + targetNames = setupDebugTestSingle(p, testSources); } else if (command.equals(COMMAND_RUN_SINGLE)) { - FileObject[] files = findFunctionalTestSources(context); - if (files != null) { - String path = FileUtil.getRelativePath(project.getFunctionalTestSourceDirectory(), files[0]); - p = new Properties(); - p.setProperty("xtest.testtype", "qa-functional"); // NOI18N - p.setProperty("classname", path.substring(0, path.length() - 5).replace('/', '.')); // NOI18N - targetNames = new String[] {"internal-execution"}; // NOI18N - buildScript = findTestBuildXml(project); - } else if ((files = findPerformanceTestSources(context)) != null) { - String path = FileUtil.getRelativePath(project.getPerformanceTestSourceDirectory(), files[0]); - p = new Properties(); - p.setProperty("xtest.testtype", "qa-performance"); // NOI18N - p.setProperty("classname", path.substring(0, path.length() - 5).replace('/', '.')); // NOI18N - targetNames = new String[] {"internal-execution"}; // NOI18N - buildScript = findTestBuildXml(project); - } else { - files = findTestSources(context, false); - p = new Properties(); - targetNames = setupTestSingle(p, files); - } + TestSources testSources = findTestSources(context, false); + targetNames = setupTestSingle(p, testSources); } else if (command.equals(COMMAND_DEBUG_SINGLE)) { - FileObject[] files = findTestSources(context, false); - p = new Properties(); - targetNames = setupDebugTestSingle(p, files); + TestSources testSources = findTestSources(context, false); + targetNames = setupDebugTestSingle(p, testSources); } else if (command.equals(JavaProjectConstants.COMMAND_DEBUG_FIX)) { FileObject[] files = findSources(context); String path = null; @@ -410,31 +374,26 @@ assert path.endsWith(".java"); targetNames = new String[] {"debug-fix-nb"}; // NOI18N } else { - files = findTestSources(context, false); - path = FileUtil.getRelativePath(project.getTestSourceDirectory(), files[0]); + TestSources testSources = findTestSources(context, false); + path = FileUtil.getRelativePath(testSources.sourceDirectory, testSources.sources[0]); + p.setProperty("test.type", testSources.testType); assert path != null; assert path.endsWith(".java"); targetNames = new String[] {"debug-fix-test-nb"}; // NOI18N } String clazzSlash = path.substring(0, path.length() - 5); - p = new Properties(); p.setProperty("fix.class", clazzSlash); // NOI18N - buildScript = findBuildXml(project); } else if (command.equals(JavaProjectConstants.COMMAND_JAVADOC) && !project.supportsJavadoc()) { promptForPublicPackagesToDocument(); return; } else { - p = null; targetNames = globalCommands.get(command); if (targetNames == null) { throw new IllegalArgumentException(command); } } - if (buildScript == null) { - buildScript = findBuildXml(project); - } try { - ActionUtils.runTarget(buildScript, targetNames, p); + ActionUtils.runTarget(findBuildXml(project), targetNames, p); } catch (IOException e) { Util.err.notify(e); } @@ -469,15 +428,17 @@ DialogDisplayer.getDefault().notify(d); } - private String[] setupTestSingle(Properties p, FileObject[] files) { - p.setProperty("test.includes", ActionUtils.antIncludesList(files, project.getTestSourceDirectory())); // NOI18N + private String[] setupTestSingle(Properties p, TestSources testSources) { + p.setProperty("test.includes", ActionUtils.antIncludesList(testSources.sources, testSources.sourceDirectory)); // NOI18N + p.setProperty("test.type", testSources.testType); // NOI18N return new String[] {"test-single"}; // NOI18N } - private String[] setupDebugTestSingle(Properties p, FileObject[] files) { - String path = FileUtil.getRelativePath(project.getTestSourceDirectory(), files[0]); + private String[] setupDebugTestSingle(Properties p, TestSources testSources) { + String path = FileUtil.getRelativePath(testSources.sourceDirectory, testSources.sources[0]); // Convert foo/FooTest.java -> foo.FooTest p.setProperty("test.class", path.substring(0, path.length() - 5).replace('/', '.')); // NOI18N + p.setProperty("test.type", testSources.testType); // NOI18N return new String[] {"debug-test-single-nb"}; // NOI18N } diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/TestDataDirsNodeFactory.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/TestDataDirsNodeFactory.java new file mode 100644 --- /dev/null +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/TestDataDirsNodeFactory.java @@ -0,0 +1,121 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.apisupport.project.ui; + +import java.util.ArrayList; +import java.util.List; +import javax.swing.event.ChangeListener; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.SourceGroup; +import org.netbeans.modules.apisupport.project.NbModuleProject; +import org.netbeans.spi.project.support.GenericSources; +import org.netbeans.spi.project.ui.support.NodeFactory; +import org.netbeans.spi.project.ui.support.NodeList; +import org.openide.filesystems.FileObject; +import org.openide.loaders.DataObject; +import org.openide.loaders.DataObjectNotFoundException; +import org.openide.nodes.FilterNode; +import org.openide.nodes.Node; +import org.openide.util.NbBundle; + +/** + * Displays data directories. + */ +public class TestDataDirsNodeFactory implements NodeFactory { + + /** public for layer */ + public TestDataDirsNodeFactory() {} + + public NodeList createNodes(Project p) { + NbModuleProject prj = p.getLookup().lookup(NbModuleProject.class); + return new TestDataDirsNL(prj); + } + + private static class TestDataDirsNL implements NodeList { + + private final NbModuleProject project; + + public TestDataDirsNL(NbModuleProject project) { + this.project = project; + } + + public List keys() { + List keys = new ArrayList(); + for (String testType : project.supportedTestTypes()) { + String dataDir = project.evaluator().getProperty("test." + testType + ".data.dir"); + if (dataDir != null) { + FileObject root = project.getHelper().resolveFileObject(dataDir); + if (root != null) { + String displayName = NbBundle.getMessage(TestDataDirsNodeFactory.class, "TestDataDirsNodeFactory." + testType + "_test_data"); + keys.add(GenericSources.group(project, root, testType,displayName, null, null)); + } + } + } + return keys; + } + + public Node node(final SourceGroup key) { + try { + return new FilterNode(DataObject.find(key.getRootFolder()).getNodeDelegate()) { + @Override + public String getName() { + return key.getName(); + } + @Override + public String getDisplayName() { + return key.getDisplayName(); + } + }; + } catch (DataObjectNotFoundException ex) { + throw new AssertionError(ex); + } + } + + public void addChangeListener(ChangeListener l) {} + + public void removeChangeListener(ChangeListener l) {} + + public void addNotify() {} + + public void removeNotify() {} + + } + +} diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/UnitTestLibrariesNode.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/UnitTestLibrariesNode.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/UnitTestLibrariesNode.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/UnitTestLibrariesNode.java @@ -87,7 +87,6 @@ import org.openide.nodes.Children; import org.openide.nodes.FilterNode; import org.openide.nodes.Node; -import org.openide.util.Exceptions; import org.openide.util.HelpCtx; import org.openide.util.Lookup; import org.openide.util.Mutex; @@ -104,18 +103,14 @@ */ final class UnitTestLibrariesNode extends AbstractNode { - static final String UNIT_TEST_LIBRARIES_NAME = "unit libraries"; // NOI18N - - private static final String DISPLAY_NAME = getMessage("LBL_unit_test_libraries"); - private final Action[] actions; - public UnitTestLibrariesNode(final NbModuleProject project) { - super(new LibrariesChildren(project)); - setName(UNIT_TEST_LIBRARIES_NAME); - setDisplayName(DISPLAY_NAME); + public UnitTestLibrariesNode(String testType, final NbModuleProject project) { + super(new LibrariesChildren(testType, project)); + setName(testType); + setDisplayName(getMessage("LBL_" + testType + "_test_libraries")); actions = new Action[] { - new AddUnitTestDependencyAction(project) + new AddUnitTestDependencyAction(testType, project) }; } @@ -156,26 +151,20 @@ } - private static final class LibrariesChildren extends Children.Keys implements AntProjectListener { - - private static final String JUNIT = "junit"; //NOI18N - - private static final String JUNIT_CNB = "org.netbeans.modules.junit"; - - private static final String NBJUNIT = "nbjunit"; //NOI18N - - private static final String NBJUNIT_CNB = "org.netbeans.modules.nbjunit"; + private static final class LibrariesChildren extends Children.Keys implements AntProjectListener { private static final String LIBRARIES_ICON = "org/netbeans/modules/apisupport/project/ui/resources/libraries.gif"; // NOI18N static final Action REMOVE_DEPENDENCY_ACTION = new RemoveDependencyAction(); + private final String testType; private final NbModuleProject project; private ImageIcon librariesIcon; - LibrariesChildren(final NbModuleProject project) { + LibrariesChildren(String testType, final NbModuleProject project) { + this.testType = testType; this.project = project; } @@ -186,7 +175,7 @@ } protected void removeNotify() { - setKeys(Collections.emptySet()); + setKeys(Collections.emptySet()); project.getHelper().removeAntProjectListener(this); super.removeNotify(); } @@ -196,16 +185,10 @@ ProjectManager.mutex().readAccess(new Mutex.ExceptionAction() { public Object run() throws Exception { ProjectXMLManager pxm = new ProjectXMLManager(project); - List keys = new ArrayList(); - if(isModuleInModuleList(JUNIT_CNB)) { - keys.add(JUNIT); - } - if(isModuleInModuleList(NBJUNIT_CNB)) { - keys.add(NBJUNIT); - } + final List keys = new ArrayList(); SortedSet deps = new TreeSet(TestModuleDependency.CNB_COMPARATOR); Set d = pxm.getTestDependencies( - project.getModuleList()).get(TestModuleDependency.UNIT); + project.getModuleList()).get(testType); //draw only compile time deps if(d != null){ for (TestModuleDependency tmd : d) { @@ -224,69 +207,25 @@ } } - private boolean isModuleInModuleList(String cnb){ - ModuleEntry me = null; - boolean result = false; - try { - me = project.getModuleList().getEntry(cnb); - if(me != null) { - File moduleJar = me.getJarLocation(); - result = moduleJar.exists(); - - } - } catch (IOException ex) { - Exceptions.printStackTrace(ex); + protected Node[] createNodes(TestModuleDependency dep) { + Node node = null; + File srcF = dep.getModule().getSourceLocation(); + if (srcF == null) { + File jarF = dep.getModule().getJarLocation(); + URL jarRootURL = FileUtil.urlForArchiveOrDir(jarF); + assert jarRootURL != null; + FileObject root = URLMapper.findFileObject(jarRootURL); + ModuleEntry me = dep.getModule(); + String name = me.getLocalizedName() + " - " + me.getCodeNameBase(); // NOI18N + Icon icon = getLibrariesIcon(); + Node pvNode = ActionFilterNode.create( + PackageView.createPackageView(new LibrariesSourceGroup(root, name, icon, icon))); + node = new LibraryDependencyNode(dep, testType, project, pvNode); + node.setName(me.getLocalizedName()); + } else { + node = new ProjectDependencyNode(dep, testType, project); + node.setName(dep.getModule().getLocalizedName()); } - return result; - } - - - protected Node[] createNodes(Object key) { - Node node = null; - //special nodes - junit, nbjunit - if (JUNIT.equals(key) || NBJUNIT.equals(key)) { - String cnb = null; - if (JUNIT.equals(key)) { - cnb = JUNIT_CNB; - } else { - cnb = NBJUNIT_CNB; - } - try { - ModuleEntry me = project.getModuleList().getEntry(cnb); - Icon icon = getLibrariesIcon(); // TODO a better icon for JUNIT - File junitJar = me.getJarLocation(); - URL junitURL = FileUtil.urlForArchiveOrDir(junitJar); - assert junitURL != null; - FileObject junitFO = URLMapper.findFileObject(junitURL); - String name = me.getLocalizedName(); - node = ActionFilterNode.create( - PackageView.createPackageView(new LibrariesSourceGroup(junitFO, name, icon, icon))); - node.setName(name); //node does not have a name by default - } catch (IOException ex) { - ex.printStackTrace(); - } - } else { - TestModuleDependency dep = (TestModuleDependency) key; - File srcF = dep.getModule().getSourceLocation(); - if (srcF == null) { - File jarF = dep.getModule().getJarLocation(); - URL jarRootURL = FileUtil.urlForArchiveOrDir(jarF); - assert jarRootURL != null; - FileObject root = URLMapper.findFileObject(jarRootURL); - ModuleEntry me = dep.getModule(); - String name = me.getLocalizedName() + " - " + me.getCodeNameBase(); // NOI18N - Icon icon = getLibrariesIcon(); - Node pvNode = ActionFilterNode.create( - PackageView.createPackageView(new LibrariesSourceGroup(root, name, icon, icon))); - node = new LibraryDependencyNode(dep, project, pvNode); - node.setName(me.getLocalizedName()); - } else { - node = new ProjectDependencyNode(dep, project); - node.setName(dep.getModule().getLocalizedName()); - } - - } - assert node != null; return new Node[] { node }; } @@ -316,12 +255,14 @@ private static final class ProjectDependencyNode extends AbstractNode { private final TestModuleDependency dep; + private final String testType; private final NbModuleProject project; private Action[] actions; - ProjectDependencyNode(final TestModuleDependency dep, final NbModuleProject project) { + ProjectDependencyNode(final TestModuleDependency dep, String testType, final NbModuleProject project) { super(Children.LEAF, Lookups.fixed(new Object[] { dep, project, dep.getModule()})); this.dep = dep; + this.testType = testType; this.project = project; ModuleEntry me = dep.getModule(); setIconBaseWithExtension(NbModuleProject.NB_PROJECT_ICON_PATH); @@ -336,7 +277,7 @@ // Open project action result.add(SystemAction.get(LibrariesNode.OpenProjectAction.class)); // Edit dependency action - result.add(new EditTestDependencyAction(dep, project)); + result.add(new EditTestDependencyAction(dep, testType, project)); // Remove dependency result.add(LibrariesChildren.REMOVE_DEPENDENCY_ACTION); actions = result.toArray(new Action[result.size()]); @@ -353,16 +294,19 @@ private static final class LibraryDependencyNode extends FilterNode { private final TestModuleDependency dep; + private final String testType; private final NbModuleProject project; private Action[] actions; LibraryDependencyNode(final TestModuleDependency dep, + String testType, final NbModuleProject project, final Node original) { super(original, null, new ProxyLookup(new Lookup[] { original.getLookup(), Lookups.fixed(new Object[] { dep, project }) })); this.dep = dep; + this.testType = testType; this.project = project; setShortDescription(UnitTestLibrariesNode.createHtmlDescription(dep)); } @@ -370,7 +314,7 @@ public Action[] getActions(boolean context) { if (actions == null) { Set result = new LinkedHashSet(); - result.add(new EditTestDependencyAction(dep, project)); + result.add(new EditTestDependencyAction(dep, testType, project)); Action[] superActions = super.getActions(false); for (int i = 0; i < superActions.length; i++) { if (superActions[i] instanceof FindAction) { @@ -391,10 +335,12 @@ static final class AddUnitTestDependencyAction extends AbstractAction { + private final String testType; private final NbModuleProject project; - AddUnitTestDependencyAction(final NbModuleProject project) { - super(getMessage("CTL_AddTestDependency")); + AddUnitTestDependencyAction(String testType, final NbModuleProject project) { + super(getMessage("CTL_AddTestDependency_" + testType)); + this.testType = testType; this.project = project; } @@ -403,7 +349,7 @@ SingleModuleProperties props = SingleModuleProperties.getInstance(project); final AddModulePanel addPanel = new AddModulePanel(props); final DialogDescriptor descriptor = new DialogDescriptor(addPanel, - getMessage("CTL_AddTestDependency")); + getMessage("CTL_AddTestDependency_" + testType)); descriptor.setHelpCtx(new HelpCtx(AddModulePanel.class)); descriptor.setClosingOptions(new Object[0]); final Dialog d = DialogDisplayer.getDefault().createDialog(descriptor); @@ -425,7 +371,7 @@ try { for (int i = 0; i < newDeps.length; i++) { // by default, add compile-time dependency - pxm.addTestDependency(TestModuleDependency.UNIT + pxm.addTestDependency(testType ,new TestModuleDependency(newDeps[i].getModuleEntry(), false, false, true)); ProjectManager.getDefault().saveProject(project); } @@ -464,7 +410,9 @@ ProjectXMLManager pxm = new ProjectXMLManager(project); //remove dep one by one for (TestModuleDependency rem : me.getValue()) { + // XXX fix - should know what test type it is pxm.removeTestDependency(TestModuleDependency.UNIT, rem.getModule().getCodeNameBase()); + pxm.removeTestDependency(TestModuleDependency.QA_FUNCTIONAL, rem.getModule().getCodeNameBase()); } try { ProjectManager.getDefault().saveProject(project); @@ -503,11 +451,13 @@ static final class EditTestDependencyAction extends AbstractAction { private final TestModuleDependency testDep; + private final String testType; private final NbModuleProject project; - EditTestDependencyAction(final TestModuleDependency testDep, final NbModuleProject project) { + EditTestDependencyAction(final TestModuleDependency testDep, String testType, final NbModuleProject project) { super(getMessage("CTL_EditDependency")); this.testDep = testDep; + this.testType = testType; this.project = project; } @@ -524,9 +474,8 @@ TestModuleDependency editedDep = editTestPanel.getEditedDependency(); try { ProjectXMLManager pxm = new ProjectXMLManager(project); - final String UNIT = TestModuleDependency.UNIT; - pxm.removeTestDependency(UNIT, testDep.getModule().getCodeNameBase()); - pxm.addTestDependency(UNIT, editedDep); + pxm.removeTestDependency(testType, testDep.getModule().getCodeNameBase()); + pxm.addTestDependency(testType, editedDep); ProjectManager.getDefault().saveProject(project); diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/resources/layer.xml b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/resources/layer.xml --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/resources/layer.xml +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/resources/layer.xml @@ -268,6 +268,9 @@ + + + diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/universe/TestEntry.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/universe/TestEntry.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/universe/TestEntry.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/universe/TestEntry.java @@ -60,22 +60,20 @@ public final class TestEntry { private static final String JAR_NAME = "tests.jar"; // NOI18N - private static final String QA_FUNCTIONAL = "qa-functional"; // NOI18N - private static final String UNIT = "unit"; // NOI18N; /** Hardcoded location of testdistribution relatively to nb source root. */ private static final String TEST_DIST_DIR = "nbbuild/build/testdist"; // NOI18N; private final String codeNameBase; - private final boolean unit; + private final String testType; private final String cluster; private final File jarFile; /** * Creates a new instance of TestEntry */ - private TestEntry(File jarFile,String codeNameBase,boolean unit,String cluster) { + private TestEntry(File jarFile, String codeNameBase, String testType, String cluster) { this.jarFile = jarFile; this.codeNameBase = codeNameBase; - this.unit = unit; + this.testType = testType; this.cluster = cluster; } @@ -95,15 +93,7 @@ String cnb = tokens[len - 2].replace('-','.') ; String cluster = tokens[len - 3]; String testType = tokens[len - 4]; - boolean unit = true; - if (!testType.equals(UNIT)) { - if (testType.equals(QA_FUNCTIONAL)) { - unit = false; - } else { - return null; - } - } - return new TestEntry(jarFile,cnb,unit,cluster); + return new TestEntry(jarFile, cnb, testType, cluster); } } return null; @@ -111,10 +101,6 @@ public String getCodeNameBase() { return codeNameBase; - } - - public boolean isUnit() { - return unit; } public String getCluster() { @@ -158,7 +144,7 @@ if (p instanceof NbModuleProject) { NbModuleProject nbm = (NbModuleProject) p; if (nbm != null && nbm.getCodeNameBase().equals(getCodeNameBase())) { - FileObject file = (isUnit()) ? nbm.getTestSourceDirectory() : nbm.getFunctionalTestSourceDirectory(); + FileObject file = nbm.getTestSourceDirectory(testType); if (file != null) { return file.getURL(); } @@ -195,7 +181,7 @@ } public String getTestType() { - return (isUnit()) ? UNIT : QA_FUNCTIONAL; + return testType; } /**