org.apache.archiva.proxy
Class DefaultRepositoryProxyConnectors

java.lang.Object
  extended by org.apache.archiva.proxy.DefaultRepositoryProxyConnectors
All Implemented Interfaces:
RepositoryProxyConnectors, org.apache.archiva.redback.components.registry.RegistryListener

@Service(value="repositoryProxyConnectors#default")
public class DefaultRepositoryProxyConnectors
extends Object
implements RepositoryProxyConnectors, org.apache.archiva.redback.components.registry.RegistryListener

DefaultRepositoryProxyConnectors

To Do:
exception handling needs work - "not modified" is not really an exceptional case, and it has more layers than your average brown onion

Field Summary
private  ArchivaConfiguration archivaConfiguration
           
private  Map<String,DownloadErrorPolicy> downloadErrorPolicies
           
private  org.slf4j.Logger log
           
private  MetadataTools metadataTools
           
private  NetworkProxyAdmin networkProxyAdmin
           
private  Map<String,org.apache.maven.wagon.proxy.ProxyInfo> networkProxyMap
           
private  Map<String,PostDownloadPolicy> postDownloadPolicies
           
private  Map<String,PreDownloadPolicy> preDownloadPolicies
           
private  Map<String,List<ProxyConnector>> proxyConnectorMap
           
private  RepositoryContentFactory repositoryFactory
           
private  ArchivaTaskScheduler scheduler
           
private  UrlFailureCache urlFailureCache
           
private  WagonFactory wagonFactory
           
 
Constructor Summary
DefaultRepositoryProxyConnectors()
           
 
Method Summary
protected  String addParameters(String path, RemoteRepository remoteRepository)
           
 void afterConfigurationChange(org.apache.archiva.redback.components.registry.Registry registry, String propertyName, Object propertyValue)
           
 void beforeConfigurationChange(org.apache.archiva.redback.components.registry.Registry registry, String propertyName, Object propertyValue)
           
private  boolean connectToRepository(ProxyConnector connector, org.apache.maven.wagon.Wagon wagon, RemoteRepositoryContent remoteRepository)
          Using wagon, connect to the remote repository.
private  File createWorkingDirectory(ManagedRepositoryContent repository)
          Creates a working directory
 File fetchFromProxies(ManagedRepositoryContent repository, ArtifactReference artifact)
          Performs the artifact fetch operation against the target repositories of the provided source repository.
 File fetchFromProxies(ManagedRepositoryContent repository, String path)
          Performs the fetch operation against the target repositories of the provided source repository.
 File fetchMetatadaFromProxies(ManagedRepositoryContent repository, String logicalPath)
          Performs the metadata fetch operation against the target repositories of the provided source repository.
private  boolean fileExists(File file)
          Simple method to test if the file exists on the local disk.
private  List<ProxyConnectorRuleConfiguration> findProxyConnectorRules(String sourceRepository, String targetRepository, List<ProxyConnectorRuleConfiguration> all)
           
 ArchivaConfiguration getArchivaConfiguration()
           
 Map<String,DownloadErrorPolicy> getDownloadErrorPolicies()
           
private  long getLastModified(File file)
           
 MetadataTools getMetadataTools()
           
 Map<String,PostDownloadPolicy> getPostDownloadPolicies()
           
 Map<String,PreDownloadPolicy> getPreDownloadPolicies()
           
 List<ProxyConnector> getProxyConnectors(ManagedRepositoryContent repository)
          TODO: Ensure that list is correctly ordered based on configuration.
 RepositoryContentFactory getRepositoryFactory()
           
 UrlFailureCache getUrlFailureCache()
           
 WagonFactory getWagonFactory()
           
private  boolean hasBeenUpdated(File file, long originalLastModified)
           
 boolean hasProxies(ManagedRepositoryContent repository)
          Test if the provided ManagedRepositoryContent has any proxies configured for it.
private  void initConnectorsAndNetworkProxies()
           
 void initialize()
           
private  boolean matchesPattern(String path, List<String> patterns)
          Tests whitelist and blacklist patterns against path.
