001package org.eclipse.aether.internal.impl; 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.LocalRepository; 027import org.eclipse.aether.repository.LocalRepositoryManager; 028import org.eclipse.aether.repository.NoLocalRepositoryManagerException; 029import org.eclipse.aether.spi.localrepo.LocalRepositoryManagerFactory; 030import org.eclipse.aether.spi.locator.Service; 031import org.eclipse.aether.spi.locator.ServiceLocator; 032import org.eclipse.aether.spi.log.Logger; 033import org.eclipse.aether.spi.log.LoggerFactory; 034import org.eclipse.aether.spi.log.NullLoggerFactory; 035 036/** 037 * Creates local repository managers for repository type {@code "simple"}. 038 */ 039@Named( "simple" ) 040public class SimpleLocalRepositoryManagerFactory 041 implements LocalRepositoryManagerFactory, Service 042{ 043 044 private Logger logger = NullLoggerFactory.LOGGER; 045 046 private float priority; 047 048 public SimpleLocalRepositoryManagerFactory() 049 { 050 // enable no-arg constructor 051 } 052 053 @Inject 054 SimpleLocalRepositoryManagerFactory( LoggerFactory loggerFactory ) 055 { 056 setLoggerFactory( loggerFactory ); 057 } 058 059 public LocalRepositoryManager newInstance( RepositorySystemSession session, LocalRepository repository ) 060 throws NoLocalRepositoryManagerException 061 { 062 if ( "".equals( repository.getContentType() ) || "simple".equals( repository.getContentType() ) ) 063 { 064 return new SimpleLocalRepositoryManager( repository.getBasedir() ).setLogger( logger ); 065 } 066 else 067 { 068 throw new NoLocalRepositoryManagerException( repository ); 069 } 070 } 071 072 public void initService( ServiceLocator locator ) 073 { 074 setLoggerFactory( locator.getService( LoggerFactory.class ) ); 075 } 076 077 public SimpleLocalRepositoryManagerFactory setLoggerFactory( LoggerFactory loggerFactory ) 078 { 079 this.logger = NullLoggerFactory.getSafeLogger( loggerFactory, SimpleLocalRepositoryManager.class ); 080 return this; 081 } 082 083 public float getPriority() 084 { 085 return priority; 086 } 087 088 /** 089 * Sets the priority of this component. 090 * 091 * @param priority The priority. 092 * @return This component for chaining, never {@code null}. 093 */ 094 public SimpleLocalRepositoryManagerFactory setPriority( float priority ) 095 { 096 this.priority = priority; 097 return this; 098 } 099 100}