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; + } }