private  void moveFileIfExists(File fileToMove, File directory)
          Moves the file into repository location if it exists
private  void moveTempToTarget(File temp, File target)
          Used to move the temporary file to its real destination.
private  void queueRepositoryTask(String repositoryId, File localFile)
           
 void setArchivaConfiguration(ArchivaConfiguration archivaConfiguration)
           
 void setDownloadErrorPolicies(Map<String,DownloadErrorPolicy> downloadErrorPolicies)
           
 void setMetadataTools(MetadataTools metadataTools)
           
 void setPostDownloadPolicies(Map<String,PostDownloadPolicy> postDownloadPolicies)
           
 void setPreDownloadPolicies(Map<String,PreDownloadPolicy> preDownloadPolicies)
           
 void setRepositoryFactory(RepositoryContentFactory repositoryFactory)
           
 void setUrlFailureCache(UrlFailureCache urlFailureCache)
           
 void setWagonFactory(WagonFactory wagonFactory)
           
private  File toLocalFile(ManagedRepositoryContent repository, ArtifactReference artifact)
           
private  File toLocalRepoFile(ManagedRepositoryContent repository, RemoteRepositoryContent targetRepository, String targetPath)
           
private  void transferArtifact(org.apache.maven.wagon.Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath, ManagedRepositoryContent repository, File resource, File tmpDirectory, File destFile)
           
private  void transferChecksum(org.apache.maven.wagon.Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath, ManagedRepositoryContent repository, File resource, File tmpDirectory, String ext, File destFile)
           Quietly transfer the checksum file from the remote repository to the local file.
private  File transferFile(ProxyConnector connector, RemoteRepositoryContent remoteRepository, String remotePath, ManagedRepositoryContent repository, File resource, Properties requestProperties, boolean executeConsumers)
          Perform the transfer of the file.
protected  void transferResources(ProxyConnector connector, RemoteRepositoryContent remoteRepository, File tmpMd5, File tmpSha1, File tmpResource, String url, String remotePath, File resource, File workingDirectory, ManagedRepositoryContent repository)
           
private  void transferSimpleFile(org.apache.maven.wagon.Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath, ManagedRepositoryContent repository, File origFile, File destFile)
          Perform the transfer of the remote file to the local file specified.
private  void validatePolicies(Map<String,? extends DownloadPolicy> policies, Map<String,String> settings, Properties request, File localFile)
          Apply the policies.
private  void validatePolicies(Map<String,DownloadErrorPolicy> policies, Map<String,String> settings, Properties request, ArtifactReference artifact, RemoteRepositoryContent content, File localFile, Exception exception, Map<String,Exception> previousExceptions)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private org.slf4j.Logger log

archivaConfiguration

@Inject
@Named(value="archivaConfiguration#default")
private ArchivaConfiguration archivaConfiguration

repositoryFactory

@Inject
@Named(value="repositoryContentFactory#default")
private RepositoryContentFactory repositoryFactory

metadataTools

@Inject
@Named(value="metadataTools#default")
private MetadataTools metadataTools

preDownloadPolicies

@Inject
private Map<String,PreDownloadPolicy> preDownloadPolicies

postDownloadPolicies

@Inject
private Map<String,PostDownloadPolicy> postDownloadPolicies

downloadErrorPolicies

@Inject
private Map<String,DownloadErrorPolicy> downloadErrorPolicies

urlFailureCache

@Inject
private UrlFailureCache urlFailureCache

proxyConnectorMap

private Map<String,List<ProxyConnector>> proxyConnectorMap

networkProxyMap

private Map<String,org.apache.maven.wagon.proxy.ProxyInfo> networkProxyMap

wagonFactory

@Inject
private WagonFactory wagonFactory

scheduler

@Inject
@Named(value="archivaTaskScheduler#repository")
private ArchivaTaskScheduler scheduler

networkProxyAdmin

@Inject
private NetworkProxyAdmin networkProxyAdmin
Constructor Detail

