| 1 |
/* |
| 2 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 3 |
* or more contributor license agreements. See the NOTICE file |
| 4 |
* distributed with this work for additional information |
| 5 |
* regarding copyright ownership. The ASF licenses this file |
| 6 |
* to you under the Apache License, Version 2.0 (the |
| 7 |
* "License"); you may not use this file except in compliance |
| 8 |
* with the License. You may obtain a copy of the License at |
| 9 |
* |
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
* |
| 12 |
* Unless required by applicable law or agreed to in writing, |
| 13 |
* software distributed under the License is distributed on an |
| 14 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 |
* KIND, either express or implied. See the License for the |
| 16 |
* specific language governing permissions and limitations |
| 17 |
* under the License. |
| 18 |
*/ |
| 19 |
package org.apache.maven.resolver.examples; |
| 20 |
|
| 21 |
import java.io.File; |
| 22 |
import java.util.Collections; |
| 23 |
|
| 24 |
import org.apache.maven.resolver.examples.util.Booter; |
| 25 |
import org.eclipse.aether.DefaultRepositorySystemSession; |
| 26 |
import org.eclipse.aether.RepositorySystem; |
| 27 |
import org.eclipse.aether.artifact.Artifact; |
| 28 |
import org.eclipse.aether.artifact.DefaultArtifact; |
| 29 |
import org.eclipse.aether.collection.CollectRequest; |
| 30 |
import org.eclipse.aether.collection.CollectResult; |
| 31 |
import org.eclipse.aether.repository.RemoteRepository; |
| 32 |
import org.eclipse.aether.repository.RepositoryPolicy; |
| 33 |
import org.eclipse.aether.resolution.ArtifactDescriptorRequest; |
| 34 |
import org.eclipse.aether.resolution.ArtifactDescriptorResult; |
| 35 |
import org.eclipse.aether.util.graph.manager.DependencyManagerUtils; |
| 36 |
import org.eclipse.aether.util.graph.transformer.ConflictResolver; |
| 37 |
|
| 38 |
/** |
| 39 |
* Visualizes the transitive dependencies of an artifact similar to m2e's dependency hierarchy view. Artifact in this |
| 40 |
* test is not "plain" one as is original "demo" {@link GetDependencyHierarchy}, but specially crafted for case |
| 41 |
* described in MRESOLVER-345. |
| 42 |
* |
| 43 |
* @see <a href="https://issues.apache.org/jira/browse/MRESOLVER-345">MRESOLVER-345</a> |
| 44 |
*/ |
| 45 |
public class DependencyHierarchyWithRanges { |
| 46 |
|
| 47 |
/** |
| 48 |
* Main. |
| 49 |
*/ |
| 50 |
public static void main(String[] args) throws Exception { |
| 51 |
System.out.println("------------------------------------------------------------"); |
| 52 |
System.out.println(DependencyHierarchyWithRanges.class.getSimpleName()); |
| 53 |
|
| 54 |
RepositorySystem system = Booter.newRepositorySystem(Booter.selectFactory(args)); |
| 55 |
|
| 56 |
DefaultRepositorySystemSession session = Booter.newRepositorySystemSession(system); |
| 57 |
|
| 58 |
session.setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_IGNORE); // to not bother with checksums |
| 59 |
session.setConfigProperty(ConflictResolver.CONFIG_PROP_VERBOSE, true); |
| 60 |
session.setConfigProperty(DependencyManagerUtils.CONFIG_PROP_VERBOSE, true); |
| 61 |
|
| 62 |
// this artifact is in "remote" repository in src/main/remote-repository |
| 63 |
Artifact artifact = new DefaultArtifact("org.apache.maven.resolver.demo.mresolver345:a:1.0"); |
| 64 |
|
| 65 |
File remoteRepoBasedir = new File("src/main/remote-repository"); |
| 66 |
|
| 67 |
ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest(); |
| 68 |
descriptorRequest.setArtifact(artifact); |
| 69 |
descriptorRequest.setRepositories(Collections.singletonList(new RemoteRepository.Builder( |
| 70 |
"remote", "default", remoteRepoBasedir.toURI().toASCIIString()) |
| 71 |
.build())); |
| 72 |
ArtifactDescriptorResult descriptorResult = system.readArtifactDescriptor(session, descriptorRequest); |
| 73 |
|
| 74 |
CollectRequest collectRequest = new CollectRequest(); |
| 75 |
collectRequest.setRootArtifact(descriptorResult.getArtifact()); |
| 76 |
collectRequest.setDependencies(descriptorResult.getDependencies()); |
| 77 |
collectRequest.setManagedDependencies(descriptorResult.getManagedDependencies()); |
| 78 |
collectRequest.setRepositories(descriptorRequest.getRepositories()); |
| 79 |
|
| 80 |
CollectResult collectResult = system.collectDependencies(session, collectRequest); |
| 81 |
|
| 82 |
collectResult.getRoot().accept(Booter.DUMPER_SOUT); |
| 83 |
} |
| 84 |
} |