View Javadoc
1   package org.eclipse.aether.connector.basic;
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 static java.util.Objects.requireNonNull;
26  
27  import org.eclipse.aether.RepositorySystemSession;
28  import org.eclipse.aether.repository.RemoteRepository;
29  import org.eclipse.aether.spi.connector.RepositoryConnector;
30  import org.eclipse.aether.spi.connector.RepositoryConnectorFactory;
31  import org.eclipse.aether.spi.connector.checksum.ChecksumPolicyProvider;
32  import org.eclipse.aether.spi.connector.layout.RepositoryLayoutProvider;
33  import org.eclipse.aether.spi.connector.transport.TransporterProvider;
34  import org.eclipse.aether.spi.io.FileProcessor;
35  import org.eclipse.aether.spi.locator.Service;
36  import org.eclipse.aether.spi.locator.ServiceLocator;
37  import org.eclipse.aether.transfer.NoRepositoryConnectorException;
38  
39  /**
40   * A repository connector factory that employs pluggable
41   * {@link org.eclipse.aether.spi.connector.transport.TransporterFactory transporters} and
42   * {@link org.eclipse.aether.spi.connector.layout.RepositoryLayoutFactory repository layouts} for the transfers.
43   */
44  @Named( "basic" )
45  public final class BasicRepositoryConnectorFactory
46      implements RepositoryConnectorFactory, Service
47  {
48      private TransporterProvider transporterProvider;
49  
50      private RepositoryLayoutProvider layoutProvider;
51  
52      private ChecksumPolicyProvider checksumPolicyProvider;
53  
54      private FileProcessor fileProcessor;
55  
56      private float priority;
57  
58      /**
59       * Creates an (uninitialized) instance of this connector factory. <em>Note:</em> In case of manual instantiation by
60       * clients, the new factory needs to be configured via its various mutators before first use or runtime errors will
61       * occur.
62       */
63      public BasicRepositoryConnectorFactory()
64      {
65          // enables default constructor
66      }
67  
68      @Inject
69      BasicRepositoryConnectorFactory( TransporterProvider transporterProvider, RepositoryLayoutProvider layoutProvider,
70                                       ChecksumPolicyProvider checksumPolicyProvider, FileProcessor fileProcessor )
71      {
72          setTransporterProvider( transporterProvider );
73          setRepositoryLayoutProvider( layoutProvider );
74          setChecksumPolicyProvider( checksumPolicyProvider );
75          setFileProcessor( fileProcessor );
76      }
77  
78      public void initService( ServiceLocator locator )
79      {
80          setTransporterProvider( locator.getService( TransporterProvider.class ) );
81          setRepositoryLayoutProvider( locator.getService( RepositoryLayoutProvider.class ) );
82          setChecksumPolicyProvider( locator.getService( ChecksumPolicyProvider.class ) );
83          setFileProcessor( locator.getService( FileProcessor.class ) );
84      }
85  
86      /**
87       * Sets the transporter provider to use for this component.
88       *
89       * @param transporterProvider The transporter provider to use, must not be {@code null}.
90       * @return This component for chaining, never {@code null}.
91       */
92      public BasicRepositoryConnectorFactory setTransporterProvider( TransporterProvider transporterProvider )
93      {
94          this.transporterProvider = requireNonNull( transporterProvider, "transporter provider cannot be null" );
95          return this;
96      }
97  
98      /**
99       * Sets the repository layout provider to use for this component.
100      *
101      * @param layoutProvider The repository layout provider to use, must not be {@code null}.
102      * @return This component for chaining, never {@code null}.
103      */
104     public BasicRepositoryConnectorFactory setRepositoryLayoutProvider( RepositoryLayoutProvider layoutProvider )
105     {
106         this.layoutProvider =  requireNonNull( layoutProvider, "repository layout provider cannot be null" );
107         return this;
108     }
109 
110     /**
111      * Sets the checksum policy provider to use for this component.
112      *
113      * @param checksumPolicyProvider The checksum policy provider to use, must not be {@code null}.
114      * @return This component for chaining, never {@code null}.
115      */
116     public BasicRepositoryConnectorFactory setChecksumPolicyProvider( ChecksumPolicyProvider checksumPolicyProvider )
117     {
118         this.checksumPolicyProvider = requireNonNull(
119                 checksumPolicyProvider, "checksum policy provider cannot be null" );
120         return this;
121     }
122 
123     /**
124      * Sets the file processor to use for this component.
125      *
126      * @param fileProcessor The file processor to use, must not be {@code null}.
127      * @return This component for chaining, never {@code null}.
128      */
129     public BasicRepositoryConnectorFactory setFileProcessor( FileProcessor fileProcessor )
130     {
131         this.fileProcessor = requireNonNull( fileProcessor, "file processor cannot be null" );
132         return this;
133     }
134 
135     public float getPriority()
136     {
137         return priority;
138     }
139 
140     /**
141      * Sets the priority of this component.
142      *
143      * @param priority The priority.
144      * @return This component for chaining, never {@code null}.
145      */
146     public BasicRepositoryConnectorFactory setPriority( float priority )
147     {
148         this.priority = priority;
149         return this;
150     }
151 
152     public RepositoryConnector newInstance( RepositorySystemSession session, RemoteRepository repository )
153         throws NoRepositoryConnectorException
154     {
155         requireNonNull( "session", "session cannot be null" );
156         requireNonNull( "repository", "repository cannot be null" );
157 
158         return new BasicRepositoryConnector( session, repository, transporterProvider, layoutProvider,
159                                              checksumPolicyProvider, fileProcessor );
160     }
161 
162 }