diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0e6229a16..782474543 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,9 @@ jobs: - uses: actions/setup-java@v3 with: distribution: adopt - java-version: ${{ matrix.java }} + java-version: | + 22 + 17 cache: gradle - name: Build run: ./gradlew build @@ -41,7 +43,9 @@ jobs: - uses: actions/setup-java@v3 with: distribution: adopt - java-version: 17 + java-version: | + 22 + 17 cache: gradle - uses: jfrog/setup-jfrog-cli@v3 with: diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index ed6b6d679..3cb238fef 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -52,5 +52,9 @@ gradlePlugin { id = "org.springframework.shell.sample" implementationClass = "org.springframework.shell.gradle.SamplePlugin" } + toolchainPlugin { + id = "org.springframework.shell.toolchain" + implementationClass = "org.springframework.shell.gradle.ToolchainPlugin" + } } } diff --git a/buildSrc/src/main/java/org/springframework/shell/gradle/ToolchainExtension.java b/buildSrc/src/main/java/org/springframework/shell/gradle/ToolchainExtension.java new file mode 100644 index 000000000..5d68767e5 --- /dev/null +++ b/buildSrc/src/main/java/org/springframework/shell/gradle/ToolchainExtension.java @@ -0,0 +1,42 @@ +/* + * Copyright 2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.shell.gradle; + +import org.gradle.api.Project; +import org.gradle.api.provider.Property; +import org.gradle.jvm.toolchain.JavaLanguageVersion; + +public class ToolchainExtension { + + private final Property maximumCompatibleJavaVersion; + + private final JavaLanguageVersion javaVersion; + + public ToolchainExtension(Project project) { + this.maximumCompatibleJavaVersion = project.getObjects().property(JavaLanguageVersion.class); + String toolchainVersion = (String) project.findProperty("toolchainVersion"); + this.javaVersion = (toolchainVersion != null) ? JavaLanguageVersion.of(toolchainVersion) : null; + } + + public Property getMaximumCompatibleJavaVersion() { + return this.maximumCompatibleJavaVersion; + } + + JavaLanguageVersion getJavaVersion() { + return this.javaVersion; + } + +} \ No newline at end of file diff --git a/buildSrc/src/main/java/org/springframework/shell/gradle/ToolchainPlugin.java b/buildSrc/src/main/java/org/springframework/shell/gradle/ToolchainPlugin.java new file mode 100644 index 000000000..5e7c66b4b --- /dev/null +++ b/buildSrc/src/main/java/org/springframework/shell/gradle/ToolchainPlugin.java @@ -0,0 +1,47 @@ +/* + * Copyright 2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.shell.gradle; + +import org.gradle.api.Plugin; +import org.gradle.api.Project; +import org.gradle.api.plugins.JavaPluginExtension; +import org.gradle.jvm.toolchain.JavaLanguageVersion; +import org.gradle.jvm.toolchain.JavaToolchainSpec; + +public class ToolchainPlugin implements Plugin { + + @Override + public void apply(Project project) { + configureToolchain(project); + } + + private void configureToolchain(Project project) { + ToolchainExtension toolchain = project.getExtensions().create("toolchain", ToolchainExtension.class, project); + project.afterEvaluate((evaluated) -> configure(evaluated, toolchain)); + } + + private void configure(Project project, ToolchainExtension toolchain) { + JavaLanguageVersion toolchainVersion = toolchain.getJavaVersion(); + if (toolchainVersion == null) { + toolchainVersion = JavaLanguageVersion.of(22); + } + JavaToolchainSpec toolchainSpec = project.getExtensions() + .getByType(JavaPluginExtension.class) + .getToolchain(); + toolchainSpec.getLanguageVersion().set(toolchainVersion); + } + +} \ No newline at end of file diff --git a/spring-shell-samples/spring-shell-sample-ffm/spring-shell-sample-ffm.gradle b/spring-shell-samples/spring-shell-sample-ffm/spring-shell-sample-ffm.gradle new file mode 100644 index 000000000..25a6f61fa --- /dev/null +++ b/spring-shell-samples/spring-shell-sample-ffm/spring-shell-sample-ffm.gradle @@ -0,0 +1,20 @@ +plugins { + id 'org.springframework.shell.sample' + id 'org.springframework.shell.toolchain' +} + +description = 'Spring Shell Sample FFM' + +tasks.named("bootJar") { + manifest { + attributes 'Enable-Native-Access': 'ALL-UNNAMED' + } +} + +dependencies { + management platform(project(":spring-shell-management")) + implementation project(':spring-shell-starters:spring-shell-starter-ffm') + testImplementation project(':spring-shell-starters:spring-shell-starter-test') + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation 'org.awaitility:awaitility' +} diff --git a/spring-shell-samples/spring-shell-sample-ffm/src/main/java/org/springframework/shell/samples/ffm/SpringShellApplication.java b/spring-shell-samples/spring-shell-sample-ffm/src/main/java/org/springframework/shell/samples/ffm/SpringShellApplication.java new file mode 100644 index 000000000..29d8941cd --- /dev/null +++ b/spring-shell-samples/spring-shell-sample-ffm/src/main/java/org/springframework/shell/samples/ffm/SpringShellApplication.java @@ -0,0 +1,33 @@ +/* + * Copyright 2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.shell.samples.ffm; + +import org.springframework.boot.Banner.Mode; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.shell.command.annotation.CommandScan; + +@SpringBootApplication +@CommandScan +public class SpringShellApplication { + + public static void main(String[] args) throws Exception { + SpringApplication application = new SpringApplication(SpringShellApplication.class); + application.setBannerMode(Mode.OFF); + application.run(args); + } + +} diff --git a/spring-shell-samples/spring-shell-sample-ffm/src/main/resources/application.yml b/spring-shell-samples/spring-shell-sample-ffm/src/main/resources/application.yml new file mode 100644 index 000000000..8b75a2cca --- /dev/null +++ b/spring-shell-samples/spring-shell-sample-ffm/src/main/resources/application.yml @@ -0,0 +1,18 @@ +spring: + main: + banner-mode: off + shell: + interactive: + enabled: true +## disable console logging +logging: + pattern: + console: +## log debug from a cli + # file: + # name: shell-ffm.log + # level: + # root: debug + # org: + # springframework: + # shell: debug diff --git a/spring-shell-samples/spring-shell-sample-ffm/src/test/java/org/springframework/shell/samples/ffm/SpringShellApplicationTests.java b/spring-shell-samples/spring-shell-sample-ffm/src/test/java/org/springframework/shell/samples/ffm/SpringShellApplicationTests.java new file mode 100644 index 000000000..58bf6d8b7 --- /dev/null +++ b/spring-shell-samples/spring-shell-sample-ffm/src/test/java/org/springframework/shell/samples/ffm/SpringShellApplicationTests.java @@ -0,0 +1,20 @@ +/* + * Copyright 2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.shell.samples.ffm; + +public class SpringShellApplicationTests { + +} diff --git a/spring-shell-starters/spring-shell-starter-ffm/spring-shell-starter-ffm.gradle b/spring-shell-starters/spring-shell-starter-ffm/spring-shell-starter-ffm.gradle new file mode 100644 index 000000000..177b9aa3d --- /dev/null +++ b/spring-shell-starters/spring-shell-starter-ffm/spring-shell-starter-ffm.gradle @@ -0,0 +1,12 @@ +plugins { + id 'org.springframework.shell.starter' + id 'org.springframework.shell.toolchain' +} + +description = 'Spring Shell Starter FFM' + +dependencies { + management platform(project(':spring-shell-management')) + api(project(':spring-shell-starters:spring-shell-starter')) + implementation 'org.jline:jline-terminal-ffm' +}