This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 49113
Collapse All | Expand All

(-)ant/freeform/test/unit/src/org/netbeans/modules/ant/freeform/ClasspathsTest.java (-6 / +33 lines)
Lines 18-25 Link Here
18
import java.util.Arrays;
18
import java.util.Arrays;
19
import java.util.Collections;
19
import java.util.Collections;
20
import java.util.HashSet;
20
import java.util.HashSet;
21
import java.util.Iterator;
21
import java.util.List;
22
import java.util.List;
22
import java.util.Set;
23
import java.util.Set;
24
import java.util.TreeSet;
23
import java.util.regex.Matcher;
25
import java.util.regex.Matcher;
24
import java.util.regex.Pattern;
26
import java.util.regex.Pattern;
25
import org.netbeans.api.java.classpath.ClassPath;
27
import org.netbeans.api.java.classpath.ClassPath;
Lines 27-32 Link Here
27
import org.netbeans.spi.project.support.ant.EditableProperties;
29
import org.netbeans.spi.project.support.ant.EditableProperties;
28
import org.openide.filesystems.FileLock;
30
import org.openide.filesystems.FileLock;
29
import org.openide.filesystems.FileObject;
31
import org.openide.filesystems.FileObject;
32
import org.openide.filesystems.FileUtil;
30
33
31
// XXX testClasspathsOfBuildProducts
34
// XXX testClasspathsOfBuildProducts
32
// - should have BOOT and EXECUTE
35
// - should have BOOT and EXECUTE
Lines 85-100 Link Here
85
    }
88
    }
86
    
89
    
87
    public void testExecuteClasspath() throws Exception {
90
    public void testExecuteClasspath() throws Exception {
88
        // For now, just the same as COMPILE.
89
        // XXX should include built-to paths
90
        ClassPath cp = ClassPath.getClassPath(myAppJava, ClassPath.EXECUTE);
91
        ClassPath cp = ClassPath.getClassPath(myAppJava, ClassPath.EXECUTE);
91
        assertNotNull("have some EXECUTE classpath for src/", cp);
92
        assertNotNull("have some EXECUTE classpath for src/", cp);
92
        assertEquals("have two entries in " + cp, 2, cp.getRoots().length);
93
        Set/*<String>*/ roots = new TreeSet();
93
        assertNotNull("found WeakSet in " + cp, cp.findResource("org/openide/util/WeakSet.class"));
94
        roots.add(urlForJar("lib/lib1.jar"));
94
        assertNotNull("found NullInputStream", cp.findResource("org/openide/util/io/NullInputStream.class"));
95
        roots.add(urlForJar("lib/lib2.jar"));
96
        // #49113: includes built-to dirs as well.
97
        roots.add(urlForJar("build/simple-app.jar"));
98
        roots.add(urlForFolder("build/classes"));
99
        assertEquals("right EXECUTE cp for src/", roots.toString(), urlsOfCp(cp).toString());
95
        cp = ClassPath.getClassPath(specialTaskJava, ClassPath.EXECUTE);
100
        cp = ClassPath.getClassPath(specialTaskJava, ClassPath.EXECUTE);
96
        assertNotNull("have some EXECUTE classpath for antsrc/", cp);
101
        assertNotNull("have some EXECUTE classpath for antsrc/", cp);
97
        assertEquals("have one entry", 1, cp.getRoots().length);
102
        // Just check number of entries here... could instead find ${ant.home}/lib/ant.jar.
103
        assertEquals("have two entries (ant.jar + build/antclasses) in " + cp, 2, cp.entries().size());
98
        assertNotNull("found Task", cp.findResource("org/apache/tools/ant/Task.class"));
104
        assertNotNull("found Task", cp.findResource("org/apache/tools/ant/Task.class"));
99
        cp = ClassPath.getClassPath(buildProperties, ClassPath.EXECUTE);
105
        cp = ClassPath.getClassPath(buildProperties, ClassPath.EXECUTE);
100
        assertNull("have no EXECUTE classpath for build.properties", cp);
106
        assertNull("have no EXECUTE classpath for build.properties", cp);
Lines 207-212 Link Here
207
        assertEquals("have one root in " + cp, 1, cp.getRoots().length);
213
        assertEquals("have one root in " + cp, 1, cp.getRoots().length);
208
        assertNotNull("found WeakSet in " + cp, cp.findResource("org/openide/util/WeakSet.class"));
214
        assertNotNull("found WeakSet in " + cp, cp.findResource("org/openide/util/WeakSet.class"));
209
        assertNull("did not find NullInputStream", cp.findResource("org/openide/util/io/NullInputStream.class"));
215
        assertNull("did not find NullInputStream", cp.findResource("org/openide/util/io/NullInputStream.class"));
216
    }
217
218
    // Copied from org.netbeans.modules.apisupport.project.ClassPathProviderImplTest:
219
    private String urlForJar(String path) throws Exception {
220
        return FileUtil.getArchiveRoot(simple.helper().resolveFile(path).toURI().toURL()).toExternalForm();
221
    }
222
    private String urlForFolder(String path) throws Exception {
223
        String s = simple.helper().resolveFile(path).toURI().toURL().toExternalForm();
224
        if (s.endsWith("/")) {
225
            return s;
226
        } else {
227
            return s + "/";
228
        }
229
    }
230
    private Set/*<String>*/ urlsOfCp(ClassPath cp) {
231
        Set/*<String>*/ s = new TreeSet();
232
        Iterator it = cp.entries().iterator();
233
        while (it.hasNext()) {
234
            s.add(((ClassPath.Entry) it.next()).getURL().toExternalForm());
235
        }
236
        return s;
210
    }
237
    }
