|
What this is
Other links
The source code
/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.ant.freeform;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.netbeans.api.java.classpath.ClassPath;
import org.netbeans.api.java.classpath.GlobalPathRegistry;
import org.netbeans.spi.project.support.ant.EditableProperties;
import org.openide.filesystems.FileLock;
import org.openide.filesystems.FileObject;
// XXX testClasspathsOfBuildProducts
// - should have BOOT and EXECUTE
// XXX testBootClasspathChanges
// - check that after e.g. changing plain source level, new JDK picked
// XXX testSourcepathChanges
// - check that after adding/removing a source root to a given compilation unit, SOURCE changes to match
// (but can this really work generally? what if a single compilation unit is split in half??)
// XXX testIgnoredRoot
// - check that after removing a compilation unit, ClassPath.gCP returns null again, and the ClassPath object is invalidated
// XXX testRegisterDeregisterAfterChanges
// - check that after changing set of compilation units, new/removed classpaths are added to or removed from list in GPR
// XXX testNonexistentEntries
// - check that correct URL (ending in '/') picked for dirs (not JARs) in CP that do not yet exist
// and that for nonexistent JARs ('.' in simple name) the correct jar: protocol URL is used
/**
* Test functionality of classpath definitions in FreeformProject.
* This class just tests the basic functionality found in the "simple" project.
* @author Jesse Glick
*/
public class ClasspathsTest extends TestBase {
public ClasspathsTest(String name) {
super(name);
}
public void testSourcePath() throws Exception {
ClassPath cp = ClassPath.getClassPath(myAppJava, ClassPath.SOURCE);
assertNotNull("have some SOURCE classpath for src/", cp);
FileObject[] roots = cp.getRoots();
assertEquals("have one entry in " + cp, 1, roots.length);
assertEquals("that is src/", simple.getProjectDirectory().getFileObject("src"), roots[0]);
cp = ClassPath.getClassPath(specialTaskJava, ClassPath.SOURCE);
assertNotNull("have some SOURCE classpath for antsrc/", cp);
roots = cp.getRoots();
assertEquals("have one entry", 1, roots.length);
assertEquals("that is antsrc/", simple.getProjectDirectory().getFileObject("antsrc"), roots[0]);
cp = ClassPath.getClassPath(buildProperties, ClassPath.SOURCE);
assertNull("have no SOURCE classpath for build.properties", cp);
}
public void testCompileClasspath() throws Exception {
ClassPath cp = ClassPath.getClassPath(myAppJava, ClassPath.COMPILE);
assertNotNull("have some COMPILE classpath for src/", cp);
assertEquals("have two entries in " + cp, 2, cp.entries().size());
assertEquals("have two roots 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"));
cp = ClassPath.getClassPath(specialTaskJava, ClassPath.COMPILE);
assertNotNull("have some COMPILE classpath for antsrc/", cp);
assertEquals("have one entry", 1, cp.getRoots().length);
assertNotNull("found Task", cp.findResource("org/apache/tools/ant/Task.class"));
cp = ClassPath.getClassPath(buildProperties, ClassPath.COMPILE);
assertNull("have no COMPILE classpath for build.properties", cp);
}
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"));
cp = ClassPath.getClassPath(specialTaskJava, ClassPath.EXECUTE);
assertNotNull("have some EXECUTE classpath for antsrc/", cp);
assertEquals("have one entry", 1, cp.getRoots().length);
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);
}
public void testBootClasspath() throws Exception {
ClassPath cp = ClassPath.getClassPath(myAppJava, ClassPath.BOOT);
assertNotNull("have some BOOT classpath for src/", cp);
assertEquals("and it is JDK 1.4", "1.4", specOfBootClasspath(cp));
ClassPath cp2 = ClassPath.getClassPath(specialTaskJava, ClassPath.BOOT);
assertNotNull("have some BOOT classpath for antsrc/", cp2);
assertEquals("and it is JDK 1.4", "1.4", specOfBootClasspath(cp2));
/* Not actually required:
assertEquals("same BOOT classpath for all files (since use same spec level)", cp, cp2);
*/
cp = ClassPath.getClassPath(buildProperties, ClassPath.BOOT);
assertNull("have no BOOT classpath for build.properties", cp);
}
private static String specOfBootClasspath(ClassPath cp) {
List/*
|
Copyright 1998-2008 Alvin Alexander
All Rights Reserved.
devdaily.com is based in louisville, kentucky, and this web site is hosted by godaddy.com