Search in sources :

Example 1 with AssemblyFormattingException

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

the class TypeConversionUtilsTest method testModeToInt_FailOnInvalidOctalValue.

public void testModeToInt_FailOnInvalidOctalValue() {
    try {
        TypeConversionUtils.modeToInt("493", new ConsoleLogger(Logger.LEVEL_DEBUG, "test"));
        fail("'493' is an invalid mode and should trigger an exception.");
    } catch (final AssemblyFormattingException e) {
    // expected.
    }
}
Also used : AssemblyFormattingException(org.apache.maven.plugins.assembly.format.AssemblyFormattingException) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger)

Example 2 with AssemblyFormattingException

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

Example 3 with AssemblyFormattingException

use of org.apache.maven.plugins.assembly.format.AssemblyFormattingException 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 4 with AssemblyFormattingException

use of org.apache.maven.plugins.assembly.format.AssemblyFormattingException 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 5 with AssemblyFormattingException

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

the class AddFileSetsTask method addFileSet.

void addFileSet(final FileSet fileSet, final Archiver archiver, final AssemblerConfigurationSource configSource, final File archiveBaseDir) throws AssemblyFormattingException, ArchiveCreationException {
    // throw this check in just in case someone extends this class...
    checkLogger();
    if (project == null) {
        project = configSource.getProject();
    }
    final File basedir = project.getBasedir();
    String destDirectory = fileSet.getOutputDirectory();
    if (destDirectory == null) {
        destDirectory = fileSet.getDirectory();
    }
    AssemblyFormatUtils.warnForPlatformSpecifics(logger, destDirectory);
    destDirectory = AssemblyFormatUtils.getOutputDirectory(destDirectory, configSource.getFinalName(), configSource, AssemblyFormatUtils.moduleProjectInterpolator(moduleProject), AssemblyFormatUtils.artifactProjectInterpolator(project));
    if (logger.isDebugEnabled()) {
        logger.debug("FileSet[" + destDirectory + "]" + " dir perms: " + Integer.toString(archiver.getOverrideDirectoryMode(), 8) + " file perms: " + Integer.toString(archiver.getOverrideFileMode(), 8) + (fileSet.getLineEnding() == null ? "" : " lineEndings: " + fileSet.getLineEnding()));
    }
    logger.debug("The archive base directory is '" + archiveBaseDir + "'");
    File fileSetDir = getFileSetDirectory(fileSet, basedir, archiveBaseDir);
    if (fileSetDir.exists()) {
        InputStreamTransformer fileSetTransformers = ReaderFormatter.getFileSetTransformers(configSource, fileSet.isFiltered(), fileSet.getLineEnding());
        if (fileSetTransformers == null) {
            logger.debug("NOT reformatting any files in " + fileSetDir);
        }
        if (fileSetDir.getPath().equals(File.separator)) {
            throw new AssemblyFormattingException("Your assembly descriptor specifies a directory of " + File.separator + ", which is your *entire* file system.\nThese are not the files you are looking for");
        }
        final AddDirectoryTask task = new AddDirectoryTask(fileSetDir, fileSetTransformers);
        final int dirMode = TypeConversionUtils.modeToInt(fileSet.getDirectoryMode(), logger);
        if (dirMode != -1) {
            task.setDirectoryMode(dirMode);
        }
        final int fileMode = TypeConversionUtils.modeToInt(fileSet.getFileMode(), logger);
        if (fileMode != -1) {
            task.setFileMode(fileMode);
        }
        task.setUseDefaultExcludes(fileSet.isUseDefaultExcludes());
        task.setExcludes(fileSet.getExcludes());
        task.setIncludes(fileSet.getIncludes());
        task.setOutputDirectory(destDirectory);
        task.execute(archiver);
    }
}
Also used : AssemblyFormattingException(org.apache.maven.plugins.assembly.format.AssemblyFormattingException) InputStreamTransformer(org.codehaus.plexus.components.io.functions.InputStreamTransformer) File(java.io.File)

Aggregations

AssemblyFormattingException (org.apache.maven.plugins.assembly.format.AssemblyFormattingException)6 File (java.io.File)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 InvalidAssemblerConfigurationException (org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException)3 ArchiveCreationException (org.apache.maven.plugins.assembly.archive.ArchiveCreationException)3 Assembly (org.apache.maven.plugins.assembly.model.Assembly)2 AssemblyConfiguration (io.fabric8.maven.docker.config.AssemblyConfiguration)1 AssemblyMode (io.fabric8.maven.docker.config.AssemblyMode)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 AssemblyReadException (org.apache.maven.plugins.assembly.io.AssemblyReadException)1 MavenProject (org.apache.maven.project.MavenProject)1 InputStreamTransformer (org.codehaus.plexus.components.io.functions.InputStreamTransformer)1 ConsoleLogger (org.codehaus.plexus.logging.console.ConsoleLogger)1