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.Collections;
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      public static final String SERVICE_LOCATOR = "serviceLocator";
39  
40      public static final String GUICE = "guice";
41  
42      public static final String SISU = "sisu";
43  
44      public static String selectFactory( String[] args )
45      {
46          if ( args == null || args.length == 0 )
47          {
48              return SERVICE_LOCATOR;
49          }
50          else
51          {
52              return args[0];
53          }
54      }
55  
56      public static RepositorySystem newRepositorySystem( final String factory )
57      {
58          switch ( factory ) 
59          {
60              case SERVICE_LOCATOR:
61                  return org.apache.maven.resolver.examples.manual.ManualRepositorySystemFactory.newRepositorySystem();
62              case GUICE:
63                  return org.apache.maven.resolver.examples.guice.GuiceRepositorySystemFactory.newRepositorySystem();
64              case SISU:
65                  return org.apache.maven.resolver.examples.sisu.SisuRepositorySystemFactory.newRepositorySystem();
66              default:
67                  throw new IllegalArgumentException( "Unknown factory: " + factory );
68          }
69      }
70  
71      public static DefaultRepositorySystemSession newRepositorySystemSession( RepositorySystem system )
72      {
73          DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
74  
75          LocalRepository localRepo = new LocalRepository( "target/local-repo" );
76          session.setLocalRepositoryManager( system.newLocalRepositoryManager( session, localRepo ) );
77  
78          session.setTransferListener( new ConsoleTransferListener() );
79          session.setRepositoryListener( new ConsoleRepositoryListener() );
80  
81          // uncomment to generate dirty trees
82          // session.setDependencyGraphTransformer( null );
83  
84          return session;
85      }
86  
87      public static List<RemoteRepository> newRepositories( RepositorySystem system, RepositorySystemSession session )
88      {
89          return new ArrayList<>( Collections.singletonList( newCentralRepository() ) );
90      }
91  
92      private static RemoteRepository newCentralRepository()
93      {
94          return new RemoteRepository.Builder( "central", "default", "https://repo.maven.apache.org/maven2/" ).build();
95      }
96  
97  }