Java Code Examples for org.apache.tools.ant.taskdefs.Java#setClasspath()

The following examples show how to use org.apache.tools.ant.taskdefs.Java#setClasspath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PitestTask.java    From pitest with Apache License 2.0 6 votes vote down vote up
void execute(final Java java) {

    this.setOption(ConfigOption.INCLUDE_LAUNCH_CLASSPATH, "false");
    this.setOption(ConfigOption.CLASSPATH, generateAnalysisClasspath());

    java.setClasspath(generateLaunchClasspath());
    java.setClassname(MutationCoverageReport.class.getCanonicalName());
    java.setFailonerror(true);
    java.setFork(true);

    checkRequiredOptions();
    for (final Map.Entry<String, String> option : this.options.entrySet()) {
      java.createArg().setValue(
          "--" + option.getKey() + "=" + option.getValue());
    }

    java.execute();
  }
 
Example 2
Source File: JavaCard.java    From ant-javacard with MIT License 5 votes vote down vote up
private void addKitClasses(Java j) {
    Project project = getProject();
    // classpath to jckit bits
    Path cp = j.createClasspath();
    for (File jar : jckit.getToolJars()) {
        cp.append(new Path(project, jar.getPath()));
    }
    j.setClasspath(cp);
}
 
Example 3
Source File: AbstractFindBugsTask.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Create the FindBugs engine (the Java process that will run whatever
 * FindBugs-related program this task is going to execute).
 */
protected void createFindbugsEngine() {
    findbugsEngine = new Java();
    findbugsEngine.setProject(getProject());
    findbugsEngine.setTaskName(getTaskName());
    findbugsEngine.setFork(true);
    if (jvm.length() > 0) {
        findbugsEngine.setJvm(jvm);
    }
    findbugsEngine.setTimeout(timeout);

    if (debug) {
        jvmargs = jvmargs + " -Dfindbugs.debug=true";
    }
    jvmargs = jvmargs + " -Dfindbugs.hostApp=FBAntTask";
    findbugsEngine.createJvmarg().setLine(jvmargs);

    // Add JVM arguments for system properties
    for (SystemProperty systemProperty : systemPropertyList) {
        String jvmArg = "-D" + systemProperty.getName() + "=" + systemProperty.getValue();
        findbugsEngine.createJvmarg().setValue(jvmArg);
    }

    if (homeDir != null) {
        // Use findbugs.home to locate findbugs.jar and the standard
        // plugins. This is the usual means of initialization.
        File findbugsLib = new File(homeDir, "lib");
        if (!findbugsLib.exists() && "lib".equals(homeDir.getName())) {
            findbugsLib = homeDir;
            homeDir = homeDir.getParentFile();
        }
        File findbugsLibFindBugs = new File(findbugsLib, "spotbugs.jar");
        // log("executing using home dir [" + homeDir + "]");
        if (findbugsLibFindBugs.exists()) {
            findbugsEngine.setClasspath(new Path(getProject(), findbugsLibFindBugs.getPath()));
        } else {
            throw new IllegalArgumentException("Can't find spotbugs.jar in " + findbugsLib);
        }
        findbugsEngine.createJvmarg().setValue("-Dspotbugs.home=" + homeDir.getPath());
    } else {
        // Use an explicitly specified classpath and list of plugin Jars
        // to initialize. This is useful for other tools which may have
        // FindBugs installed using a non-standard directory layout.

        findbugsEngine.setClasspath(classpath);
    }
    if (pluginList != null) {
        addArg("-pluginList");
        addArg(pluginList.toString());
    }
    // Set the main class to be whatever the subclass's constructor
    // specified.
    findbugsEngine.setClassname(mainClass);
}
 
Example 4
Source File: FindBugsViewerTask.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void execute() throws BuildException {
    findbugsEngine = (Java) getProject().createTask("java");

    findbugsEngine.setTaskName(getTaskName());
    findbugsEngine.setFork(true);

    if (timeout > 0) {
        findbugsEngine.setTimeout(timeout);
    }

    if (debug) {
        jvmargs = jvmargs + " -Dfindbugs.debug=true";
    }
    findbugsEngine.createJvmarg().setLine(jvmargs);

    if (homeDir != null) {
        // Use findbugs.home to locate findbugs.jar and the standard
        // plugins. This is the usual means of initialization.
        File findbugsLib = new File(homeDir, "lib");

        File findbugsLibFindBugs = new File(findbugsLib, "spotbugs.jar");
        File findBugsFindBugs = new File(homeDir, "spotbugs.jar");
        // log("executing using home dir [" + homeDir + "]");
        if (findbugsLibFindBugs.exists()) {
            findbugsEngine.setClasspath(new Path(getProject(), findbugsLibFindBugs.getPath()));
        } else if (findBugsFindBugs.exists()) {
            findbugsEngine.setClasspath(new Path(getProject(), findBugsFindBugs.getPath()));
        } else {
            throw new IllegalArgumentException("Can't find spotbugs.jar in " + homeDir);
        }

        findbugsEngine.setClassname("edu.umd.cs.findbugs.LaunchAppropriateUI");
        findbugsEngine.createJvmarg().setValue("-Dspotbugs.home=" + homeDir.getPath());
    } else {
        // Use an explicitly specified classpath and list of plugin Jars
        // to initialize. This is useful for other tools which may have
        // FindBugs installed using a non-standard directory layout.

        findbugsEngine.setClasspath(classpath);
        findbugsEngine.setClassname("edu.umd.cs.findbugs.LaunchAppropriateUI");

        addArg("-pluginList");
        addArg(pluginList.toString());
    }

    if (projectFile != null) {
        addArg("-project");
        addArg(projectFile.getPath());
    }

    if (loadbugs != null) {
        addArg("-loadbugs");
        addArg(loadbugs.getPath());
    }

    if (look != null) {
        addArg("-look:" + look);
        // addArg("-look");
        // addArg(look);
    }

    // findbugsEngine.setClassname("edu.umd.cs.findbugs.gui.FindBugsFrame");

    log("Launching FindBugs Viewer...");

    int rc = findbugsEngine.executeJava();

    if ((rc & ExitCodes.ERROR_FLAG) != 0) {
        throw new BuildException("Execution of findbugs failed.");
    }
    if ((rc & ExitCodes.MISSING_CLASS_FLAG) != 0) {
        log("Classes needed for analysis were missing");
    }
}