org.apache.tools.ant.taskdefs.Java Java Examples
The following examples show how to use
org.apache.tools.ant.taskdefs.Java.
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 |
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: BasicSupport.java From ci.maven with Apache License 2.0 | 6 votes |
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 #3
Source File: JavaCard.java From ant-javacard with MIT License | 5 votes |
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 #4
Source File: EtlExecuteTask.java From scriptella-etl with Apache License 2.0 | 5 votes |
/** * 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 #5
Source File: PitestTask.java From pitest with Apache License 2.0 | 5 votes |
@Override public void execute() throws BuildException { try { execute(new Java(this)); } catch (final Throwable t) { throw new BuildException(t); } }
Example #6
Source File: ProGuardMojo.java From code-hidding-plugin with GNU Lesser General Public License v2.1 | 4 votes |
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 #7
Source File: AbstractFindBugsTask.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
/** * 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 #8
Source File: AbstractFindBugsTask.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
/** * Get the Findbugs engine. */ protected Java getFindbugsEngine() { return findbugsEngine; }
Example #9
Source File: FindBugsViewerTask.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@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"); } }
Example #10
Source File: JavaCard.java From ant-javacard with MIT License | 4 votes |
private void convert(File applet_folder, List<File> exps) { setTaskName("convert"); // construct java task Java j = new Java(this); j.setTaskName("convert"); j.setFailonerror(true); j.setFork(true); // add classpath for SDK tools addKitClasses(j); // set class depending on SDK if (jckit.getVersion().isV3()) { j.setClassname("com.sun.javacard.converter.Main"); // XXX: See https://community.oracle.com/message/10452555 Variable jchome = new Variable(); jchome.setKey("jc.home"); jchome.setValue(jckit.getRoot().toString()); j.addSysproperty(jchome); } else { j.setClassname("com.sun.javacard.converter.Converter"); } // output path j.createArg().setLine("-d '" + applet_folder.getAbsolutePath() + "'"); // classes for conversion j.createArg().setLine("-classdir '" + classes_path + "'"); // construct export path StringJoiner expstringbuilder = new StringJoiner(File.pathSeparator); // Add targetSDK export files if (jckit.getVersion() == V310) { switch (targetsdk.getVersion()) { case V310: j.createArg().setLine("-target 3.1.0"); break; case V305: j.createArg().setLine("-target 3.0.5"); break; case V304: j.createArg().setLine("-target 3.0.4"); break; default: throw new HelpingBuildException("targetsdk " + targetsdk.getRelease() + " incompatible with jckit " + jckit.getRelease()); } } else { expstringbuilder.add(getTargetSdkExportDir().toString()); } // imports for (File imp : exps) { expstringbuilder.add(imp.toString()); } j.createArg().setLine("-exportpath '" + expstringbuilder.toString() + "'"); // always be a little verbose j.createArg().setLine("-verbose"); j.createArg().setLine("-nobanner"); // simple options if (debug) { j.createArg().setLine("-debug"); } if (!verify && !jckit.getVersion().isOneOf(V211, V212)) { j.createArg().setLine("-noverify"); } if (jckit.getVersion().isV3()) { j.createArg().setLine("-useproxyclass"); } if (ints) { j.createArg().setLine("-i"); } // determine output types String outputs = "CAP"; if (output_exp != null) { outputs += " EXP"; } if (output_jca != null) { outputs += " JCA"; } j.createArg().setLine("-out " + outputs); // define applets for (JCApplet app : raw_applets) { j.createArg().setLine("-applet " + hexAID(app.aid) + " " + app.klass); } // package properties j.createArg().setLine(package_name + " " + hexAID(package_aid) + " " + package_version); // report the command log("command: " + j.getCommandLine(), Project.MSG_VERBOSE); // execute the converter j.execute(); }