private void extractFilesFromDependencies()

in scrooge-maven-plugin/src/main/java/com/twitter/AbstractMavenScroogeMojo.java [414:451]


  private void extractFilesFromDependencies(Collection<Artifact> dependencies, File destFolder)
    throws IOException, MojoExecutionException{
    for (Artifact idlArtifact : dependencies) {
      if (!idlArtifact.isResolved()) {
        throw new MojoExecutionException(format("Could not resolve idl thrift dependency %s",
          idlArtifact));
      }
      File dep = idlArtifact.getFile();
      if (dep.isFile() && dep.canRead()) {
        getLog().info("Extracting thrift files from " + dep.getCanonicalPath());
        JarFile jar = new JarFile(dep);
        for (JarEntry entry : list(jar.entries())) {
          if (entry.getName().endsWith(THRIFT_FILE_SUFFIX)) {
            File destination = new File(destFolder, entry.getName());

            if (destination.isFile() && dep.lastModified() <= destination.lastModified()) {
              if (!haveSameContents(destination, jar, entry)) {
                throw new IOException(format("extracting %s from %s would overwrite %s", entry.getName(), dep.getCanonicalPath(), destination.getCanonicalPath()));
              } else {
                getLog().info(format("skipping extraction of %s from %s", entry.getName(), dep.getCanonicalPath()));
              }
            } else {
              if (destination.isFile()) {
                getLog().warn(format("overwriting %s with %s", entry.getName(), destination.getCanonicalPath()));
              } else {
                getLog().info(format("extracting %s to %s", entry.getName(), destination.getCanonicalPath()));
              }
              copyStreamToFile(new RawInputStreamFacade(jar.getInputStream(entry)), destination);
              if (!destination.setLastModified(dep.lastModified()))
                getLog().warn(format("fail to set last modified time for %s", destination.getCanonicalPath()));
            }
          }
        }
      } else {
        getLog().warn(format("dep %s isn't a file or can't be read", dep.getCanonicalPath()));
      }
    }
  }