Search in sources :

Example 1 with ArchiverManager

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;
}
Also used : Path(java.nio.file.Path) ArchiverManager(org.codehaus.plexus.archiver.manager.ArchiverManager) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) ArtifactResolver(org.apache.maven.artifact.resolver.ArtifactResolver) MavenSession(org.apache.maven.execution.MavenSession) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) MavenProject(org.apache.maven.project.MavenProject) Build(org.apache.maven.model.Build) ArtifactHandlerManager(org.apache.maven.artifact.handler.manager.ArtifactHandlerManager) JarFile(java.util.jar.JarFile) File(java.io.File) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) HashSet(java.util.HashSet)

Example 2 with ArchiverManager

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);
}
Also used : ArchiverManager(org.codehaus.plexus.archiver.manager.ArchiverManager) MavenProject(org.apache.maven.project.MavenProject) Build(org.apache.maven.model.Build) Embedder(org.jbehave.core.embedder.Embedder) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with ArchiverManager

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();
}
Also used : ArchiverManager(org.codehaus.plexus.archiver.manager.ArchiverManager) MavenProject(org.apache.maven.project.MavenProject) Build(org.apache.maven.model.Build) Embedder(org.jbehave.core.embedder.Embedder) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with ArchiverManager

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 ...
}
Also used : ArchiverManager(org.codehaus.plexus.archiver.manager.ArchiverManager) MavenProject(org.apache.maven.project.MavenProject) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) Build(org.apache.maven.model.Build) Embedder(org.jbehave.core.embedder.Embedder) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with ArchiverManager

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();
}
Also used : EasyMockSupport(org.easymock.classextension.EasyMockSupport) ArchiverManager(org.codehaus.plexus.archiver.manager.ArchiverManager) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) File(java.io.File) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException)

Aggregations

File (java.io.File)5 ArchiverManager (org.codehaus.plexus.archiver.manager.ArchiverManager)5 HashSet (java.util.HashSet)4 Build (org.apache.maven.model.Build)4 MavenProject (org.apache.maven.project.MavenProject)4 UnArchiver (org.codehaus.plexus.archiver.UnArchiver)4 Artifact (org.apache.maven.artifact.Artifact)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)3 Embedder (org.jbehave.core.embedder.Embedder)3 Test (org.junit.Test)3 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)2 NoSuchArchiverException (org.codehaus.plexus.archiver.manager.NoSuchArchiverException)2 Path (java.nio.file.Path)1 JarFile (java.util.jar.JarFile)1 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)1 ArtifactHandler (org.apache.maven.artifact.handler.ArtifactHandler)1 ArtifactHandlerManager (org.apache.maven.artifact.handler.manager.ArtifactHandlerManager)1 ArtifactResolver (org.apache.maven.artifact.resolver.ArtifactResolver)1 MavenSession (org.apache.maven.execution.MavenSession)1