List of usage examples for org.apache.commons.exec CommandLine addArgument
public CommandLine addArgument(final String argument)
From source file:org.jboss.jdocbook.translate.PoSynchronizerImpl.java
private void updateTranslation(File template, File translation, Locale translationLocale) { if (!template.exists()) { log.trace("skipping PO updates; POT file did not exist : {0}", template); return;/* w ww. java2 s . co m*/ } if (translation.lastModified() >= template.lastModified()) { log.trace("skipping PO updates; up-to-date : {0}", translation); return; } final String translationLocaleString = componentRegistry.toLanguageString(translationLocale); CommandLine commandLine; if (translation.exists()) { commandLine = CommandLine.parse("msgmerge"); commandLine.addArgument("--quiet"); commandLine.addArgument("--update"); commandLine.addArgument("--backup=none"); commandLine.addArgument(FileUtils.resolveFullPathName(translation)); commandLine.addArgument(FileUtils.resolveFullPathName(template)); } else { if (!translation.getParentFile().exists()) { boolean created = translation.getParentFile().mkdirs(); if (!created) { log.info("Unable to create PO directory {}", translation.getParentFile().getAbsolutePath()); } } commandLine = CommandLine.parse("msginit"); commandLine.addArgument("--no-translator"); commandLine.addArgument("--locale=" + translationLocaleString); commandLine.addArgument("-i"); commandLine.addArgument(FileUtils.resolveFullPathName(template)); commandLine.addArgument("-o"); commandLine.addArgument(FileUtils.resolveFullPathName(translation)); } log.info("po-synch -> " + commandLine.toString()); DefaultExecutor executor = new DefaultExecutor(); try { executor.execute(commandLine); } catch (IOException e) { throw new JDocBookProcessException( "Error synchronizing PO file [" + template.getName() + "] for " + translationLocaleString, e); } }
From source file:org.jboss.jdocbook.translate.PotSynchronizerImpl.java
private void executeXml2pot(File masterFile, File potFile) { CommandLine commandLine = CommandLine.parse("xml2pot"); commandLine.addArgument(FileUtils.resolveFullPathName(masterFile)); DefaultExecutor executor = new DefaultExecutor(); try {/*from w w w. j a v a 2s . com*/ final FileOutputStream xmlStream = new FileOutputStream(potFile); PumpStreamHandler streamDirector = new PumpStreamHandler(xmlStream, System.err); executor.setStreamHandler(streamDirector); try { log.trace("updating POT file {0}", potFile); executor.execute(commandLine); } finally { try { xmlStream.flush(); xmlStream.close(); } catch (IOException ignore) { // intentionally empty... } } } catch (IOException e) { throw new JDocBookProcessException("unable to open output stream for POT file [" + potFile + "]"); } }
From source file:org.jboss.jdocbook.translate.TranslatorImpl.java
private void generateTranslatedXML(File masterFile, File poFile, File translatedFile) { if (!masterFile.exists()) { log.trace("skipping translation; source file did not exist : {}", masterFile); return;//from w ww . jav a 2s. c o m } if (!poFile.exists()) { log.trace("skipping translation; PO file did not exist : {}", poFile); return; } if (translatedFile.exists() && translatedFile.lastModified() >= masterFile.lastModified() && translatedFile.lastModified() >= poFile.lastModified()) { log.trace("skipping translation; up-to-date : {0}", translatedFile); return; } if (!translatedFile.getParentFile().exists()) { boolean created = translatedFile.getParentFile().mkdirs(); if (!created) { log.info("Unable to create directories for translation"); } } CommandLine commandLine = CommandLine.parse("po2xml"); commandLine.addArgument(FileUtils.resolveFullPathName(masterFile)); commandLine.addArgument(FileUtils.resolveFullPathName(poFile)); try { final FileOutputStream xmlStream = new FileOutputStream(translatedFile); DefaultExecutor executor = new DefaultExecutor(); try { PumpStreamHandler streamDirector = new PumpStreamHandler(xmlStream, System.err); executor.setStreamHandler(streamDirector); executor.execute(commandLine); } catch (IOException ioe) { throw new JDocBookProcessException("unable to execute po2xml : " + ioe.getMessage()); } finally { try { xmlStream.flush(); xmlStream.close(); } catch (IOException ignore) { // intentionally empty... } } } catch (IOException e) { throw new JDocBookProcessException( "unable to open output stream for translated XML file [" + translatedFile + "]"); } }
From source file:org.jboss.tools.windup.runtime.WindupRmiClient.java
public void startWindup(final IProgressMonitor monitor, String jreHome) { logInfo("Begin start RHAMT."); //$NON-NLS-1$ monitor.worked(1);//from w ww.j a va2s.com String windupExecutable = WindupRuntimePlugin.computeWindupExecutable(); if (windupExecutable == null) { WindupRuntimePlugin.logErrorMessage("rhamt-cli not specified."); //$NON-NLS-1$ return; } boolean executable = new File(windupExecutable).setExecutable(true); if (!executable) { WindupRuntimePlugin.logErrorMessage("rhamt-cli not executable."); //$NON-NLS-1$ return; } CommandLine cmdLine = CommandLine.parse(windupExecutable); Map<String, String> env = Maps.newHashMap(); for (Map.Entry<String, String> entry : System.getenv().entrySet()) { env.put(entry.getKey(), entry.getValue()); } if (!jreHome.trim().isEmpty()) { env.put(JAVA_HOME, jreHome); } logInfo("Using " + JAVA_HOME + " - " + jreHome); cmdLine.addArgument("--startServer"); //$NON-NLS-1$ cmdLine.addArgument(String.valueOf(getRmiPort())); watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT); ExecuteResultHandler handler = new ExecuteResultHandler() { @Override public void onProcessFailed(ExecuteException e) { logInfo("The RHAMT process failed:"); //$NON-NLS-1$ logInfo(e.getMessage()); //$NON-NLS-1$ executionBuilder = null; notifyServerChanged(); } @Override public void onProcessComplete(int exitValue) { logInfo("The RHAMT process has completed."); //$NON-NLS-1$ executionBuilder = null; notifyServerChanged(); } }; DefaultExecutor executor = new DefaultExecutor(); executor.setStreamHandler(new PumpStreamHandler(new LogOutputStream() { @Override protected void processLine(String line, int logLevel) { logInfo("Message from RHAMT executor: " + line); //$NON-NLS-1$ monitor.worked(1); } })); executor.setWatchdog(watchdog); executor.setExitValue(1); monitor.worked(1); try { logInfo("Starting RHAMT in server mode..."); //$NON-NLS-1$ logInfo("Command-line: " + cmdLine); //$NON-NLS-1$ executor.execute(cmdLine, env, handler); } catch (IOException e) { WindupRuntimePlugin.log(e); } }
From source file:org.jboss.windup.decorator.java.decompiler.BackupOfJadretroDecompilerAdapter.java
private void executeJad(File classLocation, File sourceOutputLocation) { try {/*from ww w. ja va2 s.com*/ // Build command array CommandLine cmdLine = new CommandLine(APP_NAME); cmdLine.addArgument("-d"); cmdLine.addArgument("${outputLocation}"); cmdLine.addArgument("-f"); cmdLine.addArgument("-o"); cmdLine.addArgument("-s"); cmdLine.addArgument("java"); cmdLine.addArgument("${classLocation}"); Map<String, Object> argMap = new HashMap<String, Object>(); argMap.put("outputLocation", sourceOutputLocation); argMap.put("classLocation", classLocation); cmdLine.setSubstitutionMap(argMap); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); int exitValue = executor.execute(cmdLine); LOG.debug("Decompiler exited with exit code: " + exitValue); if (!sourceOutputLocation.exists()) { LOG.error("Expected decompiled source: " + sourceOutputLocation.getAbsolutePath() + "; did not find file. This likey means that the decompiler did not successfully decompile the class."); } else { LOG.debug("Decompiled to: " + sourceOutputLocation.getAbsolutePath()); } } catch (IOException e) { throw new FatalWindupException( "Error running " + APP_NAME + " decompiler. Validate that " + APP_NAME + " is on your PATH.", e); } catch (Exception e) { throw new FatalWindupException( "Error running " + APP_NAME + " decompiler. Validate that " + APP_NAME + " is on your PATH.", e); } }
From source file:org.jboss.windup.decorator.java.decompiler.JadretroDecompilerAdapter.java
private void executeJad(File classLocation, File sourceOutputLocation) { try {// w w w . j a v a 2 s . c o m // Build command array CommandLine cmdLine = new CommandLine(APP_NAME); cmdLine.addArgument("-d"); cmdLine.addArgument("${outputLocation}"); cmdLine.addArgument("-f"); cmdLine.addArgument("-o"); cmdLine.addArgument("-s"); cmdLine.addArgument("java"); cmdLine.addArgument("${classLocation}"); Map<String, Object> argMap = new HashMap<String, Object>(); argMap.put("outputLocation", sourceOutputLocation); argMap.put("classLocation", classLocation); cmdLine.setSubstitutionMap(argMap); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); int exitValue = executor.execute(cmdLine); LOG.debug("Decompiler exited with exit code: " + exitValue); if (!sourceOutputLocation.exists()) { LOG.error("Expected decompiled source: " + sourceOutputLocation.getAbsolutePath() + "; did not find file. This likey means that the decompiler did not successfully decompile the class."); } else { LOG.debug("Decompiled to: " + sourceOutputLocation.getAbsolutePath()); } } catch (IOException e) { throw new FatalWindupException( "Error running " + APP_NAME + " decompiler. Validate that " + APP_NAME + " is on your PATH.", e); } }
From source file:org.jlab.clara.std.services.DataManager.java
private void stageInputFile(FilePaths files, EngineData output) { Path stagePath = FileUtils.getParent(files.stagedInputFile); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try {/*from ww w. j av a 2 s . co m*/ FileUtils.createDirectories(stagePath); CommandLine cmdLine = new CommandLine("cp"); cmdLine.addArgument(files.inputFile.toString()); cmdLine.addArgument(files.stagedInputFile.toString()); DefaultExecutor executor = new DefaultExecutor(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); executor.setStreamHandler(streamHandler); executor.execute(cmdLine); System.out.printf("%s service: input file '%s' copied to '%s'%n", NAME, files.inputFile, stagePath); returnFilePaths(output, files); } catch (ExecuteException e) { ServiceUtils.setError(output, "could not complete request: " + outputStream.toString().trim()); } catch (IOException e) { ServiceUtils.setError(output, "could not complete request: " + e.getMessage()); } }
From source file:org.jlab.clara.std.services.DataManager.java
private void removeStagedInputFile(FilePaths files, EngineData output) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try {/*from w ww. java 2 s . c o m*/ CommandLine cmdLine = new CommandLine("rm"); cmdLine.addArgument(files.stagedInputFile.toString()); DefaultExecutor executor = new DefaultExecutor(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); executor.setStreamHandler(streamHandler); executor.execute(cmdLine); System.out.printf("%s service: staged input file %s removed%n", NAME, files.stagedInputFile); returnFilePaths(output, files); } catch (ExecuteException e) { ServiceUtils.setError(output, "could not complete request: " + outputStream.toString().trim()); } catch (IOException e) { ServiceUtils.setError(output, "could not complete request: " + e.getMessage()); } }
From source file:org.jlab.clara.std.services.DataManager.java
private void saveOutputFile(FilePaths files, EngineData output) { Path outputPath = FileUtils.getParent(files.outputFile); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try {//from ww w . ja v a 2 s .c o m FileUtils.createDirectories(outputPath); CommandLine cmdLine = new CommandLine("mv"); // cmdLine.addArgument(files.stagedOutputFile.toString()); // cmdLine.addArgument(files.outputFile.toString()); // modified 09.12.18. Stage back multiple output files. vg Files.list(directoryPaths.stagePath).forEach(name -> { name.startsWith(files.stagedOutputFile.toString()); cmdLine.addArgument(name.toString()); }); cmdLine.addArgument(outputPath.toString()); // vg DefaultExecutor executor = new DefaultExecutor(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); executor.setStreamHandler(streamHandler); executor.execute(cmdLine); System.out.printf("%s service: output file '%s' saved to '%s'%n", NAME, files.stagedOutputFile, outputPath); returnFilePaths(output, files); } catch (ExecuteException e) { ServiceUtils.setError(output, "could not complete request: " + outputStream.toString().trim()); } catch (IOException e) { ServiceUtils.setError(output, "could not complete request: " + e.getMessage()); } }
From source file:org.kgi.mybatis.scala.generator.GenerateDaoMojo.java
public void execute() throws MojoExecutionException { String scaladocParamFileName = project.getBuild().getOutputDirectory() + File.separator + "myb-doclet.txt"; try {// w w w. jav a2 s. c o m File f = outputDirectory; getLog().info("writing generated files to directory:" + outputDirectory.getAbsolutePath()); if (!f.exists()) { f.mkdirs(); } File sourcesDir = new File(project.getBasedir(), "src" + File.separator + "main"); getLog().info("sources located in:" + sourcesDir.getAbsolutePath()); Collection<File> sourceFiles = FileUtils.listFiles(sourcesDir, new String[] { "scala", "java" }, true); PrintWriter scaladocParamFileWriter = new PrintWriter(new FileWriter(scaladocParamFileName)); scaladocParamFileWriter.println("-d"); scaladocParamFileWriter.println("src"); scaladocParamFileWriter.println("-doc-generator"); scaladocParamFileWriter.println("org.kgi.mybatis.scala.generator.doclet.MyBatisMappingDoclet"); for (File sourceFile : sourceFiles) { scaladocParamFileWriter.println(sourceFile.getAbsolutePath()); } scaladocParamFileWriter.flush(); scaladocParamFileWriter.close(); DependencyNode depTree = dependencyGraphBuilder.buildDependencyGraph(project, new ArtifactFilter() { public boolean include(Artifact artifact) { return "jar".equals(artifact.getType()); } }); List deps = collectDependencies(depTree); Iterator depIterator = deps.iterator(); StringBuilder cpBuilder = new StringBuilder(); String docletPath = null; while (depIterator.hasNext()) { Artifact dep = (Artifact) depIterator.next(); String path = System.getProperty("user.home") + File.separator + ".m2" + File.separator + "repository" + File.separator + dep.getGroupId().replace('.', File.separatorChar) + File.separator + dep.getArtifactId() + File.separator + dep.getVersion() + File.separator + dep.getArtifactId() + "-" + dep.getVersion() + "." + dep.getType(); if (cpBuilder.length() > 0) { cpBuilder.append(File.pathSeparator); } cpBuilder.append(path); if ("mybatis-scala-gen-doclet".equals(dep.getArtifactId())) { docletPath = path; } } CommandLine cmdl = new CommandLine("scaladoc"); cmdl.addArgument("-Dmyb-gen-destination=" + outputDirectory.getAbsolutePath()); cmdl.addArgument("-Dmyb-gen-destination-package=" + destinationPackage); cmdl.addArgument("-classpath"); cmdl.addArgument(cpBuilder.toString()); cmdl.addArgument("-toolcp"); cmdl.addArgument(docletPath); cmdl.addArgument("@" + scaladocParamFileName); getLog().info("generation command:\n" + cmdl.toString()); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); executor.execute(cmdl); } catch (Exception e) { getLog().error(e); throw new MojoExecutionException("Problems generating DAO sources" + scaladocParamFileName); } }