Package org.sonatype.aether.util.repository

Source Code of org.sonatype.aether.util.repository.ConservativeProxySelector

package org.sonatype.aether.util.repository;

/*******************************************************************************
* Copyright (c) 2010-2011 Sonatype, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
* The Eclipse Public License is available at
*   http://www.eclipse.org/legal/epl-v10.html
* The Apache License v2.0 is available at
*   http://www.apache.org/licenses/LICENSE-2.0.html
* You may elect to redistribute this code under either of these licenses.
*******************************************************************************/

import org.sonatype.aether.repository.Proxy;
import org.sonatype.aether.repository.ProxySelector;
import org.sonatype.aether.repository.RemoteRepository;

/**
* A proxy selector that delegates to another selector but only if a repository has no proxy yet. If a proxy has already
* been assigned to a repository, that is selected.
*
* @author Benjamin Bentmann
*/
public class ConservativeProxySelector
    implements ProxySelector
{

    private final ProxySelector selector;

    /**
     * Creates a new selector that delegates to the specified selector.
     *
     * @param selector The selector to delegate to in case a repository has no proxy yet, must not be {@code null}.
     */
    public ConservativeProxySelector( ProxySelector selector )
    {
        if ( selector == null )
        {
            throw new IllegalArgumentException( "no proxy selector specified" );
        }
        this.selector = selector;
    }

    public Proxy getProxy( RemoteRepository repository )
    {
        Proxy proxy = repository.getProxy();
        if ( proxy != null )
        {
            return proxy;
        }
        return selector.getProxy( repository );
    }

}
TOP

Related Classes of org.sonatype.aether.util.repository.ConservativeProxySelector

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.