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
  • Loading branch information
netodevel committed Nov 23, 2021
1 parent 2764b1f commit c338e50
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 44 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

This comment has been minimized.

Copy link
@maxandersen

maxandersen Nov 23, 2021

Member

should this not continue to be image so it continue to function with older clis?


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

This comment has been minimized.

Copy link
@maxandersen

maxandersen Nov 23, 2021

Member

is this USER id change expected?


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<Integer> JAVA_VERSIONS_LTS = List.of(8, 11, 17);

This comment has been minimized.

Copy link
@maxandersen

maxandersen Nov 23, 2021

Member

why is 8 even here ? if you run with java 8 we should still generate java 11 should we not ?

private static final int 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,16 @@ 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()) {
int versionExtracted = Integer.parseInt(matcher.group(1));
int version = JAVA_VERSIONS_LTS.stream()
.filter(e -> e.equals(versionExtracted))
.findFirst().orElse(DEFAULT_JAVA_VERSION);

values.put(ProjectGenerator.JAVA_TARGET, String.valueOf(version));
} else {
values.put(ProjectGenerator.JAVA_TARGET, "11");
values.put(ProjectGenerator.JAVA_TARGET, String.valueOf(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"));
}
}

0 comments on commit c338e50

Please sign in to comment.