org.apache.tools.ant.types.Commandline Java Examples
The following examples show how to use
org.apache.tools.ant.types.Commandline.
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: JDTCompilerAdapter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * 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); } }
Example #2
Source File: BcryptToolTest.java From bcrypt with Apache License 2.0 | 5 votes |
@Test public void testExecuteHash() { int exitCode = BcryptTool.execute(CLIParser.parse(Commandline.translateCommandline("\"mySecretPw\" -b 8 8e270d6129fd45f30a9b3fe44b4a8d9a")), out, err); verify(out).println("$2a$08$hgaLWQl7PdKIkx9iQyoLkeuIqizWtPErpyC7aDBasi2Pav97wwW9G"); verify(err, never()).println(any(String.class)); assertEquals(0, exitCode); }
Example #3
Source File: BcryptToolTest.java From bcrypt with Apache License 2.0 | 5 votes |
@Test public void testExecuteCheck() { int exitCode = BcryptTool.execute(CLIParser.parse(Commandline.translateCommandline("\"mySecretPw\" -c '$2a$08$hgaLWQl7PdKIkx9iQyoLkeuIqizWtPErpyC7aDBasi2Pav97wwW9G'")), out, err); verify(out).println(any(String.class)); verify(err, never()).println(any(String.class)); assertEquals(0, exitCode); }
Example #4
Source File: PostgresqlBackupProcessor.java From gocd with Apache License 2.0 | 5 votes |
ProcessExecutor createProcessExecutor(File targetDir, DbProperties dbProperties) { Properties connectionProperties = dbProperties.connectionProperties(); Properties pgProperties = Driver.parseURL(dbProperties.url(), connectionProperties); ArrayList<String> argv = new ArrayList<>(); LinkedHashMap<String, String> env = new LinkedHashMap<>(); if (isNotBlank(dbProperties.password())) { env.put("PGPASSWORD", dbProperties.password()); } // override with any user specified environment env.putAll(dbProperties.extraBackupEnv()); String dbName = pgProperties.getProperty("PGDBNAME"); argv.add("pg_dump"); argv.add("--no-password"); argv.add("--host=" + pgProperties.getProperty("PGHOST")); argv.add("--port=" + pgProperties.getProperty("PGPORT")); if (isNotBlank(dbProperties.user())) { argv.add("--username=" + dbProperties.user()); } argv.add(pgProperties.getProperty("PGDBNAME")); // append any user specified args for pg_dump if (isNotBlank(dbProperties.extraBackupCommandArgs())) { Collections.addAll(argv, Commandline.translateCommandline(dbProperties.extraBackupCommandArgs())); } argv.add("--file=" + new File(targetDir, "db." + dbName).toString()); ProcessExecutor processExecutor = new ProcessExecutor(); processExecutor.redirectOutputAlsoTo(Slf4jStream.of(getClass()).asDebug()); processExecutor.redirectErrorAlsoTo(Slf4jStream.of(getClass()).asDebug()); processExecutor.environment(env); processExecutor.command(argv); return processExecutor; }
Example #5
Source File: MySQLBackupProcessor.java From gocd with Apache License 2.0 | 5 votes |
private ProcessExecutor createProcessExecutor(File targetDir, DbProperties dbProperties) { ConnectionUrl connectionUrlInstance = ConnectionUrl.getConnectionUrlInstance(dbProperties.url(), dbProperties.connectionProperties()); LinkedHashMap<String, String> env = new LinkedHashMap<>(); if (isNotBlank(dbProperties.password())) { env.put("MYSQL_PWD", dbProperties.password()); } // override with any user specified environment env.putAll(dbProperties.extraBackupEnv()); ArrayList<String> argv = new ArrayList<>(); argv.add("mysqldump"); String dbName = connectionUrlInstance.getDatabase(); HostInfo mainHost = connectionUrlInstance.getMainHost(); if (mainHost != null) { argv.add("--host=" + mainHost.getHost()); argv.add("--port=" + mainHost.getPort()); } if (isNotBlank(dbProperties.user())) { argv.add("--user=" + dbProperties.user()); } // append any user specified args for mysqldump if (isNotBlank(dbProperties.extraBackupCommandArgs())) { Collections.addAll(argv, Commandline.translateCommandline(dbProperties.extraBackupCommandArgs())); } argv.add("--result-file=" + new File(targetDir, "db." + dbName).toString()); argv.add(connectionUrlInstance.getDatabase()); ProcessExecutor processExecutor = new ProcessExecutor(); processExecutor.redirectOutputAlsoTo(Slf4jStream.of(getClass()).asDebug()); processExecutor.redirectErrorAlsoTo(Slf4jStream.of(getClass()).asDebug()); processExecutor.environment(env); processExecutor.command(argv); return processExecutor; }
Example #6
Source File: Groovy.java From groovy with Apache License 2.0 | 5 votes |
private void createNewArgs(String txt) throws IOException { final String[] args = cmdline.getCommandline(); // Temporary file - delete on exit, create (assured unique name). final File tempFile = FileUtils.getFileUtils().createTempFile(PREFIX, SUFFIX, null, true, true); final String[] commandline = new String[args.length + 1]; ResourceGroovyMethods.write(tempFile, txt); commandline[0] = tempFile.getCanonicalPath(); System.arraycopy(args, 0, commandline, 1, args.length); super.clearArgs(); for (String arg : commandline) { final Commandline.Argument argument = super.createArg(); argument.setValue(arg); } }
Example #7
Source File: Groovy.java From groovy with Apache License 2.0 | 5 votes |
public static void main(String[] args) { final GroovyShell shell = new GroovyShell(new Binding()); final Groovy groovy = new Groovy(); for (int i = 1; i < args.length; i++) { final Commandline.Argument argument = groovy.createArg(); argument.setValue(args[i]); } final AntBuilder builder = new AntBuilder(); groovy.setProject(builder.getProject()); groovy.parseAndRunScript(shell, null, null, null, new File(args[0]), builder); }
Example #8
Source File: DockerUtils.java From docker-workflow-plugin with MIT License | 5 votes |
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; }
Example #9
Source File: MXJC2Task.java From mxjc with MIT License | 4 votes |
public Commandline.Argument createArg() { return cmdLine.createArgument(); }
Example #10
Source File: CLIParserTest.java From bcrypt with Apache License 2.0 | 4 votes |
public static String[] asArgArray(String cmd) { return Commandline.translateCommandline(cmd); }
Example #11
Source File: JDTCompilerAdapter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Modified from base class, Logs the compilation parameters, adds the files * to compile and logs the "niceSourceList" * Appends encoding information at the end of arguments * * @param cmd the given command line */ protected void logAndAddFilesToCompile(Commandline cmd) { this.attributes.log("Compilation " + cmd.describeArguments(), //$NON-NLS-1$ Project.MSG_VERBOSE); StringBuffer niceSourceList = new StringBuffer("File"); //$NON-NLS-1$ if (this.compileList.length != 1) { niceSourceList.append("s"); //$NON-NLS-1$ } niceSourceList.append(" to be compiled:"); //$NON-NLS-1$ niceSourceList.append(lSep); String[] encodedFiles = null, encodedDirs = null; int encodedFilesLength = 0, encodedDirsLength = 0; if (this.fileEncodings != null) { encodedFilesLength = this.fileEncodings.size(); encodedFiles = new String[encodedFilesLength]; this.fileEncodings.keySet().toArray(encodedFiles); } if (this.dirEncodings != null) { encodedDirsLength = this.dirEncodings.size(); encodedDirs = new String[encodedDirsLength]; this.dirEncodings.keySet().toArray(encodedDirs); //we need the directories sorted, longest first,since sub directories can //override encodings for their parent directories Comparator comparator = new Comparator() { public int compare(Object o1, Object o2) { return ((String) o2).length() - ((String) o1).length(); } }; Arrays.sort(encodedDirs, comparator); } for (int i = 0; i < this.compileList.length; i++) { String arg = this.compileList[i].getAbsolutePath(); boolean encoded = false; if (encodedFiles != null) { //check for file level custom encoding for (int j = 0; j < encodedFilesLength; j++) { if (arg.endsWith(encodedFiles[j])) { //found encoding, remove it from the list to speed things up next time around arg = arg + (String) this.fileEncodings.get(encodedFiles[j]); if (j < encodedFilesLength - 1) { System.arraycopy(encodedFiles, j + 1, encodedFiles, j, encodedFilesLength - j - 1); } encodedFiles[--encodedFilesLength] = null; encoded = true; break; } } } if (!encoded && encodedDirs != null) { //check folder level custom encoding for (int j = 0; j < encodedDirsLength; j++) { if (arg.lastIndexOf(encodedDirs[j]) != -1) { arg = arg + (String) this.dirEncodings.get(encodedDirs[j]); break; } } } cmd.createArgument().setValue(arg); niceSourceList.append(" " + arg + lSep); //$NON-NLS-1$ } this.attributes.log(niceSourceList.toString(), Project.MSG_VERBOSE); }
Example #12
Source File: Groovy.java From groovy with Apache License 2.0 | 4 votes |
public Commandline.Argument createArg() { return cmdline.createArgument(); }
Example #13
Source File: CLIParserTest.java From uber-adb-tools with Apache License 2.0 | 4 votes |
public static String[] asArgArray(String cmd) { return Commandline.translateCommandline(cmd); }
Example #14
Source File: CLIParserTest.java From uber-apk-signer with Apache License 2.0 | 4 votes |
public static String[] asArgArray(String cmd) { return Commandline.translateCommandline(cmd); }
Example #15
Source File: CLIParserTest.java From density-converter with Apache License 2.0 | 4 votes |
public static String[] asArgArray(String cmd) { return Commandline.translateCommandline(cmd); }
Example #16
Source File: StartProfiledServer.java From netbeans with Apache License 2.0 | 4 votes |
public Commandline.Argument createJvmarg() { return jvmarg.createVmArgument(); }
Example #17
Source File: VulasAgentMojo.java From steady with Apache License 2.0 | 4 votes |
public String prependVMArguments(final String arguments, final File agentJarFile) { CommandlineJava commandlineJava = new CommandlineJava() { @Override public void setVm(String vm) { //do not set "**/java" as the first command } }; //add the javaagent commandlineJava.createVmArgument().setLine(format("-javaagent:%s", agentJarFile)); //remove any javaagent with the same file name from the arguments final String[] args = Commandline.translateCommandline(arguments); // the new javaagent, as used by the prepare-vulas-agent goal final String regexForCurrentVulasAgent = format("-javaagent:(\"?)%s(\"?)", Pattern.quote(agentJarFile.toString())); // the default name of the legacy JAR final String regexForOldVulasAgent = format("-javaagent:(\"?).*%s(\"?)", Pattern.quote("/vulas/lib/vulas-core-latest-jar-with-dependencies.jar")); ArrayList<String> patterns = new ArrayList<>(); patterns.add(regexForCurrentVulasAgent); patterns.add(regexForOldVulasAgent); // go through the arguments to check for existing javaagents argprocess: for (String arg : args) { // check if one of vulas's agents is already defined as an arg // if yes ignore the arg for (String regExExp : patterns) { if (arg.matches(regExExp)) { continue argprocess; } } commandlineJava.createArgument().setLine(arg); } //add my properties for (final String key : this.agentOptions.keySet()) { final String value = this.agentOptions.get(key); if (value != null && !value.isEmpty()) { Environment.Variable variable = new Environment.Variable(); variable.setKey(key); variable.setValue(value); commandlineJava.addSysproperty(variable); } } //add -noverify commandlineJava.createVmArgument().setValue("-noverify"); return commandlineJava.toString(); }
Example #18
Source File: QuarkusDev.java From quarkus with Apache License 2.0 | 4 votes |
@Option(description = "Set application arguments", option = "quarkus-args") public void setArgsString(String argsString) { this.setArgs(Arrays.asList(Commandline.translateCommandline(argsString))); }
Example #19
Source File: BcryptToolTest.java From bcrypt with Apache License 2.0 | 4 votes |
@Test public void testCheckDoesNotVerify() { assertEquals(1, BcryptTool.execute(CLIParser.parse(Commandline.translateCommandline("\"mySecretPw\" -c '$2a$07$hgaLWQl7PdKIkx9iQyoLkeuIqizWtPErpyC7aDBasi2Pav97wwW9G'")), out, err)); }
Example #20
Source File: BcryptToolTest.java From bcrypt with Apache License 2.0 | 4 votes |
@Test public void testCheckInvalidFormat() { assertEquals(3, BcryptTool.execute(CLIParser.parse(Commandline.translateCommandline("\"mySecretPw\" -c '$2$$08$hgaLWQl7PdKIkx9iQyoLkeuIqizWtPErpyC7aDBasi2Pav97wwW9G'")), out, err)); }