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.filter; 020 021import javax.inject.Inject; 022import javax.inject.Named; 023import javax.inject.Singleton; 024 025import org.eclipse.aether.RepositorySystemSession; 026import org.eclipse.aether.impl.RemoteRepositoryFilterManager; 027import org.eclipse.aether.repository.RemoteRepository; 028import org.eclipse.aether.spi.connector.PipelineRepositoryConnectorFactory; 029import org.eclipse.aether.spi.connector.RepositoryConnector; 030import org.eclipse.aether.spi.connector.filter.RemoteRepositoryFilter; 031 032import static java.util.Objects.requireNonNull; 033 034/** 035 * A filtering connector factory. 036 * 037 * @since 2.0.8 038 */ 039@Singleton 040@Named(FilteringPipelineRepositoryConnectorFactory.NAME) 041public final class FilteringPipelineRepositoryConnectorFactory implements PipelineRepositoryConnectorFactory { 042 public static final String NAME = "rrf"; 043 044 private final RemoteRepositoryFilterManager remoteRepositoryFilterManager; 045 046 /** 047 * This connector should be usually the right-most in pipeline. 048 */ 049 private float priority = 10000; 050 051 @Inject 052 public FilteringPipelineRepositoryConnectorFactory(RemoteRepositoryFilterManager remoteRepositoryFilterManager) { 053 this.remoteRepositoryFilterManager = requireNonNull(remoteRepositoryFilterManager); 054 } 055 056 @Override 057 public RepositoryConnector newInstance( 058 RepositorySystemSession session, RemoteRepository repository, RepositoryConnector delegate) { 059 RemoteRepositoryFilter filter = remoteRepositoryFilterManager.getRemoteRepositoryFilter(session); 060 if (filter != null) { 061 return new FilteringRepositoryConnector(repository, delegate, filter); 062 } else { 063 return delegate; 064 } 065 } 066 067 @Override 068 public float getPriority() { 069 return priority; 070 } 071 072 public FilteringPipelineRepositoryConnectorFactory setPriority(float priority) { 073 this.priority = priority; 074 return this; 075 } 076}