Search in sources :

Example 1 with Assembly

use of org.apache.maven.plugin.assembly.model.Assembly 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);
    } 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.plugin.assembly.format.AssemblyFormattingException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiveCreationException(org.apache.maven.plugin.assembly.archive.ArchiveCreationException) AssemblyMode(io.fabric8.maven.docker.config.AssemblyMode) InvalidAssemblerConfigurationException(org.apache.maven.plugin.assembly.InvalidAssemblerConfigurationException) File(java.io.File) Assembly(org.apache.maven.plugin.assembly.model.Assembly)

Example 2 with Assembly

use of org.apache.maven.plugin.assembly.model.Assembly in project docker-maven-plugin by fabric8io.

the class DockerAssemblyManager method getAssemblyFiles.

/**
 * Extract all files with a tracking archiver. These can be used to track changes in the filesystem and triggering
 * a rebuild of the image if needed ('docker:watch')
 */
public AssemblyFiles getAssemblyFiles(String name, BuildImageConfiguration buildConfig, MojoParameters mojoParams, Logger log) throws InvalidAssemblerConfigurationException, ArchiveCreationException, AssemblyFormattingException, MojoExecutionException {
    BuildDirs buildDirs = createBuildDirs(name, mojoParams);
    AssemblyConfiguration assemblyConfig = buildConfig.getAssemblyConfiguration();
    String assemblyName = assemblyConfig.getName();
    DockerAssemblyConfigurationSource source = new DockerAssemblyConfigurationSource(mojoParams, buildDirs, assemblyConfig);
    Assembly assembly = getAssemblyConfig(assemblyConfig, source);
    synchronized (trackArchiver) {
        MappingTrackArchiver ta = (MappingTrackArchiver) trackArchiver;
        ta.init(log, assemblyName);
        assembly.setId("tracker");
        assemblyArchiver.createArchive(assembly, assemblyName, "track", source, false);
        return ta.getAssemblyFiles(mojoParams.getSession());
    }
}
Also used : AssemblyConfiguration(io.fabric8.maven.docker.config.AssemblyConfiguration) Assembly(org.apache.maven.plugin.assembly.model.Assembly)

Example 3 with Assembly

use of org.apache.maven.plugin.assembly.model.Assembly in project fabric8-maven-plugin by fabric8io.

the class JavaExecGenerator method addAssembly.

protected void addAssembly(AssemblyConfiguration.Builder builder) throws MojoExecutionException {
    String assemblyRef = getConfig(Config.assemblyRef);
    if (assemblyRef != null) {
        builder.descriptorRef(assemblyRef);
    } else {
        if (isFatJar()) {
            FatJarDetector.Result fatJar = detectFatJar();
            Assembly assembly = new Assembly();
            MavenProject project = getProject();
            if (fatJar == null) {
                DependencySet dependencySet = new DependencySet();
                dependencySet.addInclude(project.getGroupId() + ":" + project.getArtifactId());
                assembly.addDependencySet(dependencySet);
            } else {
                FileSet fileSet = new FileSet();
                File buildDir = new File(project.getBuild().getDirectory());
                fileSet.setDirectory(toRelativePath(buildDir, project.getBasedir()));
                fileSet.addInclude(toRelativePath(fatJar.getArchiveFile(), buildDir));
                fileSet.setOutputDirectory(".");
                assembly.addFileSet(fileSet);
            }
            assembly.addFileSet(createFileSet("src/main/fabric8-includes/bin", "bin", "0755", "0755"));
            assembly.addFileSet(createFileSet("src/main/fabric8-includes", ".", "0644", "0755"));
            builder.assemblyDef(assembly);
        } else {
            builder.descriptorRef("artifact-with-dependencies");
        }
    }
    ;
}
Also used : MavenProject(org.apache.maven.project.MavenProject) FileSet(org.apache.maven.plugin.assembly.model.FileSet) DependencySet(org.apache.maven.plugin.assembly.model.DependencySet) File(java.io.File) Assembly(org.apache.maven.plugin.assembly.model.Assembly)

Aggregations

Assembly (org.apache.maven.plugin.assembly.model.Assembly)3 File (java.io.File)2 AssemblyConfiguration (io.fabric8.maven.docker.config.AssemblyConfiguration)1 AssemblyMode (io.fabric8.maven.docker.config.AssemblyMode)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 InvalidAssemblerConfigurationException (org.apache.maven.plugin.assembly.InvalidAssemblerConfigurationException)1 ArchiveCreationException (org.apache.maven.plugin.assembly.archive.ArchiveCreationException)1 AssemblyFormattingException (org.apache.maven.plugin.assembly.format.AssemblyFormattingException)1 DependencySet (org.apache.maven.plugin.assembly.model.DependencySet)1 FileSet (org.apache.maven.plugin.assembly.model.FileSet)1 MavenProject (org.apache.maven.project.MavenProject)1