Search in sources :

Example 1 with GeneratorContext

use of org.eclipse.jkube.generator.api.GeneratorContext in project jkube by eclipse.

the class WildflyJARGeneratorTest method slimServerFalseDist.

@Test
public void slimServerFalseDist(@Mocked final JavaProject project) throws IOException {
    Map<String, Object> options = new HashMap<>();
    Map<String, String> pluginOptions = new HashMap();
    options.put(PLUGIN_OPTIONS, pluginOptions);
    pluginOptions.put(JBOSS_MAVEN_REPO, "myrepo");
    pluginOptions.put(JBOSS_MAVEN_DIST, "false");
    GeneratorContext ctx = contextForSlimServer(project, options, null);
    WildflyJARGenerator generator = new WildflyJARGenerator(ctx);
    List<String> extraOptions = generator.getExtraJavaOptions();
    assertNotNull(extraOptions);
    assertEquals(1, extraOptions.size());
    assertEquals("-Djava.net.preferIPv4Stack=true", extraOptions.get(0));
}
Also used : HashMap(java.util.HashMap) GeneratorContext(org.eclipse.jkube.generator.api.GeneratorContext) Test(org.junit.Test)

Example 2 with GeneratorContext

use of org.eclipse.jkube.generator.api.GeneratorContext in project jkube by eclipse.

the class WildflyJARGeneratorTest method slimServerAbsoluteDir.

@Test
public void slimServerAbsoluteDir(@Mocked final JavaProject project) throws IOException {
    Map<String, Object> options = new HashMap<>();
    Map<String, String> pluginOptions = new HashMap();
    Path tmpDir = Files.createTempDirectory("bootable-jar-test-project2");
    Path targetDir = tmpDir.resolve("target");
    Path repoDir = targetDir.resolve("myrepo");
    Files.createDirectories(repoDir);
    options.put(PLUGIN_OPTIONS, pluginOptions);
    pluginOptions.put(JBOSS_MAVEN_DIST, null);
    pluginOptions.put(JBOSS_MAVEN_REPO, repoDir.toString());
    try {
        GeneratorContext ctx = contextForSlimServer(project, options, null);
        WildflyJARGenerator generator = new WildflyJARGenerator(ctx);
        List<String> extraOptions = generator.getExtraJavaOptions();
        assertNotNull(extraOptions);
        assertEquals(2, extraOptions.size());
        assertEquals("-Djava.net.preferIPv4Stack=true", extraOptions.get(0));
        assertEquals("-Dmaven.repo.local=/deployments/myrepo", extraOptions.get(1));
        List<AssemblyFileSet> files = generator.addAdditionalFiles();
        assertFalse(files.isEmpty());
        AssemblyFileSet set = files.get(files.size() - 1);
        assertEquals(targetDir.toFile(), set.getDirectory());
        assertEquals(1, set.getIncludes().size());
        assertEquals("myrepo", set.getIncludes().get(0));
    } finally {
        Files.delete(repoDir);
        Files.delete(targetDir);
        Files.delete(tmpDir);
    }
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) AssemblyFileSet(org.eclipse.jkube.kit.common.AssemblyFileSet) GeneratorContext(org.eclipse.jkube.generator.api.GeneratorContext) Test(org.junit.Test)

Example 3 with GeneratorContext

use of org.eclipse.jkube.generator.api.GeneratorContext in project jkube by eclipse.

the class WildflyJARGeneratorTest method slimServerNoRepo.

@Test
public void slimServerNoRepo(@Mocked final JavaProject project) throws IOException {
    Map<String, Object> options = new HashMap<>();
    Map<String, String> pluginOptions = new HashMap();
    options.put(PLUGIN_OPTIONS, pluginOptions);
    pluginOptions.put(JBOSS_MAVEN_DIST, null);
    GeneratorContext ctx = contextForSlimServer(project, options, null);
    WildflyJARGenerator generator = new WildflyJARGenerator(ctx);
    List<String> extraOptions = generator.getExtraJavaOptions();
    assertNotNull(extraOptions);
    assertEquals(1, extraOptions.size());
    assertEquals("-Djava.net.preferIPv4Stack=true", extraOptions.get(0));
}
Also used : HashMap(java.util.HashMap) GeneratorContext(org.eclipse.jkube.generator.api.GeneratorContext) Test(org.junit.Test)