DefaultRepositoryProxyConnectors

public DefaultRepositoryProxyConnectors()
Method Detail

initialize

@PostConstruct
public void initialize()

initConnectorsAndNetworkProxies

private void initConnectorsAndNetworkProxies()

findProxyConnectorRules

private List<ProxyConnectorRuleConfiguration> findProxyConnectorRules(String sourceRepository,
                                                                      String targetRepository,
                                                                      List<ProxyConnectorRuleConfiguration> all)

fetchFromProxies

public File fetchFromProxies(ManagedRepositoryContent repository,
                             ArtifactReference artifact)
                      throws ProxyDownloadException
Description copied from interface: RepositoryProxyConnectors
Performs the artifact fetch operation against the target repositories of the provided source repository. If the artifact is found, it is downloaded and placed into the source repository filesystem.

Specified by:
fetchFromProxies in interface RepositoryProxyConnectors
Parameters:
repository - the source repository to use. (must be a managed repository)
artifact - the artifact to fetch.
Returns:
the file that was obtained, or null if no content was obtained
Throws:
ProxyDownloadException - if there was a problem fetching the content from the target repositories.

fetchFromProxies

public File fetchFromProxies(ManagedRepositoryContent repository,
                             String path)
Description copied from interface: RepositoryProxyConnectors
Performs the fetch operation against the target repositories of the provided source repository.

Specified by:
fetchFromProxies in interface RepositoryProxyConnectors
Parameters:
repository - the source repository to use. (must be a managed repository)
path - the path of the resource to fetch
Returns:
the file that was obtained, or null if no content was obtained

fetchMetatadaFromProxies

public File fetchMetatadaFromProxies(ManagedRepositoryContent repository,
                                     String logicalPath)
Description copied from interface: RepositoryProxyConnectors
Performs the metadata fetch operation against the target repositories of the provided source repository. If the metadata is found, it is downloaded and placed into the source repository filesystem.

Specified by:
fetchMetatadaFromProxies in interface RepositoryProxyConnectors
Parameters:
repository - the source repository to use. (must be a managed repository)
logicalPath - the metadata to fetch.
Returns:
the file that was obtained, or null if no content was obtained

transferResources

protected void transferResources(ProxyConnector connector,
                                 RemoteRepositoryContent remoteRepository,
                                 File tmpMd5,
                                 File tmpSha1,
                                 File tmpResource,
                                 String url,
                                 String remotePath,
                                 File resource,
                                 File workingDirectory,
                                 ManagedRepositoryContent repository)
                          throws ProxyException,
                                 NotModifiedException,
                                 RepositoryAdminException
Parameters:
connector -
remoteRepository -
tmpMd5 -
tmpSha1 -
tmpResource -
url -
remotePath -
resource -
workingDirectory -
repository -
Throws:
ProxyException
NotModifiedException
RepositoryAdminException

transferArtifact

private void transferArtifact(org.apache.maven.wagon.Wagon wagon,
                              RemoteRepositoryContent remoteRepository,
                              String remotePath,
                              ManagedRepositoryContent repository,
                              File resource,
                              File tmpDirectory,
                              File destFile)
                       throws ProxyException
Throws:
ProxyException

getLastModified

private long getLastModified(File file)

hasBeenUpdated

private boolean hasBeenUpdated(File file,
                               long originalLastModified)

toLocalRepoFile

private File toLocalRepoFile(ManagedRepositoryContent repository,
                             RemoteRepositoryContent targetRepository,
                             String targetPath)

hasProxies

public boolean hasProxies(ManagedRepositoryContent repository)
Test if the provided ManagedRepositoryContent has any proxies configured for it.

Specified by:
hasProxies in interface RepositoryProxyConnectors
Parameters:
repository - the source repository to look for.
Returns:
true if there are proxy connectors that use the provided repository as a source repository.

toLocalFile

private File toLocalFile(ManagedRepositoryContent repository,
                         ArtifactReference artifact)

fileExists

private boolean fileExists(File file)
Simple method to test if the file exists on the local disk.

