Search in sources :

Example 6 with InvalidAssemblerConfigurationException

use of org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException in project docker-maven-plugin by fabric8io.

the class DockerAssemblyManager method createAssemblyArchive.

private void createAssemblyArchive(AssemblyConfiguration assemblyConfig, MojoParameters params, BuildDirs buildDirs) throws MojoExecutionException {
    DockerAssemblyConfigurationSource source = new DockerAssemblyConfigurationSource(params, buildDirs, assemblyConfig);
    Assembly assembly = getAssemblyConfig(assemblyConfig, source);
    AssemblyMode buildMode = assemblyConfig.getMode();
    File originalArtifactFile = null;
    try {
        originalArtifactFile = ensureThatArtifactFileIsSet(params.getProject());
        assembly.setId("docker");
        assemblyArchiver.createArchive(assembly, assemblyConfig.getName(), buildMode.getExtension(), source, false, null);
    } catch (ArchiveCreationException | AssemblyFormattingException e) {
        String error = "Failed to create assembly for docker image " + " (with mode '" + buildMode + "'): " + e.getMessage() + ".";
        if (params.getProject().getArtifact().getFile() == null) {
            error += " If you include the build artifact please ensure that you have " + "built the artifact before with 'mvn package' (should be available in the target/ dir). " + "Please see the documentation (section \"Assembly\") for more information.";
        }
        throw new MojoExecutionException(error, e);
    } catch (InvalidAssemblerConfigurationException e) {
        throw new MojoExecutionException(assembly, "Assembly is incorrectly configured: " + assembly.getId(), "Assembly: " + assembly.getId() + " is not configured correctly: " + e.getMessage());
    } finally {
        setArtifactFile(params.getProject(), originalArtifactFile);
    }
}
Also used : AssemblyFormattingException(org.apache.maven.plugins.assembly.format.AssemblyFormattingException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException) AssemblyMode(io.fabric8.maven.docker.config.AssemblyMode) InvalidAssemblerConfigurationException(org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 7 with InvalidAssemblerConfigurationException

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

the class ModuleSetAssemblyPhaseTest method testAddModuleBinaries_ShouldFailWhenOneModuleDoesntHaveAttachmentWithMatchingClassifier.

public void testAddModuleBinaries_ShouldFailWhenOneModuleDoesntHaveAttachmentWithMatchingClassifier() throws ArchiveCreationException, AssemblyFormattingException, IOException, DependencyResolutionException {
    final EasyMockSupport mm = new EasyMockSupport();
    final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask(mm);
    final ArtifactMock artifactMock = new ArtifactMock(mm, "group", "artifact", "version", "jar", "test", false);
    artifactMock.setNewFile();
    final ModuleBinaries binaries = new ModuleBinaries();
    binaries.setUnpack(false);
    binaries.setFileMode("777");
    binaries.setOutputDirectory("out");
    binaries.setOutputFileNameMapping("artifact");
    binaries.setAttachmentClassifier("test");
    final MavenProject project = createProject("group", "artifact", "version", null);
    project.setArtifact(artifactMock.getArtifact());
    final Set<MavenProject> projects = singleton(project);
    mm.replayAll();
    final Logger logger = new ConsoleLogger(Logger.LEVEL_DEBUG, "test");
    try {
        createPhase(logger, null).addModuleBinaries(null, null, binaries, projects, macTask.archiver, macTask.configSource);
        fail("Should throw an invalid configuration exception because of module with missing attachment.");
    } catch (final InvalidAssemblerConfigurationException e) {
    // should throw this because of missing attachment.
    }
    mm.verifyAll();
}
Also used : MockAndControlForAddArtifactTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddArtifactTask) EasyMockSupport(org.easymock.classextension.EasyMockSupport) ModuleBinaries(org.apache.maven.plugins.assembly.model.ModuleBinaries) MavenProject(org.apache.maven.project.MavenProject) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) ArtifactMock(org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock) InvalidAssemblerConfigurationException(org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) Logger(org.codehaus.plexus.logging.Logger)

