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 lombok.EqualsAndHashCode;
import lombok.Value;
import org.jspecify.annotations.Nullable;
import org.openrewrite.*;
import org.openrewrite.maven.table.MavenMetadataFailures;
import org.openrewrite.maven.trait.MavenDependency;
import org.openrewrite.maven.tree.*;
import org.openrewrite.maven.utilities.RetainVersions;
import org.openrewrite.semver.Semver;
import org.openrewrite.semver.VersionComparator;
import org.openrewrite.xml.AddToTagVisitor;
import org.openrewrite.xml.ChangeTagValueVisitor;
import org.openrewrite.xml.XPathMatcher;
import org.openrewrite.xml.tree.Xml;
import java.nio.file.Path;
import java.util.*;
import static java.util.Collections.emptyList;
import static java.util.Objects.requireNonNull;
import static org.openrewrite.internal.StringUtils.matchesGlob;
/**
* Upgrade the version of a dependency by specifying a group or group and artifact using Node Semver
* advanced range selectors, allowing
* more precise control over version updates to patch or minor releases.
*
* NOTES:
*
If a version is defined as a property, this recipe will only change the property value if the property exists within the same pom.
*
This recipe will alter the managed version of the dependency if it exists in the pom.
*
The default behavior for managed dependencies is to leave them unaltered unless the "overrideManagedVersion" is set to true.
*/
@Value
@EqualsAndHashCode(callSuper = false)
public class UpgradeDependencyVersion extends ScanningRecipe {
@EqualsAndHashCode.Exclude
transient MavenMetadataFailures metadataFailures = new MavenMetadataFailures(this);
// there are several implicitly defined version properties that we should never attempt to update
private static final Collection implicitlyDefinedVersionProperties = Arrays.asList(
"${version}", "${project.version}", "${pom.version}", "${project.parent.version}"
);
@Option(displayName = "Group",
description = "The first part of a dependency coordinate `com.google.guava:guava:VERSION`. This can be a glob expression.",
example = "com.fasterxml.jackson*")
String groupId;
@Option(displayName = "Artifact",
description = "The second part of a dependency coordinate `com.google.guava:guava:VERSION`. This can be a glob expression.",
example = "jackson-module*")
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 'newVersion' 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;
@Option(displayName = "Override managed version",
description = "This flag can be set to explicitly override a managed dependency's version. The default for this flag is `false`.",
required = false)
@Nullable
Boolean overrideManagedVersion;
@Option(displayName = "Retain versions",
description = "Accepts a list of GAVs. For each GAV, if it is a project direct dependency, and it is removed "
+ "from dependency management after the changes from this recipe, then it will be retained with an explicit version. "
+ "The version can be omitted from the GAV to use the old value from dependency management",
example = "com.jcraft:jsch",
required = false)
@Nullable
List retainVersions;
@SuppressWarnings("ConstantConditions")
@Override
public Validated