use of org.codehaus.plexus.archiver.manager.NoSuchArchiverException in project docker-maven-plugin by fabric8io.
the class DockerAssemblyManager method createBuildTarBall.
// Create final tar-ball to be used for building the archive to send to the Docker daemon
private File createBuildTarBall(BuildDirs buildDirs, List<ArchiverCustomizer> archiverCustomizers, AssemblyConfiguration assemblyConfig, ArchiveCompression compression) throws MojoExecutionException {
File archive = new File(buildDirs.getTemporaryRootDirectory(), "docker-build." + compression.getFileSuffix());
try {
TarArchiver archiver = createBuildArchiver(buildDirs.getOutputDirectory(), archive, assemblyConfig);
for (ArchiverCustomizer customizer : archiverCustomizers) {
if (customizer != null) {
archiver = customizer.customize(archiver);
}
}
archiver.setCompression(compression.getTarCompressionMethod());
archiver.createArchive();
return archive;
} catch (NoSuchArchiverException e) {
throw new MojoExecutionException("No archiver for type 'tar' found", e);
} catch (IOException e) {
throw new MojoExecutionException("Cannot create archive " + archive, e);
}
}
use of org.codehaus.plexus.archiver.manager.NoSuchArchiverException in project felix by apache.
the class CheckMojo method extract.
private File extract(final File file) throws IOException, MojoExecutionException {
final File rootDir = Files.createTempDirectory("osgicheck").toFile();
UnArchiver zipUnarchiver = null;
try {
zipUnarchiver = archiverManager.getUnArchiver(file);
} catch (NoSuchArchiverException e) {
// should not happen
throw new MojoExecutionException("Impossible to unarchive the '" + file + "' file: " + e.getMessage());
}
zipUnarchiver.setDestDirectory(rootDir);
zipUnarchiver.setSourceFile(file);
zipUnarchiver.extract();
return rootDir;
}
use of org.codehaus.plexus.archiver.manager.NoSuchArchiverException 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.manager.NoSuchArchiverException in project docker-maven-plugin by fabric8io.
the class DockerAssemblyManager method extractDockerTarArchive.
/**
* Extract a docker tar archive into the given directory.
*
* @param archiveFile a tar archive to extract
* @param destinationDirectory directory where to place extracted content
* @throws MojoExecutionException if an error occurs during extracting.
*/
public void extractDockerTarArchive(File archiveFile, File destinationDirectory) throws MojoExecutionException {
try {
TarUnArchiver unArchiver = (TarUnArchiver) archiverManager.getUnArchiver(TAR_ARCHIVER_TYPE);
unArchiver.setCompression(UntarCompressionMethod.NONE);
unArchiver.setSourceFile(archiveFile);
unArchiver.setDestDirectory(destinationDirectory);
unArchiver.extract();
} catch (NoSuchArchiverException e) {
throw new MojoExecutionException("No archiver found for file " + archiveFile, e);
} catch (ArchiverException e) {
throw new MojoExecutionException("Cannot extract archive " + archiveFile, e);
}
}
use of org.codehaus.plexus.archiver.manager.NoSuchArchiverException in project jbehave-core by jbehave.
the class EmbedderMojoBehaviour method shouldNotIgnoreFailureInUnpackingViewResources.
@Test(expected = MojoExecutionException.class)
public void shouldNotIgnoreFailureInUnpackingViewResources() throws MojoExecutionException, MojoFailureException, NoSuchArchiverException, ArchiverException {
// Given
UnpackViewResources mojo = new UnpackViewResources() {
@Override
protected Embedder newEmbedder() {
return new Embedder();
}
};
ArchiverManager archiveManager = mock(ArchiverManager.class);
MavenProject project = mock(MavenProject.class);
File coreFile = new File("core");
Artifact coreResources = mock(Artifact.class);
when(coreResources.getArtifactId()).thenReturn("jbehave-core");
when(coreResources.getType()).thenReturn("zip");
when(coreResources.getFile()).thenReturn(coreFile);
File siteFile = new File("site");
Artifact siteResources = mock(Artifact.class);
when(siteResources.getArtifactId()).thenReturn("jbehave-site-resources");
when(siteResources.getType()).thenReturn("zip");
when(siteResources.getFile()).thenReturn(siteFile);
Set<Artifact> allArtifacts = new HashSet<>();
allArtifacts.add(coreResources);
allArtifacts.add(siteResources);
String buildDirectory = "target";
Build build = new Build();
build.setDirectory(buildDirectory);
UnArchiver coreArchiver = mock(UnArchiver.class);
UnArchiver siteArchiver = mock(UnArchiver.class);
// When
mojo.project = project;
mojo.archiverManager = archiveManager;
when(project.getArtifacts()).thenReturn(allArtifacts);
when(project.getBuild()).thenReturn(build);
when(archiveManager.getUnArchiver(coreFile)).thenReturn(coreArchiver);
when(archiveManager.getUnArchiver(siteFile)).thenReturn(siteArchiver);
Mockito.doThrow(new ArchiverException("bum")).when(siteArchiver).extract();
mojo.execute();
// Then
verify(coreArchiver).extract();
// and fail as expected ...
}
Aggregations