Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2020 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.maven;
import com.fasterxml.jackson.annotation.JsonCreator;
import lombok.EqualsAndHashCode;
import lombok.Value;
import org.jspecify.annotations.Nullable;
import org.openrewrite.*;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.internal.StringUtils;
import org.openrewrite.maven.internal.MavenPomDownloader;
import org.openrewrite.maven.tree.*;
import org.openrewrite.semver.ExactVersion;
import org.openrewrite.semver.LatestIntegration;
import org.openrewrite.semver.Semver;
import org.openrewrite.semver.VersionComparator;
import org.openrewrite.xml.tree.Xml;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static org.openrewrite.internal.StringUtils.matchesGlob;
@Value
@EqualsAndHashCode(callSuper = false)
public class RemoveRedundantDependencyVersions extends Recipe {
@Option(displayName = "Group",
description = "Group glob expression pattern used to match dependencies that should be managed." +
"Group is the first part of a dependency coordinate `com.google.guava:guava:VERSION`.",
example = "com.google.*",
required = false)
@Nullable
String groupPattern;
@Option(displayName = "Artifact",
description = "Artifact glob expression pattern used to match dependencies that should be managed." +
"Artifact is the second part of a dependency coordinate `com.google.guava:guava:VERSION`.",
example = "guava*",
required = false)
@Nullable
String artifactPattern;
@Option(displayName = "Only if versions match",
description = "Only remove the explicit version if it exactly matches the managed dependency version. " +
"When `false` explicit versions will be removed if they are older than or equal to the managed dependency version. " +
"Default `true`.",
required = false)
@Nullable
@Deprecated
@SuppressWarnings("DeprecatedIsStillUsed")
Boolean onlyIfVersionsMatch;
@Option(displayName = "Only if managed version is ...",
description = "Only remove the explicit version if the managed version has the specified comparative relationship to the explicit version. " +
"For example, `gte` will only remove the explicit version if the managed version is the same or newer. " +
"Default `eq`.",
valid = {"any", "eq", "lt", "lte", "gt", "gte"},
required = false)
@Nullable
Comparator onlyIfManagedVersionIs;
@Option(displayName = "Except",
description = "Accepts a list of GAVs. Dependencies matching a GAV will be ignored by this recipe."
+ " GAV versions are ignored if provided.",
example = "com.jcraft:jsch",
required = false)
@Nullable
List except;
@Deprecated
public RemoveRedundantDependencyVersions(@Nullable String groupPattern, @Nullable String artifactPattern,
@Nullable Boolean onlyIfVersionsMatch, @Nullable List except) {
this(groupPattern, artifactPattern, onlyIfVersionsMatch, null, except);
}
public RemoveRedundantDependencyVersions(@Nullable String groupPattern, @Nullable String artifactPattern,
@Nullable Comparator onlyIfManagedVersionIs, @Nullable List except) {
this(groupPattern, artifactPattern, null, onlyIfManagedVersionIs, except);
}
@JsonCreator
@Deprecated
@SuppressWarnings("DeprecatedIsStillUsed")
public RemoveRedundantDependencyVersions(@Nullable String groupPattern, @Nullable String artifactPattern,
@Nullable Boolean onlyIfVersionsMatch, @Nullable Comparator onlyIfManagedVersionIs,
@Nullable List except) {
this.groupPattern = groupPattern;
this.artifactPattern = artifactPattern;
this.onlyIfVersionsMatch = onlyIfVersionsMatch;
this.onlyIfManagedVersionIs = onlyIfManagedVersionIs;
this.except = except;
}
public enum Comparator {
ANY,
EQ,
LT,
LTE,
GT,
GTE
}
@Override
public String getDisplayName() {
return "Remove redundant explicit dependency and plugin versions";
}
@Override
public String getDescription() {
return "Remove explicitly-specified dependency/plugin versions when a parent POM's `dependencyManagement`/`pluginManagement` " +
"specifies the version.";
}
@Override
public Validated