1 package org.apache.archiva.proxy.model;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.archiva.model.ArtifactReference;
23 import org.apache.archiva.policies.Policy;
24 import org.apache.archiva.policies.ProxyDownloadException;
25 import org.apache.archiva.repository.ManagedRepository;
26 import org.apache.archiva.repository.RepositoryType;
27 import org.apache.archiva.repository.storage.StorageAsset;
29 import java.util.List;
33 * A repository proxy handler is used to fetch remote artifacts from different remote repositories.
34 * A proxy handler is connected to one managed repository and a list of remote repositories.
36 * Repository proxies should not be confused with network proxies. Network are proxies for specific network protocols,
37 * like HTTP. A repository proxy delegates the repository requests to remote repositories and caches artifacts.
39 * If a artifact is requested for the managed repository and the artifact is not cached locally, the handler goes through
40 * the list of remotes and tries to download the artifact. If a download was successful the artifact is cached locally.
42 * The connection between managed and remote repositories is defined by list of {@link ProxyConnector} each defines a one-to-one relationship.
44 * A proxy connector defines specifics about the download behaviour:
46 * <li>Policies {@link org.apache.archiva.policies.Policy} define the behaviour for different cases (errors, not available, caching lifetime).</li>
47 * <li>Black- and Whitelists are used to ban or allow certain paths on the remote repositories.
50 * The policies and black- and whitelist are set on the {@link ProxyConnector}
52 * There may be network proxies needed to connect the remote repositories.
55 public interface RepositoryProxyHandler
58 List<RepositoryType> supports( );
61 * Performs the artifact fetch operation against the target repositories
62 * of the provided source repository.
64 * If the artifact is found, it is downloaded and placed into the source repository
67 * @param repository the source repository to use. (must be a managed repository)
68 * @param artifact the artifact to fetch.
69 * @return the file that was obtained, or null if no content was obtained
70 * @throws ProxyDownloadException if there was a problem fetching the content from the target repositories.
72 StorageAsset fetchFromProxies( ManagedRepository repository, ArtifactReference artifact )
73 throws ProxyDownloadException;
76 * Performs the metadata fetch operation against the target repositories
77 * of the provided source repository.
79 * If the metadata is found, it is downloaded and placed into the source repository
82 * @param repository the source repository to use. (must be a managed repository)
83 * @param logicalPath the metadata to fetch.
84 * @return the file that was obtained, or null if no content was obtained
86 ProxyFetchResult fetchMetadataFromProxies( ManagedRepository repository, String logicalPath );
89 * Performs the fetch operation against the target repositories
90 * of the provided source repository by a specific path.
92 * @param managedRepository the source repository to use. (must be a managed repository)
93 * @param path the path of the resource to fetch
94 * @return the file that was obtained, or null if no content was obtained
96 StorageAsset fetchFromProxies( ManagedRepository managedRepository, String path );
99 * Get the List of {@link ProxyConnector} objects of the source repository.
101 * @param repository the source repository to look for.
102 * @return the List of {@link ProxyConnector} objects.
104 List<ProxyConnector> getProxyConnectors( ManagedRepository repository );
107 * Tests to see if the provided repository is a source repository for
108 * any {@link ProxyConnector} objects.
110 * @param repository the source repository to look for.
111 * @return true if there are proxy connectors that use the provided
112 * repository as a source repository.
114 boolean hasProxies( ManagedRepository repository );
117 * Sets network proxies (normally HTTP proxies) to access the remote repositories.
119 * @param networkProxies A map of (repository id, network proxy) where the repository id must be the id of an
120 * existing remote repository.
122 void setNetworkProxies( Map<String, NetworkProxy> networkProxies );
125 * Adds a network proxy that is used to access the remote repository.
127 * @param id The repository id
128 * @param networkProxy The network proxy to use
130 void addNetworkproxy( String id, NetworkProxy networkProxy);
133 * Returns a map of the defined network proxies, or a empty map, if no proxy is defined.
135 * @return A map (repository id, network proxy). If none is defined, a empty map is returned.
137 Map<String, NetworkProxy> getNetworkProxies( );
140 * Returns the network proxy that is defined for the given repository id.
141 * @param id The remote repository id
142 * @return A network proxy or <code>null</code> if no one is defined for this id.
144 NetworkProxy getNetworkProxy( String id );
147 * Returns the proxy handler implementation. This can be used, if the underlying implementation for a specific
148 * repository type is needed.
150 * @param clazz The class to convert to
151 * @param <T> The type
152 * @return The handler
154 <T extends RepositoryProxyHandler> T getHandler( Class<T> clazz ) throws IllegalArgumentException;
157 * Sets the policies that this handler should validate.
160 void setPolicies(List<Policy> policyList);
166 void addPolicy( Policy policy );
172 void removePolicy( Policy policy );
174 void addProxyConnector(ProxyConnector connector);
176 void setProxyConnectors( List<ProxyConnector> proxyConnectors );