Search in sources :

Example 1 with AssemblyArchiverPhase

use of org.apache.maven.plugins.assembly.archive.phase.AssemblyArchiverPhase in project maven-plugins by apache.

the class DefaultAssemblyArchiverTest method testCreateArchiver_ShouldConfigureArchiver.

@Test
public void testCreateArchiver_ShouldConfigureArchiver() throws NoSuchArchiverException, ArchiverException {
    final EasyMockSupport mm = new EasyMockSupport();
    final MockAndControlForAssemblyArchiver macArchiverManager = new MockAndControlForAssemblyArchiver(mm);
    final TestArchiverWithConfig archiver = new TestArchiverWithConfig();
    macArchiverManager.expectGetArchiver("dummy", archiver);
    final AssemblerConfigurationSource configSource = mm.createMock(AssemblerConfigurationSource.class);
    final String simpleConfig = "value";
    expect(configSource.getArchiverConfig()).andReturn("<configuration><simpleConfig>" + simpleConfig + "</simpleConfig></configuration>").anyTimes();
    final MavenProject project = new MavenProject(new Model());
    expect(configSource.getProject()).andReturn(project).anyTimes();
    expect(configSource.getMavenSession()).andReturn(null).anyTimes();
    expect(configSource.isDryRun()).andReturn(false).anyTimes();
    expect(configSource.getWorkingDirectory()).andReturn(new File(".")).anyTimes();
    expect(configSource.isUpdateOnly()).andReturn(false).anyTimes();
    final ArtifactRepository lr = mm.createMock(ArtifactRepository.class);
    expect(lr.getBasedir()).andReturn("/path/to/local/repo").anyTimes();
    expect(configSource.getLocalRepository()).andReturn(lr).anyTimes();
    expect(configSource.isIgnorePermissions()).andReturn(true);
    setupInterpolators(configSource, project);
    mm.replayAll();
    final DefaultAssemblyArchiver subject = createSubject(macArchiverManager, new ArrayList<AssemblyArchiverPhase>(), null);
    subject.createArchiver("dummy", false, "finalName", configSource, null, false, null);
    assertEquals(simpleConfig, archiver.getSimpleConfig());
    mm.verifyAll();
}
Also used : EasyMockSupport(org.easymock.classextension.EasyMockSupport) MavenProject(org.apache.maven.project.MavenProject) Model(org.apache.maven.model.Model) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) AssemblerConfigurationSource(org.apache.maven.plugins.assembly.AssemblerConfigurationSource) File(java.io.File) AssemblyArchiverPhase(org.apache.maven.plugins.assembly.archive.phase.AssemblyArchiverPhase) Test(org.junit.Test)

Example 2 with AssemblyArchiverPhase

use of org.apache.maven.plugins.assembly.archive.phase.AssemblyArchiverPhase in project maven-plugins by apache.

the class DefaultAssemblyArchiverTest method testCreateArchive.

@Test
public void testCreateArchive() throws ArchiveCreationException, AssemblyFormattingException, InvalidAssemblerConfigurationException, IOException, DependencyResolutionException {
    final EasyMockSupport mm = new EasyMockSupport();
    final MockAndControlForAssemblyArchiver macMgr = new MockAndControlForAssemblyArchiver(mm);
    macMgr.expectGetArchiver("zip", Archiver.class);
    macMgr.expectGetDestFile(new File("test"));
    final AssemblyArchiverPhase phase = mm.createControl().createMock(AssemblyArchiverPhase.class);
    phase.execute((Assembly) anyObject(), (Archiver) anyObject(), (AssemblerConfigurationSource) anyObject());
    final AssemblerConfigurationSource configSource = mm.createControl().createMock(AssemblerConfigurationSource.class);
    final File tempDir = fileManager.createTempDir();
    FileUtils.deleteDirectory(tempDir);
    expect(configSource.getTemporaryRootDirectory()).andReturn(tempDir).anyTimes();
    expect(configSource.isDryRun()).andReturn(false).anyTimes();
    expect(configSource.isIgnoreDirFormatExtensions()).andReturn(false).anyTimes();
    final File outDir = fileManager.createTempDir();
    macMgr.archiver.setDestFile(new File(outDir, "full-name.zip"));
    try {
        macMgr.archiver.createArchive();
    } catch (final ArchiverException e) {
        fail("Should never happen");
    } catch (final IOException e) {
        fail("Should never happen");
    }
    expect(configSource.getOutputDirectory()).andReturn(outDir);
    expect(configSource.getFinalName()).andReturn("finalName");
    expect(configSource.getArchiverConfig()).andReturn(null).anyTimes();
    expect(configSource.getWorkingDirectory()).andReturn(new File(".")).anyTimes();
    expect(configSource.isUpdateOnly()).andReturn(false).anyTimes();
    expect(configSource.isIgnorePermissions()).andReturn(false).anyTimes();
    final Assembly assembly = new Assembly();
    assembly.setId("id");
    // try
    // {
    // expect( macMgr.dependencyResolver.resolve( (Assembly) anyObject(), (AssemblerConfigurationSource)
    // anyObject() )).andReturn( new HashSet<Artifact>(  ) );
    // macMgr.dependencyResolverControl.setMatcher( MockControl.ALWAYS_MATCHER );
    // }
    // catch ( final DependencyResolutionException e )
    // {
    // fail( "Should never happen" );
    // }
    mm.replayAll();
    final DefaultAssemblyArchiver subject = createSubject(macMgr, Collections.singletonList(phase), null);
    subject.createArchive(assembly, "full-name", "zip", configSource, false, null);
    mm.verifyAll();
}
Also used : EasyMockSupport(org.easymock.classextension.EasyMockSupport) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) AssemblerConfigurationSource(org.apache.maven.plugins.assembly.AssemblerConfigurationSource) IOException(java.io.IOException) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly) AssemblyArchiverPhase(org.apache.maven.plugins.assembly.archive.phase.AssemblyArchiverPhase) Test(org.junit.Test)

