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());
}
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));
}
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));
}
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));
}
}
}
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);
}
}
Aggregations