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 bbfae66
Show file tree
Hide file tree
Showing 17 changed files with 251 additions and 135 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

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.

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/)
Loading

0 comments on commit bbfae66

Please sign in to comment.