Index: ant/freeform/test/unit/src/org/netbeans/modules/ant/freeform/ClasspathsTest.java =================================================================== RCS file: /cvs/ant/freeform/test/unit/src/org/netbeans/modules/ant/freeform/ClasspathsTest.java,v retrieving revision 1.9 diff -u -r1.9 ClasspathsTest.java --- ant/freeform/test/unit/src/org/netbeans/modules/ant/freeform/ClasspathsTest.java 12 Aug 2004 04:56:52 -0000 1.9 +++ ant/freeform/test/unit/src/org/netbeans/modules/ant/freeform/ClasspathsTest.java 16 Sep 2004 18:48:51 -0000 @@ -18,8 +18,10 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Set; +import java.util.TreeSet; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.netbeans.api.java.classpath.ClassPath; @@ -27,6 +29,7 @@ import org.netbeans.spi.project.support.ant.EditableProperties; import org.openide.filesystems.FileLock; import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; // XXX testClasspathsOfBuildProducts // - should have BOOT and EXECUTE @@ -85,16 +88,19 @@ } public void testExecuteClasspath() throws Exception { - // For now, just the same as COMPILE. - // XXX should include built-to paths ClassPath cp = ClassPath.getClassPath(myAppJava, ClassPath.EXECUTE); assertNotNull("have some EXECUTE classpath for src/", cp); - assertEquals("have two entries in " + cp, 2, cp.getRoots().length); - assertNotNull("found WeakSet in " + cp, cp.findResource("org/openide/util/WeakSet.class")); - assertNotNull("found NullInputStream", cp.findResource("org/openide/util/io/NullInputStream.class")); + Set/**/ roots = new TreeSet(); + roots.add(urlForJar("lib/lib1.jar")); + roots.add(urlForJar("lib/lib2.jar")); + // #49113: includes built-to dirs as well. + roots.add(urlForJar("build/simple-app.jar")); + roots.add(urlForFolder("build/classes")); + assertEquals("right EXECUTE cp for src/", roots.toString(), urlsOfCp(cp).toString()); cp = ClassPath.getClassPath(specialTaskJava, ClassPath.EXECUTE); assertNotNull("have some EXECUTE classpath for antsrc/", cp); - assertEquals("have one entry", 1, cp.getRoots().length); + // Just check number of entries here... could instead find ${ant.home}/lib/ant.jar. + assertEquals("have two entries (ant.jar + build/antclasses) in " + cp, 2, cp.entries().size()); assertNotNull("found Task", cp.findResource("org/apache/tools/ant/Task.class")); cp = ClassPath.getClassPath(buildProperties, ClassPath.EXECUTE); assertNull("have no EXECUTE classpath for build.properties", cp); @@ -207,6 +213,27 @@ assertEquals("have one root in " + cp, 1, cp.getRoots().length); assertNotNull("found WeakSet in " + cp, cp.findResource("org/openide/util/WeakSet.class")); assertNull("did not find NullInputStream", cp.findResource("org/openide/util/io/NullInputStream.class")); + } + + // Copied from org.netbeans.modules.apisupport.project.ClassPathProviderImplTest: + private String urlForJar(String path) throws Exception { + return FileUtil.getArchiveRoot(simple.helper().resolveFile(path).toURI().toURL()).toExternalForm(); + } + private String urlForFolder(String path) throws Exception { + String s = simple.helper().resolveFile(path).toURI().toURL().toExternalForm(); + if (s.endsWith("/")) { + return s; + } else { + return s + "/"; + } + } + private Set/**/ urlsOfCp(ClassPath cp) { + Set/**/ s = new TreeSet(); + Iterator it = cp.entries().iterator(); + while (it.hasNext()) { + s.add(((ClassPath.Entry) it.next()).getURL().toExternalForm()); + } + return s; } } Index: ant/freeform/src/org/netbeans/modules/ant/freeform/Classpaths.java =================================================================== RCS file: /cvs/ant/freeform/src/org/netbeans/modules/ant/freeform/Classpaths.java,v retrieving revision 1.9 diff -u -r1.9 Classpaths.java --- ant/freeform/src/org/netbeans/modules/ant/freeform/Classpaths.java 12 Aug 2004 04:56:52 -0000 1.9 +++ ant/freeform/src/org/netbeans/modules/ant/freeform/Classpaths.java 16 Sep 2004 18:48:51 -0000 @@ -355,32 +355,37 @@ String[] path = PropertyUtils.tokenizePath(cpEval); URL[] pathURL = new URL[path.length]; for (int i = 0; i < path.length; i++) { - File entryFile = project.helper().resolveFile(path[i]); - URL entry; - try { - entry = entryFile.toURI().toURL(); - } catch (MalformedURLException x) { - throw new AssertionError(x); - } - if (FileUtil.isArchiveFile(entry)) { - entry = FileUtil.getArchiveRoot(entry); - } else { - String entryS = entry.toExternalForm(); - if (!entryS.endsWith("/")) { // NOI18N - // A nonexistent dir. Have to add trailing slash ourselves. - try { - entry = new URL(entryS + '/'); - } catch (MalformedURLException x) { - throw new AssertionError(x); - } + pathURL[i] = createClasspathEntry(path[i]); + } + return Arrays.asList(pathURL); + } + + private URL createClasspathEntry(String text) { + File entryFile = project.helper().resolveFile(text); + URL entry; + try { + entry = entryFile.toURI().toURL(); + } catch (MalformedURLException x) { + throw new AssertionError(x); + } + if (FileUtil.isArchiveFile(entry)) { + return FileUtil.getArchiveRoot(entry); + } else { + String entryS = entry.toExternalForm(); + if (!entryS.endsWith("/")) { // NOI18N + // A nonexistent dir. Have to add trailing slash ourselves. + try { + return new URL(entryS + '/'); + } catch (MalformedURLException x) { + throw new AssertionError(x); } + } else { + return entry; } - pathURL[i] = entry; } - return Arrays.asList(pathURL); } - private List/**/ createExecuteClasspath(Element compilationUnitEl) { + private List/**/ createExecuteClasspath(List/**/ packageRoots, Element compilationUnitEl) { Iterator/**/ it = Util.findSubElements(compilationUnitEl).iterator(); while (it.hasNext()) { Element e = (Element)it.next(); @@ -388,9 +393,30 @@ return createClasspath(e); } } - // None specified; assume it is same as compile classpath. - // XXX but add built-to dirs - return createCompileClasspath(compilationUnitEl); + // None specified; assume it is same as compile classpath plus (cf. #49113) dirs/JARs + // if there are any (else include the source dir(s) as a fallback for the I18N wizard to work). + List/**/ urls = new ArrayList(); + urls.addAll(createCompileClasspath(compilationUnitEl)); + boolean foundBuiltTos = false; + Iterator/**/ builtTos = Util.findSubElements(compilationUnitEl).iterator(); + while (builtTos.hasNext()) { + Element builtTo = (Element) builtTos.next(); + if (!builtTo.getLocalName().equals("built-to")) { // NOI18N + continue; + } + foundBuiltTos = true; + String rawtext = Util.findText(builtTo); + assert rawtext != null : "Must have nonempty text inside "; + String text = project.evaluator().evaluate(rawtext); + if (text == null) { + continue; + } + urls.add(createClasspathEntry(text)); + } + if (!foundBuiltTos) { + urls.addAll(createSourcePath(packageRoots)); + } + return urls; } private List/**/ createBootClasspath(Element compilationUnitEl) { @@ -515,7 +541,7 @@ } else if (type.equals(ClassPath.COMPILE)) { roots = createCompileClasspath(compilationUnitEl); } else if (type.equals(ClassPath.EXECUTE)) { - roots = createExecuteClasspath(compilationUnitEl); + roots = createExecuteClasspath(packageRootNames, compilationUnitEl); } else { assert type.equals(ClassPath.BOOT) : type; roots = createBootClasspath(compilationUnitEl);