1 package org.apache.maven.repository.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.repository.proxy.ProxiedArtifactRepository;
26 import java.util.ArrayList;
27 import java.util.Iterator;
28 import java.util.List;
32 * Create artifact repositories from a configuration.
34 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
35 * @plexus.component role="org.apache.maven.repository.configuration.ConfiguredRepositoryFactory"
37 public class DefaultConfiguredRepositoryFactory
38 implements ConfiguredRepositoryFactory
41 * @plexus.requirement role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout"
43 private Map repositoryLayouts;
48 private ArtifactRepositoryFactory repoFactory;
50 public ArtifactRepository createRepository( RepositoryConfiguration configuration )
52 File repositoryDirectory = new File( configuration.getDirectory() );
53 String repoDir = repositoryDirectory.toURI().toString();
55 ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) repositoryLayouts.get( configuration.getLayout() );
56 return repoFactory.createArtifactRepository( configuration.getId(), repoDir, layout, null, null );
59 public ProxiedArtifactRepository createProxiedRepository( ProxiedRepositoryConfiguration configuration )
61 boolean enabled = isEnabled( configuration.getSnapshotsPolicy() );
63 getUpdatePolicy( configuration.getSnapshotsPolicy(), configuration.getSnapshotsInterval() );
64 ArtifactRepositoryPolicy snapshotsPolicy =
65 new ArtifactRepositoryPolicy( enabled, updatePolicy, ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL );
67 enabled = isEnabled( configuration.getReleasesPolicy() );
68 updatePolicy = getUpdatePolicy( configuration.getReleasesPolicy(), configuration.getReleasesInterval() );
69 ArtifactRepositoryPolicy releasesPolicy =
70 new ArtifactRepositoryPolicy( enabled, updatePolicy, ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL );
72 ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) repositoryLayouts.get( configuration.getLayout() );
73 ArtifactRepository artifactRepository = repoFactory.createArtifactRepository( configuration.getId(),
74 configuration.getUrl(), layout,
75 snapshotsPolicy, releasesPolicy );
76 ProxiedArtifactRepository repository = new ProxiedArtifactRepository( artifactRepository );
77 repository.setCacheFailures( configuration.isCacheFailures() );
78 repository.setHardFail( configuration.isHardFail() );
79 repository.setName( configuration.getName() );
80 repository.setUseNetworkProxy( configuration.isUseNetworkProxy() );
84 public List createRepositories( Configuration configuration )
86 List managedRepositories = configuration.getRepositories();
87 List repositories = new ArrayList( managedRepositories.size() );
89 for ( Iterator i = managedRepositories.iterator(); i.hasNext(); )
91 repositories.add( createRepository( (RepositoryConfiguration) i.next() ) );
97 public List createProxiedRepositories( Configuration configuration )
99 List proxiedRepositories = configuration.getProxiedRepositories();
100 List repositories = new ArrayList( proxiedRepositories.size() );
102 for ( Iterator i = proxiedRepositories.iterator(); i.hasNext(); )
104 repositories.add( createProxiedRepository( (ProxiedRepositoryConfiguration) i.next() ) );
110 public ArtifactRepository createLocalRepository( Configuration configuration )
112 ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) repositoryLayouts.get( "default" );
113 File localRepository = new File( configuration.getLocalRepository() );
114 localRepository.mkdirs();
115 return repoFactory.createArtifactRepository( "local", localRepository.toURI().toString(), layout, null, null );
118 private static String getUpdatePolicy( String policy, int interval )
120 return "interval".equals( policy ) ? policy + ":" + interval : policy;
123 private static boolean isEnabled( String policy )
125 return !"disabled".equals( policy );