Ejemplo n.º 1
0
  /**
   * Internal copy file method.
   *
   * @param srcFile the validated source file, must not be <code>null</code>
   * @param destFile the validated destination file, must not be <code>null</code>
   * @throws IOException if an error occurs
   */
  private static void doCopyFile(File srcFile, File destFile) throws IOException {
    if (destFile.exists() && destFile.isDirectory()) {
      throw new IOException("Destination '" + destFile + "' exists but is a directory");
    }

    FileInputStream fis = null;
    FileOutputStream fos = null;
    FileChannel input = null;
    FileChannel output = null;
    try {
      fis = new FileInputStream(srcFile);
      fos = new FileOutputStream(destFile);
      input = fis.getChannel();
      output = fos.getChannel();
      long size = input.size();
      long pos = 0;
      long count = 0;
      while (pos < size) {
        count = (size - pos) > FIFTY_MB ? FIFTY_MB : (size - pos);
        pos += output.transferFrom(input, pos, count);
      }
    } finally {
      Streams.closeQuietly(output);
      Streams.closeQuietly(fos);
      Streams.closeQuietly(input);
      Streams.closeQuietly(fis);
    }

    if (srcFile.length() != destFile.length()) {
      throw new IOException(
          "Failed to copy full contents from '" + srcFile + "' to '" + destFile + "'");
    }
  }
Ejemplo n.º 2
0
  @Override
  public MavenModelResource setCurrentModel(final Model pom) {
    Document document;
    try (InputStream is = getResourceInputStream()) {
      document = new SAXBuilder().build(is);
    } catch (JDOMException e) {
      throw new RuntimeException("Could not parse POM file: " + getFullyQualifiedName(), e);
    } catch (IOException e) {
      throw new RuntimeException("Could not read POM file: " + getFullyQualifiedName(), e);
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try (OutputStreamWriter os = new OutputStreamWriter(baos)) {
      MavenJDOMWriter writer = new MavenJDOMWriter();
      writer.write(pom, document, "UTF-8", os);
    } catch (IOException e) {
      throw new RuntimeException("Could not write POM file: " + getFullyQualifiedName(), e);
    }
    try (OutputStream resourceOutputStream = getResourceOutputStream()) {
      Streams.write(new ByteArrayInputStream(baos.toByteArray()), resourceOutputStream);
    } catch (IOException e) {
      throw new RuntimeException(
          "Error while writing to resource stream: " + getFullyQualifiedName(), e);
    }

    return this;
  }
Ejemplo n.º 3
0
  /*
   * Facet Methods
   */
  @Override
  public WebAppDescriptor getConfig() {
    FileResource<?> configFile = getConfigFile();
    WebAppDescriptor descriptor;
    if (configFile.exists()) {

      DescriptorImporter<WebAppDescriptor> importer = Descriptors.importAs(WebAppDescriptor.class);
      InputStream inputStream = configFile.getResourceInputStream();
      try {
        descriptor = importer.fromStream(inputStream);
      } finally {
        Streams.closeQuietly(inputStream);
      }
    } else {
      descriptor = Descriptors.create(WebAppDescriptor.class);
      String projectName = getFaceted().getFacet(MetadataFacet.class).getProjectName();
      WebAppDescriptor unit =
          descriptor
              .version("3.1")
              .displayName(projectName)
              .createSessionConfig()
              .sessionTimeout(30)
              .up();
      // FORGE-657
      unit.createMimeMapping().extension("ico").mimeType("image/x-icon");
    }
    return descriptor;
  }
Ejemplo n.º 4
0
  @Test
  public void testGitIgnoreCreate() throws Exception {
    executeGitIgnoreCreate();

    GitIgnoreResource gitignore = gitIgnoreResource();
    assertTrue(gitignore.exists());
    String content = Streams.toString(gitignore.getResourceInputStream());
    assertTrue(content.contains(".settings/"));
  }
Ejemplo n.º 5
0
  @Test
  public void testGitIgnoreAddPattern() throws Exception {
    executeGitIgnoreCreate();

    CommandController gitIgnoreAddPatternTester =
        testHarness.createCommandController(GitIgnoreAddPatternCommand.class, project.getRoot());
    gitIgnoreAddPatternTester.initialize();
    gitIgnoreAddPatternTester.setValueFor("pattern", "*.forge");
    gitIgnoreAddPatternTester.execute();

    GitIgnoreResource gitignore = gitIgnoreResource();
    String content = Streams.toString(gitignore.getResourceInputStream());
    assertTrue(content.contains("*.forge"));
  }
Ejemplo n.º 6
0
 protected String fetch(String type, String example) throws Exception {
   InputStream is = getClass().getClassLoader().getResourceAsStream(OUTPUT + type + "/" + example);
   return Streams.toString(is, DEFAULT_CHARSET);
 }