Search in sources :

Example 16 with Path

use of org.apache.tools.ant.types.Path in project ant by apache.

the class JavacTest method testModulesourcepathAndSrcDirForbidden.

@Test(expected = BuildException.class)
public void testModulesourcepathAndSrcDirForbidden() {
    javac.checkParameters();
    final Path p = new Path(project);
    p.setPath("src");
    javac.setSrcdir(p);
    final Path mp = new Path(project);
    p.setPath("modsrc");
    javac.setModulesourcepath(mp);
}
Also used : Path(org.apache.tools.ant.types.Path) Test(org.junit.Test)

Example 17 with Path

use of org.apache.tools.ant.types.Path in project ant by apache.

the class JavacTest method testSrcDir.

@Test
public void testSrcDir() {
    final Path p = new Path(project);
    p.setPath("src");
    javac.setSrcdir(p);
    javac.checkParameters();
}
Also used : Path(org.apache.tools.ant.types.Path) Test(org.junit.Test)

Example 18 with Path

use of org.apache.tools.ant.types.Path in project ant by apache.

the class AntClassLoaderTest method testInvalidZipException.

/**
 * @see <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=47593">
 *     bug 47593, request to log the name of corrupt zip files from which
 *     classes cannot be loaded</a>
 */
@Test
public void testInvalidZipException() {
    buildRule.executeTarget("createNonJar");
    File jar = new File(buildRule.getProject().getProperty("tmp.dir") + "/foo.jar");
    Path myPath = new Path(buildRule.getProject());
    myPath.setLocation(jar);
    buildRule.getProject().setUserProperty("build.sysclasspath", "ignore");
    loader = buildRule.getProject().createClassLoader(myPath);
    PrintStream sysErr = System.err;
    try {
        StringBuffer errBuffer = new StringBuffer();
        PrintStream err = new PrintStream(new BuildFileRule.AntOutputStream(errBuffer));
        System.setErr(err);
        loader.getResource("foo.txt");
        String log = buildRule.getLog();
        int startMessage = log.indexOf("CLASSPATH element ");
        assertTrue(startMessage >= 0);
        assertTrue(log.indexOf("foo.jar is not a JAR", startMessage) > 0);
    } finally {
        System.setErr(sysErr);
    }
}
Also used : Path(org.apache.tools.ant.types.Path) PrintStream(java.io.PrintStream) File(java.io.File) Test(org.junit.Test)

Example 19 with Path

use of org.apache.tools.ant.types.Path in project ant by apache.

the class AntClassLoaderTest method testGetResourcesUsingFactory.

@Test
public void testGetResourcesUsingFactory() throws IOException {
    AntClassLoader acl = AntClassLoader.newAntClassLoader(new EmptyLoader(), null, new Path(null), true);
    assertNull(acl.getResource("META-INF/MANIFEST.MF"));
    assertFalse(acl.getResources("META-INF/MANIFEST.MF").hasMoreElements());
}
Also used : Path(org.apache.tools.ant.types.Path) Test(org.junit.Test)

Example 20 with Path

use of org.apache.tools.ant.types.Path in project ant by apache.

the class AntClassLoaderTest method testGetResources.

/**
 * Asserts that getResources won't return resources that cannot be
 * seen by AntClassLoader but by ClassLoader.this.parent.
 *
 * @see <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=46752">
 *     https://issues.apache.org/bugzilla/show_bug.cgi?id=46752</a>
 */
@SuppressWarnings("resource")
@Test
public void testGetResources() throws IOException {
    AntClassLoader acl = new AntClassLoader(new EmptyLoader(), null, new Path(null), true);
    assertNull(acl.getResource("META-INF/MANIFEST.MF"));
    assertFalse(acl.getResources("META-INF/MANIFEST.MF").hasMoreElements());
    // double check using system classloader as parent
    acl = new AntClassLoader(null, null, new Path(null), true);
    assertNotNull(acl.getResource("META-INF/MANIFEST.MF"));
    assertTrue(acl.getResources("META-INF/MANIFEST.MF").hasMoreElements());
}
Also used : Path(org.apache.tools.ant.types.Path) Test(org.junit.Test)

Aggregations

Path (org.apache.tools.ant.types.Path)174 File (java.io.File)78 BuildException (org.apache.tools.ant.BuildException)55 Test (org.junit.Test)49 Project (org.apache.tools.ant.Project)28 IOException (java.io.IOException)24 Commandline (org.apache.tools.ant.types.Commandline)21 ArrayList (java.util.ArrayList)12 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)10 URL (java.net.URL)8 AntClassLoader (org.apache.tools.ant.AntClassLoader)7 Java (org.apache.tools.ant.taskdefs.Java)7 StringTokenizer (java.util.StringTokenizer)6 FileSet (org.apache.tools.ant.types.FileSet)6 Reference (org.apache.tools.ant.types.Reference)6 Resource (org.apache.tools.ant.types.Resource)6 Test (org.junit.jupiter.api.Test)6 GroovyClassLoader (groovy.lang.GroovyClassLoader)5 Enumeration (java.util.Enumeration)5 Vector (java.util.Vector)5