aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2017-11-01 15:30:35 +0100
committerMartin Stockhammer <martin_s@apache.org>2017-11-01 15:30:35 +0100
commitfd51964c13cdeb633aad1944c0b95b1a571681e2 (patch)
tree0aba628d9451dd2a03af20604c5f6fa9cdbf4614 /archiva-modules
parentd6e4a5b48580ffc0420df5c6b2486fa0e57ab7c4 (diff)
downloadarchiva-fd51964c13cdeb633aad1944c0b95b1a571681e2.tar.gz
archiva-fd51964c13cdeb633aad1944c0b95b1a571681e2.zip
Using RepositoryRegistry in repository admin implementations
Switching to the repository registry to retrieve repository data. Indexing is currently kept in the admin part, but will be moved in the future to the registry.
Diffstat (limited to 'archiva-modules')
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/pom.xml4
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/AbstractRepository.java124
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ManagedRepository.java38
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RemoteRepository.java20
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/managed/ManagedRepositoryAdmin.java1
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/pom.xml4
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/AbstractRepositoryAdmin.java44
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java422
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/networkproxy/DefaultNetworkProxyAdmin.java28
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java202
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java8
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java46
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/proxyconnectorrule/ProxyConnectorRuleAdminTest.java5
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/resources/default-archiva.xml185
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/resources/spring-context.xml5
15 files changed, 769 insertions, 367 deletions
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/pom.xml b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/pom.xml
index b7e8ad21a..bf2868c42 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/pom.xml
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/pom.xml
@@ -30,6 +30,10 @@
<name>Archiva Base :: Repository Admin Api</name>
<dependencies>
<dependency>
+ <groupId>org.apache.archiva</groupId>
+ <artifactId>archiva-repository-layer</artifactId>
+ </dependency>
+ <dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency>
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/AbstractRepository.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/AbstractRepository.java
index 7438f4f12..0f2ce93b8 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/AbstractRepository.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/AbstractRepository.java
@@ -19,6 +19,12 @@ package org.apache.archiva.admin.model.beans;
*/
import java.io.Serializable;
+import java.security.KeyStore;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.stream.Collectors;
/**
* @author Olivier Lamy
@@ -28,29 +34,51 @@ public class AbstractRepository
implements Serializable
{
+ private Locale defaultLocale = Locale.getDefault();
+
+ private String type;
+
private String id;
- private String name;
+ /*
+ * @since 3.0.0 as Map
+ */
+ private Map<Locale, String> name = new HashMap<>( );
+
+ /*
+ * @since 3.0.0 as Map
+ */
+ private Map<Locale, String> description = new HashMap<>( );
private String layout = "default";
private String indexDirectory;
- /**
- * @since 1.4-M3
- */
- private String description;
+ private String toStringCache = null;
+
public AbstractRepository()
{
// no op
}
+ public AbstractRepository(Locale defaultLocale) {
+ this.defaultLocale = defaultLocale;
+ }
+
+ public AbstractRepository( Locale defaultLocale, String id, String name, String layout )
+ {
+ this.defaultLocale = defaultLocale;
+ setId(id);
+ setName(name);
+ setLayout(layout);
+ }
+
public AbstractRepository( String id, String name, String layout )
{
- this.id = id;
- this.name = name;
- this.layout = layout;
+ setId(id);
+ setName(name);
+ setLayout(layout);
}
public String getId()
@@ -60,17 +88,32 @@ public class AbstractRepository
public void setId( String id )
{
+ this.toStringCache=null;
this.id = id;
}
public String getName()
{
- return name;
+ return name.get(defaultLocale);
+ }
+
+ public Map<String,String> getNames() {
+ if (this.name==null) {
+ return Collections.emptyMap();
+ }
+ return this.name.entrySet().stream().collect( Collectors.toMap( e -> e.getKey().toLanguageTag(), Map.Entry::getValue ) );
}
public void setName( String name )
{
- this.name = name;
+ this.toStringCache=null;
+ this.name.put(defaultLocale, name);
+ }
+
+ public void setName( String languageTag, String name ) {
+ this.toStringCache=null;
+ final Locale loc = Locale.forLanguageTag( languageTag );
+ this.name.put(loc, name);
}
public String getLayout()
@@ -80,6 +123,7 @@ public class AbstractRepository
public void setLayout( String layout )
{
+ this.toStringCache=null;
this.layout = layout;
}
@@ -97,12 +141,28 @@ public class AbstractRepository
public String getDescription()
{
- return description;
+ return this.description.get(defaultLocale);
}
+ public Map<String,String> getDescriptions() {
+ if (this.description==null) {
+ return Collections.emptyMap();
+ }
+ return this.description.entrySet().stream().filter( e -> e!=null && e.getKey()!=null )
+ .collect( Collectors.toMap( e -> e.getKey().toLanguageTag(), e -> e.getValue()==null ? "" : e.getValue() ) );
+ }
+
+
public void setDescription( String description )
{
- this.description = description;
+ this.toStringCache=null;
+ this.description.put(defaultLocale, description);
+ }
+
+ public void setDescription( String languageTag, String description) {
+ this.toStringCache = null;
+ final Locale loc = Locale.forLanguageTag( languageTag );
+ this.description.put(loc, description);
}
@Override
@@ -132,17 +192,39 @@ public class AbstractRepository
return result;
}
+ private String getLocaleString(Map<Locale, String> map) {
+ return map.entrySet().stream().map(entry -> entry.getKey().toLanguageTag()+'='+entry.getValue()).collect( Collectors.joining( ",") );
+ }
+
+ public String getType( )
+ {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
@Override
public String toString()
{
- final StringBuilder sb = new StringBuilder();
- sb.append( "AbstractRepository" );
- sb.append( "{id='" ).append( id ).append( '\'' );
- sb.append( ", name='" ).append( name ).append( '\'' );
- sb.append( ", layout='" ).append( layout ).append( '\'' );
- sb.append( ", indexDirectory='" ).append( indexDirectory ).append( '\'' );
- sb.append( ", description='" ).append( description ).append( '\'' );
- sb.append( '}' );
- return sb.toString();
+ if (toStringCache!=null) {
+ return toStringCache;
+ } else
+ {
+ final StringBuilder sb = new StringBuilder( );
+ sb.append( "AbstractRepository" );
+ sb.append( "{id='" ).append( id ).append( '\'' );
+ sb.append(", type='").append(type).append('\'');
+ sb.append( ", name='" ).append( getLocaleString( name ) ).append( '\'' );
+ sb.append( ", layout='" ).append( layout ).append( '\'' );
+ sb.append( ", indexDirectory='" ).append( indexDirectory ).append( '\'' );
+ sb.append( ", description='" ).append( getLocaleString( description ) ).append( '\'' );
+ sb.append( '}' );
+ toStringCache=sb.toString( );
+ return toStringCache;
+ }
}
+
+
}
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ManagedRepository.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ManagedRepository.java
index b8b58ea50..bd0b2af60 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ManagedRepository.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ManagedRepository.java
@@ -21,6 +21,7 @@ package org.apache.archiva.admin.model.beans;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
+import java.util.Locale;
/**
* @author Olivier Lamy
@@ -57,7 +58,7 @@ public class ManagedRepository
/**
* default model value
*/
- private int retentionTime = 100;
+ private int retentionPeriod = 100;
/**
* default model value
@@ -75,17 +76,22 @@ public class ManagedRepository
*/
private boolean skipPackedIndexCreation;
- public ManagedRepository()
+ public ManagedRepository() {
+ super(Locale.getDefault());
+ }
+
+ public ManagedRepository(Locale defaultLocale)
{
- // no op
+ super(defaultLocale);
}
- public ManagedRepository( String id, String name, String location, String layout, boolean snapshots,
+
+ public ManagedRepository( Locale defaultLocale, String id, String name, String location, String layout, boolean snapshots,
boolean releases, boolean blockRedeployments, String cronExpression, String indexDir,
- boolean scanned, int retentionTime, int retentionCount, boolean deleteReleasedSnapshots,
+ boolean scanned, int retentionPeriod, int retentionCount, boolean deleteReleasedSnapshots,
boolean stageRepoNeeded )
{
- super( id, name, layout );
+ super( defaultLocale, id, name, layout );
this.location = location;
this.snapshots = snapshots;
@@ -94,7 +100,7 @@ public class ManagedRepository
this.setCronExpression( cronExpression );
this.setIndexDirectory( indexDir );
this.scanned = scanned;
- this.retentionTime = retentionTime;
+ this.retentionPeriod = retentionPeriod;
this.retentionCount = retentionCount;
this.deleteReleasedSnapshots = deleteReleasedSnapshots;
this.stageRepoNeeded = stageRepoNeeded;
@@ -103,13 +109,13 @@ public class ManagedRepository
/**
* @since 1.4-M3
*/
- public ManagedRepository( String id, String name, String location, String layout, boolean snapshots,
+ public ManagedRepository( Locale defaultLocale, String id, String name, String location, String layout, boolean snapshots,
boolean releases, boolean blockRedeployments, String cronExpression, String indexDir,
- boolean scanned, int retentionTime, int retentionCount, boolean deleteReleasedSnapshots,
+ boolean scanned, int retentionPeriod, int retentionCount, boolean deleteReleasedSnapshots,
boolean stageRepoNeeded, String description, boolean skipPackedIndexCreation )
{
- this( id, name, location, layout, snapshots, releases, blockRedeployments, cronExpression, indexDir, scanned,
- retentionTime, retentionCount, deleteReleasedSnapshots, stageRepoNeeded );
+ this( defaultLocale, id, name, location, layout, snapshots, releases, blockRedeployments, cronExpression, indexDir, scanned,
+ retentionPeriod, retentionCount, deleteReleasedSnapshots, stageRepoNeeded );
setDescription( description );
setSkipPackedIndexCreation( skipPackedIndexCreation );
}
@@ -192,14 +198,14 @@ public class ManagedRepository
}
- public int getDaysOlder()
+ public int getRetentionPeriod()
{
- return retentionTime;
+ return retentionPeriod;
}
- public void setDaysOlder( int retentionTime )
+ public void setRetentionPeriod( int periodInDays )
{
- this.retentionTime = retentionTime;
+ this.retentionPeriod = periodInDays;
}
public int getRetentionCount()
@@ -265,7 +271,7 @@ public class ManagedRepository
sb.append( ", cronExpression='" ).append( cronExpression ).append( '\'' );
sb.append( ", stagingRepository=" ).append( stagingRepository );
sb.append( ", scanned=" ).append( scanned );
- sb.append( ", retentionTime=" ).append( retentionTime );
+ sb.append( ", retentionPeriod=" ).append( retentionPeriod );
sb.append( ", retentionCount=" ).append( retentionCount );
sb.append( ", deleteReleasedSnapshots=" ).append( deleteReleasedSnapshots );
sb.append( ", stageRepoNeeded=" ).append( stageRepoNeeded );
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RemoteRepository.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RemoteRepository.java
index fd07ce9ac..f56127aaf 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RemoteRepository.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RemoteRepository.java
@@ -26,6 +26,7 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
/**
@@ -104,22 +105,25 @@ public class RemoteRepository
*/
private List<PropertyEntry> extraHeadersEntries;
+ public RemoteRepository() {
+ super(Locale.getDefault());
+ }
- public RemoteRepository()
+ public RemoteRepository(Locale locale)
{
- // no op
+ super(locale);
}
- public RemoteRepository( String id, String name, String url, String layout )
+ public RemoteRepository( Locale locale, String id, String name, String url, String layout )
{
- super( id, name, layout );
+ super( locale, id, name, layout );
this.url = url;
}
- public RemoteRepository( String id, String name, String url, String layout, String userName, String password,
+ public RemoteRepository( Locale locale, String id, String name, String url, String layout, String userName, String password,
int timeout )
{
- super( id, name, layout );
+ super( locale, id, name, layout );
this.url = StringUtils.stripEnd(url,"/");
this.userName = userName;
this.password = password;
@@ -129,10 +133,10 @@ public class RemoteRepository
/**
* @since 1.4-M3
*/
- public RemoteRepository( String id, String name, String url, String layout, String userName, String password,
+ public RemoteRepository( Locale locale, String id, String name, String url, String layout, String userName, String password,
int timeout, String description )
{
- this( id, name, url, layout, userName, password, timeout );
+ this( locale, id, name, url, layout, userName, password, timeout );
setDescription( description );
}
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/managed/ManagedRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/managed/ManagedRepositoryAdmin.java
index 2591b7569..a73e457d1 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/managed/ManagedRepositoryAdmin.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/managed/ManagedRepositoryAdmin.java
@@ -68,4 +68,5 @@ public interface ManagedRepositoryAdmin
throws RepositoryAdminException;
+ IndexingContext createIndexContext( org.apache.archiva.repository.ManagedRepository repository) throws RepositoryAdminException;
}
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/pom.xml b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/pom.xml
index 724d838f8..cfcf79349 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/pom.xml
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/pom.xml
@@ -75,6 +75,10 @@
<artifactId>metadata-model</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.archiva</groupId>
+ <artifactId>maven2-repository</artifactId>
+ </dependency>
+ <dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/AbstractRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/AbstractRepositoryAdmin.java
index 183e15b75..1a8ccc712 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/AbstractRepositoryAdmin.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/AbstractRepositoryAdmin.java
@@ -21,13 +21,18 @@ package org.apache.archiva.admin.repository;
import org.apache.archiva.admin.model.AuditInformation;
import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.admin.model.RepositoryCommonValidator;
+import org.apache.archiva.admin.model.beans.AbstractRepository;
+import org.apache.archiva.configuration.AbstractRepositoryConfiguration;
import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.Configuration;
import org.apache.archiva.configuration.IndeterminateConfigurationException;
import org.apache.archiva.metadata.model.facets.AuditEvent;
import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.components.registry.Registry;
+import org.apache.archiva.repository.Repository;
import org.apache.archiva.repository.events.AuditListener;
+import org.apache.archiva.repository.features.IndexCreationFeature;
+import org.apache.commons.lang.StringUtils;
import org.modelmapper.ModelMapper;
import org.modelmapper.convention.MatchingStrategies;
import org.slf4j.Logger;
@@ -36,6 +41,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import javax.inject.Inject;
import javax.inject.Named;
+import java.net.URI;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
@@ -93,6 +100,43 @@ public abstract class AbstractRepositoryAdmin
}
}
+ protected String convertUriToString( URI uri ) {
+ if (uri==null) {
+ return "";
+ }
+ String result;
+ if (uri.getScheme()==null) {
+ result = uri.getPath();
+ } else if ("file".equals(uri.getScheme())) {
+ result = Paths.get(uri).normalize().toString();
+ } else {
+ result = uri.toString();
+ }
+ log.debug("Converted uri {} -> {}", uri, result);
+ return result;
+ }
+
+ protected void setBaseRepoAttributes( AbstractRepository adminRepo, Repository repo){
+ adminRepo.setId(repo.getId());
+ adminRepo.setName( repo.getName() );
+ adminRepo.setLayout( repo.getLayout( ) );
+ adminRepo.setDescription( repo.getDescription() );
+ adminRepo.setType(repo.getType()==null?"MAVEN": repo.getType().name());
+ if (repo.supportsFeature( IndexCreationFeature.class )) {
+ IndexCreationFeature icf = repo.getFeature( IndexCreationFeature.class ).get();
+ adminRepo.setIndexDirectory( convertUriToString( icf.getIndexPath() ) );
+ }
+ }
+
+ protected void setBaseRepoAttributes( AbstractRepositoryConfiguration repoConfig, AbstractRepository repo) {
+ repoConfig.setId( repo.getId() );
+ repoConfig.setName( repo.getName() );
+ repoConfig.setLayout( repo.getLayout() );
+ repoConfig.setDescription( repo.getDescription() );
+ repoConfig.setIndexDir( repo.getIndexDirectory() );
+ repoConfig.setType( StringUtils.isEmpty( repo.getType() ) ? "MAVEN" : repo.getType() );
+ }
+
private static class ModelMapperHolder
{
private static ModelMapper MODEL_MAPPER = new ModelMapper();
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
index 6d7a914f5..ae7cd6255 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
@@ -24,6 +24,7 @@ import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
import org.apache.archiva.configuration.Configuration;
+import org.apache.archiva.configuration.IndeterminateConfigurationException;
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.archiva.configuration.ProxyConnectorConfiguration;
import org.apache.archiva.configuration.RepositoryGroupConfiguration;
@@ -34,13 +35,19 @@ import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.metadata.repository.RepositorySessionFactory;
import org.apache.archiva.metadata.repository.stats.model.RepositoryStatisticsManager;
import org.apache.archiva.redback.components.cache.Cache;
+import org.apache.archiva.redback.components.registry.RegistryException;
import org.apache.archiva.redback.components.taskqueue.TaskQueueException;
import org.apache.archiva.redback.role.RoleManager;
import org.apache.archiva.redback.role.RoleManagerException;
+import org.apache.archiva.repository.ReleaseScheme;
+import org.apache.archiva.repository.RepositoryException;
+import org.apache.archiva.repository.RepositoryRegistry;
+import org.apache.archiva.repository.features.ArtifactCleanupFeature;
+import org.apache.archiva.repository.features.IndexCreationFeature;
+import org.apache.archiva.repository.features.StagingRepositoryFeature;
import org.apache.archiva.scheduler.repository.model.RepositoryArchivaTaskScheduler;
import org.apache.archiva.scheduler.repository.model.RepositoryTask;
import org.apache.archiva.security.common.ArchivaRoleConstants;
-import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.index.NexusIndexer;
import org.apache.maven.index.context.IndexCreator;
@@ -56,10 +63,15 @@ import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.IOException;
+import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
/**
* FIXME review the staging mechanism to have a per user session one
@@ -76,6 +88,10 @@ public class DefaultManagedRepositoryAdmin
public static final String STAGE_REPO_ID_END = "-stage";
+
+ @Inject
+ private RepositoryRegistry repositoryRegistry;
+
@Inject
@Named(value = "archivaTaskScheduler#repository")
private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
@@ -110,6 +126,7 @@ public class DefaultManagedRepositoryAdmin
// initialize index context on start and check roles here
for ( ManagedRepository managedRepository : getManagedRepositories() )
{
+ log.debug("Initializating {}", managedRepository.getId());
createIndexContext( managedRepository );
addRepositoryRoles( managedRepository.getId() );
@@ -138,63 +155,80 @@ public class DefaultManagedRepositoryAdmin
}
}
+ /*
+ * Conversion between the repository from the registry and the serialized DTO for the admin API
+ */
+ private ManagedRepository convertRepo( org.apache.archiva.repository.ManagedRepository repo ) {
+ if (repo==null) {
+ return null;
+ }
+ ManagedRepository adminRepo = new ManagedRepository( getArchivaConfiguration().getDefaultLocale() );
+ setBaseRepoAttributes( adminRepo, repo );
+ adminRepo.setLocation( convertUriToString( repo.getLocation()) );
+ adminRepo.setReleases(repo.getActiveReleaseSchemes().contains( ReleaseScheme.RELEASE ));
+ adminRepo.setSnapshots( repo.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT) );
+ adminRepo.setBlockRedeployments( repo.blocksRedeployments() );
+ adminRepo.setCronExpression( repo.getSchedulingDefinition() );
+ if (repo.supportsFeature( IndexCreationFeature.class )) {
+ IndexCreationFeature icf = repo.getFeature( IndexCreationFeature.class ).get();
+ adminRepo.setIndexDirectory(convertUriToString( icf.getIndexPath() ));
+ adminRepo.setSkipPackedIndexCreation( icf.isSkipPackedIndexCreation() );
+ }
+ adminRepo.setScanned( repo.isScanned() );
+ if (repo.supportsFeature( ArtifactCleanupFeature.class) ) {
+ ArtifactCleanupFeature acf = repo.getFeature( ArtifactCleanupFeature.class ).get();
+ adminRepo.setRetentionPeriod( acf.getRetentionPeriod().getDays() );
+ adminRepo.setRetentionCount( acf.getRetentionCount() );
+ adminRepo.setDeleteReleasedSnapshots( acf.isDeleteReleasedSnapshots() );
+
+ }
+ if (repo.supportsFeature( StagingRepositoryFeature.class )) {
+ StagingRepositoryFeature stf = repo.getFeature( StagingRepositoryFeature.class ).get();
+ adminRepo.setStageRepoNeeded( stf.isStageRepoNeeded() );
+ if (stf.getStagingRepository()!=null) {
+ adminRepo.setStagingRepository( convertRepo( stf.getStagingRepository() ) );
+ }
+ }
+ return adminRepo;
+ }
+
+ private ManagedRepositoryConfiguration getRepositoryConfiguration(ManagedRepository repo) {
+ ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
+ setBaseRepoAttributes( repoConfig, repo );
+ repoConfig.setBlockRedeployments( repo.isBlockRedeployments( ) );
+ repoConfig.setReleases( repo.isReleases() );
+ repoConfig.setSnapshots( repo.isSnapshots() );
+ repoConfig.setScanned( repo.isScanned() );
+ repoConfig.setLocation( getRepositoryCommonValidator().removeExpressions( repo.getLocation() ) );
+ repoConfig.setRefreshCronExpression( repo.getCronExpression() );
+ repoConfig.setRetentionPeriod( repo.getRetentionPeriod() );
+ repoConfig.setRetentionCount( repo.getRetentionCount());
+ repoConfig.setDeleteReleasedSnapshots( repo.isDeleteReleasedSnapshots() );
+ repoConfig.setSkipPackedIndexCreation( repo.isSkipPackedIndexCreation());
+ repoConfig.setStageRepoNeeded( repo.isStageRepoNeeded() );
+ return repoConfig;
+ }
+
@Override
public List<ManagedRepository> getManagedRepositories()
throws RepositoryAdminException
{
- List<ManagedRepositoryConfiguration> managedRepoConfigs =
- getArchivaConfiguration().getConfiguration().getManagedRepositories();
-
- if ( managedRepoConfigs == null )
- {
- return Collections.emptyList();
- }
-
- List<ManagedRepository> managedRepos = new ArrayList<ManagedRepository>( managedRepoConfigs.size() );
-
- for ( ManagedRepositoryConfiguration repoConfig : managedRepoConfigs )
- {
- ManagedRepository repo =
- new ManagedRepository( repoConfig.getId(), repoConfig.getName(), repoConfig.getLocation(),
- repoConfig.getLayout(), repoConfig.isSnapshots(), repoConfig.isReleases(),
- repoConfig.isBlockRedeployments(), repoConfig.getRefreshCronExpression(),
- repoConfig.getIndexDir(), repoConfig.isScanned(), repoConfig.getRetentionTime(),
- repoConfig.getRetentionCount(), repoConfig.isDeleteReleasedSnapshots(),
- repoConfig.isStageRepoNeeded() );
- repo.setDescription( repoConfig.getDescription() );
- repo.setSkipPackedIndexCreation( repoConfig.isSkipPackedIndexCreation() );
- managedRepos.add( repo );
- }
- return managedRepos;
+ return repositoryRegistry.getManagedRepositories().stream().map( rep -> this.convertRepo( rep ) ).collect( Collectors.toList());
}
@Override
public Map<String, ManagedRepository> getManagedRepositoriesAsMap()
throws RepositoryAdminException
{
- List<ManagedRepository> managedRepositories = getManagedRepositories();
- Map<String, ManagedRepository> repositoriesMap = new HashMap<>( managedRepositories.size() );
- for ( ManagedRepository managedRepository : managedRepositories )
- {
- repositoriesMap.put( managedRepository.getId(), managedRepository );
- }
- return repositoriesMap;
+ return repositoryRegistry.getManagedRepositories().stream().collect( Collectors.toMap( e -> e.getId(), e -> convertRepo( e ) ) );
}
@Override
public ManagedRepository getManagedRepository( String repositoryId )
throws RepositoryAdminException
{
- List<ManagedRepository> repos = getManagedRepositories();
- for ( ManagedRepository repo : repos )
- {
- if ( StringUtils.equals( repo.getId(), repositoryId ) )
- {
- return repo;
- }
- }
- return null;
+ return convertRepo( repositoryRegistry.getManagedRepository( repositoryId ) );
}
@Override
@@ -202,105 +236,66 @@ public class DefaultManagedRepositoryAdmin
AuditInformation auditInformation )
throws RepositoryAdminException
{
+ log.debug("addManagedRepository {}, {}, {}", managedRepository.getId(), needStageRepo, auditInformation);
getRepositoryCommonValidator().basicValidation( managedRepository, false );
getRepositoryCommonValidator().validateManagedRepository( managedRepository );
triggerAuditEvent( managedRepository.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation );
- Boolean res =
- addManagedRepository( managedRepository.getId(), managedRepository.getLayout(), managedRepository.getName(),
- managedRepository.getLocation(), managedRepository.isBlockRedeployments(),
- managedRepository.isReleases(), managedRepository.isSnapshots(), needStageRepo,
- managedRepository.getCronExpression(), managedRepository.getIndexDirectory(),
- managedRepository.getDaysOlder(), managedRepository.getRetentionCount(),
- managedRepository.isDeleteReleasedSnapshots(), managedRepository.getDescription(),
- managedRepository.isSkipPackedIndexCreation(), managedRepository.isScanned(),
- auditInformation, getArchivaConfiguration().getConfiguration() ) != null;
-
- createIndexContext( managedRepository );
- return res;
-
- }
-
- private ManagedRepositoryConfiguration addManagedRepository( String repoId, String layout, String name,
- String location, boolean blockRedeployments,
- boolean releasesIncluded, boolean snapshotsIncluded,
- boolean stageRepoNeeded, String cronExpression,
- String indexDir, int retentionTime, int retentionCount,
- boolean deteleReleasedSnapshots, String description,
- boolean skipPackedIndexCreation, boolean scanned,
- AuditInformation auditInformation,
- Configuration config )
- throws RepositoryAdminException
- {
-
- ManagedRepositoryConfiguration repository = new ManagedRepositoryConfiguration();
-
- repository.setId( repoId );
- repository.setBlockRedeployments( blockRedeployments );
- repository.setReleases( releasesIncluded );
- repository.setSnapshots( snapshotsIncluded );
- repository.setScanned( scanned );
- repository.setName( name );
- repository.setLocation( getRepositoryCommonValidator().removeExpressions( location ) );
- repository.setLayout( layout );
- repository.setRefreshCronExpression( cronExpression );
- repository.setIndexDir( indexDir );
- repository.setRetentionTime( retentionTime );
- repository.setRetentionCount( retentionCount );
- repository.setDeleteReleasedSnapshots( deteleReleasedSnapshots );
- repository.setIndexDir( indexDir );
- repository.setDescription( description );
- repository.setSkipPackedIndexCreation( skipPackedIndexCreation );
- repository.setStageRepoNeeded( stageRepoNeeded );
-
+ ManagedRepositoryConfiguration repoConfig = getRepositoryConfiguration( managedRepository );
+ if (needStageRepo) {
+ repoConfig.setStageRepoNeeded( true );
+ }
+ Configuration configuration = getArchivaConfiguration().getConfiguration();
try
{
- addRepository( repository, config );
- addRepositoryRoles( repository.getId() );
+ org.apache.archiva.repository.ManagedRepository newRepo = repositoryRegistry.putRepository( repoConfig, configuration );
+ log.debug("Added new repository {}", newRepo.getId());
+ org.apache.archiva.repository.ManagedRepository stagingRepo = null;
+ addRepositoryRoles( newRepo.getId() );
+ if ( newRepo.supportsFeature( StagingRepositoryFeature.class )) {
+ StagingRepositoryFeature stf = newRepo.getFeature( StagingRepositoryFeature.class ).get();
+ stagingRepo = stf.getStagingRepository();
+ if (stf.isStageRepoNeeded() && stagingRepo != null) {
+ addRepositoryRoles( stagingRepo.getId() );
+ triggerAuditEvent( stagingRepo.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation );
+ }
+ }
+ saveConfiguration( configuration );
+ //MRM-1342 Repository statistics report doesn't appear to be working correctly
+ //scan repository when adding of repository is successful
+ try
+ {
+ if ( newRepo.isScanned())
+ {
+ scanRepository( newRepo.getId(), true );
+ }
- if ( stageRepoNeeded )
+ if ( stagingRepo!=null && stagingRepo.isScanned() )
+ {
+ scanRepository( stagingRepo.getId(), true );
+ }
+ }
+ catch ( Exception e )
{
- ManagedRepositoryConfiguration stagingRepository = getStageRepoConfig( repository );
- addRepository( stagingRepository, config );
- addRepositoryRoles( stagingRepository.getId() );
- triggerAuditEvent( stagingRepository.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation );
+ log.warn("Unable to scan repository [{}]: {}", newRepo.getId(), e.getMessage(), e);
}
}
- catch ( RoleManagerException e )
+ catch ( RepositoryException e )
{
- throw new RepositoryAdminException( "failed to add repository roles " + e.getMessage(), e );
+ log.error("Could not add managed repository {}"+managedRepository);
+ throw new RepositoryAdminException( "Could not add repository "+e.getMessage() );
}
- catch ( IOException e )
+ catch ( RoleManagerException e )
{
- throw new RepositoryAdminException( "failed to add repository " + e.getMessage(), e );
+ log.error("Could not add repository roles for repository [{}]: {}", managedRepository.getId(), e.getMessage(), e);
+ throw new RepositoryAdminException( "Could not add roles to repository "+e.getMessage() );
}
+ createIndexContext( managedRepository );
+ return Boolean.TRUE;
- saveConfiguration( config );
-
- //MRM-1342 Repository statistics report doesn't appear to be working correctly
- //scan repository when adding of repository is successful
- try
- {
- if ( scanned )
- {
- scanRepository( repoId, true );
- }
+ }
- // TODO need a better to define scanning or not for staged repo
- if ( stageRepoNeeded && scanned )
- {
- ManagedRepositoryConfiguration stagingRepository = getStageRepoConfig( repository );
- scanRepository( stagingRepository.getId(), true );
- }
- }
- catch ( Exception e )
- {
- log.warn( new StringBuilder( "Unable to scan repository [" ).append( repoId ).append( "]: " ).append(
- e.getMessage() ).toString(), e );
- }
- return repository;
- }
@Override
public Boolean deleteManagedRepository( String repositoryId, AuditInformation auditInformation,
@@ -308,25 +303,53 @@ public class DefaultManagedRepositoryAdmin
throws RepositoryAdminException
{
Configuration config = getArchivaConfiguration().getConfiguration();
+ ManagedRepositoryConfiguration repoConfig=config.findManagedRepositoryById( repositoryId );
- ManagedRepositoryConfiguration repository = config.findManagedRepositoryById( repositoryId );
+ log.debug("Repo location "+repoConfig.getLocation());
- if ( repository == null )
- {
+ org.apache.archiva.repository.ManagedRepository repo = repositoryRegistry.getManagedRepository( repositoryId );
+ org.apache.archiva.repository.ManagedRepository stagingRepository = null;
+ if (repo!=null) {
+ try
+ {
+ if (repo.supportsFeature( StagingRepositoryFeature.class )) {
+ stagingRepository = repo.getFeature( StagingRepositoryFeature.class ).get().getStagingRepository();
+ }
+ repositoryRegistry.removeRepository( repo, config );
+ }
+ catch ( RepositoryException e )
+ {
+ log.error("Removal of repository {} failed: {}", repositoryId, e.getMessage(), e);
+ throw new RepositoryAdminException( "Removal of repository "+repositoryId+" failed." );
+ }
+ } else {
throw new RepositoryAdminException( "A repository with that id does not exist" );
}
triggerAuditEvent( repositoryId, null, AuditEvent.DELETE_MANAGED_REPO, auditInformation );
+ if (repoConfig!=null)
+ {
+ deleteManagedRepository( repoConfig, deleteContent, config, false );
+ }
- deleteManagedRepository( repository, deleteContent, config, false );
// stage repo exists ?
- ManagedRepositoryConfiguration stagingRepository =
- getArchivaConfiguration().getConfiguration().findManagedRepositoryById( repositoryId + STAGE_REPO_ID_END );
if ( stagingRepository != null )
{
// do not trigger event when deleting the staged one
- deleteManagedRepository( stagingRepository, deleteContent, config, true );
+ ManagedRepositoryConfiguration stagingRepositoryConfig = config.findManagedRepositoryById( stagingRepository.getId( ) );
+ try
+ {
+ repositoryRegistry.removeRepository( stagingRepository );
+ if (stagingRepositoryConfig!=null)
+ {
+ deleteManagedRepository( stagingRepositoryConfig, deleteContent, config, true );
+ }
+ }
+ catch ( RepositoryException e )
+ {
+ log.error("Removal of staging repository {} failed: {}", stagingRepository.getId(), e.getMessage(), e);
+ }
}
try
@@ -383,7 +406,6 @@ public class DefaultManagedRepositoryAdmin
repositorySession.close();
}
}
- config.removeManagedRepository( repository );
if ( deleteContent )
{
@@ -455,50 +477,63 @@ public class DefaultManagedRepositoryAdmin
Configuration configuration = getArchivaConfiguration().getConfiguration();
- ManagedRepositoryConfiguration toremove = configuration.findManagedRepositoryById( managedRepository.getId() );
+ ManagedRepositoryConfiguration updatedRepoConfig = getRepositoryConfiguration( managedRepository );
+ updatedRepoConfig.setStageRepoNeeded( needStageRepo );
- boolean updateIndexContext = false;
-
- if ( toremove != null )
- {
- configuration.removeManagedRepository( toremove );
-
- updateIndexContext = !StringUtils.equals( toremove.getIndexDir(), managedRepository.getIndexDirectory() );
+ org.apache.archiva.repository.ManagedRepository oldRepo = repositoryRegistry.getManagedRepository( managedRepository.getId( ) );
+ boolean stagingExists = false;
+ if (oldRepo.supportsFeature( StagingRepositoryFeature.class ) ){
+ stagingExists = oldRepo.getFeature( StagingRepositoryFeature.class ).get().getStagingRepository() != null;
}
-
- ManagedRepositoryConfiguration stagingRepository = getStageRepoConfig( toremove );
+ boolean updateIndexContext = !StringUtils.equals( updatedRepoConfig.getIndexDir(), managedRepository.getIndexDirectory() );
// TODO remove content from old if path has changed !!!!!
+ try
+ {
+ org.apache.archiva.repository.ManagedRepository newRepo = repositoryRegistry.putRepository( updatedRepoConfig, configuration );
+ if (newRepo.supportsFeature( StagingRepositoryFeature.class )) {
+ org.apache.archiva.repository.ManagedRepository stagingRepo = newRepo.getFeature( StagingRepositoryFeature.class ).get( ).getStagingRepository( );
+ if (stagingRepo!=null && !stagingExists)
+ {
+ triggerAuditEvent( stagingRepo.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation );
+ addRepositoryRoles( stagingRepo.getId( ) );
+ }
+ }
- if ( stagingRepository != null )
+
+ }
+ catch ( RepositoryException e )
{
- configuration.removeManagedRepository( stagingRepository );
+ log.error("Could not update repository {}: {}", managedRepository.getId(), e.getMessage(), e);
+ throw new RepositoryAdminException( "Could not update repository "+managedRepository.getId());
+ }
+ catch ( RoleManagerException e ) {
+ log.error("Error during role update of stage repo {}", managedRepository.getId(), e);
+ throw new RepositoryAdminException( "Could not update repository "+managedRepository.getId());
+ }
+ triggerAuditEvent( managedRepository.getId(), null, AuditEvent.MODIFY_MANAGED_REPO,
+ auditInformation );
+ try
+ {
+ getArchivaConfiguration().save(configuration);
+ }
+ catch ( RegistryException | IndeterminateConfigurationException e )
+ {
+ log.error("Could not save repository configuration: {}", e.getMessage(), e);
+ throw new RepositoryAdminException( "Could not save repository configuration: "+e.getMessage() );
}
-
- ManagedRepositoryConfiguration managedRepositoryConfiguration =
- addManagedRepository( managedRepository.getId(), managedRepository.getLayout(), managedRepository.getName(),
- managedRepository.getLocation(), managedRepository.isBlockRedeployments(),
- managedRepository.isReleases(), managedRepository.isSnapshots(), needStageRepo,
- managedRepository.getCronExpression(), managedRepository.getIndexDirectory(),
- managedRepository.getDaysOlder(), managedRepository.getRetentionCount(),
- managedRepository.isDeleteReleasedSnapshots(), managedRepository.getDescription(),
- managedRepository.isSkipPackedIndexCreation(), managedRepository.isScanned(),
- auditInformation, getArchivaConfiguration().getConfiguration() );
// Save the repository configuration.
RepositorySession repositorySession = getRepositorySessionFactory().createSession();
try
{
- triggerAuditEvent( managedRepositoryConfiguration.getId(), null, AuditEvent.MODIFY_MANAGED_REPO,
- auditInformation );
- saveConfiguration( this.getArchivaConfiguration().getConfiguration() );
if ( resetStats )
{
log.debug( "call repositoryStatisticsManager.deleteStatistics" );
getRepositoryStatisticsManager().deleteStatistics( repositorySession.getRepository(),
- managedRepositoryConfiguration.getId() );
+ managedRepository.getId() );
repositorySession.save();
}
@@ -545,27 +580,20 @@ public class DefaultManagedRepositoryAdmin
protected void addRepository( ManagedRepositoryConfiguration repository, Configuration configuration )
throws RepositoryAdminException, IOException
{
- // Normalize the path
- Path file = Paths.get( repository.getLocation() );
- if ( !file.isAbsolute() )
- {
- // add appserver.base/repositories
- file = Paths.get( getRegistry().getString( "appserver.base" ),"repositories",
- repository.getLocation() );
- }
- repository.setLocation( file.normalize().toString() );
- if ( !Files.exists(file) )
+ try
{
- Files.createDirectories(file);
+ getRepositoryRegistry().putRepository( repository, configuration );
}
- if ( !Files.exists(file) || !Files.isDirectory(file) )
+ catch ( RepositoryException e )
{
- throw new RepositoryAdminException(
- "Unable to add repository - no write access, can not create the root directory: " + file );
+ throw new RepositoryAdminException( "Could not add the repository to the registry. Cause: "+e.getMessage() );
}
- configuration.addManagedRepository( repository );
+ }
+ public IndexingContext createIndexContext( org.apache.archiva.repository.ManagedRepository repository) throws RepositoryAdminException
+ {
+ return createIndexContext( convertRepo( repository ) );
}
@Override
@@ -668,44 +696,6 @@ public class DefaultManagedRepositoryAdmin
}
}
- private ManagedRepositoryConfiguration getStageRepoConfig( ManagedRepositoryConfiguration repository )
- {
- ManagedRepositoryConfiguration stagingRepository = new ManagedRepositoryConfiguration();
- stagingRepository.setId( repository.getId() + STAGE_REPO_ID_END );
- stagingRepository.setLayout( repository.getLayout() );
- stagingRepository.setName( repository.getName() + STAGE_REPO_ID_END );
- 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() ) )
- {
- 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;
- }
-
public Boolean scanRepository( String repositoryId, boolean fullScan )
{
if ( getRepositoryTaskScheduler().isProcessingRepositoryTask( repositoryId ) )
@@ -828,4 +818,14 @@ public class DefaultManagedRepositoryAdmin
{
this.indexCreators = indexCreators;
}
+
+ public RepositoryRegistry getRepositoryRegistry( )
+ {
+ return repositoryRegistry;
+ }
+
+ public void setRepositoryRegistry( RepositoryRegistry repositoryRegistry )
+ {
+ this.repositoryRegistry = repositoryRegistry;
+ }
}
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/networkproxy/DefaultNetworkProxyAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/networkproxy/DefaultNetworkProxyAdmin.java
index 7c3eb0c3e..6e383697b 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/networkproxy/DefaultNetworkProxyAdmin.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/networkproxy/DefaultNetworkProxyAdmin.java
@@ -25,11 +25,15 @@ import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin;
import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
import org.apache.archiva.configuration.Configuration;
import org.apache.archiva.configuration.NetworkProxyConfiguration;
-import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
import org.apache.archiva.metadata.model.facets.AuditEvent;
+import org.apache.archiva.repository.RemoteRepository;
+import org.apache.archiva.repository.RepositoryException;
+import org.apache.archiva.repository.RepositoryRegistry;
+import org.apache.archiva.repository.features.RemoteIndexFeature;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
+import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
@@ -43,6 +47,9 @@ public class DefaultNetworkProxyAdmin
implements NetworkProxyAdmin
{
+ @Inject
+ RepositoryRegistry repositoryRegistry;
+
@Override
public List<NetworkProxy> getNetworkProxies()
throws RepositoryAdminException
@@ -130,11 +137,20 @@ public class DefaultNetworkProxyAdmin
NetworkProxyConfiguration networkProxyConfiguration = getNetworkProxyConfiguration( networkProxy );
configuration.removeNetworkProxy( networkProxyConfiguration );
- for ( RemoteRepositoryConfiguration rrc : configuration.getRemoteRepositories() )
- {
- if ( StringUtils.equals( rrc.getRemoteDownloadNetworkProxyId(), networkProxyId ) )
- {
- rrc.setRemoteDownloadNetworkProxyId( null );
+ for ( RemoteRepository repo : repositoryRegistry.getRemoteRepositories()) {
+ if (repo.supportsFeature( RemoteIndexFeature.class )) {
+ RemoteIndexFeature rif = repo.getFeature( RemoteIndexFeature.class ).get();
+ if (networkProxyId.equals(rif.getProxyId())) {
+ rif.setProxyId( null );
+ try
+ {
+ repositoryRegistry.putRepository( repo, configuration);
+ }
+ catch ( RepositoryException e )
+ {
+ log.error("Could not update repository {}", repo.getId(), e);
+ }
+ }
}
}
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java
index 12c4d0766..19b540a98 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java
@@ -20,7 +20,6 @@ package org.apache.archiva.admin.repository.remote;
import org.apache.archiva.admin.model.AuditInformation;
import org.apache.archiva.admin.model.RepositoryAdminException;
-import org.apache.archiva.admin.model.beans.RemoteRepository;
import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
import org.apache.archiva.configuration.Configuration;
@@ -28,7 +27,12 @@ import org.apache.archiva.configuration.ProxyConnectorConfiguration;
import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
import org.apache.archiva.configuration.RepositoryCheckPath;
import org.apache.archiva.metadata.model.facets.AuditEvent;
-import org.apache.commons.io.FileUtils;
+import org.apache.archiva.repository.RemoteRepository;
+import org.apache.archiva.repository.PasswordCredentials;
+import org.apache.archiva.repository.RepositoryCredentials;
+import org.apache.archiva.repository.RepositoryException;
+import org.apache.archiva.repository.RepositoryRegistry;
+import org.apache.archiva.repository.features.RemoteIndexFeature;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.index.NexusIndexer;
import org.apache.maven.index.context.IndexCreator;
@@ -48,6 +52,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
/**
* @author Olivier Lamy
@@ -60,6 +65,9 @@ public class DefaultRemoteRepositoryAdmin
{
@Inject
+ RepositoryRegistry repositoryRegistry;
+
+ @Inject
private List<? extends IndexCreator> indexCreators;
@Inject
@@ -69,7 +77,7 @@ public class DefaultRemoteRepositoryAdmin
private void initialize()
throws RepositoryAdminException
{
- for ( RemoteRepository remoteRepository : getRemoteRepositories() )
+ for ( org.apache.archiva.admin.model.beans.RemoteRepository remoteRepository : getRemoteRepositories() )
{
createIndexContext( remoteRepository );
}
@@ -81,9 +89,9 @@ public class DefaultRemoteRepositoryAdmin
{
try
{
- List<RemoteRepository> remoteRepositories = getRemoteRepositories();
+ List<org.apache.archiva.admin.model.beans.RemoteRepository> remoteRepositories = getRemoteRepositories();
// close index on shutdown
- for ( RemoteRepository remoteRepository : remoteRepositories )
+ for ( org.apache.archiva.admin.model.beans.RemoteRepository remoteRepository : remoteRepositories )
{
IndexingContext context = indexer.getIndexingContexts().get( remoteRepository.getId() );
if ( context != null )
@@ -99,53 +107,74 @@ public class DefaultRemoteRepositoryAdmin
}
+ /*
+ * Conversion between the repository from the registry and the serialized DTO for the admin API
+ */
+ private org.apache.archiva.admin.model.beans.RemoteRepository convertRepo( RemoteRepository repo ) {
+ if (repo==null) {
+ return null;
+ }
+ org.apache.archiva.admin.model.beans.RemoteRepository adminRepo = new org.apache.archiva.admin.model.beans.RemoteRepository( getArchivaConfiguration().getDefaultLocale() );
+ setBaseRepoAttributes( adminRepo, repo );
+ adminRepo.setUrl( convertUriToString( repo.getLocation() ));
+ adminRepo.setCronExpression( repo.getSchedulingDefinition() );
+ adminRepo.setCheckPath( repo.getCheckPath() );
+ adminRepo.setExtraHeaders( repo.getExtraHeaders() );
+ adminRepo.setExtraParameters( repo.getExtraParameters() );
+ adminRepo.setTimeout( (int) repo.getTimeout().getSeconds() );
+ RepositoryCredentials creds = repo.getLoginCredentials();
+ if (creds!=null && creds instanceof PasswordCredentials) {
+ PasswordCredentials pCreds = (PasswordCredentials) creds;
+ adminRepo.setUserName( pCreds.getUsername() );
+ adminRepo.setPassword( new String(pCreds.getPassword()!=null ? pCreds.getPassword() : new char[0]) );
+ }
+ if (repo.supportsFeature( RemoteIndexFeature.class )) {
+ RemoteIndexFeature rif = repo.getFeature( RemoteIndexFeature.class ).get();
+ adminRepo.setRemoteIndexUrl( convertUriToString( rif.getIndexUri() ) );
+ adminRepo.setDownloadRemoteIndex( rif.isDownloadRemoteIndex() );
+ adminRepo.setRemoteDownloadNetworkProxyId( rif.getProxyId() );
+ adminRepo.setDownloadRemoteIndexOnStartup( rif.isDownloadRemoteIndexOnStartup() );
+ adminRepo.setRemoteDownloadTimeout( (int) rif.getDownloadTimeout().getSeconds() );
+ }
+ return adminRepo;
+ }
+
+ private RemoteRepositoryConfiguration getRepositoryConfiguration( org.apache.archiva.admin.model.beans.RemoteRepository repo) {
+ RemoteRepositoryConfiguration repoConfig = new RemoteRepositoryConfiguration();
+ setBaseRepoAttributes( repoConfig, repo );
+ repoConfig.setUrl( getRepositoryCommonValidator().removeExpressions( repo.getUrl() ) );
+ repoConfig.setRefreshCronExpression( repo.getCronExpression() );
+ repoConfig.setCheckPath( repo.getCheckPath() );
+ repoConfig.setExtraHeaders( repo.getExtraHeaders() );
+ repoConfig.setExtraParameters( repo.getExtraParameters() );
+ repoConfig.setUsername( repo.getUserName() );
+ repoConfig.setPassword( repo.getPassword() );
+ repoConfig.setTimeout( repo.getTimeout() );
+ repoConfig.setRemoteIndexUrl( repo.getRemoteIndexUrl() );
+ repoConfig.setDownloadRemoteIndex( repo.isDownloadRemoteIndex() );
+ repoConfig.setRemoteDownloadNetworkProxyId( repo.getRemoteDownloadNetworkProxyId() );
+ repoConfig.setDownloadRemoteIndexOnStartup( repo.isDownloadRemoteIndexOnStartup() );
+ repoConfig.setRemoteDownloadTimeout( repo.getRemoteDownloadTimeout() );
+ return repoConfig;
+ }
+
@Override
- public List<RemoteRepository> getRemoteRepositories()
+ public List<org.apache.archiva.admin.model.beans.RemoteRepository> getRemoteRepositories()
throws RepositoryAdminException
{
- List<RemoteRepository> remoteRepositories =
- new ArrayList<>( getArchivaConfiguration().getConfiguration().getRemoteRepositories().size() );
- for ( RemoteRepositoryConfiguration repositoryConfiguration : getArchivaConfiguration().getConfiguration().getRemoteRepositories() )
- {
- RemoteRepository remoteRepository =
- new RemoteRepository( repositoryConfiguration.getId(), repositoryConfiguration.getName(),
- repositoryConfiguration.getUrl(), repositoryConfiguration.getLayout(),
- repositoryConfiguration.getUsername(), repositoryConfiguration.getPassword(),
- repositoryConfiguration.getTimeout() );
- remoteRepository.setDownloadRemoteIndex( repositoryConfiguration.isDownloadRemoteIndex() );
- remoteRepository.setRemoteIndexUrl( repositoryConfiguration.getRemoteIndexUrl() );
- remoteRepository.setCronExpression( repositoryConfiguration.getRefreshCronExpression() );
- remoteRepository.setIndexDirectory( repositoryConfiguration.getIndexDir() );
- remoteRepository.setRemoteDownloadNetworkProxyId(
- repositoryConfiguration.getRemoteDownloadNetworkProxyId() );
- remoteRepository.setRemoteDownloadTimeout( repositoryConfiguration.getRemoteDownloadTimeout() );
- remoteRepository.setDownloadRemoteIndexOnStartup(
- repositoryConfiguration.isDownloadRemoteIndexOnStartup() );
- remoteRepository.setDescription( repositoryConfiguration.getDescription() );
- remoteRepository.setExtraHeaders( repositoryConfiguration.getExtraHeaders() );
- remoteRepository.setExtraParameters( repositoryConfiguration.getExtraParameters() );
- remoteRepository.setCheckPath(repositoryConfiguration.getCheckPath());
- remoteRepositories.add( remoteRepository );
- }
- return remoteRepositories;
+
+ return repositoryRegistry.getRemoteRepositories().stream().map( repo -> convertRepo( repo ) ).collect( Collectors.toList());
}
@Override
- public RemoteRepository getRemoteRepository( String repositoryId )
+ public org.apache.archiva.admin.model.beans.RemoteRepository getRemoteRepository( String repositoryId )
throws RepositoryAdminException
{
- for ( RemoteRepository remoteRepository : getRemoteRepositories() )
- {
- if ( StringUtils.equals( repositoryId, remoteRepository.getId() ) )
- {
- return remoteRepository;
- }
- }
- return null;
+ return convertRepo( repositoryRegistry.getRemoteRepository( repositoryId ));
}
@Override
- public Boolean addRemoteRepository( RemoteRepository remoteRepository, AuditInformation auditInformation )
+ public Boolean addRemoteRepository( org.apache.archiva.admin.model.beans.RemoteRepository remoteRepository, AuditInformation auditInformation )
throws RepositoryAdminException
{
triggerAuditEvent( remoteRepository.getId(), null, AuditEvent.ADD_REMOTE_REPO, auditInformation );
@@ -172,11 +201,21 @@ public class DefaultRemoteRepositoryAdmin
}
}
+ Configuration configuration = getArchivaConfiguration().getConfiguration();
RemoteRepositoryConfiguration remoteRepositoryConfiguration =
- getRemoteRepositoryConfiguration( remoteRepository );
+ getRepositoryConfiguration( remoteRepository );
+
+ try
+ {
+ repositoryRegistry.putRepository( remoteRepositoryConfiguration, configuration );
+ }
+ catch ( RepositoryException e )
+ {
+ log.error("Could not add remote repository {}: {}", remoteRepositoryConfiguration.getId(), e.getMessage(), e);
+ throw new RepositoryAdminException( "Adding of remote repository failed"+(e.getMessage()==null?"":": "+e.getMessage()) );
+
+ }
- Configuration configuration = getArchivaConfiguration().getConfiguration();
- configuration.addRemoteRepository( remoteRepositoryConfiguration );
saveConfiguration( configuration );
return Boolean.TRUE;
@@ -191,15 +230,19 @@ public class DefaultRemoteRepositoryAdmin
Configuration configuration = getArchivaConfiguration().getConfiguration();
- RemoteRepositoryConfiguration remoteRepositoryConfiguration =
- configuration.getRemoteRepositoriesAsMap().get( repositoryId );
- if ( remoteRepositoryConfiguration == null )
+ RemoteRepository repo = repositoryRegistry.getRemoteRepository( repositoryId );
+ if (repo==null) {
+ throw new RepositoryAdminException( "Could not delete repository "+repositoryId+". The repository does not exist." );
+ }
+ try
{
- throw new RepositoryAdminException(
- "remoteRepository with id " + repositoryId + " not exist cannot remove it" );
+ repositoryRegistry.removeRepository( repo, configuration );
+ }
+ catch ( RepositoryException e )
+ {
+ log.error("Deletion of remote repository failed {}: {}", repo.getId(), e.getMessage(), e);
+ throw new RepositoryAdminException( "Could not delete remote repository"+(e.getMessage()==null?"":": "+e.getMessage()) );
}
-
- configuration.removeRemoteRepository( remoteRepositoryConfiguration );
// TODO use ProxyConnectorAdmin interface ?
// [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository.
@@ -218,7 +261,7 @@ public class DefaultRemoteRepositoryAdmin
}
@Override
- public Boolean updateRemoteRepository( RemoteRepository remoteRepository, AuditInformation auditInformation )
+ public Boolean updateRemoteRepository( org.apache.archiva.admin.model.beans.RemoteRepository remoteRepository, AuditInformation auditInformation )
throws RepositoryAdminException
{
@@ -230,30 +273,27 @@ public class DefaultRemoteRepositoryAdmin
Configuration configuration = getArchivaConfiguration().getConfiguration();
- RemoteRepositoryConfiguration remoteRepositoryConfiguration =
- configuration.getRemoteRepositoriesAsMap().get( repositoryId );
- if ( remoteRepositoryConfiguration == null )
+ RemoteRepositoryConfiguration remoteRepositoryConfiguration = getRepositoryConfiguration( remoteRepository );
+ try
{
- throw new RepositoryAdminException(
- "remoteRepository with id " + repositoryId + " not exist cannot remove it" );
+ repositoryRegistry.putRepository( remoteRepositoryConfiguration, configuration );
+ }
+ catch ( RepositoryException e )
+ {
+ log.error("Could not update remote repository {}: {}", remoteRepositoryConfiguration.getId(), e.getMessage(), e);
+ throw new RepositoryAdminException( "Update of remote repository failed"+(e.getMessage()==null?"":": "+e.getMessage()) );
}
-
- configuration.removeRemoteRepository( remoteRepositoryConfiguration );
-
- remoteRepositoryConfiguration = getRemoteRepositoryConfiguration( remoteRepository );
- configuration.addRemoteRepository( remoteRepositoryConfiguration );
saveConfiguration( configuration );
-
return Boolean.TRUE;
}
@Override
- public Map<String, RemoteRepository> getRemoteRepositoriesAsMap()
+ public Map<String, org.apache.archiva.admin.model.beans.RemoteRepository> getRemoteRepositoriesAsMap()
throws RepositoryAdminException
{
- java.util.Map<String, RemoteRepository> map = new HashMap<>();
+ java.util.Map<String, org.apache.archiva.admin.model.beans.RemoteRepository> map = new HashMap<>();
- for ( RemoteRepository repo : getRemoteRepositories() )
+ for ( org.apache.archiva.admin.model.beans.RemoteRepository repo : getRemoteRepositories() )
{
map.put( repo.getId(), repo );
}
@@ -262,7 +302,7 @@ public class DefaultRemoteRepositoryAdmin
}
@Override
- public IndexingContext createIndexContext( RemoteRepository remoteRepository )
+ public IndexingContext createIndexContext( org.apache.archiva.admin.model.beans.RemoteRepository remoteRepository )
throws RepositoryAdminException
{
try
@@ -328,7 +368,7 @@ public class DefaultRemoteRepositoryAdmin
}
- protected String calculateIndexRemoteUrl( RemoteRepository remoteRepository )
+ protected String calculateIndexRemoteUrl( org.apache.archiva.admin.model.beans.RemoteRepository remoteRepository )
{
if ( StringUtils.startsWith( remoteRepository.getRemoteIndexUrl(), "http" ) )
{
@@ -345,30 +385,6 @@ public class DefaultRemoteRepositoryAdmin
}
- private RemoteRepositoryConfiguration getRemoteRepositoryConfiguration( RemoteRepository remoteRepository )
- {
- RemoteRepositoryConfiguration remoteRepositoryConfiguration = new RemoteRepositoryConfiguration();
- remoteRepositoryConfiguration.setId( remoteRepository.getId() );
- remoteRepositoryConfiguration.setPassword( remoteRepository.getPassword() );
- remoteRepositoryConfiguration.setTimeout( remoteRepository.getTimeout() );
- remoteRepositoryConfiguration.setUrl( remoteRepository.getUrl() );
- remoteRepositoryConfiguration.setUsername( remoteRepository.getUserName() );
- remoteRepositoryConfiguration.setLayout( remoteRepository.getLayout() );
- remoteRepositoryConfiguration.setName( remoteRepository.getName() );
- remoteRepositoryConfiguration.setDownloadRemoteIndex( remoteRepository.isDownloadRemoteIndex() );
- remoteRepositoryConfiguration.setRemoteIndexUrl( remoteRepository.getRemoteIndexUrl() );
- remoteRepositoryConfiguration.setRefreshCronExpression( remoteRepository.getCronExpression() );
- remoteRepositoryConfiguration.setIndexDir( remoteRepository.getIndexDirectory() );
- remoteRepositoryConfiguration.setRemoteDownloadNetworkProxyId(
- remoteRepository.getRemoteDownloadNetworkProxyId() );
- remoteRepositoryConfiguration.setRemoteDownloadTimeout( remoteRepository.getRemoteDownloadTimeout() );
- remoteRepositoryConfiguration.setDownloadRemoteIndexOnStartup(
- remoteRepository.isDownloadRemoteIndexOnStartup() );
- remoteRepositoryConfiguration.setDescription( remoteRepository.getDescription() );
- remoteRepositoryConfiguration.setExtraHeaders( remoteRepository.getExtraHeaders() );
- remoteRepositoryConfiguration.setExtraParameters( remoteRepository.getExtraParameters() );
- remoteRepositoryConfiguration.setCheckPath(remoteRepository.getCheckPath());
- return remoteRepositoryConfiguration;
- }
+
}
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java
index d3389cf4a..d158b401d 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java
@@ -43,6 +43,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
/**
@@ -106,8 +107,9 @@ public abstract class AbstractRepositoryAdminTest
protected ManagedRepository getTestManagedRepository( String repoId, String repoLocation )
{
- return new ManagedRepository( repoId, "test repo", repoLocation, "default", false, true, true, "0 0 * * * ?",
- repoLocation + "/.index", false, 1, 2, true, false );
+ String repoLocationStr = Paths.get(repoLocation, ".index").toString();
+ return new ManagedRepository( Locale.getDefault( ), repoId, "test repo", repoLocation, "default", false, true, true, "0 0 * * * ?",
+ repoLocationStr, false, 1, 2, true, false );
}
protected Path clearRepoLocation(String path )
@@ -141,7 +143,7 @@ public abstract class AbstractRepositoryAdminTest
protected RemoteRepository getRemoteRepository( String id )
{
- RemoteRepository remoteRepository = new RemoteRepository();
+ RemoteRepository remoteRepository = new RemoteRepository(Locale.getDefault());
remoteRepository.setUrl( "http://foo.com/maven-it-rocks" );
remoteRepository.setTimeout( 10 );
remoteRepository.setName( "maven foo" );
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java
index b131abc88..87c6f97c3 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java
@@ -20,14 +20,25 @@ package org.apache.archiva.admin.repository.managed;
import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest;
+import org.apache.archiva.common.utils.FileUtils;
+import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.metadata.model.facets.AuditEvent;
+import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.security.common.ArchivaRoleConstants;
+import org.junit.Before;
import org.junit.Test;
+import javax.inject.Inject;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
import java.util.List;
+import java.util.Locale;
/**
* @author Olivier Lamy
@@ -35,6 +46,12 @@ import java.util.List;
public class ManagedRepositoryAdminTest
extends AbstractRepositoryAdminTest
{
+ @Inject
+ private ArchivaConfiguration archivaConfiguration;
+
+ @Inject
+ private RepositoryRegistry repositoryRegistry;
+
public static final String STAGE_REPO_ID_END = DefaultManagedRepositoryAdmin.STAGE_REPO_ID_END;
@@ -42,6 +59,21 @@ public class ManagedRepositoryAdminTest
String repoLocation = Paths.get(APPSERVER_BASE_PATH, repoId).toString();
+ @Before
+ public void setup() throws IOException, URISyntaxException
+ {
+ Path archivaCfg1 = Paths.get( System.getProperty( "user.home" ), ".m2", "archiva.xml" );
+ Files.deleteIfExists( archivaCfg1 );
+ Path archivaCfg2 = Paths.get(APPSERVER_BASE_PATH, "conf/archiva.xml");
+ Files.deleteIfExists( archivaCfg2 );
+ Files.createDirectories( archivaCfg2.getParent() );
+ URL url = Thread.currentThread().getContextClassLoader().getResource( "default-archiva.xml" );
+ Path defaultCfg = Paths.get(url.toURI());
+ Files.copy( defaultCfg, archivaCfg2, StandardCopyOption.REPLACE_EXISTING );
+ archivaConfiguration.reload();
+ repositoryRegistry.reload();
+ }
+
@Test
public void getAllManagedRepos()
throws Exception
@@ -83,7 +115,7 @@ public class ManagedRepositoryAdminTest
int initialSize = repos.size();
assertTrue( initialSize > 0 );
- ManagedRepository repo = new ManagedRepository();
+ ManagedRepository repo = new ManagedRepository( Locale.getDefault());
repo.setId( repoId );
repo.setName( "test repo" );
repo.setLocation( repoLocation );
@@ -135,7 +167,7 @@ public class ManagedRepositoryAdminTest
int initialSize = repos.size();
assertTrue( initialSize > 0 );
- ManagedRepository repo = new ManagedRepository();
+ ManagedRepository repo = new ManagedRepository(Locale.getDefault());
repo.setId( repoId );
repo.setName( "test repo" );
repo.setLocation( repoLocation );
@@ -200,7 +232,7 @@ public class ManagedRepositoryAdminTest
int initialSize = repos.size();
assertTrue( initialSize > 0 );
- ManagedRepository repo = new ManagedRepository();
+ ManagedRepository repo = new ManagedRepository(Locale.getDefault());
repo.setId( repoId );
repo.setName( "test repo" );
repo.setLocation( repoLocation );
@@ -250,6 +282,7 @@ public class ManagedRepositoryAdminTest
String stageRepoLocation = Paths.get(APPSERVER_BASE_PATH, repoId).toString();
Path repoDir = clearRepoLocation( repoLocation );
+ clearRepoLocation( repoLocation+STAGE_REPO_ID_END );
mockAuditListener.clearEvents();
List<ManagedRepository> repos = managedRepositoryAdmin.getManagedRepositories();
@@ -284,16 +317,17 @@ public class ManagedRepositoryAdminTest
managedRepositoryAdmin.updateManagedRepository( repo, true, getFakeAuditInformation(), false );
repo = managedRepositoryAdmin.getManagedRepository( repoId );
+ System.err.println("REPOSITORY "+repo.getLocation());
assertNotNull( repo );
assertEquals( newName, repo.getName() );
- assertEquals( Paths.get( repoLocation ).normalize(), Paths.get( repo.getLocation() ).normalize() );
+ assertEquals( Paths.get( repoLocation ).toAbsolutePath(), Paths.get( repo.getLocation() ).toAbsolutePath() );
assertTrue( Files.exists( Paths.get(repoLocation )) );
assertEquals( getTestManagedRepository( repoId, repoLocation ).getCronExpression(), repo.getCronExpression() );
assertEquals( getTestManagedRepository( repoId, repoLocation ).getLayout(), repo.getLayout() );
assertEquals( getTestManagedRepository( repoId, repoLocation ).getId(), repo.getId() );
assertEquals( getTestManagedRepository( repoId, repoLocation ).getIndexDirectory(), repo.getIndexDirectory() );
- assertEquals( getTestManagedRepository( repoId, repoLocation ).getDaysOlder(), repo.getDaysOlder() );
+ assertEquals( getTestManagedRepository( repoId, repoLocation ).getRetentionPeriod(), repo.getRetentionPeriod() );
assertEquals( getTestManagedRepository( repoId, repoLocation ).getRetentionCount(), repo.getRetentionCount() );
assertEquals( getTestManagedRepository( repoId, repoLocation ).isDeleteReleasedSnapshots(),
repo.isDeleteReleasedSnapshots() );
@@ -319,7 +353,7 @@ public class ManagedRepositoryAdminTest
mockAuditListener.clearEvents();
- Files.deleteIfExists(Paths.get( repoLocation + STAGE_REPO_ID_END ));
+ FileUtils.deleteQuietly( Paths.get( repoLocation + STAGE_REPO_ID_END ));
assertFalse( Files.exists(Paths.get( repoLocation + STAGE_REPO_ID_END )) );
}
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/proxyconnectorrule/ProxyConnectorRuleAdminTest.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/proxyconnectorrule/ProxyConnectorRuleAdminTest.java
index 9a9960059..a9d4b9710 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/proxyconnectorrule/ProxyConnectorRuleAdminTest.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/proxyconnectorrule/ProxyConnectorRuleAdminTest.java
@@ -26,6 +26,7 @@ import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest;
import org.junit.Test;
import java.util.Arrays;
+import java.util.Locale;
/**
* @author Olivier Lamy
@@ -74,7 +75,7 @@ public class ProxyConnectorRuleAdminTest
public void addProxyConnectorRuleWithTwoProxyConnectors()
throws Exception
{
- RemoteRepository remoteRepository = new RemoteRepository();
+ RemoteRepository remoteRepository = new RemoteRepository(Locale.getDefault());
remoteRepository.setId( "archiva" );
remoteRepository.setName( "archiva rocks" );
remoteRepository.setUrl( "http://wine.org" );
@@ -120,7 +121,7 @@ public class ProxyConnectorRuleAdminTest
public void updateProxyConnectorRuleWithTwoProxyConnectors()
throws Exception
{
- RemoteRepository remoteRepository = new RemoteRepository();
+ RemoteRepository remoteRepository = new RemoteRepository( Locale.getDefault( ));
remoteRepository.setId( "archiva" );
remoteRepository.setName( "archiva rocks" );
remoteRepository.setUrl( "http://wine.org" );
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/resources/default-archiva.xml b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/resources/default-archiva.xml
new file mode 100644
index 000000000..795579843
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/resources/default-archiva.xml
@@ -0,0 +1,185 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<configuration>
+ <version>3.0.0</version>
+ <managedRepositories>
+ <managedRepository>
+ <id>internal</id>
+ <name>Archiva Managed Internal Repository</name>
+ <location>${appserver.base}/repositories/internal</location>
+ <indexDir>${appserver.base}/repositories/internal/.indexer</indexDir>
+ <layout>default</layout>
+ <releases>true</releases>
+ <snapshots>false</snapshots>
+ <blockRedeployments>true</blockRedeployments>
+ <scanned>true</scanned>
+ <refreshCronExpression>0 0 * * * ?</refreshCronExpression>
+ <retentionPeriod>30</retentionPeriod>
+ </managedRepository>
+ <managedRepository>
+ <id>snapshots</id>
+ <name>Archiva Managed Snapshot Repository</name>
+ <location>${appserver.base}/repositories/snapshots</location>
+ <indexDir>${appserver.base}/repositories/snapshots/.indexer</indexDir>
+ <layout>default</layout>
+ <releases>false</releases>
+ <snapshots>true</snapshots>
+ <blockRedeployments>false</blockRedeployments>
+ <scanned>true</scanned>
+ <refreshCronExpression>0 0\,30 * * * ?</refreshCronExpression>
+ <retentionPeriod>30</retentionPeriod>
+ </managedRepository>
+ </managedRepositories>
+ <remoteRepositories>
+ <remoteRepository>
+ <id>central</id>
+ <name>Central Repository</name>
+ <url>https://repo.maven.apache.org/maven2</url>
+ <layout>default</layout>
+ </remoteRepository>
+ </remoteRepositories>
+
+ <proxyConnectors>
+ <proxyConnector>
+ <sourceRepoId>internal</sourceRepoId>
+ <targetRepoId>central</targetRepoId>
+ <proxyId/>
+ <policies>
+ <snapshots>disabled</snapshots>
+ <releases>once</releases>
+ <checksum>fix</checksum>
+ <cache-failures>cached</cache-failures>
+ </policies>
+ <whiteListPatterns>
+ <whiteListPattern>**/*</whiteListPattern>
+ </whiteListPatterns>
+ </proxyConnector>
+ </proxyConnectors>
+
+ <legacyArtifactPaths>
+ <legacyArtifactPath>
+ <path>jaxen/jars/jaxen-1.0-FCS-full.jar</path>
+ <artifact>jaxen:jaxen:1.0-FCS:full:jar</artifact>
+ </legacyArtifactPath>
+ </legacyArtifactPaths>
+
+ <repositoryScanning>
+ <fileTypes>
+ <fileType>
+ <id>artifacts</id>
+ <patterns>
+ <pattern>**/*.pom</pattern>
+ <pattern>**/*.jar</pattern>
+ <pattern>**/*.ear</pattern>
+ <pattern>**/*.war</pattern>
+ <pattern>**/*.car</pattern>
+ <pattern>**/*.sar</pattern>
+ <pattern>**/*.mar</pattern>
+ <pattern>**/*.rar</pattern>
+ <pattern>**/*.dtd</pattern>
+ <pattern>**/*.tld</pattern>
+ <pattern>**/*.tar.gz</pattern>
+ <pattern>**/*.tar.bz2</pattern>
+ <pattern>**/*.zip</pattern>
+ </patterns>
+ </fileType>
+ <fileType>
+ <id>indexable-content</id>
+ <patterns>
+ <pattern>**/*.txt</pattern>
+ <pattern>**/*.TXT</pattern>
+ <pattern>**/*.block</pattern>
+ <pattern>**/*.config</pattern>
+ <pattern>**/*.pom</pattern>
+ <pattern>**/*.xml</pattern>
+ <pattern>**/*.xsd</pattern>
+ <pattern>**/*.dtd</pattern>
+ <pattern>**/*.tld</pattern>
+ </patterns>
+ </fileType>
+ <fileType>
+ <id>auto-remove</id>
+ <patterns>
+ <pattern>**/*.bak</pattern>
+ <pattern>**/*~</pattern>
+ <pattern>**/*-</pattern>
+ </patterns>
+ </fileType>
+ <fileType>
+ <id>ignored</id>
+ <patterns>
+ <pattern>**/.htaccess</pattern>
+ <pattern>**/KEYS</pattern>
+ <pattern>**/*.rb</pattern>
+ <pattern>**/*.sh</pattern>
+ <pattern>**/.svn/**</pattern>
+ <pattern>**/.DAV/**</pattern>
+ <pattern>.index/**</pattern>
+ <pattern>.indexer/**</pattern>
+ </patterns>
+ </fileType>
+ </fileTypes>
+ <knownContentConsumers>
+ <knownContentConsumer>create-missing-checksums</knownContentConsumer>
+ <knownContentConsumer>validate-checksum</knownContentConsumer>
+ <knownContentConsumer>validate-signature</knownContentConsumer>
+ <knownContentConsumer>index-content</knownContentConsumer>
+ <knownContentConsumer>auto-remove</knownContentConsumer>
+ <knownContentConsumer>auto-rename</knownContentConsumer>
+ <knownContentConsumer>metadata-updater</knownContentConsumer>
+ <knownContentConsumer>create-archiva-metadata</knownContentConsumer>
+ <knownContentConsumer>duplicate-artifacts</knownContentConsumer>
+ <!--knownContentConsumer>repository-purge</knownContentConsumer-->
+ </knownContentConsumers>
+ <invalidContentConsumers>
+ <invalidContentConsumer>update-db-bad-content</invalidContentConsumer>
+ </invalidContentConsumers>
+ </repositoryScanning>
+
+ <webapp>
+ <ui>
+ <showFindArtifacts>true</showFindArtifacts>
+ <appletFindEnabled>true</appletFindEnabled>
+ </ui>
+ </webapp>
+
+ <redbackRuntimeConfiguration>
+ <userManagerImpls>
+ <userManagerImpl>jpa</userManagerImpl>
+ </userManagerImpls>
+ <rbacManagerImpls>
+ <rbacManagerImpl>cached</rbacManagerImpl>
+ </rbacManagerImpls>
+ </redbackRuntimeConfiguration>
+
+ <archivaDefaultConfiguration>
+ <defaultCheckPaths>
+ <defaultCheckPath>
+ <url>http://download.oracle.com/maven</url>
+ <path>com/sleepycat/je/license.txt</path>
+ </defaultCheckPath>
+ <defaultCheckPath>
+ <url>https://download.oracle.com/maven</url>
+ <path>com/sleepycat/je/license.txt</path>
+ </defaultCheckPath>
+ </defaultCheckPaths>
+ </archivaDefaultConfiguration>
+
+</configuration>
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/resources/spring-context.xml b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/resources/spring-context.xml
index 84adf6d01..a2670af4b 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/resources/spring-context.xml
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/resources/spring-context.xml
@@ -31,7 +31,10 @@
default-lazy-init="true">
<context:annotation-config/>
- <context:component-scan base-package="org.apache.archiva.admin.mock"/>
+ <context:component-scan base-package="org.apache.archiva.admin.mock,org.apache.archiva.repository.content.maven2"/>
+
+ <alias name="managedRepositoryContent#maven" alias="managedRepositoryContent#default" />
+ <alias name="remoteRepositoryContent#maven" alias="remoteRepositoryContent#default" />
<bean name="scheduler" class="org.apache.archiva.redback.components.scheduler.DefaultScheduler">
<property name="properties">