/** * Return a String that describes the arguments suitable for * verbose output before a call to <code>Runtime.exec(String[])</code>. * @param line the Commandline whose arguments to describe. * @return a string that describes the arguments. * @since Ant 1.5 */ public static String describeArguments(Commandline line) { return describeArguments(line.getArguments()); }
private void verifyArguments(Commandline cmd) { if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9)) { for (String arg : cmd.getArguments()) { if ("-Xnew".equals(arg)) { throw new BuildException("JDK9 has removed support for -Xnew"); } } } }
/** {@inheritDoc} */ @Override protected boolean run(Commandline cmd, ProjectComponent log) throws BuildException { try { Class<?> n2aMain = Class.forName(SUN_TOOLS_NATIVE2ASCII_MAIN); Method convert = n2aMain.getMethod("convert", String[].class); return Boolean.TRUE.equals(convert.invoke(n2aMain.newInstance(), (Object) cmd.getArguments())); } catch (BuildException ex) { //rethrow throw ex; } catch (NoSuchMethodException ex) { throw new BuildException("Could not find convert() method in %s", SUN_TOOLS_NATIVE2ASCII_MAIN); } catch (Exception ex) { //wrap throw new BuildException("Error starting Sun's native2ascii: ", ex); } } }
/** * Run the compilation. * @return true if the compiler ran with a zero exit result (ok) * @exception BuildException if the compilation has problems. */ @Override public boolean execute() throws BuildException { attributes.log("Using modern compiler", Project.MSG_VERBOSE); Commandline cmd = setupModernJavacCommand(); // Use reflection to be able to build on all JDKs >= 1.1: try { Class<?> c = Class.forName("com.sun.tools.javac.Main"); Object compiler = c.newInstance(); Method compile = c.getMethod("compile", String[].class); int result = (Integer) compile.invoke(compiler, (Object) cmd.getArguments()); return result == MODERN_COMPILER_SUCCESS; } catch (Exception ex) { if (ex instanceof BuildException) { throw (BuildException) ex; } throw new BuildException("Error starting modern compiler", ex, location); } } }
/** * Run this ExecuteJava in a Thread. * @since Ant 1.5 */ @Override public void run() { final Object[] argument = {javaCommand.getArguments()}; try { if (perm != null) { perm.setSecurityManager(); } main.invoke(null, argument); } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); if (!(t instanceof InterruptedException)) { caught = t; } /* else { swallow, probably due to timeout } */ } catch (Throwable t) { caught = t; } finally { if (perm != null) { perm.restoreSecurityManager(); } synchronized (this) { done = true; notifyAll(); } } }
optionsTmpFile = FILE_UTILS.createTempFile( "javadocOptions", "", null, true, true); final String[] listOpt = toExecute.getArguments(); toExecute.clearArgs(); toExecute.createArgument().setValue(
return (Boolean) compile.invoke(compiler, new Object[] {cmd.getArguments()}); } catch (ClassNotFoundException ex) { throw new BuildException("Cannot use classic compiler, as it is "
/** * helper method to execute our command on VMS. * @param cmd Commandline * @param firstFileName int * @return boolean */ private boolean execOnVMS(Commandline cmd, int firstFileName) { File vmsFile = null; try { vmsFile = JavaEnvUtils.createVmsJavaOptionFile(cmd.getArguments()); String[] commandLine = {cmd.getExecutable(), "-V", vmsFile.getPath()}; return 0 == executeExternalCompile(commandLine, firstFileName, true); } catch (IOException e) { throw new BuildException( "Failed to create a temporary file for \"-V\" switch"); } finally { FileUtils.delete(vmsFile); } }
.equals(doRmic.invoke(rmic, (Object) cmd.getArguments())); success = true; return ok;
doRmic.invoke(null, (Object) cmd.getArguments()); return true; } catch (ClassNotFoundException ex) {
/** * Execute the given command, and return it's output * @param cmdline command line to execute * @return output of the command line */ protected String runS(Commandline cmdline) { String outV = "opts.cc.runS.output" + pcnt++; ExecTask exe = new ExecTask(this); Commandline.Argument arg = exe.createArg(); exe.setExecutable(cmdline.getExecutable()); arg.setLine(Commandline.toString(cmdline.getArguments())); exe.setOutputproperty(outV); exe.execute(); return getProject().getProperty(outV); }
CommandlineJava cmdl = new CommandlineJava(); cmdl.setClassname(javaCommand.getExecutable()); for (String arg : javaCommand.getArguments()) { cmdl.createArgument().setValue(arg);
java.setClassname("org.apache.jasper.JspC"); for (String arg : cmd.getJavaCommand().getArguments()) { java.createArg().setValue(arg);
public boolean execute() throws BuildException { Commandline cmd = setupModernJavacCommand(); try { Class apt = Class.forName ("com.sun.tools.apt.Main"); Method process; try { process = apt.getMethod ("process", new Class [] {AnnotationProcessorFactory.class,String[].class}); } catch (NoSuchMethodException e) { throw new BuildException("JDK 1.5.0_01 or later is necessary",e, location); } int result = ((Integer) process.invoke(null, new Object[] {createFactory(),cmd.getArguments()})) .intValue (); return result == 0; } catch (BuildException e) { throw e; } catch (Exception ex) { throw new BuildException("Error starting apt",ex, location); } } }
public boolean execute() throws BuildException { Commandline cmd = setupModernJavacCommand(); try { Class apt = Class.forName ("com.sun.tools.apt.Main"); Method process; try { process = apt.getMethod ("process", new Class [] {AnnotationProcessorFactory.class,String[].class}); } catch (NoSuchMethodException e) { throw new BuildException("JDK 1.5.0_01 or later is necessary",e, location); } int result = ((Integer) process.invoke(null, new Object[] {createFactory(),cmd.getArguments()})) .intValue (); return result == 0; } catch (BuildException e) { throw e; } catch (Exception ex) { throw new BuildException("Error starting apt",ex, location); } } }
public static Map<String, String> parseBuildArgs(final Dockerfile dockerfile, final String commandLine) { // this also accounts for quote, escapes, ... Commandline parsed = new Commandline(commandLine); Map<String, String> result = new HashMap<>(); if (dockerfile != null) { result.putAll(dockerfile.getArgs()); } String[] arguments = parsed.getArguments(); for (int i = 0; i < arguments.length; i++) { String arg = arguments[i]; if (arg.equals("--build-arg")) { if (arguments.length <= i + 1) { throw new IllegalArgumentException("Missing parameter for --build-arg: " + commandLine); } String keyVal = arguments[i+1]; String parts[] = keyVal.split("=", 2); if (parts.length != 2) { throw new IllegalArgumentException("Illegal syntax for --build-arg " + keyVal + ", need KEY=VALUE"); } String key = parts[0]; String value = parts[1]; result.put(key, value); } } return result; } }
public boolean execute() throws BuildException { try { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); DiagnosticCollector diagnostics = new DiagnosticCollector(); StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null); Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(Arrays.asList(compileList)); JavaCompiler.CompilationTask task = compiler.getTask( null, fileManager, diagnostics, Arrays.asList(setupModernJavacCommand().getArguments()), null, compilationUnits); task.setProcessors(Collections.singleton(getProcessor())); return task.call(); } catch (BuildException e) { throw e; } catch (Exception ex) { throw new BuildException("Error starting ap", ex, location); } } }
public boolean execute() throws BuildException { try { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); DiagnosticCollector diagnostics = new DiagnosticCollector(); StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null); Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(Arrays.asList(compileList)); JavaCompiler.CompilationTask task = compiler.getTask( null, fileManager, diagnostics, Arrays.asList(setupModernJavacCommand().getArguments()), null, compilationUnits); task.setProcessors(Collections.singleton(getProcessor())); return task.call(); } catch (BuildException e) { throw e; } catch (Exception ex) { throw new BuildException("Error starting ap", ex, location); } } }
/** * Performs a compile using the JDT batch compiler * @throws BuildException if anything wrong happen during the compilation * @return boolean true if the compilation is ok, false otherwise */ public boolean execute() throws BuildException { this.attributes.log(AntAdapterMessages.getString("ant.jdtadapter.info.usingJDTCompiler"), Project.MSG_VERBOSE); //$NON-NLS-1$ Commandline cmd = setupJavacCommand(); try { Class c = Class.forName(compilerClass); Constructor batchCompilerConstructor = c.getConstructor(new Class[] { PrintWriter.class, PrintWriter.class, Boolean.TYPE, Map.class}); Object batchCompilerInstance = batchCompilerConstructor.newInstance(new Object[] {new PrintWriter(System.out), new PrintWriter(System.err), Boolean.TRUE, this.customDefaultOptions}); Method compile = c.getMethod("compile", new Class[] {String[].class}); //$NON-NLS-1$ Object result = compile.invoke(batchCompilerInstance, new Object[] { cmd.getArguments()}); final boolean resultValue = ((Boolean) result).booleanValue(); if (!resultValue && this.logFileName != null) { this.attributes.log(AntAdapterMessages.getString("ant.jdtadapter.error.compilationFailed", this.logFileName)); //$NON-NLS-1$ } return resultValue; } catch (ClassNotFoundException cnfe) { throw new BuildException(AntAdapterMessages.getString("ant.jdtadapter.error.cannotFindJDTCompiler")); //$NON-NLS-1$ } catch (Exception ex) { throw new BuildException(ex); } }
/** * Performs a compile using the JDT batch compiler * @throws BuildException if anything wrong happen during the compilation * @return boolean true if the compilation is ok, false otherwise */ public boolean execute() throws BuildException { this.attributes.log(AntAdapterMessages.getString("ant.jdtadapter.info.usingJDTCompiler"), Project.MSG_VERBOSE); //$NON-NLS-1$ Commandline cmd = setupJavacCommand(); try { Class c = Class.forName(compilerClass); Constructor batchCompilerConstructor = c.getConstructor(new Class[] { PrintWriter.class, PrintWriter.class, Boolean.TYPE, Map.class}); Object batchCompilerInstance = batchCompilerConstructor.newInstance(new Object[] {new PrintWriter(System.out), new PrintWriter(System.err), Boolean.TRUE, this.customDefaultOptions}); Method compile = c.getMethod("compile", new Class[] {String[].class}); //$NON-NLS-1$ Object result = compile.invoke(batchCompilerInstance, new Object[] { cmd.getArguments()}); final boolean resultValue = ((Boolean) result).booleanValue(); if (!resultValue && this.logFileName != null) { this.attributes.log(AntAdapterMessages.getString("ant.jdtadapter.error.compilationFailed", this.logFileName)); //$NON-NLS-1$ } return resultValue; } catch (ClassNotFoundException cnfe) { throw new BuildException(AntAdapterMessages.getString("ant.jdtadapter.error.cannotFindJDTCompiler")); //$NON-NLS-1$ } catch (Exception ex) { throw new BuildException(ex); } }