org.openrewrite.gradle.marker.GradleSettings Maven / Gradle / Ivy
Show all versions of rewrite-gradle Show documentation
/*
* Copyright 2023 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 com.fasterxml.jackson.annotation.JsonCreator;
import lombok.AllArgsConstructor;
import lombok.Builder;
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.*;
import java.util.stream.Collectors;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static org.openrewrite.Tree.randomId;
@Value
@With
@AllArgsConstructor(onConstructor_ = { @JsonCreator})
@Builder
public class GradleSettings implements Marker, Serializable {
@Builder.Default
UUID id = randomId();
@Deprecated
@Nullable
@Builder.Default
List pluginRepositories = emptyList();
@Builder.Default
List plugins = emptyList();
@Builder.Default
Map featurePreviews = emptyMap();
@Builder.Default
GradleBuildscript buildscript = GradleBuildscript.builder().build();
// 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 GradleBuildscript getBuildscript() {
// Temporary workaround for better compatibility with old LSTs that don't have a buildscript field yet.
//noinspection ConstantValue
if (buildscript == null) {
return new GradleBuildscript(randomId(), emptyList(), emptyMap());
}
return buildscript;
}
public @Nullable Boolean isFeatureEnabled(String name) {
return featurePreviews.get(name).getEnabled();
}
public Set 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 getPluginRepositories() {
if (buildscript != null) {
return buildscript.getMavenRepositories();
}
return pluginRepositories == null ? emptyList() : pluginRepositories;
}
}