/**
   * Extract Composite baseline information in an external file
   *
   * @param compositeComponnentName
   * @param pvob
   * @param compositeBaselineName
   * @param fileName
   * @param clearToolLauncher
   * @param filePath
   * @throws Exception
   */
  private void processExtractInfoFile(
      ClearTool clearTool,
      String compositeComponnentName,
      String pvob,
      String compositeBaselineName,
      String fileName)
      throws Exception {
    String output = clearTool.lsbl(compositeBaselineName + "@" + pvob, "\"%[depends_on]p\"");
    if (output.contains("cleartool: Error")) {
      throw new Exception("Failed to make baseline, reason: " + output);
    }

    String baselinesComp[] = output.split(" ");
    List<String> baselineList = Arrays.asList(baselinesComp);
    Collections.sort(baselineList);

    Writer writer = null;
    try {
      FilePath fp = new FilePath(clearTool.getLauncher().getLauncher().getChannel(), fileName);
      OutputStream outputStream = fp.write();
      writer = new OutputStreamWriter(outputStream);
      writer.write("The composite baseline is '" + compositeBaselineName + "'");
      for (String baseLine : baselineList) {
        writer.write(
            "\nThe  baseline of component '"
                + getComponent(clearTool, baseLine)
                + "' is :"
                + baseLine);
      }
    } finally {
      if (writer != null) {
        writer.close();
      }
    }
  }
Beispiel #2
0
  private boolean checkoutCode(
      final Launcher launcher, final FilePath workspace, final OutputStream logger)
      throws IOException, InterruptedException {
    final List<String> commands = new ArrayList<String>(4);

    debug.log(Level.INFO, "Checking out code in: " + workspace.getName());

    commands.add(getDescriptor().getExecutable());
    commands.add("init");
    commands.add("-u");
    commands.add(manifestRepositoryUrl);
    if (manifestBranch != null) {
      commands.add("-b");
      commands.add(manifestBranch);
    }
    if (manifestFile != null) {
      commands.add("-m");
      commands.add(manifestFile);
    }
    if (mirrorDir != null) {
      commands.add("--reference=" + mirrorDir);
    }
    if (repoUrl != null) {
      commands.add("--repo-url=" + repoUrl);
      commands.add("--no-repo-verify");
    }
    int returnCode = launcher.launch().stdout(logger).pwd(workspace).cmds(commands).join();
    if (returnCode != 0) {
      return false;
    }
    if (workspace != null) {
      FilePath rdir = workspace.child(".repo");
      FilePath lm = rdir.child("local_manifest.xml");
      lm.delete();
      if (localManifest != null) {
        if (localManifest.startsWith("<?xml")) {
          lm.write(localManifest, null);
        } else {
          URL url = new URL(localManifest);
          lm.copyFrom(url);
        }
      }
    }

    returnCode = doSync(launcher, workspace, logger);
    if (returnCode != 0) {
      debug.log(Level.WARNING, "Sync failed. Resetting repository");
      commands.clear();
      commands.add(getDescriptor().getExecutable());
      commands.add("forall");
      commands.add("-c");
      commands.add("git reset --hard");
      launcher.launch().stdout(logger).pwd(workspace).cmds(commands).join();
      returnCode = doSync(launcher, workspace, logger);
      if (returnCode != 0) {
        return false;
      }
    }
    return true;
  }
 private static void screenCaptureToFile(AbstractBuild build, AndroidDeviceContext device)
     throws IOException, InterruptedException {
   FilePath screencapFile = build.getWorkspace().createTempFile("screencap", ".png");
   OutputStream screencapStream = screencapFile.write();
   FilterOutputStream replaceFilterStream = new ReplaceFilterOutputStream(screencapStream);
   device.screenshot(replaceFilterStream);
   screencapFile.copyTo(new FilePath(build.getArtifactsDir()).child("screencap.png"));
 }
  private MimeBodyPart getContent(
      final EmailType type,
      final AbstractBuild<?, ?> build,
      BuildListener listener,
      String charset,
      EmailTrigger trigger)
      throws MessagingException {
    final String text = new ContentBuilder().transformText(type.getBody(), this, build, listener);

    String messageContentType = contentType;
    // contentType is null if the project was not reconfigured after upgrading.
    if (messageContentType == null || "default".equals(messageContentType)) {
      messageContentType = DESCRIPTOR.getDefaultContentType();
      // The defaultContentType is null if the main Jenkins configuration
      // was not reconfigured after upgrading.
      if (messageContentType == null) {
        messageContentType = "text/plain";
      }
    }
    messageContentType += "; charset=" + charset;

    try {
      if (saveOutput) {
        Random random = new Random();
        String extension = ".html";
        if (messageContentType.startsWith("text/plain")) {
          extension = ".txt";
        }

        FilePath savedOutput =
            new FilePath(
                build.getWorkspace(),
                String.format(
                    "%s-%s%d%s",
                    trigger.getDescriptor().getDisplayName(),
                    build.getId(),
                    random.nextInt(),
                    extension));
        savedOutput.write(text, charset);
      }
    } catch (IOException e) {
      listener.getLogger().println("Error trying to save email output to file. " + e.getMessage());
    } catch (InterruptedException e) {
      listener.getLogger().println("Error trying to save email output to file. " + e.getMessage());
    }

    // set the email message text
    // (plain text or HTML depending on the content type)
    MimeBodyPart msgPart = new MimeBodyPart();
    debug(listener.getLogger(), "messageContentType = %s", messageContentType);
    if (messageContentType.startsWith("text/html")) {
      String inlinedCssHtml = new CssInliner().process(text);
      msgPart.setContent(inlinedCssHtml, messageContentType);
    } else {
      msgPart.setContent(text, messageContentType);
    }
    return msgPart;
  }
  public static void generateFile(String mavenSettingsPath, FilePath outputPath) {
    try {
      // create directories if needed
      outputPath.getParent().mkdirs();

      StringBuilder sb = new StringBuilder("eclipse.m2.userSettingsFile=");
      sb.append(OSPathHacks.escapePathForEclipseConf(mavenSettingsPath));
      sb.append("\neclipse.preferences.version=1");
      outputPath.write(sb.toString(), null);
    } catch (IOException e) {
      throw new RuntimeException("Error generating xCP Designer m2e preferences file.", e);
    } catch (InterruptedException e) {
      throw new RuntimeException("Error generating xCP Designer m2e preferences file.", e);
    }
  }
