Search in sources :

Example 6 with MojoParameters

use of io.fabric8.maven.docker.util.MojoParameters 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 7 with MojoParameters

use of io.fabric8.maven.docker.util.MojoParameters in project docker-maven-plugin by fabric8io.

the class DockerAssemblyManagerTest method assemblyFiles.

@Test
public void assemblyFiles(@Injectable final MojoParameters mojoParams, @Injectable final MavenProject project, @Injectable final Assembly assembly) throws AssemblyFormattingException, ArchiveCreationException, InvalidAssemblerConfigurationException, MojoExecutionException, AssemblyReadException, IllegalAccessException {
    ReflectionUtils.setVariableValueInObject(assemblyManager, "trackArchiver", trackArchiver);
    new Expectations() {

        {
            mojoParams.getOutputDirectory();
            result = "target/";
            times = 3;
            mojoParams.getProject();
            project.getBasedir();
            result = ".";
            assemblyReader.readAssemblies((AssemblerConfigurationSource) any);
            result = Arrays.asList(assembly);
        }
    };
    BuildImageConfiguration buildConfig = createBuildConfig();
    assemblyManager.getAssemblyFiles("testImage", buildConfig, mojoParams, new AnsiLogger(new SystemStreamLog(), true, true));
}
Also used : Expectations(mockit.Expectations) SystemStreamLog(org.apache.maven.plugin.logging.SystemStreamLog) AnsiLogger(io.fabric8.maven.docker.util.AnsiLogger) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) Test(org.junit.Test)

Example 8 with MojoParameters

use of io.fabric8.maven.docker.util.MojoParameters in project docker-maven-plugin by fabric8io.

the class DockerAssemblyManagerTest method mockMojoParams.

private MojoParameters mockMojoParams(MavenProject project) {
    Settings settings = new Settings();
    ArtifactRepository localRepository = new MockUp<ArtifactRepository>() {

        @Mock
        public String getBasedir() {
            return "repository";
        }
    }.getMockInstance();
    @SuppressWarnings("deprecation") MavenSession session = new MavenSession(null, settings, localRepository, null, null, Collections.<String>emptyList(), ".", null, null, new Date());
    return new MojoParameters(session, project, null, null, null, settings, "src", "target", Collections.singletonList(project));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) MojoParameters(io.fabric8.maven.docker.util.MojoParameters) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Settings(org.apache.maven.settings.Settings) Mock(mockit.Mock) Date(java.util.Date)

Example 9 with MojoParameters

use of io.fabric8.maven.docker.util.MojoParameters in project docker-maven-plugin by fabric8io.

the class DockerFileUtilTest method interpolate.

@Test
public void interpolate() throws Exception {
    MojoParameters params = mockMojoParams();
    Map<String, String> filterMapping = new HashMap<>();
    filterMapping.put("none", "false");
    filterMapping.put("var", "${*}");
    filterMapping.put("at", "@");
    for (Map.Entry<String, String> entry : filterMapping.entrySet()) {
        for (int i = 1; i < 2; i++) {
            File dockerFile = getDockerfilePath(i, entry.getKey());
            File expectedDockerFile = new File(dockerFile.getParent(), dockerFile.getName() + ".expected");
            File actualDockerFile = createTmpFile(dockerFile.getName());
            FixedStringSearchInterpolator interpolator = DockerFileUtil.createInterpolator(params, entry.getValue());
            FileUtils.write(actualDockerFile, DockerFileUtil.interpolate(dockerFile, interpolator), "UTF-8");
            // Compare text lines without regard to EOL delimiters
            assertEquals(FileUtils.readLines(expectedDockerFile), FileUtils.readLines(actualDockerFile));
        }
    }
}
Also used : FixedStringSearchInterpolator(org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) PathTestUtil.createTmpFile(io.fabric8.maven.docker.util.PathTestUtil.createTmpFile) Test(org.junit.Test)

Example 10 with MojoParameters

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

Aggregations

File (java.io.File)7 MojoParameters (io.fabric8.maven.docker.util.MojoParameters)6 Test (org.junit.Test)5 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)3 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)3 IOException (java.io.IOException)3 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)2 ExecException (io.fabric8.maven.docker.access.ExecException)2 AssemblyFiles (io.fabric8.maven.docker.assembly.AssemblyFiles)2 AssemblyConfiguration (io.fabric8.maven.docker.config.AssemblyConfiguration)2 WatchImageConfiguration (io.fabric8.maven.docker.config.WatchImageConfiguration)2 ArrayList (java.util.ArrayList)2 Assembly (org.apache.maven.plugin.assembly.model.Assembly)2 MavenProject (org.apache.maven.project.MavenProject)2 FixedStringSearchInterpolator (org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator)2 BuildOptions (io.fabric8.maven.docker.access.BuildOptions)1 DockerAssemblyConfigurationSource (io.fabric8.maven.docker.assembly.DockerAssemblyConfigurationSource)1 AssemblyMode (io.fabric8.maven.docker.config.AssemblyMode)1 CleanupMode (io.fabric8.maven.docker.config.CleanupMode)1