Skip to content
Open
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
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.shared.dependency.graph.internal;
package org.apache.maven.shared.dependency.graph;

/**
* Explicit subset of Aether's DependencyNode.getData().
Expand All @@ -26,37 +26,36 @@
public class ConflictData {
private String winnerVersion;

private String originalScope;

private String ignoredScope;

private Boolean originaOptionality;

/**
* Construct ConflictData. Containing information about conflicts during dependency resolution.
* Either this node lost the conflict and winnerVersion is set with the version of the winnig node,
* or this node won and winnerVersion is @code{null}.
* If this node won, ignoredScope can contain potential scopes that were ignored during conflict resolution.
*
* @param winnerVersion the version of the dependency that was selected
* @param ignoredScope the scope of the dependency that was ignored and not updated to
*/
public ConflictData(String winnerVersion, String ignoredScope) {
this.winnerVersion = winnerVersion;
this.ignoredScope = ignoredScope;
}

/**
* In case of a conflict, the version of the dependency that was selected.
*
* @return the version of the dependency node that was selected
*/
public String getWinnerVersion() {
return winnerVersion;
}

public String getOriginalScope() {
return originalScope;
}

public void setOriginalScope(String originalScope) {
this.originalScope = originalScope;
}

public Boolean getOriginaOptionality() {
return originaOptionality;
}

public void setOriginaOptionality(Boolean originaOptionality) {
this.originaOptionality = originaOptionality;
}

/**
* The scope of the dependency that was not updated to during dependency resolution.
*
* @return the scope of the dependency that was ignored and not updated to
*/
public String getIgnoredScope() {
return ignoredScope;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,11 @@ public interface DependencyNode {
* @return the exclusions of the dependency
*/
List<Exclusion> getExclusions();

/**
* If this is a verbose dependency node, this returns the conflict data. Otherwise, it returns null.
*
* @return the conflict data of verbose dependency node or null
*/
ConflictData getConflictData();
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.maven.model.Dependency;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.shared.dependency.graph.ConflictData;
import org.apache.maven.shared.dependency.graph.DependencyCollectorBuilder;
import org.apache.maven.shared.dependency.graph.DependencyCollectorBuilderException;
import org.apache.maven.shared.dependency.graph.DependencyCollectorRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Exclusion;
import org.apache.maven.shared.dependency.graph.ConflictData;
import org.apache.maven.shared.dependency.graph.DependencyNode;
import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor;

Expand Down Expand Up @@ -177,4 +178,9 @@ public List<Exclusion> getExclusions() {
public String toNodeString() {
return artifact + (Boolean.TRUE.equals(optional) ? " (optional)" : "");
}

@Override
public ConflictData getConflictData() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Exclusion;
import org.apache.maven.shared.dependency.graph.ConflictData;
import org.apache.maven.shared.dependency.graph.DependencyNode;

class VerboseDependencyNode extends DefaultDependencyNode {
Expand Down Expand Up @@ -64,10 +65,6 @@ public String toNodeString() {
appender.append("scope managed from ", getPremanagedScope());
}

if (data.getOriginalScope() != null) {
appender.append("scope updated from ", data.getOriginalScope());
}

if (data.getIgnoredScope() != null) {
appender.append("scope not updated to ", data.getIgnoredScope());
}
Expand Down Expand Up @@ -96,6 +93,11 @@ public String toNodeString() {
return buffer.toString();
}

@Override
public ConflictData getConflictData() {
return data;
}

/**
* Utility class to concatenate a number of parameters with separator tokens.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import static java.util.Collections.emptyList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

public class DefaultDependencyNodeTest {

Expand All @@ -42,4 +43,12 @@ public void nodeString_for_mandatory_depenendency_does_not_contain_optional_info
new DefaultDependencyNode(null, artifact, "1.0", "compile", "1.0", false, emptyList());
assertEquals("group:artifact:jar:1.2:compile", optionalNode.toNodeString());
}

@Test
public void defaultDependencyNodeHasNullConflictData() {
DefaultDependencyNode node =
new DefaultDependencyNode(null, artifact, "1.0", "compile", "1.0", false, emptyList());

assertNull(node.getConflictData());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.shared.dependency.graph.internal;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.shared.dependency.graph.ConflictData;
import org.junit.jupiter.api.Test;

import static java.util.Collections.emptyList;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class VerboseDependencyNodeTest {

private final Artifact artifact = new DefaultArtifact("group", "artifact", "1.2", "compile", "jar", "", null);

@Test
public void verboseDependencyNode_should_return_conflict_data() {
ConflictData conflictData = new ConflictData("winnerVersion", "ignoredScope");
VerboseDependencyNode verboseDependencyNode =
new VerboseDependencyNode(null, artifact, "1.0", "compile", "1.0", false, emptyList(), conflictData);

assertEquals("winnerVersion", verboseDependencyNode.getConflictData().getWinnerVersion());
assertEquals("ignoredScope", verboseDependencyNode.getConflictData().getIgnoredScope());
}
}