Search in sources :

Example 6 with GeneratorContext

use of io.fabric8.maven.generator.api.GeneratorContext in project fabric8-maven-plugin by fabric8io.

the class JavaExecGeneratorMainClassDeterminationTest method testMainClassDeterminationFromConfig.

/**
 * The main class is determined via config in a non-fat-jar deployment
 * @throws MojoExecutionException
 */
@Test
public void testMainClassDeterminationFromConfig() throws MojoExecutionException {
    new MockBuild();
    new MockProcessorConfig("the.main.ClassName");
    new MockMavenProject();
    final GeneratorContext generatorContext = new GeneratorContext.Builder().project(new MavenProject()).config(new ProcessorConfig()).strategy(OpenShiftBuildStrategy.docker).logger(log).build();
    JavaExecGenerator generator = new JavaExecGenerator(generatorContext);
    final List<ImageConfiguration> images = new ArrayList<ImageConfiguration>();
    List<ImageConfiguration> customized = generator.customize(images, false);
    assertEquals("1 images returned", (long) 1, (long) customized.size());
    ImageConfiguration imageConfig = customized.get(0);
    assertEquals("Image name", "TheImageName", imageConfig.getName());
    assertEquals("Main Class set as environment variable", "the.main.ClassName", imageConfig.getBuildConfiguration().getEnv().get(JavaExecGenerator.JAVA_MAIN_CLASS_ENV_VAR));
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) ArrayList(java.util.ArrayList) GeneratorContext(io.fabric8.maven.generator.api.GeneratorContext) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) Test(org.junit.Test)

Example 7 with GeneratorContext

use of io.fabric8.maven.generator.api.GeneratorContext in project fabric8-maven-plugin by fabric8io.

the class JavaExecGeneratorMainClassDeterminationTest method testMainClassDeterminationFromDetectionOnNonFatJar.

/**
 * The main class is determined via main class detection in a non-fat-jar deployment
 * @throws MojoExecutionException
 */
@Test
public void testMainClassDeterminationFromDetectionOnNonFatJar() throws MojoExecutionException {
    new MockBuild();
    new MockProcessorConfig(null);
    new MockMavenProject();
    new MockFatJarDetector(false);
    new MockClassUtils();
    final GeneratorContext generatorContext = new GeneratorContext.Builder().project(new MavenProject()).config(new ProcessorConfig()).strategy(OpenShiftBuildStrategy.docker).logger(log).build();
    JavaExecGenerator generator = new JavaExecGenerator(generatorContext);
    final List<ImageConfiguration> images = new ArrayList<ImageConfiguration>();
    List<ImageConfiguration> customized = generator.customize(images, false);
    assertEquals("1 images returned", (long) 1, (long) customized.size());
    ImageConfiguration imageConfig = customized.get(0);
    assertEquals("Image name", "TheImageName", imageConfig.getName());
    assertEquals("Main Class set as environment variable", "the.detected.MainClass", imageConfig.getBuildConfiguration().getEnv().get(JavaExecGenerator.JAVA_MAIN_CLASS_ENV_VAR));
}
Also used : ArrayList(java.util.ArrayList) GeneratorContext(io.fabric8.maven.generator.api.GeneratorContext) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) MavenProject(org.apache.maven.project.MavenProject) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) Test(org.junit.Test)

Example 8 with GeneratorContext

use of io.fabric8.maven.generator.api.GeneratorContext in project fabric8-maven-plugin by fabric8io.

the class JavaExecGeneratorMainClassDeterminationTest method testMainClassDeterminationFromFatJar.

/**
 * The main class is determined as the Main-Class of a fat jar
 * @throws MojoExecutionException
 */
@Test
public void testMainClassDeterminationFromFatJar() throws MojoExecutionException {
    new MockBuild();
    new MockProcessorConfig(null);
    new MockMavenProject();
    new MockFatJarDetector(true);
    new MockJavaExecGenerator();
    final GeneratorContext generatorContext = new GeneratorContext.Builder().project(new MavenProject()).config(new ProcessorConfig()).strategy(OpenShiftBuildStrategy.docker).logger(log).build();
    JavaExecGenerator generator = new JavaExecGenerator(generatorContext);
    final List<ImageConfiguration> images = new ArrayList<ImageConfiguration>();
    List<ImageConfiguration> customized = generator.customize(images, false);
    assertEquals("1 images returned", (long) 1, (long) customized.size());
    ImageConfiguration imageConfig = customized.get(0);
    assertEquals("Image name", "TheImageName", imageConfig.getName());
    assertNull("Main Class is NOT set as environment variable#", imageConfig.getBuildConfiguration().getEnv().get(JavaExecGenerator.JAVA_MAIN_CLASS_ENV_VAR));
}
Also used : ArrayList(java.util.ArrayList) GeneratorContext(io.fabric8.maven.generator.api.GeneratorContext) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) MavenProject(org.apache.maven.project.MavenProject) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) Test(org.junit.Test)

Aggregations

GeneratorContext (io.fabric8.maven.generator.api.GeneratorContext)8 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)5 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 MavenProject (org.apache.maven.project.MavenProject)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 Fabric8ServiceException (io.fabric8.maven.core.service.Fabric8ServiceException)1 Fabric8ServiceHub (io.fabric8.maven.core.service.Fabric8ServiceHub)1 ImageConfigResolver (io.fabric8.maven.docker.config.handler.ImageConfigResolver)1 ImageNameFormatter (io.fabric8.maven.docker.util.ImageNameFormatter)1 Logger (io.fabric8.maven.docker.util.Logger)1 FromSelector (io.fabric8.maven.generator.api.FromSelector)1 Generator (io.fabric8.maven.generator.api.Generator)1 IOException (java.io.IOException)1 Date (java.util.Date)1 List (java.util.List)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 MavenFilteringException (org.apache.maven.shared.filtering.MavenFilteringException)1