From 0a7f47835126e00e7634ffda67d2727f2173e092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zsef=20Bart=C3=B3k?= Date: Sat, 10 Dec 2022 14:08:18 +0200 Subject: [PATCH 1/4] Consider IBM and IBM_SEMERU vendors identical, deprecate the later --- .../src/docs/userguide/jvm/toolchains.adoc | 1 - .../migration/upgrading_version_7.adoc | 2 +- .../toolchain-filters/groovy/build.gradle | 2 +- .../toolchain-filters/kotlin/build.gradle.kts | 2 +- .../internal/jvm/inspection/JvmVendor.java | 3 +- .../DefaultJvmMetadataDetectorTest.groovy | 48 ++++-- ...avaToolchainDownloadIntegrationTest.groovy | 6 +- .../gradle/jvm/toolchain/JvmVendorSpec.java | 5 +- .../internal/JavaToolchainMatcher.java | 9 +- .../install/AdoptOpenJdkRemoteBinary.java | 4 +- .../AdoptOpenJdkRemoteBinaryTest.groovy | 4 +- .../internal/JavaToolchainMatcherTest.groovy | 162 ++++++++++++++++++ .../JavaToolchainQueryServiceTest.groovy | 6 +- 13 files changed, 218 insertions(+), 36 deletions(-) create mode 100644 subprojects/platform-jvm/src/test/groovy/org/gradle/jvm/toolchain/internal/JavaToolchainMatcherTest.groovy diff --git a/subprojects/docs/src/docs/userguide/jvm/toolchains.adoc b/subprojects/docs/src/docs/userguide/jvm/toolchains.adoc index 9d207d77ee86..d3bd070fbb2a 100644 --- a/subprojects/docs/src/docs/userguide/jvm/toolchains.adoc +++ b/subprojects/docs/src/docs/userguide/jvm/toolchains.adoc @@ -387,7 +387,6 @@ Sorting is done based on the following rules: .. GRAAL_VM .. HEWLETT_PACKARD .. IBM -.. IBM_SEMERU .. MICROSOFT .. ORACLE .. SAP diff --git a/subprojects/docs/src/docs/userguide/migration/upgrading_version_7.adoc b/subprojects/docs/src/docs/userguide/migration/upgrading_version_7.adoc index 2d90feea08ee..f3c6f02ecd95 100644 --- a/subprojects/docs/src/docs/userguide/migration/upgrading_version_7.adoc +++ b/subprojects/docs/src/docs/userguide/migration/upgrading_version_7.adoc @@ -538,7 +538,7 @@ Following the move from AdoptOpenJDK to Adoptium, under the Eclipse foundation, Instead, an Eclipse Temurin or IBM Semeru build is returned. Gradle 7.4+ will now emit a deprecation warning when the AdoptOpenJDK vendor is specified in the <> and it is used by auto provisioning. -If you must use AdoptOpenJDK, you should turn off auto-download. If an Eclipse Temurin or IBM Semeru build works for you, specify `JvmVendorSpec.ADOPTIUM` or `JvmVendorSpec.IBM_SEMERU` as the vendor or leave the vendor unspecified. +If you must use AdoptOpenJDK, you should turn off auto-download. If an Eclipse Temurin or IBM Semeru build works for you, specify `JvmVendorSpec.ADOPTIUM` or `JvmVendorSpec.IBM` as the vendor or leave the vendor unspecified. [[empty_directories_file_tree]] ==== File trees and empty directory handling diff --git a/subprojects/docs/src/snippets/java/toolchain-filters/groovy/build.gradle b/subprojects/docs/src/snippets/java/toolchain-filters/groovy/build.gradle index 8a431fa2eda2..39a69909f09c 100644 --- a/subprojects/docs/src/snippets/java/toolchain-filters/groovy/build.gradle +++ b/subprojects/docs/src/snippets/java/toolchain-filters/groovy/build.gradle @@ -25,7 +25,7 @@ java { java { toolchain { languageVersion = JavaLanguageVersion.of(11) - vendor = JvmVendorSpec.IBM_SEMERU + vendor = JvmVendorSpec.IBM implementation = JvmImplementation.J9 } } diff --git a/subprojects/docs/src/snippets/java/toolchain-filters/kotlin/build.gradle.kts b/subprojects/docs/src/snippets/java/toolchain-filters/kotlin/build.gradle.kts index b6b13a6edaa7..a91542f7450c 100644 --- a/subprojects/docs/src/snippets/java/toolchain-filters/kotlin/build.gradle.kts +++ b/subprojects/docs/src/snippets/java/toolchain-filters/kotlin/build.gradle.kts @@ -26,7 +26,7 @@ java { java { toolchain { languageVersion.set(JavaLanguageVersion.of(11)) - vendor.set(JvmVendorSpec.IBM_SEMERU) + vendor.set(JvmVendorSpec.IBM) implementation.set(JvmImplementation.J9) } } diff --git a/subprojects/jvm-services/src/main/java/org/gradle/internal/jvm/inspection/JvmVendor.java b/subprojects/jvm-services/src/main/java/org/gradle/internal/jvm/inspection/JvmVendor.java index 0e053e322649..31f8edd5a943 100644 --- a/subprojects/jvm-services/src/main/java/org/gradle/internal/jvm/inspection/JvmVendor.java +++ b/subprojects/jvm-services/src/main/java/org/gradle/internal/jvm/inspection/JvmVendor.java @@ -29,8 +29,7 @@ enum KnownJvmVendor { BELLSOFT("bellsoft", "BellSoft Liberica"), GRAAL_VM("graalvm community", "GraalVM Community"), HEWLETT_PACKARD("hewlett-packard", "HP-UX"), - IBM("ibm", "IBM"), - IBM_SEMERU("international business machines corporation", "IBM Semeru Runtimes"), + IBM("ibm", "ibm|international business machines corporation", "IBM"), MICROSOFT("microsoft", "Microsoft"), ORACLE("oracle", "Oracle"), SAP("sap se", "SAP SapMachine"), diff --git a/subprojects/jvm-services/src/test/groovy/org/gradle/internal/jvm/inspection/DefaultJvmMetadataDetectorTest.groovy b/subprojects/jvm-services/src/test/groovy/org/gradle/internal/jvm/inspection/DefaultJvmMetadataDetectorTest.groovy index df1a15e4f4e6..66aac24d49c0 100644 --- a/subprojects/jvm-services/src/test/groovy/org/gradle/internal/jvm/inspection/DefaultJvmMetadataDetectorTest.groovy +++ b/subprojects/jvm-services/src/test/groovy/org/gradle/internal/jvm/inspection/DefaultJvmMetadataDetectorTest.groovy @@ -120,12 +120,9 @@ class DefaultJvmMetadataDetectorTest extends Specification { 'temurinjdk17' | temurinJvm('17') | JavaVersion.VERSION_17 | 'Eclipse Temurin JDK 17' | false 'temurinjre8' | temurin8Jvm('8') | JavaVersion.VERSION_1_8 | 'Eclipse Temurin JRE 8' | true 'temurinjre11' | temurin11Jvm('11') | JavaVersion.VERSION_11 | 'Eclipse Temurin JRE 11' | true - 'semerujdk8' | semeruJvm('8') | JavaVersion.VERSION_1_8 | 'IBM Semeru Runtimes JDK 8' | false - 'semerujdk11' | semeruJvm('11') | JavaVersion.VERSION_11 | 'IBM Semeru Runtimes JDK 11' | false - 'semerujdk16' | semeruJvm('16') | JavaVersion.VERSION_16 | 'IBM Semeru Runtimes JDK 16' | false - 'semerujre8' | semeruJvm('8') | JavaVersion.VERSION_1_8 | 'IBM Semeru Runtimes JRE 8' | true - 'semerujre11' | semeruJvm('11') | JavaVersion.VERSION_11 | 'IBM Semeru Runtimes JRE 11' | true - 'semerujre16' | semeruJvm('16') | JavaVersion.VERSION_16 | 'IBM Semeru Runtimes JRE 16' | true + 'semerujdk11' | semeruJvm11() | JavaVersion.VERSION_11 | 'IBM JDK 11' | false + 'semerujdk16' | semeruJvm16() | JavaVersion.VERSION_16 | 'IBM JDK 16' | false + 'semerujdk17' | semeruJvm17() | JavaVersion.VERSION_17 | 'IBM JDK 17' | false 'whitespaces' | whitespaces('11.0.3') | JavaVersion.VERSION_11 | 'AdoptOpenJDK JRE 11' | true } @@ -154,9 +151,8 @@ class DefaultJvmMetadataDetectorTest extends Specification { 'ibmJdk7' | ibmJvm('7') | true 'ibmJdk8' | ibmJvm('8') | true 'ibmJdk9' | ibmJvm('9') | true - 'semeru8' | semeruJvm('8') | true - 'semeru11' | semeruJvm('11') | true - 'semeru16' | semeruJvm('16') | true + 'semeru11' | semeruJvm11() | true + 'semeru16' | semeruJvm16() | true 'temurin8' | temurin8Jvm('8') | false 'temurin11' | temurin11Jvm('11') | false 'temurin17' | temurinJvm('17') | false @@ -436,16 +432,42 @@ class DefaultJvmMetadataDetectorTest extends Specification { ] } - private static Map semeruJvm(String version) { + private static Map semeruJvm11() { ['java.home': "java-home", - 'java.version': "${version}", + 'java.version': "11.0.17", + 'java.vendor': "IBM Corporation", + 'os.arch': "x86_64", + 'java.vm.name': "Eclipse OpenJ9 VM", + 'java.vm.version': "openj9-0.35.0", + 'java.vm.vendor': "Eclipse OpenJ9", + 'java.runtime.name': "IBM Semeru Runtime Open Edition", + 'java.runtime.version': "11.0.17+8" + ] + } + + private static Map semeruJvm16() { + ['java.home': "java-home", + 'java.version': "16.0.2", 'java.vendor': "International Business Machines Corporation", 'os.arch': "x86_64", 'java.vm.name': "Eclipse OpenJ9 VM", 'java.vm.version': "openj9-0.27.0", - 'java.vm.vendor': "International Business Machines Corporation", + 'java.vm.vendor': "Eclipse OpenJ9", 'java.runtime.name': "IBM Semeru Runtime Open Edition", - 'java.runtime.version': "${version}-b08" + 'java.runtime.version': "16.0.2+7" + ] + } + + private static Map semeruJvm17() { + ['java.home': "java-home", + 'java.version': "17.0.5", + 'java.vendor': "IBM Corporation", + 'os.arch': "x86_64", + 'java.vm.name': "Eclipse OpenJ9 VM", + 'java.vm.version': "openj9-0.35.0", + 'java.vm.vendor': "Eclipse OpenJ9", + 'java.runtime.name': "IBM Semeru Runtime Open Edition", + 'java.runtime.version': "17.0.5+8" ] } diff --git a/subprojects/platform-jvm/src/integTest/groovy/org/gradle/jvm/toolchain/JavaToolchainDownloadIntegrationTest.groovy b/subprojects/platform-jvm/src/integTest/groovy/org/gradle/jvm/toolchain/JavaToolchainDownloadIntegrationTest.groovy index c8733dcd2e9d..dc8ac783a409 100644 --- a/subprojects/platform-jvm/src/integTest/groovy/org/gradle/jvm/toolchain/JavaToolchainDownloadIntegrationTest.groovy +++ b/subprojects/platform-jvm/src/integTest/groovy/org/gradle/jvm/toolchain/JavaToolchainDownloadIntegrationTest.groovy @@ -241,14 +241,14 @@ class JavaToolchainDownloadIntegrationTest extends AbstractIntegrationSpec { } @ToBeFixedForConfigurationCache(because = "Fails the build with an additional error") - def 'toolchain download of Semeru forces openj9'() { + def 'toolchain download of IBM forces openj9'() { buildFile << """ apply plugin: "java" java { toolchain { languageVersion = JavaLanguageVersion.of(99) - vendor = JvmVendorSpec.IBM_SEMERU + vendor = JvmVendorSpec.IBM } } """ @@ -274,7 +274,7 @@ class JavaToolchainDownloadIntegrationTest extends AbstractIntegrationSpec { then: failure.assertHasDescription("Execution failed for task ':compileJava'.") .assertHasCause("Failed to calculate the value of task ':compileJava' property 'javaCompiler'") - .assertHasCause("Unable to download toolchain matching the requirements ({languageVersion=99, vendor=IBM_SEMERU, implementation=vendor-specific}) from 'https://example.com/v3/binary/latest/99/ga/${os()}/${architecture()}/jdk/openj9/normal/adoptopenjdk'.") + .assertHasCause("Unable to download toolchain matching the requirements ({languageVersion=99, vendor=IBM, implementation=vendor-specific}) from 'https://example.com/v3/binary/latest/99/ga/${os()}/${architecture()}/jdk/openj9/normal/adoptopenjdk'.") .assertHasCause("Could not read 'https://example.com/v3/binary/latest/99/ga/${os()}/${architecture()}/jdk/openj9/normal/adoptopenjdk' as it does not exist.") } diff --git a/subprojects/platform-jvm/src/main/java/org/gradle/jvm/toolchain/JvmVendorSpec.java b/subprojects/platform-jvm/src/main/java/org/gradle/jvm/toolchain/JvmVendorSpec.java index 8d5d9b4afb97..84d0ce811f16 100644 --- a/subprojects/platform-jvm/src/main/java/org/gradle/jvm/toolchain/JvmVendorSpec.java +++ b/subprojects/platform-jvm/src/main/java/org/gradle/jvm/toolchain/JvmVendorSpec.java @@ -54,9 +54,10 @@ public abstract class JvmVendorSpec { * A constant for using IBM Semeru Runtimes as the JVM vendor. * * @since 7.4 + * @deprecated All IBM runtimes are Semeru runtimes, so no point in having two separate vendor definitions. IBM should be used instead. */ - @Incubating - public static final JvmVendorSpec IBM_SEMERU = matching(KnownJvmVendor.IBM_SEMERU); + @Deprecated + public static final JvmVendorSpec IBM_SEMERU = IBM; /** * A constant for using Microsoft OpenJDK as the JVM vendor. diff --git a/subprojects/platform-jvm/src/main/java/org/gradle/jvm/toolchain/internal/JavaToolchainMatcher.java b/subprojects/platform-jvm/src/main/java/org/gradle/jvm/toolchain/internal/JavaToolchainMatcher.java index f6c1f9e82066..1a99ca10e62a 100644 --- a/subprojects/platform-jvm/src/main/java/org/gradle/jvm/toolchain/internal/JavaToolchainMatcher.java +++ b/subprojects/platform-jvm/src/main/java/org/gradle/jvm/toolchain/internal/JavaToolchainMatcher.java @@ -21,7 +21,6 @@ import org.gradle.jvm.toolchain.JavaLanguageVersion; import org.gradle.jvm.toolchain.JavaToolchainSpec; import org.gradle.jvm.toolchain.JvmImplementation; -import org.gradle.jvm.toolchain.JvmVendorSpec; import java.util.function.Predicate; @@ -69,12 +68,12 @@ private static boolean isJ9ExplicitlyRequested(JavaToolchainSpec spec) { private static boolean isJ9RequestedViaVendor(JavaToolchainSpec spec) { DefaultJvmVendorSpec vendorSpec = (DefaultJvmVendorSpec) spec.getVendor().get(); - return vendorSpec != DefaultJvmVendorSpec.any() && vendorSpec.test(JvmVendor.KnownJvmVendor.IBM_SEMERU.asJvmVendor()); + return vendorSpec != DefaultJvmVendorSpec.any() && vendorSpec.test(JvmVendor.KnownJvmVendor.IBM.asJvmVendor()); } @SuppressWarnings("unchecked") - private Predicate vendorPredicate() { - JvmVendorSpec vendorSpec = spec.getVendor().get(); - return (Predicate) vendorSpec; + private Predicate vendorPredicate() { + return (DefaultJvmVendorSpec) spec.getVendor().get(); } + } diff --git a/subprojects/platform-jvm/src/main/java/org/gradle/jvm/toolchain/internal/install/AdoptOpenJdkRemoteBinary.java b/subprojects/platform-jvm/src/main/java/org/gradle/jvm/toolchain/internal/install/AdoptOpenJdkRemoteBinary.java index 872f86e49769..bffaaec42ae7 100644 --- a/subprojects/platform-jvm/src/main/java/org/gradle/jvm/toolchain/internal/install/AdoptOpenJdkRemoteBinary.java +++ b/subprojects/platform-jvm/src/main/java/org/gradle/jvm/toolchain/internal/install/AdoptOpenJdkRemoteBinary.java @@ -77,7 +77,7 @@ private boolean matchesVendor(JavaToolchainSpec spec) { return true; } - return vendorSpec.test(JvmVendor.KnownJvmVendor.IBM_SEMERU.asJvmVendor()); + return vendorSpec.test(JvmVendor.KnownJvmVendor.IBM.asJvmVendor()); } private URI constructUri(JavaToolchainSpec spec, BuildPlatform platform) { @@ -171,7 +171,7 @@ private static boolean isJ9ExplicitlyRequested(JavaToolchainSpec spec) { private static boolean isJ9RequestedViaVendor(JavaToolchainSpec spec) { DefaultJvmVendorSpec vendorSpec = (DefaultJvmVendorSpec) spec.getVendor().get(); - return vendorSpec != DefaultJvmVendorSpec.any() && vendorSpec.test(JvmVendor.KnownJvmVendor.IBM_SEMERU.asJvmVendor()); + return vendorSpec != DefaultJvmVendorSpec.any() && vendorSpec.test(JvmVendor.KnownJvmVendor.IBM.asJvmVendor()); } } diff --git a/subprojects/platform-jvm/src/test/groovy/org/gradle/jvm/toolchain/install/internal/AdoptOpenJdkRemoteBinaryTest.groovy b/subprojects/platform-jvm/src/test/groovy/org/gradle/jvm/toolchain/install/internal/AdoptOpenJdkRemoteBinaryTest.groovy index e836dade7dec..09cbfcaa8c85 100644 --- a/subprojects/platform-jvm/src/test/groovy/org/gradle/jvm/toolchain/install/internal/AdoptOpenJdkRemoteBinaryTest.groovy +++ b/subprojects/platform-jvm/src/test/groovy/org/gradle/jvm/toolchain/install/internal/AdoptOpenJdkRemoteBinaryTest.groovy @@ -116,7 +116,7 @@ class AdoptOpenJdkRemoteBinaryTest extends Specification { !download.isPresent() where: - vendor << [JvmVendorSpec.AMAZON, JvmVendorSpec.IBM] + vendor << [JvmVendorSpec.AMAZON] } def "can provide matching vendor spec using #vendor"() { @@ -136,7 +136,7 @@ class AdoptOpenJdkRemoteBinaryTest extends Specification { download.get().getUri() == URI.create("https://api.adoptopenjdk.net/v3/binary/latest/12/ga/mac/x64/jdk/hotspot/normal/adoptopenjdk") where: - vendor << [JvmVendorSpec.ADOPTOPENJDK, JvmVendorSpec.matching("adoptopenjdk"), DefaultJvmVendorSpec.any()] + vendor << [JvmVendorSpec.ADOPTOPENJDK, JvmVendorSpec.IBM, JvmVendorSpec.matching("adoptopenjdk"), DefaultJvmVendorSpec.any()] } def "can provide j9 impl if requested"() { diff --git a/subprojects/platform-jvm/src/test/groovy/org/gradle/jvm/toolchain/internal/JavaToolchainMatcherTest.groovy b/subprojects/platform-jvm/src/test/groovy/org/gradle/jvm/toolchain/internal/JavaToolchainMatcherTest.groovy new file mode 100644 index 000000000000..a5a896d3f6ed --- /dev/null +++ b/subprojects/platform-jvm/src/test/groovy/org/gradle/jvm/toolchain/internal/JavaToolchainMatcherTest.groovy @@ -0,0 +1,162 @@ +/* + * Copyright 2022 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 + * + * http://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.gradle.jvm.toolchain.internal + +import org.gradle.api.JavaVersion +import org.gradle.api.internal.file.TestFiles +import org.gradle.internal.jvm.inspection.DefaultJvmMetadataDetector +import org.gradle.internal.jvm.inspection.MetadataProbe +import org.gradle.internal.jvm.inspection.ProbedSystemProperty +import org.gradle.jvm.toolchain.JavaLanguageVersion +import org.gradle.jvm.toolchain.JvmImplementation +import org.gradle.jvm.toolchain.JvmVendorSpec +import org.gradle.process.ExecResult +import org.gradle.process.internal.ExecHandle +import org.gradle.process.internal.ExecHandleBuilder +import org.gradle.process.internal.ExecHandleFactory +import org.gradle.test.fixtures.file.TestFile +import org.gradle.util.TestUtil +import spock.lang.Specification +import spock.lang.TempDir + +class JavaToolchainMatcherTest extends Specification { + + @TempDir + File temporaryFolder + + TestFile tmpDir + def setup() { + tmpDir = new TestFile(new File(temporaryFolder, "tmp").tap { mkdirs() }) + } + + def "ibm vendors match semeru runtime metadata (java version: #javaVersion, vendor: #vendor, implementation: #implementation)"() { + given: + def execHandleFactory = createExecHandleFactory(systemProperties) + def detector = createDefaultJvmMetadataDetector(execHandleFactory) + def javaHome = new File(temporaryFolder, jdk).tap { mkdirs() } + def metadata = detector.getMetadata(testLocation(javaHome)) + + when: + def spec = new DefaultToolchainSpec(TestUtil.objectFactory()) + spec.getLanguageVersion().set(JavaLanguageVersion.of(javaVersion.getMajorVersion())) + spec.getVendor().set(vendor) + spec.getImplementation().set(implementation) + + then: + new JavaToolchainMatcher(spec).test(metadata) + + where: + jdk | systemProperties | javaVersion | vendor | implementation + 'semeru11' | semeruJvm11() | JavaVersion.VERSION_11 | JvmVendorSpec.IBM | JvmImplementation.VENDOR_SPECIFIC + 'semeru16' | semeruJvm16() | JavaVersion.VERSION_16 | JvmVendorSpec.IBM | JvmImplementation.VENDOR_SPECIFIC + 'semeru17' | semeruJvm17() | JavaVersion.VERSION_17 | JvmVendorSpec.IBM | JvmImplementation.VENDOR_SPECIFIC + + 'semeru11' | semeruJvm11() | JavaVersion.VERSION_11 | JvmVendorSpec.IBM | JvmImplementation.J9 + 'semeru16' | semeruJvm16() | JavaVersion.VERSION_16 | JvmVendorSpec.IBM | JvmImplementation.J9 + 'semeru17' | semeruJvm17() | JavaVersion.VERSION_17 | JvmVendorSpec.IBM | JvmImplementation.J9 + + 'semeru11' | semeruJvm11() | JavaVersion.VERSION_11 | JvmVendorSpec.IBM_SEMERU | JvmImplementation.VENDOR_SPECIFIC + 'semeru16' | semeruJvm16() | JavaVersion.VERSION_16 | JvmVendorSpec.IBM_SEMERU | JvmImplementation.VENDOR_SPECIFIC + 'semeru17' | semeruJvm17() | JavaVersion.VERSION_17 | JvmVendorSpec.IBM_SEMERU | JvmImplementation.VENDOR_SPECIFIC + + 'semeru11' | semeruJvm11() | JavaVersion.VERSION_11 | JvmVendorSpec.IBM_SEMERU | JvmImplementation.J9 + 'semeru16' | semeruJvm16() | JavaVersion.VERSION_16 | JvmVendorSpec.IBM_SEMERU | JvmImplementation.J9 + 'semeru17' | semeruJvm17() | JavaVersion.VERSION_17 | JvmVendorSpec.IBM_SEMERU | JvmImplementation.J9 + } + + def createExecHandleFactory(Map actualProperties) { + def probedSystemProperties = ProbedSystemProperty.values().findAll { it != ProbedSystemProperty.Z_ERROR } + if (!actualProperties.isEmpty()) { + assert actualProperties.keySet() == probedSystemProperties.collect { it.systemPropertyKey }.toSet() + } + + def execHandleFactory = Mock(ExecHandleFactory) + def exec = Mock(ExecHandleBuilder) + execHandleFactory.newExec() >> exec + PrintStream output + exec.setStandardOutput(_ as OutputStream) >> { OutputStream outputStream -> + output = new PrintStream(outputStream) + null + } + def handle = Mock(ExecHandle) + handle.start() >> handle + handle.waitForFinish() >> { + // important to output in the order of the enum members as parsing uses enum ordinals + probedSystemProperties.each { + def actualValue = actualProperties[it.systemPropertyKey] + // write conditionally to simulate wrong number of outputs + if (actualValue != null) { + output.println(MetadataProbe.MARKER_PREFIX + actualValue) + } + } + Mock(ExecResult) + } + exec.build() >> handle + execHandleFactory + } + + private DefaultJvmMetadataDetector createDefaultJvmMetadataDetector(ExecHandleFactory execHandleFactory) { + return new DefaultJvmMetadataDetector( + execHandleFactory, + TestFiles.tmpDirTemporaryFileProvider(tmpDir) + ) + } + + private InstallationLocation testLocation(File javaHome) { + new InstallationLocation(javaHome, "test") + } + + private static Map semeruJvm11() { + ['java.home': "java-home", + 'java.version': "11.0.17", + 'java.vendor': "IBM Corporation", + 'os.arch': "x86_64", + 'java.vm.name': "Eclipse OpenJ9 VM", + 'java.vm.version': "openj9-0.35.0", + 'java.vm.vendor': "Eclipse OpenJ9", + 'java.runtime.name': "IBM Semeru Runtime Open Edition", + 'java.runtime.version': "11.0.17+8" + ] + } + + private static Map semeruJvm16() { + ['java.home': "java-home", + 'java.version': "16.0.2", + 'java.vendor': "International Business Machines Corporation", + 'os.arch': "x86_64", + 'java.vm.name': "Eclipse OpenJ9 VM", + 'java.vm.version': "openj9-0.27.0", + 'java.vm.vendor': "Eclipse OpenJ9", + 'java.runtime.name': "IBM Semeru Runtime Open Edition", + 'java.runtime.version': "16.0.2+7" + ] + } + + private static Map semeruJvm17() { + ['java.home': "java-home", + 'java.version': "17.0.5", + 'java.vendor': "IBM Corporation", + 'os.arch': "x86_64", + 'java.vm.name': "Eclipse OpenJ9 VM", + 'java.vm.version': "openj9-0.35.0", + 'java.vm.vendor': "Eclipse OpenJ9", + 'java.runtime.name': "IBM Semeru Runtime Open Edition", + 'java.runtime.version': "17.0.5+8" + ] + } + +} diff --git a/subprojects/platform-jvm/src/test/groovy/org/gradle/jvm/toolchain/internal/JavaToolchainQueryServiceTest.groovy b/subprojects/platform-jvm/src/test/groovy/org/gradle/jvm/toolchain/internal/JavaToolchainQueryServiceTest.groovy index 4f0574a37b39..d2d99a288fc7 100644 --- a/subprojects/platform-jvm/src/test/groovy/org/gradle/jvm/toolchain/internal/JavaToolchainQueryServiceTest.groovy +++ b/subprojects/platform-jvm/src/test/groovy/org/gradle/jvm/toolchain/internal/JavaToolchainQueryServiceTest.groovy @@ -157,13 +157,13 @@ class JavaToolchainQueryServiceTest extends Specification { when: def filter = new DefaultToolchainSpec(TestUtil.objectFactory()) filter.languageVersion.set(JavaLanguageVersion.of(8)) - filter.vendor.set(JvmVendorSpec.IBM_SEMERU) + filter.vendor.set(JvmVendorSpec.IBM) def toolchain = queryService.findMatchingToolchain(filter) then: toolchain.isPresent() - toolchain.get().metadata.vendor.knownVendor == JvmVendor.KnownJvmVendor.IBM_SEMERU - toolchain.get().vendor == "IBM Semeru Runtimes" + toolchain.get().metadata.vendor.knownVendor == JvmVendor.KnownJvmVendor.IBM + toolchain.get().vendor == "IBM" } def "ignores invalid toolchains when finding a matching one"() { From 25e4fa7724f90427f7a7d93904aecafb2c4d3803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zsef=20Bart=C3=B3k?= Date: Mon, 12 Dec 2022 15:20:40 +0200 Subject: [PATCH 2/4] Fix test --- .../install/internal/AdoptOpenJdkRemoteBinaryTest.groovy | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/subprojects/platform-jvm/src/test/groovy/org/gradle/jvm/toolchain/install/internal/AdoptOpenJdkRemoteBinaryTest.groovy b/subprojects/platform-jvm/src/test/groovy/org/gradle/jvm/toolchain/install/internal/AdoptOpenJdkRemoteBinaryTest.groovy index 09cbfcaa8c85..91da7e595df1 100644 --- a/subprojects/platform-jvm/src/test/groovy/org/gradle/jvm/toolchain/install/internal/AdoptOpenJdkRemoteBinaryTest.groovy +++ b/subprojects/platform-jvm/src/test/groovy/org/gradle/jvm/toolchain/install/internal/AdoptOpenJdkRemoteBinaryTest.groovy @@ -133,10 +133,14 @@ class AdoptOpenJdkRemoteBinaryTest extends Specification { then: download.isPresent() - download.get().getUri() == URI.create("https://api.adoptopenjdk.net/v3/binary/latest/12/ga/mac/x64/jdk/hotspot/normal/adoptopenjdk") + download.get().getUri() == URI.create("https://api.adoptopenjdk.net/v3/binary/latest/12/ga/mac/x64/jdk/${implementation}/normal/adoptopenjdk") where: - vendor << [JvmVendorSpec.ADOPTOPENJDK, JvmVendorSpec.IBM, JvmVendorSpec.matching("adoptopenjdk"), DefaultJvmVendorSpec.any()] + vendor | implementation + JvmVendorSpec.IBM | "openj9" + JvmVendorSpec.ADOPTOPENJDK | "hotspot" + JvmVendorSpec.matching("adoptopenjdk") | "hotspot" + DefaultJvmVendorSpec.any() | "hotspot" } def "can provide j9 impl if requested"() { From d5fae0cf0f3044c3c3c42c413c67e69be7184a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zsef=20Bart=C3=B3k?= Date: Wed, 14 Dec 2022 13:56:31 +0200 Subject: [PATCH 3/4] Fix deprecation message --- .../java/org/gradle/jvm/toolchain/JvmVendorSpec.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/subprojects/platform-jvm/src/main/java/org/gradle/jvm/toolchain/JvmVendorSpec.java b/subprojects/platform-jvm/src/main/java/org/gradle/jvm/toolchain/JvmVendorSpec.java index 84d0ce811f16..3fa4289c195e 100644 --- a/subprojects/platform-jvm/src/main/java/org/gradle/jvm/toolchain/JvmVendorSpec.java +++ b/subprojects/platform-jvm/src/main/java/org/gradle/jvm/toolchain/JvmVendorSpec.java @@ -34,10 +34,15 @@ public abstract class JvmVendorSpec { */ @Incubating public static final JvmVendorSpec ADOPTIUM = matching(KnownJvmVendor.ADOPTIUM); + public static final JvmVendorSpec ADOPTOPENJDK = matching(KnownJvmVendor.ADOPTOPENJDK); + public static final JvmVendorSpec AMAZON = matching(KnownJvmVendor.AMAZON); + public static final JvmVendorSpec APPLE = matching(KnownJvmVendor.APPLE); + public static final JvmVendorSpec AZUL = matching(KnownJvmVendor.AZUL); + public static final JvmVendorSpec BELLSOFT = matching(KnownJvmVendor.BELLSOFT); /** @@ -49,12 +54,14 @@ public abstract class JvmVendorSpec { public static final JvmVendorSpec GRAAL_VM = matching(KnownJvmVendor.GRAAL_VM); public static final JvmVendorSpec HEWLETT_PACKARD = matching(KnownJvmVendor.HEWLETT_PACKARD); + public static final JvmVendorSpec IBM = matching(KnownJvmVendor.IBM); + /** * A constant for using IBM Semeru Runtimes as the JVM vendor. * * @since 7.4 - * @deprecated All IBM runtimes are Semeru runtimes, so no point in having two separate vendor definitions. IBM should be used instead. + * @deprecated We are grouping all IBM runtimes under the '{@code IBM}' vendor, won't keep a separate constant for Semeru ones. Just use '{@code IBM}' instead. */ @Deprecated public static final JvmVendorSpec IBM_SEMERU = IBM; @@ -66,7 +73,9 @@ public abstract class JvmVendorSpec { */ @Incubating public static final JvmVendorSpec MICROSOFT = matching(KnownJvmVendor.MICROSOFT); + public static final JvmVendorSpec ORACLE = matching(KnownJvmVendor.ORACLE); + public static final JvmVendorSpec SAP = matching(KnownJvmVendor.SAP); /** From 55896a8e66353126951828b47e36a5fc61620013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zsef=20Bart=C3=B3k?= Date: Wed, 14 Dec 2022 13:59:39 +0200 Subject: [PATCH 4/4] Reformat to one sentence per line --- .../migration/upgrading_version_7.adoc | 109 ++++++++++++------ 1 file changed, 72 insertions(+), 37 deletions(-) diff --git a/subprojects/docs/src/docs/userguide/migration/upgrading_version_7.adoc b/subprojects/docs/src/docs/userguide/migration/upgrading_version_7.adoc index f3c6f02ecd95..ba2871372864 100644 --- a/subprojects/docs/src/docs/userguide/migration/upgrading_version_7.adoc +++ b/subprojects/docs/src/docs/userguide/migration/upgrading_version_7.adoc @@ -15,7 +15,8 @@ [[upgrading_version_7]] = Upgrading your build from Gradle 7.x to the latest -This chapter provides the information you need to migrate your Gradle 7.x builds to the latest Gradle release. For migrating from Gradle 4.x, 5.x, or 6.x, see the <> first. +This chapter provides the information you need to migrate your Gradle 7.x builds to the latest Gradle release. +For migrating from Gradle 4.x, 5.x, or 6.x, see the <> first. We recommend the following steps for all users: @@ -28,7 +29,8 @@ This is so that you can see any deprecation warnings that apply to your build. Alternatively, you could run `gradle help --warning-mode=all` to see the deprecations in the console, though it may not report as much detailed information. . Update your plugins. + -Some plugins will break with this new version of Gradle, for example because they use internal APIs that have been removed or changed. The previous step will help you identify potential problems by issuing deprecation warnings when a plugin does try to use a deprecated part of the API. +Some plugins will break with this new version of Gradle, for example because they use internal APIs that have been removed or changed. +The previous step will help you identify potential problems by issuing deprecation warnings when a plugin does try to use a deprecated part of the API. + . Run `gradle wrapper --gradle-version {gradleVersion}` to update the project to {gradleVersion}. . Try to run the project and debug any errors using the <>. @@ -166,7 +168,8 @@ Other syntax effected by this change includes: - You cannot use `Provider` as a dependency declaration. - You cannot use a `Map` as a dependency declaration for Kotlin or Java. -- You cannot use a bundle as a dependency declaration directly (`implementation(libs.bundles.testing)`). Use `implementation.bundle(libs.bundles.testing)` instead. +- You cannot use a bundle as a dependency declaration directly (`implementation(libs.bundles.testing)`). +Use `implementation.bundle(libs.bundles.testing)` instead. For more information, see the updated <> example in the JVM Test Suite Plugin section of the user guide and the link:{groovyDslPath}/org.gradle.api.artifacts.dsl.DependencyAdder.html[`DependencyAdder`] page in the DSL reference. @@ -206,14 +209,18 @@ These members will be removed in Gradle 9.0. [[dependency_factory_renamed]] ==== Internal DependencyFactory was renamed -The internal `org.gradle.api.internal.artifacts.dsl.dependencies.DependencyFactory` type was renamed to `org.gradle.api.internal.artifacts.dsl.dependencies.DependencyFactoryInternal`. As an internal type, it should not be used, but for compatibility reasons the inner `ClassPathNotation` type is still available. This name for the type is deprecated and will be removed in Gradle 8.0. The public API for this is on `DependencyHandler`, with methods such as `localGroovy()` providing the same functionality. +The internal `org.gradle.api.internal.artifacts.dsl.dependencies.DependencyFactory` type was renamed to `org.gradle.api.internal.artifacts.dsl.dependencies.DependencyFactoryInternal`. +As an internal type, it should not be used, but for compatibility reasons the inner `ClassPathNotation` type is still available. +This name for the type is deprecated and will be removed in Gradle 8.0. +The public API for this is on `DependencyHandler`, with methods such as `localGroovy()` providing the same functionality. ==== Replacement collections in `org.gradle.plugins.ide.idea.model.IdeaModule` The `testResourcesDirs` and `testSourcesDirs` fields and their getters and setters have been deprecated. Replace usages with the now stable `getTestSources()` and `getTestResources()` methods and their respective setters. These new methods return and are backed by `ConfigurableFileCollection` instances for improved flexibility of use. -Gradle now warns upon usage of these deprecated methods. They will be removed in a future version of Gradle. +Gradle now warns upon usage of these deprecated methods. +They will be removed in a future version of Gradle. ==== Replacement methods in `org.gradle.api.tasks.testing.TestReport` @@ -348,7 +355,8 @@ Alternatively, you can adjust or remove classpath attributes in the `eclipse.cla ==== Signing plugin defaults to `gpg` instead of `gpg2` when using the GPG command -The signature plugin's default executable link:signing_plugin.html#sec:using_gpg_agent[when using the GPG command] changed from `gpg2` to `gpg`. The change was motivated as GPG 2.x became stable, and distributions started to migrate by not linking the `gpg2` executable. +The signature plugin's default executable link:signing_plugin.html#sec:using_gpg_agent[when using the GPG command] changed from `gpg2` to `gpg`. +The change was motivated as GPG 2.x became stable, and distributions started to migrate by not linking the `gpg2` executable. In order to set the old default, the executable can be manually defined in `gradle.properties`: @@ -427,11 +435,15 @@ Due to that, if you use `zincVersion` setting it's advised to remove it and only ==== Removes implicit `--add-opens` for test workers -Prior to Gradle 7.5, JDK modules `java.base/java.util` and `java.base/java.lang` were automatically opened in test workers on JDK9+ by passing `--add-opens` CLI arguments. This meant any tests were able to perform deep reflection on JDK internals without warning or failing. This caused tests to be unreliable by allowing code to pass when it would otherwise fail in a production environment. +Prior to Gradle 7.5, JDK modules `java.base/java.util` and `java.base/java.lang` were automatically opened in test workers on JDK9+ by passing `--add-opens` CLI arguments. +This meant any tests were able to perform deep reflection on JDK internals without warning or failing. +This caused tests to be unreliable by allowing code to pass when it would otherwise fail in a production environment. -These implicit arguments have been removed and are no longer added by default. If your code or any of your dependencies are performing deep reflection into JDK internals during test execution, you may see the following behavior changes: +These implicit arguments have been removed and are no longer added by default. +If your code or any of your dependencies are performing deep reflection into JDK internals during test execution, you may see the following behavior changes: -Before Java 16, new build warnings are shown. These new warnings are printed to stderr and will not fail the build: +Before Java 16, new build warnings are shown. +These new warnings are printed to stderr and will not fail the build: ``` WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.ReflectUtils$2 (file:/.../testng-5.12.1.jar) to @@ -460,7 +472,8 @@ org.gradle.api.GradleException: Could not inject synthetic classes. Caused by: java.lang.RuntimeException: java.lang.IllegalAccessException: module java.base does not open java.lang to unnamed module @1e92bd61 ``` -In most cases, these errors can be resolved by updating the code or dependency performing the illegal access. If the code-under-test or the newest version of the dependency in question performs illegal access by design, the old behavior can be restored by opening the `java.base/java.lang` and `java.base/java.util` modules manually with `--add-opens`: +In most cases, these errors can be resolved by updating the code or dependency performing the illegal access. +If the code-under-test or the newest version of the dependency in question performs illegal access by design, the old behavior can be restored by opening the `java.base/java.lang` and `java.base/java.util` modules manually with `--add-opens`: ``` tasks.withType(Test).configureEach { @@ -469,23 +482,29 @@ tasks.withType(Test).configureEach { } ``` -If you are developing Gradle plugins, `ProjectBuilder` relies on reflection in the `java.base/java.lang` module. Gradle will automatically add the appropriate `--add-opens` flag to tests when the `java-gradle-plugin` plugin is applied. +If you are developing Gradle plugins, `ProjectBuilder` relies on reflection in the `java.base/java.lang` module. +Gradle will automatically add the appropriate `--add-opens` flag to tests when the `java-gradle-plugin` plugin is applied. -If you are using TestNG, versions prior to `5.14.6` perform illegal reflection. Updating to at least `5.14.6` should fix the incompatibility. +If you are using TestNG, versions prior to `5.14.6` perform illegal reflection. +Updating to at least `5.14.6` should fix the incompatibility. [[checkstyle_worker_api]] ==== Checkstyle tasks use toolchains and execute in parallel by default The <> now uses the Gradle worker API to run Checkstyle as an external worker process, so that multiple Checkstyle tasks may now run in parallel within a project. -Since Checkstyle runs as an external process you can control the memory via the `minHeapSize` and `maxHeapSize` properties on the Checkstyle tasks. In case of out of memory errors, increasing the max memory via the `maxHeapSize` property should solve the issue. By default, the process will start with `maxHeapSize` of 512MB. We also recommend to update Checkstyle to version 9.3 or later. +Since Checkstyle runs as an external process you can control the memory via the `minHeapSize` and `maxHeapSize` properties on the Checkstyle tasks. +In case of out of memory errors, increasing the max memory via the `maxHeapSize` property should solve the issue. +By default, the process will start with `maxHeapSize` of 512MB. +We also recommend to update Checkstyle to version 9.3 or later. ==== Missing files specified with relative paths when running Checkstyle Gradle 7.5 consistently sets the current working directory for the Checkstyle task to `GRADLE_USER_HOME/workers`. This may cause problems with custom Checkstyle tasks or Checkstyle configuration files that assume a different directory for relative paths. -Previously, Gradle selected the current working directory based on the directory where you ran Gradle. If you ran Gradle in: +Previously, Gradle selected the current working directory based on the directory where you ran Gradle. +If you ran Gradle in: - the root directory of a project: Gradle uses the root directory as the current working directory. - a nested directory of a project: Gradle uses the root directory of the subproject as the current working directory. @@ -505,8 +524,8 @@ Using a file collection with paths which contain a path separator may lead to in [[dependencyinsight_singlepath]] ==== `dependencyInsight` `--singlepath` option is deprecated -For consistency, this was changed to `--single-path`. The API -method has remained the same, this only affects the CLI. +For consistency, this was changed to `--single-path`. +The API method has remained the same, this only affects the CLI. [[groovydoc_option_improvements]] ==== Groovydoc `includePrivate` property is deprecated @@ -538,7 +557,8 @@ Following the move from AdoptOpenJDK to Adoptium, under the Eclipse foundation, Instead, an Eclipse Temurin or IBM Semeru build is returned. Gradle 7.4+ will now emit a deprecation warning when the AdoptOpenJDK vendor is specified in the <> and it is used by auto provisioning. -If you must use AdoptOpenJDK, you should turn off auto-download. If an Eclipse Temurin or IBM Semeru build works for you, specify `JvmVendorSpec.ADOPTIUM` or `JvmVendorSpec.IBM` as the vendor or leave the vendor unspecified. +If you must use AdoptOpenJDK, you should turn off auto-download. +If an Eclipse Temurin or IBM Semeru build works for you, specify `JvmVendorSpec.ADOPTIUM` or `JvmVendorSpec.IBM` as the vendor or leave the vendor unspecified. [[empty_directories_file_tree]] ==== File trees and empty directory handling @@ -559,8 +579,8 @@ The same is true for `link:{javadocPath}/org/gradle/api/tasks/TaskInputs.html#di ==== Using LazyPublishArtifact without a FileResolver is deprecated When using a LazyPublishArtifact without a FileResolver, a different file resolution strategy is used, which duplicates -some logic in the FileResolver. To improve consistency, LazyPublishArtifact should be used with a FileResolver, and will -require it in the future. +some logic in the FileResolver. +To improve consistency, LazyPublishArtifact should be used with a FileResolver, and will require it in the future. This also affects other internal APIs that use LazyPublishArtifact, which now also have deprecation warnings where needed. @@ -577,20 +597,23 @@ This way, Gradle is able to apply optimizations like up-to-date checks instead o [[unique_attribute_sets]] ==== Unique attribute sets -The set of link:{javadocPath}/org/gradle/api/attribute/Attribute.html[Attribute]s associated with a _consumable_ configuration within a project, must be unique across all other configurations within that project which share the same set of link:{javadocPath}/org/gradle/api/capabilities/Capability.html[Capability]s. This will be checked at the end of configuring variant configurations, as they are locked against further mutation. +The set of link:{javadocPath}/org/gradle/api/attribute/Attribute.html[Attribute]s associated with a _consumable_ configuration within a project, must be unique across all other configurations within that project which share the same set of link:{javadocPath}/org/gradle/api/capabilities/Capability.html[Capability]s. +This will be checked at the end of configuring variant configurations, as they are locked against further mutation. If the set of attributes is shared across configurations, consider adding an additional attribute to one of the variants for the sole purpose of disambiguation. [[for_use_at_configuration_time_deprecation]] ==== `Provider#forUseAtConfigurationTime()` has been deprecated -link:{javadocPath}/org/gradle/api/provider/Provider.html#forUseAtConfigurationTime--[Provider#forUseAtConfigurationTime] is now deprecated and scheduled for removal in Gradle 9.0. Clients should simply remove the call. +link:{javadocPath}/org/gradle/api/provider/Provider.html#forUseAtConfigurationTime--[Provider#forUseAtConfigurationTime] is now deprecated and scheduled for removal in Gradle 9.0. +Clients should simply remove the call. The call was mandatory on providers of external values such as link:{javadocPath}/org/gradle/api/provider/ProviderFactory.html#systemProperty-java.lang.String-[system properties], link:{javadocPath}/org/gradle/api/provider/ProviderFactory.html#environmentVariable-java.lang.String-[environment variables], link:{javadocPath}/org/gradle/api/provider/ProviderFactory.html#gradleProperty-java.lang.String-[Gradle properties] and link:{javadocPath}/org/gradle/api/provider/ProviderFactory.html#fileContents-org.gradle.api.file.RegularFile-[file contents] meant to be used at configuration time together with the configuration cache feature. Starting with version 7.4 Gradle will implicitly treat an external value used at configuration time as a configuration cache input. -Clients are also free to use standard Java APIs such as `System#getenv` to read environment variables, `System#getProperty` to read system properties as well as Gradle APIs such as link:{javadocPath}/org/gradle/api/provider/ProviderFactory.html#systemProperty-java.lang.String-[`Project#property(String)`] and link:{javadocPath}/org/gradle/api/Project.html#findProperty-java.lang.String-[`Project#findProperty(String)`] to read Gradle properties at configuration time. The `Provider` based APIs are still the recommended way to connect external values to task inputs for maximum configuration cache reuse. +Clients are also free to use standard Java APIs such as `System#getenv` to read environment variables, `System#getProperty` to read system properties as well as Gradle APIs such as link:{javadocPath}/org/gradle/api/provider/ProviderFactory.html#systemProperty-java.lang.String-[`Project#property(String)`] and link:{javadocPath}/org/gradle/api/Project.html#findProperty-java.lang.String-[`Project#findProperty(String)`] to read Gradle properties at configuration time. +The `Provider` based APIs are still the recommended way to connect external values to task inputs for maximum configuration cache reuse. ==== `ConfigurableReport#setDestination(org.gradle.api.provider.Provider)` has been deprecated @@ -620,8 +643,8 @@ these usages to APIs that are supported by the configuration cache. [[build_finished_events]] ==== Build finished events -Build finished listeners are not supported by the Gradle configuration cache. And so, the following API are deprecated and will be -removed in Gradle 8.0: +Build finished listeners are not supported by the Gradle configuration cache. +And so, the following API are deprecated and will be removed in Gradle 8.0: - Method link:{javadocPath}/org/gradle/api/invocation/Gradle.html#buildFinished-org.gradle.api.Action-[Gradle.buildFinished()] - Method link:{javadocPath}/org/gradle/BuildListener.html#buildFinished-org.gradle.BuildResult-[BuildListener.buildFinished()] @@ -661,7 +684,8 @@ Check the <