View Javadoc
1   package org.apache.maven.resolver.examples.util;
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.util.ArrayList;
23  import java.util.Arrays;
24  import java.util.List;
25  
26  import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
27  import org.eclipse.aether.DefaultRepositorySystemSession;
28  import org.eclipse.aether.RepositorySystem;
29  import org.eclipse.aether.RepositorySystemSession;
30  import org.eclipse.aether.repository.LocalRepository;
31  import org.eclipse.aether.repository.RemoteRepository;
32  
33  /**
34   * A helper to boot the repository system and a repository system session.
35   */
36  public class Booter
37  {
38  
39      public static RepositorySystem newRepositorySystem()
40      {
41          return org.apache.maven.resolver.examples.manual.ManualRepositorySystemFactory.newRepositorySystem();
42          // return org.eclipse.aether.examples.guice.GuiceRepositorySystemFactory.newRepositorySystem();
43          // return org.eclipse.aether.examples.sisu.SisuRepositorySystemFactory.newRepositorySystem();
44          // return org.eclipse.aether.examples.plexus.PlexusRepositorySystemFactory.newRepositorySystem();
45      }
46  
47      public static DefaultRepositorySystemSession newRepositorySystemSession( RepositorySystem system )
48      {
49          DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
50  
51          LocalRepository localRepo = new LocalRepository( "target/local-repo" );
52          session.setLocalRepositoryManager( system.newLocalRepositoryManager( session, localRepo ) );
53  
54          session.setTransferListener( new ConsoleTransferListener() );
55          session.setRepositoryListener( new ConsoleRepositoryListener() );
56  
57          // uncomment to generate dirty trees
58          // session.setDependencyGraphTransformer( null );
59  
60          return session;
61      }
62  
63      public static List<RemoteRepository> newRepositories( RepositorySystem system, RepositorySystemSession session )
64      {
65          return new ArrayList<RemoteRepository>( Arrays.asList( newCentralRepository() ) );
66      }
67  
68      private static RemoteRepository newCentralRepository()
69      {
70          return new RemoteRepository.Builder( "central", "default", "https://repo.maven.apache.org/maven2/" ).build();
71      }
72  
73  }