]> source.dussan.org Git - archiva.git/commitdiff
Improving repository provider
authorMartin Stockhammer <martin_s@apache.org>
Sun, 15 Oct 2017 21:36:30 +0000 (23:36 +0200)
committerMartin Stockhammer <martin_s@apache.org>
Sun, 15 Oct 2017 21:36:30 +0000 (23:36 +0200)
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRemoteRepository.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepository.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/EditableRepository.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryProvider.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryRegistry.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/features/IndexCreationFeature.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/features/RemoteIndexFeature.java
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRemoteRepository.java
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java
archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/maven2/MavenRepositoryProviderTest.java

index 4d2842342d2b0f2b9bad52a74cf28a0eb0ae3fc8..e1e570a78759dfe069fddb2953e3f4ef5a17562a 100644 (file)
@@ -39,7 +39,7 @@ public abstract class AbstractRemoteRepository extends AbstractRepository implem
     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;
 
index ad55d5c464c926248b88788941f2c082e1792cb8..a517d84d7c2307537b29ff19575cb37a97623e04 100644 (file)
@@ -52,7 +52,6 @@ public abstract class AbstractRepository implements EditableRepository
     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);
 
@@ -134,10 +133,7 @@ public abstract class AbstractRepository implements EditableRepository
     }
 
     @Override
-    public boolean hasIndex( )
-    {
-        return index;
-    }
+    public abstract boolean hasIndex( );
 
     @Override
     public String getLayout( )
@@ -208,12 +204,6 @@ public abstract class AbstractRepository implements EditableRepository
         this.scanned = scanned;
     }
 
-    @Override
-    public void setIndex( boolean hasIndex )
-    {
-        this.index = hasIndex;
-    }
-
     @Override
     public void setLayout( String layout )
     {
index 3af558080f48171bc3c25c08e04ecb8bedd5b66b..67154223e249b77474f4f3264cf2d3ced49d0874 100644 (file)
@@ -107,12 +107,6 @@ public interface EditableRepository extends Repository
      */
     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
index 0d5fd7eb9282208e34c4b1955c49b3c2e90d6b31..9a4c8f1cf156b58b5c9333ac6e04fc75763b571d 100644 (file)
@@ -36,5 +36,11 @@ public interface RepositoryProvider
 
     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;
 }
index 8f608d22811d483bbe581886fbe87cf9a243b39c..a5273a61259f380aeefe8f24cca651470ec7d642 100644 (file)
@@ -23,6 +23,7 @@ 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.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
@@ -30,16 +31,20 @@ 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
 {
 
@@ -57,98 +62,135 @@ 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 );
                 }
             }
         }
@@ -156,35 +198,102 @@ public class RepositoryRegistry
         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( );
+        }
     }
 
 }
index 38c44c83ed2d10a64ec1de232a1e7313674a2271..276232e82aa79cb3bb8ab984a7877249ebaa60db 100644 (file)
@@ -20,6 +20,8 @@ package org.apache.archiva.repository.features;
  */
 
 
+import org.apache.commons.lang.StringUtils;
+
 import java.net.URI;
 
 /**
@@ -82,4 +84,7 @@ public class IndexCreationFeature implements RepositoryFeature<IndexCreationFeat
     }
 
 
+    public boolean hasIndex() {
+        return this.indexPath!=null && !StringUtils.isEmpty( this.indexPath.getPath() );
+    }
 }
index 7f510ddf97cc889c0f6395d1d704930dcd57ecce..dca455a7fdeb19a030d0a2f13a4d0f03865fc8bc 100644 (file)
@@ -20,6 +20,8 @@ package org.apache.archiva.repository.features;
  */
 
 
+import org.apache.commons.lang.StringUtils;
+
 import java.net.URI;
 import java.time.Duration;
 
@@ -122,4 +124,13 @@ public class RemoteIndexFeature implements RepositoryFeature<RemoteIndexFeature>
     {
         this.proxyId = proxyId;
     }
+
+    /**
+     * Returns true, if there is a index available.
+     *
+     * @return
+     */
+    public boolean hasIndex() {
+        return this.indexUri!=null && !StringUtils.isEmpty( this.indexUri.getPath() );
+    }
 }
index 8f885c23a81064c6eeac46f63d5b93c5383eb02f..f9b169808dac36f8feac6d2db36b57274a28d586 100644 (file)
@@ -101,7 +101,9 @@ public class MavenManagedRepository extends AbstractManagedRepository
         return false;
     }
 
-
-
-
+    @Override
+    public boolean hasIndex( )
+    {
+        return indexCreationFeature.hasIndex();
+    }
 }
index 9887a056d80ccb1811d146c0762e30bb8f78dea7..224177d74d28dcf141c52e65344c802035358a15 100644 (file)
@@ -40,13 +40,14 @@ import java.util.Locale;
 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,
@@ -64,6 +65,12 @@ public class MavenRemoteRepository extends AbstractRemoteRepository
         super( primaryLocale, RepositoryType.MAVEN, id, name );
     }
 
+    @Override
+    public boolean hasIndex( )
+    {
+        return remoteIndexFeature.hasIndex();
+    }
+
     @Override
     public RepositoryCapabilities getCapabilities( )
     {
@@ -75,6 +82,8 @@ public class MavenRemoteRepository extends AbstractRemoteRepository
     {
         if (RemoteIndexFeature.class.equals( clazz )) {
             return (RepositoryFeature<T>) remoteIndexFeature;
+        } else if (IndexCreationFeature.class.equals(clazz)) {
+            return (RepositoryFeature<T>) indexCreationFeature;
         } else {
             throw new UnsupportedFeatureException(  );
         }
@@ -83,7 +92,7 @@ public class MavenRemoteRepository extends AbstractRemoteRepository
     @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;
index 2f862fee46f4ed353648c5193f226d13d8009251..0df46964b8d3196c7ed70ff870d3942193548579 100644 (file)
@@ -27,6 +27,7 @@ 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.RepositoryCredentials;
 import org.apache.archiva.repository.RepositoryException;
 import org.apache.archiva.repository.RepositoryProvider;
 import org.apache.archiva.repository.RepositoryType;
@@ -35,18 +36,21 @@ 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.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
@@ -68,27 +72,30 @@ public class MavenRepositoryProvider implements RepositoryProvider
         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;
@@ -98,7 +105,7 @@ public class MavenRepositoryProvider implements RepositoryProvider
     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() );
@@ -113,12 +120,10 @@ public class MavenRepositoryProvider implements RepositoryProvider
 
         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();
 
@@ -129,10 +134,15 @@ public class MavenRepositoryProvider implements RepositoryProvider
         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 );
@@ -146,6 +156,7 @@ public class MavenRepositoryProvider implements RepositoryProvider
         {
             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() );
@@ -175,34 +186,144 @@ public class MavenRepositoryProvider implements RepositoryProvider
         } 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() );
 
     }
index 9a08f070b10fb977c24a2a023573eef841a33cd9..aa5ddefb5d86fe00fea1c9bb169b24b0a0ddcb12 100644 (file)
@@ -23,6 +23,7 @@ import org.apache.archiva.configuration.ArchivaConfiguration;
 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;
@@ -35,26 +36,27 @@ import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
 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;
 
 
@@ -75,32 +77,51 @@ public class MavenRepositoryProviderTest
     @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());
 
 
@@ -109,17 +130,51 @@ public class MavenRepositoryProviderTest
     @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( );
@@ -128,13 +183,8 @@ public class MavenRepositoryProviderTest
             // 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( );
@@ -146,4 +196,84 @@ public class MavenRepositoryProviderTest
         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