001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.eclipse.aether.internal.impl; 020 021import javax.inject.Inject; 022import javax.inject.Named; 023import javax.inject.Singleton; 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; 032 033import static java.util.Objects.requireNonNull; 034 035/** 036 * Creates local repository managers for repository type {@code "simple"}. 037 */ 038@Singleton 039@Named("simple") 040public class SimpleLocalRepositoryManagerFactory implements LocalRepositoryManagerFactory, Service { 041 private float priority; 042 043 private LocalPathComposer localPathComposer; 044 045 @Deprecated 046 public SimpleLocalRepositoryManagerFactory() { 047 // enable no-arg constructor 048 this.localPathComposer = new DefaultLocalPathComposer(); // maven UTs needs this 049 } 050 051 @Inject 052 public SimpleLocalRepositoryManagerFactory(final LocalPathComposer localPathComposer) { 053 this.localPathComposer = requireNonNull(localPathComposer); 054 } 055 056 @Override 057 public void initService(final ServiceLocator locator) { 058 this.localPathComposer = requireNonNull(locator.getService(LocalPathComposer.class)); 059 } 060 061 @Override 062 public LocalRepositoryManager newInstance(RepositorySystemSession session, LocalRepository repository) 063 throws NoLocalRepositoryManagerException { 064 requireNonNull(session, "session cannot be null"); 065 requireNonNull(repository, "repository cannot be null"); 066 067 if ("".equals(repository.getContentType()) || "simple".equals(repository.getContentType())) { 068 return new SimpleLocalRepositoryManager(repository.getBasedir(), "simple", localPathComposer); 069 } else { 070 throw new NoLocalRepositoryManagerException(repository); 071 } 072 } 073 074 @Override 075 public float getPriority() { 076 return priority; 077 } 078 079 /** 080 * Sets the priority of this component. 081 * 082 * @param priority The priority. 083 * @return This component for chaining, never {@code null}. 084 */ 085 public SimpleLocalRepositoryManagerFactory setPriority(float priority) { 086 this.priority = priority; 087 return this; 088 } 089}