From 350454123fc8818208aac5afb665c50e9a95a991 Mon Sep 17 00:00:00 2001 From: Shannon Pamperl Date: Wed, 4 Sep 2024 16:31:21 -0500 Subject: [PATCH] Add missing buildscript classpath configuration (#4459) * Add missing buildscript classpath configuration * Rollback updates to recipes to ease release --- rewrite-gradle/build.gradle.kts | 3 +- .../gradle/marker/GradleBuildscript.java | 43 +++++++++++++++++++ .../gradle/marker/GradleProject.java | 21 ++++++++- .../gradle/marker/GradleSettings.java | 40 ++++++++++++++--- 4 files changed, 98 insertions(+), 9 deletions(-) create mode 100644 rewrite-gradle/src/main/java/org/openrewrite/gradle/marker/GradleBuildscript.java diff --git a/rewrite-gradle/build.gradle.kts b/rewrite-gradle/build.gradle.kts index 109bf35375c..6a13b318e64 100644 --- a/rewrite-gradle/build.gradle.kts +++ b/rewrite-gradle/build.gradle.kts @@ -89,6 +89,7 @@ tasks.named("processResources") { //Javadoc compiler will complain about the use of the internal types. tasks.withType { exclude( - "**/GradleProject**" + "**/GradleProject**", + "**/GradleSettings**" ) } diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/marker/GradleBuildscript.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/marker/GradleBuildscript.java new file mode 100644 index 00000000000..7c08a94dfba --- /dev/null +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/marker/GradleBuildscript.java @@ -0,0 +1,43 @@ +/* + * Copyright 2024 the original author or authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openrewrite.gradle.marker; + +import lombok.Value; +import lombok.With; +import org.jspecify.annotations.Nullable; +import org.openrewrite.maven.tree.MavenRepository; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +@Value +@With +public class GradleBuildscript implements Serializable { + UUID id; + List mavenRepositories; + Map nameToConfiguration; + + public @Nullable GradleDependencyConfiguration getConfiguration(String name) { + return nameToConfiguration.get(name); + } + + public List getConfigurations() { + return new ArrayList<>(nameToConfiguration.values()); + } +} diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/marker/GradleProject.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/marker/GradleProject.java index 3e77f0bdd4f..3aa601e2571 100644 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/marker/GradleProject.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/marker/GradleProject.java @@ -60,24 +60,40 @@ public class GradleProject implements Marker, Serializable { List mavenRepositories; @With + @Deprecated + @Nullable List mavenPluginRepositories; Map nameToConfiguration; + GradleBuildscript buildscript; + // Backwards compatibility to ease convoluted release process with rewrite-gradle-tooling-model public GradleProject( UUID id, + String group, String name, + String version, String path, List plugins, List mavenRepositories, List mavenPluginRepositories, Map nameToConfiguration ) { - this(id, "", name, "", path, plugins, mavenRepositories, mavenPluginRepositories, nameToConfiguration); + this(id, group, name, version, path, plugins, mavenRepositories, mavenPluginRepositories, nameToConfiguration, null); } + /** + * Get a list of Maven plugin repositories. + * + * @return list of Maven plugin repositories + * @deprecated Use {@link GradleBuildscript#getMavenRepositories()} instead. + */ + @Deprecated public List getMavenPluginRepositories() { + if (buildscript != null) { + return buildscript.getMavenRepositories(); + } return mavenPluginRepositories == null ? Collections.emptyList() : mavenPluginRepositories; } @@ -151,7 +167,8 @@ public GradleProject withNameToConfiguration(Map pluginRepositories; + List plugins; Map featurePreviews; + GradleBuildscript buildscript; + + // Backwards compatibility to ease convoluted release process with rewrite-gradle-tooling-model + public GradleSettings( + UUID id, + List pluginRepositories, + List plugins, + Map featurePreviews + ) { + this(id, pluginRepositories, plugins, featurePreviews, null); + } public @Nullable Boolean isFeatureEnabled(String name) { - // Unclear how enabled status can be determined in latest gradle APIs - return null; + return featurePreviews.get(name).getEnabled(); } public Set getActiveFeatures() { @@ -46,4 +60,18 @@ public Set getActiveFeatures() { .filter(FeaturePreview::isActive) .collect(Collectors.toSet()); } + + /** + * Get a list of Maven plugin repositories. + * + * @return list of Maven plugin repositories + * @deprecated Use {@link GradleBuildscript#getMavenRepositories()} instead. + */ + @Deprecated + public List getPluginRepositories() { + if (buildscript != null) { + return buildscript.getMavenRepositories(); + } + return pluginRepositories == null ? Collections.emptyList() : pluginRepositories; + } }