Skip to content
Permalink
Browse files
Refactoring repository registry
  • Loading branch information
effrafax committed Aug 9, 2021
1 parent 32cf204 commit 3e959d5b07d1cbd0f6111b59d8928e9502aa258f
Showing 45 changed files with 2,073 additions and 812 deletions.
@@ -430,7 +430,7 @@ public synchronized void save(Configuration configuration, String eventTag)
if (section == null) {
section = baseSection;
if (section == null) {
section = createDefaultConfigurationFile();
section = createDefaultConfigurationFile(eventTag);
}
} else if (baseSection != null) {
Collection<String> keys = baseSection.getKeys();
@@ -513,7 +513,7 @@ private void escapeCronExpressions(Configuration configuration) {
}
}

private Registry createDefaultConfigurationFile()
private Registry createDefaultConfigurationFile(String eventTag)
throws RegistryException {
// TODO: may not be needed under commons-configuration 1.4 - check

@@ -543,7 +543,7 @@ private Registry createDefaultConfigurationFile()
addRegistryChangeListener(regListener);
}

triggerEvent(ConfigurationEvent.SAVED, "default-file");
triggerEvent(ConfigurationEvent.SAVED, eventTag==null?"default-file":eventTag);

Registry section = registry.getSection(KEY + ".user");
if (section == null) {
@@ -29,7 +29,7 @@
* @version $Revision$ $Date$
*/
@SuppressWarnings( "all" )
public class RepositoryGroupConfiguration
public class RepositoryGroupConfiguration extends AbstractRepositoryConfiguration
implements Serializable
{

@@ -21,10 +21,13 @@

import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.RepositorySessionFactory;
import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
import org.apache.archiva.repository.base.managed.BasicManagedRepository;
import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler;
import org.apache.archiva.repository.RepositoryException;
import org.apache.archiva.repository.RepositoryRegistry;
import org.junit.Before;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
@@ -52,7 +55,15 @@
private SimpleArtifactConsumer consumer;

@Inject
private RepositoryRegistry repositoryRegistry;
private ArchivaRepositoryRegistry repositoryRegistry;

@SuppressWarnings( "unused" )
@Inject
private ManagedRepositoryHandler managedRepositoryHandler;

@SuppressWarnings( "unused" )
@Inject
private org.apache.archiva.repository.base.group.RepositoryGroupHandler repositoryGroupHandler;

@Inject
private RepositorySessionFactory repositorySessionFactory;
@@ -70,9 +81,20 @@ public void setUp()
setUpMockRepository();
}

@After
public void tearDown() {
try
{
repositoryRegistry.removeRepository( "test-consumer-repository" );
} catch (Throwable ex) {
log.error( "Could not remove repository: {}", ex.getMessage( ) );
}
}

private void setUpMockRepository()
throws IOException, RepositoryException
{
((ArchivaRepositoryRegistry)repositoryRegistry).setIgnoreIndexing( true );
Path repoDir = Paths.get( "target/test-consumer-repo" );
Files.createDirectories( repoDir );
repoDir.toFile().deleteOnExit();
@@ -25,7 +25,10 @@
import org.apache.archiva.configuration.FileTypes;
import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
import org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate;
import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
import org.apache.archiva.repository.base.group.RepositoryGroupHandler;
import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.commons.lang3.StringUtils;
import org.junit.After;
@@ -56,6 +59,19 @@
@Inject
ArchivaConfiguration archivaConfiguration;

@SuppressWarnings( "unused" )
@Inject
RepositoryRegistry repositoryRegistry;

@SuppressWarnings( "unused" )
@Inject
RepositoryGroupHandler repositoryGroupHandler;

@SuppressWarnings( "unused" )
@Inject
ManagedRepositoryHandler managedRepositoryHandler;


@Before
public void setUp()
throws Exception
@@ -25,6 +25,7 @@
import org.apache.archiva.metadata.repository.RepositorySessionFactory;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.base.group.RepositoryGroupHandler;
import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler;
import org.apache.archiva.repository.maven.metadata.storage.Maven2RepositoryPathTranslator;
import org.apache.archiva.repository.base.managed.BasicManagedRepository;
import org.apache.archiva.repository.ReleaseScheme;
@@ -115,6 +116,10 @@
@Inject
RepositoryGroupHandler repositoryGroupHandler;

@SuppressWarnings( "unused" )
@Inject
ManagedRepositoryHandler managedRepositoryHandler;


@Before
public void setUp()
@@ -28,6 +28,7 @@
import org.apache.archiva.repository.base.managed.BasicManagedRepository;
import org.apache.archiva.repository.ReleaseScheme;
import org.apache.archiva.repository.base.group.RepositoryGroupHandler;
import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler;
import org.apache.archiva.scheduler.ArchivaTaskScheduler;
import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
@@ -101,6 +102,10 @@ public void queueTask( ArtifactIndexingTask task )
@Inject
RepositoryGroupHandler repositoryGroupHandler;

@SuppressWarnings( "unused" )
@Inject
ManagedRepositoryHandler managedRepositoryHandler;

@Override
@Before
public void setUp()
@@ -40,8 +40,11 @@
import org.apache.archiva.redback.role.RoleManager;
import org.apache.archiva.redback.role.RoleManagerException;
import org.apache.archiva.repository.ReleaseScheme;
import org.apache.archiva.repository.Repository;
import org.apache.archiva.repository.RepositoryException;
import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.repository.base.group.RepositoryGroupHandler;
import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler;
import org.apache.archiva.repository.features.ArtifactCleanupFeature;
import org.apache.archiva.repository.features.IndexCreationFeature;
import org.apache.archiva.repository.features.StagingRepositoryFeature;
@@ -85,6 +88,12 @@
@Inject
private RepositoryRegistry repositoryRegistry;

@Inject
private ManagedRepositoryHandler managedRepositoryHandler;

@Inject
private RepositoryGroupHandler repositoryGroupHandler;

@Inject
@Named(value = "archivaTaskScheduler#repository")
private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
@@ -223,19 +232,9 @@ public Boolean addManagedRepository( ManagedRepository managedRepository, boolea
Configuration configuration = getArchivaConfiguration().getConfiguration();
try
{
org.apache.archiva.repository.ManagedRepository newRepo = repositoryRegistry.putRepository( repoConfig, configuration );
org.apache.archiva.repository.ManagedRepository newRepo = repositoryRegistry.putRepository( repoConfig );
log.debug("Added new repository {}", newRepo.getId());
org.apache.archiva.repository.ManagedRepository stagingRepo = null;
addRepositoryRoles( newRepo.getId() );
if ( newRepo.supportsFeature( StagingRepositoryFeature.class )) {
StagingRepositoryFeature stf = newRepo.getFeature( StagingRepositoryFeature.class ).get();
stagingRepo = stf.getStagingRepository();
if (stf.isStageRepoNeeded() && stagingRepo != null) {
addRepositoryRoles( stagingRepo.getId() );
triggerAuditEvent( stagingRepo.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation );
}
}
saveConfiguration( configuration );
//MRM-1342 Repository statistics report doesn't appear to be working correctly
//scan repository when adding of repository is successful
try
@@ -245,9 +244,13 @@ public Boolean addManagedRepository( ManagedRepository managedRepository, boolea
scanRepository( newRepo.getId(), true );
}

if ( stagingRepo!=null && stagingRepo.isScanned() )
org.apache.archiva.repository.ManagedRepository stagingRepo = newRepo.getFeature( StagingRepositoryFeature.class ).get( ).getStagingRepository( );
if ( stagingRepo!=null)
{
scanRepository( stagingRepo.getId(), true );
if (stagingRepo.isScanned()) {
scanRepository( stagingRepo.getId(), true );
}
addRepositoryRoles( stagingRepo.getId( ) );
}
}
catch ( Exception e )
@@ -285,14 +288,8 @@ public Boolean deleteManagedRepository( String repositoryId, AuditInformation au
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.");
if (repo.supportsFeature(StagingRepositoryFeature.class)) {
stagingRepository = repo.getFeature(StagingRepositoryFeature.class).get().getStagingRepository();
}
} else {
throw new RepositoryAdminException("A repository with that id does not exist");
@@ -308,13 +305,8 @@ public Boolean deleteManagedRepository( String repositoryId, AuditInformation au
if (stagingRepository != null) {
// do not trigger event when deleting the staged one
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);
if (stagingRepositoryConfig != null) {
deleteManagedRepository(stagingRepositoryConfig, deleteContent, config, true);
}
}

@@ -371,12 +363,6 @@ private Boolean deleteManagedRepository( ManagedRepositoryConfiguration reposito

}

if ( deleteContent )
{
// TODO could be async ? as directory can be huge
Path dir = Paths.get( repository.getLocation() );
org.apache.archiva.common.utils.FileUtils.deleteQuietly( dir );
}

// olamy: copy list for reading as a unit test in webapp fail with ConcurrentModificationException
List<ProxyConnectorConfiguration> proxyConnectors = new ArrayList<>( config.getProxyConnectors() );
@@ -387,27 +373,6 @@ private Boolean deleteManagedRepository( ManagedRepositoryConfiguration reposito
config.removeProxyConnector( proxyConnector );
}
}

Map<String, List<String>> repoToGroupMap = config.getRepositoryToGroupMap();
if ( repoToGroupMap != null )
{
if ( repoToGroupMap.containsKey( repository.getId() ) )
{
List<String> repoGroups = repoToGroupMap.get( repository.getId() );
for ( String repoGroup : repoGroups )
{
// copy to prevent UnsupportedOperationException
RepositoryGroupConfiguration repositoryGroupConfiguration =
config.findRepositoryGroupById( repoGroup );
List<String> repos = new ArrayList<>( repositoryGroupConfiguration.getRepositories() );
config.removeRepositoryGroup( repositoryGroupConfiguration );
repos.remove( repository.getId() );
repositoryGroupConfiguration.setRepositories( repos );
config.addRepositoryGroup( repositoryGroupConfiguration );
}
}
}

try
{
removeRepositoryRoles( repository );
@@ -419,16 +384,24 @@ private Boolean deleteManagedRepository( ManagedRepositoryConfiguration reposito
}

try {
final RepositoryRegistry reg = getRepositoryRegistry();
if (reg.getManagedRepository(repository.getId())!=null) {
reg.removeRepository(reg.getManagedRepository(repository.getId()));
org.apache.archiva.repository.ManagedRepository repo = repositoryRegistry.getManagedRepository( repository.getId( ) );
if (repo!=null)
{
repositoryRegistry.removeRepository( repo, config );
if ( deleteContent )
{
// TODO could be async ? as directory can be huge
Path dir = Paths.get( repository.getLocation( ) );
org.apache.archiva.common.utils.FileUtils.deleteQuietly( dir );
}
}
} catch (RepositoryException e) {
throw new RepositoryAdminException("Removal of repository "+repository.getId()+ " failed: "+e.getMessage());
}

saveConfiguration( config );


return Boolean.TRUE;
}

@@ -452,8 +425,6 @@ public Boolean updateManagedRepository( ManagedRepository managedRepository, boo

getRepositoryCommonValidator().validateManagedRepository( managedRepository );

Configuration configuration = getArchivaConfiguration().getConfiguration();

ManagedRepositoryConfiguration updatedRepoConfig = getRepositoryConfiguration( managedRepository );
updatedRepoConfig.setStageRepoNeeded( needStageRepo );

@@ -467,7 +438,7 @@ public Boolean updateManagedRepository( ManagedRepository managedRepository, boo
// TODO remove content from old if path has changed !!!!!
try
{
newRepo = repositoryRegistry.putRepository( updatedRepoConfig, configuration );
newRepo = repositoryRegistry.putRepository( updatedRepoConfig );
if (newRepo.supportsFeature( StagingRepositoryFeature.class )) {
org.apache.archiva.repository.ManagedRepository stagingRepo = newRepo.getFeature( StagingRepositoryFeature.class ).get( ).getStagingRepository( );
if (stagingRepo!=null && !stagingExists)
@@ -490,16 +461,6 @@ public Boolean updateManagedRepository( ManagedRepository managedRepository, boo
}
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.
RepositorySession repositorySession = null;
try
@@ -31,7 +31,9 @@
import org.apache.archiva.redback.role.RoleManager;
import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.memory.SimpleUser;
import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.repository.base.group.RepositoryGroupHandler;
import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.commons.lang3.StringUtils;
import org.junit.Before;
@@ -84,10 +86,18 @@
@Inject
private ArchivaConfiguration archivaConfiguration;

@Inject
protected RepositoryRegistry repositoryRegistry;

@SuppressWarnings( "unused" )
@Inject
ManagedRepositoryHandler managedRepositoryHandler;

@SuppressWarnings( "unused" )
@Inject
RepositoryGroupHandler repositoryGroupHandler;


@Before
public void initialize() {
Path confFile = Paths.get(APPSERVER_BASE_PATH, "conf/archiva.xml");

0 comments on commit 3e959d5

Please sign in to comment.