elharo commented on a change in pull request #92:
URL:
https://github.com/apache/maven-dependency-plugin/pull/92#discussion_r465241721
##########
File path: pom.xml
##########
@@ -320,6 +311,27 @@ under the License.
</exclusion>
</exclusions>
</dependency>
+ <!-- VerboseGraphBuilder & VerboseSerializer -->
Review comment:
I wouldn't include this comment since these are not the artifacts where
those classes are found.
##########
File path: src/it/projects/tree-verbose-small/verify.bsh
##########
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.*;
+
+import org.codehaus.plexus.util.*;
+
+System.out.println( "Basedir is " + basedir );
+
+String actual = FileUtils.fileRead( new File( basedir, "target/tree.txt" ) );
+String expected = FileUtils.fileRead( new File( basedir, "expected.txt" ) );
+
+actual = actual.replaceAll( "[\n\r]+", "\n" );
+expected = expected.replaceAll( "[\n\r]+", "\n" );
+
+System.out.println( "Checking dependency tree..." );
+
+if ( !actual.equals( expected ) )
+{
+ throw new Exception( "Unexpected dependency tree" );
Review comment:
It helps if a test failure can indicate why it failed; in this case what
was expected and what did it actually get. Or if those two are large, then
what's the difference?
Might not be worth doing here unless there's a good utility method for this
we can call to calculate the diff.
##########
File path: src/it/projects/tree-verbose-small/verify.bsh
##########
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.*;
+
+import org.codehaus.plexus.util.*;
+
+System.out.println( "Basedir is " + basedir );
Review comment:
This might be something Maven commonly does in integration tests, but
the general principle is that a passing test generates no output.
##########
File path:
src/main/java/org/apache/maven/plugins/dependency/tree/verbose/RepositoryUtility.java
##########
@@ -0,0 +1,216 @@
+package org.apache.maven.plugins.dependency.tree.verbose;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
+import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.collection.DependencySelector;
+import org.eclipse.aether.repository.LocalRepository;
+import org.eclipse.aether.repository.RemoteRepository;
+import org.eclipse.aether.resolution.VersionRangeRequest;
+import org.eclipse.aether.resolution.VersionRangeResolutionException;
+import org.eclipse.aether.resolution.VersionRangeResult;
+import org.eclipse.aether.util.graph.selector.AndDependencySelector;
+import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector;
+import org.eclipse.aether.util.graph.selector.ScopeDependencySelector;
+import
org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransformer;
+import org.eclipse.aether.util.graph.transformer.JavaDependencyContextRefiner;
+import org.eclipse.aether.version.Version;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+
+/**
+ * Aether initialization. This uses Maven Resolver 1.4.2 or later. There are
many other versions of Aether
+ * from Sonatype and the Eclipse Project, but this is the current one.
+ */
+public final class RepositoryUtility
+{
+
+ public static final RemoteRepository CENTRAL = new
RemoteRepository.Builder( "central", "default",
+ "https://repo1.maven.org/maven2/" ).build();
+
+ // DefaultTransporterProvider.newTransporter checks these transporters
+ private static final Set<String> ALLOWED_REPOSITORY_URL_SCHEMES = new
HashSet<String>(
+ Arrays.asList( "file", "http", "https" ) );
+
+ private RepositoryUtility()
+ {
+ }
+
+ //@VisibleForTesting
+ static DefaultRepositorySystemSession
createDefaultRepositorySystemSession( RepositorySystem system )
+ {
+ DefaultRepositorySystemSession session =
MavenRepositorySystemUtils.newSession();
+ LocalRepository localRepository = new LocalRepository(
findLocalRepository() );
+ session.setLocalRepositoryManager( system.newLocalRepositoryManager(
session, localRepository ) );
+ return session;
+ }
+
+ /**
+ * Opens a new Maven repository session that looks for the local
repository in the customary ~/.m2 directory. If not
+ * found, it creates an initially empty repository in a temporary location.
+ */
+ public static DefaultRepositorySystemSession newSession( RepositorySystem
system )
+ {
+ DefaultRepositorySystemSession session =
createDefaultRepositorySystemSession( system );
+ return session;
+ }
+
+ /**
+ * Open a new Maven repository session for full dependency graph
resolution.
+ *
+ * @see {@link VerboseDependencyGraphBuilder}
+ */
+ static DefaultRepositorySystemSession newSessionForFullDependency(
RepositorySystem system )
+ {
+ // This combination of DependencySelector comes from the default
specified in
+ // `MavenRepositorySystemUtils.newSession`.
+ // LinkageChecker needs to include 'provided'-scope and optional
dependencies.
+ DependencySelector dependencySelector = new AndDependencySelector(
+ // ScopeDependencySelector takes exclusions. 'Provided' scope
is not here to avoid
+ // false positive in LinkageChecker.
+ new ScopeDependencySelector(), // removed "test" parameter
+ new ExclusionDependencySelector() );
+
+ return newSession( system, dependencySelector );
+ }
+
+ private static DefaultRepositorySystemSession newSession( RepositorySystem
system,
+
DependencySelector dependencySelector )
+ {
+ DefaultRepositorySystemSession session =
createDefaultRepositorySystemSession( system );
+ session.setDependencySelector( dependencySelector );
+
+ // By default, Maven's MavenRepositorySystemUtils.newSession() returns
a session with
+ // ChainedDependencyGraphTransformer(ConflictResolver(...),
JavaDependencyContextRefiner()).
+ // Because the full dependency graph does not resolve conflicts of
versions, this session does
+ // not use ConflictResolver.
+ session.setDependencyGraphTransformer(
+ new ChainedDependencyGraphTransformer( new
CycleBreakerGraphTransformer(), // Avoids StackOverflowError
+ new JavaDependencyContextRefiner() ) );
+
+ // No dependency management in the full dependency graph
+ session.setDependencyManager( null );
+
+ return session;
+ }
+
+ private static String findLocalRepository()
+ {
+ // TODO is there Maven code for this?
+ Path home = Paths.get( System.getProperty( "user.home" ) );
+ Path localRepo = home.resolve( ".m2" ).resolve( "repository" );
+ if ( Files.isDirectory( localRepo ) )
+ {
+ return localRepo.toAbsolutePath().toString();
+ }
+ else
+ {
+ return makeTemporaryLocalRepository();
+ }
+ }
+
+ private static String makeTemporaryLocalRepository()
+ {
+ try
+ {
+ File temporaryDirectory = Files.createTempDirectory( "m2"
).toFile();
+ temporaryDirectory.deleteOnExit();
+ return temporaryDirectory.getAbsolutePath();
+ }
+ catch ( IOException ex )
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Returns Maven repository specified as {@code mavenRepositoryUrl}, after
validating the syntax of the URL.
+ *
+ * @throws IllegalArgumentException if the URL is malformed for a Maven
repository
+ */
+ public static RemoteRepository mavenRepositoryFromUrl( String
mavenRepositoryUrl )
+ {
+ try
+ {
+ // Because the protocol is not an empty string (checked below),
this URI is absolute.
+ new URI( mavenRepositoryUrl );
+ }
+ catch ( URISyntaxException ex )
+ {
+ throw new IllegalArgumentException( "Invalid URL syntax: " +
mavenRepositoryUrl );
+ }
+
+ RemoteRepository repository = new RemoteRepository.Builder( null,
"default", mavenRepositoryUrl ).build();
+
+ return repository;
+ }
+
+ private static VersionRangeResult findVersionRange( RepositorySystem
repositorySystem,
+
RepositorySystemSession session,
+ String groupId, String
artifactId )
+ throws VersionRangeResolutionException
+ {
+
+ Artifact artifactWithVersionRange = new DefaultArtifact( groupId,
artifactId, null, "(0,]" );
+ VersionRangeRequest request = new VersionRangeRequest(
artifactWithVersionRange,
+ Arrays.asList( RepositoryUtility.CENTRAL ), null );
+
+
+ return repositorySystem.resolveVersionRange( session, request );
+
+ }
+
+ /**
+ * Returns the highest version for {@code groupId:artifactId} in {@code
repositorySystem}.
+ */
+ static Version findHighestVersion( RepositorySystem repositorySystem,
RepositorySystemSession session,
+ String groupId, String artifactId )
throws VersionRangeResolutionException
+ {
+ return findVersionRange( repositorySystem, session, groupId,
artifactId ).getHighestVersion();
+ }
+
+ /**
+ * Returns the latest Maven coordinates for {@code groupId:artifactId} in
{@code repositorySystem}.
+ */
+ public static String findLatestCoordinates( RepositorySystem
repositorySystem, String groupId, String artifactId )
Review comment:
please verify that we need all public methods in this class
##########
File path:
src/main/java/org/apache/maven/plugins/dependency/tree/verbose/VerboseDependencyGraphBuilder.java
##########
@@ -0,0 +1,332 @@
+package org.apache.maven.plugins.dependency.tree.verbose;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.model.DependencyManagement;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Repository;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.collection.CollectRequest;
+import org.eclipse.aether.graph.DefaultDependencyNode;
+import org.eclipse.aether.graph.Dependency;
+import org.eclipse.aether.graph.DependencyNode;
+import org.eclipse.aether.repository.RemoteRepository;
+import org.eclipse.aether.resolution.DependencyRequest;
+import org.eclipse.aether.resolution.DependencyResult;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static
org.apache.maven.plugins.dependency.tree.verbose.RepositoryUtility.mavenRepositoryFromUrl;
+
+/**
+ * Builds the VerboseDependencyGraph
+ */
+public class VerboseDependencyGraphBuilder
+{
+ private RepositorySystem repositorySystem;
+
+ /**
+ * Maven repositories to use when resolving dependencies.
+ */
+ private final List<RemoteRepository> repositories;
+
+ private static final String PRE_MANAGED_SCOPE = "preManagedScope",
PRE_MANAGED_VERSION = "preManagedVersion",
+ MANAGED_SCOPE = "managedScope";
+
+
+ public static final RemoteRepository CENTRAL = new
RemoteRepository.Builder( "central", "default",
Review comment:
There should be a constant for this somewhere in Maven core or utils
##########
File path:
src/main/java/org/apache/maven/plugins/dependency/tree/verbose/RepositoryUtility.java
##########
@@ -0,0 +1,216 @@
+package org.apache.maven.plugins.dependency.tree.verbose;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
+import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.collection.DependencySelector;
+import org.eclipse.aether.repository.LocalRepository;
+import org.eclipse.aether.repository.RemoteRepository;
+import org.eclipse.aether.resolution.VersionRangeRequest;
+import org.eclipse.aether.resolution.VersionRangeResolutionException;
+import org.eclipse.aether.resolution.VersionRangeResult;
+import org.eclipse.aether.util.graph.selector.AndDependencySelector;
+import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector;
+import org.eclipse.aether.util.graph.selector.ScopeDependencySelector;
+import
org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransformer;
+import org.eclipse.aether.util.graph.transformer.JavaDependencyContextRefiner;
+import org.eclipse.aether.version.Version;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+
+/**
+ * Aether initialization. This uses Maven Resolver 1.4.2 or later. There are
many other versions of Aether
+ * from Sonatype and the Eclipse Project, but this is the current one.
+ */
+public final class RepositoryUtility
+{
+
+ public static final RemoteRepository CENTRAL = new
RemoteRepository.Builder( "central", "default",
Review comment:
I'm a little worried this class is not how we should be doing things in
a Maven plugin. Generally we'd inject the session.
##########
File path:
src/main/java/org/apache/maven/plugins/dependency/tree/verbose/RepositoryUtility.java
##########
@@ -0,0 +1,216 @@
+package org.apache.maven.plugins.dependency.tree.verbose;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
+import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.collection.DependencySelector;
+import org.eclipse.aether.repository.LocalRepository;
+import org.eclipse.aether.repository.RemoteRepository;
+import org.eclipse.aether.resolution.VersionRangeRequest;
+import org.eclipse.aether.resolution.VersionRangeResolutionException;
+import org.eclipse.aether.resolution.VersionRangeResult;
+import org.eclipse.aether.util.graph.selector.AndDependencySelector;
+import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector;
+import org.eclipse.aether.util.graph.selector.ScopeDependencySelector;
+import
org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransformer;
+import org.eclipse.aether.util.graph.transformer.JavaDependencyContextRefiner;
+import org.eclipse.aether.version.Version;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+
+/**
+ * Aether initialization. This uses Maven Resolver 1.4.2 or later. There are
many other versions of Aether
+ * from Sonatype and the Eclipse Project, but this is the current one.
+ */
+public final class RepositoryUtility
+{
+
+ public static final RemoteRepository CENTRAL = new
RemoteRepository.Builder( "central", "default",
+ "https://repo1.maven.org/maven2/" ).build();
+
+ // DefaultTransporterProvider.newTransporter checks these transporters
+ private static final Set<String> ALLOWED_REPOSITORY_URL_SCHEMES = new
HashSet<String>(
+ Arrays.asList( "file", "http", "https" ) );
+
+ private RepositoryUtility()
+ {
+ }
+
+ //@VisibleForTesting
Review comment:
@VisibleForTesting --> visible for testing
since it's no longer an annotation
##########
File path:
src/main/java/org/apache/maven/plugins/dependency/tree/verbose/RepositoryUtility.java
##########
@@ -0,0 +1,216 @@
+package org.apache.maven.plugins.dependency.tree.verbose;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
+import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.collection.DependencySelector;
+import org.eclipse.aether.repository.LocalRepository;
+import org.eclipse.aether.repository.RemoteRepository;
+import org.eclipse.aether.resolution.VersionRangeRequest;
+import org.eclipse.aether.resolution.VersionRangeResolutionException;
+import org.eclipse.aether.resolution.VersionRangeResult;
+import org.eclipse.aether.util.graph.selector.AndDependencySelector;
+import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector;
+import org.eclipse.aether.util.graph.selector.ScopeDependencySelector;
+import
org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransformer;
+import org.eclipse.aether.util.graph.transformer.JavaDependencyContextRefiner;
+import org.eclipse.aether.version.Version;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+
+/**
+ * Aether initialization. This uses Maven Resolver 1.4.2 or later. There are
many other versions of Aether
+ * from Sonatype and the Eclipse Project, but this is the current one.
+ */
+public final class RepositoryUtility
Review comment:
can this be non-public?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]