1 package org.eclipse.aether.transport.file;
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.RemoteRepository;
27 import org.eclipse.aether.spi.connector.transport.Transporter;
28 import org.eclipse.aether.spi.connector.transport.TransporterFactory;
29 import org.eclipse.aether.spi.locator.Service;
30 import org.eclipse.aether.spi.locator.ServiceLocator;
31 import org.eclipse.aether.spi.log.Logger;
32 import org.eclipse.aether.spi.log.LoggerFactory;
33 import org.eclipse.aether.spi.log.NullLoggerFactory;
34 import org.eclipse.aether.transfer.NoTransporterException;
35
36 /**
37 * A transporter factory for repositories using the {@code file:} protocol.
38 */
39 @Named( "file" )
40 public final class FileTransporterFactory
41 implements TransporterFactory, Service
42 {
43
44 private Logger logger = NullLoggerFactory.LOGGER;
45
46 private float priority;
47
48 /**
49 * Creates an (uninitialized) instance of this transporter factory. <em>Note:</em> In case of manual instantiation
50 * by clients, the new factory needs to be configured via its various mutators before first use or runtime errors
51 * will occur.
52 */
53 public FileTransporterFactory()
54 {
55 // enables default constructor
56 }
57
58 @Inject
59 FileTransporterFactory( LoggerFactory loggerFactory )
60 {
61 setLoggerFactory( loggerFactory );
62 }
63
64 public void initService( ServiceLocator locator )
65 {
66 setLoggerFactory( locator.getService( LoggerFactory.class ) );
67 }
68
69 /**
70 * Sets the logger factory to use for this component.
71 *
72 * @param loggerFactory The logger factory to use, may be {@code null} to disable logging.
73 * @return This component for chaining, never {@code null}.
74 */
75 public FileTransporterFactory setLoggerFactory( LoggerFactory loggerFactory )
76 {
77 this.logger = NullLoggerFactory.getSafeLogger( loggerFactory, FileTransporter.class );
78 return this;
79 }
80
81 public float getPriority()
82 {
83 return priority;
84 }
85
86 /**
87 * Sets the priority of this component.
88 *
89 * @param priority The priority.
90 * @return This component for chaining, never {@code null}.
91 */
92 public FileTransporterFactory setPriority( float priority )
93 {
94 this.priority = priority;
95 return this;
96 }
97
98 public Transporter newInstance( RepositorySystemSession session, RemoteRepository repository )
99 throws NoTransporterException
100 {
101 return new FileTransporter( repository, logger );
102 }
103
104 }