View Javadoc
1   package org.eclipse.aether.internal.impl;
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 javax.inject.Inject;
23  import javax.inject.Named;
24  
25  import org.eclipse.aether.RepositorySystemSession;
26  import org.eclipse.aether.repository.LocalRepository;
27  import org.eclipse.aether.repository.LocalRepositoryManager;
28  import org.eclipse.aether.repository.NoLocalRepositoryManagerException;
29  import org.eclipse.aether.spi.localrepo.LocalRepositoryManagerFactory;
30  import org.eclipse.aether.spi.locator.Service;
31  import org.eclipse.aether.spi.locator.ServiceLocator;
32  import org.eclipse.aether.spi.log.Logger;
33  import org.eclipse.aether.spi.log.LoggerFactory;
34  import org.eclipse.aether.spi.log.NullLoggerFactory;
35  
36  /**
37   * Creates local repository managers for repository type {@code "simple"}.
38   */
39  @Named( "simple" )
40  public class SimpleLocalRepositoryManagerFactory
41      implements LocalRepositoryManagerFactory, Service
42  {
43  
44      private Logger logger = NullLoggerFactory.LOGGER;
45  
46      private float priority;
47  
48      public SimpleLocalRepositoryManagerFactory()
49      {
50          // enable no-arg constructor
51      }
52  
53      @Inject
54      SimpleLocalRepositoryManagerFactory( LoggerFactory loggerFactory )
55      {
56          setLoggerFactory( loggerFactory );
57      }
58  
59      public LocalRepositoryManager newInstance( RepositorySystemSession session, LocalRepository repository )
60          throws NoLocalRepositoryManagerException
61      {
62          if ( "".equals( repository.getContentType() ) || "simple".equals( repository.getContentType() ) )
63          {
64              return new SimpleLocalRepositoryManager( repository.getBasedir() ).setLogger( logger );
65          }
66          else
67          {
68              throw new NoLocalRepositoryManagerException( repository );
69          }
70      }
71  
72      public void initService( ServiceLocator locator )
73      {
74          setLoggerFactory( locator.getService( LoggerFactory.class ) );
75      }
76  
77      public SimpleLocalRepositoryManagerFactory setLoggerFactory( LoggerFactory loggerFactory )
78      {
79          this.logger = NullLoggerFactory.getSafeLogger( loggerFactory, SimpleLocalRepositoryManager.class );
80          return this;
81      }
82  
83      public float getPriority()
84      {
85          return priority;
86      }
87  
88      /**
89       * Sets the priority of this component.
90       * 
91       * @param priority The priority.
92       * @return This component for chaining, never {@code null}.
93       */
94      public SimpleLocalRepositoryManagerFactory setPriority( float priority )
95      {
96          this.priority = priority;
97          return this;
98      }
99  
100 }