Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Versions refactor 2 #1204

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@

import groovy.xml.XmlSlurper

def project = new XmlSlurper().parse( new File( basedir, 'pom.xml' ) )
assert project.parent.version == '70'


def buildLog = new File( basedir, "build.log")

assert buildLog.text.contains( '[INFO] The parent project is the latest version')
Original file line number Diff line number Diff line change
Expand Up @@ -113,30 +113,6 @@ public abstract class AbstractVersionsDependencyUpdaterMojo extends AbstractVers
@Parameter(property = "scope")
private String scope = null;

/**
* Whether to process the dependencies section of the project.
*
* @since 1.0-alpha-3
*/
@Parameter(property = "processDependencies", defaultValue = "true")
private boolean processDependencies = true;

/**
* Whether to process the dependencyManagement section of the project.
*
* @since 1.0-alpha-3
*/
@Parameter(property = "processDependencyManagement", defaultValue = "true")
private boolean processDependencyManagement = true;

/**
* Whether to process the parent section of the project. If not set will default to false.
*
* @since 2.3
*/
@Parameter(property = "processParent", defaultValue = "false")
private boolean processParent = false;

/**
* Artifact filter to determine if artifact should be included
*
Expand Down Expand Up @@ -174,29 +150,23 @@ protected AbstractVersionsDependencyUpdaterMojo(
* @return returns <code>true</code> if the project/dependencies section of the pom should be processed.
* @since 1.0-alpha-3
*/
public boolean isProcessingDependencies() {
return processDependencies;
}
protected abstract boolean getProcessDependencies();

/**
* Should the project/dependencyManagement section of the pom be processed.
*
* @return returns <code>true</code> if the project/dependencyManagement section of the pom should be processed.
* @since 1.0-alpha-3
*/
public boolean isProcessingDependencyManagement() {
return processDependencyManagement;
}
protected abstract boolean getProcessDependencyManagement();

/**
* Should the project/parent section of the pom be processed.
*
* @return returns <code>true</code> if the project/parent section of the pom should be processed.
* @since 2.3
*/
public boolean isProcessingParent() {
return processParent;
}
public abstract boolean getProcessParent();

