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 java.util.Objects;
23  
24  import javax.inject.Inject;
25  import javax.inject.Named;
26  import javax.inject.Singleton;
27  
28  import org.eclipse.aether.RepositorySystemSession;
29  import org.eclipse.aether.repository.LocalRepository;
30  import org.eclipse.aether.repository.LocalRepositoryManager;
31  import org.eclipse.aether.repository.NoLocalRepositoryManagerException;
32  import org.eclipse.aether.spi.localrepo.LocalRepositoryManagerFactory;
33  import org.eclipse.aether.spi.locator.Service;
34  import org.eclipse.aether.spi.locator.ServiceLocator;
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  @Singleton
44  @Named( "enhanced" )
45  public class EnhancedLocalRepositoryManagerFactory
46      implements LocalRepositoryManagerFactory, Service
47  {
48      private float priority = 10.0f;
49  
50      private TrackingFileManager trackingFileManager;
51  
52      public EnhancedLocalRepositoryManagerFactory()
53      {
54          // no arg ctor for ServiceLocator
55      }
56  
57      @Inject
58      public EnhancedLocalRepositoryManagerFactory( final TrackingFileManager trackingFileManager )
59      {
60          this.trackingFileManager = Objects.requireNonNull( trackingFileManager );
61      }
62  
63      @Override
64      public void initService( final ServiceLocator locator )
65      {
66          this.trackingFileManager = Objects.requireNonNull( locator.getService( TrackingFileManager.class ) );
67      }
68  
69      public LocalRepositoryManager newInstance( RepositorySystemSession session, LocalRepository repository )
70          throws NoLocalRepositoryManagerException
71      {
72          Objects.requireNonNull( "session", "session cannot be null" );
73          Objects.requireNonNull( "repository", "repository cannot be null" );
74  
75          if ( "".equals( repository.getContentType() ) || "default".equals( repository.getContentType() ) )
76          {
77              return new EnhancedLocalRepositoryManager( repository.getBasedir(), session, trackingFileManager );
78          }
79          else
80          {
81              throw new NoLocalRepositoryManagerException( repository );
82          }
83      }
84  
85      public float getPriority()
86      {
87          return priority;
88      }
89  
90      /**
91       * Sets the priority of this component.
92       *
93       * @param priority The priority.
94       * @return This component for chaining, never {@code null}.
95       */
96      public EnhancedLocalRepositoryManagerFactory setPriority( float priority )
97      {
98          this.priority = priority;
99          return this;
100     }
101 
102 }