org.openrewrite.maven.UpgradePluginVersion Maven / Gradle / Ivy
Show all versions of rewrite-maven Show documentation
/*
* 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 lombok.EqualsAndHashCode;
import lombok.Value;
import org.jspecify.annotations.Nullable;
import org.openrewrite.*;
import org.openrewrite.marker.ci.GithubActionsBuildEnvironment;
import org.openrewrite.maven.search.FindPlugin;
import org.openrewrite.maven.table.MavenMetadataFailures;
import org.openrewrite.maven.tree.MavenMetadata;
import org.openrewrite.maven.tree.ResolvedPom;
import org.openrewrite.semver.Semver;
import org.openrewrite.semver.VersionComparator;
import org.openrewrite.xml.AddToTagVisitor;
import org.openrewrite.xml.ChangeTagValueVisitor;
import org.openrewrite.xml.tree.Xml;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Optional;
import static java.util.Objects.requireNonNull;
/**
* Upgrade the version of a plugin using Node Semver
* advanced range selectors, allowing
* more precise control over version updates to patch or minor releases.
*/
@Value
@EqualsAndHashCode(callSuper = false)
public class UpgradePluginVersion extends Recipe {
@EqualsAndHashCode.Exclude
MavenMetadataFailures metadataFailures = new MavenMetadataFailures(this);
@Option(displayName = "Group",
description = "The first part of a dependency coordinate 'org.openrewrite.maven:rewrite-maven-plugin:VERSION'. " +
"Supports globs.",
example = "org.openrewrite.maven")
String groupId;
@Option(displayName = "Artifact",
description = "The second part of a dependency coordinate 'org.openrewrite.maven:rewrite-maven-plugin:VERSION'. " +
"Supports globs.",
example = "rewrite-maven-plugin")
String artifactId;
@Option(displayName = "New version",
description = "An exact version number or node-style semver selector used to select the version number. " +
"You can also use `latest.release` for the latest available version and `latest.patch` if " +
"the current version is a valid semantic version. For more details, you can look at the documentation " +
"page of [version selectors](https://docs.openrewrite.org/reference/dependency-version-selectors)",
example = "29.X")
String newVersion;
@Option(displayName = "Version pattern",
description = "Allows version selection to be extended beyond the original Node Semver semantics. So for example," +
"Setting 'version' to \"25-29\" can be paired with a metadata pattern of \"-jre\" to select Guava 29.0-jre",
example = "-jre",
required = false)
@Nullable
String versionPattern;
// needs implementation, left here as syntactic placeholder // todo
@Option(displayName = "Trust parent POM",
description = "Even if the parent suggests a version that is older than what we are trying to upgrade to, trust it anyway. " +
"Useful when you want to wait for the parent to catch up before upgrading. The parent is not trusted by default.",
required = false)
@Nullable
Boolean trustParent;
@Option(displayName = "Add version if missing",
description = "If the plugin is missing a version, add the latest release. Defaults to false.",
required = false)
@Nullable
Boolean addVersionIfMissing;
@SuppressWarnings("ConstantConditions")
@Override
public Validated