1 package org.apache.archiva.repository.maven2;
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.archiva.configuration.AbstractRepositoryConfiguration;
23 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
24 import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
25 import org.apache.archiva.repository.EditableRepository;
26 import org.apache.archiva.repository.ManagedRepository;
27 import org.apache.archiva.repository.PasswordCredentials;
28 import org.apache.archiva.repository.ReleaseScheme;
29 import org.apache.archiva.repository.RemoteRepository;
30 import org.apache.archiva.repository.Repository;
31 import org.apache.archiva.repository.RepositoryProvider;
32 import org.apache.archiva.repository.RepositoryType;
33 import org.apache.archiva.repository.features.ArtifactCleanupFeature;
34 import org.apache.archiva.repository.features.IndexCreationFeature;
35 import org.apache.archiva.repository.features.RemoteIndexFeature;
36 import org.apache.archiva.repository.features.StagingRepositoryFeature;
37 import org.apache.commons.lang.StringUtils;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import org.springframework.stereotype.Service;
43 import java.net.URISyntaxException;
44 import java.time.Duration;
45 import java.time.Period;
46 import java.util.HashSet;
47 import java.util.Locale;
51 * Provider for the maven2 repository implementations
53 @Service("mavenRepositoryProvider")
54 public class MavenRepositoryProvider implements RepositoryProvider
56 private static final Logger log = LoggerFactory.getLogger( MavenRepositoryProvider.class );
58 static final Set<RepositoryType> TYPES = new HashSet<>( );
60 TYPES.add( RepositoryType.MAVEN);
64 public Set<RepositoryType> provides( )
70 public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration cfg )
72 MavenManagedRepository repo = new MavenManagedRepository(cfg.getId() ,cfg.getName());
75 if (cfg.getLocation().startsWith("file:")) {
76 repo.setLocation( new URI(cfg.getLocation()) );
78 repo.setLocation( new URI("file://"+cfg.getLocation()) );
81 catch ( URISyntaxException e )
83 log.error("Could not set repository uri "+cfg.getLocation());
85 setBaseConfig( repo, cfg );
86 repo.setSchedulingDefinition(cfg.getRefreshCronExpression());
87 repo.setBlocksRedeployment( cfg.isBlockRedeployments() );
88 repo.setScanned( cfg.isScanned() );
89 Set<ReleaseScheme> schemes = new HashSet<>( );
90 if (cfg.isReleases()) {
91 repo.addActiveReleaseScheme(ReleaseScheme.RELEASE);
93 if (cfg.isSnapshots()) {
94 repo.addActiveReleaseScheme(ReleaseScheme.SNAPSHOT);
97 StagingRepositoryFeature stagingRepositoryFeature = repo.getFeature( StagingRepositoryFeature.class ).get();
98 stagingRepositoryFeature.setStageRepoNeeded( cfg.isStageRepoNeeded() );
99 // TODO: staging repository -> here or in repositoryregistry?
102 IndexCreationFeature indexCreationFeature = repo.getFeature( IndexCreationFeature.class ).get( );
103 indexCreationFeature.setSkipPackedIndexCreation( cfg.isSkipPackedIndexCreation() );
105 ArtifactCleanupFeature artifactCleanupFeature = repo.getFeature( ArtifactCleanupFeature.class ).get();
107 artifactCleanupFeature.setDeleteReleasedSnapshots( cfg.isDeleteReleasedSnapshots() );
108 artifactCleanupFeature.setRetentionCount( cfg.getRetentionCount() );
109 artifactCleanupFeature.setRetentionTime( Period.ofDays( cfg.getRetentionTime() ) );
115 public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration cfg )
117 MavenRemoteRepository repo = new MavenRemoteRepository( cfg.getId( ), cfg.getName( ) );
118 setBaseConfig( repo, cfg );
119 repo.setCheckPath( cfg.getCheckPath() );
120 repo.setSchedulingDefinition( cfg.getRefreshCronExpression() );
123 repo.setLocation(new URI(cfg.getUrl()));
125 catch ( URISyntaxException e )
127 log.error("Could not set remote url "+cfg.getUrl());
129 RemoteIndexFeature remoteIndexFeature = repo.getFeature( RemoteIndexFeature.class ).get();
130 remoteIndexFeature.setDownloadRemoteIndex( cfg.isDownloadRemoteIndex() );
131 remoteIndexFeature.setDownloadRemoteIndexOnStartup( cfg.isDownloadRemoteIndexOnStartup() );
132 remoteIndexFeature.setDownloadTimeout( Duration.ofSeconds( cfg.getRemoteDownloadTimeout()) );
133 remoteIndexFeature.setProxyId( cfg.getRemoteDownloadNetworkProxyId() );
134 if (cfg.isDownloadRemoteIndex())
138 remoteIndexFeature.setIndexUri( new URI( cfg.getRemoteIndexUrl( ) ) );
140 catch ( URISyntaxException e )
142 log.error( "Could not set remote index url " + cfg.getRemoteIndexUrl( ) );
143 remoteIndexFeature.setDownloadRemoteIndex( false );
144 remoteIndexFeature.setDownloadRemoteIndexOnStartup( false );
147 repo.setExtraHeaders( cfg.getExtraHeaders() );
148 repo.setExtraParameters( cfg.getExtraParameters() );
149 PasswordCredentials credentials = new PasswordCredentials();
150 credentials.setPassword( cfg.getPassword().toCharArray() );
151 credentials.setUsername( cfg.getUsername() );
152 repo.setCredentials( credentials );
157 private void setBaseConfig( EditableRepository repo, AbstractRepositoryConfiguration cfg) {
158 repo.setDescription( Locale.getDefault( ), cfg.getDescription() );
159 String indexDir = cfg.getIndexDir();
162 if ( StringUtils.isEmpty( indexDir )) {
163 repo.setIndex( false );
164 repo.setIndexPath( null );
167 if ( indexDir.startsWith( "file://" ) )
169 repo.setIndexPath( new URI( indexDir ) );
173 repo.setIndexPath( new URI( "file://" + indexDir ) );
177 catch ( URISyntaxException e )
179 log.error("Could not set index path "+cfg.getIndexDir());
180 repo.setIndex(false);
182 repo.setLayout( cfg.getLayout() );