Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for java 17 in generated projects - Codestarts #20849

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ version = "{project.version}"

{#insert java}
java {
{#if java.version == "11"}
{#if java.version == "17"}
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
{#else}
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
{#else}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
{/if}
}
{/}
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ version '{project.version}'

{#insert java}
java {
{#if java.version == "11"}
{#if java.version == "17"}
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
{#else}
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
{#else}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
{/if}
}
{/}
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
ia3andy marked this conversation as resolved.
Show resolved Hide resolved

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
ia3andy marked this conversation as resolved.
Show resolved Hide resolved

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}
ia3andy marked this conversation as resolved.
Show resolved Hide resolved
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
ia3andy marked this conversation as resolved.
Show resolved Hide resolved
{/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 @@ -18,6 +18,9 @@
import javax.lang.model.SourceVersion;

public class CreateProjectHelper {

private static final Set<String> JAVA_VERSIONS_LTS = Set.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 +81,13 @@ 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.contains(versionExtracted) ? versionExtracted : 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"))
ia3andy marked this conversation as resolved.
Show resolved Hide resolved
.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