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 enhanced local repository managers for repository types {@code "default"} or {@code "" (automatic)}. Enhanced
38   * local repository manager is built upon the classical Maven 2.0 local repository structure but additionally keeps
39   * track of from what repositories a cached artifact was resolved. Resolution of locally cached artifacts will be
40   * rejected in case the current resolution request does not match the known source repositories of an artifact, thereby
41   * emulating physically separated artifact caches per remote repository.
42   */
43  @Named( "enhanced" )
44  public class EnhancedLocalRepositoryManagerFactory
45      implements LocalRepositoryManagerFactory, Service
46  {
47  
48      private Logger logger = NullLoggerFactory.LOGGER;
49  
50      private float priority = 10.0f;
51  
52      public EnhancedLocalRepositoryManagerFactory()
53      {
54          // enable no-arg constructor
55      }
56  
57      @Inject
58      EnhancedLocalRepositoryManagerFactory( LoggerFactory loggerFactory )
59      {
60          setLoggerFactory( loggerFactory );
61      }
62  
63      public LocalRepositoryManager newInstance( RepositorySystemSession session, LocalRepository repository )
64          throws NoLocalRepositoryManagerException
65      {
66          if ( "".equals( repository.getContentType() ) || "default".equals( repository.getContentType() ) )
67          {
68              return new EnhancedLocalRepositoryManager( repository.getBasedir(), session ).setLogger( logger );
69          }
70          else
71          {
72              throw new NoLocalRepositoryManagerException( repository );
73          }
74      }
75  
76      public void initService( ServiceLocator locator )
77      {
78          setLoggerFactory( locator.getService( LoggerFactory.class ) );
79      }
80  
81      public EnhancedLocalRepositoryManagerFactory setLoggerFactory( LoggerFactory loggerFactory )
82      {
83          this.logger = NullLoggerFactory.getSafeLogger( loggerFactory, EnhancedLocalRepositoryManager.class );
84          return this;
85      }
86  
87      public float getPriority()
88      {
89          return priority;
90      }
91  
92      /**
93       * Sets the priority of this component.
94       * 
95       * @param priority The priority.
96       * @return This component for chaining, never {@code null}.
97       */
98      public EnhancedLocalRepositoryManagerFactory setPriority( float priority )
99      {
100         this.priority = priority;
101         return this;
102     }
103 
104 }