Search in sources :

Example 1 with InvalidAssemblerConfigurationException

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

the class DefaultAssemblyReaderTest method testIncludeSiteInAssembly_ShouldFailIfSiteDirectoryNonExistent.

public void testIncludeSiteInAssembly_ShouldFailIfSiteDirectoryNonExistent() throws IOException {
    final File siteDir = File.createTempFile("assembly-reader.", ".test");
    siteDir.delete();
    expect(configSource.getSiteDirectory()).andReturn(siteDir).anyTimes();
    final Assembly assembly = new Assembly();
    mockManager.replayAll();
    try {
        new DefaultAssemblyReader().includeSiteInAssembly(assembly, configSource);
        fail("Should fail when site directory is non-existent.");
    } catch (final InvalidAssemblerConfigurationException e) {
    // this should happen.
    }
    mockManager.verifyAll();
}
Also used : InvalidAssemblerConfigurationException(org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 2 with InvalidAssemblerConfigurationException

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

the class FilterUtilsTest method testFilterArtifacts_ShouldThrowExceptionUsingStrictModeWithUnmatchedInclude.

public void testFilterArtifacts_ShouldThrowExceptionUsingStrictModeWithUnmatchedInclude() {
    final Artifact artifact = mockManager.createMock(Artifact.class);
    expect(artifact.getGroupId()).andReturn("group").atLeastOnce();
    expect(artifact.getArtifactId()).andReturn("artifact").atLeastOnce();
    expect(artifact.getId()).andReturn("group:artifact:type:version").atLeastOnce();
    expect(artifact.getDependencyConflictId()).andReturn("group:artifact:type").atLeastOnce();
    final List<String> includes = new ArrayList<String>();
    includes.add("other.group:other-artifact:type:version");
    final List<String> excludes = Collections.emptyList();
    final Set<Artifact> artifacts = new HashSet<Artifact>();
    artifacts.add(artifact);
    mockManager.replayAll();
    try {
        FilterUtils.filterArtifacts(artifacts, includes, excludes, true, false, logger);
        fail("Should fail because of unmatched include.");
    } catch (final InvalidAssemblerConfigurationException e) {
    // expected.
    }
    mockManager.verifyAll();
}
Also used : ArrayList(java.util.ArrayList) InvalidAssemblerConfigurationException(org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException) Artifact(org.apache.maven.artifact.Artifact) HashSet(java.util.HashSet)

Example 3 with InvalidAssemblerConfigurationException

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

the class DefaultAssemblyArchiver method selectContainerDescriptorHandlers.

// CHECKSTYLE_OFF: LineLength
private List<ContainerDescriptorHandler> selectContainerDescriptorHandlers(List<ContainerDescriptorHandlerConfig> requestedContainerDescriptorHandlers, final AssemblerConfigurationSource configSource) throws InvalidAssemblerConfigurationException // CHECKSTYLE_ON: LineLength
{
    getLogger().debug("All known ContainerDescriptorHandler components: " + (containerDescriptorHandlers == null ? "none; map is null." : "" + containerDescriptorHandlers.keySet()));
    if (requestedContainerDescriptorHandlers == null) {
        requestedContainerDescriptorHandlers = new ArrayList<ContainerDescriptorHandlerConfig>();
    }
    final List<ContainerDescriptorHandler> handlers = new ArrayList<ContainerDescriptorHandler>();
    final List<String> hints = new ArrayList<String>();
    if (!requestedContainerDescriptorHandlers.isEmpty()) {
        for (final ContainerDescriptorHandlerConfig config : requestedContainerDescriptorHandlers) {
            final String hint = config.getHandlerName();
            final ContainerDescriptorHandler handler = containerDescriptorHandlers.get(hint);
            if (handler == null) {
                throw new InvalidAssemblerConfigurationException("Cannot find ContainerDescriptorHandler with hint: " + hint);
            }
            getLogger().debug("Found container descriptor handler with hint: " + hint + " (component: " + handler + ")");
            if (config.getConfiguration() != null) {
                getLogger().debug("Configuring handler with:\n\n" + config.getConfiguration() + "\n\n");
                configureContainerDescriptorHandler(handler, (Xpp3Dom) config.getConfiguration(), configSource);
            }
            handlers.add(handler);
            hints.add(hint);
        }
    }
    if (!hints.contains("plexus")) {
        handlers.add(new ComponentsXmlArchiverFileFilter());
    }
    return handlers;
}
Also used : ContainerDescriptorHandler(org.apache.maven.plugins.assembly.filter.ContainerDescriptorHandler) ContainerDescriptorHandlerConfig(org.apache.maven.plugins.assembly.model.ContainerDescriptorHandlerConfig) ArrayList(java.util.ArrayList) ComponentsXmlArchiverFileFilter(org.apache.maven.plugins.assembly.filter.ComponentsXmlArchiverFileFilter) InvalidAssemblerConfigurationException(org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException)

Example 4 with InvalidAssemblerConfigurationException

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

the class DefaultAssemblyArchiver method configureContainerDescriptorHandler.

private void configureContainerDescriptorHandler(final ContainerDescriptorHandler handler, final Xpp3Dom config, final AssemblerConfigurationSource configSource) throws InvalidAssemblerConfigurationException {
    getLogger().debug("Configuring handler: '" + handler.getClass().getName() + "' -->");
    try {
        configureComponent(handler, config, configSource);
    } catch (final ComponentConfigurationException e) {
        throw new InvalidAssemblerConfigurationException("Failed to configure handler: " + handler.getClass().getName(), e);
    } catch (final ComponentLookupException e) {
        throw new InvalidAssemblerConfigurationException("Failed to lookup configurator for setup of handler: " + handler.getClass().getName(), e);
    }
    getLogger().debug("-- end configuration --");
}
Also used : ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) InvalidAssemblerConfigurationException(org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException) ComponentConfigurationException(org.codehaus.plexus.component.configurator.ComponentConfigurationException)

