Exemplo n.º 1
0
  // Deploy exploded for now, could also rsync as jar file
  public void deploy() throws Exception {
    ArrayList<String> args = new ArrayList<String>();
    File onWindows = new File("C:/cygwin/bin/rsync.exe");
    args.add(onWindows.exists() ? onWindows.getAbsolutePath() : "rsync");
    args.add("-vrzute");
    args.add(ssh(_user, _key));
    args.add("--delete");
    args.add("--chmod=u=rwx");

    args.add("--exclude");
    args.add("'build/*.jar'");
    args.add("--exclude");
    args.add("'lib/hexbase_impl.jar'");
    args.add("--exclude");
    args.add("'lib/javassist'");

    ArrayList<String> sources = new ArrayList<String>();
    sources.add("build");
    sources.add("lib");
    for( int i = 0; i < sources.size(); i++ ) {
      String path = new File(sources.get(i)).getAbsolutePath();
      // Adapts paths in case running on Windows
      sources.set(i, path.replace('\\', '/').replace("C:/", "/cygdrive/c/"));
    }
    args.addAll(sources);

    args.add(_host + ":" + "/home/" + _user + "/" + TARGET);
    ProcessBuilder builder = new ProcessBuilder(args);
    builder.environment().put("CYGWIN", "nodosfilewarning");
    builder.redirectErrorStream(true);
    Process process = null;

    try {
      process = builder.start();
      SeparateVM.inheritIO(process, "rsync to " + _host, true);
      process.waitFor();
    } finally {
      if( process != null ) {
        try {
          process.destroy();
        } catch( Exception _ ) {
        }
      }
    }
  }
Exemplo n.º 2
0
    public static void main(String[] args) throws Exception {
      final String host = args[0], user = args[1], key = args[2];

      Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
          SeparateBox.close(host, user, key);
        }
      });

      exitWithParent();

      ArrayList<String> list = new ArrayList<String>();
      list.addAll(Arrays.asList(ssh(user, key).split(" ")));
      list.add(host);

      // Port forwarding
      // args.add("-L");
      // args.add("8000:127.0.0.1:" + local);

      String debug = "", cp = "";
      // TODO switch to address=127.0.0.1:8000 & port forwarding for security
      // debug =
      // "-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n";
      int shared = new File(".").getCanonicalPath().length() + 1;
      for( String s : System.getProperty("java.class.path").split(File.pathSeparator) ) {
        cp += cp.length() != 0 ? ":" : "";
        cp += new File(s).getCanonicalPath().substring(shared).replace('\\', '/');
      }

      String command = "" //
          + "cd " + TARGET + ";" //
          + "java " + debug + " -ea -cp " + cp;
      for( int i = 3; i < args.length; i++ )
        command += " " + args[i];
      list.add(command);

      ProcessBuilder builder = new ProcessBuilder(list);
      builder.environment().put("CYGWIN", "nodosfilewarning");
      builder.redirectErrorStream(true);
      Process process = builder.start();
      SeparateVM.inheritIO(process, null, false);
      process.waitFor();
    }