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.collect; 020 021import javax.inject.Inject; 022import javax.inject.Named; 023import javax.inject.Singleton; 024 025import java.util.Map; 026 027import org.eclipse.aether.RepositorySystemSession; 028import org.eclipse.aether.collection.CollectRequest; 029import org.eclipse.aether.collection.CollectResult; 030import org.eclipse.aether.collection.DependencyCollectionException; 031import org.eclipse.aether.impl.DependencyCollector; 032import org.eclipse.aether.util.ConfigUtils; 033 034import static java.util.Objects.requireNonNull; 035 036/** 037 * Default implementation of {@link DependencyCollector} that merely indirect to selected delegate. 038 */ 039@Singleton 040@Named 041public class DefaultDependencyCollector implements DependencyCollector { 042 private static final String CONFIG_PROP_COLLECTOR_IMPL = "aether.dependencyCollector.impl"; 043 044 private static final String DEFAULT_COLLECTOR_IMPL = 045 org.eclipse.aether.internal.impl.collect.bf.BfDependencyCollector.NAME; 046 047 private final Map<String, DependencyCollectorDelegate> delegates; 048 049 @Inject 050 public DefaultDependencyCollector(Map<String, DependencyCollectorDelegate> delegates) { 051 this.delegates = requireNonNull(delegates); 052 } 053 054 @Override 055 public CollectResult collectDependencies(RepositorySystemSession session, CollectRequest request) 056 throws DependencyCollectionException { 057 String delegateName = ConfigUtils.getString(session, DEFAULT_COLLECTOR_IMPL, CONFIG_PROP_COLLECTOR_IMPL); 058 DependencyCollectorDelegate delegate = delegates.get(delegateName); 059 if (delegate == null) { 060 throw new IllegalArgumentException( 061 "Unknown collector impl: '" + delegateName + "', known implementations are " + delegates.keySet()); 062 } 063 return delegate.collectDependencies(session, request); 064 } 065}