Search in sources :

Example 51 with Assembly

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

the class FileItemAssemblyPhaseTest method testExecute_ShouldAddAbsoluteFileNoFilterNoLineEndingConversion.

public void testExecute_ShouldAddAbsoluteFileNoFilterNoLineEndingConversion() throws ArchiveCreationException, AssemblyFormattingException, IOException {
    final EasyMockSupport mm = new EasyMockSupport();
    final MockAndControlForConfigSource macCS = new MockAndControlForConfigSource(mm);
    final File basedir = fileManager.createTempDir();
    final File file = fileManager.createFile(basedir, "file.txt", "This is a test file.");
    macCS.expectGetBasedir(basedir);
    macCS.expectGetProject(new MavenProject(new Model()));
    macCS.expectGetFinalName("final-name");
    macCS.expectInterpolators();
    final MockAndControlForLogger macLogger = new MockAndControlForLogger(mm);
    final MockAndControlForArchiver macArchiver = new MockAndControlForArchiver(mm);
    final Assembly assembly = new Assembly();
    assembly.setId("test");
    final FileItem fi = new FileItem();
    fi.setSource(file.getAbsolutePath());
    fi.setFiltered(false);
    fi.setLineEnding("keep");
    fi.setFileMode("777");
    macArchiver.expectAddFile(file, "file.txt", TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test")));
    assembly.addFile(fi);
    mm.replayAll();
    createPhase(macLogger.logger).execute(assembly, macArchiver.archiver, macCS.configSource);
    mm.verifyAll();
}
Also used : FileItem(org.apache.maven.plugins.assembly.model.FileItem) EasyMockSupport(org.easymock.classextension.EasyMockSupport) MavenProject(org.apache.maven.project.MavenProject) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) Model(org.apache.maven.model.Model) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 52 with Assembly

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

the class FileItemAssemblyPhaseTest method testExecute_WithOutputDirectoryAndDestNameAndIncludeBaseDirectoryFalse.

