Search in sources :

Example 1 with ArchiveCreationException

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

the class ModuleSetAssemblyPhaseTest method testAddModuleArtifact_ShouldThrowExceptionWhenArtifactFileIsNull.

public void testAddModuleArtifact_ShouldThrowExceptionWhenArtifactFileIsNull() throws AssemblyFormattingException, IOException {
    final EasyMockSupport mm = new EasyMockSupport();
    final ArtifactMock artifactMock = new ArtifactMock(mm, "group", "artifact", "version", "type", false);
    artifactMock.setNullFile();
    mm.replayAll();
    try {
        createPhase(new ConsoleLogger(Logger.LEVEL_DEBUG, "test"), null).addModuleArtifact(artifactMock.getArtifact(), null, null, null, null);
        fail("Expected ArchiveCreationException since artifact file is null.");
    } catch (final ArchiveCreationException e) {
    // expected
    }
    mm.verifyAll();
}
Also used : EasyMockSupport(org.easymock.classextension.EasyMockSupport) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException) ArtifactMock(org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock)

Example 2 with ArchiveCreationException

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

the class FileItemAssemblyPhase method execute.

/**
     * {@inheritDoc}
     */
@Override
public void execute(final Assembly assembly, final Archiver archiver, final AssemblerConfigurationSource configSource) throws ArchiveCreationException, AssemblyFormattingException {
    final List<FileItem> fileList = assembly.getFiles();
    final File basedir = configSource.getBasedir();
    for (final FileItem fileItem : fileList) {
        final String sourcePath = fileItem.getSource();
        // ensure source file is in absolute path for reactor build to work
        File source = new File(sourcePath);
        // save the original sourcefile's name, because filtration may
        // create a temp file with a different name.
        final String sourceName = source.getName();
        if (!source.isAbsolute()) {
            source = new File(basedir, sourcePath);
        }
        String destName = fileItem.getDestName();
        if (destName == null) {
            destName = sourceName;
        }
        final String outputDirectory1 = fileItem.getOutputDirectory();
        AssemblyFormatUtils.warnForPlatformSpecifics(getLogger(), outputDirectory1);
        final String outputDirectory = AssemblyFormatUtils.getOutputDirectory(outputDirectory1, configSource.getFinalName(), configSource, AssemblyFormatUtils.moduleProjectInterpolator(configSource.getProject()), AssemblyFormatUtils.artifactProjectInterpolator(null));
        String target;
        // omit the last char if ends with / or \\
        if (outputDirectory.endsWith("/") || outputDirectory.endsWith("\\")) {
            target = outputDirectory + destName;
        } else if (outputDirectory.length() < 1) {
            target = destName;
        } else {
            target = outputDirectory + "/" + destName;
        }
        try {
            final InputStreamTransformer fileSetTransformers = ReaderFormatter.getFileSetTransformers(configSource, fileItem.isFiltered(), fileItem.getLineEnding());
            final PlexusIoResource restoUse = createResource(source, fileSetTransformers);
            int mode = TypeConversionUtils.modeToInt(fileItem.getFileMode(), getLogger());
            archiver.addResource(restoUse, target, mode);
        } catch (final ArchiverException e) {
            throw new ArchiveCreationException("Error adding file to archive: " + e.getMessage(), e);
        } catch (IOException e) {
            throw new ArchiveCreationException("Error adding file to archive: " + e.getMessage(), e);
        }
    }
}
Also used : FileItem(org.apache.maven.plugins.assembly.model.FileItem) PlexusIoResource(org.codehaus.plexus.components.io.resources.PlexusIoResource) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException) InputStreamTransformer(org.codehaus.plexus.components.io.functions.InputStreamTransformer) IOException(java.io.IOException) File(java.io.File)

Example 3 with ArchiveCreationException

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

the class RepositoryAssemblyPhase method execute.

/**
     * {@inheritDoc}
     */
@Override
@SuppressWarnings("ResultOfMethodCallIgnored")
public void execute(final Assembly assembly, final Archiver archiver, final AssemblerConfigurationSource configSource) throws ArchiveCreationException, AssemblyFormattingException, InvalidAssemblerConfigurationException {
    final List<Repository> repositoriesList = assembly.getRepositories();
    final File tempRoot = configSource.getTemporaryRootDirectory();
    for (final Repository repository : repositoriesList) {
        final String outputDirectory = AssemblyFormatUtils.getOutputDirectory(repository.getOutputDirectory(), configSource.getFinalName(), configSource, AssemblyFormatUtils.moduleProjectInterpolator(configSource.getProject()), AssemblyFormatUtils.artifactProjectInterpolator(null));
        final File repositoryDirectory = new File(tempRoot, outputDirectory);
        if (!repositoryDirectory.exists()) {
            repositoryDirectory.mkdirs();
        }
        try {
            getLogger().debug("Assembling repository to: " + repositoryDirectory);
            repositoryAssembler.buildRemoteRepository(repositoryDirectory, wrap(repository), wrap(configSource));
            getLogger().debug("Finished assembling repository to: " + repositoryDirectory);
        } catch (final RepositoryAssemblyException e) {
            throw new ArchiveCreationException("Failed to assemble repository: " + e.getMessage(), e);
        }
        final AddDirectoryTask task = new AddDirectoryTask(repositoryDirectory);
        final int dirMode = TypeConversionUtils.modeToInt(repository.getDirectoryMode(), getLogger());
        if (dirMode != -1) {
            task.setDirectoryMode(dirMode);
        }
        final int fileMode = TypeConversionUtils.modeToInt(repository.getFileMode(), getLogger());
        if (fileMode != -1) {
            task.setFileMode(fileMode);
        }
        task.setOutputDirectory(outputDirectory);
        task.execute(archiver);
    }
}
Also used : Repository(org.apache.maven.plugins.assembly.model.Repository) RepositoryAssemblyException(org.apache.maven.plugins.assembly.repository.RepositoryAssemblyException) ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException) AddDirectoryTask(org.apache.maven.plugins.assembly.archive.task.AddDirectoryTask) File(java.io.File)

