View Javadoc
1   package org.apache.maven.resolver.examples.resolver;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   * 
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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() 
40          throws DependencyResolutionException
41      {
42          Resolver resolver = new Resolver( "http://localhost:8081/nexus/content/groups/public", "target/aether-repo" );
43                  
44          ResolverResult result = resolver.resolve( "com.mycompany.app", "super-app", "1.0" );
45  
46          // Get the root of the resolved tree of artifacts
47          //
48          DependencyNode root = result.getRoot();
49  
50          // Get the list of files for the artifacts resolved
51          //
52          List<File> artifacts = result.getResolvedFiles();
53          
54          // Get the classpath of the artifacts resolved
55          //
56          String classpath = result.getResolvedClassPath();        
57      }
58      
59      public void installAndDeploy() 
60          throws InstallationException, DeploymentException
61      {
62          Resolver resolver = new Resolver( "http://localhost:8081/nexus/content/groups/public", "target/aether-repo" );
63          
64          Artifact artifact = new DefaultArtifact( "com.mycompany.super", "super-core", "jar", "0.1-SNAPSHOT" );
65          artifact = artifact.setFile( new File( "jar-from-whatever-process.jar" ) );
66          Artifact pom = new SubArtifact( artifact, null, "pom" );
67          pom = pom.setFile( new File( "pom-from-whatever-process.xml" ) );
68            
69          // Install into the local repository specified
70          //
71          resolver.install( artifact, pom );
72          
73          // Deploy to a remote reposistory
74          //
75          resolver.deploy( artifact, pom, "http://localhost:8081/nexus/content/repositories/snapshots/" );
76      }
77  
78  }