View Javadoc
1   package org.apache.maven.resolver.examples.manual;
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.repository.internal.MavenRepositorySystemUtils;
23  import org.eclipse.aether.RepositorySystem;
24  import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory;
25  import org.eclipse.aether.impl.DefaultServiceLocator;
26  import org.eclipse.aether.spi.connector.RepositoryConnectorFactory;
27  import org.eclipse.aether.spi.connector.transport.TransporterFactory;
28  import org.eclipse.aether.transport.file.FileTransporterFactory;
29  import org.eclipse.aether.transport.http.HttpTransporterFactory;
30  
31  /**
32   * A factory for repository system instances that employs Maven Artifact Resolver's built-in service locator
33   * infrastructure to wire up the system's components.
34   */
35  public class ManualRepositorySystemFactory
36  {
37  
38      public static RepositorySystem newRepositorySystem()
39      {
40          /*
41           * Aether's components implement org.eclipse.aether.spi.locator.Service to ease manual wiring and using the
42           * prepopulated DefaultServiceLocator, we only need to register the repository connector and transporter
43           * factories.
44           */
45          DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
46          locator.addService( RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class );
47          locator.addService( TransporterFactory.class, FileTransporterFactory.class );
48          locator.addService( TransporterFactory.class, HttpTransporterFactory.class );
49  
50          locator.setErrorHandler( new DefaultServiceLocator.ErrorHandler()
51          {
52              @Override
53              public void serviceCreationFailed( Class<?> type, Class<?> impl, Throwable exception )
54              {
55                  exception.printStackTrace();
56              }
57          } );
58  
59          return locator.getService( RepositorySystem.class );
60      }
61  
62  }