/**
* Should the artifacts produced in the current reactor be excluded from processing.
Expand All @@ -205,7 +175,7 @@ public boolean isProcessingParent() {
* should be excluded from processing.
* @since 1.0-alpha-3
*/
public boolean isExcludeReactor() {
public boolean getExcludeReactor() {
return excludeReactor;
}

Expand Down Expand Up @@ -503,7 +473,7 @@ protected boolean updateDependencyVersion(
MutableXMLStreamReader pom, Dependency dep, String newVersion, DependencyChangeRecord.ChangeKind changeKind)
throws XMLStreamException, MojoExecutionException {
boolean updated = false;
if (isProcessingParent()
if (getProcessParent()
&& getProject().getParent() != null
&& (DependencyComparator.INSTANCE.compare(
dep,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ public abstract class AbstractVersionsUpdaterMojo extends AbstractMojo {
@Parameter(property = "generateBackupPoms", defaultValue = "true")
protected boolean generateBackupPoms;

protected abstract boolean isAllowSnapshots();

/**
* Our versions helper.
*/
Expand Down Expand Up @@ -209,6 +207,8 @@ protected AbstractVersionsUpdaterMojo(
this.changeRecorders = changeRecorders;
}

protected abstract boolean getAllowSnapshots();

public VersionsHelper getHelper() throws MojoExecutionException {
if (helper == null) {
helper = new DefaultVersionsHelper.Builder()
Expand Down Expand Up @@ -290,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 : isAllowSnapshots();
boolean includeSnapshots = allowingSnapshots != null ? allowingSnapshots : getAllowSnapshots();
final ArtifactVersions artifactVersions =
getHelper().lookupArtifactVersions(artifact, versionRange, usePluginRepositories);
return artifactVersions.getNewestVersion(versionRange, null, includeSnapshots, false);
Expand Down Expand Up @@ -431,7 +431,7 @@ protected ArtifactVersion updatePropertyToNewestVersion(
ArtifactVersion winner = version.getNewestVersion(
currentVersion,
property,
isAllowSnapshots(),
getAllowSnapshots(),
this.reactorProjects,
this.getHelper(),
allowDowngrade,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,29 @@ 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;
}
/**
* Whether to process the dependencies section of the project.
*
* @since 1.0-alpha-3
*/
@Parameter(property = "processDependencies", defaultValue = "true")
private boolean processDependencies = true;

/**
* Whether to process the dependencyManagement section of the project.
*
* @since 1.0-alpha-3
*/
@Parameter(property = "processDependencyManagement", defaultValue = "true")
private boolean processDependencyManagement = true;

/**
* Whether to process the parent section of the project. If not set will default to false.
*
* @since 2.3
*/
@Parameter(property = "processParent", defaultValue = "false")
private boolean processParent = false;

/**
* The (injected) instance of {@link ProjectBuilder}
Expand All @@ -142,6 +160,27 @@ public CompareDependenciesMojo(
this.projectBuilder = projectBuilder;
}

@Override
protected boolean getProcessDependencies() {
return processDependencies;
}

@Override
protected boolean getProcessDependencyManagement() {
return processDependencyManagement;
}

@Override
public boolean getProcessParent() {
return processParent;
}

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

/**
* @param pom the pom to update.
* @throws org.apache.maven.plugin.MojoExecutionException Something wrong with the plugin itself
Expand Down Expand Up @@ -187,14 +226,14 @@ protected void update(MutableXMLStreamReader pom)

List<String> totalDiffs = new ArrayList<>();
List<String> propertyDiffs = new ArrayList<>();
if (getProject().getDependencyManagement() != null && isProcessingDependencyManagement()) {
if (getProject().getDependencyManagement() != null && getProcessDependencyManagement()) {
totalDiffs.addAll(compareVersions(
pom,
getProject().getDependencyManagement().getDependencies(),
remoteDepsMap,
DependencyChangeRecord.ChangeKind.DEPENDENCY_MANAGEMENT));
}
if (getProject().getDependencies() != null && isProcessingDependencies()) {
if (getProject().getDependencies() != null && getProcessDependencies()) {
totalDiffs.addAll(compareVersions(
pom, getProject().getDependencies(), remoteDepsMap, DependencyChangeRecord.ChangeKind.DEPENDENCY));
}
Expand All @@ -205,7 +244,7 @@ protected void update(MutableXMLStreamReader pom)
.build());
propertyDiffs.addAll(updatePropertyVersions(pom, versionProperties, remoteDepsMap));
}
if (getProject().getParent() != null && remoteMavenProject.getParent() != null && isProcessingParent()) {
if (getProject().getParent() != null && remoteMavenProject.getParent() != null && getProcessParent()) {
Dependency parent = DependencyBuilder.newBuilder()
.withGroupId(remoteMavenProject.getParentArtifact().getGroupId())
.withArtifactId(remoteMavenProject.getParentArtifact().getArtifactId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,6 @@ public class DisplayDependencyUpdatesMojo extends AbstractVersionsDisplayMojo {
@Parameter(property = "allowSnapshots", defaultValue = "false")
protected boolean allowSnapshots;

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

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

@Inject
Expand All @@ -334,6 +329,11 @@ public DisplayDependencyUpdatesMojo(
super(artifactHandlerManager, repositorySystem, wagonMap, changeRecorders);
}

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

// open for tests
protected static boolean dependenciesMatch(Dependency dependency, Dependency managedDependency) {
if (!managedDependency.getGroupId().equals(dependency.getGroupId())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,6 @@ public class DisplayExtensionUpdatesMojo extends AbstractVersionsDisplayMojo {
@Parameter(property = "allowSnapshots", defaultValue = "false")
protected boolean allowSnapshots;

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

@Inject
public DisplayExtensionUpdatesMojo(
ArtifactHandlerManager artifactHandlerManager,
Expand All @@ -167,6 +162,11 @@ public DisplayExtensionUpdatesMojo(
super(artifactHandlerManager, repositorySystem, wagonMap, changeRecorders);
}

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

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
logInit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@ public class DisplayParentUpdatesMojo extends AbstractVersionsDisplayMojo {
@Parameter(property = "allowSnapshots", defaultValue = "false")
protected boolean allowSnapshots;

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

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

@Inject
Expand All @@ -155,6 +150,11 @@ public DisplayParentUpdatesMojo(
super(artifactHandlerManager, repositorySystem, wagonMap, changeRecorders);
}

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

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
logInit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,6 @@ public class DisplayPluginUpdatesMojo extends AbstractVersionsDisplayMojo {
@Parameter(property = "allowSnapshots", defaultValue = "false")
protected boolean allowSnapshots;

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

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

@Inject
Expand All @@ -204,6 +199,11 @@ public DisplayPluginUpdatesMojo(
this.runtimeInformation = runtimeInformation;
}

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

/**
* Returns the pluginManagement section of the super-pom.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,6 @@ public class DisplayPropertyUpdatesMojo extends AbstractVersionsDisplayMojo {
@Parameter(property = "allowSnapshots", defaultValue = "false")
protected boolean allowSnapshots;

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

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

// -------------------------- OTHER METHODS --------------------------
Expand All @@ -165,6 +160,11 @@ public DisplayPropertyUpdatesMojo(
super(artifactHandlerManager, repositorySystem, wagonMap, changeRecorders);
}

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

public void execute() throws MojoExecutionException, MojoFailureException {
logInit();
List<String> current = new ArrayList<>();
Expand Down
Loading
Loading