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

The following examples show how to use org.apache.tools.ant.taskdefs.Java#executeJava() . 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: BasicSupport.java    From ci.maven with Apache License 2.0 6 votes vote down vote up
protected void installLicense() throws MojoExecutionException, IOException {
    if (licenseArtifact != null) {
        Artifact license = getArtifact(licenseArtifact);
        if (!hasSameLicense(license)) {
            log.info(MessageFormat.format(messages.getString("info.install.license"), 
                    licenseArtifact.getGroupId() + ":" + licenseArtifact.getArtifactId() + ":" + licenseArtifact.getVersion()));
            Java installLicenseTask = (Java) ant.createTask("java");
            installLicenseTask.setJar(license.getFile());
            Argument args = installLicenseTask.createArg();
            args.setLine("--acceptLicense " + assemblyInstallDirectory.getCanonicalPath());
            installLicenseTask.setTimeout(30000L);
            installLicenseTask.setFork(true);
            int rc = installLicenseTask.executeJava();
            if (rc != 0) {
                throw new MojoExecutionException(MessageFormat.format(messages.getString("error.install.license"), 
                        licenseArtifact.getGroupId() + ":" + licenseArtifact.getArtifactId() + ":" + licenseArtifact.getVersion(), rc));
            }
        }
    }
}
 
Example 2
Source File: EtlExecuteTask.java    From scriptella-etl with Apache License 2.0 5 votes vote down vote up
/**
     * TODO Implement fork correctly - use ant LoaderUtils to get scriptella.jar location
     * TODO Output errors
     */
    private void fork(final List<File> files) {
        Java j = new Java();
        j.setFork(true);
        j.setProject(getProject());
//        j.setClasspath(getClasspath());

        j.setClassname(EtlLauncher.class.getName());

        StringBuilder line = new StringBuilder();

        if (nostat) {
            line.append("-nostat ");
        }

        for (File file : files) {
            line.append(file.getPath()).append(' ');
        }
        j.createArg().setLine(line.toString());

        if (maxmemory != null) {
            j.setMaxmemory(maxmemory);
        }

        int r = j.executeJava();
        if (r != 0) {
            throw new BuildException("Unable to execute files: " + files +
                    ". See error log.");
        }
    }
 
Example 3
Source File: ProGuardMojo.java    From code-hidding-plugin with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static void proguardMain(File proguardJar, ArrayList argsList, ProGuardMojo mojo)
                                                                                         throws MojoExecutionException {

    Java java = new Java();

    Project antProject = new Project();
    antProject.setName(mojo.mavenProject.getName());
    antProject.init();

    DefaultLogger antLogger = new DefaultLogger();
    antLogger.setOutputPrintStream(System.out);
    antLogger.setErrorPrintStream(System.err);
    antLogger.setMessageOutputLevel(mojo.log.isDebugEnabled() ? Project.MSG_DEBUG
        : Project.MSG_INFO);

    antProject.addBuildListener(antLogger);
    antProject.setBaseDir(mojo.mavenProject.getBasedir());

    java.setProject(antProject);
    java.setTaskName("proguard");

    mojo.getLog().info("proguard jar: " + proguardJar);

    java.createClasspath().setLocation(proguardJar);
    // java.createClasspath().setPath(System.getProperty("java.class.path"));
    java.setClassname(mojo.proguardMainClass);

    java.setFailonerror(true);

    java.setFork(true);

    // get the maxMemory setting
    if (mojo.maxMemory != null) {
        java.setMaxmemory(mojo.maxMemory);
    }

    for (Iterator i = argsList.iterator(); i.hasNext();) {
        java.createArg().setValue(i.next().toString());
    }

    int result = java.executeJava();
    if (result != 0) {
        throw new MojoExecutionException("Obfuscation failed (result=" + result + ")");
    }
}
 
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");
    }
}