use of org.codehaus.plexus.archiver.manager.NoSuchArchiverException in project maven-plugins by apache.
the class DefaultAssemblyArchiver method createArchive.
/**
* {@inheritDoc}
*/
@Override
public File createArchive(final Assembly assembly, final String fullName, final String format, final AssemblerConfigurationSource configSource, boolean recompressZippedFiles, String mergeManifestMode) throws ArchiveCreationException, AssemblyFormattingException, InvalidAssemblerConfigurationException {
validate(assembly);
String filename = fullName;
if (!configSource.isIgnoreDirFormatExtensions() || !format.startsWith("dir")) {
filename += "." + format;
}
AssemblyFileUtils.verifyTempDirectoryAvailability(configSource.getTemporaryRootDirectory());
final File outputDirectory = configSource.getOutputDirectory();
final File destFile = new File(outputDirectory, filename);
try {
final String finalName = configSource.getFinalName();
final String specifiedBasedir = assembly.getBaseDirectory();
String basedir = finalName;
if (specifiedBasedir != null) {
basedir = AssemblyFormatUtils.getOutputDirectory(specifiedBasedir, finalName, configSource, AssemblyFormatUtils.moduleProjectInterpolator(configSource.getProject()), AssemblyFormatUtils.artifactProjectInterpolator(null));
}
final List<ContainerDescriptorHandler> containerHandlers = selectContainerDescriptorHandlers(assembly.getContainerDescriptorHandlers(), configSource);
final Archiver archiver = createArchiver(format, assembly.isIncludeBaseDirectory(), basedir, configSource, containerHandlers, recompressZippedFiles, mergeManifestMode);
archiver.setDestFile(destFile);
for (AssemblyArchiverPhase phase : sortedPhases()) {
phase.execute(assembly, archiver, configSource);
}
archiver.createArchive();
} catch (final ArchiverException e) {
throw new ArchiveCreationException("Error creating assembly archive " + assembly.getId() + ": " + e.getMessage(), e);
} catch (final IOException e) {
throw new ArchiveCreationException("Error creating assembly archive " + assembly.getId() + ": " + e.getMessage(), e);
} catch (final NoSuchArchiverException e) {
throw new ArchiveCreationException("Unable to obtain archiver for extension '" + format + "', for assembly: '" + assembly.getId() + "'", e);
} catch (final DependencyResolutionException e) {
throw new ArchiveCreationException("Unable to resolve dependencies for assembly '" + assembly.getId() + "'", e);
}
return destFile;
}
use of org.codehaus.plexus.archiver.manager.NoSuchArchiverException in project maven-plugins by apache.
the class AssemblyFileUtilsTest method testUnpack_ShouldSetSourceAndDestinationAndCallExtract.
public void testUnpack_ShouldSetSourceAndDestinationAndCallExtract() throws IOException, ArchiveExpansionException, NoSuchArchiverException {
EasyMockSupport mockManager = new EasyMockSupport();
File source = fileManager.createTempFile();
File destDir = fileManager.createTempDir();
UnArchiver unarchiver = mockManager.createMock(UnArchiver.class);
ArchiverManager archiverManager = mockManager.createMock(ArchiverManager.class);
try {
expect(archiverManager.getUnArchiver(source)).andReturn(unarchiver);
} catch (NoSuchArchiverException e) {
fail("Should never happen.");
}
unarchiver.setSourceFile(source);
unarchiver.setDestDirectory(destDir);
try {
unarchiver.extract();
} catch (ArchiverException e) {
fail("Should never happen.");
}
mockManager.replayAll();
AssemblyFileUtils.unpack(source, destDir, archiverManager);
mockManager.verifyAll();
}
use of org.codehaus.plexus.archiver.manager.NoSuchArchiverException 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