Ejemplo n.º 1
0
  private boolean isGpgKeyAvailable(
      GpgKey gpgKey, AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
      throws IOException, InterruptedException {
    ArgumentListBuilder command = new ArgumentListBuilder();
    command.add("gpg", "--fingerprint", gpgKey.getName());
    Launcher.ProcStarter ps = launcher.new ProcStarter();
    ps = ps.cmds(command).stdout(listener);
    ps = ps.pwd(build.getWorkspace()).envs(build.getEnvironment(listener));
    Proc proc = launcher.launch(ps);

    return proc.join() == 0;
  }
Ejemplo n.º 2
0
  private void importGpgKey(
      String privateKey, AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
      throws InterruptedException, IOException {
    ArgumentListBuilder command = new ArgumentListBuilder();
    command.add("gpg", "--import", "-");
    Launcher.ProcStarter ps = launcher.new ProcStarter();
    ps = ps.cmds(command).stdout(listener);
    ps = ps.pwd(build.getWorkspace()).envs(build.getEnvironment(listener));

    InputStream is = new ByteArrayInputStream(privateKey.getBytes());

    ps.stdin(is);
    Proc proc = launcher.launch(ps);
    proc.join();
    is.close();
  }
Ejemplo n.º 3
0
        public RemoteProcess call() throws IOException {
            Launcher.ProcStarter ps = new LocalLauncher(listener).launch();
            ps.cmds(cmd).masks(masks).envs(env).stdin(in).stdout(out).stderr(err);
            if(workDir!=null)   ps.pwd(workDir);
            if (reverseStdin)   ps.writeStdin();
            if (reverseStdout)  ps.readStdout();
            if (reverseStderr)  ps.readStderr();

            final Proc p = ps.start();

            return Channel.current().export(RemoteProcess.class,new RemoteProcess() {
                public int join() throws InterruptedException, IOException {
                    try {
                        return p.join();
                    } finally {
                        // make sure I/O is delivered to the remote before we return
                        try {
                            Channel.current().syncIO();
                        } catch (Throwable _) {
                            // this includes a failure to sync, slave.jar too old, etc
                        }
                    }
                }

                public void kill() throws IOException, InterruptedException {
                    p.kill();
                }

                public boolean isAlive() throws IOException, InterruptedException {
                    return p.isAlive();
                }

                public IOTriplet getIOtriplet() {
                    IOTriplet r = new IOTriplet();
                    if (reverseStdout)  r.stdout = new RemoteInputStream(p.getStdout());
                    if (reverseStderr)  r.stderr = new RemoteInputStream(p.getStderr());
                    if (reverseStdin)   r.stdin  = new RemoteOutputStream(p.getStdin());
                    return r;
                }
            });
        }
  public void testDecoratingLauncher() throws IOException {
    TaskListener listener = new LogTaskListener(Logger.getLogger(getName()), Level.ALL);
    Launcher outer = new Launcher.LocalLauncher(listener);
    CIOptions.Builder options = new CIOptions.Builder();
    CloverBuildWrapper wrapper = new CloverBuildWrapper(true, true, "FOO", null, false);
    CloverBuildWrapper.CloverDecoratingLauncher cloverLauncher =
        new CloverBuildWrapper.CloverDecoratingLauncher(
            wrapper, null, outer, options, "MYLICENSESTRING");

    Launcher.ProcStarter starter =
        new Launcher(cloverLauncher) {
          public Proc launch(ProcStarter starter) throws IOException {
            return null;
          }

          public Channel launchChannel(
              String[] cmd, OutputStream out, FilePath workDir, Map<String, String> envVars)
              throws IOException, InterruptedException {
            return null;
          }

          public void kill(Map<String, String> modelEnvVars)
              throws IOException, InterruptedException {}
        }.launch();

    starter.cmds("cmd.exe", "/C", "\"ant.bat clean test.run    &&  exit %%ERRORLEVEL%%\"");
    starter.pwd("target");
    List<String> cmds = starter.cmds();
    starter.masks(new boolean[cmds.size()]);
    cloverLauncher.decorateArgs(starter);

    cmds = starter.cmds();
    int i = 0;
    assertEquals("cmd.exe", cmds.get(i++));
    assertEquals("/C", cmds.get(i++));
    assertEquals("ant.bat", cmds.get(i++));
    assertEquals("clover.fullclean", cmds.get(i++));
  }
Ejemplo n.º 5
0
  @Override
  public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
      throws InterruptedException, IOException {
    if (isPerformDeployment(build)) {
      listener.getLogger().println("[RpmSignPlugin] - Starting signing RPMs ...");

      for (Rpm rpmEntry : entries) {
        StringTokenizer rpmGlobTokenizer = new StringTokenizer(rpmEntry.getIncludes(), ",");

        GpgKey gpgKey = getGpgKey(rpmEntry.getGpgKeyName());
        if (gpgKey != null && gpgKey.getPrivateKey().getPlainText().length() > 0) {
          listener.getLogger().println("[RpmSignPlugin] - Importing private key");
          importGpgKey(gpgKey.getPrivateKey().getPlainText(), build, launcher, listener);
          listener.getLogger().println("[RpmSignPlugin] - Imported private key");
        }

        if (!isGpgKeyAvailable(gpgKey, build, launcher, listener)) {
          listener
              .getLogger()
              .println("[RpmSignPlugin] - Can't find GPG key: " + rpmEntry.getGpgKeyName());
          return false;
        }

        while (rpmGlobTokenizer.hasMoreTokens()) {
          String rpmGlob = rpmGlobTokenizer.nextToken();

          listener.getLogger().println("[RpmSignPlugin] - Publishing " + rpmGlob);

          FilePath[] matchedRpms = build.getWorkspace().list(rpmGlob);
          if (ArrayUtils.isEmpty(matchedRpms)) {
            listener.getLogger().println("[RpmSignPlugin] - No RPMs matching " + rpmGlob);
          } else {
            ArgumentListBuilder rpmSignCommand = new ArgumentListBuilder();

            rpmSignCommand.add("rpm", "--define");
            rpmSignCommand.add("_gpg_name " + gpgKey.getName());
            rpmSignCommand.addTokenized(rpmEntry.getCmdlineOpts());

            if (rpmEntry.isResign()) {
              rpmSignCommand.add("--resign");
            } else {
              rpmSignCommand.add("--addsign");
            }

            for (FilePath rpmFilePath : matchedRpms) {
              rpmSignCommand.add(rpmFilePath.toURI().normalize().getPath());
            }

            String rpmCommandLine = rpmSignCommand.toString();
            listener.getLogger().println("[RpmSignPlugin] - Running " + rpmCommandLine);

            ArgumentListBuilder expectCommand = new ArgumentListBuilder();
            expectCommand.add("expect", "-");

            Launcher.ProcStarter ps = launcher.new ProcStarter();
            ps = ps.cmds(expectCommand).stdout(listener);
            ps = ps.pwd(build.getWorkspace()).envs(build.getEnvironment(listener));

            byte[] expectScript =
                createExpectScriptFile(rpmCommandLine, gpgKey.getPassphrase().getPlainText());
            ByteArrayInputStream is = new ByteArrayInputStream(expectScript);
            ps.stdin(is);

            Proc proc = launcher.launch(ps);
            int retcode = proc.join();
            if (retcode != 0) {
              listener.getLogger().println("[RpmSignPlugin] - Failed signing RPMs ...");
              return false;
            }
          }
        }
      }

      listener.getLogger().println("[RpmSignPlugin] - Finished signing RPMs ...");
    } else {
      listener.getLogger().println("[RpmSignPlugin] - Skipping signing RPMs ...");
    }
    return true;
  }