Search in sources :

Example 31 with Path

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

the class DefaultRmicAdapter method setupRmicCommand.

/**
 * Setup rmic argument for rmic.
 * @param options additional parameters needed by a specific
 *                implementation.
 * @return the command line
 */
protected Commandline setupRmicCommand(String[] options) {
    Commandline cmd = new Commandline();
    if (options != null) {
        for (String option : options) {
            cmd.createArgument().setValue(option);
        }
    }
    Path classpath = getCompileClasspath();
    cmd.createArgument().setValue("-d");
    cmd.createArgument().setFile(attributes.getOutputDir());
    if (attributes.getExtdirs() != null) {
        cmd.createArgument().setValue("-extdirs");
        cmd.createArgument().setPath(attributes.getExtdirs());
    }
    cmd.createArgument().setValue("-classpath");
    cmd.createArgument().setPath(classpath);
    String stubOption = addStubVersionOptions();
    if (stubOption != null) {
        // set the non-null stubOption
        cmd.createArgument().setValue(stubOption);
    }
    if (null != attributes.getSourceBase()) {
        cmd.createArgument().setValue("-keepgenerated");
    }
    if (attributes.getIiop()) {
        if (!areIiopAndIdlSupported()) {
            throw new BuildException("this rmic implementation doesn't support the -iiop switch");
        }
        attributes.log("IIOP has been turned on.", Project.MSG_INFO);
        cmd.createArgument().setValue("-iiop");
        if (attributes.getIiopopts() != null) {
            attributes.log("IIOP Options: " + attributes.getIiopopts(), Project.MSG_INFO);
            cmd.createArgument().setValue(attributes.getIiopopts());
        }
    }
    if (attributes.getIdl()) {
        if (!areIiopAndIdlSupported()) {
            throw new BuildException("this rmic implementation doesn't support the -idl switch");
        }
        cmd.createArgument().setValue("-idl");
        attributes.log("IDL has been turned on.", Project.MSG_INFO);
        if (attributes.getIdlopts() != null) {
            cmd.createArgument().setValue(attributes.getIdlopts());
            attributes.log("IDL Options: " + attributes.getIdlopts(), Project.MSG_INFO);
        }
    }
    if (attributes.getDebug()) {
        cmd.createArgument().setValue("-g");
    }
    String[] compilerArgs = attributes.getCurrentCompilerArgs();
    compilerArgs = preprocessCompilerArgs(compilerArgs);
    cmd.addArguments(compilerArgs);
    verifyArguments(cmd);
    logAndAddFilesToCompile(cmd);
    return cmd;
}
Also used : Path(org.apache.tools.ant.types.Path) Commandline(org.apache.tools.ant.types.Commandline) BuildException(org.apache.tools.ant.BuildException)

Example 32 with Path

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

the class JUnitTaskTest method testModulePathNeedsFork.

@Test(expected = BuildException.class)
public void testModulePathNeedsFork() throws Exception {
    final Project project = new Project();
    project.init();
    JUnitTask task = new JUnitTask();
    task.setProject(project);
    final Path p = new Path(project);
    p.setPath("modules");
    task.createModulepath().add(p);
    task.addTest(new JUnitTest("org.apache.tools.ant.taskdefs.optional.junit.TestTest"));
    task.execute();
}
Also used : XPath(javax.xml.xpath.XPath) Path(org.apache.tools.ant.types.Path) Project(org.apache.tools.ant.Project) Test(org.junit.Test)

Example 33 with Path

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

the class JUnitTaskTest method testUpgradeModulePathNeedsFork.

@Test(expected = BuildException.class)
public void testUpgradeModulePathNeedsFork() throws Exception {
    final Project project = new Project();
    project.init();
    JUnitTask task = new JUnitTask();
    task.setProject(project);
    final Path p = new Path(project);
    p.setPath("modules");
    task.createUpgrademodulepath().add(p);
    task.addTest(new JUnitTest("org.apache.tools.ant.taskdefs.optional.junit.TestTest"));
    task.execute();
}
Also used : XPath(javax.xml.xpath.XPath) Path(org.apache.tools.ant.types.Path) Project(org.apache.tools.ant.Project) Test(org.junit.Test)

Example 34 with Path

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

the class XmlPropertyTest method ensureProperties.

/**
 * Make sure every property loaded from the goldfile was also
 * read from the XmlProperty.  We could try and test the other way,
 * but some other properties may get set in the XmlProperty due
 * to generic Project/Task configuration.
 */
private static void ensureProperties(String msg, File inputFile, File workingDir, Project p, Properties properties) {
    Hashtable xmlproperties = p.getProperties();
    // Every key identified by the Properties must have been loaded.
    Enumeration<?> propertyKeyEnum = properties.propertyNames();
    while (propertyKeyEnum.hasMoreElements()) {
        String currentKey = propertyKeyEnum.nextElement().toString();
        String assertMsg = msg + "-" + inputFile.getName() + " Key=" + currentKey;
        String propertyValue = properties.getProperty(currentKey);
        String xmlValue = (String) xmlproperties.get(currentKey);
        if (propertyValue.startsWith("ID.")) {
            // The property is an id's thing -- either a property
            // or a path.  We need to make sure
            // that the object was created with the given id.
            // We don't have an adequate way of testing the actual
            // *value* of the Path object, though...
            Object obj = p.getReferences().get(currentKey);
            if (obj == null) {
                fail(assertMsg + " Object ID does not exist.");
            }
            // What is the property supposed to be?
            propertyValue = propertyValue.substring(3, propertyValue.length());
            if (propertyValue.equals("path")) {
                if (!(obj instanceof Path)) {
                    fail(assertMsg + " Path ID is a " + obj.getClass().getName());
                }
            } else {
                assertEquals(assertMsg, propertyValue, obj.toString());
            }
        } else {
            if (propertyValue.startsWith("FILE.")) {
                // The property is the name of a file.  We are testing
                // a location attribute, so we need to resolve the given
                // file name in the provided folder.
                String fileName = propertyValue.substring(5, propertyValue.length());
                File f = new File(workingDir, fileName);
                propertyValue = f.getAbsolutePath();
            }
            assertEquals(assertMsg, propertyValue, xmlValue);
        }
    }
}
Also used : Path(org.apache.tools.ant.types.Path) Hashtable(java.util.Hashtable) File(java.io.File)

Example 35 with Path

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

the class DefaultCompilerAdapterTest method releaseIsUsedForJava9.

@Test
public void releaseIsUsedForJava9() {
    LogCapturingJavac javac = new LogCapturingJavac();
    Project p = new Project();
    javac.setProject(p);
    javac.setCompiler("javac9");
    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("Ignoring source, target and bootclasspath as " + "release has been set", javac.getLog());
    String[] args = cmd.getCommandline();
    assertEquals(5, args.length);
    assertEquals("-classpath", args[0]);
    assertEquals("-g:none", args[2]);
    assertEquals("--release", args[3]);
    assertEquals("6", args[4]);
}
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)

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