Example 4 with GeneratorContext

use of org.eclipse.jkube.generator.api.GeneratorContext in project jkube by eclipse.

the class WildflyJARGeneratorTest method slimServerNoDir.

@Test
public void slimServerNoDir(@Mocked final JavaProject project) throws Exception {
    Map<String, Object> options = new HashMap<>();
    Map<String, String> pluginOptions = new HashMap();
    Path tmpDir = Files.createTempDirectory("bootable-jar-test-project2");
    Path targetDir = tmpDir.resolve("target");
    Path repoDir = targetDir.resolve("myrepo");
    options.put(PLUGIN_OPTIONS, pluginOptions);
    pluginOptions.put(JBOSS_MAVEN_DIST, null);
    pluginOptions.put(JBOSS_MAVEN_REPO, repoDir.toString());
    try {
        GeneratorContext ctx = contextForSlimServer(project, options, null);
        WildflyJARGenerator generator = new WildflyJARGenerator(ctx);
        List<String> extraOptions = generator.getExtraJavaOptions();
        assertNotNull(extraOptions);
        assertEquals(2, extraOptions.size());
        assertEquals("-Djava.net.preferIPv4Stack=true", extraOptions.get(0));
        assertEquals("-Dmaven.repo.local=/deployments/myrepo", extraOptions.get(1));
        Exception result = assertThrows(Exception.class, () -> {
            generator.addAdditionalFiles();
            fail("Test should have failed, no directory for maven repo");
        });
        assertEquals("Error, WildFly bootable JAR generator can't retrieve " + "generated maven local cache, directory " + repoDir + " doesn't exist.", result.getMessage());
    } finally {
        Files.delete(tmpDir);
    }
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) GeneratorContext(org.eclipse.jkube.generator.api.GeneratorContext) IOException(java.io.IOException) Test(org.junit.Test)

Example 5 with GeneratorContext

use of org.eclipse.jkube.generator.api.GeneratorContext in project jkube by eclipse.

the class JavaExecGeneratorMainClassDeterminationTest method testMainClassDeterminationFromDetectionOnNonFatJar.

/**
 * The main class is determined via main class detection in a non-fat-jar deployment
 */
@Test
public void testMainClassDeterminationFromDetectionOnNonFatJar(@Injectable File baseDir) {
    processorConfig.getConfig().put("java-exec", Collections.singletonMap("name", "TheNonFatJarImageName"));
    new Expectations() {

        {
            project.getBaseDirectory();
            result = baseDir;
            fatJarDetector.scan();
            result = null;
            mainClassDetector.getMainClass();
            result = "the.detected.MainClass";
        }
    };
    final GeneratorContext generatorContext = GeneratorContext.builder().project(project).config(processorConfig).strategy(JKubeBuildStrategy.docker).logger(log).build();
    JavaExecGenerator generator = new JavaExecGenerator(generatorContext);
    List<ImageConfiguration> customized = generator.customize(new ArrayList<>(), false);
    assertEquals("1 images returned", 1, customized.size());
    ImageConfiguration imageConfig = customized.get(0);
    assertEquals("Image name", "TheNonFatJarImageName", imageConfig.getName());
    assertEquals("Main Class set as environment variable", "the.detected.MainClass", imageConfig.getBuildConfiguration().getEnv().get(JavaExecGenerator.JAVA_MAIN_CLASS_ENV_VAR));
}
Also used : Expectations(mockit.Expectations) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) GeneratorContext(org.eclipse.jkube.generator.api.GeneratorContext) Test(org.junit.Test)

Aggregations

GeneratorContext (org.eclipse.jkube.generator.api.GeneratorContext)16 Test (org.junit.Test)13 HashMap (java.util.HashMap)8 File (java.io.File)3 Path (java.nio.file.Path)3 ImageConfiguration (org.eclipse.jkube.kit.config.image.ImageConfiguration)3 Properties (java.util.Properties)2 Expectations (mockit.Expectations)2 AssemblyFileSet (org.eclipse.jkube.kit.common.AssemblyFileSet)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 FromSelector (org.eclipse.jkube.generator.api.FromSelector)1 Before (org.junit.Before)1