Skip to content

Commit

Permalink
Refactoring: coalescing use-*-* goals. (#1202)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejj0 authored Dec 26, 2024
1 parent b2ce2d8 commit 74624c5
Show file tree
Hide file tree
Showing 33 changed files with 839 additions and 814 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -228,15 +229,12 @@ protected boolean isHandledByProperty(Dependency dependency) {
* @since 1.0-alpha-3
*/
protected Artifact findArtifact(Dependency dependency) {
if (getProject().getDependencyArtifacts() == null) {
return null;
}
for (Artifact artifact : getProject().getDependencyArtifacts()) {
if (compare(artifact, dependency)) {
return artifact;
}
}
return null;
return Optional.ofNullable(getProject().getDependencyArtifacts())
// no mutation, so parallelStream is safe
.flatMap(artifacts -> artifacts.parallelStream()
.filter(artifact -> compare(artifact, dependency))
.findAny())
.orElse(null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,7 @@ public abstract class AbstractVersionsUpdaterMojo extends AbstractMojo {
@Parameter(property = "generateBackupPoms", defaultValue = "true")
protected boolean generateBackupPoms;

/**
* Whether to allow snapshots when searching for the latest version of an artifact.
*
* @since 1.0-alpha-1
*/
@Parameter(property = "allowSnapshots", defaultValue = "false")
protected boolean allowSnapshots;
protected abstract boolean isAllowSnapshots();

/**
* Our versions helper.
Expand Down Expand Up @@ -296,7 +290,7 @@ protected void validateInput() throws MojoExecutionException {}
protected ArtifactVersion findLatestVersion(
Artifact artifact, VersionRange versionRange, Boolean allowingSnapshots, boolean usePluginRepositories)
throws MojoExecutionException, VersionRetrievalException {
boolean includeSnapshots = allowingSnapshots != null ? allowingSnapshots : this.allowSnapshots;
boolean includeSnapshots = allowingSnapshots != null ? allowingSnapshots : isAllowSnapshots();
final ArtifactVersions artifactVersions =
getHelper().lookupArtifactVersions(artifact, versionRange, usePluginRepositories);
return artifactVersions.getNewestVersion(versionRange, null, includeSnapshots, false);
Expand Down Expand Up @@ -437,7 +431,7 @@ protected ArtifactVersion updatePropertyToNewestVersion(
ArtifactVersion winner = version.getNewestVersion(
currentVersion,
property,
this.allowSnapshots,
isAllowSnapshots(),
this.reactorProjects,
this.getHelper(),
allowDowngrade,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ public class CompareDependenciesMojo extends AbstractVersionsDependencyUpdaterMo
@Parameter(property = "reportOutputFile")
protected File reportOutputFile;

@Override
protected boolean isAllowSnapshots() {
// this parameter is used by base class, but shouldn't affect comparison; setting to true
return true;
}

/**
* The (injected) instance of {@link ProjectBuilder}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,19 @@ public class DisplayDependencyUpdatesMojo extends AbstractVersionsDisplayMojo {
@Parameter(property = "pluginManagementDependencyExcludes")
private List<String> pluginManagementDependencyExcludes;

/**
* Whether to allow snapshots when searching for the latest version of an artifact.
*
* @since 1.0-alpha-1
*/
@Parameter(property = "allowSnapshots", defaultValue = "false")
protected boolean allowSnapshots;

@Override
protected boolean isAllowSnapshots() {
return allowSnapshots;
}

// --------------------- GETTER / SETTER METHODS ---------------------

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ public class DisplayExtensionUpdatesMojo extends AbstractVersionsDisplayMojo {
@Parameter(property = "verbose", defaultValue = "false")
private boolean verbose;

/**
* Whether to allow snapshots when searching for the latest version of an artifact.
*
* @since 1.0-alpha-1
*/
@Parameter(property = "allowSnapshots", defaultValue = "false")
protected boolean allowSnapshots;

@Override
protected boolean isAllowSnapshots() {
return allowSnapshots;
}

@Inject
public DisplayExtensionUpdatesMojo(
ArtifactHandlerManager artifactHandlerManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,19 @@ public class DisplayParentUpdatesMojo extends AbstractVersionsDisplayMojo {
@Parameter(property = "allowIncrementalUpdates", defaultValue = "true")
protected boolean allowIncrementalUpdates = true;

/**
* Whether to allow snapshots when searching for the latest version of an artifact.
*
* @since 1.0-alpha-1
*/
@Parameter(property = "allowSnapshots", defaultValue = "false")
protected boolean allowSnapshots;

@Override
protected boolean isAllowSnapshots() {
return allowSnapshots;
}

// -------------------------- OTHER METHODS --------------------------

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,19 @@ public class DisplayPluginUpdatesMojo extends AbstractVersionsDisplayMojo {
@Parameter(property = "processUnboundPlugins", defaultValue = "false")
protected boolean processUnboundPlugins;

/**
* Whether to allow snapshots when searching for the latest version of an artifact.
*
* @since 1.0-alpha-1
*/
@Parameter(property = "allowSnapshots", defaultValue = "false")
protected boolean allowSnapshots;

@Override
protected boolean isAllowSnapshots() {
return allowSnapshots;
}

// --------------------- GETTER / SETTER METHODS ---------------------

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,19 @@ public class DisplayPropertyUpdatesMojo extends AbstractVersionsDisplayMojo {
@Parameter(property = "includeParent", defaultValue = "false")
protected boolean includeParent;

/**
* Whether to allow snapshots when searching for the latest version of an artifact.
*
* @since 1.0-alpha-1
*/
@Parameter(property = "allowSnapshots", defaultValue = "false")
protected boolean allowSnapshots;

@Override
protected boolean isAllowSnapshots() {
return allowSnapshots;
}

// -------------------------- STATIC METHODS --------------------------

// -------------------------- OTHER METHODS --------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public class ForceReleasesMojo extends AbstractVersionsDependencyUpdaterMojo {
@Parameter(property = "failIfNotReplaced", defaultValue = "false")
protected boolean failIfNotReplaced;

@Override
protected boolean isAllowSnapshots() {
return false;
}

// ------------------------------ METHODS --------------------------

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ public class LockSnapshotsMojo extends AbstractVersionsDependencyUpdaterMojo {

// ------------------------------ METHODS --------------------------

@Override
protected boolean isAllowSnapshots() {
// used by base method; must be true so that it's able to select snapshots
return true;
}

@Inject
public LockSnapshotsMojo(
ArtifactHandlerManager artifactHandlerManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ public class ResolveRangesMojo extends AbstractVersionsDependencyUpdaterMojo {
@Parameter(property = "allowIncrementalUpdates", defaultValue = "true")
private boolean allowIncrementalUpdates;

/**
* Whether to allow snapshots when searching for the latest version of an artifact.
*
* @since 1.0-alpha-1
*/
@Parameter(property = "allowSnapshots", defaultValue = "false")
protected boolean allowSnapshots;

@Override
protected boolean isAllowSnapshots() {
return allowSnapshots;
}

// ------------------------------ FIELDS ------------------------------

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,19 @@ public class SetMojo extends AbstractVersionsUpdaterMojo {
@Parameter(property = "updateBuildOutputTimestampPolicy", defaultValue = "onchange")
private String updateBuildOutputTimestampPolicy;

/**
* Whether to allow snapshots when searching for the latest version of an artifact.
*
* @since 1.0-alpha-1
*/
@Parameter(property = "allowSnapshots", defaultValue = "false")
protected boolean allowSnapshots;

@Override
protected boolean isAllowSnapshots() {
return allowSnapshots;
}

/**
* The changes to module coordinates. Guarded by this.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@ public class SetPropertyMojo extends AbstractVersionsUpdaterMojo {
@Parameter(property = "profileId")
private String profileId = null;

/**
* Whether to allow snapshots when searching for the latest version of an artifact.
*
* @since 1.0-alpha-1
*/
@Parameter(property = "allowSnapshots", defaultValue = "false")
protected boolean allowSnapshots;

@Override
protected boolean isAllowSnapshots() {
return allowSnapshots;
}

@Inject
public SetPropertyMojo(
ArtifactHandlerManager artifactHandlerManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ public class SetScmTagMojo extends AbstractVersionsUpdaterMojo {
@Parameter(property = "url")
private String url;

/**
* Whether to allow snapshots when searching for the latest version of an artifact.
*
* @since 1.0-alpha-1
*/
@Parameter(property = "allowSnapshots", defaultValue = "false")
protected boolean allowSnapshots;

@Override
protected boolean isAllowSnapshots() {
return allowSnapshots;
}

@Inject
public SetScmTagMojo(
ArtifactHandlerManager artifactHandlerManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public class UnlockSnapshotsMojo extends AbstractVersionsDependencyUpdaterMojo {

// ------------------------------ METHODS --------------------------

@Override
protected boolean isAllowSnapshots() {
// used by base class; must be true so that it can select snapshots
return true;
}

@Inject
public UnlockSnapshotsMojo(
ArtifactHandlerManager artifactHandlerManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.wagon.Wagon;
import org.codehaus.mojo.versions.api.PomHelper;
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
Expand Down Expand Up @@ -65,6 +66,19 @@ public class UpdateChildModulesMojo extends AbstractVersionsUpdaterMojo {
*/
private transient String sourceVersion = null;

/**
* Whether to allow snapshots when searching for the latest version of an artifact.
*
* @since 1.0-alpha-1
*/
@Parameter(property = "allowSnapshots", defaultValue = "false")
protected boolean allowSnapshots;

@Override
protected boolean isAllowSnapshots() {
return allowSnapshots;
}

@Inject
public UpdateChildModulesMojo(
ArtifactHandlerManager artifactHandlerManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,19 @@ public class UpdateParentMojo extends AbstractVersionsUpdaterMojo {
@Parameter(property = "allowIncrementalUpdates", defaultValue = "true")
protected boolean allowIncrementalUpdates = true;

/**
* Whether to allow snapshots when searching for the latest version of an artifact.
*
* @since 1.0-alpha-1
*/
@Parameter(property = "allowSnapshots", defaultValue = "false")
protected boolean allowSnapshots;

@Override
protected boolean isAllowSnapshots() {
return allowSnapshots;
}

// -------------------------- OTHER METHODS --------------------------

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ public abstract class UpdatePropertiesMojoBase extends AbstractVersionsDependenc
@Parameter(property = "includeParent", defaultValue = "true")
protected boolean includeParent = true;

/**
* Whether to allow snapshots when searching for the latest version of an artifact.
*
* @since 1.0-alpha-1
*/
@Parameter(property = "allowSnapshots", defaultValue = "false")
protected boolean allowSnapshots;

@Override
protected boolean isAllowSnapshots() {
return allowSnapshots;
}

public UpdatePropertiesMojoBase(
ArtifactHandlerManager artifactHandlerManager,
RepositorySystem repositorySystem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ public class UseDepVersionMojo extends AbstractVersionsDependencyUpdaterMojo {
@Parameter(property = "forceVersion", defaultValue = "false")
protected boolean forceVersion;

/**
* Whether to allow snapshots when searching for the latest version of an artifact.
*
* @since 1.0-alpha-1
*/
@Parameter(property = "allowSnapshots", defaultValue = "false")
protected boolean allowSnapshots;

@Override
protected boolean isAllowSnapshots() {
return allowSnapshots;
}

/**
* <p>Will augment normal processing by, if a dependency value is set using a property, trying to update
* the value of the property.</p>
Expand Down
Loading

0 comments on commit 74624c5

Please sign in to comment.