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