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; 030 031import static java.util.Objects.requireNonNull; 032 033/** 034 * Creates local repository managers for repository type {@code "simple"}. 035 */ 036@Singleton 037@Named(SimpleLocalRepositoryManagerFactory.NAME) 038public class SimpleLocalRepositoryManagerFactory implements LocalRepositoryManagerFactory { 039 public static final String NAME = "simple"; 040 private float priority; 041 042 private final LocalPathComposer localPathComposer; 043 044 /** 045 * No-arg constructor, as "simple" local repository is meant mainly for use in tests. 046 */ 047 public SimpleLocalRepositoryManagerFactory() { 048 this.localPathComposer = new DefaultLocalPathComposer(); 049 } 050 051 @Inject 052 public SimpleLocalRepositoryManagerFactory(final LocalPathComposer localPathComposer) { 053 this.localPathComposer = requireNonNull(localPathComposer); 054 } 055 056 @Override 057 public LocalRepositoryManager newInstance(RepositorySystemSession session, LocalRepository repository) 058 throws NoLocalRepositoryManagerException { 059 requireNonNull(session, "session cannot be null"); 060 requireNonNull(repository, "repository cannot be null"); 061 062 if ("".equals(repository.getContentType()) || "simple".equals(repository.getContentType())) { 063 return new SimpleLocalRepositoryManager(repository.getBasePath(), "simple", localPathComposer); 064 } else { 065 throw new NoLocalRepositoryManagerException(repository); 066 } 067 } 068 069 @Override 070 public float getPriority() { 071 return priority; 072 } 073 074 /** 075 * Sets the priority of this component. 076 * 077 * @param priority The priority. 078 * @return This component for chaining, never {@code null}. 079 */ 080 public SimpleLocalRepositoryManagerFactory setPriority(float priority) { 081 this.priority = priority; 082 return this; 083 } 084}