Skip to content

Commit

Permalink
Fixes mojohaus#1140: Added showVersionless (default true)
Browse files Browse the repository at this point in the history
showVersionless false filters out dependencies managed outside of the reactor
verbose true adds the source of these dependencies
  • Loading branch information
slawekjaranowski authored and andrzejj0 committed Nov 23, 2024
1 parent 814c9b1 commit 2972ae9
Show file tree
Hide file tree
Showing 25 changed files with 407 additions and 134 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>org.codehaus.mojo.versions</groupId>
<artifactId>versions</artifactId>
<version>2.18.0</version>
<version>2.18.1-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Versions</name>
Expand Down Expand Up @@ -104,7 +104,7 @@
<scm>
<connection>scm:git:https://github.com/mojohaus/versions.git</connection>
<developerConnection>scm:git:ssh://[email protected]/mojohaus/versions.git</developerConnection>
<tag>2.18.0</tag>
<tag>HEAD</tag>
<url>https://github.com/mojohaus/versions/tree/master</url>
</scm>

Expand Down Expand Up @@ -147,7 +147,7 @@
<!-- execute ITS in parallel by default -->
<invoker.parallelThreads>0.75C</invoker.parallelThreads>
<!-- mono-module doesn't require site:stage for scm-publish -->
<project.build.outputTimestamp>2024-11-13T20:43:32Z</project.build.outputTimestamp>
<project.build.outputTimestamp>2024-11-13T20:44:06Z</project.build.outputTimestamp>
</properties>

<dependencyManagement>
Expand Down
2 changes: 1 addition & 1 deletion versions-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.mojo.versions</groupId>
<artifactId>versions</artifactId>
<version>2.18.0</version>
<version>2.18.1-SNAPSHOT</version>
</parent>

<artifactId>versions-api</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion versions-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.codehaus.mojo.versions</groupId>
<artifactId>versions</artifactId>
<version>2.18.0</version>
<version>2.18.1-SNAPSHOT</version>
</parent>

<artifactId>versions-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,42 @@
* limitations under the License.
*/

import java.util.Optional;
import java.util.HashMap;
import java.util.Map;

import org.apache.maven.model.Dependency;

import static java.util.Optional.empty;
import static java.util.Optional.of;
import static java.util.Optional.ofNullable;
import org.apache.maven.model.InputLocation;

