Search in sources :

Example 1 with AssemblyMode

use of io.fabric8.maven.docker.config.AssemblyMode in project docker-maven-plugin by fabric8io.

the class DockerAssemblyManager method createBuildArchiver.

private TarArchiver createBuildArchiver(File outputDir, File archive, List<AssemblyConfiguration> assemblyConfigs) throws NoSuchArchiverException {
    TarArchiver archiver = (TarArchiver) archiverManager.getArchiver(TAR_ARCHIVER_TYPE);
    archiver.setLongfile(TarLongFileMode.posix);
    boolean needsDefaultFileSet = assemblyConfigs.isEmpty();
    for (AssemblyConfiguration assemblyConfig : assemblyConfigs) {
        AssemblyMode mode = assemblyConfig != null ? assemblyConfig.getMode() : null;
        if (mode != null && mode.isArchive()) {
            DefaultArchivedFileSet archiveSet = DefaultArchivedFileSet.archivedFileSet(new File(outputDir, assemblyConfig.getName() + "." + mode.getExtension()));
            archiveSet.setPrefix(assemblyConfig.getName() + "/");
            archiveSet.setIncludingEmptyDirectories(true);
            archiveSet.setUsingDefaultExcludes(false);
            archiver.addArchivedFileSet(archiveSet);
        } else {
            needsDefaultFileSet = true;
        }
    }
    if (needsDefaultFileSet) {
        DefaultFileSet fileSet = DefaultFileSet.fileSet(outputDir);
        fileSet.setUsingDefaultExcludes(false);
        archiver.addFileSet(fileSet);
    }
    archiver.setDestFile(archive);
    return archiver;
}
Also used : TarArchiver(org.codehaus.plexus.archiver.tar.TarArchiver) DefaultFileSet(org.codehaus.plexus.archiver.util.DefaultFileSet) AssemblyConfiguration(io.fabric8.maven.docker.config.AssemblyConfiguration) DefaultArchivedFileSet(org.codehaus.plexus.archiver.util.DefaultArchivedFileSet) AssemblyMode(io.fabric8.maven.docker.config.AssemblyMode) File(java.io.File)

Example 2 with AssemblyMode

use of io.fabric8.maven.docker.config.AssemblyMode in project docker-maven-plugin by fabric8io.

the class DockerAssemblyManager method createBuildArchiver.

private TarArchiver createBuildArchiver(File outputDir, File archive, AssemblyConfiguration assemblyConfig) throws NoSuchArchiverException {
    TarArchiver archiver = (TarArchiver) archiverManager.getArchiver("tar");
    archiver.setLongfile(TarLongFileMode.posix);
    AssemblyMode mode = assemblyConfig != null ? assemblyConfig.getMode() : null;
    if (mode != null && mode.isArchive()) {
        DefaultArchivedFileSet archiveSet = DefaultArchivedFileSet.archivedFileSet(new File(outputDir, assemblyConfig.getName() + "." + mode.getExtension()));
        archiveSet.setPrefix(assemblyConfig.getName() + "/");
        archiveSet.setIncludingEmptyDirectories(true);
        archiveSet.setUsingDefaultExcludes(false);
        archiver.addArchivedFileSet(archiveSet);
    } else {
        DefaultFileSet fileSet = DefaultFileSet.fileSet(outputDir);
        fileSet.setUsingDefaultExcludes(false);
        archiver.addFileSet(fileSet);
    }
    archiver.setDestFile(archive);
    return archiver;
}
Also used : TarArchiver(org.codehaus.plexus.archiver.tar.TarArchiver) DefaultFileSet(org.codehaus.plexus.archiver.util.DefaultFileSet) DefaultArchivedFileSet(org.codehaus.plexus.archiver.util.DefaultArchivedFileSet) AssemblyMode(io.fabric8.maven.docker.config.AssemblyMode) File(java.io.File)

Example 3 with AssemblyMode

use of io.fabric8.maven.docker.config.AssemblyMode 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)

Aggregations

AssemblyMode (io.fabric8.maven.docker.config.AssemblyMode)3 File (java.io.File)3 TarArchiver (org.codehaus.plexus.archiver.tar.TarArchiver)2 DefaultArchivedFileSet (org.codehaus.plexus.archiver.util.DefaultArchivedFileSet)2 DefaultFileSet (org.codehaus.plexus.archiver.util.DefaultFileSet)2 AssemblyConfiguration (io.fabric8.maven.docker.config.AssemblyConfiguration)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 InvalidAssemblerConfigurationException (org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException)1 ArchiveCreationException (org.apache.maven.plugins.assembly.archive.ArchiveCreationException)1 AssemblyFormattingException (org.apache.maven.plugins.assembly.format.AssemblyFormattingException)1 Assembly (org.apache.maven.plugins.assembly.model.Assembly)1