View Javadoc
1   package org.apache.maven.resolver.examples;
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 org.apache.maven.resolver.examples.util.Booter;
23  import org.eclipse.aether.DefaultRepositorySystemSession;
24  import org.eclipse.aether.RepositorySystem;
25  import org.eclipse.aether.artifact.Artifact;
26  import org.eclipse.aether.artifact.DefaultArtifact;
27  import org.eclipse.aether.repository.RepositoryPolicy;
28  import org.eclipse.aether.resolution.ArtifactRequest;
29  import org.eclipse.aether.resolution.ArtifactResult;
30  
31  /**
32   * Resolves a single artifact.
33   */
34  public class ResolveArtifact
35  {
36  
37      /**
38       * Main.
39       * @param args
40       * @throws Exception
41       */
42      public static void main( String[] args )
43          throws Exception
44      {
45          System.out.println( "------------------------------------------------------------" );
46          System.out.println( ResolveArtifact.class.getSimpleName() );
47  
48          RepositorySystem system = Booter.newRepositorySystem( Booter.selectFactory( args ) );
49  
50          DefaultRepositorySystemSession session = Booter.newRepositorySystemSession( system );
51  
52          Artifact artifact;
53          ArtifactRequest artifactRequest;
54          ArtifactResult artifactResult;
55  
56          // artifact
57          artifact = new DefaultArtifact( "org.apache.maven.resolver:maven-resolver-util:1.3.3" );
58  
59          artifactRequest = new ArtifactRequest();
60          artifactRequest.setArtifact( artifact );
61          artifactRequest.setRepositories( Booter.newRepositories( system, session ) );
62  
63          artifactResult = system.resolveArtifact( session, artifactRequest );
64  
65          artifact = artifactResult.getArtifact();
66  
67          System.out.println( artifact + " resolved to  " + artifact.getFile() );
68  
69          // signature
70          session.setChecksumPolicy( RepositoryPolicy.CHECKSUM_POLICY_FAIL );
71  
72          artifact = new DefaultArtifact( "org.apache.maven.resolver:maven-resolver-util:jar.asc:1.3.3" );
73  
74          artifactRequest = new ArtifactRequest();
75          artifactRequest.setArtifact( artifact );
76          artifactRequest.setRepositories( Booter.newRepositories( system, session ) );
77  
78          artifactResult = system.resolveArtifact( session, artifactRequest );
79  
80          artifact = artifactResult.getArtifact();
81  
82          System.out.println( artifact + " resolved signature to  " + artifact.getFile() );
83      }
84  
85  }