Search in sources :

Example 6 with ArchiveCreationException

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

the class DefaultDependencyResolver method updateModuleSetResolutionRequirements.

void updateModuleSetResolutionRequirements(AssemblyId assemblyId, ModuleSet set, DependencySet dependencySet, final ResolutionManagementInfo requirements, final AssemblerConfigurationSource configSource) throws DependencyResolutionException {
    final ModuleBinaries binaries = set.getBinaries();
    if (binaries != null) {
        Set<MavenProject> projects;
        try {
            projects = ModuleSetAssemblyPhase.getModuleProjects(set, configSource, getLogger());
        } catch (final ArchiveCreationException e) {
            throw new DependencyResolutionException("Error determining project-set for moduleSet with binaries.", e);
        }
        if (!projects.isEmpty()) {
            for (final MavenProject p : projects) {
                requirements.enableProjectResolution(p);
                if (p.getArtifact() == null) {
                    // TODO: such a call in MavenMetadataSource too - packaging not really the intention of
                    // type
                    final Artifact artifact = resolver.createArtifact(p.getGroupId(), p.getArtifactId(), p.getVersion(), p.getPackaging());
                    p.setArtifact(artifact);
                }
            }
        }
        if (binaries.isIncludeDependencies()) {
            updateDependencySetResolutionRequirements(dependencySet, requirements, assemblyId, configSource.getMavenSession().getProjectBuildingRequest(), projects.toArray(new MavenProject[projects.size()]));
        }
    }
}
Also used : ModuleBinaries(org.apache.maven.plugins.assembly.model.ModuleBinaries) MavenProject(org.apache.maven.project.MavenProject) ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException) Artifact(org.apache.maven.artifact.Artifact)

Example 7 with ArchiveCreationException

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

the class AddFileSetsTaskTest method testExecute_ShouldThrowExceptionIfArchiveBasedirProvidedIsNotADirectory.

public void testExecute_ShouldThrowExceptionIfArchiveBasedirProvidedIsNotADirectory() throws AssemblyFormattingException, IOException {
    macTask.archiveBaseDir = fileManager.createTempFile();
    macTask.expectGetArchiveBaseDirectory();
    mockManager.replayAll();
    final AddFileSetsTask task = new AddFileSetsTask(new ArrayList<FileSet>());
    try {
        task.execute(macTask.archiver, macTask.configSource);
        fail("Should throw exception due to non-directory archiveBasedir location that was provided.");
    } catch (final ArchiveCreationException e) {
    // should do this, because it cannot use the provide archiveBasedir.
    }
    mockManager.verifyAll();
}
Also used : FileSet(org.apache.maven.plugins.assembly.model.FileSet) ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException) MockAndControlForAddFileSetsTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddFileSetsTask)

Example 8 with ArchiveCreationException

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

the class AddFileSetsTaskTest method testExecute_ShouldThrowExceptionIfArchiveBasedirProvidedIsNonExistent.

public void testExecute_ShouldThrowExceptionIfArchiveBasedirProvidedIsNonExistent() throws AssemblyFormattingException {
    macTask.archiveBaseDir.delete();
    macTask.expectGetArchiveBaseDirectory();
    mockManager.replayAll();
    final AddFileSetsTask task = new AddFileSetsTask(new ArrayList<FileSet>());
    try {
        task.execute(macTask.archiver, macTask.configSource);
        fail("Should throw exception due to non-existent archiveBasedir location that was provided.");
    } catch (final ArchiveCreationException e) {
    // should do this, because it cannot use the provide archiveBasedir.
    }
    mockManager.verifyAll();
}
Also used : FileSet(org.apache.maven.plugins.assembly.model.FileSet) ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException) MockAndControlForAddFileSetsTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddFileSetsTask)

Example 9 with ArchiveCreationException

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

the class AbstractAssemblyMojo method execute.

