001package org.eclipse.aether.transport.file; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import javax.inject.Inject; 023import javax.inject.Named; 024 025import org.eclipse.aether.RepositorySystemSession; 026import org.eclipse.aether.repository.RemoteRepository; 027import org.eclipse.aether.spi.connector.transport.Transporter; 028import org.eclipse.aether.spi.connector.transport.TransporterFactory; 029import org.eclipse.aether.spi.locator.Service; 030import org.eclipse.aether.spi.locator.ServiceLocator; 031import org.eclipse.aether.spi.log.Logger; 032import org.eclipse.aether.spi.log.LoggerFactory; 033import org.eclipse.aether.spi.log.NullLoggerFactory; 034import org.eclipse.aether.transfer.NoTransporterException; 035 036/** 037 * A transporter factory for repositories using the {@code file:} protocol. 038 */ 039@Named( "file" ) 040public final class FileTransporterFactory 041 implements TransporterFactory, Service 042{ 043 044 private Logger logger = NullLoggerFactory.LOGGER; 045 046 private float priority; 047 048 /** 049 * Creates an (uninitialized) instance of this transporter factory. <em>Note:</em> In case of manual instantiation 050 * by clients, the new factory needs to be configured via its various mutators before first use or runtime errors 051 * will occur. 052 */ 053 public FileTransporterFactory() 054 { 055 // enables default constructor 056 } 057 058 @Inject 059 FileTransporterFactory( LoggerFactory loggerFactory ) 060 { 061 setLoggerFactory( loggerFactory ); 062 } 063 064 public void initService( ServiceLocator locator ) 065 { 066 setLoggerFactory( locator.getService( LoggerFactory.class ) ); 067 } 068 069 /** 070 * Sets the logger factory to use for this component. 071 * 072 * @param loggerFactory The logger factory to use, may be {@code null} to disable logging. 073 * @return This component for chaining, never {@code null}. 074 */ 075 public FileTransporterFactory setLoggerFactory( LoggerFactory loggerFactory ) 076 { 077 this.logger = NullLoggerFactory.getSafeLogger( loggerFactory, FileTransporter.class ); 078 return this; 079 } 080 081 public float getPriority() 082 { 083 return priority; 084 } 085 086 /** 087 * Sets the priority of this component. 088 * 089 * @param priority The priority. 090 * @return This component for chaining, never {@code null}. 091 */ 092 public FileTransporterFactory setPriority( float priority ) 093 { 094 this.priority = priority; 095 return this; 096 } 097 098 public Transporter newInstance( RepositorySystemSession session, RemoteRepository repository ) 099 throws NoTransporterException 100 { 101 return new FileTransporter( repository, logger ); 102 } 103 104}