Search in sources :

Example 16 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project maven-plugins by apache.

the class SimpleAggregatingDescriptorHandler method finalizeArchiveCreation.

@Override
public void finalizeArchiveCreation(final Archiver archiver) {
    checkConfig();
    if (outputPath.endsWith("/")) {
        throw new ArchiverException("Cannot write aggregated properties to a directory. " + "You must specify a file name in the outputPath configuration for this" + " handler. (handler: " + getClass().getName());
    }
    if (outputPath.startsWith("/")) {
        outputPath = outputPath.substring(1);
    }
    final File temp = writePropertiesFile();
    overrideFilterAction = true;
    archiver.addFile(temp, outputPath);
    overrideFilterAction = false;
}
Also used : ArchiverException(org.codehaus.plexus.archiver.ArchiverException) File(java.io.File)

Example 17 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException 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 18 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project maven-plugins by apache.

the class AssemblyFileUtils method unpack.

/**
     * Unpacks the archive file.
     *
     * @param source  File to be unpacked.
     * @param destDir Location where to put the unpacked files.
     */
public static void unpack(File source, File destDir, ArchiverManager archiverManager) throws ArchiveExpansionException, NoSuchArchiverException {
    try {
        UnArchiver unArchiver = archiverManager.getUnArchiver(source);
        unArchiver.setSourceFile(source);
        unArchiver.setDestDirectory(destDir);
        unArchiver.extract();
    } catch (ArchiverException e) {
        throw new ArchiveExpansionException("Error unpacking file: " + source + "to: " + destDir, e);
    }
}
Also used : ArchiverException(org.codehaus.plexus.archiver.ArchiverException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) ArchiveExpansionException(org.apache.maven.plugins.assembly.archive.ArchiveExpansionException) UnArchiver(org.codehaus.plexus.archiver.UnArchiver)

Example 19 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project maven-plugins by apache.

the class AddArtifactTaskTest method testShouldAddArchiveFileWithUnpackAndModes.

public void testShouldAddArchiveFileWithUnpackAndModes() throws ArchiveCreationException, AssemblyFormattingException, IOException {
    int directoryMode = TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test"));
    int fileMode = TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test"));
    mac.expectModeChange(-1, -1, directoryMode, fileMode, 2);
    mac.expectInterpolators();
    ArtifactMock artifactMock = new ArtifactMock(mockManager, "group", "artifact", "version", "jar", false);
    artifactMock.setNewFile();
    mac.expectGetDestFile(new File("junk"));
    try {
        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.setDirectoryMode(directoryMode);
    task.setFileMode(fileMode);
    task.execute(mac.archiver, mac.configSource);
    mockManager.verifyAll();
}
Also used : ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) MockAndControlForAddArtifactTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddArtifactTask) ArtifactMock(org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock) File(java.io.File)

Example 20 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project maven-plugins by apache.

the class EjbMojo method generateEjbClient.

private File generateEjbClient() throws MojoExecutionException {
    File clientJarFile = EjbHelper.getJarFile(outputDirectory, jarName, getClientClassifier());
    getLog().info("Building EJB client " + clientJarFile.getPath());
    MavenArchiver clientArchiver = new MavenArchiver();
    clientArchiver.setArchiver(clientJarArchiver);
    clientArchiver.setOutputFile(clientJarFile);
    try {
        List<String> defaultExcludes = DEFAULT_CLIENT_EXCLUDES_LIST;
        List<String> defaultIncludes = DEFAULT_INCLUDES_LIST;
        IncludesExcludes ie = new IncludesExcludes(clientIncludes, clientExcludes, defaultIncludes, defaultExcludes);
        clientArchiver.getArchiver().addDirectory(sourceDirectory, ie.resultingIncludes(), ie.resultingExcludes());
        clientArchiver.createArchive(session, project, archive);
    } catch (ArchiverException e) {
        throw new MojoExecutionException("There was a problem creating the EJB client archive: " + e.getMessage(), e);
    } catch (ManifestException e) {
        throw new MojoExecutionException("There was a problem creating the EJB client archive: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new MojoExecutionException("There was a problem creating the EJB client archive: " + e.getMessage(), e);
    } catch (DependencyResolutionRequiredException e) {
        throw new MojoExecutionException("There was a problem creating the EJB client archive: " + e.getMessage(), e);
    }
    return clientJarFile;
}
Also used : DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) MavenArchiver(org.apache.maven.archiver.MavenArchiver) IOException(java.io.IOException) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) File(java.io.File)

Aggregations

ArchiverException (org.codehaus.plexus.archiver.ArchiverException)51 File (java.io.File)33 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)26 IOException (java.io.IOException)25 NoSuchArchiverException (org.codehaus.plexus.archiver.manager.NoSuchArchiverException)17 UnArchiver (org.codehaus.plexus.archiver.UnArchiver)9 Artifact (org.apache.maven.artifact.Artifact)8 ManifestException (org.codehaus.plexus.archiver.jar.ManifestException)8 DependencyResolutionRequiredException (org.apache.maven.artifact.DependencyResolutionRequiredException)7 MavenArchiver (org.apache.maven.archiver.MavenArchiver)6 ArchiveCreationException (org.apache.maven.plugins.assembly.archive.ArchiveCreationException)5 ArrayList (java.util.ArrayList)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)3 Archiver (org.codehaus.plexus.archiver.Archiver)3 JarArchiver (org.codehaus.plexus.archiver.jar.JarArchiver)3 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 FileWriter (java.io.FileWriter)2 OutputStreamWriter (java.io.OutputStreamWriter)2 PrintWriter (java.io.PrintWriter)2