1 package org.apache.maven.repository.proxy.configuration;
4 * Copyright 2005-2006 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import org.apache.maven.artifact.repository.ArtifactRepository;
20 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
21 import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
22 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
23 import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
24 import org.apache.maven.repository.proxy.repository.ProxyRepository;
27 import java.io.FileInputStream;
28 import java.io.IOException;
29 import java.util.ArrayList;
30 import java.util.Collections;
31 import java.util.Iterator;
32 import java.util.List;
35 * Class to represent the configuration file for the proxy
37 * @author Edwin Punzalan
38 * @plexus.component role="org.apache.maven.repository.proxy.configuration.ProxyConfiguration"
40 public class ProxyConfiguration
42 public static final String ROLE = ProxyConfiguration.class.getName();
47 private ArtifactRepositoryFactory artifactRepositoryFactory;
49 private boolean browsable;
51 private ArtifactRepository repoCache;
53 private List repositories = new ArrayList();
56 * Method to set/unset the web-view of the repository cache
58 * @param browsable set to true to enable the web-view of the proxy repository cache
60 public void setBrowsable( boolean browsable )
62 this.browsable = browsable;
66 * Used to determine if the repsented configuration allows web view of the repository cache
68 * @return true if the repository cache is configured for web view.
70 public boolean isBrowsable()
76 * Used to set the location where the proxy should cache the configured repositories
80 public void setRepositoryCachePath( String path )
82 ArtifactRepositoryPolicy standardPolicy;
83 standardPolicy = new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS,
84 ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE );
86 ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();
88 repoCache = artifactRepositoryFactory.createArtifactRepository( "localCache",
89 "file://" + new File( path ).getAbsolutePath(),
90 layout, standardPolicy, standardPolicy );
94 * Used to retrieve an ArtifactRepository Object of the proxy cache
96 * @return the ArtifactRepository representation of the proxy cache
98 public ArtifactRepository getRepositoryCache()
104 * Used to retrieved the absolute path of the repository cache
106 * @return path to the proxy cache
108 public String getRepositoryCachePath()
110 return repoCache.getBasedir();
114 * Used to add proxied repositories.
116 * @param repository the repository to be proxied
118 public void addRepository( ProxyRepository repository )
120 repositories.add( repository );
124 * Used to retrieve an unmodifyable list of proxied repositories. They returned list determines the search sequence
125 * for retrieving artifacts.
127 * @return a list of ProxyRepository objects representing proxied repositories
129 public List getRepositories()
131 return Collections.unmodifiableList( repositories );
135 * Used to set the list of repositories to be proxied. This replaces any repositories already added to this
136 * configuraion instance. Useful for re-arranging an existing proxied list.
138 * @param repositories
140 public void setRepositories( List repositories )
142 this.repositories = repositories;
146 * Uses maven-proxy classes to read a maven-proxy properties configuration
148 * @param mavenProxyConfigurationFile The location of the maven-proxy configuration file
149 * @throws ValidationException When a problem occured while processing the properties file
150 * @throws IOException When a problem occured while reading the property file
152 public void loadMavenProxyConfiguration( File mavenProxyConfigurationFile )
153 throws ValidationException, IOException
155 MavenProxyPropertyLoader loader = new MavenProxyPropertyLoader();
156 RetrievalComponentConfiguration rcc = loader.load( new FileInputStream( mavenProxyConfigurationFile ) );
158 this.setRepositoryCachePath( rcc.getLocalStore() );
159 this.setBrowsable( rcc.isBrowsable() );
161 List repoList = new ArrayList();
162 ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();
163 for ( Iterator repos = rcc.getRepos().iterator(); repos.hasNext(); )
165 RepoConfiguration repoConfig = (RepoConfiguration) repos.next();
167 //skip local store repo
168 if ( !repoConfig.getKey().equals( "global" ) )
170 ProxyRepository repo = new ProxyRepository( repoConfig.getKey(), repoConfig.getUrl(), layout );
171 repo.setCacheFailures( repoConfig.getCacheFailures() );
172 repo.setCachePeriod( repoConfig.getCachePeriod() );
173 repo.setHardfail( repoConfig.getHardFail() );
175 if ( repoConfig instanceof HttpRepoConfiguration )
177 HttpRepoConfiguration httpRepo = (HttpRepoConfiguration) repoConfig;
178 MavenProxyConfiguration httpProxy = httpRepo.getProxy();
179 repo.setProxy( httpProxy.getHost(), httpProxy.getPort(), httpProxy.getUsername(),
180 httpProxy.getPassword() );
183 repoList.add( repo );
187 this.setRepositories( repoList );