public void testExecute_WithOutputDirectoryAndDestNameAndIncludeBaseDirectoryFalse() throws Exception {
    final EasyMockSupport mm = new EasyMockSupport();
    final MockAndControlForConfigSource macCS = new MockAndControlForConfigSource(mm);
    final File basedir = fileManager.createTempDir();
    final File readmeFile = fileManager.createFile(basedir, "README.txt", "This is a test file for README.txt.");
    final File licenseFile = fileManager.createFile(basedir, "LICENSE.txt", "This is a test file for LICENSE.txt.");
    final File configFile = fileManager.createFile(basedir, "config/config.txt", "This is a test file for config/config.txt");
    macCS.expectGetBasedir(basedir);
    macCS.expectGetProject(new MavenProject(new Model()));
    macCS.expectGetFinalName("final-name");
    macCS.expectInterpolators();
    final MockAndControlForLogger macLogger = new MockAndControlForLogger(mm);
    final MockAndControlForArchiver macArchiver = new MockAndControlForArchiver(mm);
    final Assembly assembly = new Assembly();
    assembly.setId("test");
    assembly.setIncludeBaseDirectory(false);
    final FileItem readmeFileItem = new FileItem();
    readmeFileItem.setSource("README.txt");
    readmeFileItem.setDestName("README_renamed.txt");
    readmeFileItem.setFiltered(false);
    readmeFileItem.setLineEnding("keep");
    readmeFileItem.setFileMode("777");
    final FileItem licenseFileItem = new FileItem();
    licenseFileItem.setSource("LICENSE.txt");
    licenseFileItem.setDestName("LICENSE_renamed.txt");
    licenseFileItem.setFiltered(false);
    licenseFileItem.setLineEnding("keep");
    licenseFileItem.setFileMode("777");
    final FileItem configFileItem = new FileItem();
    configFileItem.setSource("config/config.txt");
    configFileItem.setDestName("config_renamed.txt");
    configFileItem.setOutputDirectory("config");
    configFileItem.setFiltered(false);
    configFileItem.setLineEnding("keep");
    configFileItem.setFileMode("777");
    macArchiver.expectAddFile(readmeFile, "README_renamed.txt", TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test")));
    macArchiver.expectAddFile(licenseFile, "LICENSE_renamed.txt", TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test")));
    macArchiver.expectAddFile(configFile, "config/config_renamed.txt", TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test")));
    assembly.addFile(readmeFileItem);
    assembly.addFile(licenseFileItem);
    assembly.addFile(configFileItem);
    mm.replayAll();
    createPhase(macLogger.logger).execute(assembly, macArchiver.archiver, macCS.configSource);
    mm.verifyAll();
}
Also used : FileItem(org.apache.maven.plugins.assembly.model.FileItem) EasyMockSupport(org.easymock.classextension.EasyMockSupport) MavenProject(org.apache.maven.project.MavenProject) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) Model(org.apache.maven.model.Model) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 53 with Assembly

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

the class DefaultAssemblyReader method addAssemblyForDescriptorReference.

private Assembly addAssemblyForDescriptorReference(final String ref, final AssemblerConfigurationSource configSource, final List<Assembly> assemblies) throws AssemblyReadException, InvalidAssemblerConfigurationException {
    final InputStream resourceAsStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("assemblies/" + ref + ".xml");
    if (resourceAsStream == null) {
        if (configSource.isIgnoreMissingDescriptor()) {
            getLogger().debug("Ignoring missing assembly descriptor with ID '" + ref + "' per configuration.");
            return null;
        } else {
            throw new AssemblyReadException("Descriptor with ID '" + ref + "' not found");
        }
    }
    Reader reader = null;
    try {
        reader = ReaderFactory.newXmlReader(resourceAsStream);
        final Assembly assembly = readAssembly(reader, ref, null, configSource);
        reader.close();
        reader = null;
        assemblies.add(assembly);
        return assembly;
    } catch (final IOException e) {
        throw new AssemblyReadException("Problem with descriptor with ID '" + ref + "'", e);
    } finally {
        IOUtils.closeQuietly(reader);
    }
}
Also used : InputStream(java.io.InputStream) ComponentXpp3Reader(org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Reader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) AssemblyXpp3Reader(org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Reader) IOException(java.io.IOException) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 54 with Assembly

use of org.apache.maven.plugins.assembly.model.Assembly 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 55 with Assembly

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

the class DefaultAssemblyReader method addAssemblyFromDescriptor.

private Assembly addAssemblyFromDescriptor(final String spec, final Locator locator, final AssemblerConfigurationSource configSource, final List<Assembly> assemblies) throws AssemblyReadException, InvalidAssemblerConfigurationException {
    final Location location = locator.resolve(spec);
    if (location == null) {
        if (configSource.isIgnoreMissingDescriptor()) {
            getLogger().debug("Ignoring missing assembly descriptor with ID '" + spec + "' per configuration.\nLocator output was:\n\n" + locator.getMessageHolder().render());
            return null;
        } else {
            throw new AssemblyReadException("Error locating assembly descriptor: " + spec + "\n\n" + locator.getMessageHolder().render());
        }
    }
    Reader r = null;
    try {
        r = ReaderFactory.newXmlReader(location.getInputStream());
        File dir = null;
        if (location.getFile() != null) {
            dir = location.getFile().getParentFile();
        }
        final Assembly assembly = readAssembly(r, spec, dir, configSource);
        r.close();
        r = null;
        assemblies.add(assembly);
        return assembly;
    } catch (final IOException e) {
        throw new AssemblyReadException("Error reading assembly descriptor: " + spec, e);
    } finally {
        IOUtil.close(r);
    }
}
Also used : ComponentXpp3Reader(org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Reader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) AssemblyXpp3Reader(org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Reader) IOException(java.io.IOException) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly) Location(org.apache.maven.shared.io.location.Location)

Aggregations

Assembly (org.apache.maven.plugins.assembly.model.Assembly)56 File (java.io.File)29 MavenProject (org.apache.maven.project.MavenProject)28 Model (org.apache.maven.model.Model)21 EasyMockSupport (org.easymock.classextension.EasyMockSupport)13 ConsoleLogger (org.codehaus.plexus.logging.console.ConsoleLogger)12 FileSet (org.apache.maven.plugins.assembly.model.FileSet)9 ArrayList (java.util.ArrayList)8 Component (org.apache.maven.plugins.assembly.model.Component)8 DependencySet (org.apache.maven.plugins.assembly.model.DependencySet)7 PojoConfigSource (org.apache.maven.plugins.assembly.testutils.PojoConfigSource)7 FileItem (org.apache.maven.plugins.assembly.model.FileItem)6 FileOutputStream (java.io.FileOutputStream)5 IOException (java.io.IOException)5 OutputStreamWriter (java.io.OutputStreamWriter)5 StringWriter (java.io.StringWriter)5 Writer (java.io.Writer)5 AssemblyXpp3Writer (org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Writer)5 ComponentXpp3Reader (org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Reader)5 ComponentXpp3Writer (org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Writer)5