Search in sources :

Example 1 with AssemblyReadException

use of org.apache.maven.plugins.assembly.io.AssemblyReadException 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)

Aggregations

File (java.io.File)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 InvalidAssemblerConfigurationException (org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException)1 ArchiveCreationException (org.apache.maven.plugins.assembly.archive.ArchiveCreationException)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 MavenProject (org.apache.maven.project.MavenProject)1