211
    
238
    
212
}
239
}
(-)ant/freeform/src/org/netbeans/modules/ant/freeform/Classpaths.java (-25 / +51 lines)
Lines 355-386 Link Here
355
        String[] path = PropertyUtils.tokenizePath(cpEval);
355
        String[] path = PropertyUtils.tokenizePath(cpEval);
356
        URL[] pathURL = new URL[path.length];
356
        URL[] pathURL = new URL[path.length];
357
        for (int i = 0; i < path.length; i++) {
357
        for (int i = 0; i < path.length; i++) {
358
            File entryFile = project.helper().resolveFile(path[i]);
358
            pathURL[i] = createClasspathEntry(path[i]);
359
            URL entry;
359
        }
360
            try {
360
        return Arrays.asList(pathURL);
361
                entry = entryFile.toURI().toURL();
361
    }
362
            } catch (MalformedURLException x) {
362
    
363
                throw new AssertionError(x);
363
    private URL createClasspathEntry(String text) {
364
            }
364
        File entryFile = project.helper().resolveFile(text);
365
            if (FileUtil.isArchiveFile(entry)) {
365
        URL entry;
366
                entry = FileUtil.getArchiveRoot(entry);
366
        try {
367
            } else {
367
            entry = entryFile.toURI().toURL();
368
                String entryS = entry.toExternalForm();
368
        } catch (MalformedURLException x) {
369
                if (!entryS.endsWith("/")) { // NOI18N
369
            throw new AssertionError(x);
370
                    // A nonexistent dir. Have to add trailing slash ourselves.
370
        }
371
                    try {
371
        if (FileUtil.isArchiveFile(entry)) {
372
                        entry = new URL(entryS + '/');
372
            return FileUtil.getArchiveRoot(entry);
373
                    } catch (MalformedURLException x) {
373
        } else {
374
                        throw new AssertionError(x);
374
            String entryS = entry.toExternalForm();
375
                    }
375
            if (!entryS.endsWith("/")) { // NOI18N
376
                // A nonexistent dir. Have to add trailing slash ourselves.
377
                try {
378
                    return new URL(entryS + '/');
379
                } catch (MalformedURLException x) {
380
                    throw new AssertionError(x);
376
                }
381
                }
382
            } else {
383
                return entry;
377
            }
384
            }
378
            pathURL[i] = entry;
379
        }
385
        }
380
        return Arrays.asList(pathURL);
381
    }
386
    }
382
    
387
    
383
    private List/*<URL>*/ createExecuteClasspath(Element compilationUnitEl) {
388
    private List/*<URL>*/ createExecuteClasspath(List/*<String>*/ packageRoots, Element compilationUnitEl) {
384
        Iterator/*<Element>*/ it = Util.findSubElements(compilationUnitEl).iterator();
389
        Iterator/*<Element>*/ it = Util.findSubElements(compilationUnitEl).iterator();
385
        while (it.hasNext()) {
390
        while (it.hasNext()) {
386
            Element e = (Element)it.next();
391
            Element e = (Element)it.next();
Lines 388-396 Link Here
388
                return createClasspath(e);
393
                return createClasspath(e);
389
            }
394
            }
390
        }
395
        }
391
        // None specified; assume it is same as compile classpath.
396
        // None specified; assume it is same as compile classpath plus (cf. #49113) <built-to> dirs/JARs
392
        // XXX but add built-to dirs
397
        // if there are any (else include the source dir(s) as a fallback for the I18N wizard to work).
393
        return createCompileClasspath(compilationUnitEl);
398
        List/*<URL>*/ urls = new ArrayList();
399
        urls.addAll(createCompileClasspath(compilationUnitEl));
400
        boolean foundBuiltTos = false;
401
        Iterator/*<Element>*/ builtTos = Util.findSubElements(compilationUnitEl).iterator();
402
        while (builtTos.hasNext()) {
403
            Element builtTo = (Element) builtTos.next();
404
            if (!builtTo.getLocalName().equals("built-to")) { // NOI18N
405
                continue;
406
            }
407
            foundBuiltTos = true;
408
            String rawtext = Util.findText(builtTo);
409
            assert rawtext != null : "Must have nonempty text inside <built-to>";
410
            String text = project.evaluator().evaluate(rawtext);
411
            if (text == null) {
412
                continue;
413
            }
414
            urls.add(createClasspathEntry(text));
415
        }
416
        if (!foundBuiltTos) {
417
            urls.addAll(createSourcePath(packageRoots));
418
        }
419
        return urls;
394
    }
420
    }
395
    
421
    
396
    private List/*<URL>*/ createBootClasspath(Element compilationUnitEl) {
422
    private List/*<URL>*/ createBootClasspath(Element compilationUnitEl) {
Lines 515-521 Link Here
515
            } else if (type.equals(ClassPath.COMPILE)) {
541
            } else if (type.equals(ClassPath.COMPILE)) {
516
                roots = createCompileClasspath(compilationUnitEl);
542
                roots = createCompileClasspath(compilationUnitEl);
517
            } else if (type.equals(ClassPath.EXECUTE)) {
543
            } else if (type.equals(ClassPath.EXECUTE)) {
518
                roots = createExecuteClasspath(compilationUnitEl);
544
                roots = createExecuteClasspath(packageRootNames, compilationUnitEl);
519
            } else {
545
            } else {
520
                assert type.equals(ClassPath.BOOT) : type;
546
                assert type.equals(ClassPath.BOOT) : type;
521
                roots = createBootClasspath(compilationUnitEl);
547
                roots = createBootClasspath(compilationUnitEl);

Return to bug 49113