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();
  }
예제 #2
0
 /**
  * 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();
 }
예제 #3
0
파일: Cab.java 프로젝트: nhojpatrick/ant
  /**
   * 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());
      }
    }
  }