Logo Search packages:      
Sourcecode: jmk version File versions  Download package

void edu::neu::ccs::jmk::Command::run ( Rule  target,
Rule  first,
Rule[]  newer,
String  match,
boolean  justPrinting,
java.io.PrintWriter  out 
) throws CommandFailedException [inline, package]

Runs a command. It produces an argument list from the operands and then applies the operator to the arguments. Each command variable is replaced by its value.

target the origin for the value of '@' command variable
first the origin for the value of '<' command variable
newer the origin for the value of '?' command variable
match the origin for the value of '' command variable
justPrinting if true, print but do not run commands
out the place to write messages

Definition at line 63 of file Command.java.

References edu::neu::ccs::jmk::StringList::getRest(), edu::neu::ccs::jmk::StringList::getString(), edu::neu::ccs::jmk::Rule::getTarget(), and edu::neu::ccs::jmk::Function::invoke().

Referenced by edu::neu::ccs::jmk::Rule::runCommands().

    // Construct the function's arguments
    StringList at = new StringList(target.getTarget());
    StringList lt = null;
    if (first != null)
      lt = new StringList(first.getTarget());
    StringList qm = null;
    for (int i = newer.length - 1; i >= 0; i--)
      qm = new StringList(newer[i].getTarget(), qm);
    StringList pc = null;
    if (match != null)
      pc = new StringList(match);
    // This must match Command.commandArgs
    Value[] params = new Value [] { at, lt, qm, pc };

    // Generate operands
    Value result = null;
    try {
      result = operands.invoke(params, null);
    catch (Exception ex) {
      String msg = "Command failed: " + ex.getMessage();
      throw new CommandFailedException(msg);

    if (!StringList.isStringList(result)) {
      String msg
      = "Command failed: Cannot convert operands to a list of strings";
      throw new CommandFailedException(msg);

    // Convert operand into a localized array of strings
    StringList sl = (StringList)result;
    int len = StringList.length(sl);
    String[] args = new String[len];
    for (int i = 0; sl != null; sl = sl.getRest())
      args[i++] = StringUtils.localizePaths(sl.getString());

    // Print the command after command variable substitution.
    for (int i = 0; i < args.length; i++)
      out.print(" " + args[i]);

    // Run the command.
    try {
      if (!justPrinting)
      operator.exec(args, out);
    catch (CommandFailedException ex) {
      if (ignore)
      out.println("Command failed: " + ex.getMessage() + " (ignored)");
      throw ex;
    catch (Throwable t) {
      throw new CommandFailedException(t.toString());

Generated by  Doxygen 1.6.0   Back to index