/**
     * Create the binary distribution.
     *
     * @throws org.apache.maven.plugin.MojoExecutionException
     */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (skipAssembly) {
        getLog().info("Assemblies have been skipped per configuration of the skipAssembly parameter.");
        return;
    }
    // run only at the execution root.
    if (runOnlyAtExecutionRoot && !isThisTheExecutionRoot()) {
        getLog().info("Skipping the assembly in this project because it's not the Execution Root");
        return;
    }
    List<Assembly> assemblies;
    try {
        assemblies = assemblyReader.readAssemblies(this);
    } catch (final AssemblyReadException e) {
        throw new MojoExecutionException("Error reading assemblies: " + e.getMessage(), e);
    } catch (final InvalidAssemblerConfigurationException e) {
        throw new MojoFailureException(assemblyReader, e.getMessage(), "Mojo configuration is invalid: " + e.getMessage());
    }
    // TODO: include dependencies marked for distribution under certain formats
    // TODO: how, might we plug this into an installer, such as NSIS?
    boolean warnedAboutMainProjectArtifact = false;
    for (final Assembly assembly : assemblies) {
        try {
            final String fullName = AssemblyFormatUtils.getDistributionName(assembly, this);
            List<String> effectiveFormats = formats;
            if (effectiveFormats == null || effectiveFormats.size() == 0) {
                effectiveFormats = assembly.getFormats();
            }
            if (effectiveFormats == null || effectiveFormats.size() == 0) {
                throw new MojoFailureException("No formats specified in the execution parameters or the assembly descriptor.");
            }
            for (final String format : effectiveFormats) {
                final File destFile = assemblyArchiver.createArchive(assembly, fullName, format, this, isRecompressZippedFiles(), getMergeManifestMode());
                final MavenProject project = getProject();
                final String type = project.getArtifact().getType();
                if (attach && destFile.isFile()) {
                    if (isAssemblyIdAppended()) {
                        projectHelper.attachArtifact(project, format, assembly.getId(), destFile);
                    } else if (!"pom".equals(type) && format.equals(type)) {
                        if (!warnedAboutMainProjectArtifact) {
                            final StringBuilder message = new StringBuilder();
                            message.append("Configuration option 'appendAssemblyId' is set to false.");
                            message.append("\nInstead of attaching the assembly file: ").append(destFile);
                            message.append(", it will become the file for main project artifact.");
                            message.append("\nNOTE: If multiple descriptors or descriptor-formats are provided " + "for this project, the value of this file will be " + "non-deterministic!");
                            getLog().warn(message);
                            warnedAboutMainProjectArtifact = true;
                        }
                        final File existingFile = project.getArtifact().getFile();
                        if ((existingFile != null) && existingFile.exists()) {
                            getLog().warn("Replacing pre-existing project main-artifact file: " + existingFile + "\nwith assembly file: " + destFile);
                        }
                        project.getArtifact().setFile(destFile);
                    } else {
                        projectHelper.attachArtifact(project, format, null, destFile);
                    }
                } else if (attach) {
                    getLog().warn("Assembly file: " + destFile + " is not a regular file (it may be a directory). " + "It cannot be attached to the project build for installation or " + "deployment.");
                }
            }
        } catch (final ArchiveCreationException e) {
            throw new MojoExecutionException("Failed to create assembly: " + e.getMessage(), e);
        } catch (final AssemblyFormattingException e) {
            throw new MojoExecutionException("Failed to create assembly: " + e.getMessage(), e);
        } catch (final InvalidAssemblerConfigurationException e) {
            throw new MojoFailureException(assembly, "Assembly is incorrectly configured: " + assembly.getId(), "Assembly: " + assembly.getId() + " is not configured correctly: " + e.getMessage());
        }
    }
}
Also used : AssemblyFormattingException(org.apache.maven.plugins.assembly.format.AssemblyFormattingException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) AssemblyReadException(org.apache.maven.plugins.assembly.io.AssemblyReadException) InvalidAssemblerConfigurationException(org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException) MavenProject(org.apache.maven.project.MavenProject) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 10 with ArchiveCreationException

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

the class AddArtifactTask method moveArtifactSomewhereElse.

private File moveArtifactSomewhereElse(AssemblerConfigurationSource configSource) throws ArchiveCreationException {
    final File tempRoot = configSource.getTemporaryRootDirectory();
    final File tempArtifactFile = new File(tempRoot, artifact.getFile().getName());
    logger.warn("Artifact: " + artifact.getId() + " references the same file as the assembly destination file. " + "Moving it to a temporary location for inclusion.");
    try {
        FileUtils.copyFile(artifact.getFile(), tempArtifactFile);
    } catch (final IOException e) {
        throw new ArchiveCreationException("Error moving artifact file: '" + artifact.getFile() + "' to temporary location: " + tempArtifactFile + ". Reason: " + e.getMessage(), e);
    }
    return tempArtifactFile;
}
Also used : ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException) IOException(java.io.IOException) 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