This is an automated email from the ASF dual-hosted git repository. elharo pushed a commit to branch parent in repository https://gitbox.apache.org/repos/asf/maven-dependency-tree.git
commit 38213f1c37a9bd23dfee094d0d0011412a602c05 Author: Elliotte Rusty Harold <[email protected]> AuthorDate: Sat Mar 11 15:51:03 2023 -0500 Bump parent from 37 to 39 --- pom.xml | 18 +- .../graph/DependencyCollectorBuilder.java | 22 +-- .../graph/DependencyCollectorBuilderException.java | 23 +-- .../graph/DependencyCollectorRequest.java | 69 +++---- .../dependency/graph/DependencyGraphBuilder.java | 25 ++- .../graph/DependencyGraphBuilderException.java | 19 +- .../shared/dependency/graph/DependencyNode.java | 26 ++- .../filter/AncestorOrSelfDependencyNodeFilter.java | 40 ++-- .../graph/filter/AndDependencyNodeFilter.java | 39 ++-- .../graph/filter/ArtifactDependencyNodeFilter.java | 26 +-- .../graph/filter/DependencyNodeFilter.java | 14 +- .../dependency/graph/internal/ConflictData.java | 44 ++--- .../DefaultDependencyCollectorBuilder.java | 217 +++++++++------------ .../internal/DefaultDependencyGraphBuilder.java | 137 ++++++------- .../graph/internal/DefaultDependencyNode.java | 84 ++++---- .../internal/DirectScopeDependencySelector.java | 72 +++---- .../graph/internal/VerboseDependencyNode.java | 124 +++++------- .../graph/internal/VerboseJavaScopeSelector.java | 53 +++-- .../traversal/BuildingDependencyNodeVisitor.java | 70 +++---- .../traversal/CollectingDependencyNodeVisitor.java | 29 ++- .../graph/traversal/DependencyNodeVisitor.java | 18 +- .../traversal/FilteringDependencyNodeVisitor.java | 50 ++--- .../SerializingDependencyNodeVisitor.java | 101 ++++------ 23 files changed, 554 insertions(+), 766 deletions(-) diff --git a/pom.xml b/pom.xml index 0938ed8..fc068ac 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,4 @@ -<?xml version='1.0' encoding='UTF-8'?> +<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -23,7 +23,7 @@ <parent> <groupId>org.apache.maven.shared</groupId> <artifactId>maven-shared-components</artifactId> - <version>37</version> + <version>39</version> <relativePath /> </parent> @@ -33,11 +33,17 @@ <name>Apache Maven Dependency Tree</name> <description>A tree-based API for resolution of Maven project dependencies</description> + <contributors> + <contributor> + <name>Tuomas Kiviaho</name> + </contributor> + </contributors> + <scm> <connection>scm:git:https://gitbox.apache.org/repos/asf/maven-dependency-tree.git</connection> <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-dependency-tree.git</developerConnection> - <url>https://github.com/apache/maven-dependency-tree/tree/${project.scm.tag}</url> <tag>HEAD</tag> + <url>https://github.com/apache/maven-dependency-tree/tree/${project.scm.tag}</url> </scm> <issueManagement> <system>jira</system> @@ -61,12 +67,6 @@ <project.build.outputTimestamp>2022-11-16T01:25:26Z</project.build.outputTimestamp> </properties> - <contributors> - <contributor> - <name>Tuomas Kiviaho</name> - </contributor> - </contributors> - <dependencies> <dependency> <groupId>org.apache.maven</groupId> diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/DependencyCollectorBuilder.java b/src/main/java/org/apache/maven/shared/dependency/graph/DependencyCollectorBuilder.java index 48c0a77..e0fa14a 100644 --- a/src/main/java/org/apache/maven/shared/dependency/graph/DependencyCollectorBuilder.java +++ b/src/main/java/org/apache/maven/shared/dependency/graph/DependencyCollectorBuilder.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.dependency.graph; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ package org.apache.maven.shared.dependency.graph; * "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 + * 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 @@ -18,6 +16,7 @@ package org.apache.maven.shared.dependency.graph; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.dependency.graph; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.project.ProjectBuildingRequest; @@ -25,26 +24,24 @@ import org.apache.maven.project.ProjectBuildingRequest; /** * Maven project dependency raw dependency collector API, providing an abstraction layer against Maven 3 and Maven 3.1+ * particular Aether implementations. - * + * * @author Gabriel Belingueres * @since 3.1.0 */ -public interface DependencyCollectorBuilder -{ +public interface DependencyCollectorBuilder { /** * collect the project's raw dependency graph, with information to allow the API client to reason on its own about * dependencies. - * + * * @param buildingRequest the request with the project to process its dependencies. * @param filter an artifact filter if not all dependencies are required (can be <code>null</code>) * @return the raw dependency tree * @throws DependencyCollectorBuilderException if some of the dependencies could not be collected. */ - default DependencyNode collectDependencyGraph( ProjectBuildingRequest buildingRequest, ArtifactFilter filter ) - throws DependencyCollectorBuilderException - { - return collectDependencyGraph( new DependencyCollectorRequest( buildingRequest, filter ) ); + default DependencyNode collectDependencyGraph(ProjectBuildingRequest buildingRequest, ArtifactFilter filter) + throws DependencyCollectorBuilderException { + return collectDependencyGraph(new DependencyCollectorRequest(buildingRequest, filter)); } /** @@ -56,7 +53,6 @@ public interface DependencyCollectorBuilder * @throws DependencyCollectorBuilderException if some of the dependencies could not be collected. * @since 3.2.1 */ - DependencyNode collectDependencyGraph( DependencyCollectorRequest dependencyCollectorRequest ) + DependencyNode collectDependencyGraph(DependencyCollectorRequest dependencyCollectorRequest) throws DependencyCollectorBuilderException; - } diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/DependencyCollectorBuilderException.java b/src/main/java/org/apache/maven/shared/dependency/graph/DependencyCollectorBuilderException.java index 866213d..0e53c74 100644 --- a/src/main/java/org/apache/maven/shared/dependency/graph/DependencyCollectorBuilderException.java +++ b/src/main/java/org/apache/maven/shared/dependency/graph/DependencyCollectorBuilderException.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.dependency.graph; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ package org.apache.maven.shared.dependency.graph; * "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 + * 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 @@ -18,18 +16,17 @@ package org.apache.maven.shared.dependency.graph; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.dependency.graph; /** * Indicates an issue with the DependencyCollectorBuilder - * + * * @author Robert Scholte * @since 3.1.0 */ -public class DependencyCollectorBuilderException - extends Exception -{ +public class DependencyCollectorBuilderException extends Exception { /** - * + * */ private static final long serialVersionUID = 1305852327231950979L; @@ -38,17 +35,15 @@ public class DependencyCollectorBuilderException /** * @param message Message indicating why dependency graph could not be resolved. */ - public DependencyCollectorBuilderException( String message ) - { - super( message ); + public DependencyCollectorBuilderException(String message) { + super(message); } /** * @param message Message indicating why dependency graph could not be resolved. * @param cause Throwable indicating at which point the graph failed to be resolved. */ - public DependencyCollectorBuilderException( String message, Throwable cause ) - { - super( message, cause ); + public DependencyCollectorBuilderException(String message, Throwable cause) { + super(message, cause); } } diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/DependencyCollectorRequest.java b/src/main/java/org/apache/maven/shared/dependency/graph/DependencyCollectorRequest.java index 450650e..a290580 100644 --- a/src/main/java/org/apache/maven/shared/dependency/graph/DependencyCollectorRequest.java +++ b/src/main/java/org/apache/maven/shared/dependency/graph/DependencyCollectorRequest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.dependency.graph; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ package org.apache.maven.shared.dependency.graph; * "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 + * 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 @@ -18,6 +16,11 @@ package org.apache.maven.shared.dependency.graph; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.dependency.graph; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.project.ProjectBuildingRequest; @@ -35,10 +38,6 @@ import org.eclipse.aether.util.graph.transformer.JavaScopeDeriver; import org.eclipse.aether.util.graph.transformer.NearestVersionSelector; import org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; - /** * <div> * This class will carry various options used by @@ -77,8 +76,7 @@ import java.util.Objects; * </div> * @since 3.2.1 */ -public class DependencyCollectorRequest -{ +public class DependencyCollectorRequest { private final ProjectBuildingRequest buildingRequest; @@ -87,76 +85,65 @@ public class DependencyCollectorRequest private Map<String, Object> configProperties = new HashMap<>(); private DependencySelector dependencySelector = new AndDependencySelector( - new DirectScopeDependencySelector( JavaScopes.TEST ), - new DirectScopeDependencySelector( JavaScopes.PROVIDED ), + new DirectScopeDependencySelector(JavaScopes.TEST), + new DirectScopeDependencySelector(JavaScopes.PROVIDED), new OptionalDependencySelector(), - new ExclusionDependencySelector() ); + new ExclusionDependencySelector()); private DependencyGraphTransformer dependencyGraphTransformer = new ConflictResolver( new NearestVersionSelector(), new VerboseJavaScopeSelector(), new SimpleOptionalitySelector(), - new JavaScopeDeriver() ); + new JavaScopeDeriver()); - public DependencyCollectorRequest( ProjectBuildingRequest buildingRequest ) - { - this( buildingRequest, null ); + public DependencyCollectorRequest(ProjectBuildingRequest buildingRequest) { + this(buildingRequest, null); } - public DependencyCollectorRequest( ProjectBuildingRequest buildingRequest, ArtifactFilter filter ) - { - Objects.requireNonNull( buildingRequest, "ProjectBuildingRequest cannot be null" ); + public DependencyCollectorRequest(ProjectBuildingRequest buildingRequest, ArtifactFilter filter) { + Objects.requireNonNull(buildingRequest, "ProjectBuildingRequest cannot be null"); this.buildingRequest = buildingRequest; this.filter = filter; - configProperties.put( ConflictResolver.CONFIG_PROP_VERBOSE, true ); - configProperties.put( DependencyManagerUtils.CONFIG_PROP_VERBOSE, true ); + configProperties.put(ConflictResolver.CONFIG_PROP_VERBOSE, true); + configProperties.put(DependencyManagerUtils.CONFIG_PROP_VERBOSE, true); } - public ProjectBuildingRequest getBuildingRequest() - { + public ProjectBuildingRequest getBuildingRequest() { return buildingRequest; } - public ArtifactFilter getFilter() - { + public ArtifactFilter getFilter() { return filter; } - public DependencySelector getDependencySelector() - { + public DependencySelector getDependencySelector() { return dependencySelector; } - public DependencyCollectorRequest dependencySelector( DependencySelector dependencySelector ) - { + public DependencyCollectorRequest dependencySelector(DependencySelector dependencySelector) { this.dependencySelector = dependencySelector; return this; } - public DependencyGraphTransformer getDependencyGraphTransformer() - { + public DependencyGraphTransformer getDependencyGraphTransformer() { return dependencyGraphTransformer; } public DependencyCollectorRequest dependencyGraphTransformer( - DependencyGraphTransformer dependencyGraphTransformer ) - { + DependencyGraphTransformer dependencyGraphTransformer) { this.dependencyGraphTransformer = dependencyGraphTransformer; return this; } - public Map<String, Object> getConfigProperties() - { + public Map<String, Object> getConfigProperties() { return this.configProperties; } - public void addConfigProperty( String key, Object value ) - { - this.configProperties.put( key, value ); + public void addConfigProperty(String key, Object value) { + this.configProperties.put(key, value); } - public void removeConfigProperty( String key ) - { - this.configProperties.remove( key ); + public void removeConfigProperty(String key) { + this.configProperties.remove(key); } } diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/DependencyGraphBuilder.java b/src/main/java/org/apache/maven/shared/dependency/graph/DependencyGraphBuilder.java index cab4ce8..96b9ce3 100644 --- a/src/main/java/org/apache/maven/shared/dependency/graph/DependencyGraphBuilder.java +++ b/src/main/java/org/apache/maven/shared/dependency/graph/DependencyGraphBuilder.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.dependency.graph; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ package org.apache.maven.shared.dependency.graph; * "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 + * 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 @@ -18,21 +16,21 @@ package org.apache.maven.shared.dependency.graph; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.dependency.graph; + +import java.util.Collection; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuildingRequest; -import java.util.Collection; - /** * Maven project dependency graph builder API, neutral against Maven 2 or Maven 3. * * @author Hervé Boutemy * @since 2.0 */ -public interface DependencyGraphBuilder -{ +public interface DependencyGraphBuilder { /** * Build the dependency graph. * @@ -41,8 +39,8 @@ public interface DependencyGraphBuilder * @return the dependency graph * @throws DependencyGraphBuilderException if some of the dependencies could not be resolved. */ - DependencyNode buildDependencyGraph( ProjectBuildingRequest buildingRequest, ArtifactFilter filter ) - throws DependencyGraphBuilderException; + DependencyNode buildDependencyGraph(ProjectBuildingRequest buildingRequest, ArtifactFilter filter) + throws DependencyGraphBuilderException; /** * @@ -54,10 +52,9 @@ public interface DependencyGraphBuilder * @deprecated Use {@link #buildDependencyGraph(ProjectBuildingRequest, ArtifactFilter)} instead */ @Deprecated - default DependencyNode buildDependencyGraph( ProjectBuildingRequest buildingRequest, ArtifactFilter filter, - Collection<MavenProject> reactorProjects ) - throws DependencyGraphBuilderException - { - return buildDependencyGraph( buildingRequest, filter ); + default DependencyNode buildDependencyGraph( + ProjectBuildingRequest buildingRequest, ArtifactFilter filter, Collection<MavenProject> reactorProjects) + throws DependencyGraphBuilderException { + return buildDependencyGraph(buildingRequest, filter); } } diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/DependencyGraphBuilderException.java b/src/main/java/org/apache/maven/shared/dependency/graph/DependencyGraphBuilderException.java index 9d92bda..c71f970 100644 --- a/src/main/java/org/apache/maven/shared/dependency/graph/DependencyGraphBuilderException.java +++ b/src/main/java/org/apache/maven/shared/dependency/graph/DependencyGraphBuilderException.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.dependency.graph; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ package org.apache.maven.shared.dependency.graph; * "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 + * 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 @@ -18,6 +16,7 @@ package org.apache.maven.shared.dependency.graph; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.dependency.graph; /** * Indicates that a Maven project's dependency graph cannot be resolved. @@ -25,9 +24,7 @@ package org.apache.maven.shared.dependency.graph; * @author Hervé Boutemy * @since 2.0 */ -public class DependencyGraphBuilderException - extends Exception -{ +public class DependencyGraphBuilderException extends Exception { private static final long serialVersionUID = -7428777046707410949L; // constructors ----------------------------------------------------------- @@ -35,17 +32,15 @@ public class DependencyGraphBuilderException /** * @param message Message indicating why dependency graph could not be resolved. */ - public DependencyGraphBuilderException( String message ) - { - super( message ); + public DependencyGraphBuilderException(String message) { + super(message); } /** * @param message Message indicating why dependency graph could not be resolved. * @param cause Throwable indicating at which point the graph failed to be resolved. */ - public DependencyGraphBuilderException( String message, Throwable cause ) - { - super( message, cause ); + public DependencyGraphBuilderException(String message, Throwable cause) { + super(message, cause); } } diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/DependencyNode.java b/src/main/java/org/apache/maven/shared/dependency/graph/DependencyNode.java index e46d6a5..1f925a5 100644 --- a/src/main/java/org/apache/maven/shared/dependency/graph/DependencyNode.java +++ b/src/main/java/org/apache/maven/shared/dependency/graph/DependencyNode.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.dependency.graph; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ package org.apache.maven.shared.dependency.graph; * "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 + * 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 @@ -18,6 +16,7 @@ package org.apache.maven.shared.dependency.graph; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.dependency.graph; import java.util.List; @@ -32,8 +31,7 @@ import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor; * @author Hervé Boutemy * @since 2.0 */ -public interface DependencyNode -{ +public interface DependencyNode { /** * @return Artifact for this DependencyNode. */ @@ -46,30 +44,30 @@ public interface DependencyNode /** * Applies the specified dependency node visitor to this dependency node and its children. - * + * * @param visitor the dependency node visitor to use * @return the visitor result of ending the visit to this node * @since 1.1 */ - boolean accept( DependencyNodeVisitor visitor ); + boolean accept(DependencyNodeVisitor visitor); /** * Gets the parent dependency node of this dependency node. - * + * * @return the parent dependency node */ DependencyNode getParent(); /** * Gets the version or version range for the dependency before dependency management was applied (if any). - * + * * @return The dependency version before dependency management or {@code null} if the version was not managed. */ String getPremanagedVersion(); /** * Gets the scope for the dependency before dependency management was applied (if any). - * + * * @return The dependency scope before dependency management or {@code null} if the scope was not managed. */ String getPremanagedScope(); @@ -77,14 +75,14 @@ public interface DependencyNode /** * A constraint on versions for a dependency. A constraint can either consist of one or more version ranges or a * single version. - * + * * @return The constraint on the dependency. */ String getVersionConstraint(); /** * Returns a string representation of this dependency node. - * + * * @return the string representation */ String toNodeString(); @@ -93,9 +91,9 @@ public interface DependencyNode * @return true for an optional dependency. */ Boolean getOptional(); - + /** - * + * * @return the exclusions of the dependency */ List<Exclusion> getExclusions(); diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/filter/AncestorOrSelfDependencyNodeFilter.java b/src/main/java/org/apache/maven/shared/dependency/graph/filter/AncestorOrSelfDependencyNodeFilter.java index f26c4e3..e96684d 100644 --- a/src/main/java/org/apache/maven/shared/dependency/graph/filter/AncestorOrSelfDependencyNodeFilter.java +++ b/src/main/java/org/apache/maven/shared/dependency/graph/filter/AncestorOrSelfDependencyNodeFilter.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.dependency.graph.filter; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ package org.apache.maven.shared.dependency.graph.filter; * "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 + * 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 @@ -18,6 +16,7 @@ package org.apache.maven.shared.dependency.graph.filter; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.dependency.graph.filter; import java.util.Collections; import java.util.List; @@ -26,14 +25,12 @@ import org.apache.maven.shared.dependency.graph.DependencyNode; /** * A dependency node filter than only accepts nodes that are ancestors of, or equal to, a given list of nodes. - * + * * @author <a href="mailto:[email protected]">Mark Hobson</a> * @version $Id$ * @since 1.1 */ -public class AncestorOrSelfDependencyNodeFilter - implements DependencyNodeFilter -{ +public class AncestorOrSelfDependencyNodeFilter implements DependencyNodeFilter { // fields ----------------------------------------------------------------- /** @@ -43,19 +40,17 @@ public class AncestorOrSelfDependencyNodeFilter // constructors ----------------------------------------------------------- - public AncestorOrSelfDependencyNodeFilter( DependencyNode descendantNode ) - { - this( Collections.singletonList( descendantNode ) ); + public AncestorOrSelfDependencyNodeFilter(DependencyNode descendantNode) { + this(Collections.singletonList(descendantNode)); } /** * Creates a dependency node filter that only accepts nodes that are ancestors of, or equal to, the specified list * of nodes. - * + * * @param descendantNodes the list of nodes to accept ancestors-or-self of */ - public AncestorOrSelfDependencyNodeFilter( List<DependencyNode> descendantNodes ) - { + public AncestorOrSelfDependencyNodeFilter(List<DependencyNode> descendantNodes) { this.descendantNodes = descendantNodes; } @@ -65,12 +60,9 @@ public class AncestorOrSelfDependencyNodeFilter * {@inheritDoc} */ @Override - public boolean accept( DependencyNode node ) - { - for ( DependencyNode descendantNode : descendantNodes ) - { - if ( isAncestorOrSelf( node, descendantNode ) ) - { + public boolean accept(DependencyNode node) { + for (DependencyNode descendantNode : descendantNodes) { + if (isAncestorOrSelf(node, descendantNode)) { return true; } } @@ -82,18 +74,16 @@ public class AncestorOrSelfDependencyNodeFilter /** * Gets whether the first dependency node is an ancestor-or-self of the second. - * + * * @param ancestorNode the ancestor-or-self dependency node * @param descendantNode the dependency node to test * @return <code>true</code> if <code>ancestorNode</code> is an ancestor, or equal to, <code>descendantNode</code> */ - private boolean isAncestorOrSelf( DependencyNode ancestorNode, DependencyNode descendantNode ) - { + private boolean isAncestorOrSelf(DependencyNode ancestorNode, DependencyNode descendantNode) { boolean ancestor = false; - while ( !ancestor && descendantNode != null ) - { - ancestor = ancestorNode.equals( descendantNode ); + while (!ancestor && descendantNode != null) { + ancestor = ancestorNode.equals(descendantNode); descendantNode = descendantNode.getParent(); } diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/filter/AndDependencyNodeFilter.java b/src/main/java/org/apache/maven/shared/dependency/graph/filter/AndDependencyNodeFilter.java index 84c0829..99b1917 100644 --- a/src/main/java/org/apache/maven/shared/dependency/graph/filter/AndDependencyNodeFilter.java +++ b/src/main/java/org/apache/maven/shared/dependency/graph/filter/AndDependencyNodeFilter.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.dependency.graph.filter; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ package org.apache.maven.shared.dependency.graph.filter; * "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 + * 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 @@ -18,6 +16,7 @@ package org.apache.maven.shared.dependency.graph.filter; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.dependency.graph.filter; import java.util.Arrays; import java.util.Collections; @@ -27,14 +26,12 @@ import org.apache.maven.shared.dependency.graph.DependencyNode; /** * A dependency node filter that logically ANDs together a number of other dependency node filters. - * + * * @author <a href="mailto:[email protected]">Mark Hobson</a> * @version $Id$ * @since 1.1 */ -public class AndDependencyNodeFilter - implements DependencyNodeFilter -{ +public class AndDependencyNodeFilter implements DependencyNodeFilter { // fields ----------------------------------------------------------------- /** @@ -46,23 +43,21 @@ public class AndDependencyNodeFilter /** * Creates a dependency node filter that logically ANDs together the two specified dependency node filters. - * + * * @param filter1 the first dependency node filter to logically AND together * @param filter2 the second dependency node filter to logically AND together */ - public AndDependencyNodeFilter( DependencyNodeFilter filter1, DependencyNodeFilter filter2 ) - { - this( Arrays.asList( filter1, filter2 ) ); + public AndDependencyNodeFilter(DependencyNodeFilter filter1, DependencyNodeFilter filter2) { + this(Arrays.asList(filter1, filter2)); } /** * Creates a dependency node filter that logically ANDs together the specified dependency node filters. - * + * * @param filters the list of dependency node filters to logically AND together */ - public AndDependencyNodeFilter( List<DependencyNodeFilter> filters ) - { - this.filters = Collections.unmodifiableList( filters ); + public AndDependencyNodeFilter(List<DependencyNodeFilter> filters) { + this.filters = Collections.unmodifiableList(filters); } // DependencyNodeFilter methods ------------------------------------------- @@ -71,12 +66,9 @@ public class AndDependencyNodeFilter * {@inheritDoc} */ @Override - public boolean accept( DependencyNode node ) - { - for ( DependencyNodeFilter filter : filters ) - { - if ( !filter.accept( node ) ) - { + public boolean accept(DependencyNode node) { + for (DependencyNodeFilter filter : filters) { + if (!filter.accept(node)) { return false; } } @@ -88,11 +80,10 @@ public class AndDependencyNodeFilter /** * Gets the list of dependency node filters that this filter ANDs together. - * + * * @return the dependency node filters that this filter ANDs together */ - public List<DependencyNodeFilter> getDependencyNodeFilters() - { + public List<DependencyNodeFilter> getDependencyNodeFilters() { return filters; } } diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/filter/ArtifactDependencyNodeFilter.java b/src/main/java/org/apache/maven/shared/dependency/graph/filter/ArtifactDependencyNodeFilter.java index 829f625..6da097d 100644 --- a/src/main/java/org/apache/maven/shared/dependency/graph/filter/ArtifactDependencyNodeFilter.java +++ b/src/main/java/org/apache/maven/shared/dependency/graph/filter/ArtifactDependencyNodeFilter.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.dependency.graph.filter; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ package org.apache.maven.shared.dependency.graph.filter; * "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 + * 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 @@ -18,6 +16,7 @@ package org.apache.maven.shared.dependency.graph.filter; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.dependency.graph.filter; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; @@ -25,14 +24,12 @@ import org.apache.maven.shared.dependency.graph.DependencyNode; /** * A dependency node filter that delegates to an artifact filter. - * + * * @author <a href="mailto:[email protected]">Mark Hobson</a> * @version $Id$ * @since 1.1 */ -public class ArtifactDependencyNodeFilter - implements DependencyNodeFilter -{ +public class ArtifactDependencyNodeFilter implements DependencyNodeFilter { // fields ----------------------------------------------------------------- /** @@ -44,11 +41,10 @@ public class ArtifactDependencyNodeFilter /** * Creates a dependency node filter that delegates to the specified artifact filter. - * + * * @param filter the artifact filter to delegate to */ - public ArtifactDependencyNodeFilter( ArtifactFilter filter ) - { + public ArtifactDependencyNodeFilter(ArtifactFilter filter) { this.filter = filter; } @@ -58,22 +54,20 @@ public class ArtifactDependencyNodeFilter * {@inheritDoc} */ @Override - public boolean accept( DependencyNode node ) - { + public boolean accept(DependencyNode node) { Artifact artifact = node.getArtifact(); - return filter.include( artifact ); + return filter.include(artifact); } // public methods --------------------------------------------------------- /** * Gets the artifact filter this dependency node filter delegates to. - * + * * @return the artifact filter this dependency node filter delegates to */ - public ArtifactFilter getArtifactFilter() - { + public ArtifactFilter getArtifactFilter() { return filter; } } diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/filter/DependencyNodeFilter.java b/src/main/java/org/apache/maven/shared/dependency/graph/filter/DependencyNodeFilter.java index 0d508d0..5949ff4 100644 --- a/src/main/java/org/apache/maven/shared/dependency/graph/filter/DependencyNodeFilter.java +++ b/src/main/java/org/apache/maven/shared/dependency/graph/filter/DependencyNodeFilter.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.dependency.graph.filter; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ package org.apache.maven.shared.dependency.graph.filter; * "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 + * 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 @@ -18,23 +16,23 @@ package org.apache.maven.shared.dependency.graph.filter; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.dependency.graph.filter; import org.apache.maven.shared.dependency.graph.DependencyNode; /** * Defines a filter for dependency nodes. - * + * * @author <a href="mailto:[email protected]">Mark Hobson</a> * @version $Id$ * @since 1.1 */ -public interface DependencyNodeFilter -{ +public interface DependencyNodeFilter { /** * Gets whether this filter accepts the specified dependency node. - * + * * @param node the dependency node to check * @return <code>true</code> if this filter accepts the specified dependency node */ - boolean accept( DependencyNode node ); + boolean accept(DependencyNode node); } diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/internal/ConflictData.java b/src/main/java/org/apache/maven/shared/dependency/graph/internal/ConflictData.java index 9393c66..1ee9f43 100644 --- a/src/main/java/org/apache/maven/shared/dependency/graph/internal/ConflictData.java +++ b/src/main/java/org/apache/maven/shared/dependency/graph/internal/ConflictData.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.dependency.graph.internal; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ package org.apache.maven.shared.dependency.graph.internal; * "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 + * 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 @@ -18,56 +16,48 @@ package org.apache.maven.shared.dependency.graph.internal; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.dependency.graph.internal; /** - * Excplicit subset of Aethers DependencyNode.getData() - * - * @author Robert Scholte + * Explicit subset of Aether's DependencyNode.getData(). * + * @author Robert Scholte */ -public class ConflictData -{ +public class ConflictData { private String winnerVersion; private String originalScope; - + private String ignoredScope; - + private Boolean originaOptionality; - - public ConflictData( String winnerVersion, String ignoredScope ) - { + + public ConflictData(String winnerVersion, String ignoredScope) { this.winnerVersion = winnerVersion; this.ignoredScope = ignoredScope; } - - public String getWinnerVersion() - { + + public String getWinnerVersion() { return winnerVersion; } - - public String getOriginalScope() - { + + public String getOriginalScope() { return originalScope; } - public void setOriginalScope( String originalScope ) - { + public void setOriginalScope(String originalScope) { this.originalScope = originalScope; } - public Boolean getOriginaOptionality() - { + public Boolean getOriginaOptionality() { return originaOptionality; } - public void setOriginaOptionality( Boolean originaOptionality ) - { + public void setOriginaOptionality(Boolean originaOptionality) { this.originaOptionality = originaOptionality; } - public String getIgnoredScope() - { + public String getIgnoredScope() { return ignoredScope; } } diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyCollectorBuilder.java b/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyCollectorBuilder.java index b30f782..3a436eb 100644 --- a/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyCollectorBuilder.java +++ b/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyCollectorBuilder.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.dependency.graph.internal; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ package org.apache.maven.shared.dependency.graph.internal; * "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 + * 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 @@ -18,15 +16,16 @@ package org.apache.maven.shared.dependency.graph.internal; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.dependency.graph.internal; + +import javax.inject.Inject; +import javax.inject.Named; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; -import javax.inject.Inject; -import javax.inject.Named; - import org.apache.maven.RepositoryUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; @@ -56,31 +55,26 @@ import org.slf4j.LoggerFactory; /** * Project dependency raw dependency collector API, abstracting Maven 3.1+'s Aether implementation. - * + * * @author Gabriel Belingueres * @since 3.1.0 */ @Named -public class DefaultDependencyCollectorBuilder - implements DependencyCollectorBuilder -{ - private static final Logger LOGGER = LoggerFactory.getLogger( DefaultDependencyCollectorBuilder.class ); +public class DefaultDependencyCollectorBuilder implements DependencyCollectorBuilder { + private static final Logger LOGGER = LoggerFactory.getLogger(DefaultDependencyCollectorBuilder.class); private final RepositorySystem repositorySystem; @Inject - public DefaultDependencyCollectorBuilder( RepositorySystem repositorySystem ) - { + public DefaultDependencyCollectorBuilder(RepositorySystem repositorySystem) { this.repositorySystem = repositorySystem; } @Override - public DependencyNode collectDependencyGraph( DependencyCollectorRequest dependencyCollectorRequest ) - throws DependencyCollectorBuilderException - { + public DependencyNode collectDependencyGraph(DependencyCollectorRequest dependencyCollectorRequest) + throws DependencyCollectorBuilderException { DefaultRepositorySystemSession session = null; - try - { + try { ProjectBuildingRequest buildingRequest = dependencyCollectorRequest.getBuildingRequest(); MavenProject project = buildingRequest.getProject(); @@ -89,177 +83,160 @@ public class DefaultDependencyCollectorBuilder RepositorySystemSession repositorySession = buildingRequest.getRepositorySession(); - session = new DefaultRepositorySystemSession( repositorySession ); + session = new DefaultRepositorySystemSession(repositorySession); - session.setDependencyGraphTransformer( dependencyCollectorRequest.getDependencyGraphTransformer() ); + session.setDependencyGraphTransformer(dependencyCollectorRequest.getDependencyGraphTransformer()); - session.setDependencySelector( dependencyCollectorRequest.getDependencySelector() ); + session.setDependencySelector(dependencyCollectorRequest.getDependencySelector()); - for ( Map.Entry<String, Object> entry : dependencyCollectorRequest.getConfigProperties().entrySet() ) - { - session.setConfigProperty( entry.getKey(), entry.getValue() ); + for (Map.Entry<String, Object> entry : + dependencyCollectorRequest.getConfigProperties().entrySet()) { + session.setConfigProperty(entry.getKey(), entry.getValue()); } - org.eclipse.aether.artifact.Artifact aetherArtifact = RepositoryUtils.toArtifact( projectArtifact ); + org.eclipse.aether.artifact.Artifact aetherArtifact = RepositoryUtils.toArtifact(projectArtifact); List<org.eclipse.aether.repository.RemoteRepository> aetherRepos = - RepositoryUtils.toRepos( remoteArtifactRepositories ); + RepositoryUtils.toRepos(remoteArtifactRepositories); CollectRequest collectRequest = new CollectRequest(); - collectRequest.setRootArtifact( aetherArtifact ); - collectRequest.setRepositories( aetherRepos ); + collectRequest.setRootArtifact(aetherArtifact); + collectRequest.setRepositories(aetherRepos); org.eclipse.aether.artifact.ArtifactTypeRegistry stereotypes = session.getArtifactTypeRegistry(); - collectDependencyList( collectRequest, project, stereotypes ); - collectManagedDependencyList( collectRequest, project, stereotypes ); + collectDependencyList(collectRequest, project, stereotypes); + collectManagedDependencyList(collectRequest, project, stereotypes); - CollectResult collectResult = repositorySystem.collectDependencies( session, collectRequest ); + CollectResult collectResult = repositorySystem.collectDependencies(session, collectRequest); org.eclipse.aether.graph.DependencyNode rootNode = collectResult.getRoot(); - if ( LOGGER.isDebugEnabled() ) - { - logTree( rootNode ); + if (LOGGER.isDebugEnabled()) { + logTree(rootNode); } - return buildDependencyNode( null, rootNode, projectArtifact, dependencyCollectorRequest.getFilter() ); - } - catch ( DependencyCollectionException e ) - { - throw new DependencyCollectorBuilderException( "Could not collect dependencies: " + e.getResult(), e ); - } - finally - { - if ( session != null ) - { + return buildDependencyNode(null, rootNode, projectArtifact, dependencyCollectorRequest.getFilter()); + } catch (DependencyCollectionException e) { + throw new DependencyCollectorBuilderException("Could not collect dependencies: " + e.getResult(), e); + } finally { + if (session != null) { session.setReadOnly(); } } } - private void logTree( org.eclipse.aether.graph.DependencyNode rootNode ) - { + private void logTree(org.eclipse.aether.graph.DependencyNode rootNode) { // print the node tree with its associated data Map - rootNode.accept( new TreeDependencyVisitor( new DependencyVisitor() - { + rootNode.accept(new TreeDependencyVisitor(new DependencyVisitor() { String indent = ""; @Override - public boolean visitEnter( org.eclipse.aether.graph.DependencyNode dependencyNode ) - { - LOGGER.debug( "{}Aether node: {} data map: {}", indent, dependencyNode, dependencyNode.getData() ); + public boolean visitEnter(org.eclipse.aether.graph.DependencyNode dependencyNode) { + LOGGER.debug("{}Aether node: {} data map: {}", indent, dependencyNode, dependencyNode.getData()); indent += " "; return true; } @Override - public boolean visitLeave( org.eclipse.aether.graph.DependencyNode dependencyNode ) - { - indent = indent.substring( 0, indent.length() - 4 ); + public boolean visitLeave(org.eclipse.aether.graph.DependencyNode dependencyNode) { + indent = indent.substring(0, indent.length() - 4); return true; } - } ) ); + })); } - private void collectManagedDependencyList( CollectRequest collectRequest, MavenProject project, - ArtifactTypeRegistry stereotypes ) - { - if ( project.getDependencyManagement() != null ) - { - for ( Dependency dependency : project.getDependencyManagement().getDependencies() ) - { - org.eclipse.aether.graph.Dependency aetherDep = RepositoryUtils.toDependency( dependency, stereotypes ); - collectRequest.addManagedDependency( aetherDep ); + private void collectManagedDependencyList( + CollectRequest collectRequest, MavenProject project, ArtifactTypeRegistry stereotypes) { + if (project.getDependencyManagement() != null) { + for (Dependency dependency : project.getDependencyManagement().getDependencies()) { + org.eclipse.aether.graph.Dependency aetherDep = RepositoryUtils.toDependency(dependency, stereotypes); + collectRequest.addManagedDependency(aetherDep); } } } - private void collectDependencyList( CollectRequest collectRequest, MavenProject project, - org.eclipse.aether.artifact.ArtifactTypeRegistry stereotypes ) - { - for ( Dependency dependency : project.getDependencies() ) - { - org.eclipse.aether.graph.Dependency aetherDep = RepositoryUtils.toDependency( dependency, stereotypes ); - collectRequest.addDependency( aetherDep ); + private void collectDependencyList( + CollectRequest collectRequest, + MavenProject project, + org.eclipse.aether.artifact.ArtifactTypeRegistry stereotypes) { + for (Dependency dependency : project.getDependencies()) { + org.eclipse.aether.graph.Dependency aetherDep = RepositoryUtils.toDependency(dependency, stereotypes); + collectRequest.addDependency(aetherDep); } } - private Artifact getDependencyArtifact( org.eclipse.aether.graph.Dependency dep ) - { + private Artifact getDependencyArtifact(org.eclipse.aether.graph.Dependency dep) { org.eclipse.aether.artifact.Artifact artifact = dep.getArtifact(); - Artifact mavenArtifact = RepositoryUtils.toArtifact( artifact ); - mavenArtifact.setScope( dep.getScope() ); - mavenArtifact.setOptional( dep.isOptional() ); + Artifact mavenArtifact = RepositoryUtils.toArtifact(artifact); + mavenArtifact.setScope(dep.getScope()); + mavenArtifact.setOptional(dep.isOptional()); return mavenArtifact; } - private DependencyNode buildDependencyNode( DependencyNode parent, org.eclipse.aether.graph.DependencyNode node, - Artifact artifact, ArtifactFilter filter ) - { - String premanagedVersion = DependencyManagerUtils.getPremanagedVersion( node ); - String premanagedScope = DependencyManagerUtils.getPremanagedScope( node ); + private DependencyNode buildDependencyNode( + DependencyNode parent, + org.eclipse.aether.graph.DependencyNode node, + Artifact artifact, + ArtifactFilter filter) { + String premanagedVersion = DependencyManagerUtils.getPremanagedVersion(node); + String premanagedScope = DependencyManagerUtils.getPremanagedScope(node); Boolean optional = null; - if ( node.getDependency() != null ) - { + if (node.getDependency() != null) { optional = node.getDependency().isOptional(); } - + List<org.apache.maven.model.Exclusion> exclusions = null; - if ( node.getDependency() != null ) - { - exclusions = new ArrayList<>( node.getDependency().getExclusions().size() ); - for ( Exclusion exclusion : node.getDependency().getExclusions() ) - { + if (node.getDependency() != null) { + exclusions = new ArrayList<>(node.getDependency().getExclusions().size()); + for (Exclusion exclusion : node.getDependency().getExclusions()) { org.apache.maven.model.Exclusion modelExclusion = new org.apache.maven.model.Exclusion(); - modelExclusion.setGroupId( exclusion.getGroupId() ); - modelExclusion.setArtifactId( exclusion.getArtifactId() ); - exclusions.add( modelExclusion ); + modelExclusion.setGroupId(exclusion.getGroupId()); + modelExclusion.setArtifactId(exclusion.getArtifactId()); + exclusions.add(modelExclusion); } } org.eclipse.aether.graph.DependencyNode winner = - (org.eclipse.aether.graph.DependencyNode) node.getData().get( ConflictResolver.NODE_DATA_WINNER ); + (org.eclipse.aether.graph.DependencyNode) node.getData().get(ConflictResolver.NODE_DATA_WINNER); String winnerVersion = null; String ignoredScope = null; - if ( winner != null ) - { + if (winner != null) { winnerVersion = winner.getArtifact().getBaseVersion(); + } else { + ignoredScope = (String) node.getData().get(VerboseJavaScopeSelector.REDUCED_SCOPE); } - else - { - ignoredScope = (String) node.getData().get( VerboseJavaScopeSelector.REDUCED_SCOPE ); - } - - ConflictData data = new ConflictData( winnerVersion, ignoredScope ); - - VerboseDependencyNode current = - new VerboseDependencyNode( parent, artifact, premanagedVersion, premanagedScope, - getVersionSelectedFromRange( node.getVersionConstraint() ), optional, - exclusions, data ); - - List<DependencyNode> nodes = new ArrayList<>( node.getChildren().size() ); - for ( org.eclipse.aether.graph.DependencyNode child : node.getChildren() ) - { - Artifact childArtifact = getDependencyArtifact( child.getDependency() ); - - if ( ( filter == null ) || filter.include( childArtifact ) ) - { - nodes.add( buildDependencyNode( current, child, childArtifact, filter ) ); + + ConflictData data = new ConflictData(winnerVersion, ignoredScope); + + VerboseDependencyNode current = new VerboseDependencyNode( + parent, + artifact, + premanagedVersion, + premanagedScope, + getVersionSelectedFromRange(node.getVersionConstraint()), + optional, + exclusions, + data); + + List<DependencyNode> nodes = new ArrayList<>(node.getChildren().size()); + for (org.eclipse.aether.graph.DependencyNode child : node.getChildren()) { + Artifact childArtifact = getDependencyArtifact(child.getDependency()); + + if ((filter == null) || filter.include(childArtifact)) { + nodes.add(buildDependencyNode(current, child, childArtifact, filter)); } } - current.setChildren( Collections.unmodifiableList( nodes ) ); + current.setChildren(Collections.unmodifiableList(nodes)); return current; } - private String getVersionSelectedFromRange( VersionConstraint constraint ) - { - if ( ( constraint == null ) || ( constraint.getVersion() != null ) ) - { + private String getVersionSelectedFromRange(VersionConstraint constraint) { + if ((constraint == null) || (constraint.getVersion() != null)) { return null; } diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyGraphBuilder.java b/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyGraphBuilder.java index 599f5a5..955dc3d 100644 --- a/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyGraphBuilder.java +++ b/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyGraphBuilder.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.dependency.graph.internal; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ package org.apache.maven.shared.dependency.graph.internal; * "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 + * 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 @@ -18,16 +16,15 @@ package org.apache.maven.shared.dependency.graph.internal; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.dependency.graph.internal; -import static org.eclipse.aether.util.graph.manager.DependencyManagerUtils.NODE_DATA_PREMANAGED_VERSION; +import javax.inject.Inject; +import javax.inject.Named; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import javax.inject.Inject; -import javax.inject.Named; - import org.apache.maven.RepositoryUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; @@ -49,6 +46,8 @@ import org.eclipse.aether.graph.Exclusion; import org.eclipse.aether.util.graph.manager.DependencyManagerUtils; import org.eclipse.aether.version.VersionConstraint; +import static org.eclipse.aether.util.graph.manager.DependencyManagerUtils.NODE_DATA_PREMANAGED_VERSION; + /** * Wrapper around Eclipse Aether dependency resolver, used in Maven 3.1. * @@ -57,14 +56,11 @@ import org.eclipse.aether.version.VersionConstraint; * @since 2.1 */ @Named -public class DefaultDependencyGraphBuilder - implements DependencyGraphBuilder -{ +public class DefaultDependencyGraphBuilder implements DependencyGraphBuilder { private final ProjectDependenciesResolver resolver; @Inject - public DefaultDependencyGraphBuilder( ProjectDependenciesResolver resolver ) - { + public DefaultDependencyGraphBuilder(ProjectDependenciesResolver resolver) { this.resolver = resolver; } @@ -77,105 +73,98 @@ public class DefaultDependencyGraphBuilder * @throws DependencyGraphBuilderException if some of the dependencies could not be resolved. */ @Override - public DependencyNode buildDependencyGraph( ProjectBuildingRequest buildingRequest, ArtifactFilter filter ) - throws DependencyGraphBuilderException - { + public DependencyNode buildDependencyGraph(ProjectBuildingRequest buildingRequest, ArtifactFilter filter) + throws DependencyGraphBuilderException { MavenProject project = buildingRequest.getProject(); RepositorySystemSession session = buildingRequest.getRepositorySession(); - - if ( Boolean.TRUE != session.getConfigProperties().get( NODE_DATA_PREMANAGED_VERSION ) ) - { - DefaultRepositorySystemSession newSession = new DefaultRepositorySystemSession( session ); - newSession.setConfigProperty( NODE_DATA_PREMANAGED_VERSION, true ); + + if (Boolean.TRUE != session.getConfigProperties().get(NODE_DATA_PREMANAGED_VERSION)) { + DefaultRepositorySystemSession newSession = new DefaultRepositorySystemSession(session); + newSession.setConfigProperty(NODE_DATA_PREMANAGED_VERSION, true); session = newSession; - } + } final DependencyResolutionRequest request = new DefaultDependencyResolutionRequest(); - request.setMavenProject( project ); - request.setRepositorySession( session ); + request.setMavenProject(project); + request.setRepositorySession(session); // only download the poms, not the artifacts - DependencyFilter collectFilter = ( node, parents ) -> false; - request.setResolutionFilter( collectFilter ); + DependencyFilter collectFilter = (node, parents) -> false; + request.setResolutionFilter(collectFilter); - final DependencyResolutionResult result = resolveDependencies( request ); + final DependencyResolutionResult result = resolveDependencies(request); org.eclipse.aether.graph.DependencyNode graph = result.getDependencyGraph(); - return buildDependencyNode( null, graph, project.getArtifact(), filter ); + return buildDependencyNode(null, graph, project.getArtifact(), filter); } - private DependencyResolutionResult resolveDependencies( DependencyResolutionRequest request ) - throws DependencyGraphBuilderException - { - try - { - return resolver.resolve( request ); - } - catch ( DependencyResolutionException e ) - { - throw new DependencyGraphBuilderException( "Could not resolve following dependencies: " - + e.getResult().getUnresolvedDependencies(), e ); + private DependencyResolutionResult resolveDependencies(DependencyResolutionRequest request) + throws DependencyGraphBuilderException { + try { + return resolver.resolve(request); + } catch (DependencyResolutionException e) { + throw new DependencyGraphBuilderException( + "Could not resolve following dependencies: " + e.getResult().getUnresolvedDependencies(), e); } } - private Artifact getDependencyArtifact( Dependency dep ) - { + private Artifact getDependencyArtifact(Dependency dep) { org.eclipse.aether.artifact.Artifact artifact = dep.getArtifact(); - Artifact mavenArtifact = RepositoryUtils.toArtifact( artifact ); + Artifact mavenArtifact = RepositoryUtils.toArtifact(artifact); - mavenArtifact.setScope( dep.getScope() ); - mavenArtifact.setOptional( dep.isOptional() ); + mavenArtifact.setScope(dep.getScope()); + mavenArtifact.setOptional(dep.isOptional()); return mavenArtifact; } - private DependencyNode buildDependencyNode( DependencyNode parent, org.eclipse.aether.graph.DependencyNode node, - Artifact artifact, ArtifactFilter filter ) - { - String premanagedVersion = DependencyManagerUtils.getPremanagedVersion( node ); - String premanagedScope = DependencyManagerUtils.getPremanagedScope( node ); + private DependencyNode buildDependencyNode( + DependencyNode parent, + org.eclipse.aether.graph.DependencyNode node, + Artifact artifact, + ArtifactFilter filter) { + String premanagedVersion = DependencyManagerUtils.getPremanagedVersion(node); + String premanagedScope = DependencyManagerUtils.getPremanagedScope(node); List<org.apache.maven.model.Exclusion> exclusions = null; Boolean optional = null; - if ( node.getDependency() != null ) - { - exclusions = new ArrayList<>( node.getDependency().getExclusions().size() ); - for ( Exclusion exclusion : node.getDependency().getExclusions() ) - { + if (node.getDependency() != null) { + exclusions = new ArrayList<>(node.getDependency().getExclusions().size()); + for (Exclusion exclusion : node.getDependency().getExclusions()) { org.apache.maven.model.Exclusion modelExclusion = new org.apache.maven.model.Exclusion(); - modelExclusion.setGroupId( exclusion.getGroupId() ); - modelExclusion.setArtifactId( exclusion.getArtifactId() ); - exclusions.add( modelExclusion ); + modelExclusion.setGroupId(exclusion.getGroupId()); + modelExclusion.setArtifactId(exclusion.getArtifactId()); + exclusions.add(modelExclusion); } } - DefaultDependencyNode current = - new DefaultDependencyNode( parent, artifact, premanagedVersion, premanagedScope, - getVersionSelectedFromRange( node.getVersionConstraint() ), - optional, exclusions ); - - List<DependencyNode> nodes = new ArrayList<>( node.getChildren().size() ); - for ( org.eclipse.aether.graph.DependencyNode child : node.getChildren() ) - { - Artifact childArtifact = getDependencyArtifact( child.getDependency() ); - - if ( ( filter == null ) || filter.include( childArtifact ) ) - { - nodes.add( buildDependencyNode( current, child, childArtifact, filter ) ); + DefaultDependencyNode current = new DefaultDependencyNode( + parent, + artifact, + premanagedVersion, + premanagedScope, + getVersionSelectedFromRange(node.getVersionConstraint()), + optional, + exclusions); + + List<DependencyNode> nodes = new ArrayList<>(node.getChildren().size()); + for (org.eclipse.aether.graph.DependencyNode child : node.getChildren()) { + Artifact childArtifact = getDependencyArtifact(child.getDependency()); + + if ((filter == null) || filter.include(childArtifact)) { + nodes.add(buildDependencyNode(current, child, childArtifact, filter)); } } - current.setChildren( Collections.unmodifiableList( nodes ) ); + current.setChildren(Collections.unmodifiableList(nodes)); return current; } - private String getVersionSelectedFromRange( VersionConstraint constraint ) - { - if ( ( constraint == null ) || ( constraint.getVersion() != null ) ) - { + private String getVersionSelectedFromRange(VersionConstraint constraint) { + if ((constraint == null) || (constraint.getVersion() != null)) { return null; } diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyNode.java b/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyNode.java index 218bea1..1c2d712 100644 --- a/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyNode.java +++ b/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyNode.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.dependency.graph.internal; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ package org.apache.maven.shared.dependency.graph.internal; * "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 + * 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 @@ -18,6 +16,7 @@ package org.apache.maven.shared.dependency.graph.internal; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.dependency.graph.internal; import java.util.List; @@ -29,10 +28,9 @@ import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor; /** * Default implementation of a DependencyNode. */ -public class DefaultDependencyNode implements DependencyNode -{ +public class DefaultDependencyNode implements DependencyNode { private final Artifact artifact; - + private final DependencyNode parent; private final String premanagedVersion; @@ -56,9 +54,12 @@ public class DefaultDependencyNode implements DependencyNode * @param premanagedScope the premanaged scope, may be {@code null}. * @param versionConstraint the version constraint, may be {@code null.} */ - public DefaultDependencyNode( DependencyNode parent, Artifact artifact, String premanagedVersion, - String premanagedScope, String versionConstraint ) - { + public DefaultDependencyNode( + DependencyNode parent, + Artifact artifact, + String premanagedVersion, + String premanagedScope, + String versionConstraint) { this.parent = parent; this.artifact = artifact; this.premanagedVersion = premanagedVersion; @@ -66,10 +67,14 @@ public class DefaultDependencyNode implements DependencyNode this.versionConstraint = versionConstraint; } - public DefaultDependencyNode( DependencyNode parent, Artifact artifact, String premanagedVersion, - String premanagedScope, String versionConstraint, Boolean optional, - List<Exclusion> exclusions ) - { + public DefaultDependencyNode( + DependencyNode parent, + Artifact artifact, + String premanagedVersion, + String premanagedScope, + String versionConstraint, + Boolean optional, + List<Exclusion> exclusions) { this.parent = parent; this.artifact = artifact; this.premanagedVersion = premanagedVersion; @@ -78,10 +83,9 @@ public class DefaultDependencyNode implements DependencyNode this.optional = optional; this.exclusions = exclusions; } - + // user to refer to winner - public DefaultDependencyNode( Artifact artifact ) - { + public DefaultDependencyNode(Artifact artifact) { this.artifact = artifact; this.parent = null; this.premanagedScope = null; @@ -91,34 +95,29 @@ public class DefaultDependencyNode implements DependencyNode /** * Applies the specified dependency node visitor to this dependency node and its children. - * + * * @param visitor the dependency node visitor to use * @return the visitor result of ending the visit to this node * @since 1.1 */ @Override - public boolean accept( DependencyNodeVisitor visitor ) - { - if ( visitor.visit( this ) ) - { - for ( DependencyNode child : getChildren() ) - { - if ( !child.accept( visitor ) ) - { + public boolean accept(DependencyNodeVisitor visitor) { + if (visitor.visit(this)) { + for (DependencyNode child : getChildren()) { + if (!child.accept(visitor)) { break; } } } - return visitor.endVisit( this ); + return visitor.endVisit(this); } /** * @return Artifact for this DependencyNode. */ @Override - public Artifact getArtifact() - { + public Artifact getArtifact() { return artifact; } @@ -126,8 +125,7 @@ public class DefaultDependencyNode implements DependencyNode * * @param children List of DependencyNode to set as child nodes. */ - public void setChildren( List<DependencyNode> children ) - { + public void setChildren(List<DependencyNode> children) { this.children = children; } @@ -135,8 +133,7 @@ public class DefaultDependencyNode implements DependencyNode * @return List of child nodes for this DependencyNode. */ @Override - public List<DependencyNode> getChildren() - { + public List<DependencyNode> getChildren() { return children; } @@ -144,38 +141,32 @@ public class DefaultDependencyNode implements DependencyNode * @return Parent of this DependencyNode. */ @Override - public DependencyNode getParent() - { + public DependencyNode getParent() { return parent; } @Override - public String getPremanagedVersion() - { + public String getPremanagedVersion() { return premanagedVersion; } @Override - public String getPremanagedScope() - { + public String getPremanagedScope() { return premanagedScope; } @Override - public String getVersionConstraint() - { + public String getVersionConstraint() { return versionConstraint; } @Override - public Boolean getOptional() - { + public Boolean getOptional() { return optional; } @Override - public List<Exclusion> getExclusions() - { + public List<Exclusion> getExclusions() { return exclusions; } @@ -183,8 +174,7 @@ public class DefaultDependencyNode implements DependencyNode * @return Stringified representation of this DependencyNode. */ @Override - public String toNodeString() - { - return String.valueOf( artifact ); + public String toNodeString() { + return String.valueOf(artifact); } } diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/internal/DirectScopeDependencySelector.java b/src/main/java/org/apache/maven/shared/dependency/graph/internal/DirectScopeDependencySelector.java index 2e6fc0a..63e2df5 100644 --- a/src/main/java/org/apache/maven/shared/dependency/graph/internal/DirectScopeDependencySelector.java +++ b/src/main/java/org/apache/maven/shared/dependency/graph/internal/DirectScopeDependencySelector.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.dependency.graph.internal; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ package org.apache.maven.shared.dependency.graph.internal; * "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 + * 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 @@ -18,6 +16,7 @@ package org.apache.maven.shared.dependency.graph.internal; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.dependency.graph.internal; import org.eclipse.aether.collection.DependencyCollectionContext; import org.eclipse.aether.collection.DependencySelector; @@ -26,29 +25,24 @@ import org.eclipse.aether.graph.Dependency; /** * A dependency selector that excludes dependencies of an specific Scope which occur beyond level one of the dependency * graph. - * + * * @see Dependency#getScope() * @author Gabriel Belingueres * @since 3.1.0 */ -public class DirectScopeDependencySelector - implements DependencySelector -{ +public class DirectScopeDependencySelector implements DependencySelector { private final String scope; private final int depth; - public DirectScopeDependencySelector( String scope ) - { - this( scope, 0 ); + public DirectScopeDependencySelector(String scope) { + this(scope, 0); } - private DirectScopeDependencySelector( String scope, int depth ) - { - if ( scope == null ) - { - throw new IllegalArgumentException( "scope is null!" ); + private DirectScopeDependencySelector(String scope, int depth) { + if (scope == null) { + throw new IllegalArgumentException("scope is null!"); } this.scope = scope; this.depth = depth; @@ -56,77 +50,63 @@ public class DirectScopeDependencySelector /** * Decides whether the specified dependency should be included in the dependency graph. - * + * * @param dependency The dependency to check, must not be {@code null}. * @return {@code false} if the dependency should be excluded from the children of the current node, {@code true} * otherwise. */ @Override - public boolean selectDependency( Dependency dependency ) - { - return depth < 2 || !scope.equals( dependency.getScope() ); + public boolean selectDependency(Dependency dependency) { + return depth < 2 || !scope.equals(dependency.getScope()); } /** * Derives a dependency selector for the specified collection context. When calculating the child selector, * implementors are strongly advised to simply return the current instance if nothing changed to help save memory. - * + * * @param context The dependency collection context, must not be {@code null}. * @return The dependency selector for the target node, must not be {@code null}. */ @Override - public DependencySelector deriveChildSelector( DependencyCollectionContext context ) - { - if ( depth >= 2 ) - { + public DependencySelector deriveChildSelector(DependencyCollectionContext context) { + if (depth >= 2) { return this; } - return new DirectScopeDependencySelector( scope, depth + 1 ); + return new DirectScopeDependencySelector(scope, depth + 1); } @Override - public int hashCode() - { + public int hashCode() { final int prime = 31; int result = 1; result = prime * result + depth; - result = prime * result + ( ( scope == null ) ? 0 : scope.hashCode() ); + result = prime * result + ((scope == null) ? 0 : scope.hashCode()); return result; } @Override - public boolean equals( Object obj ) - { - if ( this == obj ) - { + public boolean equals(Object obj) { + if (this == obj) { return true; } - if ( obj == null ) - { + if (obj == null) { return false; } - if ( getClass() != obj.getClass() ) - { + if (getClass() != obj.getClass()) { return false; } DirectScopeDependencySelector other = (DirectScopeDependencySelector) obj; - if ( depth != other.depth ) - { + if (depth != other.depth) { return false; } - if ( scope == null ) - { - if ( other.scope != null ) - { + if (scope == null) { + if (other.scope != null) { return false; } - } - else if ( !scope.equals( other.scope ) ) - { + } else if (!scope.equals(other.scope)) { return false; } return true; } - } diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/internal/VerboseDependencyNode.java b/src/main/java/org/apache/maven/shared/dependency/graph/internal/VerboseDependencyNode.java index d13b623..b96d3e8 100644 --- a/src/main/java/org/apache/maven/shared/dependency/graph/internal/VerboseDependencyNode.java +++ b/src/main/java/org/apache/maven/shared/dependency/graph/internal/VerboseDependencyNode.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.dependency.graph.internal; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ package org.apache.maven.shared.dependency.graph.internal; * "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 + * 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 @@ -18,6 +16,7 @@ package org.apache.maven.shared.dependency.graph.internal; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.dependency.graph.internal; import java.util.List; @@ -25,81 +24,73 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.model.Exclusion; import org.apache.maven.shared.dependency.graph.DependencyNode; -class VerboseDependencyNode - extends DefaultDependencyNode -{ +class VerboseDependencyNode extends DefaultDependencyNode { private final ConflictData data; - - VerboseDependencyNode( DependencyNode parent, Artifact artifact, String premanagedVersion, - String premanagedScope, String versionConstraint, Boolean optional, - List<Exclusion> exclusions, ConflictData data ) - { - super( parent, artifact, premanagedVersion, premanagedScope, versionConstraint, optional, exclusions ); + + VerboseDependencyNode( + DependencyNode parent, + Artifact artifact, + String premanagedVersion, + String premanagedScope, + String versionConstraint, + Boolean optional, + List<Exclusion> exclusions, + ConflictData data) { + super(parent, artifact, premanagedVersion, premanagedScope, versionConstraint, optional, exclusions); this.data = data; } - + @Override - public String toNodeString() - { + public String toNodeString() { StringBuilder buffer = new StringBuilder(); - boolean included = ( data.getWinnerVersion() == null ); + boolean included = (data.getWinnerVersion() == null); - if ( !included ) - { - buffer.append( '(' ); + if (!included) { + buffer.append('('); } - buffer.append( getArtifact() ); + buffer.append(getArtifact()); - ItemAppender appender = new ItemAppender( buffer, included ? " (" : " - ", "; ", included ? ")" : "" ); + ItemAppender appender = new ItemAppender(buffer, included ? " (" : " - ", "; ", included ? ")" : ""); - if ( getPremanagedVersion() != null ) - { - appender.append( "version managed from ", getPremanagedVersion() ); + if (getPremanagedVersion() != null) { + appender.append("version managed from ", getPremanagedVersion()); } - if ( getPremanagedScope() != null ) - { - appender.append( "scope managed from ", getPremanagedScope() ); + if (getPremanagedScope() != null) { + appender.append("scope managed from ", getPremanagedScope()); } - if ( data.getOriginalScope() != null ) - { - appender.append( "scope updated from ", data.getOriginalScope() ); + if (data.getOriginalScope() != null) { + appender.append("scope updated from ", data.getOriginalScope()); } - if ( data.getIgnoredScope() != null ) - { - appender.append( "scope not updated to ", data.getIgnoredScope() ); + if (data.getIgnoredScope() != null) { + appender.append("scope not updated to ", data.getIgnoredScope()); } -// if ( getVersionSelectedFromRange() != null ) -// { -// appender.append( "version selected from range ", getVersionSelectedFromRange().toString() ); -// appender.append( "available versions ", getAvailableVersions().toString() ); -// } - - if ( !included ) - { - String winnerVersion = data.getWinnerVersion(); - if ( winnerVersion.equals( getArtifact().getVersion() ) ) - { - appender.append( "omitted for duplicate" ); - } - else - { - appender.append( "omitted for conflict with ", winnerVersion ); + // if ( getVersionSelectedFromRange() != null ) + // { + // appender.append( "version selected from range ", getVersionSelectedFromRange().toString() ); + // appender.append( "available versions ", getAvailableVersions().toString() ); + // } + + if (!included) { + String winnerVersion = data.getWinnerVersion(); + if (winnerVersion.equals(getArtifact().getVersion())) { + appender.append("omitted for duplicate"); + } else { + appender.append("omitted for conflict with ", winnerVersion); } } appender.flush(); - if ( !included ) - { - buffer.append( ')' ); + if (!included) { + buffer.append(')'); } return buffer.toString(); @@ -108,8 +99,7 @@ class VerboseDependencyNode /** * Utility class to concatenate a number of parameters with separator tokens. */ - private static class ItemAppender - { + private static class ItemAppender { private StringBuilder buffer; private String startToken; @@ -120,8 +110,7 @@ class VerboseDependencyNode private boolean appended; - ItemAppender( StringBuilder buffer, String startToken, String separatorToken, String endToken ) - { + ItemAppender(StringBuilder buffer, String startToken, String separatorToken, String endToken) { this.buffer = buffer; this.startToken = startToken; this.separatorToken = separatorToken; @@ -130,37 +119,32 @@ class VerboseDependencyNode appended = false; } - public ItemAppender append( String item1 ) - { + public ItemAppender append(String item1) { appendToken(); - buffer.append( item1 ); + buffer.append(item1); return this; } - public ItemAppender append( String item1, String item2 ) - { + public ItemAppender append(String item1, String item2) { appendToken(); - buffer.append( item1 ).append( item2 ); + buffer.append(item1).append(item2); return this; } - public void flush() - { - if ( appended ) - { - buffer.append( endToken ); + public void flush() { + if (appended) { + buffer.append(endToken); appended = false; } } - private void appendToken() - { - buffer.append( appended ? separatorToken : startToken ); + private void appendToken() { + buffer.append(appended ? separatorToken : startToken); appended = true; } diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/internal/VerboseJavaScopeSelector.java b/src/main/java/org/apache/maven/shared/dependency/graph/internal/VerboseJavaScopeSelector.java index b5cd5ee..7cf2194 100644 --- a/src/main/java/org/apache/maven/shared/dependency/graph/internal/VerboseJavaScopeSelector.java +++ b/src/main/java/org/apache/maven/shared/dependency/graph/internal/VerboseJavaScopeSelector.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.dependency.graph.internal; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ package org.apache.maven.shared.dependency.graph.internal; * "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 + * 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 @@ -18,48 +16,43 @@ package org.apache.maven.shared.dependency.graph.internal; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.dependency.graph.internal; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; import org.eclipse.aether.RepositoryException; import org.eclipse.aether.util.graph.transformer.ConflictResolver.ConflictContext; import org.eclipse.aether.util.graph.transformer.ConflictResolver.ScopeSelector; import org.eclipse.aether.util.graph.transformer.JavaScopeSelector; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; - /** - * A JavaScopeSelector that keeps track of reduced scopes - * + * A JavaScopeSelector that keeps track of reduced scopes. */ -public class VerboseJavaScopeSelector extends ScopeSelector -{ +public class VerboseJavaScopeSelector extends ScopeSelector { public static final String REDUCED_SCOPE = "REDUCED_SCOPE"; - + private final ScopeSelector scopeSelector = new JavaScopeSelector(); @Override - public void selectScope( ConflictContext context ) - throws RepositoryException - { - scopeSelector.selectScope( context ); - + public void selectScope(ConflictContext context) throws RepositoryException { + scopeSelector.selectScope(context); + context.getItems().stream() - .flatMap( i -> i.getScopes().stream() ) - .distinct() - .max( new ScopeComparator() ) - .filter( s -> s != context.getScope() ) - .ifPresent( s -> context.getWinner().getNode().setData( REDUCED_SCOPE, s ) ); + .flatMap(i -> i.getScopes().stream()) + .distinct() + .max(new ScopeComparator()) + .filter(s -> s != context.getScope()) + .ifPresent(s -> context.getWinner().getNode().setData(REDUCED_SCOPE, s)); } - - static class ScopeComparator implements Comparator<String> - { - List<String> orderedScopes = Arrays.asList( "compile", "runtime", "provided", "test" ); + + static class ScopeComparator implements Comparator<String> { + List<String> orderedScopes = Arrays.asList("compile", "runtime", "provided", "test"); @Override - public int compare( String lhs, String rhs ) - { - return orderedScopes.indexOf( rhs ) - orderedScopes.indexOf( lhs ); + public int compare(String lhs, String rhs) { + return orderedScopes.indexOf(rhs) - orderedScopes.indexOf(lhs); } - } + } } diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/traversal/BuildingDependencyNodeVisitor.java b/src/main/java/org/apache/maven/shared/dependency/graph/traversal/BuildingDependencyNodeVisitor.java index 159e9e9..e2f3537 100644 --- a/src/main/java/org/apache/maven/shared/dependency/graph/traversal/BuildingDependencyNodeVisitor.java +++ b/src/main/java/org/apache/maven/shared/dependency/graph/traversal/BuildingDependencyNodeVisitor.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.dependency.graph.traversal; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ package org.apache.maven.shared.dependency.graph.traversal; * "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 + * 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 @@ -18,6 +16,7 @@ package org.apache.maven.shared.dependency.graph.traversal; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.dependency.graph.traversal; import java.util.ArrayList; import java.util.Stack; @@ -28,12 +27,10 @@ import org.apache.maven.shared.dependency.graph.internal.DefaultDependencyNode; /** * A dependency node visitor that clones visited nodes into a new dependency tree. This can be used in conjunction with * a dependency node filter to construct subtrees. - * + * * @author <a href="mailto:[email protected]">Mark Hobson</a> */ -public class BuildingDependencyNodeVisitor - implements DependencyNodeVisitor -{ +public class BuildingDependencyNodeVisitor implements DependencyNodeVisitor { // fields ----------------------------------------------------------------- /** @@ -56,20 +53,18 @@ public class BuildingDependencyNodeVisitor /** * Creates a dependency node visitor that clones visited nodes into a new dependency tree. */ - public BuildingDependencyNodeVisitor() - { - this( null ); + public BuildingDependencyNodeVisitor() { + this(null); } /** * Creates a dependency node visitor that clones visited nodes into a new dependency tree, and then applies the * specified dependency node visitor on the resultant dependency tree. - * + * * @param visitor the dependency node visitor to apply on the resultant dependency tree, or <code>null</code> for * none */ - public BuildingDependencyNodeVisitor( DependencyNodeVisitor visitor ) - { + public BuildingDependencyNodeVisitor(DependencyNodeVisitor visitor) { this.visitor = visitor; parentNodes = new Stack<>(); @@ -81,27 +76,26 @@ public class BuildingDependencyNodeVisitor * {@inheritDoc} */ @Override - public boolean visit( DependencyNode node ) - { + public boolean visit(DependencyNode node) { // clone the node - DefaultDependencyNode newNode = - new DefaultDependencyNode( parentNodes.isEmpty() ? null : parentNodes.peek(), node.getArtifact(), - node.getPremanagedVersion(), node.getPremanagedScope(), - node.getVersionConstraint(), - node.getOptional(), node.getExclusions() ); - newNode.setChildren( new ArrayList<>() ); - - if ( parentNodes.empty() ) - { + DefaultDependencyNode newNode = new DefaultDependencyNode( + parentNodes.isEmpty() ? null : parentNodes.peek(), + node.getArtifact(), + node.getPremanagedVersion(), + node.getPremanagedScope(), + node.getVersionConstraint(), + node.getOptional(), + node.getExclusions()); + newNode.setChildren(new ArrayList<>()); + + if (parentNodes.empty()) { rootNode = newNode; - } - else - { + } else { DependencyNode parentNode = parentNodes.peek(); - parentNode.getChildren().add( newNode ); + parentNode.getChildren().add(newNode); } - parentNodes.push( newNode ); + parentNodes.push(newNode); return true; } @@ -110,14 +104,12 @@ public class BuildingDependencyNodeVisitor * {@inheritDoc} */ @Override - public boolean endVisit( DependencyNode node ) - { + public boolean endVisit(DependencyNode node) { parentNodes.pop(); // apply the visitor to the resultant tree on the last visit - if ( parentNodes.empty() && visitor != null ) - { - rootNode.accept( visitor ); + if (parentNodes.empty() && visitor != null) { + rootNode.accept(visitor); } return true; @@ -127,21 +119,19 @@ public class BuildingDependencyNodeVisitor /** * Gets the dependency node visitor that this visitor applies on the resultant dependency tree. - * + * * @return the dependency node visitor, or <code>null</code> for none */ - public DependencyNodeVisitor getDependencyNodeVisitor() - { + public DependencyNodeVisitor getDependencyNodeVisitor() { return visitor; } /** * Gets the root node of the resultant dependency tree constructed by this visitor. - * + * * @return the root node, or <code>null</code> if the source tree has not yet been visited */ - public DependencyNode getDependencyTree() - { + public DependencyNode getDependencyTree() { return rootNode; } } diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/traversal/CollectingDependencyNodeVisitor.java b/src/main/java/org/apache/maven/shared/dependency/graph/traversal/CollectingDependencyNodeVisitor.java index 129e2d5..49fa9c2 100644 --- a/src/main/java/org/apache/maven/shared/dependency/graph/traversal/CollectingDependencyNodeVisitor.java +++ b/src/main/java/org/apache/maven/shared/dependency/graph/traversal/CollectingDependencyNodeVisitor.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.dependency.graph.traversal; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ package org.apache.maven.shared.dependency.graph.traversal; * "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 + * 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 @@ -18,6 +16,7 @@ package org.apache.maven.shared.dependency.graph.traversal; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.dependency.graph.traversal; import java.util.ArrayList; import java.util.Collections; @@ -27,14 +26,12 @@ import org.apache.maven.shared.dependency.graph.DependencyNode; /** * A dependency node visitor that collects visited nodes for further processing. - * + * * @author <a href="mailto:[email protected]">Mark Hobson</a> * @version $Id$ * @since 1.1 */ -public class CollectingDependencyNodeVisitor - implements DependencyNodeVisitor -{ +public class CollectingDependencyNodeVisitor implements DependencyNodeVisitor { // fields ----------------------------------------------------------------- /** @@ -47,8 +44,7 @@ public class CollectingDependencyNodeVisitor /** * Creates a dependency node visitor that collects visited nodes for further processing. */ - public CollectingDependencyNodeVisitor() - { + public CollectingDependencyNodeVisitor() { nodes = new ArrayList<>(); } @@ -58,10 +54,9 @@ public class CollectingDependencyNodeVisitor * {@inheritDoc} */ @Override - public boolean visit( DependencyNode node ) - { + public boolean visit(DependencyNode node) { // collect node - nodes.add( node ); + nodes.add(node); return true; } @@ -70,8 +65,7 @@ public class CollectingDependencyNodeVisitor * {@inheritDoc} */ @Override - public boolean endVisit( DependencyNode node ) - { + public boolean endVisit(DependencyNode node) { return true; } @@ -79,11 +73,10 @@ public class CollectingDependencyNodeVisitor /** * Gets the list of collected dependency nodes. - * + * * @return the list of collected dependency nodes */ - public List<DependencyNode> getNodes() - { - return Collections.unmodifiableList( nodes ); + public List<DependencyNode> getNodes() { + return Collections.unmodifiableList(nodes); } } diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/traversal/DependencyNodeVisitor.java b/src/main/java/org/apache/maven/shared/dependency/graph/traversal/DependencyNodeVisitor.java index f50a8ae..550d848 100644 --- a/src/main/java/org/apache/maven/shared/dependency/graph/traversal/DependencyNodeVisitor.java +++ b/src/main/java/org/apache/maven/shared/dependency/graph/traversal/DependencyNodeVisitor.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.dependency.graph.traversal; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ package org.apache.maven.shared.dependency.graph.traversal; * "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 + * 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 @@ -18,33 +16,33 @@ package org.apache.maven.shared.dependency.graph.traversal; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.dependency.graph.traversal; import org.apache.maven.shared.dependency.graph.DependencyNode; /** * Defines a hierarchical visitor for processing dependency node trees. - * + * * @author <a href="mailto:[email protected]">Mark Hobson</a> * @version $Id$ * @since 1.1 */ -public interface DependencyNodeVisitor -{ +public interface DependencyNodeVisitor { /** * Starts the visit to the specified dependency node. - * + * * @param node the dependency node to visit * @return <code>true</code> to visit the specified dependency node's children, <code>false</code> to skip the * specified dependency node's children and proceed to its next sibling */ - boolean visit( DependencyNode node ); + boolean visit(DependencyNode node); /** * Ends the visit to to the specified dependency node. - * + * * @param node the dependency node to visit * @return <code>true</code> to visit the specified dependency node's next sibling, <code>false</code> to skip the * specified dependency node's next siblings and proceed to its parent */ - boolean endVisit( DependencyNode node ); + boolean endVisit(DependencyNode node); } diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/traversal/FilteringDependencyNodeVisitor.java b/src/main/java/org/apache/maven/shared/dependency/graph/traversal/FilteringDependencyNodeVisitor.java index 6c11fa6..e530344 100644 --- a/src/main/java/org/apache/maven/shared/dependency/graph/traversal/FilteringDependencyNodeVisitor.java +++ b/src/main/java/org/apache/maven/shared/dependency/graph/traversal/FilteringDependencyNodeVisitor.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.dependency.graph.traversal; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ package org.apache.maven.shared.dependency.graph.traversal; * "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 + * 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 @@ -18,20 +16,19 @@ package org.apache.maven.shared.dependency.graph.traversal; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.dependency.graph.traversal; import org.apache.maven.shared.dependency.graph.DependencyNode; import org.apache.maven.shared.dependency.graph.filter.DependencyNodeFilter; /** * A dependency node visitor that filters nodes and delegates to another visitor. - * + * * @author <a href="mailto:[email protected]">Mark Hobson</a> * @version $Id$ * @since 1.1 */ -public class FilteringDependencyNodeVisitor - implements DependencyNodeVisitor -{ +public class FilteringDependencyNodeVisitor implements DependencyNodeVisitor { // fields ----------------------------------------------------------------- /** @@ -49,12 +46,11 @@ public class FilteringDependencyNodeVisitor /** * Creates a dependency node visitor that delegates nodes that are accepted by the specified filter to the specified * visitor. - * + * * @param visitor the dependency node visitor to delegate to * @param filter the dependency node filter to apply before delegation */ - public FilteringDependencyNodeVisitor( DependencyNodeVisitor visitor, DependencyNodeFilter filter ) - { + public FilteringDependencyNodeVisitor(DependencyNodeVisitor visitor, DependencyNodeFilter filter) { this.visitor = visitor; this.filter = filter; } @@ -65,16 +61,12 @@ public class FilteringDependencyNodeVisitor * {@inheritDoc} */ @Override - public boolean visit( DependencyNode node ) - { + public boolean visit(DependencyNode node) { boolean visit; - if ( filter.accept( node ) ) - { - visit = visitor.visit( node ); - } - else - { + if (filter.accept(node)) { + visit = visitor.visit(node); + } else { visit = true; } @@ -85,16 +77,12 @@ public class FilteringDependencyNodeVisitor * {@inheritDoc} */ @Override - public boolean endVisit( DependencyNode node ) - { + public boolean endVisit(DependencyNode node) { boolean visit; - if ( filter.accept( node ) ) - { - visit = visitor.endVisit( node ); - } - else - { + if (filter.accept(node)) { + visit = visitor.endVisit(node); + } else { visit = true; } @@ -105,21 +93,19 @@ public class FilteringDependencyNodeVisitor /** * Gets the dependency node visitor that this visitor delegates to. - * + * * @return the dependency node visitor */ - public DependencyNodeVisitor getDependencyNodeVisitor() - { + public DependencyNodeVisitor getDependencyNodeVisitor() { return visitor; } /** * Gets the dependency node filter that this visitor applies before delegation. - * + * * @return the dependency node filter */ - public DependencyNodeFilter getDependencyNodeFilter() - { + public DependencyNodeFilter getDependencyNodeFilter() { return filter; } } diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/traversal/SerializingDependencyNodeVisitor.java b/src/main/java/org/apache/maven/shared/dependency/graph/traversal/SerializingDependencyNodeVisitor.java index 526aff0..ce4f321 100644 --- a/src/main/java/org/apache/maven/shared/dependency/graph/traversal/SerializingDependencyNodeVisitor.java +++ b/src/main/java/org/apache/maven/shared/dependency/graph/traversal/SerializingDependencyNodeVisitor.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.dependency.graph.traversal; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ package org.apache.maven.shared.dependency.graph.traversal; * "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 + * 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 @@ -18,6 +16,7 @@ package org.apache.maven.shared.dependency.graph.traversal; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.dependency.graph.traversal; import java.io.PrintWriter; import java.io.Writer; @@ -27,19 +26,16 @@ import org.apache.maven.shared.dependency.graph.DependencyNode; /** * A dependency node visitor that serializes visited nodes to a writer. - * + * * @author <a href="mailto:[email protected]">Mark Hobson</a> */ -public class SerializingDependencyNodeVisitor - implements DependencyNodeVisitor -{ +public class SerializingDependencyNodeVisitor implements DependencyNodeVisitor { // classes ---------------------------------------------------------------- /** * Provides tokens to use when serializing the dependency graph. */ - public static class GraphTokens - { + public static class GraphTokens { private final String nodeIndent; private final String lastNodeIndent; @@ -48,21 +44,18 @@ public class SerializingDependencyNodeVisitor private final String lastFillIndent; - public GraphTokens( String nodeIndent, String lastNodeIndent, String fillIndent, String lastFillIndent ) - { + public GraphTokens(String nodeIndent, String lastNodeIndent, String fillIndent, String lastFillIndent) { this.nodeIndent = nodeIndent; this.lastNodeIndent = lastNodeIndent; this.fillIndent = fillIndent; this.lastFillIndent = lastFillIndent; } - public String getNodeIndent( boolean last ) - { + public String getNodeIndent(boolean last) { return last ? lastNodeIndent : nodeIndent; } - public String getFillIndent( boolean last ) - { + public String getFillIndent(boolean last) { return last ? lastFillIndent : fillIndent; } } @@ -72,18 +65,18 @@ public class SerializingDependencyNodeVisitor /** * Whitespace tokens to use when outputing the dependency graph. */ - public static final GraphTokens WHITESPACE_TOKENS = new GraphTokens( " ", " ", " ", " " ); + public static final GraphTokens WHITESPACE_TOKENS = new GraphTokens(" ", " ", " ", " "); /** * The standard ASCII tokens to use when outputing the dependency graph. */ - public static final GraphTokens STANDARD_TOKENS = new GraphTokens( "+- ", "\\- ", "| ", " " ); + public static final GraphTokens STANDARD_TOKENS = new GraphTokens("+- ", "\\- ", "| ", " "); /** * The extended ASCII tokens to use when outputing the dependency graph. */ - public static final GraphTokens EXTENDED_TOKENS = new GraphTokens( "\u251C\u2500 ", "\u2514\u2500 ", "\u2502 ", - " " ); + public static final GraphTokens EXTENDED_TOKENS = + new GraphTokens("\u251C\u2500 ", "\u2514\u2500 ", "\u2502 ", " "); // fields ----------------------------------------------------------------- @@ -106,30 +99,25 @@ public class SerializingDependencyNodeVisitor /** * Creates a dependency node visitor that serializes visited nodes to the specified writer using whitespace tokens. - * + * * @param writer the writer to serialize to */ - public SerializingDependencyNodeVisitor( Writer writer ) - { - this( writer, WHITESPACE_TOKENS ); + public SerializingDependencyNodeVisitor(Writer writer) { + this(writer, WHITESPACE_TOKENS); } /** * Creates a dependency node visitor that serializes visited nodes to the specified writer using the specified * tokens. - * + * * @param writer the writer to serialize to * @param tokens the tokens to use when serializing the dependency graph */ - public SerializingDependencyNodeVisitor( Writer writer, GraphTokens tokens ) - { - if ( writer instanceof PrintWriter ) - { + public SerializingDependencyNodeVisitor(Writer writer, GraphTokens tokens) { + if (writer instanceof PrintWriter) { this.writer = (PrintWriter) writer; - } - else - { - this.writer = new PrintWriter( writer, true ); + } else { + this.writer = new PrintWriter(writer, true); } this.tokens = tokens; @@ -143,11 +131,10 @@ public class SerializingDependencyNodeVisitor * {@inheritDoc} */ @Override - public boolean visit( DependencyNode node ) - { - indent( node ); + public boolean visit(DependencyNode node) { + indent(node); - writer.println( node.toNodeString() ); + writer.println(node.toNodeString()); depth++; @@ -158,8 +145,7 @@ public class SerializingDependencyNodeVisitor * {@inheritDoc} */ @Override - public boolean endVisit( DependencyNode node ) - { + public boolean endVisit(DependencyNode node) { depth--; return true; @@ -169,45 +155,38 @@ public class SerializingDependencyNodeVisitor /** * Writes the necessary tokens to indent the specified dependency node to this visitor's writer. - * + * * @param node the dependency node to indent */ - private void indent( DependencyNode node ) - { - for ( int i = 1; i < depth; i++ ) - { - writer.write( tokens.getFillIndent( isLast( node, i ) ) ); + private void indent(DependencyNode node) { + for (int i = 1; i < depth; i++) { + writer.write(tokens.getFillIndent(isLast(node, i))); } - if ( depth > 0 ) - { - writer.write( tokens.getNodeIndent( isLast( node ) ) ); + if (depth > 0) { + writer.write(tokens.getNodeIndent(isLast(node))); } } /** * Gets whether the specified dependency node is the last of its siblings. - * + * * @param node the dependency node to check * @return <code>true</code> if the specified dependency node is the last of its last siblings */ - private boolean isLast( DependencyNode node ) - { + private boolean isLast(DependencyNode node) { // TODO: remove node argument and calculate from visitor calls only DependencyNode parent = node.getParent(); boolean last; - if ( parent == null ) - { + if (parent == null) { last = true; - } - else - { + } else { List<DependencyNode> siblings = parent.getChildren(); - last = ( siblings.indexOf( node ) == siblings.size() - 1 ); + last = (siblings.indexOf(node) == siblings.size() - 1); } return last; @@ -215,22 +194,20 @@ public class SerializingDependencyNodeVisitor /** * Gets whether the specified dependency node ancestor is the last of its siblings. - * + * * @param node the dependency node whose ancestor to check * @param ancestorDepth the depth of the ancestor of the specified dependency node to check * @return <code>true</code> if the specified dependency node ancestor is the last of its siblings */ - private boolean isLast( DependencyNode node, int ancestorDepth ) - { + private boolean isLast(DependencyNode node, int ancestorDepth) { // TODO: remove node argument and calculate from visitor calls only int distance = depth - ancestorDepth; - while ( distance-- > 0 ) - { + while (distance-- > 0) { node = node.getParent(); } - return isLast( node ); + return isLast(node); } }
