private Map<String,String> uExtraParameters = Collections.unmodifiableMap( extraParameters );
private Map<String,String> extraHeaders = new HashMap<>( );
private Map<String,String> uExtraHeaders = Collections.unmodifiableMap( extraHeaders );
- private Duration timeout;
+ private Duration timeout = Duration.ofSeconds( 60 );
private String proxyId;
private RemoteRepositoryContent content;
private Set<URI> uFailoverLocations = Collections.unmodifiableSet( failoverLocations );
private boolean scanned = true;
String schedulingDefinition = "0 0 02 * *";
- private boolean index = true;
private String layout;
public static final CronDefinition CRON_DEFINITION = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
}
@Override
- public boolean hasIndex( )
- {
- return index;
- }
+ public abstract boolean hasIndex( );
@Override
public String getLayout( )
this.scanned = scanned;
}
- @Override
- public void setIndex( boolean hasIndex )
- {
- this.index = hasIndex;
- }
-
@Override
public void setLayout( String layout )
{
*/
void setSchedulingDefinition(String cronExpression) throws IllegalArgumentException;
- /**
- * Set true, if the repository has indexes stored.
- * @param hasIndex true, if the repository has indexes, otherwise false.
- */
- void setIndex(boolean hasIndex);
-
/**
* Sets the layout string.
* @param layout
ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration) throws RepositoryException;
+ ManagedRepository createStagingInstance(ManagedRepositoryConfiguration baseConfiguration) throws RepositoryException;
+
RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration configuration) throws RepositoryException;
+
+ RemoteRepositoryConfiguration getRemoteConfiguration(RemoteRepository remoteRepository) throws RepositoryException;
+
+ ManagedRepositoryConfiguration getManagedConfiguration(ManagedRepository managedRepository) throws RepositoryException;
}
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
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 javax.annotation.PostConstruct;
import javax.inject.Inject;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
/**
* Registry for repositories
*/
-@Service("repositoryRegistry")
+@Service( "repositoryRegistry" )
public class RepositoryRegistry
{
@Inject
RepositoryContentFactory repositoryContentFactory;
- private Map<String, ManagedRepository> managedRepositories = new HashMap<>( );
- private Map<String, RemoteRepository> remoteRepositories = new HashMap<>( );
+ private Map<String, ManagedRepository> managedRepositories = new HashMap<>( );
+ private Map<String, ManagedRepository> uManagedRepository = Collections.unmodifiableMap( managedRepositories );
+
+ private Map<String, RemoteRepository> remoteRepositories = new HashMap<>( );
+ private Map<String, RemoteRepository> uRemoteRepositories = Collections.unmodifiableMap( remoteRepositories );
+
+ private ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock( );
@PostConstruct
- private void initialize() {
- managedRepositories = getManagedRepositoriesFromConfig();
- remoteRepositories = getRemoteRepositoriesFromConfig();
+ private void initialize( )
+ {
+ rwLock.writeLock( ).lock( );
+ try
+ {
+ managedRepositories.clear( );
+ managedRepositories.putAll( getManagedRepositoriesFromConfig( ) );
+ remoteRepositories.clear( );
+ remoteRepositories.putAll( getRemoteRepositoriesFromConfig( ) );
+ }
+ finally
+ {
+ rwLock.writeLock( ).unlock( );
+ }
}
- private Map<RepositoryType, RepositoryProvider> getProviderMap() {
- Map<RepositoryType, RepositoryProvider> map = new HashMap<>( );
- if (repositoryProviders!=null) {
- for(RepositoryProvider provider : repositoryProviders) {
- for (RepositoryType type : provider.provides()) {
- map.put(type, provider);
+ private Map<RepositoryType, RepositoryProvider> getProviderMap( )
+ {
+ Map<RepositoryType, RepositoryProvider> map = new HashMap<>( );
+ if ( repositoryProviders != null )
+ {
+ for ( RepositoryProvider provider : repositoryProviders )
+ {
+ for ( RepositoryType type : provider.provides( ) )
+ {
+ map.put( type, provider );
}
}
}
return map;
}
- private Map<String,ManagedRepository> getManagedRepositoriesFromConfig()
+ private Map<String, ManagedRepository> getManagedRepositoriesFromConfig( )
{
List<ManagedRepositoryConfiguration> managedRepoConfigs =
- getArchivaConfiguration().getConfiguration().getManagedRepositories();
+ getArchivaConfiguration( ).getConfiguration( ).getManagedRepositories( );
if ( managedRepoConfigs == null )
{
- return Collections.emptyMap();
+ return Collections.emptyMap( );
}
- Map<String,ManagedRepository> managedRepos = new LinkedHashMap<>( managedRepoConfigs.size() );
+ Map<String, ManagedRepository> managedRepos = new LinkedHashMap<>( managedRepoConfigs.size( ) );
Map<RepositoryType, RepositoryProvider> providerMap = getProviderMap( );
for ( ManagedRepositoryConfiguration repoConfig : managedRepoConfigs )
{
RepositoryType repositoryType = RepositoryType.valueOf( repoConfig.getType( ) );
- if (providerMap.containsKey( repositoryType )) {
+ if ( providerMap.containsKey( repositoryType ) )
+ {
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.getMessage(), e);
+ }
+ catch ( Exception e )
+ {
+ log.error( "Could not create managed repository {}: {}", repoConfig.getId( ), e.getMessage( ), e );
}
}
}
-
return managedRepos;
}
- private ManagedRepository createNewManagedRepository(RepositoryProvider provider, ManagedRepositoryConfiguration cfg) throws RepositoryException
+ 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 );
+ if ( repo.supportsFeature( StagingRepositoryFeature.class ) )
+ {
+ StagingRepositoryFeature feature = repo.getFeature( StagingRepositoryFeature.class ).get( );
+ if ( feature.isStageRepoNeeded( ) )
+ {
+ ManagedRepository stageRepo = getStageRepository( provider, cfg );
feature.setStagingRepository( stageRepo );
}
}
- if (repo instanceof EditableManagedRepository)
+ if ( repo instanceof EditableManagedRepository )
{
- ((EditableManagedRepository)repo).setContent( repositoryContentFactory.getManagedRepositoryContent( repo.getId( ) ) );
+ ( (EditableManagedRepository) repo ).setContent( repositoryContentFactory.getManagedRepositoryContent( repo.getId( ) ) );
}
return repo;
}
- private Map<String,RemoteRepository> getRemoteRepositoriesFromConfig() {
+ private ManagedRepository getStageRepository( RepositoryProvider provider, ManagedRepositoryConfiguration baseRepoCfg ) throws RepositoryException
+ {
+ ManagedRepository stageRepo = getManagedRepository( baseRepoCfg.getId( ) + StagingRepositoryFeature.STAGING_REPO_POSTFIX );
+ if ( stageRepo == null )
+ {
+ stageRepo = provider.createStagingInstance( baseRepoCfg );
+ }
+ return stageRepo;
+ }
+
+
+ private Map<String, RemoteRepository> getRemoteRepositoriesFromConfig( )
+ {
List<RemoteRepositoryConfiguration> remoteRepoConfigs =
- getArchivaConfiguration().getConfiguration().getRemoteRepositories();
+ getArchivaConfiguration( ).getConfiguration( ).getRemoteRepositories( );
if ( remoteRepoConfigs == null )
{
- return Collections.emptyMap();
+ return Collections.emptyMap( );
}
- Map<String,RemoteRepository> remoteRepos = new LinkedHashMap<>( remoteRepoConfigs.size() );
+ Map<String, RemoteRepository> remoteRepos = new LinkedHashMap<>( remoteRepoConfigs.size( ) );
Map<RepositoryType, RepositoryProvider> providerMap = getProviderMap( );
for ( RemoteRepositoryConfiguration repoConfig : remoteRepoConfigs )
{
RepositoryType repositoryType = RepositoryType.valueOf( repoConfig.getType( ) );
- if (providerMap.containsKey( repositoryType )) {
+ if ( providerMap.containsKey( repositoryType ) )
+ {
try
{
- remoteRepos.put(repoConfig.getId(), providerMap.get(repositoryType).createRemoteInstance( repoConfig ));
+ remoteRepos.put( repoConfig.getId( ), providerMap.get( repositoryType ).createRemoteInstance( repoConfig ) );
}
catch ( Exception e )
{
- log.error("Could not create repository {} from config: {}", repoConfig.getId(), e.getMessage(), e);
+ log.error( "Could not create repository {} from config: {}", repoConfig.getId( ), e.getMessage( ), e );
}
}
}
return remoteRepos;
}
- private ArchivaConfiguration getArchivaConfiguration() {
+ private ArchivaConfiguration getArchivaConfiguration( )
+ {
return this.archivaConfiguration;
}
- public List<Repository> getRepositories() {
- ArrayList<Repository> li = new ArrayList<>( );
- li.addAll(managedRepositories.values());
- li.addAll(remoteRepositories.values());
- return Collections.unmodifiableList( li );
+ public Collection<Repository> getRepositories( )
+ {
+ rwLock.readLock( ).lock( );
+ try
+ {
+ return Stream.concat( managedRepositories.values( ).stream( ), remoteRepositories.values( ).stream( ) ).collect( Collectors.toList( ) );
+ }
+ finally
+ {
+ rwLock.readLock( ).unlock( );
+ }
}
- public List<ManagedRepository> getManagedRepositories() {
- return Collections.unmodifiableList( new ArrayList(managedRepositories.values()) );
+ public Collection<ManagedRepository> getManagedRepositories( )
+ {
+ return uManagedRepository.values( );
}
- public List<RemoteRepository> getRemoteRepositories() {
- return Collections.unmodifiableList( new ArrayList(remoteRepositories.values()) );
+ public Collection<RemoteRepository> getRemoteRepositories( )
+ {
+ return uRemoteRepositories.values( );
}
- public Repository getRepository(String repoId) {
- return null;
+ public Repository getRepository( String repoId )
+ {
+ rwLock.readLock( ).lock( );
+ try
+ {
+ if ( managedRepositories.containsKey( repoId ) )
+ {
+ return managedRepositories.get( repoId );
+ }
+ else
+ {
+ return remoteRepositories.get( repoId );
+ }
+ }
+ finally
+ {
+ rwLock.readLock( ).unlock( );
+ }
}
- public ManagedRepository getManagedRepository(String repoId) {
- return null;
+ public ManagedRepository getManagedRepository( String repoId )
+ {
+ rwLock.readLock().lock();
+ try
+ {
+ return managedRepositories.get( repoId );
+ } finally
+ {
+ rwLock.readLock().unlock();
+ }
}
- public RemoteRepository getRemoteRepository(String repoId) {
- return null;
+ public RemoteRepository getRemoteRepository( String repoId )
+ {
+ rwLock.readLock().lock();
+ try
+ {
+ return remoteRepositories.get( repoId );
+ } finally
+ {
+ rwLock.readLock().unlock();
+ }
+ }
+
+ public void addRepository( ManagedRepository managedRepository )
+ {
+ rwLock.writeLock( ).lock( );
+ try
+ {
+ managedRepositories.put( managedRepository.getId( ), managedRepository );
+ }
+ finally
+ {
+ rwLock.writeLock( ).unlock( );
+ }
+ }
+
+ public void addRepository( RemoteRepository remoteRepository )
+ {
+ rwLock.writeLock( ).lock( );
+ try
+ {
+ remoteRepositories.put( remoteRepository.getId( ), remoteRepository );
+ }
+ finally
+ {
+ rwLock.writeLock( ).unlock( );
+ }
}
}
*/
+import org.apache.commons.lang.StringUtils;
+
import java.net.URI;
/**
}
+ public boolean hasIndex() {
+ return this.indexPath!=null && !StringUtils.isEmpty( this.indexPath.getPath() );
+ }
}
*/
+import org.apache.commons.lang.StringUtils;
+
import java.net.URI;
import java.time.Duration;
{
this.proxyId = proxyId;
}
+
+ /**
+ * Returns true, if there is a index available.
+ *
+ * @return
+ */
+ public boolean hasIndex() {
+ return this.indexUri!=null && !StringUtils.isEmpty( this.indexUri.getPath() );
+ }
}
return false;
}
-
-
-
+ @Override
+ public boolean hasIndex( )
+ {
+ return indexCreationFeature.hasIndex();
+ }
}
public class MavenRemoteRepository extends AbstractRemoteRepository
implements RemoteRepository
{
- private RemoteIndexFeature remoteIndexFeature = new RemoteIndexFeature();
+ final private RemoteIndexFeature remoteIndexFeature = new RemoteIndexFeature();
+ final private IndexCreationFeature indexCreationFeature = new IndexCreationFeature( );
private static final RepositoryCapabilities CAPABILITIES = new StandardCapabilities(
new ReleaseScheme[] { ReleaseScheme.RELEASE, ReleaseScheme.SNAPSHOT },
new String[] { MavenManagedRepository.DEFAULT_LAYOUT, MavenManagedRepository.LEGACY_LAYOUT},
new String[] {},
- new String[] {RemoteIndexFeature.class.getName()},
+ new String[] {RemoteIndexFeature.class.getName(), IndexCreationFeature.class.getName()},
true,
true,
true,
super( primaryLocale, RepositoryType.MAVEN, id, name );
}
+ @Override
+ public boolean hasIndex( )
+ {
+ return remoteIndexFeature.hasIndex();
+ }
+
@Override
public RepositoryCapabilities getCapabilities( )
{
{
if (RemoteIndexFeature.class.equals( clazz )) {
return (RepositoryFeature<T>) remoteIndexFeature;
+ } else if (IndexCreationFeature.class.equals(clazz)) {
+ return (RepositoryFeature<T>) indexCreationFeature;
} else {
throw new UnsupportedFeatureException( );
}
@Override
public <T extends RepositoryFeature<T>> boolean supportsFeature( Class<T> clazz )
{
- if ( RemoteIndexFeature.class.equals(clazz)) {
+ if ( RemoteIndexFeature.class.equals(clazz) || IndexCreationFeature.class.equals(clazz)) {
return true;
} else {
return false;
import org.apache.archiva.repository.PasswordCredentials;
import org.apache.archiva.repository.ReleaseScheme;
import org.apache.archiva.repository.RemoteRepository;
+import org.apache.archiva.repository.RepositoryCredentials;
import org.apache.archiva.repository.RepositoryException;
import org.apache.archiva.repository.RepositoryProvider;
import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.features.RemoteIndexFeature;
import org.apache.archiva.repository.features.StagingRepositoryFeature;
import org.apache.commons.lang.StringUtils;
+import org.apache.http.auth.UsernamePasswordCredentials;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.net.URI;
import java.net.URISyntaxException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.time.Duration;
import java.time.Period;
+import java.time.temporal.ChronoUnit;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
-import java.util.regex.Pattern;
/**
* Provider for the maven2 repository implementations
return TYPES;
}
- private URI getURIFromConfig(String config) throws RepositoryException {
+ private URI getURIFromString( String uriStr) throws RepositoryException {
URI uri;
try {
- uri = new URI(config);
- if (uri.getScheme()==null) {
- uri = new URI("file://"+config);
+ if (uriStr.startsWith("/")) {
+ // only absolute paths are prepended with file scheme
+ uri = new URI("file://"+uriStr);
+ } else
+ {
+ uri = new URI( uriStr );
}
- if (!"file".equals(uri.getScheme())) {
+ if (uri.getScheme()!=null && !"file".equals(uri.getScheme())) {
log.error("Bad URI scheme found: {}, URI={}", uri.getScheme(), uri);
- throw new RepositoryException("The uri "+config+" is not valid. Only file:// URI is allowed for maven.");
+ throw new RepositoryException("The uri "+uriStr+" is not valid. Only file:// URI is allowed for maven.");
}
} catch (URISyntaxException e) {
- String newCfg = "file://"+config;
+ String newCfg = "file://"+uriStr;
try
{
uri = new URI(newCfg);
}
catch ( URISyntaxException e1 )
{
- log.error("Could not create URI from {} -> ", config, newCfg);
- throw new RepositoryException( "The config entry "+config+" cannot be converted to URI." );
+ log.error("Could not create URI from {} -> ", uriStr, newCfg);
+ throw new RepositoryException( "The config entry "+uriStr+" cannot be converted to URI." );
}
}
return uri;
public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration cfg ) throws RepositoryException
{
MavenManagedRepository repo = new MavenManagedRepository(cfg.getId() ,cfg.getName());
- repo.setLocation( getURIFromConfig( cfg.getLocation() ) );
+ repo.setLocation( getURIFromString( cfg.getLocation() ) );
setBaseConfig( repo, cfg );
repo.setSchedulingDefinition(cfg.getRefreshCronExpression());
repo.setBlocksRedeployment( cfg.isBlockRedeployments() );
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() );
- indexCreationFeature.setIndexPath( getURIFromConfig( cfg.getIndexDir() ) );
+ indexCreationFeature.setIndexPath( getURIFromString( cfg.getIndexDir() ) );
ArtifactCleanupFeature artifactCleanupFeature = repo.getFeature( ArtifactCleanupFeature.class ).get();
return repo;
}
+ @Override
+ public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration baseConfiguration ) throws RepositoryException
+ {
+ return createManagedInstance( getStageRepoConfig( baseConfiguration ) );
+ }
@Override
- public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration cfg )
+ public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration cfg ) throws RepositoryException
{
MavenRemoteRepository repo = new MavenRemoteRepository( cfg.getId( ), cfg.getName( ) );
setBaseConfig( repo, cfg );
{
log.error("Could not set remote url "+cfg.getUrl());
}
+ repo.setTimeout( Duration.ofSeconds( cfg.getTimeout() ) );
RemoteIndexFeature remoteIndexFeature = repo.getFeature( RemoteIndexFeature.class ).get();
remoteIndexFeature.setDownloadRemoteIndex( cfg.isDownloadRemoteIndex() );
remoteIndexFeature.setDownloadRemoteIndexOnStartup( cfg.isDownloadRemoteIndexOnStartup() );
} else {
credentials.setPassword( new char[0] );
}
+ if (cfg.getIndexDir()!=null) {
+ IndexCreationFeature indexCreationFeature = repo.getFeature( IndexCreationFeature.class ).get();
+ indexCreationFeature.setIndexPath( getURIFromString( cfg.getIndexDir() ) );
+ }
return repo;
}
- private void setBaseConfig( EditableRepository repo, AbstractRepositoryConfiguration cfg) {
- repo.setDescription( Locale.getDefault( ), cfg.getDescription() );
- String indexDir = cfg.getIndexDir();
- try
+ @Override
+ public RemoteRepositoryConfiguration getRemoteConfiguration( RemoteRepository remoteRepository ) throws RepositoryException
+ {
+ if (!(remoteRepository instanceof MavenRemoteRepository)) {
+ log.error("Wrong remote repository type "+remoteRepository.getClass().getName());
+ throw new RepositoryException( "The given repository type cannot be handled by the maven provider: "+remoteRepository.getClass().getName() );
+ }
+ RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration();
+ cfg.setType( remoteRepository.getType().toString() );
+ cfg.setId( remoteRepository.getId() );
+ cfg.setName( remoteRepository.getName() );
+ cfg.setDescription( remoteRepository.getDescription() );
+ cfg.setUrl(remoteRepository.getLocation().toString());
+ cfg.setTimeout( (int)remoteRepository.getTimeout().toMillis()/1000 );
+ cfg.setCheckPath( remoteRepository.getCheckPath() );
+ RepositoryCredentials creds = remoteRepository.getLoginCredentials( );
+ if (creds!=null)
{
- if ( StringUtils.isEmpty( indexDir )) {
- repo.setIndex( false );
- } else
- {
- if ( indexDir.startsWith( "file://" ) )
- {
- //repo.setIndexPath( new URI( indexDir ) );
- }
- else
- {
- //repo.setIndexPath( new URI( "file://" + indexDir ) );
- }
+ if (creds instanceof PasswordCredentials) {
+ PasswordCredentials pCreds = (PasswordCredentials) creds;
+ cfg.setPassword( new String(pCreds.getPassword()) );
+ cfg.setUsername( pCreds.getUsername() );
}
}
- catch ( Exception e )
+ cfg.setLayout( remoteRepository.getLayout() );
+ cfg.setExtraParameters( remoteRepository.getExtraParameters() );
+ cfg.setExtraHeaders( remoteRepository.getExtraHeaders() );
+ cfg.setRefreshCronExpression( remoteRepository.getSchedulingDefinition() );
+
+ IndexCreationFeature indexCreationFeature = remoteRepository.getFeature( IndexCreationFeature.class ).get();
+ cfg.setIndexDir( indexCreationFeature.getIndexPath().toString());
+
+ RemoteIndexFeature remoteIndexFeature = remoteRepository.getFeature( RemoteIndexFeature.class ).get();
+ cfg.setRemoteIndexUrl( remoteIndexFeature.getIndexUri().toString() );
+ cfg.setRemoteDownloadTimeout( (int)remoteIndexFeature.getDownloadTimeout().get( ChronoUnit.SECONDS ) );
+ cfg.setDownloadRemoteIndexOnStartup( remoteIndexFeature.isDownloadRemoteIndexOnStartup() );
+ cfg.setDownloadRemoteIndex( remoteIndexFeature.isDownloadRemoteIndex() );
+ cfg.setRemoteDownloadNetworkProxyId( remoteIndexFeature.getProxyId() );
+
+
+
+
+ return cfg;
+
+ }
+
+ @Override
+ public ManagedRepositoryConfiguration getManagedConfiguration( ManagedRepository managedRepository ) throws RepositoryException
+ {
+ if (!(managedRepository instanceof MavenManagedRepository)) {
+ log.error("Wrong remote repository type "+managedRepository.getClass().getName());
+ throw new RepositoryException( "The given repository type cannot be handled by the maven provider: "+managedRepository.getClass().getName() );
+ }
+ ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration();
+ cfg.setType( managedRepository.getType().toString() );
+ cfg.setId( managedRepository.getId() );
+ cfg.setName( managedRepository.getName() );
+ cfg.setDescription( managedRepository.getDescription() );
+ cfg.setLocation( managedRepository.getLocation().toString() );
+ cfg.setLayout( managedRepository.getLayout() );
+ cfg.setRefreshCronExpression( managedRepository.getSchedulingDefinition() );
+ cfg.setScanned( managedRepository.isScanned() );
+ cfg.setBlockRedeployments( managedRepository.blocksRedeployments() );
+ StagingRepositoryFeature stagingRepositoryFeature = managedRepository.getFeature( StagingRepositoryFeature.class ).get();
+ cfg.setStageRepoNeeded(stagingRepositoryFeature.isStageRepoNeeded());
+
+
+ IndexCreationFeature indexCreationFeature = managedRepository.getFeature( IndexCreationFeature.class ).get();
+ cfg.setIndexDir( indexCreationFeature.getIndexPath().toString());
+ cfg.setSkipPackedIndexCreation( indexCreationFeature.isSkipPackedIndexCreation() );
+
+ ArtifactCleanupFeature artifactCleanupFeature = managedRepository.getFeature( ArtifactCleanupFeature.class ).get();
+ cfg.setRetentionCount( artifactCleanupFeature.getRetentionCount());
+ cfg.setRetentionTime( artifactCleanupFeature.getRetentionTime().getDays() );
+ cfg.setDeleteReleasedSnapshots(artifactCleanupFeature.isDeleteReleasedSnapshots());
+
+ if (managedRepository.getActiveReleaseSchemes().contains( ReleaseScheme.RELEASE )) {
+ cfg.setReleases( true );
+ } else {
+ cfg.setReleases( false );
+ }
+ if (managedRepository.getActiveReleaseSchemes().contains( ReleaseScheme.SNAPSHOT )) {
+ cfg.setSnapshots( true );
+ } else {
+ cfg.setSnapshots( false );
+ }
+ return cfg;
+
+ }
+
+ private ManagedRepositoryConfiguration getStageRepoConfig( ManagedRepositoryConfiguration repository )
+ {
+ ManagedRepositoryConfiguration stagingRepository = new ManagedRepositoryConfiguration();
+ stagingRepository.setId( repository.getId() + StagingRepositoryFeature.STAGING_REPO_POSTFIX );
+ stagingRepository.setLayout( repository.getLayout() );
+ stagingRepository.setName( repository.getName() + StagingRepositoryFeature.STAGING_REPO_POSTFIX );
+ stagingRepository.setBlockRedeployments( repository.isBlockRedeployments() );
+ stagingRepository.setRetentionTime( repository.getRetentionTime() );
+ stagingRepository.setDeleteReleasedSnapshots( repository.isDeleteReleasedSnapshots() );
+
+ String path = repository.getLocation();
+ int lastIndex = path.replace( '\\', '/' ).lastIndexOf( '/' );
+ stagingRepository.setLocation( path.substring( 0, lastIndex ) + "/" + stagingRepository.getId() );
+
+ if ( StringUtils.isNotBlank( repository.getIndexDir() ) )
{
- log.error("Could not set index path "+cfg.getIndexDir());
- repo.setIndex(false);
+ Path indexDir = Paths.get( repository.getIndexDir() );
+ // in case of absolute dir do not use the same
+ if ( indexDir.isAbsolute() )
+ {
+ stagingRepository.setIndexDir( stagingRepository.getLocation() + "/.index" );
+ }
+ else
+ {
+ stagingRepository.setIndexDir( repository.getIndexDir() );
+ }
}
+ stagingRepository.setRefreshCronExpression( repository.getRefreshCronExpression() );
+ stagingRepository.setReleases( repository.isReleases() );
+ stagingRepository.setRetentionCount( repository.getRetentionCount() );
+ stagingRepository.setScanned( repository.isScanned() );
+ stagingRepository.setSnapshots( repository.isSnapshots() );
+ stagingRepository.setSkipPackedIndexCreation( repository.isSkipPackedIndexCreation() );
+ // do not duplicate description
+ //stagingRepository.getDescription("")
+ return stagingRepository;
+ }
+
+ private void setBaseConfig( EditableRepository repo, AbstractRepositoryConfiguration cfg) {
+ repo.setDescription( repo.getPrimaryLocale(), cfg.getDescription() );
repo.setLayout( cfg.getLayout() );
}
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
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.RepositoryType;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.sonatype.aether.util.layout.RepositoryLayout;
import org.springframework.test.context.ContextConfiguration;
import javax.inject.Inject;
import javax.inject.Named;
+import java.net.URI;
+import java.time.Duration;
import java.time.Period;
+import java.time.temporal.ChronoUnit;
+import java.time.temporal.TemporalUnit;
+import java.util.HashMap;
+import java.util.Map;
import static org.junit.Assert.*;
/**
* @author Martin Stockhammer <martin_s@apache.org>
*/
-@RunWith( ArchivaSpringJUnit4ClassRunner.class )
-@ContextConfiguration( { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-no-mock-conf.xml" } )
public class MavenRepositoryProviderTest
{
- @Inject
- @Named( "archivaConfiguration#default" )
- ArchivaConfiguration archivaConfiguration;
-
MavenRepositoryProvider provider;
@Test
public void createManagedInstance( ) throws Exception
{
- assertNotNull(archivaConfiguration);
- assertNotNull(archivaConfiguration.getConfiguration());
- ManagedRepositoryConfiguration repo = archivaConfiguration.getConfiguration().getManagedRepositories().get(0);
+ ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration( );
+ repo.setId("testm001");
+ repo.setName("Managed Test Repo 001");
+ repo.setDescription( "This is a managed test" );
+ repo.setRetentionTime( 37 );
+ repo.setLocation( "file:///test/dir/repository" );
+ repo.setSnapshots( true );
+ repo.setReleases( true );
+ repo.setRefreshCronExpression( "4 0 0 ? * TUE" );
+ repo.setScanned( true );
+ repo.setBlockRedeployments( true );
+ repo.setDeleteReleasedSnapshots( true );
+ repo.setRetentionCount( 33 );
+ repo.setSkipPackedIndexCreation( true );
+ repo.setStageRepoNeeded( true );
+ repo.setIndexDir( "testmanaged/.index" );
+ repo.setLayout( "maven2" );
+ repo.setType( RepositoryType.MAVEN.toString() );
+
+
ManagedRepository mr = provider.createManagedInstance( repo );
assertNotNull(mr.getLocation());
- assertTrue(mr.getLocation().toString().endsWith( "/repositories/internal" ));
- assertEquals("Archiva Managed Internal Repository", mr.getName());
- assertEquals(1, mr.getActiveReleaseSchemes().size());
- assertEquals( ReleaseScheme.RELEASE, mr.getActiveReleaseSchemes().iterator().next());
- assertEquals("internal", mr.getId());
+ assertEquals("file:///test/dir/repository", mr.getLocation().toString());
+ assertEquals("This is a managed test", mr.getDescription());
+ assertEquals("Managed Test Repo 001", mr.getName());
+ assertEquals(2, mr.getActiveReleaseSchemes().size());
+ assertTrue( mr.getActiveReleaseSchemes().contains( ReleaseScheme.RELEASE ));
+ assertTrue( mr.getActiveReleaseSchemes().contains( ReleaseScheme.SNAPSHOT));
+ assertEquals("testm001", mr.getId());
assertTrue(mr.blocksRedeployments());
- assertEquals("0 0 * * * ?", mr.getSchedulingDefinition());
+ assertEquals("4 0 0 ? * TUE", mr.getSchedulingDefinition());
assertTrue(mr.isScanned());
ArtifactCleanupFeature artifactCleanupFeature = mr.getFeature( ArtifactCleanupFeature.class ).get();
- assertEquals( Period.ofDays( 30), artifactCleanupFeature.getRetentionTime());
- assertFalse(artifactCleanupFeature.isDeleteReleasedSnapshots());
- assertEquals(2, artifactCleanupFeature.getRetentionCount());
+ assertEquals( Period.ofDays( 37), artifactCleanupFeature.getRetentionTime());
+ assertTrue(artifactCleanupFeature.isDeleteReleasedSnapshots());
+ assertEquals(33, artifactCleanupFeature.getRetentionCount());
IndexCreationFeature indexCreationFeature = mr.getFeature( IndexCreationFeature.class ).get();
assertNotNull(indexCreationFeature.getIndexPath());
- assertTrue(indexCreationFeature.getIndexPath().toString().endsWith("/repositories/internal/.indexer"));
- assertTrue(indexCreationFeature.getIndexPath().isAbsolute());
- assertFalse(indexCreationFeature.isSkipPackedIndexCreation());
+ assertEquals("testmanaged/.index", indexCreationFeature.getIndexPath().toString());
+ assertFalse(indexCreationFeature.getIndexPath().isAbsolute());
+ assertTrue(indexCreationFeature.isSkipPackedIndexCreation());
StagingRepositoryFeature stagingRepositoryFeature = mr.getFeature( StagingRepositoryFeature.class ).get();
- assertFalse(stagingRepositoryFeature.isStageRepoNeeded());
+ assertTrue(stagingRepositoryFeature.isStageRepoNeeded());
assertNull(stagingRepositoryFeature.getStagingRepository());
@Test
public void createRemoteInstance( ) throws Exception
{
- assertNotNull(archivaConfiguration);
- assertNotNull(archivaConfiguration.getConfiguration());
- RemoteRepositoryConfiguration repo = archivaConfiguration.getConfiguration().getRemoteRepositories().get(0);
+ RemoteRepositoryConfiguration repo = new RemoteRepositoryConfiguration( );
+ repo.setUsername("testuser001");
+ repo.setPassword( "pwd0000abc" );
+ repo.setCheckPath( "test/check.html" );
+ repo.setTimeout( 50 );
+ repo.setUrl( "https://repo.maven.apache.org/maven2/test" );
+ repo.setDownloadRemoteIndex( true );
+ repo.setDownloadRemoteIndexOnStartup( true );
+ Map header = new HashMap( );
+ header.put("header1","value1");
+ header.put("header2","value2");
+ repo.setExtraHeaders( header );
+ Map params = new HashMap( );
+ params.put("param1","pval1");
+ params.put("param2","pval2");
+ repo.setExtraParameters( params );
+ repo.setRefreshCronExpression( "0 1 07 ? * MON" );
+ repo.setRemoteDownloadTimeout( 333 );
+ repo.setRemoteIndexUrl( "testremote/.index" );
+ repo.setDescription( "This is a test" );
+ repo.setId( "test001" );
+ repo.setName( "Remote Test Repo 001" );
+ repo.setIndexDir( "testindex/.index" );
+ repo.setLayout( "maven2" );
+ repo.setType( RepositoryType.MAVEN.toString() );
+ repo.setIndexDir( "local/.index" );
+
RemoteRepository mr = provider.createRemoteInstance( repo );
+ assertEquals("test001", mr.getId());
+ assertEquals("This is a test", mr.getDescription());
assertNotNull(mr.getLocation());
- assertEquals("https://repo.maven.apache.org/maven2", mr.getLocation().toString());
- assertEquals("Central Repository", mr.getName());
- assertEquals("central", mr.getId());
- assertEquals("0 0 08 ? * SUN", mr.getSchedulingDefinition());
+ assertEquals("https://repo.maven.apache.org/maven2/test", mr.getLocation().toString());
+ assertEquals("Remote Test Repo 001", mr.getName());
+ assertEquals("test001", mr.getId());
+ assertEquals("0 1 07 ? * MON", mr.getSchedulingDefinition());
+ assertEquals(50, mr.getTimeout().get( ChronoUnit.SECONDS ));
assertTrue(mr.isScanned());
- assertNull(mr.getLoginCredentials());
+ assertNotNull(mr.getLoginCredentials());
+ assertTrue(mr.getLoginCredentials() instanceof PasswordCredentials);
+ PasswordCredentials creds = (PasswordCredentials) mr.getLoginCredentials();
+ assertEquals("testuser001", creds.getUsername());
+ assertEquals("pwd0000abc", new String(creds.getPassword()));
+ assertEquals("value1", mr.getExtraHeaders().get("header1"));
+ assertEquals("pval2", mr.getExtraParameters().get("param2"));
+ assertEquals( "maven2", mr.getLayout());
try
{
ArtifactCleanupFeature artifactCleanupFeature = mr.getFeature( ArtifactCleanupFeature.class ).get( );
// correct
}
- try
- {
- IndexCreationFeature indexCreationFeature = mr.getFeature( IndexCreationFeature.class ).get( );
- throw new Exception("indexCreationFeature should not be available");
- } catch (UnsupportedFeatureException e) {
- // correct
- }
+ IndexCreationFeature indexCreationFeature = mr.getFeature( IndexCreationFeature.class ).get( );
+ assertEquals("local/.index", indexCreationFeature.getIndexPath().toString());
try
{
StagingRepositoryFeature stagingRepositoryFeature = mr.getFeature( StagingRepositoryFeature.class ).get( );
assertNull(remoteIndexFeature.getProxyId());
}
+ @Test
+ public void getManagedConfiguration() throws Exception {
+ MavenManagedRepository repo = new MavenManagedRepository( "test01", "My Test repo" );
+
+ repo.setLocation( new URI("https://this.is/a/test") );
+ repo.setScanned( true );
+ repo.setDescription( repo.getPrimaryLocale(), "This is a description" );
+ repo.setLayout( "maven2" );
+ repo.setBlocksRedeployment( true );
+ repo.setName( repo.getPrimaryLocale(), "test0002" );
+ repo.setSchedulingDefinition( "0 0 05 ? * WED" );
+ repo.addActiveReleaseScheme( ReleaseScheme.RELEASE );
+ repo.addActiveReleaseScheme( ReleaseScheme.SNAPSHOT );
+ StagingRepositoryFeature stagingFeat = repo.getFeature( StagingRepositoryFeature.class ).get( );
+ stagingFeat.setStageRepoNeeded( true );
+ IndexCreationFeature indexCreationFeature = repo.getFeature( IndexCreationFeature.class ).get();
+ indexCreationFeature.setIndexPath( new URI("test/.indexes") );
+ indexCreationFeature.setSkipPackedIndexCreation( true );
+ ArtifactCleanupFeature artifactCleanupFeature = repo.getFeature( ArtifactCleanupFeature.class ).get();
+ artifactCleanupFeature.setRetentionTime( Period.ofDays( 5 ) );
+ artifactCleanupFeature.setRetentionCount( 7 );
+ artifactCleanupFeature.setDeleteReleasedSnapshots( true );
+
+ ManagedRepositoryConfiguration cfg = provider.getManagedConfiguration( repo );
+ assertEquals("https://this.is/a/test", cfg.getLocation());
+ assertTrue(cfg.isScanned());
+ assertEquals( "This is a description", cfg.getDescription() );
+ assertEquals("maven2", cfg.getLayout());
+ assertTrue(cfg.isBlockRedeployments());
+ assertEquals("test0002", cfg.getName());
+ assertEquals("0 0 05 ? * WED", cfg.getRefreshCronExpression());
+ assertTrue(cfg.isStageRepoNeeded());
+ assertEquals("test/.indexes", cfg.getIndexDir());
+ assertTrue(cfg.isSkipPackedIndexCreation());
+ assertEquals(5, cfg.getRetentionTime());
+ assertEquals(7, cfg.getRetentionCount());
+ assertTrue(cfg.isDeleteReleasedSnapshots());
+ assertTrue(cfg.isReleases());
+ assertTrue(cfg.isSnapshots());
+ assertTrue(cfg.isScanned());
+
+
+
+ }
+
+ @Test
+ public void getRemoteConfiguration() throws Exception {
+ MavenRemoteRepository repo = new MavenRemoteRepository( "test01", "My Test repo" );
+
+ repo.setLocation( new URI("https://this.is/a/test") );
+ repo.setScanned( true );
+ repo.setDescription( repo.getPrimaryLocale(), "This is a description" );
+ repo.setLayout( "maven2" );
+ repo.setName( repo.getPrimaryLocale(), "test0003" );
+ repo.setSchedulingDefinition( "0 0 05 ? * WED" );
+ RemoteIndexFeature remoteIndexFeature = repo.getFeature( RemoteIndexFeature.class ).get();
+ remoteIndexFeature.setProxyId( "proxyabc" );
+ remoteIndexFeature.setDownloadTimeout( Duration.ofSeconds( 54 ) );
+ remoteIndexFeature.setDownloadRemoteIndex( false );
+ remoteIndexFeature.setIndexUri( new URI("/this/remote/.index") );
+ remoteIndexFeature.setDownloadRemoteIndexOnStartup( true );
+ IndexCreationFeature indexCreationFeature = repo.getFeature( IndexCreationFeature.class ).get();
+ indexCreationFeature.setIndexPath( new URI("/this/local/.index") );
+
+ RemoteRepositoryConfiguration cfg = provider.getRemoteConfiguration( repo );
+ assertEquals("https://this.is/a/test", cfg.getUrl());
+ assertEquals( "This is a description", cfg.getDescription() );
+ assertEquals("maven2", cfg.getLayout());
+ assertEquals("test0003", cfg.getName());
+ assertEquals("0 0 05 ? * WED", cfg.getRefreshCronExpression());
+ assertEquals("/this/remote/.index", cfg.getRemoteIndexUrl());
+ assertEquals("proxyabc", cfg.getRemoteDownloadNetworkProxyId());
+ assertEquals(54, cfg.getRemoteDownloadTimeout());
+ assertFalse(cfg.isDownloadRemoteIndex());
+ assertTrue(cfg.isDownloadRemoteIndexOnStartup());
+ assertEquals("/this/local/.index", cfg.getIndexDir());
+
+
+ }
+
}
\ No newline at end of file