import org.apache.archiva.admin.model.AuditInformation;
import org.apache.archiva.admin.model.RepositoryAdminException;
+import org.apache.archiva.admin.model.admin.ArchivaAdministration;
+import org.apache.archiva.admin.model.group.RepositoryGroupAdmin;
import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
+import org.apache.archiva.admin.model.proxyconnector.ProxyConnector;
+import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorAdmin;
import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
import org.apache.archiva.audit.AuditEvent;
import org.apache.archiva.audit.AuditListener;
import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.configuration.ArchivaConfiguration;
-import org.apache.maven.archiva.configuration.Configuration;
-import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
-import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
-import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
-import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
import org.apache.maven.archiva.model.VersionedReference;
import org.apache.maven.archiva.repository.RepositoryContentFactory;
import org.apache.maven.archiva.repository.RepositoryException;
import org.apache.maven.archiva.repository.RepositoryNotFoundException;
-import org.codehaus.plexus.registry.RegistryException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
{
protected Logger log = LoggerFactory.getLogger( getClass() );
- private ArchivaConfiguration archivaConfiguration;
-
private RepositoryContentConsumers repoConsumersUtil;
private RepositoryContentFactory repoFactory;
private RemoteRepositoryAdmin remoteRepositoryAdmin;
+ private ArchivaAdministration archivaAdministration;
+
+ private ProxyConnectorAdmin proxyConnectorAdmin;
+
+ private RepositoryGroupAdmin repositoryGroupAdmin;
+
private static final String REPOSITORY_ID_VALID_EXPRESSION = "^[a-zA-Z0-9._-]+$";
private static final String REPOSITORY_NAME_VALID_EXPRESSION = "^([a-zA-Z0-9.)/_(-]|\\s)+$";
private static final String REPOSITORY_LOCATION_VALID_EXPRESSION = "^[-a-zA-Z0-9._/~:?!&=\\\\]+$";
- public AdministrationServiceImpl( ArchivaConfiguration archivaConfig, RepositoryContentConsumers repoConsumersUtil,
+ public AdministrationServiceImpl( ArchivaAdministration archivaAdministration,
+ RepositoryContentConsumers repoConsumersUtil,
RepositoryContentFactory repoFactory,
RepositorySessionFactory repositorySessionFactory,
RepositoryArchivaTaskScheduler repositoryTaskScheduler,
RepositoryStatisticsManager repositoryStatisticsManager,
RepositoryMerger repositoryMerger, AuditListener auditListener,
ManagedRepositoryAdmin managedRepositoryAdmin,
- RemoteRepositoryAdmin remoteRepositoryAdmin )
+ RemoteRepositoryAdmin remoteRepositoryAdmin,
+ ProxyConnectorAdmin proxyConnectorAdmin,
+ RepositoryGroupAdmin repositoryGroupAdmin )
{
- this.archivaConfiguration = archivaConfig;
this.repoConsumersUtil = repoConsumersUtil;
this.repoFactory = repoFactory;
this.repositoryTaskScheduler = repositoryTaskScheduler;
this.auditListener = auditListener;
this.managedRepositoryAdmin = managedRepositoryAdmin;
this.remoteRepositoryAdmin = remoteRepositoryAdmin;
+ this.archivaAdministration = archivaAdministration;
+ this.proxyConnectorAdmin = proxyConnectorAdmin;
+ this.repositoryGroupAdmin = repositoryGroupAdmin;
}
/**
throw new Exception( "Invalid repository consumer." );
}
- Configuration config = archivaConfiguration.getConfiguration();
- RepositoryScanningConfiguration repoScanningConfig = config.getRepositoryScanning();
-
if ( isKnownContentConsumer )
{
- repoScanningConfig.addKnownContentConsumer( consumerId );
+ if ( enable )
+ {
+ archivaAdministration.addKnownContentConsumer( consumerId, getAuditInformation() );
+ }
+ else
+ {
+ archivaAdministration.removeKnownContentConsumer( consumerId, getAuditInformation() );
+ }
+
}
else
{
- repoScanningConfig.addInvalidContentConsumer( consumerId );
+ if ( enable )
+ {
+ archivaAdministration.addInvalidContentConsumer( consumerId, getAuditInformation() );
+ }
+ else
+ {
+ archivaAdministration.removeInvalidContentConsumer( consumerId, getAuditInformation() );
+ }
}
- config.setRepositoryScanning( repoScanningConfig );
- saveConfiguration( config );
-
return true;
}
{
// TODO: remove duplication with web
- Configuration config = archivaConfiguration.getConfiguration();
- ManagedRepositoryConfiguration repoConfig = config.findManagedRepositoryById( repoId );
+ org.apache.archiva.admin.model.managed.ManagedRepository repoConfig =
+ managedRepositoryAdmin.getManagedRepository( repoId );
if ( repoConfig == null )
{
public Boolean executeRepositoryScanner( String repoId )
throws Exception
{
- Configuration config = archivaConfiguration.getConfiguration();
- if ( config.findManagedRepositoryById( repoId ) == null )
+ if ( managedRepositoryAdmin.getManagedRepository( repoId ) == null )
{
throw new Exception( "Repository does not exist." );
}
return remoteRepos;
}
- private void saveConfiguration( Configuration config )
- throws Exception
- {
- try
- {
- archivaConfiguration.save( config );
- }
- catch ( RegistryException e )
- {
- throw new Exception( "Error occurred in the registry." );
- }
- catch ( IndeterminateConfigurationException e )
- {
- throw new Exception( "Error occurred while saving the configuration." );
- }
- }
-
public Boolean addManagedRepository( String repoId, String layout, String name, String location,
boolean blockRedeployments, boolean releasesIncluded,
boolean snapshotsIncluded, boolean stageRepoNeeded, String cronExpression,
org.apache.archiva.admin.model.managed.ManagedRepository repository =
new org.apache.archiva.admin.model.managed.ManagedRepository( repoId, name, location, layout,
- snapshotsIncluded, releasesIncluded,
- blockRedeployments, cronExpression, null,
- false, daysOlder, retentionCount,
- deleteReleasedSnapshots );
+ snapshotsIncluded, releasesIncluded,
+ blockRedeployments, cronExpression, null,
+ false, daysOlder, retentionCount,
+ deleteReleasedSnapshots );
return managedRepositoryAdmin.addManagedRepository( repository, stageRepoNeeded, getAuditInformation() );
}
public Boolean deleteManagedRepository( String repoId )
throws Exception
{
- Configuration config = archivaConfiguration.getConfiguration();
- ManagedRepositoryConfiguration repository = config.findManagedRepositoryById( repoId );
+ org.apache.archiva.admin.model.managed.ManagedRepository repository =
+ managedRepositoryAdmin.getManagedRepository( repoId );
if ( repository == null )
{
{
repositorySession.close();
}
- config.removeManagedRepository( repository );
-
- try
- {
- saveConfiguration( config );
- }
- catch ( Exception e )
- {
- throw new Exception( "Error saving configuration for delete action" + e.getMessage() );
- }
+ managedRepositoryAdmin.deleteManagedRepository( repoId, getAuditInformation(), false );
File dir = new File( repository.getLocation() );
if ( !FileUtils.deleteQuietly( dir ) )
throw new IOException( "Cannot delete repository " + dir );
}
- List<ProxyConnectorConfiguration> proxyConnectors = config.getProxyConnectors();
- for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors )
+ List<ProxyConnector> proxyConnectors = proxyConnectorAdmin.getProxyConnectors();
+ for ( ProxyConnector proxyConnector : proxyConnectors )
{
if ( StringUtils.equals( proxyConnector.getSourceRepoId(), repository.getId() ) )
{
- archivaConfiguration.getConfiguration().removeProxyConnector( proxyConnector );
+ proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getAuditInformation() );
}
}
- Map<String, List<String>> repoToGroupMap = archivaConfiguration.getConfiguration().getRepositoryToGroupMap();
+ Map<String, List<String>> repoToGroupMap = repositoryGroupAdmin.getRepositoryToGroupMap();
if ( repoToGroupMap != null )
{
if ( repoToGroupMap.containsKey( repository.getId() ) )
List<String> repoGroups = repoToGroupMap.get( repository.getId() );
for ( String repoGroup : repoGroups )
{
- archivaConfiguration.getConfiguration().findRepositoryGroupById( repoGroup ).removeRepository(
- repository.getId() );
+ repositoryGroupAdmin.deleteRepositoryFromGroup( repoGroup, repository.getId(),
+ getAuditInformation() );
}
}
}
public Boolean deleteManagedRepositoryContent( String repoId )
throws Exception
{
- Configuration config = archivaConfiguration.getConfiguration();
- ManagedRepositoryConfiguration repository = config.findManagedRepositoryById( repoId );
+ org.apache.archiva.admin.model.managed.ManagedRepository repository =
+ managedRepositoryAdmin.getManagedRepository( repoId );
if ( repository == null )
{
public ManagedRepository getManagedRepository( String repoId )
throws Exception
{
- Configuration config = archivaConfiguration.getConfiguration();
- ManagedRepositoryConfiguration managedRepository = config.findManagedRepositoryById( repoId );
+ org.apache.archiva.admin.model.managed.ManagedRepository managedRepository =
+ managedRepositoryAdmin.getManagedRepository( repoId );
if ( managedRepository == null )
{
throw new Exception( "A repository with that id does not exist" );
throws Exception
{
String stagingId = repoId + STAGE;
- ManagedRepositoryConfiguration repoConfig;
- ManagedRepositoryConfiguration stagingConfig;
+ org.apache.archiva.admin.model.managed.ManagedRepository repoConfig;
+ org.apache.archiva.admin.model.managed.ManagedRepository stagingConfig;
- Configuration config = archivaConfiguration.getConfiguration();
- repoConfig = config.findManagedRepositoryById( repoId );
+ repoConfig = managedRepositoryAdmin.getManagedRepository( repoId );
log.debug( "Retrieved repository configuration for repo '" + repoId + "'" );
MetadataRepository metadataRepository = repositorySession.getRepository();
if ( repoConfig != null )
{
- stagingConfig = config.findManagedRepositoryById( stagingId );
+ stagingConfig = managedRepositoryAdmin.getManagedRepository( stagingId );
if ( stagingConfig != null )
{
}
// todo: setting userid of audit event
- private AuditEvent createAuditEvent( ManagedRepositoryConfiguration repoConfig )
+ private AuditEvent createAuditEvent( org.apache.archiva.admin.model.managed.ManagedRepository repoConfig )
{
AuditEvent event = new AuditEvent();
repositoryMerger.merge( metadataRepository, sourceRepoId, repoid, artifactListWithOutSnapShots );
}
- private ManagedRepositoryConfiguration getStageRepoConfig( ManagedRepositoryConfiguration repository )
- {
- ManagedRepositoryConfiguration stagingRepository = new ManagedRepositoryConfiguration();
- stagingRepository.setId( repository.getId() + "-stage" );
- stagingRepository.setLayout( repository.getLayout() );
- stagingRepository.setName( repository.getName() + "-stage" );
- stagingRepository.setBlockRedeployments( repository.isBlockRedeployments() );
- stagingRepository.setDaysOlder( repository.getDaysOlder() );
- stagingRepository.setDeleteReleasedSnapshots( repository.isDeleteReleasedSnapshots() );
- stagingRepository.setIndexDir( repository.getIndexDir() );
- String path = repository.getLocation();
- int lastIndex = path.lastIndexOf( '/' );
- stagingRepository.setLocation( path.substring( 0, lastIndex ) + "/" + stagingRepository.getId() );
- stagingRepository.setRefreshCronExpression( repository.getRefreshCronExpression() );
- stagingRepository.setReleases( repository.isReleases() );
- stagingRepository.setRetentionCount( repository.getRetentionCount() );
- stagingRepository.setScanned( repository.isScanned() );
- stagingRepository.setSnapshots( repository.isSnapshots() );
- return stagingRepository;
- }
// FIXME find a way to get user id and adress
private AuditInformation getAuditInformation()
import junit.framework.TestCase;
import net.sf.beanlib.provider.replicator.BeanReplicator;
import org.apache.archiva.admin.repository.RepositoryCommonValidator;
+import org.apache.archiva.admin.repository.admin.DefaultArchivaAdministration;
+import org.apache.archiva.admin.repository.group.DefaultRepositoryGroupAdmin;
import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
+import org.apache.archiva.admin.repository.proxyconnector.DefaultProxyConnectorAdmin;
import org.apache.archiva.admin.repository.remote.DefaultRemoteRepositoryAdmin;
import org.apache.archiva.audit.AuditEvent;
import org.apache.archiva.audit.AuditListener;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
private DefaultRemoteRepositoryAdmin remoteRepositoryAdmin;
- private ApplicationContext applicationContext;
+ private DefaultArchivaAdministration archivaAdministration;
+
+ private DefaultProxyConnectorAdmin proxyConnectorAdmin;
+
+ private DefaultRepositoryGroupAdmin repositoryGroupAdmin;
@Before
public void setUp()
remoteRepositoryAdmin.setRepositoryCommonValidator( repositoryCommonValidator );
- service = new AdministrationServiceImpl( archivaConfig, repoConsumersUtil, repositoryFactory,
+ archivaAdministration = new DefaultArchivaAdministration();
+ archivaAdministration.setArchivaConfiguration( archivaConfig );
+ archivaAdministration.setRegistry( registry );
+
+ proxyConnectorAdmin = new DefaultProxyConnectorAdmin();
+ proxyConnectorAdmin.setArchivaConfiguration( archivaConfig );
+ proxyConnectorAdmin.setRegistry( registry );
+
+ repositoryGroupAdmin = new DefaultRepositoryGroupAdmin();
+ repositoryGroupAdmin.setArchivaConfiguration( archivaConfig );
+ repositoryGroupAdmin.setRegistry( registry );
+
+ service = new AdministrationServiceImpl( archivaAdministration, repoConsumersUtil, repositoryFactory,
repositorySessionFactory, repositoryTaskScheduler,
Collections.singletonList( listener ), repositoryStatisticsManager,
repositoryMerger, auditListener, managedRepositoryAdmin,
- remoteRepositoryAdmin );
+ remoteRepositoryAdmin, proxyConnectorAdmin, repositoryGroupAdmin );
}
/* Tests for repository consumers */
recordRepoConsumers();
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
- configControl.expectAndReturn( config.getRepositoryScanning(), repoScanning );
-
- config.setRepositoryScanning( repoScanning );
- configControl.setMatcher( MockControl.ALWAYS_MATCHER );
- configControl.setVoidCallable();
+ configControl.expectAndReturn( config.getRepositoryScanning(), repoScanning, 1, 5 );
archivaConfig.save( config );
archivaConfigControl.setVoidCallable();
recordRepoConsumers();
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
- configControl.expectAndReturn( config.getRepositoryScanning(), repoScanning );
-
- config.setRepositoryScanning( repoScanning );
- configControl.setMatcher( MockControl.ALWAYS_MATCHER );
- configControl.setVoidCallable();
+ configControl.expectAndReturn( config.getRepositoryScanning(), repoScanning, 1, 4 );
archivaConfig.save( config );
archivaConfigControl.setVoidCallable();
ManagedRepositoryConfiguration managedRepo = createManagedRepo( "default", "default-repo" );
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
- configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), managedRepo );
+ configControl.expectAndReturn( config.getManagedRepositories(), Arrays.asList( managedRepo ), 1, 5 );
ManagedDefaultRepositoryContent repoContent = new ManagedDefaultRepositoryContent();
repoContent.setRepository( new BeanReplicator().replicateBean( managedRepo,
ManagedRepositoryConfiguration managedRepo = createManagedRepo( "legacy", "legacy-repo" );
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
- configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), managedRepo );
+ configControl.expectAndReturn( config.getManagedRepositories(), Arrays.asList( managedRepo ), 1, 5 );
ManagedLegacyRepositoryContent repoContent = new ManagedLegacyRepositoryContent();
repoContent.setRepository( new BeanReplicator().replicateBean( managedRepo,
ManagedRepositoryConfiguration managedRepo = createManagedRepo( "default", "default-repo" );
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
- configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), managedRepo );
+ configControl.expectAndReturn( config.getManagedRepositories(), Arrays.asList( managedRepo ), 1, 5 );
ManagedDefaultRepositoryContent repoContent = new ManagedDefaultRepositoryContent();
repoContent.setRepository( new BeanReplicator().replicateBean( managedRepo,
throws Exception
{
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
- configControl.expectAndReturn( config.findManagedRepositoryById( "non-existing-repo" ), null );
+ configControl.expectAndReturn( config.getManagedRepositories(), Collections.emptyList() );
archivaConfigControl.replay();
configControl.replay();
throws Exception
{
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
- configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ),
- createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
+ configControl.expectAndReturn( config.getManagedRepositories(), Arrays.asList(
+ createManagedRepo( "internal", "default", "Internal Repository", true, false ) ), 1, 5 );
RepositoryTask task = new RepositoryTask();
throws Exception
{
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
- configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ),
- createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
+
+ configControl.expectAndReturn( config.getManagedRepositories(), Arrays.asList(
+ createManagedRepo( "internal", "default", "Internal Repository", true, false ) ), 1, 5 );
repositoryTaskSchedulerControl.expectAndReturn(
repositoryTaskScheduler.isProcessingRepositoryTask( "internal" ), true );
throws Exception
{
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
- configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), null );
+ configControl.expectAndReturn( config.getManagedRepositories(), Collections.emptyList(), 1, 5 );
archivaConfigControl.replay();
configControl.replay();
public void testDeleteInvalidRepositoryContent()
{
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
- configControl.expectAndReturn( config.findManagedRepositoryById( "invalid" ), null );
+ configControl.expectAndReturn( config.getManagedRepositories(), Collections.emptyList(), 1, 5 );
archivaConfigControl.replay();
configControl.replay();
ManagedRepositoryConfiguration managedRepo = createManagedRepo( "default", "default-repo" );
assertTrue( new File( managedRepo.getLocation(), "org" ).exists() );
- archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
- configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), managedRepo );
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 3 );
+ configControl.expectAndReturn( config.getManagedRepositories(), Arrays.asList( managedRepo ), 1, 5 );
metadataRepository.removeRepository( "internal" );
archivaConfigControl.replay();
throws Exception
{
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
- configControl.expectAndReturn( config.findManagedRepositoryById( "invalid" ), null );
+ configControl.expectAndReturn( config.getManagedRepositories(), Collections.emptyList(), 1, 2 );
archivaConfigControl.replay();
configControl.replay();
public void testMergeWithNoStagingRepository()
throws Exception
{
- archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
- configControl.expectAndReturn( config.findManagedRepositoryById( "repo" ),
- createManagedRepo( "repo", "default", "repo", true, false ) );
- configControl.expectAndReturn( config.findManagedRepositoryById( "repo-stage" ), null );
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 5 );
+
+ configControl.expectAndReturn( config.getManagedRepositories(),
+ Arrays.asList( createManagedRepo( "repo", "default", "repo", true, false ) ), 1,
+ 4 );
archivaConfigControl.replay();
configControl.replay();
RepositoryTask task = new RepositoryTask();
task.setScanAll( true );
- archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
- configControl.expectAndReturn( config.findManagedRepositoryById( "merge" ), merge );
- configControl.expectAndReturn( config.findManagedRepositoryById( "merge-stage" ), staging );
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 5 );
+ configControl.expectAndReturn( config.getManagedRepositories(), Arrays.asList( merge, staging ), 1, 5 );
metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( staging.getId() ), sources );
repositoryMergerControl.expectAndDefaultReturn(
repo.setLocation( "target/test-repository/one" );
ManagedRepositoryConfiguration staging = createStagingRepo( repo );
- archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
- configControl.expectAndReturn( config.findManagedRepositoryById( "repo" ), repo );
- configControl.expectAndReturn( config.findManagedRepositoryById( "repo-stage" ), staging );
+ configControl.expectAndReturn( config.getManagedRepositories(), Arrays.asList( repo, staging ), 1, 5 );
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 5 );
metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( staging.getId() ), sources );
repositoryMergerControl.expectAndDefaultReturn(