Skip to content

Commit

Permalink
Introduce io.quarkus.code.java-version config
Browse files Browse the repository at this point in the history
This allows setting a default java version in the deployment descriptor

Use javaVersion in frontend

Add IO_QUARKUS_CODE_JAVA_VERSION to OpenShift template
  • Loading branch information
gastaldi committed Oct 11, 2022
1 parent beaa937 commit b14cf1e
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion api/src/main/kotlin/io/quarkus/code/model/PublicConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ data class PublicConfig(
val quarkusVersion: String,
val gitHubClientId: String?,
val features: List<String>,
val gitCommitId: String?
val gitCommitId: String?,
var javaVersion: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class CodeQuarkusResource {
quarkusDevtoolsVersion = ${config().quarkusDevtoolsVersion},
gitCommitId: ${config().gitCommitId},
features: ${config().features}
javaVersion: ${config().javaVersion}
""".trimIndent()
}
}
Expand All @@ -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
)
}

Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions library/components/api/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export interface Config {
gitCommitId: string;
gitHubClientId?: string;
features: string[];
javaVersion: string;
}


10 changes: 5 additions & 5 deletions library/components/api/quarkus-project-utils.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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: [],
Expand Down Expand Up @@ -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<string> {
Expand Down
2 changes: 1 addition & 1 deletion library/components/code-quarkus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const queryParams = getQueryParams();
export function ConfiguredCodeQuarkus(props: ConfiguredCodeQuarkusProps) {
const [ analytics, setAnalytics ] = useState<Analytics>(useAnalytics());
const [ filter, setFilter ] = useState(resolveInitialFilterQueryParam());
const [ project, setProject ] = useState<QuarkusProject>(resolveInitialProject(queryParams));
const [ project, setProject ] = useState<QuarkusProject>(resolveInitialProject(queryParams, props. config));

useEffect(() => {
setAnalytics((prev) => {
Expand Down
3 changes: 3 additions & 0 deletions openshift/code-quarkus-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b14cf1e

Please sign in to comment.