Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing buildscript classpath configuration #4459

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion rewrite-gradle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ tasks.named<Copy>("processResources") {
//Javadoc compiler will complain about the use of the internal types.
tasks.withType<Javadoc> {
exclude(
"**/GradleProject**"
"**/GradleProject**",
"**/GradleSettings**"
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ private MavenMetadata downloadMetadata(String groupId, String artifactId, List<M

private List<MavenRepository> determineRepos(@Nullable String configuration) {
if (gradleSettings != null) {
return gradleSettings.getPluginRepositories();
return gradleSettings.getBuildscript().getMavenRepositories();
}
Objects.requireNonNull(gradleProject);
return "classpath".equals(configuration) ?
gradleProject.getMavenPluginRepositories() :
gradleProject.getBuildscript().getMavenRepositories() :
gradleProject.getMavenRepositories();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2024 the original author or authors.
* <p>
* 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
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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;
shanman190 marked this conversation as resolved.
Show resolved Hide resolved

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<MavenRepository> mavenRepositories;
Map<String, GradleDependencyConfiguration> nameToConfiguration;

public @Nullable GradleDependencyConfiguration getConfiguration(String name) {
return nameToConfiguration.get(name);
}

public List<GradleDependencyConfiguration> getConfigurations() {
return new ArrayList<>(nameToConfiguration.values());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,40 @@ public class GradleProject implements Marker, Serializable {
List<MavenRepository> mavenRepositories;

@With
@Deprecated
@Nullable
List<MavenRepository> mavenPluginRepositories;

Map<String, GradleDependencyConfiguration> 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<GradlePluginDescriptor> plugins,
List<MavenRepository> mavenRepositories,
List<MavenRepository> mavenPluginRepositories,
Map<String, GradleDependencyConfiguration> 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<MavenRepository> getMavenPluginRepositories() {
if (buildscript != null) {
return buildscript.getMavenRepositories();
}
return mavenPluginRepositories == null ? Collections.emptyList() : mavenPluginRepositories;
}

Expand Down Expand Up @@ -151,7 +167,8 @@ public GradleProject withNameToConfiguration(Map<String, GradleDependencyConfigu
plugins,
mavenRepositories,
mavenPluginRepositories,
configurations
configurations,
buildscript
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,63 @@
*/
package org.openrewrite.gradle.marker;

import com.fasterxml.jackson.annotation.JsonCreator;
import lombok.AllArgsConstructor;
import lombok.Value;
import lombok.With;
import org.jspecify.annotations.Nullable;
import org.openrewrite.marker.Marker;
import org.openrewrite.maven.tree.MavenRepository;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;

@Value
@With
@AllArgsConstructor(onConstructor_ = { @JsonCreator})
public class GradleSettings implements Marker, Serializable {
UUID id;

@Deprecated
@Nullable
List<MavenRepository> pluginRepositories;

List<GradlePluginDescriptor> plugins;
Map<String, FeaturePreview> featurePreviews;
GradleBuildscript buildscript;

// Backwards compatibility to ease convoluted release process with rewrite-gradle-tooling-model
public GradleSettings(
UUID id,
List<MavenRepository> pluginRepositories,
List<GradlePluginDescriptor> plugins,
Map<String, FeaturePreview> 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<FeaturePreview> getActiveFeatures() {
return featurePreviews.values().stream()
.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<MavenRepository> getPluginRepositories() {
if (buildscript != null) {
return buildscript.getMavenRepositories();
}
return pluginRepositories == null ? Collections.emptyList() : pluginRepositories;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ private J.MethodInvocation maybeUpdateApplySyntax(J.MethodInvocation m) {

private List<MavenRepository> getPluginRepositories() {
if (gradleProject != null) {
return gradleProject.getMavenPluginRepositories();
return gradleProject.getBuildscript().getMavenRepositories();
}
return gradleSettings.getPluginRepositories();
return gradleSettings.getBuildscript().getMavenRepositories();
}
}
);
Expand Down
Loading