/**
* Builder class for {@linkplain Dependency}
*/
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public class DependencyBuilder {
private Optional<String> groupId = empty();
private Optional<String> artifactId = empty();
private Optional<String> version = empty();
private Optional<String> type = empty();
private Optional<String> classifier = empty();
private Optional<String> scope = empty();
private Optional<String> optional = empty();
public enum Location {
GROUP_ID("groupId"),
ARTIFACT_ID("artifactId"),
VERSION("version");

private final String stringValue;

Location(String stringValue) {
this.stringValue = stringValue;
}

@Override
public String toString() {
return stringValue;
}
}

private static final Dependency TEMPLATE = new Dependency();
private String groupId = TEMPLATE.getGroupId();
private String artifactId = TEMPLATE.getArtifactId();
private String version = TEMPLATE.getVersion();
private String type = TEMPLATE.getType();
private String classifier = TEMPLATE.getClassifier();
private String scope = TEMPLATE.getScope();
private String optional = TEMPLATE.getOptional();
private final Map<String, InputLocation> inputLocationMap = new HashMap<>();

private DependencyBuilder() {}

Expand All @@ -44,7 +60,7 @@ private DependencyBuilder() {}
* @return builder instance
*/
public DependencyBuilder withGroupId(String groupId) {
this.groupId = ofNullable(groupId);
this.groupId = groupId;
return this;
}

Expand All @@ -54,7 +70,7 @@ public DependencyBuilder withGroupId(String groupId) {
* @return builder instance
*/
public DependencyBuilder withArtifactId(String artifactId) {
this.artifactId = ofNullable(artifactId);
this.artifactId = artifactId;
return this;
}

Expand All @@ -64,7 +80,7 @@ public DependencyBuilder withArtifactId(String artifactId) {
* @return builder instance
*/
public DependencyBuilder withVersion(String version) {
this.version = ofNullable(version);
this.version = version;
return this;
}

Expand All @@ -74,7 +90,7 @@ public DependencyBuilder withVersion(String version) {
* @return builder instance
*/
public DependencyBuilder withType(String type) {
this.type = ofNullable(type);
this.type = type;
return this;
}

Expand All @@ -84,7 +100,7 @@ public DependencyBuilder withType(String type) {
* @return builder instance
*/
public DependencyBuilder withClassifier(String classifier) {
this.classifier = ofNullable(classifier);
this.classifier = classifier;
return this;
}

Expand All @@ -94,7 +110,7 @@ public DependencyBuilder withClassifier(String classifier) {
* @return builder instance
*/
public DependencyBuilder withScope(String scope) {
this.scope = ofNullable(scope);
this.scope = scope;
return this;
}

Expand All @@ -104,7 +120,7 @@ public DependencyBuilder withScope(String scope) {
* @return builder instance
*/
public DependencyBuilder withOptional(String optional) {
this.optional = ofNullable(optional);
this.optional = optional;
return this;
}

Expand All @@ -114,7 +130,12 @@ public DependencyBuilder withOptional(String optional) {
* @return builder instance
*/
public DependencyBuilder withOptional(boolean optional) {
this.optional = of(String.valueOf(optional));
this.optional = String.valueOf(optional);
return this;
}

public DependencyBuilder withLocation(String element, InputLocation location) {
this.inputLocationMap.put(element, location);
return this;
}

Expand All @@ -132,14 +153,14 @@ public static DependencyBuilder newBuilder() {
*/
public Dependency build() {
Dependency inst = new Dependency();
groupId.ifPresent(inst::setGroupId);
artifactId.ifPresent(inst::setArtifactId);
version.ifPresent(inst::setVersion);
type.ifPresent(inst::setType);
classifier.ifPresent(inst::setClassifier);
scope.ifPresent(inst::setScope);
optional.ifPresent(inst::setOptional);

inst.setGroupId(groupId);
inst.setArtifactId(artifactId);
inst.setVersion(version);
inst.setType(type);
inst.setClassifier(classifier);
inst.setScope(scope);
inst.setOptional(optional);
inputLocationMap.forEach(inst::setLocation);
return inst;
}
}
2 changes: 1 addition & 1 deletion versions-enforcer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.codehaus.mojo.versions</groupId>
<artifactId>versions</artifactId>
<version>2.18.0</version>
<version>2.18.1-SNAPSHOT</version>
</parent>

<artifactId>versions-enforcer</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion versions-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.mojo.versions</groupId>
<artifactId>versions</artifactId>
<version>2.18.0</version>
<version>2.18.1-SNAPSHOT</version>
</parent>

<groupId>org.codehaus.mojo</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>mvc-child</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<parent>
<groupId>com.example</groupId>
<artifactId>mvc-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<dependencies>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc11</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
<version>8.0.2</version>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:dependency-updates-report -f child/pom.xml
invoker.mavenOpts = -DdependencyUpdatesReportFormats=xml -DprocessDependencyManagement=false -DprocessDependencyManagementTransitive=false -DonlyProjectDependencies=true -DonlyUpgradable=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>mvc-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<!-- as of now 3.3.5 is latest, 3.3.4 chosen deliberately for test case -->
<version>3.3.4</version>
</parent>

<build>
<plugins>
<plugin>
<!-- versions-maven-plugin requires at least maven 3.6.3 -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<id>enforce</id>
<goals>
<goal>enforce</goal>
</goals>
<phase>validate</phase>
</execution>
</executions>
<configuration>
<rules>
<requireMavenVersion><version>3.9.0</version></requireMavenVersion>
</rules>
</configuration>
</plugin>
<plugin>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def output = new File(basedir, "child/target/dependency-updates-report.xml").text
assert !output.contains("<artifactId>ojdbc11</artifactId>")

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def buildLog = new File( basedir, "build.log").text
assert buildLog =~ /\Qlocalhost:dummy-api\E\s*\.*\s*1\.1\s+->\s+3\.0/
assert !(buildLog =~ /\Qlocalhost:dummy-impl\E\s*\.*\s*1\.2\s+->\s+2\.2/)
assert buildLog =~ /\Qlocalhost:dummy-api-impl-bom-pom\E\s*\.*\s*1\.0\s+->\s+2\.0/

This file was deleted.

Loading

0 comments on commit 2972ae9

Please sign in to comment.