protected void executeScript( final String script, final boolean spawn, final String... arguments) { ExecTask exec = ant.createTask(ExecTask.class); exec.setExecutable(script); if (spawn) { exec.setSpawn(true); } else { exec.setFailIfExecutionFails(true); exec.setFailonerror(true); } if (arguments != null) { for (String argument : arguments) { Commandline.Argument arg = exec.createArg(); arg.setValue(argument); } } exec.setDir(new File(getConfiguration().getTargetDirectory(), getName())); exec.setFailIfExecutionFails(true); final Environment.Variable javaHome = new Environment.Variable(); javaHome.setKey("JAVA_HOME"); javaHome.setValue(System.getProperty("java.home")); exec.addEnv(javaHome); if (arguments != null && arguments.length > 0) { log.debug("Executing {} with arguments: {}", script, arguments); } else { log.debug("Executing {}", script); } exec.execute(); }
/** * Prepares a command line argument object for use with the appclient exec task that uses the * default set of arguments: the default location and name for the retreived app client jar file. * * @param exec the ExecTask with which the command line should be associated * @return the argument, associated with the exec task, and set to invoke the gen'd app client */ protected Commandline.Argument prepareRunCommandlineArg(ExecTask exec) { Commandline.Argument arg = exec.createArg(); String archiveDir = project.getProperty("archivedir"); String testName = project.getProperty("testName"); arg.setLine("-client " + archiveDir + "/" + testName + "Client.jar"); return arg; }
/** * Constructs an ExecTask instance, linked to the current project, for running the client. This * implementation prepares the exec task so it will run the appclient script. * * @return ExecTask initialized for running the appclient script to execute the generated and * retrieved app client */ protected ExecTask prepareRunExecTask() { /* This is the ant excerpt imitated by the exec task built by this method: <exec executable="${APPCLIENT}" resultproperty="result" failonerror="false" output="${build}/${log.id}.output.log"> <arg line="-client ${archivedir}/${testName}Client.jar"/> </exec> */ ExecTask exec = new ExecTask(); exec.setProject(project); String appclientValue = project.getProperty("APPCLIENT"); exec.setExecutable(appclientValue); exec.setFailonerror(false); exec.setTaskName("runclient"); return exec; }
private void executeDotCover(DotcoverStep step, String xmlFile) { ExecTask exec = new ExecTask(this); exec.setProject(getProject()); exec.setExecutable(execPath); exec.setFailonerror(failOnError); exec.setFailIfExecutionFails(failOnError); exec.createArg().setValue(step.name().toLowerCase()); exec.createArg().setValue(xmlFile); exec.execute(); }
/** * Sets the command line variables to be used to execute and validates for the required parameters * * @param varSet variable(name / value list) */ public void execute(VariableSet varSet, Project prj) throws ToolsProcessException { String path = null; String masterConf = null; String confml = null; String impl = null; String iby = null; String keepGoing = "false"; String report = null; String varName; String value; for (Variable variable : varSet.getVariables()) { varName = variable.getName(); value = variable.getValue(); if (varName.equals("path")) { path = value; } else if (varName.equals("master_conf")) { masterConf = value; } else if (varName.equals("confml")) { confml = value; } else if (varName.equals("impl")) { impl = value; } else if (varName.equals("iby")) { iby = value; } else if (varName.equals("keepgoing")) { keepGoing = value; } else if (varName.equals("report")) { report = value; } } if (path == null || masterConf == null || confml == null || iby == null) { throw new ToolsProcessException("Config Tool Parameter missing"); } org.apache.tools.ant.taskdefs.ExecTask task = new org.apache.tools.ant.taskdefs.ExecTask(); task.setTaskName("Configuration"); task.setDir(new java.io.File(path)); task.setExecutable(path + java.io.File.separator + "cli_build.cmd"); if (keepGoing.equals("false")) { task.setFailonerror(true); } else { task.createArg().setValue("-ignore_errors"); } task.createArg().setValue("-master_conf"); task.createArg().setValue(masterConf); task.createArg().setValue("-impl"); task.createArg().setValue(impl); task.createArg().setValue("-confml"); task.createArg().setValue(confml); task.createArg().setValue("-iby"); task.createArg().setValue(iby); if (report != null) { task.createArg().setValue("-report"); task.createArg().setValue(report); } task.execute(); }
/** * execute this task. * * @throws BuildException on error. */ public void execute() throws BuildException { checkConfiguration(); Vector files = getFileList(); // quick exit if the target is up to date if (isUpToDate(files)) { return; } log("Building " + archiveType + ": " + cabFile.getAbsolutePath()); if (!Os.isFamily("windows")) { log("Using listcab/libcabinet", Project.MSG_VERBOSE); StringBuffer sb = new StringBuffer(); Enumeration fileEnum = files.elements(); while (fileEnum.hasMoreElements()) { sb.append(fileEnum.nextElement()).append("\n"); } sb.append("\n").append(cabFile.getAbsolutePath()).append("\n"); try { Process p = Execute.launch( getProject(), new String[] {"listcab"}, null, baseDir != null ? baseDir : getProject().getBaseDir(), true); OutputStream out = p.getOutputStream(); // Create the stream pumpers to forward listcab's stdout and stderr to the log // note: listcab is an interactive program, and issues prompts for every new line. // Therefore, make it show only with verbose logging turned on. LogOutputStream outLog = new LogOutputStream(this, Project.MSG_VERBOSE); LogOutputStream errLog = new LogOutputStream(this, Project.MSG_ERR); StreamPumper outPump = new StreamPumper(p.getInputStream(), outLog); StreamPumper errPump = new StreamPumper(p.getErrorStream(), errLog); // Pump streams asynchronously (new Thread(outPump)).start(); (new Thread(errPump)).start(); out.write(sb.toString().getBytes()); out.flush(); out.close(); // A wild default for when the thread is interrupted int result = DEFAULT_RESULT; try { // Wait for the process to finish result = p.waitFor(); // Wait for the end of output and error streams outPump.waitFor(); outLog.close(); errPump.waitFor(); errLog.close(); } catch (InterruptedException ie) { log("Thread interrupted: " + ie); } // Informative summary message in case of errors if (Execute.isFailure(result)) { log("Error executing listcab; error code: " + result); } } catch (IOException ex) { String msg = "Problem creating " + cabFile + " " + ex.getMessage(); throw new BuildException(msg, getLocation()); } } else { try { File listFile = createListFile(files); ExecTask exec = createExec(); File outFile = null; // die if cabarc fails exec.setFailonerror(true); exec.setDir(baseDir); if (!doVerbose) { outFile = FILE_UTILS.createTempFile("ant", "", null, true, true); exec.setOutput(outFile); } exec.setExecutable("cabarc"); exec.createArg().setValue("-r"); exec.createArg().setValue("-p"); if (!doCompress) { exec.createArg().setValue("-m"); exec.createArg().setValue("none"); } if (cmdOptions != null) { exec.createArg().setLine(cmdOptions); } exec.createArg().setValue("n"); exec.createArg().setFile(cabFile); exec.createArg().setValue("@" + listFile.getAbsolutePath()); exec.execute(); if (outFile != null) { outFile.delete(); } listFile.delete(); } catch (IOException ioe) { String msg = "Problem creating " + cabFile + " " + ioe.getMessage(); throw new BuildException(msg, getLocation()); } } }
/** Default implementation for executing the app client */ protected void runClient() { ExecTask exec = prepareRunExecTask(); prepareRunCommandlineArg(exec); exec.execute(); }
public void execute() { // Make sure we have all the required fields set. if (outFile == null) { throw new BuildException("The outFile attribute is required"); } // First, populate all of the properties we care about for this task. if (getProject().getProperty("ant.build.native.toolchain") != null) { this.setToolchain(getProject().getProperty("ant.build.native.toolchain")); } if (getProject().getProperty("ant.build.native.host") != null) { this.setHost(getProject().getProperty("ant.build.native.host")); } // Setup the compiler. LinkerAdapter linker = ToolchainFactory.getLinker(toolchain); linker.setProject(getProject()); linker.setOutFile(outFile); if (host != null && host.length() > 0) { // Prepend the host string to the executable. linker.setExecutable(host + '-' + linker.getExecutable()); } for (AbstractFeature feat : features) { if (feat.isIfConditionValid() && feat.isUnlessConditionValid()) { linker.addArg(feat); } } long newest = 0; Iterator<File> inFile = linker.getInFiles(); while (inFile.hasNext()) { long modified = inFile.next().lastModified(); if (newest < modified) { newest = modified; } } if (newest >= outFile.lastModified()) { // Print the executed command. Echo echo = (Echo) getProject().createTask("echo"); echo.setTaskName(this.getTaskName()); echo.setAppend(true); // Create an exec task to run a shell. Using the current shell to // execute commands is required for Windows support. ExecTask shell = (ExecTask) getProject().createTask("exec"); shell.setTaskName(this.getTaskName()); shell.setFailonerror(true); // shell.setDir(dir); echo.addText(linker.getExecutable()); shell.setExecutable(linker.getExecutable()); Iterator<String> args = linker.getArgs(); while (args.hasNext()) { String arg = args.next(); echo.addText(" " + arg); shell.createArg().setLine(arg); } echo.execute(); shell.execute(); } }