All pastes #503760 Raw Edit

Stuff

public java v1 · immutable
·published 2007-05-23 00:40 UTC
rendered paste body
import java.io.File;import java.io.IOException;import java.util.Vector;import org.apache.commons.io.FileUtils;import org.apache.tools.ant.BuildException;import org.apache.tools.ant.taskdefs.Java;import org.apache.tools.ant.types.CommandlineJava;/** * An ant task that writes a bourne script for launching interactive JRuby * shells.  Extends the <java> task to take advantage of classpath handling * and java argument assembly, and overrides execute() to write the JVM * launch command-line to a file instead of executing it. * <p> * The ProjectShell is intended for exploratory programming, ad-hoc testing of * the project's API, and assembling test data. * <p> * @author dacc */public class ProjectShellAntTask extends Java{  private String outputScriptPath;  private String initScriptPath;  /**   * @see Java#init()   */  @Override  public void init() throws BuildException  {    this.setClassname("org.jruby.Main");    this.setFork(true);    super.init();  }  /**   * @see Java#execute()   */  @Override  public void execute() throws BuildException  {    CommandlineJava commandLine = getCommandLine();    String arguments      = String.format("%s --readline -r irb/completion", initScriptPath);    commandLine.createArgument().setLine(arguments);    File scriptFile = new File(outputScriptPath);    Vector<String> lines = new Vector<String>(2);    lines.add("#!/usr/bin/env sh");    lines.add(commandLine.toString());    try {      FileUtils.writeLines(scriptFile, lines);    }    catch ( IOException e ) {      throw new BuildException(e);    }        log("Wrote project shell bourne script to " + outputScriptPath);  }    public String getInitScriptPath()  {    return initScriptPath;  }  /**   * Set the path to a Ruby initialization script that should be run when the   * shell starts up.   *    * @param initScriptPath   *   Filesystem path relative to the project root including file name.   */  public void setInitScriptPath(String initScriptPath)  {    this.initScriptPath = initScriptPath;  }  public String getOutputScriptPath()  {    return outputScriptPath;  }  /**   * Set the path of the bourne script to be written.   *    * @param outputScriptPath   *   Filesystem path relative to the project root including file name.   */  public void setOutputScriptPath(String outputScriptPath)  {    this.outputScriptPath = outputScriptPath;  }}