Parameters:
file - the file to test. (may be null)
Returns:
true if file exists. false if the file param is null, doesn't exist, or is not of type File.

transferFile

private File transferFile(ProxyConnector connector,
                          RemoteRepositoryContent remoteRepository,
                          String remotePath,
                          ManagedRepositoryContent repository,
                          File resource,
                          Properties requestProperties,
                          boolean executeConsumers)
                   throws ProxyException,
                          NotModifiedException,
                          RepositoryAdminException
Perform the transfer of the file.

Parameters:
connector - the connector configuration to use.
remoteRepository - the remote repository get the resource from.
remotePath - the path in the remote repository to the resource to get.
repository - the managed repository that will hold the file
resource - the local file to place the downloaded resource into
requestProperties - the request properties to utilize for policy handling.
executeConsumers - whether to execute the consumers after proxying
Returns:
the local file that was downloaded, or null if not downloaded.
Throws:
NotFoundException - if the file was not found on the remote repository.
NotModifiedException - if the localFile was present, and the resource was present on remote repository, but the remote resource is not newer than the local File.
ProxyException - if transfer was unsuccessful.
RepositoryAdminException

queueRepositoryTask

private void queueRepositoryTask(String repositoryId,
                                 File localFile)

moveFileIfExists

private void moveFileIfExists(File fileToMove,
                              File directory)
                       throws ProxyException
Moves the file into repository location if it exists

Parameters:
fileToMove - this could be either the main artifact, sha1 or md5 checksum file.
directory - directory to write files to
Throws:
ProxyException

transferChecksum

private void transferChecksum(org.apache.maven.wagon.Wagon wagon,
                              RemoteRepositoryContent remoteRepository,
                              String remotePath,
                              ManagedRepositoryContent repository,
                              File resource,
                              File tmpDirectory,
                              String ext,
                              File destFile)
                       throws ProxyException

Quietly transfer the checksum file from the remote repository to the local file.

Parameters:
wagon - the wagon instance (should already be connected) to use.
remoteRepository - the remote repository to transfer from.
remotePath - the remote path to the resource to get.
repository - the managed repository that will hold the file
resource - the local file that should contain the downloaded contents
tmpDirectory - the temporary directory to download to
ext - the type of checksum to transfer (example: ".md5" or ".sha1")
Throws:
ProxyException - if copying the downloaded file into place did not succeed.

transferSimpleFile

private void transferSimpleFile(org.apache.maven.wagon.Wagon wagon,
                                RemoteRepositoryContent remoteRepository,
                                String remotePath,
                                ManagedRepositoryContent repository,
                                File origFile,
                                File destFile)
                         throws ProxyException
Perform the transfer of the remote file to the local file specified.

Parameters:
wagon - the wagon instance to use.
remoteRepository - the remote repository to use
remotePath - the remote path to attempt to get
repository - the managed repository that will hold the file
origFile - the local file to save to
Throws:
ProxyException - if there was a problem moving the downloaded file into place.
org.apache.maven.wagon.WagonException - if there was a problem tranfering the file.

validatePolicies

private void validatePolicies(Map<String,? extends DownloadPolicy> policies,
                              Map<String,String> settings,
                              Properties request,
                              File localFile)
                       throws PolicyViolationException
Apply the policies.

Parameters:
policies - the map of policies to execute. (Map of String policy keys, to DownloadPolicy objects)
settings - the map of settings for the policies to execute. (Map of String policy keys, to String policy setting)
request - the request properties (utilized by the DownloadPolicy.applyPolicy(String, Properties, File) )
localFile - the local file (utilized by the DownloadPolicy.applyPolicy(String, Properties, File))
Throws:
PolicyViolationException

validatePolicies

private void validatePolicies(Map<String,DownloadErrorPolicy> policies,
                              Map<String,String> settings,
                              Properties request,
                              ArtifactReference artifact,
                              RemoteRepositoryContent content,
                              File localFile,
                              Exception exception,
                              Map<String,Exception> previousExceptions)
                       throws ProxyDownloadException
