use of org.codehaus.plexus.archiver.ArchiverException 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);
}
}
use of org.codehaus.plexus.archiver.ArchiverException in project maven-plugins by apache.
the class AddArtifactTaskTest method testShouldAddArchiveFileWithUnpack.
public void testShouldAddArchiveFileWithUnpack() throws ArchiveCreationException, AssemblyFormattingException, IOException {
mac.expectModeChange(-1, -1, -1, -1, 1);
mac.expectInterpolators();
ArtifactMock artifactMock = new ArtifactMock(mockManager, "group", "artifact", "version", "jar", false);
artifactMock.setNewFile();
mac.expectGetDestFile(new File("junk"));
try {
// mac.archiver.addArchivedFileSet( artifactFile, outputLocation, AddArtifactTask.DEFAULT_INCLUDES_ARRAY,
// null );
mac.archiver.addArchivedFileSet((ArchivedFileSet) anyObject(), (Charset) anyObject());
} catch (ArchiverException e) {
fail("Should never happen.");
}
mockManager.replayAll();
AddArtifactTask task = createTask(artifactMock.getArtifact());
task.setUnpack(true);
task.execute(mac.archiver, mac.configSource);
mockManager.verifyAll();
}
use of org.codehaus.plexus.archiver.ArchiverException in project maven-plugins by apache.
the class AddDirectoryTaskTest method testAddDirectory_ShouldAddDirectoryWithDirMode.
public void testAddDirectory_ShouldAddDirectoryWithDirMode() throws ArchiveCreationException {
File dir = fileManager.createTempDir();
try {
archiver.addFileSet((FileSet) anyObject());
} catch (ArchiverException e) {
fail("Should never happen.");
}
int dirMode = Integer.parseInt("777", 8);
int fileMode = Integer.parseInt("777", 8);
configureModeExpectations(-1, -1, dirMode, fileMode, true);
mockManager.replayAll();
AddDirectoryTask task = new AddDirectoryTask(dir);
task.setDirectoryMode(dirMode);
task.setFileMode(fileMode);
task.setOutputDirectory("dir");
task.execute(archiver);
mockManager.verifyAll();
}
use of org.codehaus.plexus.archiver.ArchiverException in project maven-plugins by apache.
the class AddDirectoryTaskTest method testAddDirectory_ShouldAddDirectoryWithIncludesAndExcludes.
public void testAddDirectory_ShouldAddDirectoryWithIncludesAndExcludes() throws ArchiveCreationException {
File dir = fileManager.createTempDir();
try {
archiver.addFileSet((FileSet) anyObject());
} catch (ArchiverException e) {
fail("Should never happen.");
}
configureModeExpectations(-1, -1, -1, -1, false);
mockManager.replayAll();
AddDirectoryTask task = new AddDirectoryTask(dir);
task.setIncludes(Collections.singletonList("**/*.txt"));
task.setExcludes(Collections.singletonList("**/README.txt"));
task.setOutputDirectory("dir");
task.execute(archiver);
mockManager.verifyAll();
}
use of org.codehaus.plexus.archiver.ArchiverException in project maven-plugins by apache.
the class AddDependencySetsTask method addNonArchiveDependency.
private void addNonArchiveDependency(final Artifact depArtifact, final MavenProject depProject, final DependencySet dependencySet, final Archiver archiver, final AssemblerConfigurationSource configSource) throws AssemblyFormattingException, ArchiveCreationException {
final File source = depArtifact.getFile();
String outputDirectory = dependencySet.getOutputDirectory();
FixedStringSearchInterpolator moduleProjectInterpolator = AssemblyFormatUtils.moduleProjectInterpolator(moduleProject);
FixedStringSearchInterpolator artifactProjectInterpolator = AssemblyFormatUtils.artifactProjectInterpolator(depProject);
outputDirectory = AssemblyFormatUtils.getOutputDirectory(outputDirectory, depProject.getBuild().getFinalName(), configSource, moduleProjectInterpolator, artifactProjectInterpolator);
final String destName = AssemblyFormatUtils.evaluateFileNameMapping(dependencySet.getOutputFileNameMapping(), depArtifact, configSource.getProject(), moduleArtifact, configSource, moduleProjectInterpolator, artifactProjectInterpolator);
String target;
// omit the last char if ends with / or \\
if (outputDirectory.endsWith("/") || outputDirectory.endsWith("\\")) {
target = outputDirectory + destName;
} else {
target = outputDirectory + "/" + destName;
}
try {
final int mode = TypeConversionUtils.modeToInt(dependencySet.getFileMode(), logger);
if (mode > -1) {
archiver.addFile(source, target, mode);
} else {
archiver.addFile(source, target);
}
} catch (final ArchiverException e) {
throw new ArchiveCreationException("Error adding file to archive: " + e.getMessage(), e);
}
}
Aggregations