use of org.codehaus.plexus.archiver.manager.ArchiverManager in project sling by apache.
the class PreparePackageMojoTest method getMojoUnderTest.
private PreparePackageMojo getMojoUnderTest(String... knownArtifacts) throws Exception {
File mrr = getMavenRepoRoot();
ArtifactHandler ah = Mockito.mock(ArtifactHandler.class);
ArtifactHandlerManager ahm = Mockito.mock(ArtifactHandlerManager.class);
Mockito.when(ahm.getArtifactHandler(Mockito.anyString())).thenReturn(ah);
Set<org.apache.maven.artifact.Artifact> artifacts = new HashSet<>();
for (String s : knownArtifacts) {
String[] parts = s.split("[/]");
switch(parts.length) {
case 3:
artifacts.add(getMavenArtifact(mrr, ah, parts[0], parts[1], parts[2]));
break;
case 4:
artifacts.add(getMavenArtifact(mrr, ah, parts[0], parts[1], parts[2], parts[3]));
break;
default:
throw new IllegalStateException(s);
}
}
MavenProject mavenPrj = new MavenProject();
Build build = new Build();
Path tempDir = Files.createTempDirectory(getClass().getSimpleName());
build.setOutputDirectory(tempDir.toString());
build.setDirectory(tempDir.toString());
mavenPrj.setBuild(build);
mavenPrj.setDependencyArtifacts(artifacts);
PreparePackageMojo ppm = new PreparePackageMojo();
ppm.mavenSession = Mockito.mock(MavenSession.class);
ppm.project = mavenPrj;
ArchiverManager am = Mockito.mock(ArchiverManager.class);
UnArchiver ua = Mockito.mock(UnArchiver.class);
Mockito.when(am.getUnArchiver(Mockito.isA(File.class))).thenReturn(ua);
setPrivateField(ppm, "archiverManager", am);
setPrivateField(ppm, "artifactHandlerManager", ahm);
setPrivateField(ppm, "resolver", Mockito.mock(ArtifactResolver.class));
return ppm;
}
use of org.codehaus.plexus.archiver.manager.ArchiverManager in project jbehave-core by jbehave.
the class EmbedderMojoBehaviour method shouldNotUnpackViewResourcesThatDoNotMatchTheFilters.
@Test
public void shouldNotUnpackViewResourcesThatDoNotMatchTheFilters() 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 resourcesFile = new File("some");
Artifact someResources = mock(Artifact.class);
when(someResources.getArtifactId()).thenReturn("some-resources");
when(someResources.getType()).thenReturn("jar");
when(someResources.getFile()).thenReturn(resourcesFile);
Set<Artifact> allArtifacts = new HashSet<>();
allArtifacts.add(someResources);
String buildDirectory = "target";
Build build = new Build();
build.setDirectory(buildDirectory);
// When
mojo.project = project;
mojo.archiverManager = archiveManager;
mojo.resourceIncludes = "ftl/*";
mojo.resourcesExcludes = "com/*";
when(project.getArtifacts()).thenReturn(allArtifacts);
when(project.getBuild()).thenReturn(build);
mojo.execute();
// Then
verify(archiveManager, Mockito.never()).getUnArchiver(resourcesFile);
}
use of org.codehaus.plexus.archiver.manager.ArchiverManager in project jbehave-core by jbehave.
the class EmbedderMojoBehaviour method shouldUnpackViewResources.
@Test
public void shouldUnpackViewResources() 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;
mojo.resourceIncludes = "ftl/*";
mojo.resourcesExcludes = "com/*";
when(project.getArtifacts()).thenReturn(allArtifacts);
when(project.getBuild()).thenReturn(build);
when(archiveManager.getUnArchiver(coreFile)).thenReturn(coreArchiver);
when(archiveManager.getUnArchiver(siteFile)).thenReturn(siteArchiver);
// default view directory
unpackTo(mojo, null);
unpackTo(mojo, new File(System.getProperty("java.io.tmpdir") + "/jbehave/view"));
// Then
verify(coreArchiver, times(2)).extract();
verify(siteArchiver, times(2)).extract();
}
use of org.codehaus.plexus.archiver.manager.ArchiverManager 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 ...
}
use of org.codehaus.plexus.archiver.manager.ArchiverManager 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();
}
Aggregations