Example 8 with InvalidAssemblerConfigurationException

use of org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException 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 9 with InvalidAssemblerConfigurationException

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

the class FilterUtils method filterArtifacts.

public static void filterArtifacts(final Set<Artifact> artifacts, final List<String> includes, final List<String> excludes, final boolean strictFiltering, final boolean actTransitively, final Logger logger, final ArtifactFilter... additionalFilters) throws InvalidAssemblerConfigurationException {
    final List<ArtifactFilter> allFilters = new ArrayList<ArtifactFilter>();
    final AndArtifactFilter filter = new AndArtifactFilter();
    if (additionalFilters != null && additionalFilters.length > 0) {
        for (final ArtifactFilter additionalFilter : additionalFilters) {
            if (additionalFilter != null) {
                filter.add(additionalFilter);
            }
        }
    }
    if (!includes.isEmpty()) {
        final ArtifactFilter includeFilter = new PatternIncludesArtifactFilter(includes, actTransitively);
        filter.add(includeFilter);
        allFilters.add(includeFilter);
    }
    if (!excludes.isEmpty()) {
        final ArtifactFilter excludeFilter = new PatternExcludesArtifactFilter(excludes, actTransitively);
        filter.add(excludeFilter);
        allFilters.add(excludeFilter);
    }
    for (final Iterator<Artifact> it = artifacts.iterator(); it.hasNext(); ) {
        final Artifact artifact = it.next();
        if (!filter.include(artifact)) {
            it.remove();
            if (logger.isDebugEnabled()) {
                logger.debug(artifact.getId() + " was removed by one or more filters.");
            }
        }
    }
    reportFilteringStatistics(allFilters, logger);
    for (final ArtifactFilter f : allFilters) {
        if (f instanceof StatisticsReportingArtifactFilter) {
            final StatisticsReportingArtifactFilter sFilter = (StatisticsReportingArtifactFilter) f;
            if (strictFiltering && sFilter.hasMissedCriteria()) {
                throw new InvalidAssemblerConfigurationException("One or more filters had unmatched criteria. Check debug log for more information.");
            }
        }
    }
}
Also used : PatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) StatisticsReportingArtifactFilter(org.apache.maven.shared.artifact.filter.StatisticsReportingArtifactFilter) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) PatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter) PatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter) PatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter) ArrayList(java.util.ArrayList) StatisticsReportingArtifactFilter(org.apache.maven.shared.artifact.filter.StatisticsReportingArtifactFilter) InvalidAssemblerConfigurationException(org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) Artifact(org.apache.maven.artifact.Artifact)

Example 10 with InvalidAssemblerConfigurationException

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

the class ModuleSetAssemblyPhase method addModuleBinaries.

