Пример #1
0
  /**
   * 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();
  }
    @Override
    protected IStatus run(IProgressMonitor monitor) {
      String tmp = NO_HELP_CONTENT;
      if (template != null) {
        URI uri = template.getHelpContent();
        if (uri != null) {
          try {
            URLConnection conn = uri.toURL().openConnection();
            conn.setUseCaches(false);
            tmp = IO.collect(conn.getInputStream());
          } catch (IOException e) {
            log.log(
                new Status(
                    IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error loading template help content.", e));
          }
        }
      }

      final String text = tmp;
      if (control != null && !control.isDisposed()) {
        control
            .getDisplay()
            .asyncExec(
                new Runnable() {
                  @Override
                  public void run() {
                    if (!control.isDisposed()) control.setText(text);
                  }
                });
      }

      return Status.OK_STATUS;
    }
Пример #3
0
 /**
  * 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;
   }
 }
Пример #4
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);
   }
 }
Пример #5
0
  void download0(URI url, File path, byte[] sha) throws Exception {
    path.getParentFile().mkdirs();
    File tmp = IO.createTempFile(path.getParentFile(), "tmp", ".jar");
    URL u = url.toURL();

    URLConnection conn = u.openConnection();
    InputStream in;
    if (conn instanceof HttpURLConnection) {
      HttpURLConnection http = (HttpURLConnection) conn;
      http.setRequestProperty("Accept-Encoding", "deflate");
      http.setInstanceFollowRedirects(true);

      connector.handle(conn);

      int result = http.getResponseCode();
      if (result / 100 != 2) {
        String s = "";
        InputStream err = http.getErrorStream();
        try {
          if (err != null) s = IO.collect(err);
          if (result == 404) {
            reporter.trace("not found ");
            throw new FileNotFoundException("Cannot find " + url + " : " + s);
          }
          throw new IOException(
              "Failed request " + result + ":" + http.getResponseMessage() + " " + s);
        } finally {
          if (err != null) err.close();
        }
      }

      String deflate = http.getHeaderField("Content-Encoding");
      in = http.getInputStream();
      if (deflate != null && deflate.toLowerCase().contains("deflate")) {
        in = new InflaterInputStream(in);
        reporter.trace("inflate");
      }
    } else {
      connector.handle(conn);
      in = conn.getInputStream();
    }

    IO.copy(in, tmp);

    byte[] digest = SHA1.digest(tmp).digest();
    if (Arrays.equals(digest, sha)) {
      IO.rename(tmp, path);
    } else {
      reporter.trace(
          "sha's did not match %s, expected %s, got %s", tmp, Hex.toHexString(sha), digest);
      throw new IllegalArgumentException("Invalid sha downloaded");
    }
  }
Пример #6
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);
    }
  }
Пример #7
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);
  }