use of org.codehaus.plexus.archiver.zip.ZipUnArchiver in project tycho by eclipse.
the class UpdateSiteAssembler method unpackJar.
private void unpackJar(File location, File outputJar) {
ZipUnArchiver unzip;
FileLockService fileLockService;
try {
unzip = (ZipUnArchiver) session.lookup(ZipUnArchiver.ROLE, "zip");
fileLockService = (FileLockService) session.lookup(FileLockService.class.getName());
} catch (ComponentLookupException e) {
throw new RuntimeException("Could not lookup required component", e);
}
outputJar.mkdirs();
if (!outputJar.isDirectory()) {
throw new RuntimeException("Could not create output directory " + outputJar.getAbsolutePath());
}
unzip.setSourceFile(location);
unzip.setDestDirectory(outputJar);
FileLocker locker = fileLockService.getFileLocker(location);
locker.lock();
try {
unzip.extract();
} catch (ArchiverException e) {
throw new RuntimeException("Could not unpack jar", e);
} finally {
locker.release();
}
}
use of org.codehaus.plexus.archiver.zip.ZipUnArchiver in project maven-dependency-plugin by apache.
the class AbstractDependencyMojo method unpack.
/**
* @param artifact {@link Artifact}
* @param type The type.
* @param location The location.
* @param includes includes list.
* @param excludes excludes list.
* @param encoding the encoding.
* @throws MojoExecutionException in case of an error.
*/
protected void unpack(Artifact artifact, String type, File location, String includes, String excludes, String encoding) throws MojoExecutionException {
File file = artifact.getFile();
try {
logUnpack(file, location, includes, excludes);
location.mkdirs();
if (!location.exists()) {
throw new MojoExecutionException("Location to write unpacked files to could not be created: " + location);
}
if (file.isDirectory()) {
// usual case is a future jar packaging, but there are special cases: classifier and other packaging
throw new MojoExecutionException("Artifact has not been packaged yet. When used on reactor artifact, " + "unpack should be executed after packaging: see MDEP-98.");
}
UnArchiver unArchiver;
try {
unArchiver = archiverManager.getUnArchiver(type);
getLog().debug("Found unArchiver by type: " + unArchiver);
} catch (NoSuchArchiverException e) {
unArchiver = archiverManager.getUnArchiver(file);
getLog().debug("Found unArchiver by extension: " + unArchiver);
}
if (encoding != null && unArchiver instanceof ZipUnArchiver) {
((ZipUnArchiver) unArchiver).setEncoding(encoding);
getLog().info("Unpacks '" + type + "' with encoding '" + encoding + "'.");
}
unArchiver.setUseJvmChmod(useJvmChmod);
unArchiver.setIgnorePermissions(ignorePermissions);
unArchiver.setSourceFile(file);
unArchiver.setDestDirectory(location);
if (StringUtils.isNotEmpty(excludes) || StringUtils.isNotEmpty(includes)) {
// Create the selectors that will filter
// based on include/exclude parameters
// MDEP-47
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);
}
if (this.silent) {
silenceUnarchiver(unArchiver);
}
unArchiver.extract();
} catch (NoSuchArchiverException e) {
throw new MojoExecutionException("Unknown archiver type", e);
} catch (ArchiverException e) {
throw new MojoExecutionException("Error unpacking file: " + file + " to: " + location + "\r\n" + e.toString(), e);
}
}
use of org.codehaus.plexus.archiver.zip.ZipUnArchiver in project xwiki-platform by xwiki.
the class PackageMojo method unzip.
private void unzip(File source, File targetDirectory) throws MojoExecutionException {
createDirectory(targetDirectory);
try {
ZipUnArchiver unArchiver = new ZipUnArchiver();
unArchiver.enableLogging(new ConsoleLogger(Logger.LEVEL_ERROR, "Package"));
unArchiver.setSourceFile(source);
unArchiver.setDestDirectory(targetDirectory);
unArchiver.setOverwrite(true);
unArchiver.extract();
} catch (Exception e) {
throw new MojoExecutionException(String.format("Error unpacking file [%s] into [%s]", source, targetDirectory), e);
}
}
use of org.codehaus.plexus.archiver.zip.ZipUnArchiver in project maven-plugins by apache.
the class AbstractDependencyMojo method unpack.
protected void unpack(Artifact artifact, String type, File location, String includes, String excludes, String encoding) throws MojoExecutionException {
File file = artifact.getFile();
try {
logUnpack(file, location, includes, excludes);
location.mkdirs();
if (!location.exists()) {
throw new MojoExecutionException("Location to write unpacked files to could not be created: " + location);
}
if (file.isDirectory()) {
// usual case is a future jar packaging, but there are special cases: classifier and other packaging
throw new MojoExecutionException("Artifact has not been packaged yet. When used on reactor artifact, " + "unpack should be executed after packaging: see MDEP-98.");
}
UnArchiver unArchiver;
try {
unArchiver = archiverManager.getUnArchiver(type);
getLog().debug("Found unArchiver by type: " + unArchiver);
} catch (NoSuchArchiverException e) {
unArchiver = archiverManager.getUnArchiver(file);
getLog().debug("Found unArchiver by extension: " + unArchiver);
}
if (encoding != null && unArchiver instanceof ZipUnArchiver) {
((ZipUnArchiver) unArchiver).setEncoding(encoding);
getLog().info("Unpacks '" + type + "' with encoding '" + encoding + "'.");
}
unArchiver.setUseJvmChmod(useJvmChmod);
unArchiver.setIgnorePermissions(ignorePermissions);
unArchiver.setSourceFile(file);
unArchiver.setDestDirectory(location);
if (StringUtils.isNotEmpty(excludes) || StringUtils.isNotEmpty(includes)) {
// Create the selectors that will filter
// based on include/exclude parameters
// MDEP-47
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);
}
if (this.silent) {
silenceUnarchiver(unArchiver);
}
unArchiver.extract();
} catch (NoSuchArchiverException e) {
throw new MojoExecutionException("Unknown archiver type", e);
} catch (ArchiverException e) {
throw new MojoExecutionException("Error unpacking file: " + file + " to: " + location + "\r\n" + e.toString(), e);
}
}
Aggregations