1 package org.apache.maven.archiva.configuration;
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.commons.lang.StringUtils;
23 import org.apache.maven.archiva.proxy.ProxiedArtifactRepository;
24 import org.apache.maven.artifact.repository.ArtifactRepository;
25 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
26 import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
27 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
30 import java.util.ArrayList;
31 import java.util.Iterator;
32 import java.util.List;
36 * Create artifact repositories from a configuration.
38 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
39 * @plexus.component role="org.apache.maven.archiva.configuration.ConfiguredRepositoryFactory"
41 public class DefaultConfiguredRepositoryFactory
42 implements ConfiguredRepositoryFactory
45 * @plexus.requirement role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout"
47 private Map repositoryLayouts;
52 private ArtifactRepositoryFactory repoFactory;
54 public ArtifactRepository createRepository( RepositoryConfiguration configuration )
56 return createRepository( configuration.getLayout(), configuration.getId(), configuration.getDirectory());
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() );
76 throw new IllegalArgumentException( "Invalid layout: " + configuration.getLayout() );
79 ArtifactRepository artifactRepository = repoFactory.createArtifactRepository( configuration.getId(),
80 configuration.getUrl(), layout,
81 snapshotsPolicy, releasesPolicy );
82 ProxiedArtifactRepository repository = new ProxiedArtifactRepository( artifactRepository );
83 repository.setCacheFailures( configuration.isCacheFailures() );
84 repository.setHardFail( configuration.isHardFail() );
85 repository.setName( configuration.getName() );
86 repository.setUseNetworkProxy( configuration.isUseNetworkProxy() );
90 public List createRepositories( Configuration configuration )
92 List managedRepositories = configuration.getRepositories();
93 List repositories = new ArrayList( managedRepositories.size() );
95 for ( Iterator i = managedRepositories.iterator(); i.hasNext(); )
97 repositories.add( createRepository( (RepositoryConfiguration) i.next() ) );
103 public List createProxiedRepositories( Configuration configuration )
105 List proxiedRepositories = configuration.getProxiedRepositories();
106 List repositories = new ArrayList( proxiedRepositories.size() );
108 for ( Iterator i = proxiedRepositories.iterator(); i.hasNext(); )
110 repositories.add( createProxiedRepository( (ProxiedRepositoryConfiguration) i.next() ) );
116 public ArtifactRepository createLocalRepository( Configuration configuration )
118 return createRepository( "default", "local", configuration.getLocalRepository() );
121 public ArtifactRepository createRepository( String layout, String id, String directory )
123 ArtifactRepositoryLayout repositoryLayout = (ArtifactRepositoryLayout) repositoryLayouts.get( layout );
124 File repository = new File( directory );
127 String repoDir = repository.toURI().toString();
128 //workaround for spaces non converted by PathUtils in wagon
129 //TODO: remove it when PathUtils will be fixed
130 if ( repoDir.indexOf( "%20" ) >= 0 )
132 repoDir = StringUtils.replace( repoDir, "%20", " " );
135 return repoFactory.createArtifactRepository( id, repoDir, repositoryLayout, null, null );
138 private static String getUpdatePolicy( String policy, int interval )
140 return "interval".equals( policy ) ? policy + ":" + interval : policy;
143 private static boolean isEnabled( String policy )
145 return !"disabled".equals( policy );