Skip to content

Commit

Permalink
Add missing buildscript classpath configuration (#4459)
Browse files Browse the repository at this point in the history
* Add missing buildscript classpath configuration

* Rollback updates to recipes to ease release
  • Loading branch information
shanman190 authored Sep 4, 2024
1 parent ac74ea6 commit 3504541
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 9 deletions.
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
@@ -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;

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

0 comments on commit 3504541

Please sign in to comment.