From b14cf1e968334d7a551564fb0c1493260c842a36 Mon Sep 17 00:00:00 2001 From: George Gastaldi Date: Mon, 10 Oct 2022 16:05:02 -0300 Subject: [PATCH] Introduce io.quarkus.code.java-version config This allows setting a default java version in the deployment descriptor Use javaVersion in frontend Add IO_QUARKUS_CODE_JAVA_VERSION to OpenShift template --- .../kotlin/io/quarkus/code/config/CodeQuarkusConfig.kt | 8 +++++++- .../kotlin/io/quarkus/code/model/ProjectDefinition.kt | 2 +- .../main/kotlin/io/quarkus/code/model/PublicConfig.kt | 3 ++- .../kotlin/io/quarkus/code/rest/CodeQuarkusResource.kt | 6 ++++-- library/components/api/model.ts | 1 + library/components/api/quarkus-project-utils.ts | 10 +++++----- library/components/code-quarkus.tsx | 2 +- openshift/code-quarkus-api.yaml | 3 +++ 8 files changed, 24 insertions(+), 11 deletions(-) diff --git a/api/src/main/kotlin/io/quarkus/code/config/CodeQuarkusConfig.kt b/api/src/main/kotlin/io/quarkus/code/config/CodeQuarkusConfig.kt index 58985b9f7..e624c40d4 100644 --- a/api/src/main/kotlin/io/quarkus/code/config/CodeQuarkusConfig.kt +++ b/api/src/main/kotlin/io/quarkus/code/config/CodeQuarkusConfig.kt @@ -1,8 +1,10 @@ package io.quarkus.code.config +import io.quarkus.code.model.ProjectDefinition import io.smallrye.config.ConfigMapping +import io.smallrye.config.WithDefault import io.smallrye.config.WithName -import java.util.* +import java.util.Optional @ConfigMapping(prefix = "io.quarkus.code") interface CodeQuarkusConfig { @@ -12,6 +14,10 @@ interface CodeQuarkusConfig { @get:WithName("quarkus-devtools-version") val quarkusDevtoolsVersion: String + @get:WithName("java-version") + @get:WithDefault(ProjectDefinition.DEFAULT_JAVA_VERSION) + val javaVersion: String + @get:WithName("git-commit-id") val gitCommitId: String diff --git a/api/src/main/kotlin/io/quarkus/code/model/ProjectDefinition.kt b/api/src/main/kotlin/io/quarkus/code/model/ProjectDefinition.kt index 18cb89215..783515d3c 100644 --- a/api/src/main/kotlin/io/quarkus/code/model/ProjectDefinition.kt +++ b/api/src/main/kotlin/io/quarkus/code/model/ProjectDefinition.kt @@ -173,7 +173,7 @@ class ProjectDefinition { result = 31 * result + noExamples.hashCode() result = 31 * result + noCode.hashCode() result = 31 * result + buildTool.hashCode() - result = 31 * result + javaVersion.hashCode() + result = 31 * result + (javaVersion?.hashCode() ?: 0) result = 31 * result + extensions.hashCode() return result } diff --git a/api/src/main/kotlin/io/quarkus/code/model/PublicConfig.kt b/api/src/main/kotlin/io/quarkus/code/model/PublicConfig.kt index 1f8c2ac92..47611242e 100644 --- a/api/src/main/kotlin/io/quarkus/code/model/PublicConfig.kt +++ b/api/src/main/kotlin/io/quarkus/code/model/PublicConfig.kt @@ -10,5 +10,6 @@ data class PublicConfig( val quarkusVersion: String, val gitHubClientId: String?, val features: List, - val gitCommitId: String? + val gitCommitId: String?, + var javaVersion: String ) \ No newline at end of file diff --git a/api/src/main/kotlin/io/quarkus/code/rest/CodeQuarkusResource.kt b/api/src/main/kotlin/io/quarkus/code/rest/CodeQuarkusResource.kt index d6903476f..cb2584a4e 100644 --- a/api/src/main/kotlin/io/quarkus/code/rest/CodeQuarkusResource.kt +++ b/api/src/main/kotlin/io/quarkus/code/rest/CodeQuarkusResource.kt @@ -66,6 +66,7 @@ class CodeQuarkusResource { quarkusDevtoolsVersion = ${config().quarkusDevtoolsVersion}, gitCommitId: ${config().gitCommitId}, features: ${config().features} + javaVersion: ${config().javaVersion} """.trimIndent() } } @@ -85,7 +86,8 @@ class CodeQuarkusResource { quarkusVersion= config.quarkusPlatformVersion, gitCommitId = config.gitCommitId, gitHubClientId = gitHubConfig.clientId.filter(String::isNotBlank).orElse(null), - features = config.features.map { listOf(it) }.orElse(listOf()) + features = config.features.map { listOf(it) }.orElse(listOf()), + javaVersion = config.javaVersion ) } @@ -212,7 +214,7 @@ class CodeQuarkusResource { if (projectDefinition.buildTool != ProjectDefinition.DEFAULT_BUILDTOOL) { params.add(BasicNameValuePair("b", projectDefinition.buildTool)) } - if (projectDefinition.javaVersion != ProjectDefinition.DEFAULT_JAVA_VERSION) { + if (projectDefinition.javaVersion != null && projectDefinition.javaVersion != config.javaVersion) { params.add(BasicNameValuePair("j", projectDefinition.javaVersion)) } if (projectDefinition.noCode != ProjectDefinition.DEFAULT_NO_CODE || projectDefinition.noExamples != ProjectDefinition.DEFAULT_NO_CODE) { diff --git a/library/components/api/model.ts b/library/components/api/model.ts index 872956809..791921e9d 100644 --- a/library/components/api/model.ts +++ b/library/components/api/model.ts @@ -69,6 +69,7 @@ export interface Config { gitCommitId: string; gitHubClientId?: string; features: string[]; + javaVersion: string; } diff --git a/library/components/api/quarkus-project-utils.ts b/library/components/api/quarkus-project-utils.ts index 9df56d7bb..0d918625e 100644 --- a/library/components/api/quarkus-project-utils.ts +++ b/library/components/api/quarkus-project-utils.ts @@ -1,6 +1,6 @@ import { parse, ParsedUrlQuery, stringify } from 'querystring'; import { createGitHubProject } from './code-quarkus-github-api'; -import { Extension, PlatformMappedExtensions, QuarkusProject } from './model'; +import {Config, Extension, PlatformMappedExtensions, QuarkusProject} from './model'; import _ from 'lodash'; import { Api } from './code-quarkus-api'; @@ -147,14 +147,14 @@ export const createOnGitHub = (api: Api, project: QuarkusProject, clientId: stri window.location.href = githubAuthorizeUrl; }; -export function newDefaultProject(): QuarkusProject { +export function newDefaultProject(config? : Config): QuarkusProject { return ({ metadata: { groupId: 'org.acme', artifactId: 'code-with-quarkus', version: '1.0.0-SNAPSHOT', buildTool: 'MAVEN', - javaVersion: '17', + javaVersion: config?.javaVersion || '17', noCode: false }, extensions: [], @@ -239,8 +239,8 @@ const generateParamQuery = (filter: string, project: string) => { return ''; }; -export function resolveInitialProject(queryParams?: ParsedUrlQuery) { - return parseProjectInQuery(queryParams) || retrieveProjectFromLocalStorage() || newDefaultProject(); +export function resolveInitialProject(queryParams?: ParsedUrlQuery, config?: Config) { + return parseProjectInQuery(queryParams) || retrieveProjectFromLocalStorage() || newDefaultProject(config); } function normalizeQueryExtensions(queryExtensions: undefined | string | string[]): Set { diff --git a/library/components/code-quarkus.tsx b/library/components/code-quarkus.tsx index 5074cc137..b7fd18c14 100644 --- a/library/components/code-quarkus.tsx +++ b/library/components/code-quarkus.tsx @@ -24,7 +24,7 @@ const queryParams = getQueryParams(); export function ConfiguredCodeQuarkus(props: ConfiguredCodeQuarkusProps) { const [ analytics, setAnalytics ] = useState(useAnalytics()); const [ filter, setFilter ] = useState(resolveInitialFilterQueryParam()); - const [ project, setProject ] = useState(resolveInitialProject(queryParams)); + const [ project, setProject ] = useState(resolveInitialProject(queryParams, props. config)); useEffect(() => { setAnalytics((prev) => { diff --git a/openshift/code-quarkus-api.yaml b/openshift/code-quarkus-api.yaml index 309759f2b..631cf5e07 100644 --- a/openshift/code-quarkus-api.yaml +++ b/openshift/code-quarkus-api.yaml @@ -113,6 +113,8 @@ objects: name: secrets key: ga-tracking-id optional: true + - name: IO_QUARKUS_CODE_JAVA_VERSION + value: ${IO_QUARKUS_CODE_JAVA_VERSION} envFrom: - configMapRef: name: code-quarkus-api-registry @@ -135,6 +137,7 @@ objects: sessionAffinity: None type: ClusterIP parameters: + - name: IO_QUARKUS_CODE_JAVA_VERSION - name: IO_QUARKUS_CODE_ENVIRONMENT - name: IO_QUARKUS_CODE_FEATURES - name: IO_QUARKUS_CODE_HOSTNAME