Skip to content

Commit

Permalink
Adds support for java 17 in generated projects codestart
Browse files Browse the repository at this point in the history
Adding support to java versions lts
Updated template of builds for support java 17
Fixs imports
Remove sysout
Change codestart dockerfiles to use openjdk-xx-runtime
Remove no longer needed RUN_JAVA_VERSION
Fixs code formatting
Fixs of code review
Remove the conversion to integer from the java_version
Remove java 8 and set java 11 to default
Fixs tests of codestarts generation
  • Loading branch information
netodevel committed Nov 24, 2021
1 parent 2764b1f commit 86030b3
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ java {
{#if java.version == "11"}
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
{#else if java.version == "17"}
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
{#else}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ java {
{#if java.version == "11"}
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
{#else if java.version == "17"}
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
{#else}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,18 @@
#
# Then run the container using :
#
# docker run -i --rm -p 8080:8080 -p 5005:5005 -e JAVA_ENABLE_DEBUG="true" quarkus/{project.artifact-id}-{type}
# docker run -i --rm -p 8080:8080 quarkus/{project.artifact-id}-{type}
#
###
FROM {#insert image /}
{#insert args /}
FROM registry.access.redhat.com/ubi8/openjdk-{java.version}-runtime:1.10

ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en'
# Install java and the run-java script
# Also set up permissions for user `1001`
RUN microdnf install curl ca-certificates $\{JAVA_PACKAGE} \
&& microdnf update \
&& microdnf clean all \
&& mkdir /deployments \
&& chown 1001 /deployments \
&& chmod "g+rwX" /deployments \
&& chown 1001:root /deployments \
&& curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/$\{RUN_JAVA_VERSION}/run-java-sh-$\{RUN_JAVA_VERSION}-sh.sh -o /deployments/run-java.sh \
&& chown 1001 /deployments/run-java.sh \
&& chmod 540 /deployments/run-java.sh \
&& echo "securerandom.source=file:/dev/urandom" >> /etc/alternatives/jre/conf/security/java.security

# Configure the JAVA_OPTIONS, you can add -XshowSettings:vm to also display the heap size.
ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
{#insert copy /}

EXPOSE 8080
USER 1001
USER 185

ENTRYPOINT [ "/deployments/run-java.sh" ]
ENTRYPOINT [ "java", "-jar", "/deployments/quarkus-run.jar" ]
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
{#include Dockerfile-layout type='jvm'}
{#quarkusbuild}{buildtool.cli} {buildtool.cmd.package}{/quarkusbuild}
{#image}{dockerfile.jvm.from} {/image}
{#args}
ARG JAVA_PACKAGE={dockerfile.jvm.java-package}
ARG RUN_JAVA_VERSION={dockerfile.jvm.run-java-version}
{/args}
{#copy}
# We make four distinct layers so if there are application changes the library layers can be re-used
COPY --chown=1001 {buildtool.build-dir}/quarkus-app/lib/ /deployments/lib/
COPY --chown=1001 {buildtool.build-dir}/quarkus-app/*.jar /deployments/
COPY --chown=1001 {buildtool.build-dir}/quarkus-app/app/ /deployments/app/
COPY --chown=1001 {buildtool.build-dir}/quarkus-app/quarkus/ /deployments/quarkus/
COPY --chown=185 {buildtool.build-dir}/quarkus-app/lib/ /deployments/lib/
COPY --chown=185 {buildtool.build-dir}/quarkus-app/*.jar /deployments/
COPY --chown=185 {buildtool.build-dir}/quarkus-app/app/ /deployments/app/
COPY --chown=185 {buildtool.build-dir}/quarkus-app/quarkus/ /deployments/quarkus/
{/copy}
{/include}

Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
{#include Dockerfile-layout type='legacy-jar'}
{#quarkusbuild}{buildtool.cli} {buildtool.cmd.package-legacy-jar}{/quarkusbuild}
{#image}{dockerfile.legacy-jar.from} {/image}
{#args}
ARG JAVA_PACKAGE={dockerfile.legacy-jar.java-package}
ARG RUN_JAVA_VERSION={dockerfile.legacy-jar.run-java-version}
{/args}
{#copy}
COPY {buildtool.build-dir}/lib/* /deployments/lib/
COPY {buildtool.build-dir}/*-runner.jar /deployments/app.jar
COPY {buildtool.build-dir}/*-runner.jar /deployments/quarkus-run.jar
{/copy}
{/include}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ language:
base:
data:
dockerfile:
jvm:
from: registry.access.redhat.com/ubi8/ubi-minimal:8.4
java-package: java-11-openjdk-headless
run-java-version: 1.3.8
legacy-jar:
from: registry.access.redhat.com/ubi8/ubi-minimal:8.4
java-package: java-11-openjdk-headless
run-java-version: 1.3.8
native:
from: registry.access.redhat.com/ubi8/ubi-minimal:8.4
native-distroless:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.nio.file.Path;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
Expand All @@ -18,6 +19,9 @@
import javax.lang.model.SourceVersion;

public class CreateProjectHelper {

private static final List<String> JAVA_VERSIONS_LTS = List.of("11", "17");
private static final String DEFAULT_JAVA_VERSION = "11";
private static final Pattern JAVA_VERSION_PATTERN = Pattern.compile("(?:1\\.)?(\\d+)(?:\\..*)?");

public static final String DEFAULT_GROUP_ID = "org.acme";
Expand Down Expand Up @@ -78,10 +82,15 @@ public static void setJavaVersion(Map<String, Object> values, String javaTarget)

Matcher matcher = JAVA_VERSION_PATTERN
.matcher(javaTarget != null ? javaTarget : System.getProperty("java.version", ""));
if (matcher.matches() && Integer.parseInt(matcher.group(1)) < 11) {
values.put(ProjectGenerator.JAVA_TARGET, "8");

if (matcher.matches()) {
String versionExtracted = matcher.group(1);
String version = JAVA_VERSIONS_LTS.stream()
.filter(e -> e.equals(versionExtracted))
.findFirst().orElse(DEFAULT_JAVA_VERSION);
values.put(ProjectGenerator.JAVA_TARGET, version);
} else {
values.put(ProjectGenerator.JAVA_TARGET, "11");
values.put(ProjectGenerator.JAVA_TARGET, DEFAULT_JAVA_VERSION);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.quarkus.devtools.project.codegen;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;

class CreateProjectHelperTest {

@Test
public void givenJavaVersion17ShouldReturn17() {
Map<String, Object> values = new HashMap<>();
values.put("nonull", "nonull");

CreateProjectHelper.setJavaVersion(values, "17");
assertEquals("17", values.get("java_target"));
}

@Test
public void givenJavaVersion16ShouldReturn11() {
Map<String, Object> values = new HashMap<>();
values.put("nonull", "nonull");

CreateProjectHelper.setJavaVersion(values, "16.0.1");
assertEquals("11", values.get("java_target"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,15 @@ private void checkDockerfilesWithMaven(Path projectDir) {
assertThat(projectDir.resolve("src/main/docker/Dockerfile.jvm")).exists()
.satisfies(checkContains("./mvnw package"))
.satisfies(checkContains("docker build -f src/main/docker/Dockerfile.jvm"))
.satisfies(checkContains("registry.access.redhat.com/ubi8/ubi-minimal:8.4"))
.satisfies(checkContains("ARG JAVA_PACKAGE=java-11-openjdk-headless"))
.satisfies(checkContains("ENTRYPOINT [ \"/deployments/run-java.sh\" ]"));
.satisfies(checkContains("registry.access.redhat.com/ubi8/openjdk-11-runtime:1.10"))//TODO: make a teste to java17
.satisfies(checkContains("ENTRYPOINT [ \"java\", \"-jar\", \"/deployments/quarkus-run.jar\" ]"));
assertThat(projectDir.resolve("src/main/docker/Dockerfile.legacy-jar")).exists()
.satisfies(checkContains("./mvnw package -Dquarkus.package.type=legacy-jar"))
.satisfies(checkContains("docker build -f src/main/docker/Dockerfile.legacy-jar"))
.satisfies(checkContains("registry.access.redhat.com/ubi8/ubi-minimal:8.4"))
.satisfies(checkContains("ARG JAVA_PACKAGE=java-11-openjdk-headless"))
.satisfies(checkContains("ENTRYPOINT [ \"/deployments/run-java.sh\" ]"));
.satisfies(checkContains("registry.access.redhat.com/ubi8/openjdk-11-runtime:1.10"))
.satisfies(checkContains("EXPOSE 8080"))
.satisfies(checkContains("USER 185"))
.satisfies(checkContains("ENTRYPOINT [ \"java\", \"-jar\", \"/deployments/quarkus-run.jar\" ]"));
assertThat(projectDir.resolve("src/main/docker/Dockerfile.native")).exists()
.satisfies(checkContains("./mvnw package -Pnative"))
.satisfies(checkContains("registry.access.redhat.com/ubi8/ubi-minimal:8.4"))
Expand Down

0 comments on commit 86030b3

Please sign in to comment.