Search in sources :

Example 11 with ArchiveCreationException

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

the class AddDependencySetsTask method addNonArchiveDependency.

private void addNonArchiveDependency(final Artifact depArtifact, final MavenProject depProject, final DependencySet dependencySet, final Archiver archiver, final AssemblerConfigurationSource configSource) throws AssemblyFormattingException, ArchiveCreationException {
    final File source = depArtifact.getFile();
    String outputDirectory = dependencySet.getOutputDirectory();
    FixedStringSearchInterpolator moduleProjectInterpolator = AssemblyFormatUtils.moduleProjectInterpolator(moduleProject);
    FixedStringSearchInterpolator artifactProjectInterpolator = AssemblyFormatUtils.artifactProjectInterpolator(depProject);
    outputDirectory = AssemblyFormatUtils.getOutputDirectory(outputDirectory, depProject.getBuild().getFinalName(), configSource, moduleProjectInterpolator, artifactProjectInterpolator);
    final String destName = AssemblyFormatUtils.evaluateFileNameMapping(dependencySet.getOutputFileNameMapping(), depArtifact, configSource.getProject(), moduleArtifact, configSource, moduleProjectInterpolator, artifactProjectInterpolator);
    String target;
    // omit the last char if ends with / or \\
    if (outputDirectory.endsWith("/") || outputDirectory.endsWith("\\")) {
        target = outputDirectory + destName;
    } else {
        target = outputDirectory + "/" + destName;
    }
    try {
        final int mode = TypeConversionUtils.modeToInt(dependencySet.getFileMode(), logger);
        if (mode > -1) {
            archiver.addFile(source, target, mode);
        } else {
            archiver.addFile(source, target);
        }
    } catch (final ArchiverException e) {
        throw new ArchiveCreationException("Error adding file to archive: " + e.getMessage(), e);
    }
}
Also used : FixedStringSearchInterpolator(org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException) File(java.io.File)

Example 12 with ArchiveCreationException

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

the class AddDirectoryTask method execute.

public void execute(final Archiver archiver) throws ArchiveCreationException {
    if (".".equals(outputDirectory)) {
        outputDirectory = "";
    } else if ("..".equals(outputDirectory)) {
        throw new ArchiveCreationException("Cannot add source directory: " + directory + " to archive-path: " + outputDirectory + ". All paths must be within the archive root directory.");
    }
    final int oldDirMode = archiver.getOverrideDirectoryMode();
    final int oldFileMode = archiver.getOverrideFileMode();
    boolean fileModeSet = false;
    boolean dirModeSet = false;
    try {
        if (directoryMode != -1) {
            archiver.setDirectoryMode(directoryMode);
            dirModeSet = true;
        }
        if (fileMode != -1) {
            archiver.setFileMode(fileMode);
            fileModeSet = true;
        }
        if (directory.exists()) {
            List<String> directoryExcludes;
            if (excludes != null && !excludes.isEmpty()) {
                directoryExcludes = new ArrayList<String>(excludes);
            } else {
                directoryExcludes = new ArrayList<String>();
            }
            try {
                String[] includesArray = null;
                if (includes != null && !includes.isEmpty()) {
                    includesArray = new String[includes.size()];
                    int i = 0;
                    for (String include : includes) {
                        includesArray[i++] = normalize(include);
                    }
                }
                // this one is guaranteed to be non-null by code above.
                final String[] excludesArray = new String[directoryExcludes.size()];
                int i = 0;
                for (String directoryExclude : directoryExcludes) {
                    excludesArray[i++] = normalize(directoryExclude);
                }
                final DefaultFileSet fs = new DefaultFileSet();
                fs.setUsingDefaultExcludes(useDefaultExcludes);
                fs.setPrefix(outputDirectory);
                fs.setDirectory(directory);
                fs.setIncludes(includesArray);
                fs.setExcludes(excludesArray);
                if (transformer != null) {
                    fs.setStreamTransformer(transformer);
                }
                archiver.addFileSet(fs);
            } catch (final ArchiverException e) {
                throw new ArchiveCreationException("Error adding directory to archive: " + e.getMessage(), e);
            }
        }
    } finally {
        if (dirModeSet) {
            archiver.setDirectoryMode(oldDirMode);
        }
        if (fileModeSet) {
            archiver.setFileMode(oldFileMode);
        }
    }
}
Also used : DefaultFileSet(org.codehaus.plexus.archiver.util.DefaultFileSet) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException)

Example 13 with ArchiveCreationException

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

the class ModuleSetAssemblyPhase method getModuleProjects.

@Nonnull
public static Set<MavenProject> getModuleProjects(final ModuleSet moduleSet, final AssemblerConfigurationSource configSource, final Logger logger) throws ArchiveCreationException {
    MavenProject project = configSource.getProject();
    Set<MavenProject> moduleProjects = null;
    if (moduleSet.isUseAllReactorProjects()) {
        if (!moduleSet.isIncludeSubModules()) {
            moduleProjects = new LinkedHashSet<MavenProject>(configSource.getReactorProjects());
        }
        project = configSource.getReactorProjects().get(0);
    }
    if (moduleProjects == null) {
        try {
            moduleProjects = ProjectUtils.getProjectModules(project, configSource.getReactorProjects(), moduleSet.isIncludeSubModules(), logger);
        } catch (final IOException e) {
            throw new ArchiveCreationException("Error retrieving module-set for project: " + project.getId() + ": " + e.getMessage(), e);
        }
    }
    return FilterUtils.filterProjects(moduleProjects, moduleSet.getIncludes(), moduleSet.getExcludes(), true, logger);
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException) IOException(java.io.IOException) Nonnull(javax.annotation.Nonnull)

Example 14 with ArchiveCreationException

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

the class ModuleSetAssemblyPhase method addModuleArtifact.

void addModuleArtifact(final Artifact artifact, final MavenProject project, final Archiver archiver, final AssemblerConfigurationSource configSource, final ModuleBinaries binaries) throws ArchiveCreationException, AssemblyFormattingException {
    if (artifact.getFile() == null) {
        throw new ArchiveCreationException("Artifact: " + artifact.getId() + " (included by module) does not have an artifact with a file. " + "Please ensure the package phase is run before the assembly is generated.");
    }
    final AddArtifactTask task = new AddArtifactTask(artifact, getLogger(), null);
    task.setFileNameMapping(binaries.getOutputFileNameMapping());
    task.setOutputDirectory(binaries.getOutputDirectory());
    task.setProject(project);
    task.setModuleProject(project);
    task.setModuleArtifact(artifact);
    final int dirMode = TypeConversionUtils.modeToInt(binaries.getDirectoryMode(), getLogger());
    if (dirMode != -1) {
        task.setDirectoryMode(dirMode);
    }
    final int fileMode = TypeConversionUtils.modeToInt(binaries.getFileMode(), getLogger());
    if (fileMode != -1) {
        task.setFileMode(fileMode);
    }
    task.setUnpack(binaries.isUnpack());
    if (binaries.isUnpack() && binaries.getUnpackOptions() != null) {
        task.setIncludes(binaries.getUnpackOptions().getIncludes());
        task.setExcludes(binaries.getUnpackOptions().getExcludes());
    }
    task.execute(archiver, configSource);
}
Also used : ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException) AddArtifactTask(org.apache.maven.plugins.assembly.archive.task.AddArtifactTask)

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