Throws:
ProxyDownloadException

createWorkingDirectory

private File createWorkingDirectory(ManagedRepositoryContent repository)
Creates a working directory

Parameters:
repository -
Returns:
file location of working directory
Throws:
IOException

moveTempToTarget

private void moveTempToTarget(File temp,
                              File target)
                       throws ProxyException
Used to move the temporary file to its real destination. This is patterned from the way WagonManager handles its downloaded files.

Parameters:
temp - The completed download file
target - The final location of the downloaded file
Throws:
ProxyException - when the temp file cannot replace the target file

connectToRepository

private boolean connectToRepository(ProxyConnector connector,
                                    org.apache.maven.wagon.Wagon wagon,
                                    RemoteRepositoryContent remoteRepository)
Using wagon, connect to the remote repository.

Parameters:
connector - the connector configuration to utilize (for obtaining network proxy configuration from)
wagon - the wagon instance to establish the connection on.
remoteRepository - the remote repository to connect to.
Returns:
true if the connection was successful. false if not connected.

matchesPattern

private boolean matchesPattern(String path,
                               List<String> patterns)
Tests whitelist and blacklist patterns against path.

Parameters:
path - the path to test.
patterns - the list of patterns to check.
Returns:
true if the path matches at least 1 pattern in the provided patterns list.

getProxyConnectors

public List<ProxyConnector> getProxyConnectors(ManagedRepositoryContent repository)
TODO: Ensure that list is correctly ordered based on configuration. See MRM-477

Specified by:
getProxyConnectors in interface RepositoryProxyConnectors
Parameters:
repository - the source repository to look for.
Returns:
the List of ProxyConnector objects.

afterConfigurationChange

public void afterConfigurationChange(org.apache.archiva.redback.components.registry.Registry registry,
                                     String propertyName,
                                     Object propertyValue)
Specified by:
afterConfigurationChange in interface org.apache.archiva.redback.components.registry.RegistryListener

addParameters

protected String addParameters(String path,
                               RemoteRepository remoteRepository)

beforeConfigurationChange

public void beforeConfigurationChange(org.apache.archiva.redback.components.registry.Registry registry,
                                      String propertyName,
                                      Object propertyValue)
Specified by:
beforeConfigurationChange in interface org.apache.archiva.redback.components.registry.RegistryListener

getArchivaConfiguration

public ArchivaConfiguration getArchivaConfiguration()

setArchivaConfiguration

public void setArchivaConfiguration(ArchivaConfiguration archivaConfiguration)

getRepositoryFactory

public RepositoryContentFactory getRepositoryFactory()

setRepositoryFactory

public void setRepositoryFactory(RepositoryContentFactory repositoryFactory)

getMetadataTools

public MetadataTools getMetadataTools()

setMetadataTools

public void setMetadataTools(MetadataTools metadataTools)

getUrlFailureCache

public UrlFailureCache getUrlFailureCache()

setUrlFailureCache

public void setUrlFailureCache(UrlFailureCache urlFailureCache)

getWagonFactory

public WagonFactory getWagonFactory()

setWagonFactory

public void setWagonFactory(WagonFactory wagonFactory)

getPreDownloadPolicies

public Map<String,PreDownloadPolicy> getPreDownloadPolicies()

setPreDownloadPolicies

public void setPreDownloadPolicies(Map<String,PreDownloadPolicy> preDownloadPolicies)

getPostDownloadPolicies

public Map<String,PostDownloadPolicy> getPostDownloadPolicies()

setPostDownloadPolicies

public void setPostDownloadPolicies(Map<String,PostDownloadPolicy> postDownloadPolicies)

getDownloadErrorPolicies

public Map<String,DownloadErrorPolicy> getDownloadErrorPolicies()

setDownloadErrorPolicies

public void setDownloadErrorPolicies(Map<String,DownloadErrorPolicy> downloadErrorPolicies)


Copyright © 2006-2013 The Apache Software Foundation. All Rights Reserved.