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  import javax.inject.Singleton;
25  
26  import java.util.Objects;
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  import static java.util.Objects.requireNonNull;
37  
38  /**
39   * Creates local repository managers for repository type {@code "simple"}.
40   */
41  @Singleton
42  @Named( "simple" )
43  public class SimpleLocalRepositoryManagerFactory
44      implements LocalRepositoryManagerFactory, Service
45  {
46      private float priority;
47  
48      private LocalPathComposer localPathComposer;
49  
50      public SimpleLocalRepositoryManagerFactory()
51      {
52          // enable no-arg constructor
53          this.localPathComposer = new DefaultLocalPathComposer(); // maven UTs needs this
54      }
55  
56      @Inject
57      public SimpleLocalRepositoryManagerFactory( final LocalPathComposer localPathComposer )
58      {
59          this.localPathComposer = requireNonNull( localPathComposer );
60      }
61  
62      @Override
63      public void initService( final ServiceLocator locator )
64      {
65          this.localPathComposer = Objects.requireNonNull( locator.getService( LocalPathComposer.class ) );
66      }
67  
68      @Override
69      public LocalRepositoryManager newInstance( RepositorySystemSession session, LocalRepository repository )
70          throws NoLocalRepositoryManagerException
71      {
72          requireNonNull( session, "session cannot be null" );
73          requireNonNull( repository, "repository cannot be null" );
74  
75          if ( "".equals( repository.getContentType() ) || "simple".equals( repository.getContentType() ) )
76          {
77              return new SimpleLocalRepositoryManager( repository.getBasedir(), "simple", localPathComposer );
78          }
79          else
80          {
81              throw new NoLocalRepositoryManagerException( repository );
82          }
83      }
84  
85      @Override
86      public float getPriority()
87      {
88          return priority;
89      }
90  
91      /**
92       * Sets the priority of this component.
93       *
94       * @param priority The priority.
95       * @return This component for chaining, never {@code null}.
96       */
97      public SimpleLocalRepositoryManagerFactory setPriority( float priority )
98      {
99          this.priority = priority;
100         return this;
101     }
102 
103 }