Beispiel #6
0
 public void commit(
     final String fileName,
     final String fileContent,
     final PersonIdent author,
     final PersonIdent committer,
     final String message)
     throws GitException, InterruptedException {
   FilePath file = gitDirPath.child(fileName);
   try {
     file.write(fileContent, null);
   } catch (Exception e) {
     throw new GitException("unable to write file", e);
   }
   git.add(fileName);
   git.setAuthor(author);
   git.setCommitter(committer);
   git.commit(message);
 }
  private void logResponseToFile(
      FilePath workspace, PrintStream logger, ResponseContentSupplier responseContentSupplier)
      throws IOException, InterruptedException {

    FilePath outputFilePath = getOutputFilePath(workspace, logger);

    if (outputFilePath != null && responseContentSupplier.getContent() != null) {
      OutputStreamWriter write = null;
      try {
        write = new OutputStreamWriter(outputFilePath.write(), Charset.forName("UTF-8"));
        write.write(responseContentSupplier.getContent());
      } finally {
        if (write != null) {
          write.close();
        }
      }
    }
  }
 private void writeFitnesseResults(PrintStream log, FilePath resultsFilePath, byte[] results) {
   OutputStream resultsStream = null;
   try {
     resultsStream = resultsFilePath.write();
     resultsStream.write(results);
     log.println(
         "Xml results saved as "
             + Charset.defaultCharset().displayName()
             + " to "
             + resultsFilePath.getRemote());
   } catch (IOException e) {
     e.printStackTrace(log);
   } catch (InterruptedException e2) {
     e2.printStackTrace(log);
   } finally {
     try {
       if (resultsStream != null) resultsStream.close();
     } catch (Exception e) {
       // swallow
     }
   }
 }
 private static void saveLastBuildNr(
     String lastBuildNr, XTriggerLog xTriggerLog, FilePath lastBuildNrFile)
     throws IOException, InterruptedException {
   lastBuildNrFile.write(lastBuildNr, "UTF-8");
   xTriggerLog.info(String.format("Wrote buildNr: %s", lastBuildNr));
 }