1 package org.apache.maven.resolver.examples.resolver;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.List;
24
25 import org.eclipse.aether.artifact.Artifact;
26 import org.eclipse.aether.artifact.DefaultArtifact;
27 import org.eclipse.aether.deployment.DeploymentException;
28 import org.eclipse.aether.graph.DependencyNode;
29 import org.eclipse.aether.installation.InstallationException;
30 import org.eclipse.aether.resolution.DependencyResolutionException;
31 import org.eclipse.aether.util.artifact.SubArtifact;
32
33
34
35 @SuppressWarnings( "unused" )
36 public class ResolverDemo
37 {
38
39 public void resolve( final String factory )
40 throws DependencyResolutionException
41 {
42 Resolver resolver = new Resolver(
43 factory,
44 "http://localhost:8081/nexus/content/groups/public", "target/aether-repo" );
45
46 ResolverResult result = resolver.resolve( "com.mycompany.app", "super-app", "1.0" );
47
48
49
50 DependencyNode root = result.getRoot();
51
52
53
54 List<File> artifacts = result.getResolvedFiles();
55
56
57
58 String classpath = result.getResolvedClassPath();
59 }
60
61 public void installAndDeploy( final String factory )
62 throws InstallationException, DeploymentException
63 {
64 Resolver resolver = new Resolver(
65 factory,
66 "http://localhost:8081/nexus/content/groups/public", "target/aether-repo" );
67
68 Artifact artifact = new DefaultArtifact( "com.mycompany.super", "super-core", "jar", "0.1-SNAPSHOT" );
69 artifact = artifact.setFile( new File( "jar-from-whatever-process.jar" ) );
70 Artifact pom = new SubArtifact( artifact, null, "pom" );
71 pom = pom.setFile( new File( "pom-from-whatever-process.xml" ) );
72
73
74
75 resolver.install( artifact, pom );
76
77
78
79 resolver.deploy( artifact, pom, "http://localhost:8081/nexus/content/repositories/snapshots/" );
80 }
81
82 }