Example 5 with InvalidAssemblerConfigurationException

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

the class ArchiveService method getAssemblyFiles.

/**
 * Get a mapping of original to destination files which a covered by an assembly. This can be used
 * to watch the source files for changes in order to update the target (either by recreating a docker image
 * or by copying it into a running container)
 *
 * @param imageConfig image config for which to get files. The build- and assembly configuration in this image
 *                    config must not be null.
 * @param mojoParameters needed for tracking the assembly
 * @return mapping of assembly files
 * @throws MojoExecutionException
 */
public AssemblyFiles getAssemblyFiles(ImageConfiguration imageConfig, String assemblyName, MojoParameters mojoParameters) throws MojoExecutionException {
    String name = imageConfig.getName();
    try {
        List<AssemblyConfiguration> assemblyConfigurations = imageConfig.getBuildConfiguration().getAssemblyConfigurations();
        AssemblyConfiguration assemblyConfig = assemblyConfigurations.stream().filter(a -> a.getName().equals(assemblyName)).findFirst().orElse(null);
        if (assemblyConfig == null) {
            throw new IllegalArgumentException(String.format("Provided assembly name \"%s\" does not match any configured assemblies.", assemblyName));
        }
        return dockerAssemblyManager.getAssemblyFiles(name, assemblyConfig, mojoParameters, log);
    } catch (InvalidAssemblerConfigurationException | ArchiveCreationException | AssemblyFormattingException e) {
        throw new MojoExecutionException("Cannot extract assembly files for image " + name + ": " + e, e);
    }
}
Also used : AssemblyFormattingException(org.apache.maven.plugins.assembly.format.AssemblyFormattingException) AssemblyConfiguration(io.fabric8.maven.docker.config.AssemblyConfiguration) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException) InvalidAssemblerConfigurationException(org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException)

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