void addModuleBinaries(final Assembly assembly, ModuleSet moduleSet, final ModuleBinaries binaries, final Set<MavenProject> projects, final Archiver archiver, final AssemblerConfigurationSource configSource) throws ArchiveCreationException, AssemblyFormattingException, InvalidAssemblerConfigurationException, DependencyResolutionException {
    if (binaries == null) {
        return;
    }
    final Set<MavenProject> moduleProjects = new LinkedHashSet<MavenProject>();
    MavenProjects.select(projects, "pom", log(getLogger()), addTo(moduleProjects));
    final String classifier = binaries.getAttachmentClassifier();
    final Map<MavenProject, Artifact> chosenModuleArtifacts = new HashMap<MavenProject, Artifact>();
    for (final MavenProject project : moduleProjects) {
        Artifact artifact;
        if (classifier == null) {
            getLogger().debug("Processing binary artifact for module project: " + project.getId());
            artifact = project.getArtifact();
        } else {
            getLogger().debug("Processing binary attachment: " + classifier + " for module project: " + project.getId());
            artifact = MavenProjects.findArtifactByClassifier(project, classifier);
            if (artifact == null) {
                throw new InvalidAssemblerConfigurationException("Cannot find attachment with classifier: " + classifier + " in module project: " + project.getId() + ". Please exclude this module from the module-set.");
            }
        }
        chosenModuleArtifacts.put(project, artifact);
        addModuleArtifact(artifact, project, archiver, configSource, binaries);
    }
    final List<DependencySet> depSets = getDependencySets(binaries);
    if (depSets != null) {
        Map<DependencySet, Set<Artifact>> dependencySetSetMap = dependencyResolver.resolveDependencySets(assembly, moduleSet, configSource, depSets);
        for (final DependencySet ds : depSets) {
            // NOTE: Disabling useProjectArtifact flag, since module artifact has already been handled!
            ds.setUseProjectArtifact(false);
        }
        // TODO: The following should be moved into a shared component, cause this
        // test is the same as in maven-enforce rules ReactorModuleConvergence.
        List<MavenProject> validateModuleVersions = validateModuleVersions(moduleProjects);
        if (!validateModuleVersions.isEmpty()) {
            StringBuilder sb = new StringBuilder().append("The current modules seemed to be having different versions.");
            sb.append(LINE_SEPARATOR);
            for (MavenProject mavenProject : validateModuleVersions) {
                sb.append(" --> ");
                sb.append(mavenProject.getId());
                sb.append(LINE_SEPARATOR);
            }
            getLogger().warn(sb.toString());
        }
        for (final MavenProject moduleProject : moduleProjects) {
            getLogger().debug("Processing binary dependencies for module project: " + moduleProject.getId());
            for (Map.Entry<DependencySet, Set<Artifact>> dependencySetSetEntry : dependencySetSetMap.entrySet()) {
                final AddDependencySetsTask task = new AddDependencySetsTask(Collections.singletonList(dependencySetSetEntry.getKey()), dependencySetSetEntry.getValue(), moduleProject, projectBuilder, getLogger());
                task.setModuleProject(moduleProject);
                task.setModuleArtifact(chosenModuleArtifacts.get(moduleProject));
                task.setDefaultOutputDirectory(binaries.getOutputDirectory());
                task.setDefaultOutputFileNameMapping(binaries.getOutputFileNameMapping());
                task.execute(archiver, configSource);
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ModuleSet(org.apache.maven.plugins.assembly.model.ModuleSet) FileSet(org.apache.maven.plugins.assembly.model.FileSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) DependencySet(org.apache.maven.plugins.assembly.model.DependencySet) HashMap(java.util.HashMap) DependencySet(org.apache.maven.plugins.assembly.model.DependencySet) InvalidAssemblerConfigurationException(org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException) Artifact(org.apache.maven.artifact.Artifact) MavenProject(org.apache.maven.project.MavenProject) HashMap(java.util.HashMap) Map(java.util.Map) AddDependencySetsTask(org.apache.maven.plugins.assembly.archive.task.AddDependencySetsTask)

Aggregations

InvalidAssemblerConfigurationException (org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException)11 File (java.io.File)4 ArrayList (java.util.ArrayList)3 Artifact (org.apache.maven.artifact.Artifact)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 ArchiveCreationException (org.apache.maven.plugins.assembly.archive.ArchiveCreationException)3 AssemblyFormattingException (org.apache.maven.plugins.assembly.format.AssemblyFormattingException)3 Assembly (org.apache.maven.plugins.assembly.model.Assembly)3 MavenProject (org.apache.maven.project.MavenProject)3 FileSet (org.apache.maven.plugins.assembly.model.FileSet)2 AssemblyConfiguration (io.fabric8.maven.docker.config.AssemblyConfiguration)1 AssemblyMode (io.fabric8.maven.docker.config.AssemblyMode)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 AndArtifactFilter (org.apache.maven.artifact.resolver.filter.AndArtifactFilter)1 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1