From aa2dedfe2a8b992ef3a10cad09f59d5da958f52e Mon Sep 17 00:00:00 2001 From: Callum Rogers Date: Thu, 5 May 2022 14:25:52 +0100 Subject: [PATCH 01/14] Allow lazier configuration of jdks --- gradle-jdks/build.gradle | 2 + .../gradle/jdks/DelayedConfigurableMap.java | 73 ++++++++++ .../palantir/gradle/jdks/JdkDownloaders.java | 2 +- .../palantir/gradle/jdks/JdksExtension.java | 41 ++++-- .../com/palantir/gradle/jdks/JdksPlugin.java | 13 +- .../jdks/DelayedConfigurableMapTest.java | 133 ++++++++++++++++++ versions.lock | 9 +- versions.props | 1 + 8 files changed, 249 insertions(+), 25 deletions(-) create mode 100644 gradle-jdks/src/main/java/com/palantir/gradle/jdks/DelayedConfigurableMap.java create mode 100644 gradle-jdks/src/test/java/com/palantir/gradle/jdks/DelayedConfigurableMapTest.java diff --git a/gradle-jdks/build.gradle b/gradle-jdks/build.gradle index 5673b62a..c00afe5a 100644 --- a/gradle-jdks/build.gradle +++ b/gradle-jdks/build.gradle @@ -13,6 +13,8 @@ dependencies { testImplementation 'com.netflix.nebula:nebula-test' testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.assertj:assertj-core' + testImplementation 'org.mockito:mockito-core' + testImplementation 'org.mockito:mockito-junit-jupiter' } gradlePlugin { diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/DelayedConfigurableMap.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/DelayedConfigurableMap.java new file mode 100644 index 00000000..b5b33a48 --- /dev/null +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/DelayedConfigurableMap.java @@ -0,0 +1,73 @@ +/* + * (c) Copyright 2022 Palantir Technologies Inc. All rights reserved. + * + * 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 com.palantir.gradle.jdks; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Supplier; +import org.gradle.api.Action; +import org.gradle.api.provider.Provider; +import org.gradle.api.provider.ProviderFactory; + +final class DelayedConfigurableMap { + private final ProviderFactory providerFactory; + private final Supplier valueFactory; + private final List>>> configurations = new ArrayList<>(); + private Optional> configuredValue = Optional.empty(); + + DelayedConfigurableMap(ProviderFactory providerFactory, Supplier valueFactory) { + this.providerFactory = providerFactory; + this.valueFactory = valueFactory; + } + + public void configure(K key, Action value) { + configurations.add(providerFactory.provider(() -> Map.of(key, value))); + } + + public void configureLater(Provider>> values) { + configurations.add(values); + } + + public Map get() { + if (configuredValue.isPresent()) { + return configuredValue.get(); + } + + Map map = new HashMap<>(); + + configurations.forEach(mapActionProvider -> { + mapActionProvider.get().forEach((key, valueConfiguration) -> { + V value = map.computeIfAbsent(key, _ignored -> valueFactory.get()); + valueConfiguration.execute(value); + }); + }); + + Map unmodifiableMap = Collections.unmodifiableMap(map); + + configuredValue = Optional.of(unmodifiableMap); + + return unmodifiableMap; + } + + public Provider> getAsProvider() { + return providerFactory.provider(this::get); + } +} diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkDownloaders.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkDownloaders.java index 61e1bcca..fe070cb5 100644 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkDownloaders.java +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkDownloaders.java @@ -43,8 +43,8 @@ public JdkDownloader jdkDownloaderFor(JdkDistributionName jdkDistributionName) { jdkDistributionName, jdksExtension .getJdkDistributions() - .getting(jdkDistributionName) .get() + .get(jdkDistributionName) .getBaseUrl() .get())); } diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksExtension.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksExtension.java index 5a314da1..de626cc5 100644 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksExtension.java +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksExtension.java @@ -18,18 +18,26 @@ import groovy.lang.Closure; import groovy.lang.DelegatesTo; +import java.util.Map; import javax.inject.Inject; import org.gradle.api.Action; import org.gradle.api.file.DirectoryProperty; import org.gradle.api.model.ObjectFactory; import org.gradle.api.provider.MapProperty; +import org.gradle.api.provider.Provider; import org.gradle.api.provider.ProviderFactory; import org.gradle.jvm.toolchain.JavaLanguageVersion; public abstract class JdksExtension { - protected abstract MapProperty getJdkDistributions(); + private final DelayedConfigurableMap jdkDistributions; + private final DelayedConfigurableMap jdks; - protected abstract MapProperty getJdks(); + public JdksExtension() { + this.jdkDistributions = new DelayedConfigurableMap<>( + getProviderFactory(), () -> getObjectFactory().newInstance(JdkDistributionExtension.class)); + this.jdks = new DelayedConfigurableMap<>( + getProviderFactory(), () -> getObjectFactory().newInstance(JdkExtension.class)); + } public abstract MapProperty getCaCerts(); @@ -41,17 +49,12 @@ public abstract class JdksExtension { @Inject protected abstract ObjectFactory getObjectFactory(); + public final void jdks(Provider>> actions) { + jdks.configureLater(actions); + } + public final void jdk(JavaLanguageVersion javaLanguageVersion, Action action) { - JdkExtension jdkExtension = getJdks() - .getting(javaLanguageVersion) - .orElse(getProviderFactory().provider(() -> { - JdkExtension newJdkExtension = getObjectFactory().newInstance(JdkExtension.class); - getJdks().put(javaLanguageVersion, newJdkExtension); - return newJdkExtension; - })) - .get(); - - action.execute(jdkExtension); + jdks.configure(javaLanguageVersion, action); } @SuppressWarnings("RawTypes") @@ -59,9 +62,13 @@ public final void jdk(int javaLanguageVersion, @DelegatesTo(JdkExtension.class) jdk(JavaLanguageVersion.of(javaLanguageVersion), ConfigureUtil.toAction(closure)); } + public final void jdkDistributions(Provider>> actions) { + jdkDistributions.configureLater(actions); + } + public final void jdkDistribution( JdkDistributionName jdkDistributionName, Action action) { - action.execute(getJdkDistributions().getting(jdkDistributionName).get()); + jdkDistributions.configure(jdkDistributionName, action); } @SuppressWarnings("RawTypes") @@ -69,4 +76,12 @@ public final void jdkDistribution( String distributionName, @DelegatesTo(JdkDistributionExtension.class) Closure closure) { jdkDistribution(JdkDistributionName.fromStringThrowing(distributionName), ConfigureUtil.toAction(closure)); } + + public final Provider> getJdkDistributions() { + return jdkDistributions.getAsProvider(); + } + + public final Provider> getJdks() { + return jdks.getAsProvider(); + } } diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksPlugin.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksPlugin.java index 05994254..2cea8368 100644 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksPlugin.java +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksPlugin.java @@ -75,14 +75,11 @@ private JdksExtension extension(Project rootProject, JdkDistributions jdkDistrib () -> new File(System.getProperty("user.home"), ".gradle/caches/gradle-jdks")))); Arrays.stream(JdkDistributionName.values()).forEach(jdkDistributionName -> { - JdkDistributionExtension jdkDistributionExtension = - rootProject.getObjects().newInstance(JdkDistributionExtension.class); - - jdkDistributionExtension - .getBaseUrl() - .set(jdkDistributions.get(jdkDistributionName).defaultBaseUrl()); - - jdksExtension.getJdkDistributions().put(jdkDistributionName, jdkDistributionExtension); + jdksExtension.jdkDistribution(jdkDistributionName, jdkDistributionExtension -> { + jdkDistributionExtension + .getBaseUrl() + .set(jdkDistributions.get(jdkDistributionName).defaultBaseUrl()); + }); }); return jdksExtension; diff --git a/gradle-jdks/src/test/java/com/palantir/gradle/jdks/DelayedConfigurableMapTest.java b/gradle-jdks/src/test/java/com/palantir/gradle/jdks/DelayedConfigurableMapTest.java new file mode 100644 index 00000000..460228f6 --- /dev/null +++ b/gradle-jdks/src/test/java/com/palantir/gradle/jdks/DelayedConfigurableMapTest.java @@ -0,0 +1,133 @@ +/* + * (c) Copyright 2022 Palantir Technologies Inc. All rights reserved. + * + * 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 com.palantir.gradle.jdks; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.Map; +import java.util.concurrent.Callable; +import org.gradle.api.Action; +import org.gradle.api.provider.Provider; +import org.gradle.api.provider.ProviderFactory; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class DelayedConfigurableMapTest { + private final ProviderFactory providerFactory = mock(ProviderFactory.class); + + private final DelayedConfigurableMap delayedConfigurableMap = + new DelayedConfigurableMap<>(providerFactory, () -> new Extension(0)); + + @BeforeEach + void beforeEach() { + when(providerFactory.provider(any())).thenAnswer(invocation -> { + Callable callable = invocation.getArgument(0); + Provider provider = mock(Provider.class); + when(provider.get()).thenAnswer(_ignored -> callable.call()); + return provider; + }); + } + + @Test + void setting_one_value() { + delayedConfigurableMap.configure("abc", extension -> extension.number = 4); + assertThat(delayedConfigurableMap.get()).containsExactly(Map.entry("abc", new Extension(4))); + } + + @Test + void setting_one_value_multiple_times() { + delayedConfigurableMap.configure("abc", extension -> extension.number = 4); + delayedConfigurableMap.configure("abc", extension -> extension.number = 5); + + assertThat(delayedConfigurableMap.get()).containsExactly(Map.entry("abc", new Extension(5))); + } + + @Test + void setting_multiple_values() { + delayedConfigurableMap.configure("abc", extension -> extension.number = 4); + delayedConfigurableMap.configure("xyz", extension -> extension.number = 5); + + assertThat(delayedConfigurableMap.get()) + .containsExactlyInAnyOrderEntriesOf(Map.of("abc", new Extension(4), "xyz", new Extension(5))); + } + + @Test + void setting_multiple_values_multiple_times() { + delayedConfigurableMap.configure("abc", extension -> extension.number = 1); + delayedConfigurableMap.configure("xyz", extension -> extension.number = 8); + + delayedConfigurableMap.configure("abc", extension -> extension.number = 2); + delayedConfigurableMap.configure("xyz", extension -> extension.number = 9); + + assertThat(delayedConfigurableMap.get()) + .containsExactlyInAnyOrderEntriesOf(Map.of("abc", new Extension(2), "xyz", new Extension(9))); + } + + @Test + void lazily_providing_multiple_values() { + Provider>> foo = + providerFactory.provider(() -> Map.of("not this!", extension -> extension.number = 12)); + + delayedConfigurableMap.configureLater(foo); + + when(foo.get()) + .thenReturn(Map.of( + "yes this", + extension -> extension.number = 4, + "really this", + extension -> extension.number = 5)); + + assertThat(delayedConfigurableMap.get()) + .containsExactlyInAnyOrderEntriesOf( + Map.of("yes this", new Extension(4), "really this", new Extension(5))); + } + + @Test + void lazily_providing_multiple_values_at_multiple_times() { + delayedConfigurableMap.configureLater(providerFactory.provider( + () -> Map.of("aaa", extension -> extension.number = 3, "bbb", extension -> extension.number = 4))); + + delayedConfigurableMap.configureLater(providerFactory.provider( + () -> Map.of("ccc", extension -> extension.number = 6, "bbb", extension -> extension.number = 5))); + + assertThat(delayedConfigurableMap.get()) + .containsExactlyInAnyOrderEntriesOf( + Map.of("aaa", new Extension(3), "bbb", new Extension(5), "ccc", new Extension(6))); + } + + private static final class Extension { + public int number; + + Extension(int number) { + this.number = number; + } + + @Override + @SuppressWarnings("checkstyle:EqualsHashCode") + public boolean equals(Object obj) { + return number == ((Extension) obj).number; + } + + @Override + public String toString() { + return Integer.toString(number); + } + } +} diff --git a/versions.lock b/versions.lock index 6f377451..285cd9eb 100644 --- a/versions.lock +++ b/versions.lock @@ -71,19 +71,22 @@ org.slf4j:slf4j-api:1.7.30 (2 constraints: 6c1b52af) [Test dependencies] cglib:cglib-nodep:3.3.0 (2 constraints: 7a1acf3c) com.netflix.nebula:nebula-test:10.1.0 (1 constraints: 34052a3b) -net.bytebuddy:byte-buddy:1.10.16 (1 constraints: 950dfa39) +net.bytebuddy:byte-buddy:1.12.9 (2 constraints: db1849db) +net.bytebuddy:byte-buddy-agent:1.12.9 (1 constraints: 470b41de) org.assertj:assertj-core:3.22.0 (2 constraints: 65174647) org.hamcrest:hamcrest:2.2 (1 constraints: d20cdc04) org.junit:junit-bom:5.8.2 (10 constraints: c7a1fdc6) org.junit.jupiter:junit-jupiter:5.8.2 (2 constraints: 260e7a59) -org.junit.jupiter:junit-jupiter-api:5.8.2 (4 constraints: 8b385c34) +org.junit.jupiter:junit-jupiter-api:5.8.2 (5 constraints: 544724d7) org.junit.jupiter:junit-jupiter-engine:5.8.2 (2 constraints: 2117d23c) org.junit.jupiter:junit-jupiter-params:5.8.2 (2 constraints: 2117d23c) org.junit.platform:junit-platform-commons:1.8.2 (3 constraints: ee29ed2b) org.junit.platform:junit-platform-engine:1.8.2 (3 constraints: 062cdf16) org.junit.platform:junit-platform-launcher:1.8.2 (2 constraints: 121b944a) org.junit.platform:junit-platform-testkit:1.8.2 (1 constraints: 12097995) -org.objenesis:objenesis:3.1 (2 constraints: bb193de0) +org.mockito:mockito-core:4.5.1 (2 constraints: d0137a65) +org.mockito:mockito-junit-jupiter:4.5.1 (1 constraints: 0c050f36) +org.objenesis:objenesis:3.2 (3 constraints: 6b2483ae) org.opentest4j:opentest4j:1.2.0 (3 constraints: c53224a1) org.spockframework:spock-core:2.0-M4-groovy-3.0 (2 constraints: e822d65a) org.spockframework:spock-junit4:2.0-M4-groovy-3.0 (1 constraints: 25115ddf) diff --git a/versions.props b/versions.props index 4b77da2f..6e5562db 100644 --- a/versions.props +++ b/versions.props @@ -4,6 +4,7 @@ com.fasterxml.jackson.core:* = 2.13.2 com.netflix.nebula:nebula-test = 10.1.0 org.junit.jupiter:* = 5.8.2 org.assertj:assertj-core = 3.22.0 +org.mockito:* = 4.5.1 # dependency-upgrader:OFF com.palantir.baseline:* = 4.119.0 From d2698286bc1f0af4917a381d992b4e779357bcb3 Mon Sep 17 00:00:00 2001 From: Callum Rogers Date: Thu, 5 May 2022 14:42:43 +0100 Subject: [PATCH 02/14] Ensure configuration can't continue after value has been got --- .../gradle/jdks/DelayedConfigurableMap.java | 12 ++++++++++++ .../gradle/jdks/DelayedConfigurableMapTest.java | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/DelayedConfigurableMap.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/DelayedConfigurableMap.java index b5b33a48..9958f90b 100644 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/DelayedConfigurableMap.java +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/DelayedConfigurableMap.java @@ -39,13 +39,25 @@ final class DelayedConfigurableMap { } public void configure(K key, Action value) { + checkNotFinialized(); + configurations.add(providerFactory.provider(() -> Map.of(key, value))); } public void configureLater(Provider>> values) { + checkNotFinialized(); + configurations.add(values); } + private void checkNotFinialized() { + if (configuredValue.isPresent()) { + throw new IllegalStateException(String.format( + "This %s has been finialized by calling get(). It cannot be configured any more.", + DelayedConfigurableMap.class.getSimpleName())); + } + } + public Map get() { if (configuredValue.isPresent()) { return configuredValue.get(); diff --git a/gradle-jdks/src/test/java/com/palantir/gradle/jdks/DelayedConfigurableMapTest.java b/gradle-jdks/src/test/java/com/palantir/gradle/jdks/DelayedConfigurableMapTest.java index 460228f6..2ab1493c 100644 --- a/gradle-jdks/src/test/java/com/palantir/gradle/jdks/DelayedConfigurableMapTest.java +++ b/gradle-jdks/src/test/java/com/palantir/gradle/jdks/DelayedConfigurableMapTest.java @@ -17,6 +17,7 @@ package com.palantir.gradle.jdks; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -112,6 +113,22 @@ void lazily_providing_multiple_values_at_multiple_times() { Map.of("aaa", new Extension(3), "bbb", new Extension(5), "ccc", new Extension(6))); } + @Test + void errors_out_if_you_try_to_configure_after_setting() { + assertThat(delayedConfigurableMap.get()).isEmpty(); + + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> { + delayedConfigurableMap.configure("hey", extension -> extension.number = 3); + }); + + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> { + delayedConfigurableMap.configureLater( + providerFactory.provider(() -> Map.of("hey", extension -> extension.number = 3))); + }); + + assertThat(delayedConfigurableMap.get()).isEmpty(); + } + private static final class Extension { public int number; From 454da125181a1753a72879dc78e2f5fa0167855b Mon Sep 17 00:00:00 2001 From: svc-changelog Date: Thu, 5 May 2022 13:43:43 +0000 Subject: [PATCH 03/14] Add generated changelog entries --- changelog/@unreleased/pr-19.v2.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/@unreleased/pr-19.v2.yml diff --git a/changelog/@unreleased/pr-19.v2.yml b/changelog/@unreleased/pr-19.v2.yml new file mode 100644 index 00000000..43dea333 --- /dev/null +++ b/changelog/@unreleased/pr-19.v2.yml @@ -0,0 +1,5 @@ +type: fix +fix: + description: Allow lazy configuration of JDKs + links: + - https://github.com/palantir/gradle-jdks/pull/19 From 0d182386659b33154673126e7177a341c0102010 Mon Sep 17 00:00:00 2001 From: Callum Rogers Date: Thu, 5 May 2022 14:44:55 +0100 Subject: [PATCH 04/14] ep --- .../palantir/gradle/jdks/DelayedConfigurableMapTest.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gradle-jdks/src/test/java/com/palantir/gradle/jdks/DelayedConfigurableMapTest.java b/gradle-jdks/src/test/java/com/palantir/gradle/jdks/DelayedConfigurableMapTest.java index 2ab1493c..a819d57b 100644 --- a/gradle-jdks/src/test/java/com/palantir/gradle/jdks/DelayedConfigurableMapTest.java +++ b/gradle-jdks/src/test/java/com/palantir/gradle/jdks/DelayedConfigurableMapTest.java @@ -137,11 +137,15 @@ private static final class Extension { } @Override - @SuppressWarnings("checkstyle:EqualsHashCode") public boolean equals(Object obj) { return number == ((Extension) obj).number; } + @Override + public int hashCode() { + return number; + } + @Override public String toString() { return Integer.toString(number); From 4ec69e3b8d7f1321c0522a6cff4013db1a27582b Mon Sep 17 00:00:00 2001 From: Callum Rogers Date: Fri, 6 May 2022 19:45:49 +0100 Subject: [PATCH 05/14] Even lazier calculation of jdk paths --- .../GradleJdksJavaInstallationMetadata.java | 9 +++++++++ .../palantir/gradle/jdks/JdkDownloader.java | 12 ++++++------ .../com/palantir/gradle/jdks/JdksPlugin.java | 18 +++++++----------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/GradleJdksJavaInstallationMetadata.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/GradleJdksJavaInstallationMetadata.java index 21fee864..7fe9fc90 100644 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/GradleJdksJavaInstallationMetadata.java +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/GradleJdksJavaInstallationMetadata.java @@ -16,11 +16,20 @@ package com.palantir.gradle.jdks; +import org.gradle.api.file.Directory; +import org.gradle.api.provider.Provider; import org.gradle.jvm.toolchain.JavaInstallationMetadata; import org.immutables.value.Value; @Value.Immutable abstract class GradleJdksJavaInstallationMetadata implements JavaInstallationMetadata { + protected abstract Provider installationPathProvider(); + + @Override + public Directory getInstallationPath() { + return installationPathProvider().get(); + } + public static final class Builder extends ImmutableGradleJdksJavaInstallationMetadata.Builder {} public static Builder builder() { diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkDownloader.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkDownloader.java index 5675a77e..922b3a97 100644 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkDownloader.java +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkDownloader.java @@ -44,12 +44,12 @@ final class JdkDownloader { }); }); - rootProject - .getRepositories() - .matching(repo -> !repo.getName().equals(jdkGroup)) - .configureEach(artifactRepository -> { - artifactRepository.content(content -> content.excludeGroup(jdkGroup)); - }); + // rootProject + // .getRepositories() + // .matching(repo -> !repo.getName().equals(jdkGroup)) + // .configureEach(artifactRepository -> { + // artifactRepository.content(content -> content.excludeGroup(jdkGroup)); + // }); } public Path downloadJdkPath(JdkPath jdKPath) { diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksPlugin.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksPlugin.java index 2cea8368..e5df2045 100644 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksPlugin.java +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksPlugin.java @@ -19,7 +19,6 @@ import com.palantir.baseline.extensions.BaselineJavaVersionsExtension; import com.palantir.baseline.plugins.BaselineJavaVersions; import java.io.File; -import java.nio.file.Path; import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -96,17 +95,14 @@ private GradleJdksJavaInstallationMetadata javaInstallationForLanguageVersion( JdkDistributionName jdkDistributionName = jdkExtension.getDistributionName().get(); - Path jdk = jdkManager.jdk(JdkSpec.builder() - .distributionName(jdkDistributionName) - .release(JdkRelease.builder().version(version).build()) - .caCerts(CaCerts.from(jdksExtension.getCaCerts().get())) - .build()); - return GradleJdksJavaInstallationMetadata.builder() - .installationPath(rootProject - .getLayout() - .dir(rootProject.provider(jdk::toFile)) - .get()) + .installationPathProvider(rootProject.getLayout().dir(rootProject.provider(() -> jdkManager + .jdk(JdkSpec.builder() + .distributionName(jdkDistributionName) + .release(JdkRelease.builder().version(version).build()) + .caCerts(CaCerts.from(jdksExtension.getCaCerts().get())) + .build()) + .toFile()))) .javaRuntimeVersion(version) .languageVersion(javaLanguageVersion) .jvmVersion(version) From ab931af30561c5d9b3758b4c19e8c9d7542729d6 Mon Sep 17 00:00:00 2001 From: Callum Rogers Date: Mon, 9 May 2022 16:36:31 +0100 Subject: [PATCH 06/14] Remove excludes entirely --- .../main/java/com/palantir/gradle/jdks/JdkDownloader.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkDownloader.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkDownloader.java index 922b3a97..988ef327 100644 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkDownloader.java +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkDownloader.java @@ -43,13 +43,6 @@ final class JdkDownloader { repositoryContentDescriptor.includeGroup(jdkGroup); }); }); - - // rootProject - // .getRepositories() - // .matching(repo -> !repo.getName().equals(jdkGroup)) - // .configureEach(artifactRepository -> { - // artifactRepository.content(content -> content.excludeGroup(jdkGroup)); - // }); } public Path downloadJdkPath(JdkPath jdKPath) { From 3568c148986f46ec2b4be3e6754737089a4de73a Mon Sep 17 00:00:00 2001 From: Callum Rogers Date: Tue, 10 May 2022 14:00:49 +0100 Subject: [PATCH 07/14] Try using lazy map thing from baseline --- build.gradle | 1 + .../palantir/gradle/jdks/JdkDownloaders.java | 4 +- .../palantir/gradle/jdks/JdksExtension.java | 47 ++++++++++--------- .../com/palantir/gradle/jdks/JdksPlugin.java | 19 ++------ versions.lock | 10 ++-- versions.props | 2 +- 6 files changed, 37 insertions(+), 46 deletions(-) diff --git a/build.gradle b/build.gradle index dab97c05..87c74ce2 100644 --- a/build.gradle +++ b/build.gradle @@ -27,6 +27,7 @@ allprojects { repositories { gradlePluginPortal() mavenCentral() { metadataSources { mavenPom(); ignoreGradleMetadataRedirection() } } + mavenLocal() } group 'com.palantir.gradle.jdks' diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkDownloaders.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkDownloaders.java index fe070cb5..ce14947e 100644 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkDownloaders.java +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkDownloaders.java @@ -42,9 +42,7 @@ public JdkDownloader jdkDownloaderFor(JdkDistributionName jdkDistributionName) { rootProject, jdkDistributionName, jdksExtension - .getJdkDistributions() - .get() - .get(jdkDistributionName) + .jdkDistributionFor(jdkDistributionName) .getBaseUrl() .get())); } diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksExtension.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksExtension.java index de626cc5..e97b20bd 100644 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksExtension.java +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksExtension.java @@ -16,45 +16,41 @@ package com.palantir.gradle.jdks; +import com.palantir.baseline.plugins.javaversions.LazilyConfiguredMapping; +import com.palantir.baseline.plugins.javaversions.LazilyConfiguredMapping.LazyValues; import groovy.lang.Closure; import groovy.lang.DelegatesTo; -import java.util.Map; +import java.util.Optional; import javax.inject.Inject; import org.gradle.api.Action; import org.gradle.api.file.DirectoryProperty; import org.gradle.api.model.ObjectFactory; import org.gradle.api.provider.MapProperty; -import org.gradle.api.provider.Provider; -import org.gradle.api.provider.ProviderFactory; import org.gradle.jvm.toolchain.JavaLanguageVersion; public abstract class JdksExtension { - private final DelayedConfigurableMap jdkDistributions; - private final DelayedConfigurableMap jdks; + private final LazilyConfiguredMapping jdkDistributions; + private final LazilyConfiguredMapping jdks; public JdksExtension() { - this.jdkDistributions = new DelayedConfigurableMap<>( - getProviderFactory(), () -> getObjectFactory().newInstance(JdkDistributionExtension.class)); - this.jdks = new DelayedConfigurableMap<>( - getProviderFactory(), () -> getObjectFactory().newInstance(JdkExtension.class)); + this.jdkDistributions = + new LazilyConfiguredMapping<>(() -> getObjectFactory().newInstance(JdkDistributionExtension.class)); + this.jdks = new LazilyConfiguredMapping<>(() -> getObjectFactory().newInstance(JdkExtension.class)); } public abstract MapProperty getCaCerts(); public abstract DirectoryProperty getJdkStorageLocation(); - @Inject - protected abstract ProviderFactory getProviderFactory(); - @Inject protected abstract ObjectFactory getObjectFactory(); - public final void jdks(Provider>> actions) { - jdks.configureLater(actions); + public final void jdks(LazyJdks lazyJdks) { + jdks.put(lazyJdks); } public final void jdk(JavaLanguageVersion javaLanguageVersion, Action action) { - jdks.configure(javaLanguageVersion, action); + jdks.put(javaLanguageVersion, action); } @SuppressWarnings("RawTypes") @@ -62,13 +58,13 @@ public final void jdk(int javaLanguageVersion, @DelegatesTo(JdkExtension.class) jdk(JavaLanguageVersion.of(javaLanguageVersion), ConfigureUtil.toAction(closure)); } - public final void jdkDistributions(Provider>> actions) { - jdkDistributions.configureLater(actions); + public final void jdkDistributions(LazyJdkDistributions lazyJdkDistributions) { + jdkDistributions.put(lazyJdkDistributions); } public final void jdkDistribution( JdkDistributionName jdkDistributionName, Action action) { - jdkDistributions.configure(jdkDistributionName, action); + jdkDistributions.put(jdkDistributionName, action); } @SuppressWarnings("RawTypes") @@ -77,11 +73,18 @@ public final void jdkDistribution( jdkDistribution(JdkDistributionName.fromStringThrowing(distributionName), ConfigureUtil.toAction(closure)); } - public final Provider> getJdkDistributions() { - return jdkDistributions.getAsProvider(); + public final JdkDistributionExtension jdkDistributionFor(JdkDistributionName jdkDistributionName) { + return jdkDistributions + .get(jdkDistributionName) + .orElseThrow(() -> new RuntimeException( + String.format("No configuration for JdkDistribution " + jdkDistributionName))); } - public final Provider> getJdks() { - return jdks.getAsProvider(); + public final Optional jdkFor(JavaLanguageVersion javaLanguageVersion) { + return jdks.get(javaLanguageVersion); } + + public interface LazyJdkDistributions extends LazyValues {} + + public interface LazyJdks extends LazyValues {} } diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksPlugin.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksPlugin.java index e5df2045..7dfc51f9 100644 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksPlugin.java +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksPlugin.java @@ -20,11 +20,8 @@ import com.palantir.baseline.plugins.BaselineJavaVersions; import java.io.File; import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; import org.gradle.api.Plugin; import org.gradle.api.Project; -import org.gradle.jvm.toolchain.JavaInstallationMetadata; import org.gradle.jvm.toolchain.JavaLanguageVersion; public final class JdksPlugin implements Plugin { @@ -49,18 +46,10 @@ public void apply(Project rootProject) { rootProject .getExtensions() .getByType(BaselineJavaVersionsExtension.class) - .getJdks() - .putAll(rootProject.provider(() -> { - Map ret = new HashMap<>(); - jdksExtension.getJdks().get().forEach((javaLanguageVersion, jdkExtension) -> { - ret.put( - javaLanguageVersion, - javaInstallationForLanguageVersion( - rootProject, jdksExtension, jdkExtension, jdkManager, javaLanguageVersion)); - }); - - return ret; - })); + .jdks(javaLanguageVersion -> jdksExtension + .jdkFor(javaLanguageVersion) + .map(jdkExtension -> javaInstallationForLanguageVersion( + rootProject, jdksExtension, jdkExtension, jdkManager, javaLanguageVersion))); } private JdksExtension extension(Project rootProject, JdkDistributions jdkDistributions) { diff --git a/versions.lock b/versions.lock index 285cd9eb..5741e5bb 100644 --- a/versions.lock +++ b/versions.lock @@ -7,9 +7,9 @@ com.diffplug.durian:durian-core:1.2.0 (5 constraints: df4b51b4) com.diffplug.durian:durian-io:1.2.0 (2 constraints: cc1e3a85) com.diffplug.durian:durian-swt.os:3.5.0 (1 constraints: bf0b0dea) com.diffplug.gradle:goomph:3.35.0 (1 constraints: f4111707) -com.diffplug.spotless:spotless-lib:2.25.1 (3 constraints: da30c3b3) -com.diffplug.spotless:spotless-lib-extra:2.25.1 (1 constraints: 4a132141) -com.diffplug.spotless:spotless-plugin-gradle:6.5.1 (1 constraints: c5111ef5) +com.diffplug.spotless:spotless-lib:2.25.2 (3 constraints: dc30fbb3) +com.diffplug.spotless:spotless-lib-extra:2.25.2 (1 constraints: 4b132241) +com.diffplug.spotless:spotless-plugin-gradle:6.5.2 (1 constraints: c6111ff5) com.fasterxml.jackson:jackson-bom:2.13.2 (1 constraints: ff13bf65) com.fasterxml.jackson.core:jackson-annotations:2.13.2 (2 constraints: f1138182) com.github.ben-manes.caffeine:caffeine:3.0.5 (1 constraints: c11104f5) @@ -22,8 +22,8 @@ com.google.j2objc:j2objc-annotations:1.3 (1 constraints: b809eda0) com.googlecode.concurrent-trees:concurrent-trees:2.6.1 (1 constraints: 761166da) com.googlecode.java-diff-utils:diffutils:1.3.0 (1 constraints: bd11fef4) com.googlecode.javaewah:JavaEWAH:1.1.12 (1 constraints: 750eee5e) -com.palantir.baseline:gradle-baseline-java:4.119.0 (1 constraints: 7105c340) -com.palantir.baseline:gradle-junit-reports:4.119.0 (1 constraints: 28124519) +com.palantir.baseline:gradle-baseline-java:999 (1 constraints: c104512c) +com.palantir.baseline:gradle-junit-reports:999 (1 constraints: 7811e8d1) com.palantir.javaformat:gradle-palantir-java-format:1.1.0 (1 constraints: bb11f8f4) com.palantir.javaformat:palantir-java-format-spi:1.1.0 (2 constraints: 2b273bdb) com.squareup.okhttp3:okhttp:4.3.1 (1 constraints: bf0b0dea) diff --git a/versions.props b/versions.props index 6e5562db..e0f47ca8 100644 --- a/versions.props +++ b/versions.props @@ -7,7 +7,7 @@ org.assertj:assertj-core = 3.22.0 org.mockito:* = 4.5.1 # dependency-upgrader:OFF -com.palantir.baseline:* = 4.119.0 +com.palantir.baseline:* = 999 # dependency-upgrader:ON # conflict resolution From cbcef5171f24b5f63880a4cb77344d3399969305 Mon Sep 17 00:00:00 2001 From: Callum Rogers Date: Tue, 10 May 2022 14:02:24 +0100 Subject: [PATCH 08/14] Removed DelayedCM --- .../gradle/jdks/DelayedConfigurableMap.java | 85 ---------- .../jdks/DelayedConfigurableMapTest.java | 154 ------------------ 2 files changed, 239 deletions(-) delete mode 100644 gradle-jdks/src/main/java/com/palantir/gradle/jdks/DelayedConfigurableMap.java delete mode 100644 gradle-jdks/src/test/java/com/palantir/gradle/jdks/DelayedConfigurableMapTest.java diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/DelayedConfigurableMap.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/DelayedConfigurableMap.java deleted file mode 100644 index 9958f90b..00000000 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/DelayedConfigurableMap.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * (c) Copyright 2022 Palantir Technologies Inc. All rights reserved. - * - * 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 com.palantir.gradle.jdks; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.function.Supplier; -import org.gradle.api.Action; -import org.gradle.api.provider.Provider; -import org.gradle.api.provider.ProviderFactory; - -final class DelayedConfigurableMap { - private final ProviderFactory providerFactory; - private final Supplier valueFactory; - private final List>>> configurations = new ArrayList<>(); - private Optional> configuredValue = Optional.empty(); - - DelayedConfigurableMap(ProviderFactory providerFactory, Supplier valueFactory) { - this.providerFactory = providerFactory; - this.valueFactory = valueFactory; - } - - public void configure(K key, Action value) { - checkNotFinialized(); - - configurations.add(providerFactory.provider(() -> Map.of(key, value))); - } - - public void configureLater(Provider>> values) { - checkNotFinialized(); - - configurations.add(values); - } - - private void checkNotFinialized() { - if (configuredValue.isPresent()) { - throw new IllegalStateException(String.format( - "This %s has been finialized by calling get(). It cannot be configured any more.", - DelayedConfigurableMap.class.getSimpleName())); - } - } - - public Map get() { - if (configuredValue.isPresent()) { - return configuredValue.get(); - } - - Map map = new HashMap<>(); - - configurations.forEach(mapActionProvider -> { - mapActionProvider.get().forEach((key, valueConfiguration) -> { - V value = map.computeIfAbsent(key, _ignored -> valueFactory.get()); - valueConfiguration.execute(value); - }); - }); - - Map unmodifiableMap = Collections.unmodifiableMap(map); - - configuredValue = Optional.of(unmodifiableMap); - - return unmodifiableMap; - } - - public Provider> getAsProvider() { - return providerFactory.provider(this::get); - } -} diff --git a/gradle-jdks/src/test/java/com/palantir/gradle/jdks/DelayedConfigurableMapTest.java b/gradle-jdks/src/test/java/com/palantir/gradle/jdks/DelayedConfigurableMapTest.java deleted file mode 100644 index a819d57b..00000000 --- a/gradle-jdks/src/test/java/com/palantir/gradle/jdks/DelayedConfigurableMapTest.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * (c) Copyright 2022 Palantir Technologies Inc. All rights reserved. - * - * 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 com.palantir.gradle.jdks; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.Map; -import java.util.concurrent.Callable; -import org.gradle.api.Action; -import org.gradle.api.provider.Provider; -import org.gradle.api.provider.ProviderFactory; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -class DelayedConfigurableMapTest { - private final ProviderFactory providerFactory = mock(ProviderFactory.class); - - private final DelayedConfigurableMap delayedConfigurableMap = - new DelayedConfigurableMap<>(providerFactory, () -> new Extension(0)); - - @BeforeEach - void beforeEach() { - when(providerFactory.provider(any())).thenAnswer(invocation -> { - Callable callable = invocation.getArgument(0); - Provider provider = mock(Provider.class); - when(provider.get()).thenAnswer(_ignored -> callable.call()); - return provider; - }); - } - - @Test - void setting_one_value() { - delayedConfigurableMap.configure("abc", extension -> extension.number = 4); - assertThat(delayedConfigurableMap.get()).containsExactly(Map.entry("abc", new Extension(4))); - } - - @Test - void setting_one_value_multiple_times() { - delayedConfigurableMap.configure("abc", extension -> extension.number = 4); - delayedConfigurableMap.configure("abc", extension -> extension.number = 5); - - assertThat(delayedConfigurableMap.get()).containsExactly(Map.entry("abc", new Extension(5))); - } - - @Test - void setting_multiple_values() { - delayedConfigurableMap.configure("abc", extension -> extension.number = 4); - delayedConfigurableMap.configure("xyz", extension -> extension.number = 5); - - assertThat(delayedConfigurableMap.get()) - .containsExactlyInAnyOrderEntriesOf(Map.of("abc", new Extension(4), "xyz", new Extension(5))); - } - - @Test - void setting_multiple_values_multiple_times() { - delayedConfigurableMap.configure("abc", extension -> extension.number = 1); - delayedConfigurableMap.configure("xyz", extension -> extension.number = 8); - - delayedConfigurableMap.configure("abc", extension -> extension.number = 2); - delayedConfigurableMap.configure("xyz", extension -> extension.number = 9); - - assertThat(delayedConfigurableMap.get()) - .containsExactlyInAnyOrderEntriesOf(Map.of("abc", new Extension(2), "xyz", new Extension(9))); - } - - @Test - void lazily_providing_multiple_values() { - Provider>> foo = - providerFactory.provider(() -> Map.of("not this!", extension -> extension.number = 12)); - - delayedConfigurableMap.configureLater(foo); - - when(foo.get()) - .thenReturn(Map.of( - "yes this", - extension -> extension.number = 4, - "really this", - extension -> extension.number = 5)); - - assertThat(delayedConfigurableMap.get()) - .containsExactlyInAnyOrderEntriesOf( - Map.of("yes this", new Extension(4), "really this", new Extension(5))); - } - - @Test - void lazily_providing_multiple_values_at_multiple_times() { - delayedConfigurableMap.configureLater(providerFactory.provider( - () -> Map.of("aaa", extension -> extension.number = 3, "bbb", extension -> extension.number = 4))); - - delayedConfigurableMap.configureLater(providerFactory.provider( - () -> Map.of("ccc", extension -> extension.number = 6, "bbb", extension -> extension.number = 5))); - - assertThat(delayedConfigurableMap.get()) - .containsExactlyInAnyOrderEntriesOf( - Map.of("aaa", new Extension(3), "bbb", new Extension(5), "ccc", new Extension(6))); - } - - @Test - void errors_out_if_you_try_to_configure_after_setting() { - assertThat(delayedConfigurableMap.get()).isEmpty(); - - assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> { - delayedConfigurableMap.configure("hey", extension -> extension.number = 3); - }); - - assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> { - delayedConfigurableMap.configureLater( - providerFactory.provider(() -> Map.of("hey", extension -> extension.number = 3))); - }); - - assertThat(delayedConfigurableMap.get()).isEmpty(); - } - - private static final class Extension { - public int number; - - Extension(int number) { - this.number = number; - } - - @Override - public boolean equals(Object obj) { - return number == ((Extension) obj).number; - } - - @Override - public int hashCode() { - return number; - } - - @Override - public String toString() { - return Integer.toString(number); - } - } -} From 15db8e9e4e166e69675abf9a6a13f5238ca0688a Mon Sep 17 00:00:00 2001 From: Callum Rogers Date: Tue, 10 May 2022 16:07:43 +0100 Subject: [PATCH 09/14] Don't expose non-api types --- .../com/palantir/gradle/jdks/JdksExtension.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksExtension.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksExtension.java index e97b20bd..f6ad010f 100644 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksExtension.java +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksExtension.java @@ -17,7 +17,6 @@ package com.palantir.gradle.jdks; import com.palantir.baseline.plugins.javaversions.LazilyConfiguredMapping; -import com.palantir.baseline.plugins.javaversions.LazilyConfiguredMapping.LazyValues; import groovy.lang.Closure; import groovy.lang.DelegatesTo; import java.util.Optional; @@ -46,7 +45,7 @@ public JdksExtension() { protected abstract ObjectFactory getObjectFactory(); public final void jdks(LazyJdks lazyJdks) { - jdks.put(lazyJdks); + jdks.put(lazyJdks::configureJdkFor); } public final void jdk(JavaLanguageVersion javaLanguageVersion, Action action) { @@ -59,7 +58,7 @@ public final void jdk(int javaLanguageVersion, @DelegatesTo(JdkExtension.class) } public final void jdkDistributions(LazyJdkDistributions lazyJdkDistributions) { - jdkDistributions.put(lazyJdkDistributions); + jdkDistributions.put(lazyJdkDistributions::configureJdkDistributionFor); } public final void jdkDistribution( @@ -84,7 +83,11 @@ public final Optional jdkFor(JavaLanguageVersion javaLanguageVersi return jdks.get(javaLanguageVersion); } - public interface LazyJdkDistributions extends LazyValues {} + public interface LazyJdkDistributions { + Optional> configureJdkDistributionFor(JdkDistributionName jdkDistributionName); + } - public interface LazyJdks extends LazyValues {} + public interface LazyJdks { + Optional> configureJdkFor(JavaLanguageVersion javaLanguageVersion); + } } From 0d01a9d93fec21b1610f172eb294d629e3f9d7d5 Mon Sep 17 00:00:00 2001 From: Callum Rogers Date: Wed, 11 May 2022 19:27:02 +0100 Subject: [PATCH 10/14] Per project jdk downloading --- .../palantir/gradle/jdks/JdkDownloader.java | 18 ++++------- .../palantir/gradle/jdks/JdkDownloaders.java | 27 ++++++++++------- .../com/palantir/gradle/jdks/JdkManager.java | 23 ++++++-------- .../palantir/gradle/jdks/JdksExtension.java | 16 +++++----- .../com/palantir/gradle/jdks/JdksPlugin.java | 30 ++++++++++--------- 5 files changed, 56 insertions(+), 58 deletions(-) diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkDownloader.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkDownloader.java index 988ef327..2dd5ce79 100644 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkDownloader.java +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkDownloader.java @@ -23,18 +23,14 @@ final class JdkDownloader { - private final Project rootProject; + private final Project project; private final String jdkGroup; - JdkDownloader(Project rootProject, JdkDistributionName jdkDistributionName, String jdkBaseUrl) { - this.rootProject = rootProject; + JdkDownloader(Project project, JdkDistributionName jdkDistributionName, String jdkBaseUrl) { + this.project = project; this.jdkGroup = jdkDistributionName.uiName() + "-jdk"; - if (rootProject != rootProject.getRootProject()) { - throw new IllegalArgumentException("Must pass in the root project"); - } - - rootProject.getRepositories().ivy(ivy -> { + project.getRepositories().ivy(ivy -> { ivy.setName(jdkGroup); ivy.setUrl(jdkBaseUrl); ivy.patternLayout(patternLayout -> patternLayout.artifact("[module].[ext]")); @@ -46,10 +42,8 @@ final class JdkDownloader { } public Path downloadJdkPath(JdkPath jdKPath) { - Configuration configuration = rootProject - .getConfigurations() - .detachedConfiguration(rootProject - .getDependencies() + Configuration configuration = project.getConfigurations() + .detachedConfiguration(project.getDependencies() .create(String.format("%s:%s:@%s", jdkGroup, jdKPath.filename(), jdKPath.extension()))); return configuration.resolve().iterator().next().toPath(); } diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkDownloaders.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkDownloaders.java index ce14947e..23ffcbd9 100644 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkDownloaders.java +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkDownloaders.java @@ -19,31 +19,36 @@ import java.util.HashMap; import java.util.Map; import org.gradle.api.Project; +import org.immutables.value.Value; final class JdkDownloaders { - private final Map jdkDownloaders = new HashMap<>(); + private final Map jdkDownloaders = new HashMap<>(); - private final Project rootProject; private final JdksExtension jdksExtension; - JdkDownloaders(Project rootProject, JdksExtension jdksExtension) { - if (rootProject != rootProject.getRootProject()) { - throw new IllegalArgumentException("Must pass in the root project"); - } - - this.rootProject = rootProject; + JdkDownloaders(JdksExtension jdksExtension) { this.jdksExtension = jdksExtension; } - public JdkDownloader jdkDownloaderFor(JdkDistributionName jdkDistributionName) { + public JdkDownloader jdkDownloaderFor(Project project, JdkDistributionName jdkDistributionName) { return jdkDownloaders.computeIfAbsent( - jdkDistributionName, + ImmutableJdkDownloadersCacheKey.builder() + .project(project) + .jdkDistributionName(jdkDistributionName) + .build(), _ignored -> new JdkDownloader( - rootProject, + project, jdkDistributionName, jdksExtension .jdkDistributionFor(jdkDistributionName) .getBaseUrl() .get())); } + + @Value.Immutable + interface JdkDownloadersCacheKey { + Project project(); + + JdkDistributionName jdkDistributionName(); + } } diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkManager.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkManager.java index ca663602..d2d0fb22 100644 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkManager.java +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkManager.java @@ -35,23 +35,17 @@ import org.gradle.process.ExecResult; public final class JdkManager { - private final Project project; private final Provider storageLocation; private final JdkDistributions jdkDistributions; private final JdkDownloaders jdkDownloaders; - JdkManager( - Project project, - Provider storageLocation, - JdkDistributions jdkDistributions, - JdkDownloaders jdkDownloaders) { - this.project = project; + JdkManager(Provider storageLocation, JdkDistributions jdkDistributions, JdkDownloaders jdkDownloaders) { this.storageLocation = storageLocation; this.jdkDistributions = jdkDistributions; this.jdkDownloaders = jdkDownloaders; } - public Path jdk(JdkSpec jdkSpec) { + public Path jdk(Project project, JdkSpec jdkSpec) { Path diskPath = storageLocation .get() .getAsFile() @@ -65,21 +59,22 @@ public Path jdk(JdkSpec jdkSpec) { } JdkPath jdkPath = jdkDistributions.get(jdkSpec.distributionName()).path(jdkSpec.release()); - Path jdkArchive = - jdkDownloaders.jdkDownloaderFor(jdkSpec.distributionName()).downloadJdkPath(jdkPath); + Path jdkArchive = jdkDownloaders + .jdkDownloaderFor(project, jdkSpec.distributionName()) + .downloadJdkPath(jdkPath); Path temporaryJdkPath = Paths.get( diskPath + ".in-progress-" + UUID.randomUUID().toString().substring(0, 8)); try { project.copy(copy -> { - copy.from(unpackTree(jdkPath.extension(), jdkArchive)); + copy.from(unpackTree(project, jdkPath.extension(), jdkArchive)); copy.into(temporaryJdkPath); }); Path javaHome = findJavaHome(temporaryJdkPath); jdkSpec.caCerts().caCerts().forEach((name, caCertFile) -> { - addCaCert(javaHome, name, caCertFile); + addCaCert(project, javaHome, name, caCertFile); }); try { @@ -99,7 +94,7 @@ public Path jdk(JdkSpec jdkSpec) { } } - private FileTree unpackTree(Extension extension, Path path) { + private FileTree unpackTree(Project project, Extension extension, Path path) { switch (extension) { case ZIP: return project.zipTree(path.toFile()); @@ -128,7 +123,7 @@ private Path findJavaHome(Path temporaryJdkPath) { } } - private void addCaCert(Path javaHome, String alias, String caCert) { + private void addCaCert(Project project, Path javaHome, String alias, String caCert) { ByteArrayOutputStream output = new ByteArrayOutputStream(); ExecResult keytoolResult = project.exec(exec -> { diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksExtension.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksExtension.java index f6ad010f..ccf400a0 100644 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksExtension.java +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksExtension.java @@ -22,14 +22,15 @@ import java.util.Optional; import javax.inject.Inject; import org.gradle.api.Action; +import org.gradle.api.Project; import org.gradle.api.file.DirectoryProperty; import org.gradle.api.model.ObjectFactory; import org.gradle.api.provider.MapProperty; import org.gradle.jvm.toolchain.JavaLanguageVersion; public abstract class JdksExtension { - private final LazilyConfiguredMapping jdkDistributions; - private final LazilyConfiguredMapping jdks; + private final LazilyConfiguredMapping jdkDistributions; + private final LazilyConfiguredMapping jdks; public JdksExtension() { this.jdkDistributions = @@ -58,7 +59,8 @@ public final void jdk(int javaLanguageVersion, @DelegatesTo(JdkExtension.class) } public final void jdkDistributions(LazyJdkDistributions lazyJdkDistributions) { - jdkDistributions.put(lazyJdkDistributions::configureJdkDistributionFor); + jdkDistributions.put((jdkDistributionName, _ignored) -> + lazyJdkDistributions.configureJdkDistributionFor(jdkDistributionName)); } public final void jdkDistribution( @@ -74,13 +76,13 @@ public final void jdkDistribution( public final JdkDistributionExtension jdkDistributionFor(JdkDistributionName jdkDistributionName) { return jdkDistributions - .get(jdkDistributionName) + .get(jdkDistributionName, null) .orElseThrow(() -> new RuntimeException( String.format("No configuration for JdkDistribution " + jdkDistributionName))); } - public final Optional jdkFor(JavaLanguageVersion javaLanguageVersion) { - return jdks.get(javaLanguageVersion); + public final Optional jdkFor(JavaLanguageVersion javaLanguageVersion, Project project) { + return jdks.get(javaLanguageVersion, project); } public interface LazyJdkDistributions { @@ -88,6 +90,6 @@ public interface LazyJdkDistributions { } public interface LazyJdks { - Optional> configureJdkFor(JavaLanguageVersion javaLanguageVersion); + Optional> configureJdkFor(JavaLanguageVersion javaLanguageVersion, Project project); } } diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksPlugin.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksPlugin.java index 7dfc51f9..95e3a3c6 100644 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksPlugin.java +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksPlugin.java @@ -36,20 +36,17 @@ public void apply(Project rootProject) { JdksExtension jdksExtension = extension(rootProject, jdkDistributions); JdkManager jdkManager = new JdkManager( - rootProject.getProject(), - jdksExtension.getJdkStorageLocation(), - jdkDistributions, - new JdkDownloaders(rootProject, jdksExtension)); + jdksExtension.getJdkStorageLocation(), jdkDistributions, new JdkDownloaders(jdksExtension)); rootProject.getPluginManager().apply(BaselineJavaVersions.class); rootProject .getExtensions() .getByType(BaselineJavaVersionsExtension.class) - .jdks(javaLanguageVersion -> jdksExtension - .jdkFor(javaLanguageVersion) + .jdks((javaLanguageVersion, project) -> jdksExtension + .jdkFor(javaLanguageVersion, project) .map(jdkExtension -> javaInstallationForLanguageVersion( - rootProject, jdksExtension, jdkExtension, jdkManager, javaLanguageVersion))); + project, jdksExtension, jdkExtension, jdkManager, javaLanguageVersion))); } private JdksExtension extension(Project rootProject, JdkDistributions jdkDistributions) { @@ -74,7 +71,7 @@ private JdksExtension extension(Project rootProject, JdkDistributions jdkDistrib } private GradleJdksJavaInstallationMetadata javaInstallationForLanguageVersion( - Project rootProject, + Project project, JdksExtension jdksExtension, JdkExtension jdkExtension, JdkManager jdkManager, @@ -85,12 +82,17 @@ private GradleJdksJavaInstallationMetadata javaInstallationForLanguageVersion( jdkExtension.getDistributionName().get(); return GradleJdksJavaInstallationMetadata.builder() - .installationPathProvider(rootProject.getLayout().dir(rootProject.provider(() -> jdkManager - .jdk(JdkSpec.builder() - .distributionName(jdkDistributionName) - .release(JdkRelease.builder().version(version).build()) - .caCerts(CaCerts.from(jdksExtension.getCaCerts().get())) - .build()) + .installationPathProvider(project.getLayout().dir(project.provider(() -> jdkManager + .jdk( + project, + JdkSpec.builder() + .distributionName(jdkDistributionName) + .release(JdkRelease.builder() + .version(version) + .build()) + .caCerts(CaCerts.from( + jdksExtension.getCaCerts().get())) + .build()) .toFile()))) .javaRuntimeVersion(version) .languageVersion(javaLanguageVersion) From da0c09991c0fd469bc00502683f34ba3dfcd2021 Mon Sep 17 00:00:00 2001 From: Callum Rogers Date: Thu, 12 May 2022 11:52:52 +0100 Subject: [PATCH 11/14] copy code from baseline until we get our gradle-utils --- .../palantir/gradle/jdks/JdksExtension.java | 1 - .../gradle/jdks/LazilyConfiguredMapping.java | 89 +++++++++++++++ .../jdks/LazilyConfiguredMappingTest.java | 107 ++++++++++++++++++ 3 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 gradle-jdks/src/main/java/com/palantir/gradle/jdks/LazilyConfiguredMapping.java create mode 100644 gradle-jdks/src/test/java/com/palantir/gradle/jdks/LazilyConfiguredMappingTest.java diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksExtension.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksExtension.java index ccf400a0..ce48f854 100644 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksExtension.java +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksExtension.java @@ -16,7 +16,6 @@ package com.palantir.gradle.jdks; -import com.palantir.baseline.plugins.javaversions.LazilyConfiguredMapping; import groovy.lang.Closure; import groovy.lang.DelegatesTo; import java.util.Optional; diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/LazilyConfiguredMapping.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/LazilyConfiguredMapping.java new file mode 100644 index 00000000..5cfeeb45 --- /dev/null +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/LazilyConfiguredMapping.java @@ -0,0 +1,89 @@ +/* + * (c) Copyright 2022 Palantir Technologies Inc. All rights reserved. + * + * 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 com.palantir.gradle.jdks; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Supplier; +import org.gradle.api.Action; + +final class LazilyConfiguredMapping { + private final Supplier valueFactory; + private final List> values = new ArrayList<>(); + private final Map> computedValues = new HashMap<>(); + private boolean finalized = false; + + LazilyConfiguredMapping(Supplier valueFactory) { + this.valueFactory = valueFactory; + } + + public void put(LazyValues lazyValues) { + ensureNotFinalized(); + + values.add(lazyValues); + } + + public void put(K key, Action value) { + ensureNotFinalized(); + + put((requestedKey, _ignored) -> { + if (requestedKey.equals(key)) { + return Optional.of(value); + } + + return Optional.empty(); + }); + } + + private void ensureNotFinalized() { + if (finalized) { + throw new IllegalStateException(String.format( + "This %s has already been finalized as get() hase been called. " + + "No further elements can be added to it", + LazilyConfiguredMapping.class.getSimpleName())); + } + } + + public Optional get(K key, A additionalData) { + finalized = true; + + return computedValues.computeIfAbsent(key, _ignored -> { + V value = valueFactory.get(); + AtomicBoolean created = new AtomicBoolean(false); + values.forEach(lazyValues -> { + lazyValues.compute(key, additionalData).ifPresent(action -> { + created.set(true); + action.execute(value); + }); + }); + + if (created.get()) { + return Optional.of(value); + } + + return Optional.empty(); + }); + } + + public interface LazyValues { + Optional> compute(K key, A additionalData); + } +} diff --git a/gradle-jdks/src/test/java/com/palantir/gradle/jdks/LazilyConfiguredMappingTest.java b/gradle-jdks/src/test/java/com/palantir/gradle/jdks/LazilyConfiguredMappingTest.java new file mode 100644 index 00000000..caa56332 --- /dev/null +++ b/gradle-jdks/src/test/java/com/palantir/gradle/jdks/LazilyConfiguredMappingTest.java @@ -0,0 +1,107 @@ +/* + * (c) Copyright 2022 Palantir Technologies Inc. All rights reserved. + * + * 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 com.palantir.gradle.jdks; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +import com.palantir.baseline.plugins.javaversions.LazilyConfiguredMapping; +import java.util.Optional; +import org.junit.jupiter.api.Test; + +class LazilyConfiguredMappingTest { + private final com.palantir.baseline.plugins.javaversions.LazilyConfiguredMapping + lazilyConfiguredMapping = new LazilyConfiguredMapping<>(() -> new Extension(0)); + + @Test + void empty_mapping_returns_optional_empty() { + assertThat(lazilyConfiguredMapping.get("abc", 'a')).isEmpty(); + } + + @Test + void can_put_a_value_and_get_it_out_again() { + lazilyConfiguredMapping.put("foo", extension -> extension.number = 4); + + assertThat(lazilyConfiguredMapping.get("foo", 'a')).hasValue(new Extension(4)); + } + + @Test + void can_put_a_lazy_value_in_and_get_it_out_again() { + lazilyConfiguredMapping.put((key, additionalData) -> { + assertThat(additionalData).isEqualTo('b'); + return Optional.of(extension -> extension.number = Integer.parseInt(key)); + }); + + assertThat(lazilyConfiguredMapping.get("3", 'b')).hasValue(new Extension(3)); + assertThat(lazilyConfiguredMapping.get("9", 'b')).hasValue(new Extension(9)); + } + + @Test + void lazy_values_are_able_to_not_return_values() { + lazilyConfiguredMapping.put((_key, _additionalData) -> Optional.empty()); + + assertThat(lazilyConfiguredMapping.get("abc", 'a')).isEmpty(); + } + + @Test + void interspersing_putting_values_takes_the_last_set_value() { + lazilyConfiguredMapping.put("1", extension -> extension.number = 80); + lazilyConfiguredMapping.put( + (key, _ignored) -> Optional.of(extension -> extension.number = Integer.parseInt(key))); + lazilyConfiguredMapping.put("4", extension -> extension.number = 99); + + assertThat(lazilyConfiguredMapping.get("1", 'c')).hasValue(new Extension(1)); + assertThat(lazilyConfiguredMapping.get("3", 'c')).hasValue(new Extension(3)); + assertThat(lazilyConfiguredMapping.get("4", 'c')).hasValue(new Extension(99)); + } + + @Test + void throws_if_putting_values_after_being_finalized() { + lazilyConfiguredMapping.get("abc", 'c'); + + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> { + lazilyConfiguredMapping.put("foo", extension -> {}); + }); + + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> { + lazilyConfiguredMapping.put((_key, _additionalData) -> Optional.of(extension -> {})); + }); + } + + private static final class Extension { + public int number; + + Extension(int number) { + this.number = number; + } + + @Override + public boolean equals(Object obj) { + return number == ((Extension) obj).number; + } + + @Override + public int hashCode() { + return number; + } + + @Override + public String toString() { + return Integer.toString(number); + } + } +} From 5907ea72f32519e3dff12fd90b9a4213b35108f2 Mon Sep 17 00:00:00 2001 From: Callum Rogers Date: Thu, 12 May 2022 12:42:35 +0100 Subject: [PATCH 12/14] Use published version of baseline --- build.gradle | 1 - versions.lock | 10 +++++----- versions.props | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 87c74ce2..dab97c05 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,6 @@ allprojects { repositories { gradlePluginPortal() mavenCentral() { metadataSources { mavenPom(); ignoreGradleMetadataRedirection() } } - mavenLocal() } group 'com.palantir.gradle.jdks' diff --git a/versions.lock b/versions.lock index 5741e5bb..41117e11 100644 --- a/versions.lock +++ b/versions.lock @@ -7,9 +7,9 @@ com.diffplug.durian:durian-core:1.2.0 (5 constraints: df4b51b4) com.diffplug.durian:durian-io:1.2.0 (2 constraints: cc1e3a85) com.diffplug.durian:durian-swt.os:3.5.0 (1 constraints: bf0b0dea) com.diffplug.gradle:goomph:3.35.0 (1 constraints: f4111707) -com.diffplug.spotless:spotless-lib:2.25.2 (3 constraints: dc30fbb3) -com.diffplug.spotless:spotless-lib-extra:2.25.2 (1 constraints: 4b132241) -com.diffplug.spotless:spotless-plugin-gradle:6.5.2 (1 constraints: c6111ff5) +com.diffplug.spotless:spotless-lib:2.25.3 (3 constraints: de3033b4) +com.diffplug.spotless:spotless-lib-extra:2.25.3 (1 constraints: 4c132341) +com.diffplug.spotless:spotless-plugin-gradle:6.6.0 (1 constraints: c51120f5) com.fasterxml.jackson:jackson-bom:2.13.2 (1 constraints: ff13bf65) com.fasterxml.jackson.core:jackson-annotations:2.13.2 (2 constraints: f1138182) com.github.ben-manes.caffeine:caffeine:3.0.5 (1 constraints: c11104f5) @@ -22,8 +22,8 @@ com.google.j2objc:j2objc-annotations:1.3 (1 constraints: b809eda0) com.googlecode.concurrent-trees:concurrent-trees:2.6.1 (1 constraints: 761166da) com.googlecode.java-diff-utils:diffutils:1.3.0 (1 constraints: bd11fef4) com.googlecode.javaewah:JavaEWAH:1.1.12 (1 constraints: 750eee5e) -com.palantir.baseline:gradle-baseline-java:999 (1 constraints: c104512c) -com.palantir.baseline:gradle-junit-reports:999 (1 constraints: 7811e8d1) +com.palantir.baseline:gradle-baseline-java:4.133.0 (1 constraints: 6d05b940) +com.palantir.baseline:gradle-junit-reports:4.133.0 (1 constraints: 24123b19) com.palantir.javaformat:gradle-palantir-java-format:1.1.0 (1 constraints: bb11f8f4) com.palantir.javaformat:palantir-java-format-spi:1.1.0 (2 constraints: 2b273bdb) com.squareup.okhttp3:okhttp:4.3.1 (1 constraints: bf0b0dea) diff --git a/versions.props b/versions.props index e0f47ca8..03433ddd 100644 --- a/versions.props +++ b/versions.props @@ -7,7 +7,7 @@ org.assertj:assertj-core = 3.22.0 org.mockito:* = 4.5.1 # dependency-upgrader:OFF -com.palantir.baseline:* = 999 +com.palantir.baseline:* = 4.133.0 # dependency-upgrader:ON # conflict resolution From aed6bc3ebac2c82c268f9ff3323ac572be427544 Mon Sep 17 00:00:00 2001 From: Callum Rogers Date: Thu, 12 May 2022 12:51:25 +0100 Subject: [PATCH 13/14] Actually update code --- build.gradle | 2 +- .../com/palantir/gradle/jdks/JdksPlugin.java | 4 +-- .../jdks/LazilyConfiguredMappingTest.java | 5 ++- versions.lock | 33 +++++++++---------- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/build.gradle b/build.gradle index dab97c05..2b57014d 100644 --- a/build.gradle +++ b/build.gradle @@ -25,8 +25,8 @@ version gitVersion() allprojects { repositories { - gradlePluginPortal() mavenCentral() { metadataSources { mavenPom(); ignoreGradleMetadataRedirection() } } + gradlePluginPortal() { metadataSources { mavenPom(); ignoreGradleMetadataRedirection() } } } group 'com.palantir.gradle.jdks' diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksPlugin.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksPlugin.java index 95e3a3c6..f232c72d 100644 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksPlugin.java +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdksPlugin.java @@ -16,8 +16,8 @@ package com.palantir.gradle.jdks; -import com.palantir.baseline.extensions.BaselineJavaVersionsExtension; -import com.palantir.baseline.plugins.BaselineJavaVersions; +import com.palantir.baseline.plugins.javaversions.BaselineJavaVersions; +import com.palantir.baseline.plugins.javaversions.BaselineJavaVersionsExtension; import java.io.File; import java.util.Arrays; import org.gradle.api.Plugin; diff --git a/gradle-jdks/src/test/java/com/palantir/gradle/jdks/LazilyConfiguredMappingTest.java b/gradle-jdks/src/test/java/com/palantir/gradle/jdks/LazilyConfiguredMappingTest.java index caa56332..30a00d27 100644 --- a/gradle-jdks/src/test/java/com/palantir/gradle/jdks/LazilyConfiguredMappingTest.java +++ b/gradle-jdks/src/test/java/com/palantir/gradle/jdks/LazilyConfiguredMappingTest.java @@ -19,13 +19,12 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import com.palantir.baseline.plugins.javaversions.LazilyConfiguredMapping; import java.util.Optional; import org.junit.jupiter.api.Test; class LazilyConfiguredMappingTest { - private final com.palantir.baseline.plugins.javaversions.LazilyConfiguredMapping - lazilyConfiguredMapping = new LazilyConfiguredMapping<>(() -> new Extension(0)); + private final LazilyConfiguredMapping lazilyConfiguredMapping = + new LazilyConfiguredMapping<>(() -> new Extension(0)); @Test void empty_mapping_returns_optional_empty() { diff --git a/versions.lock b/versions.lock index 41117e11..c52dc459 100644 --- a/versions.lock +++ b/versions.lock @@ -10,8 +10,7 @@ com.diffplug.gradle:goomph:3.35.0 (1 constraints: f4111707) com.diffplug.spotless:spotless-lib:2.25.3 (3 constraints: de3033b4) com.diffplug.spotless:spotless-lib-extra:2.25.3 (1 constraints: 4c132341) com.diffplug.spotless:spotless-plugin-gradle:6.6.0 (1 constraints: c51120f5) -com.fasterxml.jackson:jackson-bom:2.13.2 (1 constraints: ff13bf65) -com.fasterxml.jackson.core:jackson-annotations:2.13.2 (2 constraints: f1138182) +com.fasterxml.jackson.core:jackson-annotations:2.13.2 (1 constraints: 3a053a3b) com.github.ben-manes.caffeine:caffeine:3.0.5 (1 constraints: c11104f5) com.google.code.findbugs:jsr305:3.0.2 (2 constraints: 1d0fb186) com.google.errorprone:error_prone_annotations:2.11.0 (3 constraints: a31fc64f) @@ -53,7 +52,7 @@ org.eclipse.platform:org.eclipse.osgi:3.15.0 (2 constraints: c724e4f0) org.eclipse.platform:org.eclipse.osgi.compatibility.state:1.1.600 (1 constraints: 1f0c1a02) org.hamcrest:hamcrest-core:1.3 (1 constraints: cc05fe3f) org.immutables:value:2.8.8 (1 constraints: 14051536) -org.jetbrains:annotations:19.0.0 (2 constraints: 441cf8cc) +org.jetbrains:annotations:13.0 (1 constraints: df0e795c) org.jetbrains.kotlin:kotlin-stdlib:1.3.61 (2 constraints: 0617a55e) org.jetbrains.kotlin:kotlin-stdlib-common:1.3.61 (2 constraints: c5196a0d) org.osgi:org.osgi.dto:1.0.0 (1 constraints: b40ca816) @@ -65,28 +64,26 @@ org.osgi:org.osgi.util.function:1.2.0 (2 constraints: f2193329) org.osgi:org.osgi.util.promise:1.2.0 (1 constraints: b60cae16) org.osgi:org.osgi.util.tracker:1.5.4 (1 constraints: bd0cbb16) org.osgi:osgi.annotation:8.0.1 (3 constraints: 1e2894a6) -org.ow2.asm:asm:9.3 (3 constraints: 7332e84a) +org.ow2.asm:asm:9.3 (2 constraints: 9d25affb) org.slf4j:slf4j-api:1.7.30 (2 constraints: 6c1b52af) [Test dependencies] -cglib:cglib-nodep:3.3.0 (2 constraints: 7a1acf3c) +cglib:cglib-nodep:3.2.2 (1 constraints: 490ded24) com.netflix.nebula:nebula-test:10.1.0 (1 constraints: 34052a3b) -net.bytebuddy:byte-buddy:1.12.9 (2 constraints: db1849db) +net.bytebuddy:byte-buddy:1.12.9 (1 constraints: 470b41de) net.bytebuddy:byte-buddy-agent:1.12.9 (1 constraints: 470b41de) -org.assertj:assertj-core:3.22.0 (2 constraints: 65174647) +org.apiguardian:apiguardian-api:1.1.2 (5 constraints: 105480ac) +org.assertj:assertj-core:3.22.0 (1 constraints: 39053f3b) org.hamcrest:hamcrest:2.2 (1 constraints: d20cdc04) -org.junit:junit-bom:5.8.2 (10 constraints: c7a1fdc6) -org.junit.jupiter:junit-jupiter:5.8.2 (2 constraints: 260e7a59) -org.junit.jupiter:junit-jupiter-api:5.8.2 (5 constraints: 544724d7) -org.junit.jupiter:junit-jupiter-engine:5.8.2 (2 constraints: 2117d23c) -org.junit.jupiter:junit-jupiter-params:5.8.2 (2 constraints: 2117d23c) -org.junit.platform:junit-platform-commons:1.8.2 (3 constraints: ee29ed2b) -org.junit.platform:junit-platform-engine:1.8.2 (3 constraints: 062cdf16) -org.junit.platform:junit-platform-launcher:1.8.2 (2 constraints: 121b944a) -org.junit.platform:junit-platform-testkit:1.8.2 (1 constraints: 12097995) +org.junit.jupiter:junit-jupiter:5.8.2 (1 constraints: 11051e36) +org.junit.jupiter:junit-jupiter-api:5.8.2 (4 constraints: 3f3ecd02) +org.junit.jupiter:junit-jupiter-engine:5.8.2 (1 constraints: 0c0edf3b) +org.junit.jupiter:junit-jupiter-params:5.8.2 (1 constraints: 0c0edf3b) +org.junit.platform:junit-platform-commons:1.8.2 (2 constraints: dd200b4b) +org.junit.platform:junit-platform-engine:1.8.2 (2 constraints: de1da64c) org.mockito:mockito-core:4.5.1 (2 constraints: d0137a65) org.mockito:mockito-junit-jupiter:4.5.1 (1 constraints: 0c050f36) -org.objenesis:objenesis:3.2 (3 constraints: 6b2483ae) -org.opentest4j:opentest4j:1.2.0 (3 constraints: c53224a1) +org.objenesis:objenesis:3.2 (2 constraints: 9a17f457) +org.opentest4j:opentest4j:1.2.0 (2 constraints: cd205b49) org.spockframework:spock-core:2.0-M4-groovy-3.0 (2 constraints: e822d65a) org.spockframework:spock-junit4:2.0-M4-groovy-3.0 (1 constraints: 25115ddf) From c24504ba3e7f161051742dbce49740dbd4be514a Mon Sep 17 00:00:00 2001 From: Callum Rogers Date: Thu, 12 May 2022 12:58:56 +0100 Subject: [PATCH 14/14] ep --- .../com/palantir/gradle/jdks/LazilyConfiguredMappingTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle-jdks/src/test/java/com/palantir/gradle/jdks/LazilyConfiguredMappingTest.java b/gradle-jdks/src/test/java/com/palantir/gradle/jdks/LazilyConfiguredMappingTest.java index 30a00d27..fb655292 100644 --- a/gradle-jdks/src/test/java/com/palantir/gradle/jdks/LazilyConfiguredMappingTest.java +++ b/gradle-jdks/src/test/java/com/palantir/gradle/jdks/LazilyConfiguredMappingTest.java @@ -73,11 +73,11 @@ void throws_if_putting_values_after_being_finalized() { lazilyConfiguredMapping.get("abc", 'c'); assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> { - lazilyConfiguredMapping.put("foo", extension -> {}); + lazilyConfiguredMapping.put("foo", _extension -> {}); }); assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> { - lazilyConfiguredMapping.put((_key, _additionalData) -> Optional.of(extension -> {})); + lazilyConfiguredMapping.put((_key, _additionalData) -> Optional.of(_extension -> {})); }); }