mirror of https://github.com/apache/archiva.git
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.
This commit is contained in:
parent
d6e4a5b485
commit
fd51964c13
|
@ -29,6 +29,10 @@
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
<name>Archiva Base :: Repository Admin Api</name>
|
<name>Archiva Base :: Repository Admin Api</name>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.archiva</groupId>
|
||||||
|
<artifactId>archiva-repository-layer</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-collections</groupId>
|
<groupId>commons-collections</groupId>
|
||||||
<artifactId>commons-collections</artifactId>
|
<artifactId>commons-collections</artifactId>
|
||||||
|
|
|
@ -19,6 +19,12 @@ package org.apache.archiva.admin.model.beans;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.Serializable;
|
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
|
* @author Olivier Lamy
|
||||||
|
@ -28,29 +34,51 @@ public class AbstractRepository
|
||||||
implements Serializable
|
implements Serializable
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private Locale defaultLocale = Locale.getDefault();
|
||||||
|
|
||||||
|
private String type;
|
||||||
|
|
||||||
private String id;
|
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 layout = "default";
|
||||||
|
|
||||||
private String indexDirectory;
|
private String indexDirectory;
|
||||||
|
|
||||||
/**
|
private String toStringCache = null;
|
||||||
* @since 1.4-M3
|
|
||||||
*/
|
|
||||||
private String description;
|
|
||||||
|
|
||||||
public AbstractRepository()
|
public AbstractRepository()
|
||||||
{
|
{
|
||||||
// no op
|
// 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 )
|
public AbstractRepository( String id, String name, String layout )
|
||||||
{
|
{
|
||||||
this.id = id;
|
setId(id);
|
||||||
this.name = name;
|
setName(name);
|
||||||
this.layout = layout;
|
setLayout(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId()
|
public String getId()
|
||||||
|
@ -60,17 +88,32 @@ public class AbstractRepository
|
||||||
|
|
||||||
public void setId( String id )
|
public void setId( String id )
|
||||||
{
|
{
|
||||||
|
this.toStringCache=null;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName()
|
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 )
|
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()
|
public String getLayout()
|
||||||
|
@ -80,6 +123,7 @@ public class AbstractRepository
|
||||||
|
|
||||||
public void setLayout( String layout )
|
public void setLayout( String layout )
|
||||||
{
|
{
|
||||||
|
this.toStringCache=null;
|
||||||
this.layout = layout;
|
this.layout = layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,12 +141,28 @@ public class AbstractRepository
|
||||||
|
|
||||||
public String getDescription()
|
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 )
|
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
|
@Override
|
||||||
|
@ -132,17 +192,39 @@ public class AbstractRepository
|
||||||
return result;
|
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
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
final StringBuilder sb = new StringBuilder();
|
if (toStringCache!=null) {
|
||||||
sb.append( "AbstractRepository" );
|
return toStringCache;
|
||||||
sb.append( "{id='" ).append( id ).append( '\'' );
|
} else
|
||||||
sb.append( ", name='" ).append( name ).append( '\'' );
|
{
|
||||||
sb.append( ", layout='" ).append( layout ).append( '\'' );
|
final StringBuilder sb = new StringBuilder( );
|
||||||
sb.append( ", indexDirectory='" ).append( indexDirectory ).append( '\'' );
|
sb.append( "AbstractRepository" );
|
||||||
sb.append( ", description='" ).append( description ).append( '\'' );
|
sb.append( "{id='" ).append( id ).append( '\'' );
|
||||||
sb.append( '}' );
|
sb.append(", type='").append(type).append('\'');
|
||||||
return sb.toString();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.apache.archiva.admin.model.beans;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Olivier Lamy
|
* @author Olivier Lamy
|
||||||
|
@ -57,7 +58,7 @@ public class ManagedRepository
|
||||||
/**
|
/**
|
||||||
* default model value
|
* default model value
|
||||||
*/
|
*/
|
||||||
private int retentionTime = 100;
|
private int retentionPeriod = 100;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default model value
|
* default model value
|
||||||
|
@ -75,17 +76,22 @@ public class ManagedRepository
|
||||||
*/
|
*/
|
||||||
private boolean skipPackedIndexCreation;
|
private boolean skipPackedIndexCreation;
|
||||||
|
|
||||||
public ManagedRepository()
|
public ManagedRepository() {
|
||||||
{
|
super(Locale.getDefault());
|
||||||
// no op
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ManagedRepository( String id, String name, String location, String layout, boolean snapshots,
|
public ManagedRepository(Locale defaultLocale)
|
||||||
|
{
|
||||||
|
super(defaultLocale);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ManagedRepository( Locale defaultLocale, String id, String name, String location, String layout, boolean snapshots,
|
||||||
boolean releases, boolean blockRedeployments, String cronExpression, String indexDir,
|
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 )
|
boolean stageRepoNeeded )
|
||||||
{
|
{
|
||||||
super( id, name, layout );
|
super( defaultLocale, id, name, layout );
|
||||||
|
|
||||||
this.location = location;
|
this.location = location;
|
||||||
this.snapshots = snapshots;
|
this.snapshots = snapshots;
|
||||||
|
@ -94,7 +100,7 @@ public class ManagedRepository
|
||||||
this.setCronExpression( cronExpression );
|
this.setCronExpression( cronExpression );
|
||||||
this.setIndexDirectory( indexDir );
|
this.setIndexDirectory( indexDir );
|
||||||
this.scanned = scanned;
|
this.scanned = scanned;
|
||||||
this.retentionTime = retentionTime;
|
this.retentionPeriod = retentionPeriod;
|
||||||
this.retentionCount = retentionCount;
|
this.retentionCount = retentionCount;
|
||||||
this.deleteReleasedSnapshots = deleteReleasedSnapshots;
|
this.deleteReleasedSnapshots = deleteReleasedSnapshots;
|
||||||
this.stageRepoNeeded = stageRepoNeeded;
|
this.stageRepoNeeded = stageRepoNeeded;
|
||||||
|
@ -103,13 +109,13 @@ public class ManagedRepository
|
||||||
/**
|
/**
|
||||||
* @since 1.4-M3
|
* @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 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 )
|
boolean stageRepoNeeded, String description, boolean skipPackedIndexCreation )
|
||||||
{
|
{
|
||||||
this( id, name, location, layout, snapshots, releases, blockRedeployments, cronExpression, indexDir, scanned,
|
this( defaultLocale, id, name, location, layout, snapshots, releases, blockRedeployments, cronExpression, indexDir, scanned,
|
||||||
retentionTime, retentionCount, deleteReleasedSnapshots, stageRepoNeeded );
|
retentionPeriod, retentionCount, deleteReleasedSnapshots, stageRepoNeeded );
|
||||||
setDescription( description );
|
setDescription( description );
|
||||||
setSkipPackedIndexCreation( skipPackedIndexCreation );
|
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()
|
public int getRetentionCount()
|
||||||
|
@ -265,7 +271,7 @@ public class ManagedRepository
|
||||||
sb.append( ", cronExpression='" ).append( cronExpression ).append( '\'' );
|
sb.append( ", cronExpression='" ).append( cronExpression ).append( '\'' );
|
||||||
sb.append( ", stagingRepository=" ).append( stagingRepository );
|
sb.append( ", stagingRepository=" ).append( stagingRepository );
|
||||||
sb.append( ", scanned=" ).append( scanned );
|
sb.append( ", scanned=" ).append( scanned );
|
||||||
sb.append( ", retentionTime=" ).append( retentionTime );
|
sb.append( ", retentionPeriod=" ).append( retentionPeriod );
|
||||||
sb.append( ", retentionCount=" ).append( retentionCount );
|
sb.append( ", retentionCount=" ).append( retentionCount );
|
||||||
sb.append( ", deleteReleasedSnapshots=" ).append( deleteReleasedSnapshots );
|
sb.append( ", deleteReleasedSnapshots=" ).append( deleteReleasedSnapshots );
|
||||||
sb.append( ", stageRepoNeeded=" ).append( stageRepoNeeded );
|
sb.append( ", stageRepoNeeded=" ).append( stageRepoNeeded );
|
||||||
|
|
|
@ -26,6 +26,7 @@ import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -104,22 +105,25 @@ public class RemoteRepository
|
||||||
*/
|
*/
|
||||||
private List<PropertyEntry> extraHeadersEntries;
|
private List<PropertyEntry> extraHeadersEntries;
|
||||||
|
|
||||||
|
public RemoteRepository() {
|
||||||
public RemoteRepository()
|
super(Locale.getDefault());
|
||||||
{
|
|
||||||
// no op
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public RemoteRepository( String id, String name, String url, String layout )
|
public RemoteRepository(Locale locale)
|
||||||
{
|
{
|
||||||
super( id, name, layout );
|
super(locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RemoteRepository( Locale locale, String id, String name, String url, String layout )
|
||||||
|
{
|
||||||
|
super( locale, id, name, layout );
|
||||||
this.url = url;
|
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 )
|
int timeout )
|
||||||
{
|
{
|
||||||
super( id, name, layout );
|
super( locale, id, name, layout );
|
||||||
this.url = StringUtils.stripEnd(url,"/");
|
this.url = StringUtils.stripEnd(url,"/");
|
||||||
this.userName = userName;
|
this.userName = userName;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
|
@ -129,10 +133,10 @@ public class RemoteRepository
|
||||||
/**
|
/**
|
||||||
* @since 1.4-M3
|
* @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 )
|
int timeout, String description )
|
||||||
{
|
{
|
||||||
this( id, name, url, layout, userName, password, timeout );
|
this( locale, id, name, url, layout, userName, password, timeout );
|
||||||
setDescription( description );
|
setDescription( description );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,4 +68,5 @@ public interface ManagedRepositoryAdmin
|
||||||
throws RepositoryAdminException;
|
throws RepositoryAdminException;
|
||||||
|
|
||||||
|
|
||||||
|
IndexingContext createIndexContext( org.apache.archiva.repository.ManagedRepository repository) throws RepositoryAdminException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,10 @@
|
||||||
<groupId>org.apache.archiva</groupId>
|
<groupId>org.apache.archiva</groupId>
|
||||||
<artifactId>metadata-model</artifactId>
|
<artifactId>metadata-model</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.archiva</groupId>
|
||||||
|
<artifactId>maven2-repository</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.inject</groupId>
|
<groupId>javax.inject</groupId>
|
||||||
<artifactId>javax.inject</artifactId>
|
<artifactId>javax.inject</artifactId>
|
||||||
|
|
|
@ -21,13 +21,18 @@ package org.apache.archiva.admin.repository;
|
||||||
import org.apache.archiva.admin.model.AuditInformation;
|
import org.apache.archiva.admin.model.AuditInformation;
|
||||||
import org.apache.archiva.admin.model.RepositoryAdminException;
|
import org.apache.archiva.admin.model.RepositoryAdminException;
|
||||||
import org.apache.archiva.admin.model.RepositoryCommonValidator;
|
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.ArchivaConfiguration;
|
||||||
import org.apache.archiva.configuration.Configuration;
|
import org.apache.archiva.configuration.Configuration;
|
||||||
import org.apache.archiva.configuration.IndeterminateConfigurationException;
|
import org.apache.archiva.configuration.IndeterminateConfigurationException;
|
||||||
import org.apache.archiva.metadata.model.facets.AuditEvent;
|
import org.apache.archiva.metadata.model.facets.AuditEvent;
|
||||||
import org.apache.archiva.redback.users.User;
|
import org.apache.archiva.redback.users.User;
|
||||||
import org.apache.archiva.redback.components.registry.Registry;
|
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.events.AuditListener;
|
||||||
|
import org.apache.archiva.repository.features.IndexCreationFeature;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.modelmapper.ModelMapper;
|
import org.modelmapper.ModelMapper;
|
||||||
import org.modelmapper.convention.MatchingStrategies;
|
import org.modelmapper.convention.MatchingStrategies;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -36,6 +41,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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 class ModelMapperHolder
|
||||||
{
|
{
|
||||||
private static ModelMapper MODEL_MAPPER = new ModelMapper();
|
private static ModelMapper MODEL_MAPPER = new ModelMapper();
|
||||||
|
|
|
@ -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.model.managed.ManagedRepositoryAdmin;
|
||||||
import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
|
import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
|
||||||
import org.apache.archiva.configuration.Configuration;
|
import org.apache.archiva.configuration.Configuration;
|
||||||
|
import org.apache.archiva.configuration.IndeterminateConfigurationException;
|
||||||
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
|
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
|
||||||
import org.apache.archiva.configuration.ProxyConnectorConfiguration;
|
import org.apache.archiva.configuration.ProxyConnectorConfiguration;
|
||||||
import org.apache.archiva.configuration.RepositoryGroupConfiguration;
|
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.RepositorySessionFactory;
|
||||||
import org.apache.archiva.metadata.repository.stats.model.RepositoryStatisticsManager;
|
import org.apache.archiva.metadata.repository.stats.model.RepositoryStatisticsManager;
|
||||||
import org.apache.archiva.redback.components.cache.Cache;
|
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.components.taskqueue.TaskQueueException;
|
||||||
import org.apache.archiva.redback.role.RoleManager;
|
import org.apache.archiva.redback.role.RoleManager;
|
||||||
import org.apache.archiva.redback.role.RoleManagerException;
|
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.RepositoryArchivaTaskScheduler;
|
||||||
import org.apache.archiva.scheduler.repository.model.RepositoryTask;
|
import org.apache.archiva.scheduler.repository.model.RepositoryTask;
|
||||||
import org.apache.archiva.security.common.ArchivaRoleConstants;
|
import org.apache.archiva.security.common.ArchivaRoleConstants;
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.maven.index.NexusIndexer;
|
import org.apache.maven.index.NexusIndexer;
|
||||||
import org.apache.maven.index.context.IndexCreator;
|
import org.apache.maven.index.context.IndexCreator;
|
||||||
|
@ -56,10 +63,15 @@ import javax.annotation.PreDestroy;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
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
|
* 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";
|
public static final String STAGE_REPO_ID_END = "-stage";
|
||||||
|
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private RepositoryRegistry repositoryRegistry;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named(value = "archivaTaskScheduler#repository")
|
@Named(value = "archivaTaskScheduler#repository")
|
||||||
private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
|
private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
|
||||||
|
@ -110,6 +126,7 @@ public class DefaultManagedRepositoryAdmin
|
||||||
// initialize index context on start and check roles here
|
// initialize index context on start and check roles here
|
||||||
for ( ManagedRepository managedRepository : getManagedRepositories() )
|
for ( ManagedRepository managedRepository : getManagedRepositories() )
|
||||||
{
|
{
|
||||||
|
log.debug("Initializating {}", managedRepository.getId());
|
||||||
createIndexContext( managedRepository );
|
createIndexContext( managedRepository );
|
||||||
addRepositoryRoles( managedRepository.getId() );
|
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
|
@Override
|
||||||
public List<ManagedRepository> getManagedRepositories()
|
public List<ManagedRepository> getManagedRepositories()
|
||||||
throws RepositoryAdminException
|
throws RepositoryAdminException
|
||||||
{
|
{
|
||||||
List<ManagedRepositoryConfiguration> managedRepoConfigs =
|
|
||||||
getArchivaConfiguration().getConfiguration().getManagedRepositories();
|
|
||||||
|
|
||||||
if ( managedRepoConfigs == null )
|
return repositoryRegistry.getManagedRepositories().stream().map( rep -> this.convertRepo( rep ) ).collect( Collectors.toList());
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, ManagedRepository> getManagedRepositoriesAsMap()
|
public Map<String, ManagedRepository> getManagedRepositoriesAsMap()
|
||||||
throws RepositoryAdminException
|
throws RepositoryAdminException
|
||||||
{
|
{
|
||||||
List<ManagedRepository> managedRepositories = getManagedRepositories();
|
return repositoryRegistry.getManagedRepositories().stream().collect( Collectors.toMap( e -> e.getId(), e -> convertRepo( e ) ) );
|
||||||
Map<String, ManagedRepository> repositoriesMap = new HashMap<>( managedRepositories.size() );
|
|
||||||
for ( ManagedRepository managedRepository : managedRepositories )
|
|
||||||
{
|
|
||||||
repositoriesMap.put( managedRepository.getId(), managedRepository );
|
|
||||||
}
|
|
||||||
return repositoriesMap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ManagedRepository getManagedRepository( String repositoryId )
|
public ManagedRepository getManagedRepository( String repositoryId )
|
||||||
throws RepositoryAdminException
|
throws RepositoryAdminException
|
||||||
{
|
{
|
||||||
List<ManagedRepository> repos = getManagedRepositories();
|
return convertRepo( repositoryRegistry.getManagedRepository( repositoryId ) );
|
||||||
for ( ManagedRepository repo : repos )
|
|
||||||
{
|
|
||||||
if ( StringUtils.equals( repo.getId(), repositoryId ) )
|
|
||||||
{
|
|
||||||
return repo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -202,131 +236,120 @@ public class DefaultManagedRepositoryAdmin
|
||||||
AuditInformation auditInformation )
|
AuditInformation auditInformation )
|
||||||
throws RepositoryAdminException
|
throws RepositoryAdminException
|
||||||
{
|
{
|
||||||
|
log.debug("addManagedRepository {}, {}, {}", managedRepository.getId(), needStageRepo, auditInformation);
|
||||||
|
|
||||||
getRepositoryCommonValidator().basicValidation( managedRepository, false );
|
getRepositoryCommonValidator().basicValidation( managedRepository, false );
|
||||||
getRepositoryCommonValidator().validateManagedRepository( managedRepository );
|
getRepositoryCommonValidator().validateManagedRepository( managedRepository );
|
||||||
triggerAuditEvent( managedRepository.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation );
|
triggerAuditEvent( managedRepository.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation );
|
||||||
Boolean res =
|
ManagedRepositoryConfiguration repoConfig = getRepositoryConfiguration( managedRepository );
|
||||||
addManagedRepository( managedRepository.getId(), managedRepository.getLayout(), managedRepository.getName(),
|
if (needStageRepo) {
|
||||||
managedRepository.getLocation(), managedRepository.isBlockRedeployments(),
|
repoConfig.setStageRepoNeeded( true );
|
||||||
managedRepository.isReleases(), managedRepository.isSnapshots(), needStageRepo,
|
}
|
||||||
managedRepository.getCronExpression(), managedRepository.getIndexDirectory(),
|
Configuration configuration = getArchivaConfiguration().getConfiguration();
|
||||||
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 );
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
addRepository( repository, config );
|
org.apache.archiva.repository.ManagedRepository newRepo = repositoryRegistry.putRepository( repoConfig, configuration );
|
||||||
addRepositoryRoles( repository.getId() );
|
log.debug("Added new repository {}", newRepo.getId());
|
||||||
|
org.apache.archiva.repository.ManagedRepository stagingRepo = null;
|
||||||
if ( stageRepoNeeded )
|
addRepositoryRoles( newRepo.getId() );
|
||||||
{
|
if ( newRepo.supportsFeature( StagingRepositoryFeature.class )) {
|
||||||
ManagedRepositoryConfiguration stagingRepository = getStageRepoConfig( repository );
|
StagingRepositoryFeature stf = newRepo.getFeature( StagingRepositoryFeature.class ).get();
|
||||||
addRepository( stagingRepository, config );
|
stagingRepo = stf.getStagingRepository();
|
||||||
addRepositoryRoles( stagingRepository.getId() );
|
if (stf.isStageRepoNeeded() && stagingRepo != null) {
|
||||||
triggerAuditEvent( stagingRepository.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation );
|
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 ( stagingRepo!=null && stagingRepo.isScanned() )
|
||||||
|
{
|
||||||
|
scanRepository( stagingRepo.getId(), true );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch ( Exception e )
|
||||||
|
{
|
||||||
|
log.warn("Unable to scan repository [{}]: {}", newRepo.getId(), e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch ( RepositoryException e )
|
||||||
|
{
|
||||||
|
log.error("Could not add managed repository {}"+managedRepository);
|
||||||
|
throw new RepositoryAdminException( "Could not add repository "+e.getMessage() );
|
||||||
}
|
}
|
||||||
catch ( RoleManagerException e )
|
catch ( RoleManagerException e )
|
||||||
{
|
{
|
||||||
throw new RepositoryAdminException( "failed to add repository roles " + 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() );
|
||||||
catch ( IOException e )
|
|
||||||
{
|
|
||||||
throw new RepositoryAdminException( "failed to add repository " + e.getMessage(), e );
|
|
||||||
}
|
}
|
||||||
|
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
|
@Override
|
||||||
public Boolean deleteManagedRepository( String repositoryId, AuditInformation auditInformation,
|
public Boolean deleteManagedRepository( String repositoryId, AuditInformation auditInformation,
|
||||||
boolean deleteContent )
|
boolean deleteContent )
|
||||||
throws RepositoryAdminException
|
throws RepositoryAdminException
|
||||||
{
|
{
|
||||||
Configuration config = getArchivaConfiguration().getConfiguration();
|
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" );
|
throw new RepositoryAdminException( "A repository with that id does not exist" );
|
||||||
}
|
}
|
||||||
|
|
||||||
triggerAuditEvent( repositoryId, null, AuditEvent.DELETE_MANAGED_REPO, auditInformation );
|
triggerAuditEvent( repositoryId, null, AuditEvent.DELETE_MANAGED_REPO, auditInformation );
|
||||||
|
if (repoConfig!=null)
|
||||||
|
{
|
||||||
|
deleteManagedRepository( repoConfig, deleteContent, config, false );
|
||||||
|
}
|
||||||
|
|
||||||
deleteManagedRepository( repository, deleteContent, config, false );
|
|
||||||
|
|
||||||
// stage repo exists ?
|
// stage repo exists ?
|
||||||
ManagedRepositoryConfiguration stagingRepository =
|
|
||||||
getArchivaConfiguration().getConfiguration().findManagedRepositoryById( repositoryId + STAGE_REPO_ID_END );
|
|
||||||
if ( stagingRepository != null )
|
if ( stagingRepository != null )
|
||||||
{
|
{
|
||||||
// do not trigger event when deleting the staged one
|
// 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
|
try
|
||||||
|
@ -383,7 +406,6 @@ public class DefaultManagedRepositoryAdmin
|
||||||
repositorySession.close();
|
repositorySession.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
config.removeManagedRepository( repository );
|
|
||||||
|
|
||||||
if ( deleteContent )
|
if ( deleteContent )
|
||||||
{
|
{
|
||||||
|
@ -455,50 +477,63 @@ public class DefaultManagedRepositoryAdmin
|
||||||
|
|
||||||
Configuration configuration = getArchivaConfiguration().getConfiguration();
|
Configuration configuration = getArchivaConfiguration().getConfiguration();
|
||||||
|
|
||||||
ManagedRepositoryConfiguration toremove = configuration.findManagedRepositoryById( managedRepository.getId() );
|
ManagedRepositoryConfiguration updatedRepoConfig = getRepositoryConfiguration( managedRepository );
|
||||||
|
updatedRepoConfig.setStageRepoNeeded( needStageRepo );
|
||||||
|
|
||||||
boolean updateIndexContext = false;
|
org.apache.archiva.repository.ManagedRepository oldRepo = repositoryRegistry.getManagedRepository( managedRepository.getId( ) );
|
||||||
|
boolean stagingExists = false;
|
||||||
if ( toremove != null )
|
if (oldRepo.supportsFeature( StagingRepositoryFeature.class ) ){
|
||||||
{
|
stagingExists = oldRepo.getFeature( StagingRepositoryFeature.class ).get().getStagingRepository() != null;
|
||||||
configuration.removeManagedRepository( toremove );
|
|
||||||
|
|
||||||
updateIndexContext = !StringUtils.equals( toremove.getIndexDir(), managedRepository.getIndexDirectory() );
|
|
||||||
}
|
}
|
||||||
|
boolean updateIndexContext = !StringUtils.equals( updatedRepoConfig.getIndexDir(), managedRepository.getIndexDirectory() );
|
||||||
ManagedRepositoryConfiguration stagingRepository = getStageRepoConfig( toremove );
|
|
||||||
|
|
||||||
// TODO remove content from old if path has changed !!!!!
|
// TODO remove content from old if path has changed !!!!!
|
||||||
|
try
|
||||||
if ( stagingRepository != null )
|
|
||||||
{
|
{
|
||||||
configuration.removeManagedRepository( stagingRepository );
|
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( ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ManagedRepositoryConfiguration managedRepositoryConfiguration =
|
|
||||||
addManagedRepository( managedRepository.getId(), managedRepository.getLayout(), managedRepository.getName(),
|
}
|
||||||
managedRepository.getLocation(), managedRepository.isBlockRedeployments(),
|
catch ( RepositoryException e )
|
||||||
managedRepository.isReleases(), managedRepository.isSnapshots(), needStageRepo,
|
{
|
||||||
managedRepository.getCronExpression(), managedRepository.getIndexDirectory(),
|
log.error("Could not update repository {}: {}", managedRepository.getId(), e.getMessage(), e);
|
||||||
managedRepository.getDaysOlder(), managedRepository.getRetentionCount(),
|
throw new RepositoryAdminException( "Could not update repository "+managedRepository.getId());
|
||||||
managedRepository.isDeleteReleasedSnapshots(), managedRepository.getDescription(),
|
}
|
||||||
managedRepository.isSkipPackedIndexCreation(), managedRepository.isScanned(),
|
catch ( RoleManagerException e ) {
|
||||||
auditInformation, getArchivaConfiguration().getConfiguration() );
|
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() );
|
||||||
|
}
|
||||||
|
|
||||||
// Save the repository configuration.
|
// Save the repository configuration.
|
||||||
RepositorySession repositorySession = getRepositorySessionFactory().createSession();
|
RepositorySession repositorySession = getRepositorySessionFactory().createSession();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
triggerAuditEvent( managedRepositoryConfiguration.getId(), null, AuditEvent.MODIFY_MANAGED_REPO,
|
|
||||||
auditInformation );
|
|
||||||
|
|
||||||
saveConfiguration( this.getArchivaConfiguration().getConfiguration() );
|
|
||||||
if ( resetStats )
|
if ( resetStats )
|
||||||
{
|
{
|
||||||
log.debug( "call repositoryStatisticsManager.deleteStatistics" );
|
log.debug( "call repositoryStatisticsManager.deleteStatistics" );
|
||||||
getRepositoryStatisticsManager().deleteStatistics( repositorySession.getRepository(),
|
getRepositoryStatisticsManager().deleteStatistics( repositorySession.getRepository(),
|
||||||
managedRepositoryConfiguration.getId() );
|
managedRepository.getId() );
|
||||||
repositorySession.save();
|
repositorySession.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -545,27 +580,20 @@ public class DefaultManagedRepositoryAdmin
|
||||||
protected void addRepository( ManagedRepositoryConfiguration repository, Configuration configuration )
|
protected void addRepository( ManagedRepositoryConfiguration repository, Configuration configuration )
|
||||||
throws RepositoryAdminException, IOException
|
throws RepositoryAdminException, IOException
|
||||||
{
|
{
|
||||||
// Normalize the path
|
try
|
||||||
Path file = Paths.get( repository.getLocation() );
|
|
||||||
if ( !file.isAbsolute() )
|
|
||||||
{
|
{
|
||||||
// add appserver.base/repositories
|
getRepositoryRegistry().putRepository( repository, configuration );
|
||||||
file = Paths.get( getRegistry().getString( "appserver.base" ),"repositories",
|
|
||||||
repository.getLocation() );
|
|
||||||
}
|
}
|
||||||
repository.setLocation( file.normalize().toString() );
|
catch ( RepositoryException e )
|
||||||
if ( !Files.exists(file) )
|
|
||||||
{
|
{
|
||||||
Files.createDirectories(file);
|
throw new RepositoryAdminException( "Could not add the repository to the registry. Cause: "+e.getMessage() );
|
||||||
}
|
|
||||||
if ( !Files.exists(file) || !Files.isDirectory(file) )
|
|
||||||
{
|
|
||||||
throw new RepositoryAdminException(
|
|
||||||
"Unable to add repository - no write access, can not create the root directory: " + file );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
configuration.addManagedRepository( repository );
|
}
|
||||||
|
|
||||||
|
public IndexingContext createIndexContext( org.apache.archiva.repository.ManagedRepository repository) throws RepositoryAdminException
|
||||||
|
{
|
||||||
|
return createIndexContext( convertRepo( repository ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 )
|
public Boolean scanRepository( String repositoryId, boolean fullScan )
|
||||||
{
|
{
|
||||||
if ( getRepositoryTaskScheduler().isProcessingRepositoryTask( repositoryId ) )
|
if ( getRepositoryTaskScheduler().isProcessingRepositoryTask( repositoryId ) )
|
||||||
|
@ -828,4 +818,14 @@ public class DefaultManagedRepositoryAdmin
|
||||||
{
|
{
|
||||||
this.indexCreators = indexCreators;
|
this.indexCreators = indexCreators;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RepositoryRegistry getRepositoryRegistry( )
|
||||||
|
{
|
||||||
|
return repositoryRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRepositoryRegistry( RepositoryRegistry repositoryRegistry )
|
||||||
|
{
|
||||||
|
this.repositoryRegistry = repositoryRegistry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,11 +25,15 @@ import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin;
|
||||||
import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
|
import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
|
||||||
import org.apache.archiva.configuration.Configuration;
|
import org.apache.archiva.configuration.Configuration;
|
||||||
import org.apache.archiva.configuration.NetworkProxyConfiguration;
|
import org.apache.archiva.configuration.NetworkProxyConfiguration;
|
||||||
import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
|
|
||||||
import org.apache.archiva.metadata.model.facets.AuditEvent;
|
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.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -43,6 +47,9 @@ public class DefaultNetworkProxyAdmin
|
||||||
implements NetworkProxyAdmin
|
implements NetworkProxyAdmin
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
RepositoryRegistry repositoryRegistry;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<NetworkProxy> getNetworkProxies()
|
public List<NetworkProxy> getNetworkProxies()
|
||||||
throws RepositoryAdminException
|
throws RepositoryAdminException
|
||||||
|
@ -130,11 +137,20 @@ public class DefaultNetworkProxyAdmin
|
||||||
NetworkProxyConfiguration networkProxyConfiguration = getNetworkProxyConfiguration( networkProxy );
|
NetworkProxyConfiguration networkProxyConfiguration = getNetworkProxyConfiguration( networkProxy );
|
||||||
configuration.removeNetworkProxy( networkProxyConfiguration );
|
configuration.removeNetworkProxy( networkProxyConfiguration );
|
||||||
|
|
||||||
for ( RemoteRepositoryConfiguration rrc : configuration.getRemoteRepositories() )
|
for ( RemoteRepository repo : repositoryRegistry.getRemoteRepositories()) {
|
||||||
{
|
if (repo.supportsFeature( RemoteIndexFeature.class )) {
|
||||||
if ( StringUtils.equals( rrc.getRemoteDownloadNetworkProxyId(), networkProxyId ) )
|
RemoteIndexFeature rif = repo.getFeature( RemoteIndexFeature.class ).get();
|
||||||
{
|
if (networkProxyId.equals(rif.getProxyId())) {
|
||||||
rrc.setRemoteDownloadNetworkProxyId( null );
|
rif.setProxyId( null );
|
||||||
|
try
|
||||||
|
{
|
||||||
|
repositoryRegistry.putRepository( repo, configuration);
|
||||||
|
}
|
||||||
|
catch ( RepositoryException e )
|
||||||
|
{
|
||||||
|
log.error("Could not update repository {}", repo.getId(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ package org.apache.archiva.admin.repository.remote;
|
||||||
|
|
||||||
import org.apache.archiva.admin.model.AuditInformation;
|
import org.apache.archiva.admin.model.AuditInformation;
|
||||||
import org.apache.archiva.admin.model.RepositoryAdminException;
|
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.model.remote.RemoteRepositoryAdmin;
|
||||||
import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
|
import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
|
||||||
import org.apache.archiva.configuration.Configuration;
|
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.RemoteRepositoryConfiguration;
|
||||||
import org.apache.archiva.configuration.RepositoryCheckPath;
|
import org.apache.archiva.configuration.RepositoryCheckPath;
|
||||||
import org.apache.archiva.metadata.model.facets.AuditEvent;
|
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.commons.lang.StringUtils;
|
||||||
import org.apache.maven.index.NexusIndexer;
|
import org.apache.maven.index.NexusIndexer;
|
||||||
import org.apache.maven.index.context.IndexCreator;
|
import org.apache.maven.index.context.IndexCreator;
|
||||||
|
@ -48,6 +52,7 @@ import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Olivier Lamy
|
* @author Olivier Lamy
|
||||||
|
@ -59,6 +64,9 @@ public class DefaultRemoteRepositoryAdmin
|
||||||
implements RemoteRepositoryAdmin
|
implements RemoteRepositoryAdmin
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
RepositoryRegistry repositoryRegistry;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private List<? extends IndexCreator> indexCreators;
|
private List<? extends IndexCreator> indexCreators;
|
||||||
|
|
||||||
|
@ -69,7 +77,7 @@ public class DefaultRemoteRepositoryAdmin
|
||||||
private void initialize()
|
private void initialize()
|
||||||
throws RepositoryAdminException
|
throws RepositoryAdminException
|
||||||
{
|
{
|
||||||
for ( RemoteRepository remoteRepository : getRemoteRepositories() )
|
for ( org.apache.archiva.admin.model.beans.RemoteRepository remoteRepository : getRemoteRepositories() )
|
||||||
{
|
{
|
||||||
createIndexContext( remoteRepository );
|
createIndexContext( remoteRepository );
|
||||||
}
|
}
|
||||||
|
@ -81,9 +89,9 @@ public class DefaultRemoteRepositoryAdmin
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<RemoteRepository> remoteRepositories = getRemoteRepositories();
|
List<org.apache.archiva.admin.model.beans.RemoteRepository> remoteRepositories = getRemoteRepositories();
|
||||||
// close index on shutdown
|
// 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() );
|
IndexingContext context = indexer.getIndexingContexts().get( remoteRepository.getId() );
|
||||||
if ( context != null )
|
if ( context != null )
|
||||||
|
@ -99,53 +107,74 @@ public class DefaultRemoteRepositoryAdmin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
/*
|
||||||
public List<RemoteRepository> getRemoteRepositories()
|
* Conversion between the repository from the registry and the serialized DTO for the admin API
|
||||||
throws RepositoryAdminException
|
*/
|
||||||
{
|
private org.apache.archiva.admin.model.beans.RemoteRepository convertRepo( RemoteRepository repo ) {
|
||||||
List<RemoteRepository> remoteRepositories =
|
if (repo==null) {
|
||||||
new ArrayList<>( getArchivaConfiguration().getConfiguration().getRemoteRepositories().size() );
|
return null;
|
||||||
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;
|
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
|
@Override
|
||||||
public RemoteRepository getRemoteRepository( String repositoryId )
|
public List<org.apache.archiva.admin.model.beans.RemoteRepository> getRemoteRepositories()
|
||||||
throws RepositoryAdminException
|
throws RepositoryAdminException
|
||||||
{
|
{
|
||||||
for ( RemoteRepository remoteRepository : getRemoteRepositories() )
|
|
||||||
{
|
return repositoryRegistry.getRemoteRepositories().stream().map( repo -> convertRepo( repo ) ).collect( Collectors.toList());
|
||||||
if ( StringUtils.equals( repositoryId, remoteRepository.getId() ) )
|
|
||||||
{
|
|
||||||
return remoteRepository;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean addRemoteRepository( RemoteRepository remoteRepository, AuditInformation auditInformation )
|
public org.apache.archiva.admin.model.beans.RemoteRepository getRemoteRepository( String repositoryId )
|
||||||
|
throws RepositoryAdminException
|
||||||
|
{
|
||||||
|
return convertRepo( repositoryRegistry.getRemoteRepository( repositoryId ));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean addRemoteRepository( org.apache.archiva.admin.model.beans.RemoteRepository remoteRepository, AuditInformation auditInformation )
|
||||||
throws RepositoryAdminException
|
throws RepositoryAdminException
|
||||||
{
|
{
|
||||||
triggerAuditEvent( remoteRepository.getId(), null, AuditEvent.ADD_REMOTE_REPO, auditInformation );
|
triggerAuditEvent( remoteRepository.getId(), null, AuditEvent.ADD_REMOTE_REPO, auditInformation );
|
||||||
|
@ -172,11 +201,21 @@ public class DefaultRemoteRepositoryAdmin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteRepositoryConfiguration remoteRepositoryConfiguration =
|
|
||||||
getRemoteRepositoryConfiguration( remoteRepository );
|
|
||||||
|
|
||||||
Configuration configuration = getArchivaConfiguration().getConfiguration();
|
Configuration configuration = getArchivaConfiguration().getConfiguration();
|
||||||
configuration.addRemoteRepository( remoteRepositoryConfiguration );
|
RemoteRepositoryConfiguration remoteRepositoryConfiguration =
|
||||||
|
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()) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
saveConfiguration( configuration );
|
saveConfiguration( configuration );
|
||||||
|
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
|
@ -191,15 +230,19 @@ public class DefaultRemoteRepositoryAdmin
|
||||||
|
|
||||||
Configuration configuration = getArchivaConfiguration().getConfiguration();
|
Configuration configuration = getArchivaConfiguration().getConfiguration();
|
||||||
|
|
||||||
RemoteRepositoryConfiguration remoteRepositoryConfiguration =
|
RemoteRepository repo = repositoryRegistry.getRemoteRepository( repositoryId );
|
||||||
configuration.getRemoteRepositoriesAsMap().get( repositoryId );
|
if (repo==null) {
|
||||||
if ( remoteRepositoryConfiguration == null )
|
throw new RepositoryAdminException( "Could not delete repository "+repositoryId+". The repository does not exist." );
|
||||||
{
|
}
|
||||||
throw new RepositoryAdminException(
|
try
|
||||||
"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 ?
|
// TODO use ProxyConnectorAdmin interface ?
|
||||||
// [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository.
|
// [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository.
|
||||||
|
@ -218,7 +261,7 @@ public class DefaultRemoteRepositoryAdmin
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean updateRemoteRepository( RemoteRepository remoteRepository, AuditInformation auditInformation )
|
public Boolean updateRemoteRepository( org.apache.archiva.admin.model.beans.RemoteRepository remoteRepository, AuditInformation auditInformation )
|
||||||
throws RepositoryAdminException
|
throws RepositoryAdminException
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -230,30 +273,27 @@ public class DefaultRemoteRepositoryAdmin
|
||||||
|
|
||||||
Configuration configuration = getArchivaConfiguration().getConfiguration();
|
Configuration configuration = getArchivaConfiguration().getConfiguration();
|
||||||
|
|
||||||
RemoteRepositoryConfiguration remoteRepositoryConfiguration =
|
RemoteRepositoryConfiguration remoteRepositoryConfiguration = getRepositoryConfiguration( remoteRepository );
|
||||||
configuration.getRemoteRepositoriesAsMap().get( repositoryId );
|
try
|
||||||
if ( remoteRepositoryConfiguration == null )
|
|
||||||
{
|
{
|
||||||
throw new RepositoryAdminException(
|
repositoryRegistry.putRepository( remoteRepositoryConfiguration, configuration );
|
||||||
"remoteRepository with id " + repositoryId + " not exist cannot remove it" );
|
}
|
||||||
|
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 );
|
saveConfiguration( configuration );
|
||||||
|
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, RemoteRepository> getRemoteRepositoriesAsMap()
|
public Map<String, org.apache.archiva.admin.model.beans.RemoteRepository> getRemoteRepositoriesAsMap()
|
||||||
throws RepositoryAdminException
|
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 );
|
map.put( repo.getId(), repo );
|
||||||
}
|
}
|
||||||
|
@ -262,7 +302,7 @@ public class DefaultRemoteRepositoryAdmin
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IndexingContext createIndexContext( RemoteRepository remoteRepository )
|
public IndexingContext createIndexContext( org.apache.archiva.admin.model.beans.RemoteRepository remoteRepository )
|
||||||
throws RepositoryAdminException
|
throws RepositoryAdminException
|
||||||
{
|
{
|
||||||
try
|
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" ) )
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -106,8 +107,9 @@ public abstract class AbstractRepositoryAdminTest
|
||||||
|
|
||||||
protected ManagedRepository getTestManagedRepository( String repoId, String repoLocation )
|
protected ManagedRepository getTestManagedRepository( String repoId, String repoLocation )
|
||||||
{
|
{
|
||||||
return new ManagedRepository( repoId, "test repo", repoLocation, "default", false, true, true, "0 0 * * * ?",
|
String repoLocationStr = Paths.get(repoLocation, ".index").toString();
|
||||||
repoLocation + "/.index", false, 1, 2, true, false );
|
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 )
|
protected Path clearRepoLocation(String path )
|
||||||
|
@ -141,7 +143,7 @@ public abstract class AbstractRepositoryAdminTest
|
||||||
|
|
||||||
protected RemoteRepository getRemoteRepository( String id )
|
protected RemoteRepository getRemoteRepository( String id )
|
||||||
{
|
{
|
||||||
RemoteRepository remoteRepository = new RemoteRepository();
|
RemoteRepository remoteRepository = new RemoteRepository(Locale.getDefault());
|
||||||
remoteRepository.setUrl( "http://foo.com/maven-it-rocks" );
|
remoteRepository.setUrl( "http://foo.com/maven-it-rocks" );
|
||||||
remoteRepository.setTimeout( 10 );
|
remoteRepository.setTimeout( 10 );
|
||||||
remoteRepository.setName( "maven foo" );
|
remoteRepository.setName( "maven foo" );
|
||||||
|
|
|
@ -20,14 +20,25 @@ package org.apache.archiva.admin.repository.managed;
|
||||||
|
|
||||||
import org.apache.archiva.admin.model.beans.ManagedRepository;
|
import org.apache.archiva.admin.model.beans.ManagedRepository;
|
||||||
import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest;
|
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.metadata.model.facets.AuditEvent;
|
||||||
|
import org.apache.archiva.repository.RepositoryRegistry;
|
||||||
import org.apache.archiva.security.common.ArchivaRoleConstants;
|
import org.apache.archiva.security.common.ArchivaRoleConstants;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
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.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Olivier Lamy
|
* @author Olivier Lamy
|
||||||
|
@ -35,6 +46,12 @@ import java.util.List;
|
||||||
public class ManagedRepositoryAdminTest
|
public class ManagedRepositoryAdminTest
|
||||||
extends AbstractRepositoryAdminTest
|
extends AbstractRepositoryAdminTest
|
||||||
{
|
{
|
||||||
|
@Inject
|
||||||
|
private ArchivaConfiguration archivaConfiguration;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private RepositoryRegistry repositoryRegistry;
|
||||||
|
|
||||||
public static final String STAGE_REPO_ID_END = DefaultManagedRepositoryAdmin.STAGE_REPO_ID_END;
|
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();
|
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
|
@Test
|
||||||
public void getAllManagedRepos()
|
public void getAllManagedRepos()
|
||||||
throws Exception
|
throws Exception
|
||||||
|
@ -83,7 +115,7 @@ public class ManagedRepositoryAdminTest
|
||||||
int initialSize = repos.size();
|
int initialSize = repos.size();
|
||||||
assertTrue( initialSize > 0 );
|
assertTrue( initialSize > 0 );
|
||||||
|
|
||||||
ManagedRepository repo = new ManagedRepository();
|
ManagedRepository repo = new ManagedRepository( Locale.getDefault());
|
||||||
repo.setId( repoId );
|
repo.setId( repoId );
|
||||||
repo.setName( "test repo" );
|
repo.setName( "test repo" );
|
||||||
repo.setLocation( repoLocation );
|
repo.setLocation( repoLocation );
|
||||||
|
@ -135,7 +167,7 @@ public class ManagedRepositoryAdminTest
|
||||||
int initialSize = repos.size();
|
int initialSize = repos.size();
|
||||||
assertTrue( initialSize > 0 );
|
assertTrue( initialSize > 0 );
|
||||||
|
|
||||||
ManagedRepository repo = new ManagedRepository();
|
ManagedRepository repo = new ManagedRepository(Locale.getDefault());
|
||||||
repo.setId( repoId );
|
repo.setId( repoId );
|
||||||
repo.setName( "test repo" );
|
repo.setName( "test repo" );
|
||||||
repo.setLocation( repoLocation );
|
repo.setLocation( repoLocation );
|
||||||
|
@ -200,7 +232,7 @@ public class ManagedRepositoryAdminTest
|
||||||
int initialSize = repos.size();
|
int initialSize = repos.size();
|
||||||
assertTrue( initialSize > 0 );
|
assertTrue( initialSize > 0 );
|
||||||
|
|
||||||
ManagedRepository repo = new ManagedRepository();
|
ManagedRepository repo = new ManagedRepository(Locale.getDefault());
|
||||||
repo.setId( repoId );
|
repo.setId( repoId );
|
||||||
repo.setName( "test repo" );
|
repo.setName( "test repo" );
|
||||||
repo.setLocation( repoLocation );
|
repo.setLocation( repoLocation );
|
||||||
|
@ -250,6 +282,7 @@ public class ManagedRepositoryAdminTest
|
||||||
String stageRepoLocation = Paths.get(APPSERVER_BASE_PATH, repoId).toString();
|
String stageRepoLocation = Paths.get(APPSERVER_BASE_PATH, repoId).toString();
|
||||||
|
|
||||||
Path repoDir = clearRepoLocation( repoLocation );
|
Path repoDir = clearRepoLocation( repoLocation );
|
||||||
|
clearRepoLocation( repoLocation+STAGE_REPO_ID_END );
|
||||||
|
|
||||||
mockAuditListener.clearEvents();
|
mockAuditListener.clearEvents();
|
||||||
List<ManagedRepository> repos = managedRepositoryAdmin.getManagedRepositories();
|
List<ManagedRepository> repos = managedRepositoryAdmin.getManagedRepositories();
|
||||||
|
@ -284,16 +317,17 @@ public class ManagedRepositoryAdminTest
|
||||||
managedRepositoryAdmin.updateManagedRepository( repo, true, getFakeAuditInformation(), false );
|
managedRepositoryAdmin.updateManagedRepository( repo, true, getFakeAuditInformation(), false );
|
||||||
|
|
||||||
repo = managedRepositoryAdmin.getManagedRepository( repoId );
|
repo = managedRepositoryAdmin.getManagedRepository( repoId );
|
||||||
|
System.err.println("REPOSITORY "+repo.getLocation());
|
||||||
assertNotNull( repo );
|
assertNotNull( repo );
|
||||||
assertEquals( newName, repo.getName() );
|
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 )) );
|
assertTrue( Files.exists( Paths.get(repoLocation )) );
|
||||||
assertEquals( getTestManagedRepository( repoId, repoLocation ).getCronExpression(), repo.getCronExpression() );
|
assertEquals( getTestManagedRepository( repoId, repoLocation ).getCronExpression(), repo.getCronExpression() );
|
||||||
assertEquals( getTestManagedRepository( repoId, repoLocation ).getLayout(), repo.getLayout() );
|
assertEquals( getTestManagedRepository( repoId, repoLocation ).getLayout(), repo.getLayout() );
|
||||||
assertEquals( getTestManagedRepository( repoId, repoLocation ).getId(), repo.getId() );
|
assertEquals( getTestManagedRepository( repoId, repoLocation ).getId(), repo.getId() );
|
||||||
assertEquals( getTestManagedRepository( repoId, repoLocation ).getIndexDirectory(), repo.getIndexDirectory() );
|
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 ).getRetentionCount(), repo.getRetentionCount() );
|
||||||
assertEquals( getTestManagedRepository( repoId, repoLocation ).isDeleteReleasedSnapshots(),
|
assertEquals( getTestManagedRepository( repoId, repoLocation ).isDeleteReleasedSnapshots(),
|
||||||
repo.isDeleteReleasedSnapshots() );
|
repo.isDeleteReleasedSnapshots() );
|
||||||
|
@ -319,7 +353,7 @@ public class ManagedRepositoryAdminTest
|
||||||
|
|
||||||
mockAuditListener.clearEvents();
|
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 )) );
|
assertFalse( Files.exists(Paths.get( repoLocation + STAGE_REPO_ID_END )) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Olivier Lamy
|
* @author Olivier Lamy
|
||||||
|
@ -74,7 +75,7 @@ public class ProxyConnectorRuleAdminTest
|
||||||
public void addProxyConnectorRuleWithTwoProxyConnectors()
|
public void addProxyConnectorRuleWithTwoProxyConnectors()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
RemoteRepository remoteRepository = new RemoteRepository();
|
RemoteRepository remoteRepository = new RemoteRepository(Locale.getDefault());
|
||||||
remoteRepository.setId( "archiva" );
|
remoteRepository.setId( "archiva" );
|
||||||
remoteRepository.setName( "archiva rocks" );
|
remoteRepository.setName( "archiva rocks" );
|
||||||
remoteRepository.setUrl( "http://wine.org" );
|
remoteRepository.setUrl( "http://wine.org" );
|
||||||
|
@ -120,7 +121,7 @@ public class ProxyConnectorRuleAdminTest
|
||||||
public void updateProxyConnectorRuleWithTwoProxyConnectors()
|
public void updateProxyConnectorRuleWithTwoProxyConnectors()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
RemoteRepository remoteRepository = new RemoteRepository();
|
RemoteRepository remoteRepository = new RemoteRepository( Locale.getDefault( ));
|
||||||
remoteRepository.setId( "archiva" );
|
remoteRepository.setId( "archiva" );
|
||||||
remoteRepository.setName( "archiva rocks" );
|
remoteRepository.setName( "archiva rocks" );
|
||||||
remoteRepository.setUrl( "http://wine.org" );
|
remoteRepository.setUrl( "http://wine.org" );
|
||||||
|
|
|
@ -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>
|
|
@ -31,7 +31,10 @@
|
||||||
default-lazy-init="true">
|
default-lazy-init="true">
|
||||||
|
|
||||||
<context:annotation-config/>
|
<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">
|
<bean name="scheduler" class="org.apache.archiva.redback.components.scheduler.DefaultScheduler">
|
||||||
<property name="properties">
|
<property name="properties">
|
||||||
|
|
Loading…
Reference in New Issue