1 package org.apache.maven.archiva.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.archiva.proxy.ProxiedArtifactRepository;
20 import org.apache.maven.artifact.repository.ArtifactRepository;
21 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
22 import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
23 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
24 import org.codehaus.plexus.util.StringUtils;
27 import java.util.ArrayList;
28 import java.util.Iterator;
29 import java.util.List;
33 * Create artifact repositories from a configuration.
35 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
36 * @plexus.component role="org.apache.maven.archiva.configuration.ConfiguredRepositoryFactory"
38 public class DefaultConfiguredRepositoryFactory
39 implements ConfiguredRepositoryFactory
42 * @plexus.requirement role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout"
44 private Map repositoryLayouts;
49 private ArtifactRepositoryFactory repoFactory;
51 public ArtifactRepository createRepository( RepositoryConfiguration configuration )
53 File repositoryDirectory = new File( configuration.getDirectory() );
54 String repoDir = repositoryDirectory.toURI().toString();
56 //workaround for spaces non converted by PathUtils in wagon
57 //todo: remove it when PathUtils will be fixed
58 if ( repoDir.indexOf( "%20" ) >= 0 )
60 repoDir = StringUtils.replace( repoDir, "%20", " " );
63 ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) repositoryLayouts.get( configuration.getLayout() );
64 return repoFactory.createArtifactRepository( configuration.getId(), repoDir, layout, null, null );
67 public ProxiedArtifactRepository createProxiedRepository( ProxiedRepositoryConfiguration configuration )
69 boolean enabled = isEnabled( configuration.getSnapshotsPolicy() );
71 getUpdatePolicy( configuration.getSnapshotsPolicy(), configuration.getSnapshotsInterval() );
72 ArtifactRepositoryPolicy snapshotsPolicy =
73 new ArtifactRepositoryPolicy( enabled, updatePolicy, ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL );
75 enabled = isEnabled( configuration.getReleasesPolicy() );
76 updatePolicy = getUpdatePolicy( configuration.getReleasesPolicy(), configuration.getReleasesInterval() );
77 ArtifactRepositoryPolicy releasesPolicy =
78 new ArtifactRepositoryPolicy( enabled, updatePolicy, ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL );
80 ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) repositoryLayouts.get( configuration.getLayout() );
84 throw new IllegalArgumentException( "Invalid layout: " + configuration.getLayout() );
87 ArtifactRepository artifactRepository = repoFactory.createArtifactRepository( configuration.getId(),
88 configuration.getUrl(), layout,
89 snapshotsPolicy, releasesPolicy );
90 ProxiedArtifactRepository repository = new ProxiedArtifactRepository( artifactRepository );
91 repository.setCacheFailures( configuration.isCacheFailures() );
92 repository.setHardFail( configuration.isHardFail() );
93 repository.setName( configuration.getName() );
94 repository.setUseNetworkProxy( configuration.isUseNetworkProxy() );
98 public List createRepositories( Configuration configuration )
100 List managedRepositories = configuration.getRepositories();
101 List repositories = new ArrayList( managedRepositories.size() );
103 for ( Iterator i = managedRepositories.iterator(); i.hasNext(); )
105 repositories.add( createRepository( (RepositoryConfiguration) i.next() ) );
111 public List createProxiedRepositories( Configuration configuration )
113 List proxiedRepositories = configuration.getProxiedRepositories();
114 List repositories = new ArrayList( proxiedRepositories.size() );
116 for ( Iterator i = proxiedRepositories.iterator(); i.hasNext(); )
118 repositories.add( createProxiedRepository( (ProxiedRepositoryConfiguration) i.next() ) );
124 public ArtifactRepository createLocalRepository( Configuration configuration )
126 ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) repositoryLayouts.get( "default" );
127 File localRepository = new File( configuration.getLocalRepository() );
128 localRepository.mkdirs();
129 return repoFactory.createArtifactRepository( "local", localRepository.toURI().toString(), layout, null, null );
132 private static String getUpdatePolicy( String policy, int interval )
134 return "interval".equals( policy ) ? policy + ":" + interval : policy;
137 private static boolean isEnabled( String policy )
139 return !"disabled".equals( policy );