Skip to content

Commit

Permalink
Fixes #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 24, 2024
1 parent ef83341 commit 67d23c2
Show file tree
Hide file tree
Showing 23 changed files with 452 additions and 329 deletions.
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;
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:display-dependency-updates
invoker.mavenOpts=-Dverbose=true -Dversions.outputFile=./output.txt -DoutputEncoding=UTF-8 -Dversions.outputLineWidth=120
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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>localhost</groupId>
<artifactId>it-display-dependency-updates-008-displayTerminalWidth</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>display-dependency-updates</name>
<description>Validate usage of displayTerminalWidth parameter</description>
<url>http://localhost/</url>
<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def output = new File(basedir, "output.txt").text
assert output.contains('localhost:dummy-api ............................................................................... 1.0 ->')

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 67d23c2

Please sign in to comment.