Java Code Examples for org.codehaus.plexus.archiver.UnArchiver#extract()

The following examples show how to use org.codehaus.plexus.archiver.UnArchiver#extract() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StagerMojo.java    From helidon-build-tools with Apache License 2.0 6 votes vote down vote up
@Override
public void unpack(Path archive, Path target, String excludes, String includes) {
    File archiveFile = archive.toFile();
    UnArchiver unArchiver = null;
    try {
        unArchiver = archiverManager.getUnArchiver(archiveFile);
    } catch (NoSuchArchiverException ex) {
        throw new IllegalStateException(ex);
    }
    unArchiver.setSourceFile(archiveFile);
    unArchiver.setDestDirectory(target.toFile());
    if (StringUtils.isNotEmpty(excludes) || StringUtils.isNotEmpty(includes)) {
        IncludeExcludeFileSelector[] selectors = new IncludeExcludeFileSelector[]{
                new IncludeExcludeFileSelector()
        };
        if (StringUtils.isNotEmpty(excludes)) {
            selectors[0].setExcludes(excludes.split(","));
        }
        if (StringUtils.isNotEmpty(includes)) {
            selectors[0].setIncludes(includes.split(","));
        }
        unArchiver.setFileSelectors(selectors);
    }
    unArchiver.extract();
}
 
Example 2
Source File: FakeTimeMojo.java    From faketime with MIT License 6 votes vote down vote up
private void unpackAgent() {
  try {
    Artifact artifact = artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), getAgentArtifactCoordinate()).getArtifact();

    getTargetDirectory().mkdirs();

    UnArchiver unArchiver = archiverManager.getUnArchiver(artifact.getType());
    unArchiver.setSourceFile(artifact.getFile());
    unArchiver.setDestDirectory(getTargetDirectory());
    unArchiver.setFileSelectors(getAgentBinaryFileSelector());
    unArchiver.extract();
  }
  catch (ArtifactResolverException | NoSuchArchiverException e) {
    throw new RuntimeException(e);
  }
}
 
Example 3
Source File: NativeUnZipIncMojo.java    From maven-native with MIT License 6 votes vote down vote up
protected void unpackZipFile( File zipFile )
    throws MojoExecutionException
{
    this.getLog().info( "Unpacking: " + zipFile );

    try
    {
        if ( !dependencyIncludeDirectory.exists() )
        {
            dependencyIncludeDirectory.mkdirs();
        }

        UnArchiver archiver = this.archiverManager.getUnArchiver( "zip" );
        archiver.setOverwrite( true );
        archiver.setDestDirectory( this.dependencyIncludeDirectory );
        archiver.setSourceFile( zipFile );
        archiver.extract();
    }
    catch ( Exception e )
    {
        throw new MojoExecutionException( e.getMessage(), e );
    }

}
 
Example 4
Source File: TarsBuildMojo.java    From TarsJava with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * extract specified artifact. 
 *  
 * @param destination destination folder 
 * @param artifactFile 
 * @throws NoSuchArchiverException 
 * @throws ArchiverException 
 * @throws MojoExecutionException 
 */
private void unArchiveArtifact(final File destination, final File artifactFile) throws MojoExecutionException, IOException {
    try {
        final UnArchiver unArchiver = archiverManager.getUnArchiver(artifactFile);
        unArchiver.setSourceFile(artifactFile);
        unArchiver.setDestDirectory(destination);
        unArchiver.setOverwrite(true);
        unArchiver.extract();
    } catch (final NoSuchArchiverException | ArchiverException e) {
        throw new MojoExecutionException("Unable to unarchive " + artifactFile.getName(), e);
    }
}