Example 4 with ArchiveCreationException

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

the class AddArtifactTask method asFile.

private void asFile(Archiver archiver, AssemblerConfigurationSource configSource, String destDirectory) throws AssemblyFormattingException, ArchiveCreationException {
    final String tempMapping = AssemblyFormatUtils.evaluateFileNameMapping(outputFileNameMapping, artifact, configSource.getProject(), moduleArtifact, configSource, AssemblyFormatUtils.moduleProjectInterpolator(moduleProject), AssemblyFormatUtils.artifactProjectInterpolator(project));
    final String outputLocation = destDirectory + tempMapping;
    try {
        final File artifactFile = artifact.getFile();
        logger.debug("Adding artifact: " + artifact.getId() + " with file: " + artifactFile + " to assembly location: " + outputLocation + ".");
        if (fileMode != -1) {
            archiver.addFile(artifactFile, outputLocation, fileMode);
        } else {
            archiver.addFile(artifactFile, outputLocation);
        }
    } catch (final ArchiverException e) {
        throw new ArchiveCreationException("Error adding file '" + artifact.getId() + "' to archive: " + e.getMessage(), e);
    }
}
Also used : ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException) File(java.io.File)

Example 5 with ArchiveCreationException

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

the class AddArtifactTask method unpacked.

private void unpacked(Archiver archiver, String destDirectory) throws ArchiveCreationException {
    String outputLocation = destDirectory;
    if ((outputLocation.length() > 0) && !outputLocation.endsWith("/")) {
        outputLocation += "/";
    }
    String[] includesArray = TypeConversionUtils.toStringArray(includes);
    if (includesArray == null) {
        includesArray = DEFAULT_INCLUDES_ARRAY;
    }
    final String[] excludesArray = TypeConversionUtils.toStringArray(excludes);
    try {
        final File artifactFile = artifact.getFile();
        if (artifactFile == null) {
            logger.warn("Skipping artifact: " + artifact.getId() + "; it does not have an associated file or directory.");
        } else if (artifactFile.isDirectory()) {
            logger.debug("Adding artifact directory contents for: " + artifact + " to: " + outputLocation);
            DefaultFileSet fs = DefaultFileSet.fileSet(artifactFile);
            fs.setIncludes(includesArray);
            fs.setExcludes(excludesArray);
            fs.setPrefix(outputLocation);
            fs.setStreamTransformer(transformer);
            archiver.addFileSet(fs);
        } else {
            logger.debug("Unpacking artifact contents for: " + artifact + " to: " + outputLocation);
            logger.debug("includes:\n" + StringUtils.join(includesArray, "\n") + "\n");
            logger.debug("excludes:\n" + (excludesArray == null ? "none" : StringUtils.join(excludesArray, "\n")) + "\n");
            DefaultArchivedFileSet afs = DefaultArchivedFileSet.archivedFileSet(artifactFile);
            afs.setIncludes(includesArray);
            afs.setExcludes(excludesArray);
            afs.setPrefix(outputLocation);
            afs.setStreamTransformer(transformer);
            archiver.addArchivedFileSet(afs, encoding);
        }
    } catch (final ArchiverException e) {
        throw new ArchiveCreationException("Error adding file-set for '" + artifact.getId() + "' to archive: " + e.getMessage(), e);
    }
}
Also used : DefaultFileSet(org.codehaus.plexus.archiver.util.DefaultFileSet) DefaultArchivedFileSet(org.codehaus.plexus.archiver.util.DefaultArchivedFileSet) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException) File(java.io.File)

Aggregations

ArchiveCreationException (org.apache.maven.plugins.assembly.archive.ArchiveCreationException)14 File (java.io.File)7 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)5 IOException (java.io.IOException)3 MavenProject (org.apache.maven.project.MavenProject)3 MockAndControlForAddFileSetsTask (org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddFileSetsTask)2 FileSet (org.apache.maven.plugins.assembly.model.FileSet)2 DefaultFileSet (org.codehaus.plexus.archiver.util.DefaultFileSet)2 Nonnull (javax.annotation.Nonnull)1 Artifact (org.apache.maven.artifact.Artifact)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 InvalidAssemblerConfigurationException (org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException)1 AddArtifactTask (org.apache.maven.plugins.assembly.archive.task.AddArtifactTask)1 AddDirectoryTask (org.apache.maven.plugins.assembly.archive.task.AddDirectoryTask)1 ArtifactMock (org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock)1 AssemblyFormattingException (org.apache.maven.plugins.assembly.format.AssemblyFormattingException)1 AssemblyReadException (org.apache.maven.plugins.assembly.io.AssemblyReadException)1 Assembly (org.apache.maven.plugins.assembly.model.Assembly)1 FileItem (org.apache.maven.plugins.assembly.model.FileItem)1