Search in sources :

Example 36 with Path

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

the class DefaultCompilerAdapterTest method testSingleModuleCompilation.

@Test
public void testSingleModuleCompilation() throws IOException {
    final File workDir = createWorkDir("testSMC");
    try {
        final File src = new File(workDir, "src");
        src.mkdir();
        final File java1 = createFile(src, "org/apache/ant/tests/J1.java");
        final File java2 = createFile(src, "org/apache/ant/tests/J2.java");
        final File modules = new File(workDir, "modules");
        modules.mkdir();
        final Project prj = new Project();
        prj.setBaseDir(workDir);
        final LogCapturingJavac javac = new LogCapturingJavac();
        javac.setProject(prj);
        final Commandline[] cmd = new Commandline[1];
        final DefaultCompilerAdapter impl = new DefaultCompilerAdapter() {

            @Override
            public boolean execute() throws BuildException {
                cmd[0] = setupModernJavacCommand();
                return true;
            }
        };
        final Path srcPath = new Path(prj);
        srcPath.setLocation(src);
        javac.setSrcdir(srcPath);
        javac.createModulepath().setLocation(modules);
        javac.setSource("9");
        javac.setTarget("9");
        javac.setIncludeantruntime(false);
        javac.add(impl);
        javac.execute();
        assertNotNull(cmd[0]);
        final List<String> cmdLine = Arrays.asList(cmd[0].getCommandline());
        // No modulesourcepath
        assertEquals(-1, cmdLine.indexOf("--module-source-path"));
        // The -sourcepath has to be followed by src
        int index = cmdLine.indexOf("-sourcepath");
        assertTrue(index != -1 && index < cmdLine.size() - 1);
        assertEquals(src.getAbsolutePath(), cmdLine.get(index + 1));
        // The --module-path has to be followed by modules
        index = cmdLine.indexOf("--module-path");
        assertTrue(index != -1 && index < cmdLine.size() - 1);
        assertEquals(modules.getAbsolutePath(), cmdLine.get(index + 1));
        // J1.java & J2.java has to be in files list
        final Set<String> expected = new TreeSet<String>();
        Collections.addAll(expected, java1.getAbsolutePath(), java2.getAbsolutePath());
        final Set<String> actual = new TreeSet<String>(cmdLine.subList(cmdLine.size() - 2, cmdLine.size()));
        assertEquals(expected, actual);
    } finally {
        delete(workDir);
    }
}
Also used : Path(org.apache.tools.ant.types.Path) Project(org.apache.tools.ant.Project) Commandline(org.apache.tools.ant.types.Commandline) TreeSet(java.util.TreeSet) File(java.io.File) Test(org.junit.Test)

Example 37 with Path

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

the class DefaultCompilerAdapterTest method releaseIsIgnoredForJava8.

@Test
public void releaseIsIgnoredForJava8() {
    LogCapturingJavac javac = new LogCapturingJavac();
    Project p = new Project();
    javac.setProject(p);
    javac.setCompiler("javac8");
    javac.setSource("6");
    javac.setTarget("6");
    javac.setRelease("6");
    javac.setSourcepath(new Path(p));
    SourceTargetHelperNoOverride sth = new SourceTargetHelperNoOverride();
    sth.setJavac(javac);
    Commandline cmd = new Commandline();
    sth.setupModernJavacCommandlineSwitches(cmd);
    assertContains("Support for javac --release has been added in " + "Java9 ignoring it", javac.getLog());
    String[] args = cmd.getCommandline();
    assertEquals(7, args.length);
    assertEquals("-classpath", args[0]);
    assertEquals("-target", args[2]);
    assertEquals("6", args[3]);
    assertEquals("-g:none", args[4]);
    assertEquals("-source", args[5]);
    assertEquals("6", args[6]);
}
Also used : Path(org.apache.tools.ant.types.Path) Project(org.apache.tools.ant.Project) Commandline(org.apache.tools.ant.types.Commandline) Test(org.junit.Test)

Example 38 with Path

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

the class Concat method createPath.

// Nested element creators.
/**
 * Path of files to concatenate.
 * @return the path used for concatenating
 * @since Ant 1.6
 */
public Path createPath() {
    Path path = new Path(getProject());
    add(path);
    return path;
}
Also used : Path(org.apache.tools.ant.types.Path)

Example 39 with Path

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

the class ModifiedSelectorTest method setUp.

// =====================  JUnit stuff  =====================
@Before
public void setUp() {
    // init the testclasses path object
    Project prj = selectorRule.getProject();
    testclasses = new Path(prj, prj.getProperty("build.tests.value"));
}
Also used : Path(org.apache.tools.ant.types.Path) Project(org.apache.tools.ant.Project) Before(org.junit.Before)

Example 40 with Path

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

the class SOSTest method testCheckinFileFlags.

/**
 *  Test CheckInFile option flags
 */
@Test
public void testCheckinFileFlags() {
    String[] sTestCmdLine = { "soscmd", "-command", "CheckInFile", "-file", SRC_FILE, "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME, "-password", SOS_PASSWORD, "-database", VSS_SERVER_PATH, "-project", DS_VSS_PROJECT_PATH, "-verbose", "-nocompress", "-nocache", "-workdir", project.getBaseDir().getAbsolutePath() + File.separator + LOCAL_PATH, "-log", SRC_COMMENT };
    // Set up a SOSCheckin task
    SOSCheckin sosCheckin = new SOSCheckin();
    sosCheckin.setProject(project);
    sosCheckin.setVssServerPath(VSS_SERVER_PATH);
    sosCheckin.setSosServerPath(SOS_SERVER_PATH);
    sosCheckin.setProjectPath(VSS_PROJECT_PATH);
    sosCheckin.setFile(SRC_FILE);
    sosCheckin.setComment(SRC_COMMENT);
    sosCheckin.setUsername(SOS_USERNAME);
    sosCheckin.setPassword(SOS_PASSWORD);
    sosCheckin.setLocalPath(new Path(project, LOCAL_PATH));
    sosCheckin.setNoCache(true);
    sosCheckin.setNoCompress(true);
    sosCheckin.setVerbose(true);
    sosCheckin.setRecursive(true);
    commandline = sosCheckin.buildCmdLine();
    checkCommandLines(sTestCmdLine, commandline.getCommandline());
}
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