Esempio n. 1
0
  @SuppressWarnings("deprecation")
  @Override
  public Bundle assemble(IssueSubmissionRequest request) throws IssueSubmissionException {
    OutputStream out = null;
    try {
      final ManagedBundle bundle = storageManager.createBundle("nexus.xml", "application/xml");
      final Configuration configuration =
          configHelper.maskPasswords(nexusConfig.getConfigurationModel());

      // No config ?
      if (configuration != null) {
        NexusConfigurationXpp3Writer writer = new NexusConfigurationXpp3Writer();
        out = bundle.getOutputStream();
        writer.write(out, configuration);
        out.close();
      } else {
        ByteStreams.write(
            "Got no configuration from config helper".getBytes("utf-8"),
            new OutputSupplier<OutputStream>() {
              @Override
              public OutputStream getOutput() throws IOException {
                return bundle.getOutputStream();
              }
            });
      }
      return bundle;
    } catch (IOException e) {
      IOUtil.close(out);
      throw new IssueSubmissionException("Could not assemble nexus.xml: " + e.getMessage(), e);
    }
  }
  protected void resultIsFine(String path, Configuration configuration) throws Exception {
    NexusConfigurationXpp3Writer w = new NexusConfigurationXpp3Writer();

    StringWriter sw = new StringWriter();

    w.write(sw, configuration);

    // System.out.println(sw.toString());

    String shouldBe = IOUtil.toString(getClass().getResourceAsStream(path + ".result"));
    shouldBe = shouldBe.replace("\r", "");

    if (!StringUtils.equals(shouldBe, sw.toString())) {
      // write the file out so we can have something to compare

      File expected = FileUtils.toFile(getClass().getResource(path + ".result"));
      File actual = new File("target", expected.getName().replaceFirst("result", "actual"));
      FileOutputStream out = new FileOutputStream(actual);
      try {
        IOUtil.copy(sw.toString(), out);
      } finally {
        IOUtil.close(out);
      }
      String diffMessage = "diff " + expected.getAbsolutePath() + " " + actual.getAbsolutePath();
      String message = "Files differ, you can manually diff them:\n" + diffMessage;

      // the method makes the error pretty, so we can keep it.
      assertEquals(message, shouldBe, sw.toString().replace("\r", ""));
    }
  }
  protected void saveConfiguration(Configuration config, String pathToConfig) throws IOException {
    NexusConfigurationXpp3Writer writer = new NexusConfigurationXpp3Writer();

    Writer fw = null;
    try {
      fw = new FileWriter(pathToConfig);

      writer.write(fw, config);
    } finally {
      IOUtil.close(fw);
    }
  }