示例#1
0
文件: Macro.java 项目: bramk/bnd
  /**
   * System command. Execute a command and insert the result.
   *
   * @param args
   * @param help
   * @param patterns
   * @param low
   * @param high
   */
  public String system_internal(boolean allowFail, String args[]) throws Exception {
    verifyCommand(
        args,
        "${"
            + (allowFail ? "system-allow-fail" : "system")
            + ";<command>[;<in>]}, execute a system command",
        null,
        2,
        3);
    String command = args[1];
    String input = null;

    if (args.length > 2) {
      input = args[2];
    }

    Process process = Runtime.getRuntime().exec(command, null, domain.getBase());
    if (input != null) {
      process.getOutputStream().write(input.getBytes("UTF-8"));
    }
    process.getOutputStream().close();

    String s = IO.collect(process.getInputStream(), "UTF-8");
    int exitValue = process.waitFor();
    if (exitValue != 0) return exitValue + "";

    if (!allowFail && (exitValue != 0)) {
      domain.error("System command " + command + " failed with " + exitValue);
    }
    return s.trim();
  }
示例#2
0
文件: Macro.java 项目: bramk/bnd
 /**
  * Get the contents of a file.
  *
  * @param in
  * @return
  * @throws IOException
  */
 public String _cat(String args[]) throws IOException {
   verifyCommand(args, "${cat;<in>}, get the content of a file", null, 2, 2);
   File f = domain.getFile(args[1]);
   if (f.isFile()) {
     return IO.collect(f);
   } else if (f.isDirectory()) {
     return Arrays.toString(f.list());
   } else {
     try {
       URL url = new URL(args[1]);
       return IO.collect(url, "UTF-8");
     } catch (MalformedURLException mfue) {
       // Ignore here
     }
     return null;
   }
 }
示例#3
0
 @Override
 public void delete(Project p) throws IOException {
   File root = p.getWorkspace().getFile("pom.xml");
   String rootPom = IO.collect(root);
   if (rootPom.contains(getTag(p))) {
     rootPom = rootPom.replaceAll("\n\\s*" + getTag(p) + "\\s*", "\n");
     IO.store(rootPom, root);
   }
 }
示例#4
0
  @Override
  public void created(Project p) throws IOException {
    Workspace workspace = p.getWorkspace();

    copy("pom.xml", "pom.xml", p);

    File root = workspace.getFile("pom.xml");

    doRoot(p, root);

    String rootPom = IO.collect(root);
    if (!rootPom.contains(getTag(p))) {
      rootPom =
          rootPom.replaceAll(
              "<!-- DO NOT EDIT MANAGED BY BND MAVEN LIFECYCLE PLUGIN -->\n",
              "$0\n\t\t" + getTag(p) + "\n");
      IO.store(rootPom, root);
    }
  }
示例#5
0
  private void copy(String source, String dest, Project p) throws IOException {

    File f = p.getWorkspace().getFile("maven/" + source + ".tmpl");
    InputStream in;

    if (f.isFile()) {
      in = new FileInputStream(f);
    } else {
      in = MavenPlugin.class.getResourceAsStream(source);
      if (in == null) {
        p.error("Cannot find Maven default for %s", source);
        return;
      }
    }

    String s = IO.collect(in);
    String process = p.getReplacer().process(s);

    File d = p.getFile(dest);
    d.getParentFile().mkdirs();
    IO.store(process, d);
  }