Example 3 with AssemblyArchiverPhase

use of org.apache.maven.plugins.assembly.archive.phase.AssemblyArchiverPhase in project maven-plugins by apache.

the class DefaultAssemblyArchiver method sortedPhases.

private List<AssemblyArchiverPhase> sortedPhases() {
    List<AssemblyArchiverPhase> sorted = new ArrayList<AssemblyArchiverPhase>(assemblyPhases);
    Collections.sort(sorted, new AssemblyArchiverPhaseComparator());
    return sorted;
}
Also used : ArrayList(java.util.ArrayList) AssemblyArchiverPhaseComparator(org.apache.maven.plugins.assembly.archive.phase.AssemblyArchiverPhaseComparator) AssemblyArchiverPhase(org.apache.maven.plugins.assembly.archive.phase.AssemblyArchiverPhase)

Example 4 with AssemblyArchiverPhase

use of org.apache.maven.plugins.assembly.archive.phase.AssemblyArchiverPhase 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;
}
Also used : ContainerDescriptorHandler(org.apache.maven.plugins.assembly.filter.ContainerDescriptorHandler) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) DependencyResolutionException(org.apache.maven.plugins.assembly.artifact.DependencyResolutionException) IOException(java.io.IOException) File(java.io.File) AssemblyProxyArchiver(org.apache.maven.plugins.assembly.archive.archiver.AssemblyProxyArchiver) AbstractZipArchiver(org.codehaus.plexus.archiver.zip.AbstractZipArchiver) JarArchiver(org.codehaus.plexus.archiver.jar.JarArchiver) TarArchiver(org.codehaus.plexus.archiver.tar.TarArchiver) Archiver(org.codehaus.plexus.archiver.Archiver) DryRunArchiver(org.codehaus.plexus.archiver.diags.DryRunArchiver) WarArchiver(org.codehaus.plexus.archiver.war.WarArchiver) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) AssemblyArchiverPhase(org.apache.maven.plugins.assembly.archive.phase.AssemblyArchiverPhase)

Example 5 with AssemblyArchiverPhase

use of org.apache.maven.plugins.assembly.archive.phase.AssemblyArchiverPhase in project maven-plugins by apache.

the class DefaultAssemblyArchiverTest method testCreateWarArchiver_ShouldDisableIgnoreWebxmlOption.

@Test
public void testCreateWarArchiver_ShouldDisableIgnoreWebxmlOption() throws NoSuchArchiverException {
    final EasyMockSupport mm = new EasyMockSupport();
    final TestWarArchiver twArchiver = new TestWarArchiver();
    final MockAndControlForAssemblyArchiver macArchiverManager = new MockAndControlForAssemblyArchiver(mm);
    macArchiverManager.expectGetArchiver("war", twArchiver);
    mm.replayAll();
    final DefaultAssemblyArchiver subject = createSubject(macArchiverManager, new ArrayList<AssemblyArchiverPhase>(), null);
    subject.createWarArchiver();
    assertFalse(twArchiver.ignoreWebxml);
}
Also used : EasyMockSupport(org.easymock.classextension.EasyMockSupport) AssemblyArchiverPhase(org.apache.maven.plugins.assembly.archive.phase.AssemblyArchiverPhase) Test(org.junit.Test)

Aggregations

AssemblyArchiverPhase (org.apache.maven.plugins.assembly.archive.phase.AssemblyArchiverPhase)7 File (java.io.File)5 EasyMockSupport (org.easymock.classextension.EasyMockSupport)4 Test (org.junit.Test)4 AssemblerConfigurationSource (org.apache.maven.plugins.assembly.AssemblerConfigurationSource)3 IOException (java.io.IOException)2 Model (org.apache.maven.model.Model)2 MavenProject (org.apache.maven.project.MavenProject)2 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)2 NoSuchArchiverException (org.codehaus.plexus.archiver.manager.NoSuchArchiverException)2 ArrayList (java.util.ArrayList)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1 AssemblyProxyArchiver (org.apache.maven.plugins.assembly.archive.archiver.AssemblyProxyArchiver)1 AssemblyArchiverPhaseComparator (org.apache.maven.plugins.assembly.archive.phase.AssemblyArchiverPhaseComparator)1 DependencyResolutionException (org.apache.maven.plugins.assembly.artifact.DependencyResolutionException)1 ContainerDescriptorHandler (org.apache.maven.plugins.assembly.filter.ContainerDescriptorHandler)1 Assembly (org.apache.maven.plugins.assembly.model.Assembly)1 Archiver (org.codehaus.plexus.archiver.Archiver)1 DryRunArchiver (org.codehaus.plexus.archiver.diags.DryRunArchiver)1 JarArchiver (org.codehaus.plexus.archiver.jar.JarArchiver)1