@@ -46,7 +46,8 @@ public abstract class AbstractManagedRepository extends AbstractRepository imple | |||
return content; | |||
} | |||
protected void setContent(ManagedRepositoryContent content) { | |||
@Override | |||
public void setContent(ManagedRepositoryContent content) { | |||
this.content = content; | |||
} | |||
@@ -40,7 +40,6 @@ public abstract class AbstractRemoteRepository extends AbstractRepository implem | |||
private Map<String,String> extraHeaders = new HashMap<>( ); | |||
private Map<String,String> uExtraHeaders = Collections.unmodifiableMap( extraHeaders ); | |||
private Duration timeout; | |||
private Duration downloadTimeout; | |||
private String proxyId; | |||
private RemoteRepositoryContent content; | |||
@@ -98,25 +97,14 @@ public abstract class AbstractRemoteRepository extends AbstractRepository implem | |||
this.timeout = duration; | |||
} | |||
@Override | |||
public void setDownloadTimeout( Duration duration ) | |||
{ | |||
this.downloadTimeout=duration; | |||
} | |||
@Override | |||
public void setProxyId( String proxyId ) | |||
{ | |||
this.proxyId = proxyId; | |||
} | |||
@Override | |||
public RemoteRepositoryContent getContent( ) | |||
{ | |||
return content; | |||
} | |||
protected void setContent(RemoteRepositoryContent content) { | |||
@Override | |||
public void setContent(RemoteRepositoryContent content) { | |||
this.content = content; | |||
} | |||
@@ -150,15 +138,4 @@ public abstract class AbstractRemoteRepository extends AbstractRepository implem | |||
return timeout; | |||
} | |||
@Override | |||
public Duration getDownloadTimeout( ) | |||
{ | |||
return downloadTimeout; | |||
} | |||
@Override | |||
public String getProxyId( ) | |||
{ | |||
return proxyId; | |||
} | |||
} |
@@ -29,4 +29,10 @@ public interface EditableManagedRepository extends EditableRepository, ManagedRe | |||
* @param blocksRedeployment The flag for blocking redeployments. | |||
*/ | |||
void setBlocksRedeployment(boolean blocksRedeployment); | |||
/** | |||
* Sets the content | |||
* @param content | |||
*/ | |||
void setContent(ManagedRepositoryContent content); | |||
} |
@@ -75,17 +75,8 @@ public interface EditableRemoteRepository extends EditableRepository, RemoteRepo | |||
void setTimeout(Duration duration); | |||
/** | |||
* Sets the maximum duration for downloads from the remote repository. | |||
* | |||
* @param duration The amount of time after that a download is aborted. | |||
*/ | |||
void setDownloadTimeout(Duration duration); | |||
/** | |||
* Sets the proxy id that is used for requests to the remote repository. | |||
* | |||
* @param proxyId The id of the proxy. | |||
* Sets the content. | |||
* @param content | |||
*/ | |||
void setProxyId(String proxyId); | |||
void setContent(RemoteRepositoryContent content); | |||
} |
@@ -34,6 +34,7 @@ import java.util.Locale; | |||
*/ | |||
public interface EditableRepository extends Repository | |||
{ | |||
/** | |||
* Returns the primary locale used for setting the default values for | |||
* name and description. |
@@ -0,0 +1,49 @@ | |||
package org.apache.archiva.repository; | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one | |||
* or more contributor license agreements. See the NOTICE file | |||
* distributed with this work for additional information | |||
* regarding copyright ownership. The ASF licenses this file | |||
* to you under the Apache License, Version 2.0 (the | |||
* "License"); you may not use this file except in compliance | |||
* with the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, | |||
* software distributed under the License is distributed on an | |||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |||
* KIND, either express or implied. See the License for the | |||
* specific language governing permissions and limitations | |||
* under the License. | |||
*/ | |||
/** | |||
* Simple credentials that hold username and password | |||
*/ | |||
public class PasswordCredentials implements RepositoryCredentials | |||
{ | |||
String username; | |||
char[] password; | |||
public String getUsername( ) | |||
{ | |||
return username; | |||
} | |||
public void setUsername( String username ) | |||
{ | |||
this.username = username; | |||
} | |||
public char[] getPassword( ) | |||
{ | |||
return password; | |||
} | |||
public void setPassword( char[] password ) | |||
{ | |||
this.password = password; | |||
} | |||
} |
@@ -69,16 +69,5 @@ public interface RemoteRepository extends Repository { | |||
*/ | |||
Duration getTimeout(); | |||
/** | |||
* Returns the time duration after that downloads from the remote repository are aborted. | |||
* @return | |||
*/ | |||
Duration getDownloadTimeout(); | |||
/** | |||
* Returns the id of the proxy, that is used for accessing the remote repository. | |||
* @return The proxy id. | |||
*/ | |||
String getProxyId(); | |||
} |
@@ -24,4 +24,8 @@ package org.apache.archiva.repository; | |||
* Credentials used to login to a remote repository. | |||
*/ | |||
public interface RepositoryCredentials { | |||
} | |||
@@ -22,6 +22,9 @@ package org.apache.archiva.repository; | |||
import org.apache.archiva.configuration.ArchivaConfiguration; | |||
import org.apache.archiva.configuration.ManagedRepositoryConfiguration; | |||
import org.apache.archiva.configuration.RemoteRepositoryConfiguration; | |||
import org.apache.archiva.repository.features.StagingRepositoryFeature; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.springframework.stereotype.Service; | |||
import javax.annotation.PostConstruct; | |||
@@ -39,6 +42,9 @@ import java.util.Map; | |||
@Service("repositoryRegistry") | |||
public class RepositoryRegistry | |||
{ | |||
private static final Logger log = LoggerFactory.getLogger( RepositoryRegistry.class ); | |||
/** | |||
* We inject all repository providers | |||
*/ | |||
@@ -48,6 +54,9 @@ public class RepositoryRegistry | |||
@Inject | |||
ArchivaConfiguration archivaConfiguration; | |||
@Inject | |||
RepositoryContentFactory repositoryContentFactory; | |||
private Map<String, ManagedRepository> managedRepositories = new HashMap<>( ); | |||
private Map<String, RemoteRepository> remoteRepositories = new HashMap<>( ); | |||
@@ -69,7 +78,8 @@ public class RepositoryRegistry | |||
return map; | |||
} | |||
private Map<String,ManagedRepository> getManagedRepositoriesFromConfig() { | |||
private Map<String,ManagedRepository> getManagedRepositoriesFromConfig() | |||
{ | |||
List<ManagedRepositoryConfiguration> managedRepoConfigs = | |||
getArchivaConfiguration().getConfiguration().getManagedRepositories(); | |||
@@ -85,13 +95,37 @@ public class RepositoryRegistry | |||
{ | |||
RepositoryType repositoryType = RepositoryType.valueOf( repoConfig.getType( ) ); | |||
if (providerMap.containsKey( repositoryType )) { | |||
managedRepos.put(repoConfig.getId(), providerMap.get(repositoryType).createManagedInstance( repoConfig )); | |||
try | |||
{ | |||
ManagedRepository repo = createNewManagedRepository( providerMap.get( repositoryType ), repoConfig ); | |||
managedRepos.put(repo.getId(), repo); | |||
} catch (Exception e) { | |||
log.error("Could not create managed repository "+repoConfig.getId(), e); | |||
} | |||
} | |||
} | |||
return managedRepos; | |||
} | |||
private ManagedRepository createNewManagedRepository(RepositoryProvider provider, ManagedRepositoryConfiguration cfg) throws RepositoryException | |||
{ | |||
ManagedRepository repo = provider.createManagedInstance( cfg ); | |||
if (repo.supportsFeature( StagingRepositoryFeature.class )) { | |||
StagingRepositoryFeature feature = repo.getFeature( StagingRepositoryFeature.class ).get(); | |||
if (feature.isStageRepoNeeded()) { | |||
ManagedRepository stageRepo = getManagedRepository( repo.getId()+StagingRepositoryFeature.STAGING_REPO_POSTFIX ); | |||
feature.setStagingRepository( stageRepo ); | |||
} | |||
} | |||
if (repo instanceof EditableManagedRepository) | |||
{ | |||
((EditableManagedRepository)repo).setContent( repositoryContentFactory.getManagedRepositoryContent( repo.getId( ) ) ); | |||
} | |||
return repo; | |||
} | |||
private Map<String,RemoteRepository> getRemoteRepositoriesFromConfig() { | |||
List<RemoteRepositoryConfiguration> remoteRepoConfigs = | |||
getArchivaConfiguration().getConfiguration().getRemoteRepositories(); |
@@ -21,6 +21,7 @@ package org.apache.archiva.repository.features; | |||
import java.net.URI; | |||
import java.time.Duration; | |||
/** | |||
* Feature for remote index download. | |||
@@ -30,6 +31,8 @@ public class RemoteIndexFeature implements RepositoryFeature<RemoteIndexFeature> | |||
private boolean downloadRemoteIndex = false; | |||
private URI indexUri; | |||
private boolean downloadRemoteIndexOnStartup = false; | |||
private Duration downloadTimeout = Duration.ofSeconds( 600 ); | |||
private String proxyId = ""; | |||
@Override | |||
@@ -85,4 +88,38 @@ public class RemoteIndexFeature implements RepositoryFeature<RemoteIndexFeature> | |||
public void setDownloadRemoteIndexOnStartup(boolean downloadRemoteIndexOnStartup) { | |||
this.downloadRemoteIndexOnStartup = downloadRemoteIndexOnStartup; | |||
} | |||
/** | |||
* Returns the timeout after that the remote index download is aborted. | |||
* @return the time duration after that, the download is aborted. | |||
*/ | |||
public Duration getDownloadTimeout() { | |||
return this.downloadTimeout; | |||
} | |||
/** | |||
* Sets the timeout after that a remote index download will be aborted. | |||
* @param timeout The duration | |||
*/ | |||
public void setDownloadTimeout(Duration timeout) { | |||
this.downloadTimeout = timeout; | |||
} | |||
/** | |||
* Returns the id of the proxy, that should be used to download the remote index. | |||
* @return The proxy id | |||
*/ | |||
public String getProxyId( ) | |||
{ | |||
return proxyId; | |||
} | |||
/** | |||
* Sets the id of the proxy that should be used to download the remote index. | |||
* @param proxyId | |||
*/ | |||
public void setProxyId( String proxyId ) | |||
{ | |||
this.proxyId = proxyId; | |||
} | |||
} |
@@ -28,6 +28,8 @@ import org.apache.archiva.repository.ManagedRepository; | |||
*/ | |||
public class StagingRepositoryFeature implements RepositoryFeature<StagingRepositoryFeature> { | |||
public static final String STAGING_REPO_POSTFIX = "-stage"; | |||
private ManagedRepository stagingRepository = null; | |||
private boolean stageRepoNeeded = false; | |||
@@ -20,7 +20,6 @@ package org.apache.archiva.repository.maven2; | |||
*/ | |||
import org.apache.archiva.repository.AbstractManagedRepository; | |||
import org.apache.archiva.repository.ManagedRepositoryContent; | |||
import org.apache.archiva.repository.ReleaseScheme; | |||
import org.apache.archiva.repository.RepositoryCapabilities; | |||
import org.apache.archiva.repository.RepositoryType; | |||
@@ -40,7 +39,6 @@ public class MavenManagedRepository extends AbstractManagedRepository | |||
{ | |||
public static final String DEFAULT_LAYOUT = "default"; | |||
public static final String LEGACY_LAYOUT = "legacy"; | |||
private ManagedRepositoryContent content; | |||
private ArtifactCleanupFeature artifactCleanupFeature = new ArtifactCleanupFeature( ); | |||
private IndexCreationFeature indexCreationFeature = new IndexCreationFeature( ); | |||
private StagingRepositoryFeature stagingRepositoryFeature = new StagingRepositoryFeature( ); | |||
@@ -68,16 +66,6 @@ public class MavenManagedRepository extends AbstractManagedRepository | |||
super( primaryLocale, RepositoryType.MAVEN, id, name ); | |||
} | |||
protected void setContent(ManagedRepositoryContent content) { | |||
this.content = content; | |||
} | |||
@Override | |||
public ManagedRepositoryContent getContent( ) | |||
{ | |||
return content; | |||
} | |||
@Override | |||
public RepositoryCapabilities getCapabilities( ) | |||
{ |
@@ -40,9 +40,6 @@ import java.util.Locale; | |||
public class MavenRemoteRepository extends AbstractRemoteRepository | |||
implements RemoteRepository | |||
{ | |||
private ArtifactCleanupFeature artifactCleanupFeature = new ArtifactCleanupFeature( ); | |||
private IndexCreationFeature indexCreationFeature = new IndexCreationFeature( ); | |||
private StagingRepositoryFeature stagingRepositoryFeature = new StagingRepositoryFeature( ); | |||
private RemoteIndexFeature remoteIndexFeature = new RemoteIndexFeature(); | |||
private static final RepositoryCapabilities CAPABILITIES = new StandardCapabilities( | |||
@@ -77,13 +74,7 @@ public class MavenRemoteRepository extends AbstractRemoteRepository | |||
@Override | |||
public <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature( Class<T> clazz ) throws UnsupportedFeatureException | |||
{ | |||
if (ArtifactCleanupFeature.class.equals(clazz)) { | |||
return (RepositoryFeature<T>) artifactCleanupFeature; | |||
} else if (IndexCreationFeature.class.equals(clazz)) { | |||
return (RepositoryFeature<T>) indexCreationFeature; | |||
} else if (StagingRepositoryFeature.class.equals(clazz)) { | |||
return (RepositoryFeature<T>) stagingRepositoryFeature; | |||
} else if (RemoteIndexFeature.class.equals( clazz )) { | |||
if (RemoteIndexFeature.class.equals( clazz )) { | |||
return (RepositoryFeature<T>) remoteIndexFeature; | |||
} else { | |||
throw new UnsupportedFeatureException( ); | |||
@@ -93,10 +84,7 @@ public class MavenRemoteRepository extends AbstractRemoteRepository | |||
@Override | |||
public <T extends RepositoryFeature<T>> boolean supportsFeature( Class<T> clazz ) | |||
{ | |||
if (ArtifactCleanupFeature.class.equals(clazz) || | |||
IndexCreationFeature.class.equals(clazz) || | |||
StagingRepositoryFeature.class.equals(clazz) || | |||
RemoteIndexFeature.class.equals(clazz)) { | |||
if ( RemoteIndexFeature.class.equals(clazz)) { | |||
return true; | |||
} else { | |||
return false; |
@@ -19,24 +19,38 @@ package org.apache.archiva.repository.maven2; | |||
* under the License. | |||
*/ | |||
import org.apache.archiva.configuration.AbstractRepositoryConfiguration; | |||
import org.apache.archiva.configuration.ManagedRepositoryConfiguration; | |||
import org.apache.archiva.configuration.RemoteRepositoryConfiguration; | |||
import org.apache.archiva.repository.EditableRepository; | |||
import org.apache.archiva.repository.ManagedRepository; | |||
import org.apache.archiva.repository.PasswordCredentials; | |||
import org.apache.archiva.repository.ReleaseScheme; | |||
import org.apache.archiva.repository.RemoteRepository; | |||
import org.apache.archiva.repository.Repository; | |||
import org.apache.archiva.repository.RepositoryProvider; | |||
import org.apache.archiva.repository.RepositoryType; | |||
import org.apache.archiva.repository.features.ArtifactCleanupFeature; | |||
import org.apache.archiva.repository.features.IndexCreationFeature; | |||
import org.apache.archiva.repository.features.RemoteIndexFeature; | |||
import org.apache.archiva.repository.features.StagingRepositoryFeature; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.springframework.stereotype.Service; | |||
import java.net.URI; | |||
import java.net.URISyntaxException; | |||
import java.time.Duration; | |||
import java.time.Period; | |||
import java.util.HashSet; | |||
import java.util.Locale; | |||
import java.util.Set; | |||
/** | |||
* Provider for the maven2 repository implementations | |||
*/ | |||
@Service("mavenRepositoryProvider") | |||
public class MavenRepositoryProvider implements RepositoryProvider | |||
{ | |||
private static final Logger log = LoggerFactory.getLogger( MavenRepositoryProvider.class ); | |||
@@ -68,16 +82,104 @@ public class MavenRepositoryProvider implements RepositoryProvider | |||
{ | |||
log.error("Could not set repository uri "+cfg.getLocation()); | |||
} | |||
cfg.getRefreshCronExpression(); | |||
setBaseConfig( repo, cfg ); | |||
repo.setSchedulingDefinition(cfg.getRefreshCronExpression()); | |||
repo.setBlocksRedeployment( cfg.isBlockRedeployments() ); | |||
repo.setScanned( cfg.isScanned() ); | |||
Set<ReleaseScheme> schemes = new HashSet<>( ); | |||
if (cfg.isReleases()) { | |||
repo.addActiveReleaseScheme(ReleaseScheme.RELEASE); | |||
} | |||
if (cfg.isSnapshots()) { | |||
repo.addActiveReleaseScheme(ReleaseScheme.SNAPSHOT); | |||
} | |||
StagingRepositoryFeature stagingRepositoryFeature = repo.getFeature( StagingRepositoryFeature.class ).get(); | |||
stagingRepositoryFeature.setStageRepoNeeded( cfg.isStageRepoNeeded() ); | |||
// TODO: staging repository -> here or in repositoryregistry? | |||
IndexCreationFeature indexCreationFeature = repo.getFeature( IndexCreationFeature.class ).get( ); | |||
indexCreationFeature.setSkipPackedIndexCreation( cfg.isSkipPackedIndexCreation() ); | |||
StagingRepositoryFeature feature = repo.getFeature( StagingRepositoryFeature.class ).get(); | |||
return null; | |||
ArtifactCleanupFeature artifactCleanupFeature = repo.getFeature( ArtifactCleanupFeature.class ).get(); | |||
artifactCleanupFeature.setDeleteReleasedSnapshots( cfg.isDeleteReleasedSnapshots() ); | |||
artifactCleanupFeature.setRetentionCount( cfg.getRetentionCount() ); | |||
artifactCleanupFeature.setRetentionTime( Period.ofDays( cfg.getRetentionTime() ) ); | |||
return repo; | |||
} | |||
@Override | |||
public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration configuration ) | |||
public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration cfg ) | |||
{ | |||
return null; | |||
MavenRemoteRepository repo = new MavenRemoteRepository( cfg.getId( ), cfg.getName( ) ); | |||
setBaseConfig( repo, cfg ); | |||
repo.setCheckPath( cfg.getCheckPath() ); | |||
repo.setSchedulingDefinition( cfg.getRefreshCronExpression() ); | |||
try | |||
{ | |||
repo.setLocation(new URI(cfg.getUrl())); | |||
} | |||
catch ( URISyntaxException e ) | |||
{ | |||
log.error("Could not set remote url "+cfg.getUrl()); | |||
} | |||
RemoteIndexFeature remoteIndexFeature = repo.getFeature( RemoteIndexFeature.class ).get(); | |||
remoteIndexFeature.setDownloadRemoteIndex( cfg.isDownloadRemoteIndex() ); | |||
remoteIndexFeature.setDownloadRemoteIndexOnStartup( cfg.isDownloadRemoteIndexOnStartup() ); | |||
remoteIndexFeature.setDownloadTimeout( Duration.ofSeconds( cfg.getRemoteDownloadTimeout()) ); | |||
remoteIndexFeature.setProxyId( cfg.getRemoteDownloadNetworkProxyId() ); | |||
if (cfg.isDownloadRemoteIndex()) | |||
{ | |||
try | |||
{ | |||
remoteIndexFeature.setIndexUri( new URI( cfg.getRemoteIndexUrl( ) ) ); | |||
} | |||
catch ( URISyntaxException e ) | |||
{ | |||
log.error( "Could not set remote index url " + cfg.getRemoteIndexUrl( ) ); | |||
remoteIndexFeature.setDownloadRemoteIndex( false ); | |||
remoteIndexFeature.setDownloadRemoteIndexOnStartup( false ); | |||
} | |||
} | |||
repo.setExtraHeaders( cfg.getExtraHeaders() ); | |||
repo.setExtraParameters( cfg.getExtraParameters() ); | |||
PasswordCredentials credentials = new PasswordCredentials(); | |||
credentials.setPassword( cfg.getPassword().toCharArray() ); | |||
credentials.setUsername( cfg.getUsername() ); | |||
repo.setCredentials( credentials ); | |||
return repo; | |||
} | |||
private void setBaseConfig( EditableRepository repo, AbstractRepositoryConfiguration cfg) { | |||
repo.setDescription( Locale.getDefault( ), cfg.getDescription() ); | |||
String indexDir = cfg.getIndexDir(); | |||
try | |||
{ | |||
if ( StringUtils.isEmpty( indexDir )) { | |||
repo.setIndex( false ); | |||
repo.setIndexPath( null ); | |||
} else | |||
{ | |||
if ( indexDir.startsWith( "file://" ) ) | |||
{ | |||
repo.setIndexPath( new URI( indexDir ) ); | |||
} | |||
else | |||
{ | |||
repo.setIndexPath( new URI( "file://" + indexDir ) ); | |||
} | |||
} | |||
} | |||
catch ( URISyntaxException e ) | |||
{ | |||
log.error("Could not set index path "+cfg.getIndexDir()); | |||
repo.setIndex(false); | |||
} | |||
repo.setLayout( cfg.getLayout() ); | |||
} | |||
} |