Search in sources :

Example 1 with DockerAssemblyConfigurationSource

use of io.fabric8.maven.docker.assembly.DockerAssemblyConfigurationSource in project docker-maven-plugin by fabric8io.

the class DockerAssemblyConfigurationSourceTest method testOutputDirHasImage.

@Test
public void testOutputDirHasImage() {
    String image = "image";
    MojoParameters params = buildParameters(".", "src/docker", "output/docker");
    DockerAssemblyConfigurationSource source = new DockerAssemblyConfigurationSource(params, new BuildDirs(image, params), assemblyConfig);
    assertTrue(containsDir(image, source.getOutputDirectory()));
    assertTrue(containsDir(image, source.getWorkingDirectory()));
    assertTrue(containsDir(image, source.getTemporaryRootDirectory()));
}
Also used : MojoParameters(io.fabric8.maven.docker.util.MojoParameters) Test(org.junit.Test)

Example 2 with DockerAssemblyConfigurationSource

use of io.fabric8.maven.docker.assembly.DockerAssemblyConfigurationSource in project docker-maven-plugin by fabric8io.

the class DockerAssemblyConfigurationSourceTest method testReactorProjects.

@Test
public void testReactorProjects() {
    MavenProject reactorProject1 = new MavenProject();
    reactorProject1.setFile(new File("../reactor-1"));
    MavenProject reactorProject2 = new MavenProject();
    reactorProject2.setFile(new File("../reactor-2"));
    DockerAssemblyConfigurationSource source = new DockerAssemblyConfigurationSource(new MojoParameters(null, null, null, null, null, null, "/src/docker", "/output/docker", Arrays.asList(new MavenProject[] { reactorProject1, reactorProject2 })), null, null);
    assertEquals(2, source.getReactorProjects().size());
}
Also used : MavenProject(org.apache.maven.project.MavenProject) MojoParameters(io.fabric8.maven.docker.util.MojoParameters) File(java.io.File) Test(org.junit.Test)

Example 3 with DockerAssemblyConfigurationSource

use of io.fabric8.maven.docker.assembly.DockerAssemblyConfigurationSource 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 4 with DockerAssemblyConfigurationSource

use of io.fabric8.maven.docker.assembly.DockerAssemblyConfigurationSource 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 5 with DockerAssemblyConfigurationSource

use of io.fabric8.maven.docker.assembly.DockerAssemblyConfigurationSource in project docker-maven-plugin by fabric8io.

the class DockerFileUtil method createInterpolator.

/**
 * Create an interpolator for the given maven parameters and filter configuration.
 *
 * @param params The maven parameters.
 * @param filter The filter configuration.
 * @return An interpolator for replacing maven properties.
 */
public static FixedStringSearchInterpolator createInterpolator(MojoParameters params, String filter) {
    String[] delimiters = extractDelimiters(filter);
    if (delimiters == null) {
        // Don't interpolate anything
        return FixedStringSearchInterpolator.create();
    }
    DockerAssemblyConfigurationSource configSource = new DockerAssemblyConfigurationSource(params, null, null);
    // Patterned after org.apache.maven.plugin.assembly.interpolation.AssemblyExpressionEvaluator
    return AssemblyInterpolator.fullInterpolator(params.getProject(), DefaultAssemblyReader.createProjectInterpolator(params.getProject()), configSource).withExpressionMarkers(delimiters[0], delimiters[1]);
}
Also used : DockerAssemblyConfigurationSource(io.fabric8.maven.docker.assembly.DockerAssemblyConfigurationSource)

Aggregations

MojoParameters (io.fabric8.maven.docker.util.MojoParameters)3 Test (org.junit.Test)3 File (java.io.File)2 Assembly (org.apache.maven.plugin.assembly.model.Assembly)2 DockerAssemblyConfigurationSource (io.fabric8.maven.docker.assembly.DockerAssemblyConfigurationSource)1 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 MavenProject (org.apache.maven.project.MavenProject)1