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.base.RepositoryHandlerDependencies;
import org.apache.archiva.repository.RepositoryException;
import org.apache.archiva.repository.RepositoryRegistry;
import org.junit.Before;
@SuppressWarnings( "unused" )
@Inject
- private ManagedRepositoryHandler managedRepositoryHandler;
-
- @SuppressWarnings( "unused" )
- @Inject
- private org.apache.archiva.repository.base.group.RepositoryGroupHandler repositoryGroupHandler;
+ private RepositoryHandlerDependencies repositoryHandlerDependencies;
@Inject
private RepositorySessionFactory repositorySessionFactory;
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.repository.base.RepositoryHandlerDependencies;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.commons.lang3.StringUtils;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.ApplicationContext;
-import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import javax.inject.Inject;
import java.nio.file.Path;
import java.nio.file.Paths;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
@RunWith( ArchivaSpringJUnit4ClassRunner.class )
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
@SuppressWarnings( "unused" )
@Inject
- RepositoryGroupHandler repositoryGroupHandler;
-
- @SuppressWarnings( "unused" )
- @Inject
- ManagedRepositoryHandler managedRepositoryHandler;
+ RepositoryHandlerDependencies repositoryHandlerDependencies;
@Before
import org.apache.archiva.metadata.repository.RepositorySession;
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.base.RepositoryHandlerDependencies;
import org.apache.archiva.repository.maven.metadata.storage.Maven2RepositoryPathTranslator;
import org.apache.archiva.repository.base.managed.BasicManagedRepository;
import org.apache.archiva.repository.ReleaseScheme;
@SuppressWarnings( "unused" )
@Inject
- RepositoryGroupHandler repositoryGroupHandler;
-
- @SuppressWarnings( "unused" )
- @Inject
- ManagedRepositoryHandler managedRepositoryHandler;
+ RepositoryHandlerDependencies repositoryHandlerDependencies;
@Before
import junit.framework.TestCase;
import org.apache.archiva.common.utils.PathUtil;
+import org.apache.archiva.components.taskqueue.TaskQueueException;
import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.FileTypes;
-import org.apache.archiva.components.taskqueue.TaskQueueException;
+import org.apache.archiva.repository.ReleaseScheme;
import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
+import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
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;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.*;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
/**
* NexusIndexerConsumerTest
@SuppressWarnings( "unused" )
@Inject
- RepositoryGroupHandler repositoryGroupHandler;
-
- @SuppressWarnings( "unused" )
- @Inject
- ManagedRepositoryHandler managedRepositoryHandler;
+ RepositoryHandlerDependencies repositoryHandlerDependencies;
@Override
@Before
Map<String, RemoteRepository> getRemoteRepositoriesAsMap()
throws RepositoryAdminException;
- /**
- * @param repository
- * @return
- * @throws RepositoryAdminException
- * @since 1.4-M2
- */
- ArchivaIndexingContext createIndexContext( RemoteRepository repository )
- throws RepositoryAdminException;
}
import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
+import org.apache.archiva.components.cache.Cache;
+import org.apache.archiva.components.taskqueue.TaskQueueException;
import org.apache.archiva.configuration.Configuration;
-import org.apache.archiva.configuration.IndeterminateConfigurationException;
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.archiva.configuration.ProxyConnectorConfiguration;
-import org.apache.archiva.configuration.RepositoryGroupConfiguration;
import org.apache.archiva.indexer.ArchivaIndexManager;
import org.apache.archiva.indexer.IndexManagerFactory;
import org.apache.archiva.indexer.IndexUpdateFailedException;
import org.apache.archiva.metadata.model.facets.AuditEvent;
-import org.apache.archiva.metadata.repository.*;
+import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.apache.archiva.metadata.repository.MetadataRepositoryException;
+import org.apache.archiva.metadata.repository.MetadataSessionException;
+import org.apache.archiva.metadata.repository.RepositorySession;
+import org.apache.archiva.metadata.repository.RepositorySessionFactory;
import org.apache.archiva.metadata.repository.stats.model.RepositoryStatisticsManager;
-import org.apache.archiva.components.cache.Cache;
-import org.apache.archiva.components.registry.RegistryException;
-import org.apache.archiva.components.taskqueue.TaskQueueException;
import org.apache.archiva.redback.role.RoleManager;
import org.apache.archiva.redback.role.RoleManagerException;
import org.apache.archiva.repository.ReleaseScheme;
-import org.apache.archiva.repository.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.base.RepositoryHandlerDependencies;
import org.apache.archiva.repository.features.ArtifactCleanupFeature;
import org.apache.archiva.repository.features.IndexCreationFeature;
import org.apache.archiva.repository.features.StagingRepositoryFeature;
@Inject
private RepositoryRegistry repositoryRegistry;
+ @SuppressWarnings( "unused" )
@Inject
- private ManagedRepositoryHandler managedRepositoryHandler;
-
- @Inject
- private RepositoryGroupHandler repositoryGroupHandler;
+ private RepositoryHandlerDependencies managedRepositoryHandler;
@Inject
@Named(value = "archivaTaskScheduler#repository")
throw new RepositoryAdminException(
"cannot delete NetworkProxy with id " + networkProxyId + " as not exist" );
}
- Configuration configuration = getArchivaConfiguration().getConfiguration();
- NetworkProxyConfiguration networkProxyConfiguration = getNetworkProxyConfiguration( networkProxy );
- configuration.removeNetworkProxy( networkProxyConfiguration );
-
for ( RemoteRepository repo : repositoryRegistry.getRemoteRepositories()) {
if (repo.supportsFeature( RemoteIndexFeature.class )) {
RemoteIndexFeature rif = repo.getFeature( RemoteIndexFeature.class ).get();
rif.setProxyId( null );
try
{
- repositoryRegistry.putRepository( repo, configuration);
+ repositoryRegistry.putRepository( repo );
}
catch ( RepositoryException e )
{
}
}
- triggerAuditEvent( networkProxy.getId(), null, AuditEvent.DELETE_NETWORK_PROXY, auditInformation );
-
+ Configuration configuration = getArchivaConfiguration().getConfiguration();
+ NetworkProxyConfiguration networkProxyConfiguration = getNetworkProxyConfiguration( networkProxy );
+ configuration.removeNetworkProxy( networkProxyConfiguration );
saveConfiguration( configuration );
+ triggerAuditEvent( networkProxy.getId(), null, AuditEvent.DELETE_NETWORK_PROXY, auditInformation );
}
protected NetworkProxy getNetworkProxy( NetworkProxyConfiguration networkProxyConfiguration )
import org.apache.archiva.configuration.Configuration;
import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
import org.apache.archiva.configuration.RepositoryCheckPath;
-import org.apache.archiva.indexer.ArchivaIndexingContext;
import org.apache.archiva.metadata.model.facets.AuditEvent;
import org.apache.archiva.repository.RemoteRepository;
import org.apache.archiva.repository.RepositoryCredentials;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
* @author Olivier Lamy
* @since 1.4-M1
*/
-@Service("remoteRepositoryAdmin#default")
+@Service( "remoteRepositoryAdmin#default" )
public class DefaultRemoteRepositoryAdmin
extends AbstractRepositoryAdmin
implements RemoteRepositoryAdmin
@PostConstruct
- private void initialize()
+ private void initialize( )
throws RepositoryAdminException
{
- for ( org.apache.archiva.admin.model.beans.RemoteRepository remoteRepository : getRemoteRepositories() )
- {
- createIndexContext( remoteRepository );
- }
}
/*
- * Conversion between the repository from the registry and the serialized DTO for the admin API
- */
- private org.apache.archiva.admin.model.beans.RemoteRepository convertRepo( RemoteRepository repo ) {
- if (repo==null) {
+ * Conversion between the repository from the registry and the serialized DTO for the admin API
+ */
+ private org.apache.archiva.admin.model.beans.RemoteRepository convertRepo( RemoteRepository repo )
+ {
+ if ( repo == null )
+ {
return null;
}
- org.apache.archiva.admin.model.beans.RemoteRepository adminRepo = new org.apache.archiva.admin.model.beans.RemoteRepository( getArchivaConfiguration().getDefaultLocale() );
+ 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) {
+ 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]) );
+ 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() );
+ 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( ) );
}
- if (repo.supportsFeature(IndexCreationFeature.class)) {
- IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
- adminRepo.setIndexDirectory(PathUtil.getPathFromUri(icf.getIndexPath()).toString());
+ if ( repo.supportsFeature( IndexCreationFeature.class ) )
+ {
+ IndexCreationFeature icf = repo.getFeature( IndexCreationFeature.class ).get( );
+ adminRepo.setIndexDirectory( PathUtil.getPathFromUri( icf.getIndexPath( ) ).toString( ) );
}
- adminRepo.setDescription(repo.getDescription());
+ adminRepo.setDescription( repo.getDescription( ) );
return adminRepo;
}
- private RemoteRepositoryConfiguration getRepositoryConfiguration( org.apache.archiva.admin.model.beans.RemoteRepository repo) {
- RemoteRepositoryConfiguration repoConfig = new RemoteRepositoryConfiguration();
+ 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() );
- repoConfig.setDescription(repo.getDescription());
- repoConfig.setIndexDir(repo.getIndexDirectory());
+ 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( ) );
+ repoConfig.setDescription( repo.getDescription( ) );
+ repoConfig.setIndexDir( repo.getIndexDirectory( ) );
return repoConfig;
}
@Override
- public List<org.apache.archiva.admin.model.beans.RemoteRepository> getRemoteRepositories()
+ public List<org.apache.archiva.admin.model.beans.RemoteRepository> getRemoteRepositories( )
throws RepositoryAdminException
{
- return repositoryRegistry.getRemoteRepositories().stream().map( repo -> convertRepo( repo ) ).collect( Collectors.toList());
+ return repositoryRegistry.getRemoteRepositories( ).stream( ).map( repo -> convertRepo( repo ) ).collect( Collectors.toList( ) );
}
@Override
public org.apache.archiva.admin.model.beans.RemoteRepository getRemoteRepository( String repositoryId )
throws RepositoryAdminException
{
- return convertRepo( repositoryRegistry.getRemoteRepository( repositoryId ));
+ return convertRepo( repositoryRegistry.getRemoteRepository( repositoryId ) );
}
@Override
public Boolean addRemoteRepository( org.apache.archiva.admin.model.beans.RemoteRepository remoteRepository, AuditInformation auditInformation )
throws RepositoryAdminException
{
- triggerAuditEvent( remoteRepository.getId(), null, AuditEvent.ADD_REMOTE_REPO, auditInformation );
- getRepositoryCommonValidator().basicValidation( remoteRepository, false );
+ triggerAuditEvent( remoteRepository.getId( ), null, AuditEvent.ADD_REMOTE_REPO, auditInformation );
+ getRepositoryCommonValidator( ).basicValidation( remoteRepository, false );
//TODO we can validate it's a good uri/url
- if ( StringUtils.isEmpty( remoteRepository.getUrl() ) )
+ if ( StringUtils.isEmpty( remoteRepository.getUrl( ) ) )
{
throw new RepositoryAdminException( "url cannot be null" );
}
//MRM-752 - url needs trimming
//MRM-1940 - URL should not end with a slash
- remoteRepository.setUrl( StringUtils.stripEnd(StringUtils.trim( remoteRepository.getUrl() ), "/"));
-
- if (StringUtils.isEmpty(remoteRepository.getCheckPath())) {
- String checkUrl = remoteRepository.getUrl().toLowerCase();
- for (RepositoryCheckPath path : getArchivaConfiguration ().getConfiguration().getArchivaDefaultConfiguration().getDefaultCheckPaths()) {
- log.debug("Checking path for urls: {} <-> {}", checkUrl, path.getUrl());
- if (checkUrl.startsWith(path.getUrl())) {
- remoteRepository.setCheckPath(path.getPath());
+ remoteRepository.setUrl( StringUtils.stripEnd( StringUtils.trim( remoteRepository.getUrl( ) ), "/" ) );
+
+ if ( StringUtils.isEmpty( remoteRepository.getCheckPath( ) ) )
+ {
+ String checkUrl = remoteRepository.getUrl( ).toLowerCase( );
+ for ( RepositoryCheckPath path : getArchivaConfiguration( ).getConfiguration( ).getArchivaDefaultConfiguration( ).getDefaultCheckPaths( ) )
+ {
+ log.debug( "Checking path for urls: {} <-> {}", checkUrl, path.getUrl( ) );
+ if ( checkUrl.startsWith( path.getUrl( ) ) )
+ {
+ remoteRepository.setCheckPath( path.getPath( ) );
break;
}
}
}
- Configuration configuration = getArchivaConfiguration().getConfiguration();
RemoteRepositoryConfiguration remoteRepositoryConfiguration =
getRepositoryConfiguration( remoteRepository );
- log.debug("Adding remote repo {}", remoteRepositoryConfiguration);
+ log.debug( "Adding remote repo {}", remoteRepositoryConfiguration );
try
{
- repositoryRegistry.putRepository( remoteRepositoryConfiguration, configuration );
+ repositoryRegistry.putRepository( remoteRepositoryConfiguration );
}
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()) );
+ 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 );
-
return Boolean.TRUE;
}
triggerAuditEvent( repositoryId, null, AuditEvent.DELETE_REMOTE_REPO, auditInformation );
- Configuration configuration = getArchivaConfiguration().getConfiguration();
+ Configuration configuration = getArchivaConfiguration( ).getConfiguration( );
RemoteRepository repo = repositoryRegistry.getRemoteRepository( repositoryId );
- if (repo==null) {
- throw new RepositoryAdminException( "Could not delete repository "+repositoryId+". The repository does not exist." );
+ if ( repo == null )
+ {
+ throw new RepositoryAdminException( "Could not delete repository " + repositoryId + ". The repository does not exist." );
}
try
{
- repositoryRegistry.removeRepository( repo, configuration );
+ repositoryRegistry.removeRepository( repo );
}
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()) );
+ 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( ) ) );
}
- saveConfiguration( configuration );
-
return Boolean.TRUE;
}
throws RepositoryAdminException
{
- String repositoryId = remoteRepository.getId();
+ String repositoryId = remoteRepository.getId( );
triggerAuditEvent( repositoryId, null, AuditEvent.MODIFY_REMOTE_REPO, auditInformation );
// update means : remove and add
- Configuration configuration = getArchivaConfiguration().getConfiguration();
+ Configuration configuration = getArchivaConfiguration( ).getConfiguration( );
RemoteRepositoryConfiguration remoteRepositoryConfiguration = getRepositoryConfiguration( remoteRepository );
try
{
- repositoryRegistry.putRepository( remoteRepositoryConfiguration, configuration );
+ repositoryRegistry.putRepository( remoteRepositoryConfiguration );
}
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()) );
+ 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( ) ) );
}
- saveConfiguration( configuration );
return Boolean.TRUE;
}
@Override
- public Map<String, org.apache.archiva.admin.model.beans.RemoteRepository> getRemoteRepositoriesAsMap()
+ public Map<String, org.apache.archiva.admin.model.beans.RemoteRepository> getRemoteRepositoriesAsMap( )
throws RepositoryAdminException
{
- java.util.Map<String, org.apache.archiva.admin.model.beans.RemoteRepository> map = new HashMap<>();
-
- for ( org.apache.archiva.admin.model.beans.RemoteRepository repo : getRemoteRepositories() )
- {
- map.put( repo.getId(), repo );
- }
-
- return map;
+ return repositoryRegistry.getRemoteRepositories( ).stream( )
+ .map( r -> convertRepo( r ) )
+ .collect( Collectors.toMap(
+ r -> r.getId( ),
+ r -> r
+ ) );
}
- @Override
- public ArchivaIndexingContext createIndexContext( org.apache.archiva.admin.model.beans.RemoteRepository remoteRepository )
- throws RepositoryAdminException
- {
- RemoteRepository repo = repositoryRegistry.getRemoteRepository(remoteRepository.getId());
- return repo.getIndexingContext();
-
- }
-
-
-
}
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.repository.base.RepositoryHandlerDependencies;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.commons.lang3.StringUtils;
import org.junit.Before;
@SuppressWarnings( "unused" )
@Inject
- ManagedRepositoryHandler managedRepositoryHandler;
-
- @SuppressWarnings( "unused" )
- @Inject
- RepositoryGroupHandler repositoryGroupHandler;
-
+ RepositoryHandlerDependencies repositoryHandlerDependencies;
@Before
public void initialize() {
import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest;
import org.apache.archiva.metadata.model.facets.AuditEvent;
import org.apache.archiva.repository.Repository;
-import org.apache.archiva.repository.RepositoryRegistry;
-import org.apache.archiva.repository.base.group.RepositoryGroupHandler;
-import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler;
import org.junit.Test;
import javax.inject.Inject;
* <li>Instance initialized: </li>
* </ul>
*
+ * The repository handler are not thread safe. Synchronization is done by registry if necessary.
*
* @author Martin Stockhammer <martin_s@apache.org>
*/
*/
void setRepositoryValidator( List<RepositoryValidator<? extends Repository>> repositoryValidatorList );
+ /**
+ * Returns the repository variant, this handler manages.
+ * @return the concrete variant class
+ */
Class<R> getVariant();
+ /**
+ * Returns the repository configuration variant, this handler manages.
+ * @return the concrete configuration variant class
+ */
Class<C> getConfigurationVariant();
}
*/
RepositoryGroup putRepositoryGroup( RepositoryGroupConfiguration repositoryGroupConfiguration, Configuration configuration ) throws RepositoryException;
- /**
- * Adds or updates the given remote repository. If a remote repository with the given id exists already, it is updated
- * from the data of the given instance. Otherwise a new repository is created and updated by the data of the given instance.
- *
- * This method can be used, if the archiva configuration should not be saved. It will only update the given configuration object.
- *
- * @param remoteRepository the remote repository
- * @param configuration the configuration that is updated
- * @return the repository instance, that was created or updated
- * @throws RepositoryException if an error occurred while creating or updating the instance
- */
- RemoteRepository putRepository( RemoteRepository remoteRepository, Configuration configuration ) throws RepositoryException;
-
/**
* Adds or updates the given remote repository. If a remote repository with the given id exists already, it is updated
* from the data of the given instance. Otherwise a new repository is created and updated by the data of the given instance.
@Override
public void deactivateRepository( R repository )
{
-
+ repository.close();
}
@Override
}
+
}
import org.apache.archiva.configuration.ConfigurationListener;
import org.apache.archiva.configuration.IndeterminateConfigurationException;
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
-import org.apache.archiva.configuration.ProxyConnectorConfiguration;
import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
import org.apache.archiva.configuration.RepositoryGroupConfiguration;
import org.apache.archiva.event.Event;
import org.apache.archiva.indexer.IndexCreationFailedException;
import org.apache.archiva.indexer.IndexManagerFactory;
import org.apache.archiva.indexer.IndexUpdateFailedException;
-import org.apache.archiva.repository.EditableManagedRepository;
-import org.apache.archiva.repository.EditableRemoteRepository;
import org.apache.archiva.repository.EditableRepository;
import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.RemoteRepository;
import org.apache.archiva.repository.Repository;
-import org.apache.archiva.repository.RepositoryContentFactory;
import org.apache.archiva.repository.RepositoryException;
import org.apache.archiva.repository.RepositoryGroup;
import org.apache.archiva.repository.RepositoryHandler;
import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.UnsupportedRepositoryTypeException;
-import org.apache.archiva.repository.event.LifecycleEvent;
-import org.apache.archiva.repository.event.RepositoryEvent;
import org.apache.archiva.repository.event.RepositoryIndexEvent;
import org.apache.archiva.repository.event.RepositoryRegistryEvent;
-import org.apache.archiva.repository.features.IndexCreationFeature;
-import org.apache.archiva.repository.features.StagingRepositoryFeature;
import org.apache.archiva.repository.metadata.MetadataReader;
import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.repository.validation.CheckedResult;
import org.apache.archiva.repository.validation.ValidationError;
import org.apache.archiva.repository.validation.ValidationResponse;
import org.apache.commons.collections4.ListUtils;
-import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
-import javax.inject.Named;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@Inject
List<RepositoryProvider> repositoryProviders;
+ @SuppressWarnings( "SpringJavaInjectionPointsAutowiringInspection" )
@Inject
IndexManagerFactory indexManagerFactory;
@Inject
List<RepositoryValidator<? extends Repository>> repositoryValidatorList;
- @Inject
- @Named( "repositoryContentFactory#default" )
- RepositoryContentFactory repositoryContentFactory;
-
-
private boolean ignoreIndexing = false;
private final EventManager eventManager;
- private Map<String, RemoteRepository> remoteRepositories = new HashMap<>( );
- private Map<String, RemoteRepository> uRemoteRepositories = Collections.unmodifiableMap( remoteRepositories );
-
- private ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock( );
+ private final ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock( );
private RepositoryHandler<RepositoryGroup, RepositoryGroupConfiguration> groupHandler;
private RepositoryHandler<ManagedRepository, ManagedRepositoryConfiguration> managedRepositoryHandler;
+ private RepositoryHandler<RemoteRepository, RemoteRepositoryConfiguration> remoteRepositoryHandler;
+
private final Set<RepositoryValidator<? extends Repository>> validators;
private final ConfigurationHandler configurationHandler;
- private AtomicBoolean groups_initalized = new AtomicBoolean( false );
- private AtomicBoolean managed_initialized = new AtomicBoolean( false );
- private AtomicBoolean remote_initialized = new AtomicBoolean( false );
+ private final AtomicBoolean groups_initalized = new AtomicBoolean( false );
+ private final AtomicBoolean managed_initialized = new AtomicBoolean( false );
+ private final AtomicBoolean remote_initialized = new AtomicBoolean( false );
public ArchivaRepositoryRegistry( ConfigurationHandler configurationHandler, List<RepositoryValidator<? extends Repository>> validatorList )
{
log.debug( "Initializing repository registry" );
initializeManagedRepositories();
- updateRemoteRepositoriesFromConfig( );
- pushEvent( new RepositoryRegistryEvent( RepositoryRegistryEvent.REMOTE_REPOS_INITIALIZED, this ) );
- remote_initialized.set( true );
-
+ initializeRemoteRepositories();
initializeRepositoryGroups( );
for ( RepositoryProvider provider : repositoryProviders )
}
}
+ private void initializeRemoteRepositories() {
+ if (this.remoteRepositoryHandler != null ){
+ this.remoteRepositoryHandler.initializeFromConfig( );
+ this.remote_initialized.set( true );
+ pushEvent( new RepositoryRegistryEvent( RepositoryRegistryEvent.REMOTE_REPOS_INITIALIZED, this ) );
+
+ }
+ }
+
public void registerGroupHandler( RepositoryHandler<RepositoryGroup, RepositoryGroupConfiguration> groupHandler )
{
this.groupHandler = groupHandler;
- registerRepositoryHandler( groupHandler );
+ doRegister( groupHandler );
initializeRepositoryGroups( );
if ( managed_initialized.get( ) && remote_initialized.get( ) && groups_initalized.get( ) )
{
public void registerManagedRepositoryHandler( RepositoryHandler<ManagedRepository, ManagedRepositoryConfiguration> managedRepositoryHandler )
{
this.managedRepositoryHandler = managedRepositoryHandler;
- registerRepositoryHandler( managedRepositoryHandler );
+ doRegister( managedRepositoryHandler );
initializeManagedRepositories();
if ( managed_initialized.get( ) && remote_initialized.get( ) && groups_initalized.get( ) )
{
}
}
+ public void registerRemoteRepositoryHandler( RepositoryHandler<RemoteRepository, RemoteRepositoryConfiguration> remoteRepositoryHandler )
+ {
+ this.remoteRepositoryHandler = remoteRepositoryHandler;
+ doRegister( remoteRepositoryHandler );
+ initializeRemoteRepositories();
+ if ( managed_initialized.get( ) && remote_initialized.get( ) && groups_initalized.get( ) )
+ {
+ pushEvent( new RepositoryRegistryEvent( RepositoryRegistryEvent.INITIALIZED, this ) );
+ }
+ }
@PreDestroy
public void destroy( )
{
managedRepositoryHandler.close( );
- for ( RemoteRepository repo : remoteRepositories.values( ) )
- {
- repo.close( );
- }
- remoteRepositories.clear( );
+ remoteRepositoryHandler.close();
groupHandler.close( );
pushEvent( new RepositoryRegistryEvent( RepositoryRegistryEvent.DESTROYED, this ) );
}
return repositoryProviders.stream( ).filter( repositoryProvider -> repositoryProvider.provides( ).contains( type ) ).findFirst( ).orElseThrow( ( ) -> new RepositoryException( "Repository type cannot be handled: " + type ) );
}
- /*
- * Updates the repositories
- */
- private void updateManagedRepositoriesFromConfig( )
- {
- managedRepositoryHandler.initializeFromConfig( );
- }
-
-
- private String getStagingId( String repoId )
- {
- return repoId + StagingRepositoryFeature.STAGING_REPO_POSTFIX;
- }
-
@Override
public ArchivaIndexManager getIndexManager( RepositoryType type )
}
}
- private void createIndexingContext( EditableRepository editableRepo ) throws RepositoryException
- {
- if ( editableRepo.supportsFeature( IndexCreationFeature.class ) )
- {
- ArchivaIndexManager idxManager = getIndexManager( editableRepo.getType( ) );
- try
- {
- editableRepo.setIndexingContext( idxManager.createContext( editableRepo ) );
- idxManager.updateLocalIndexPath( editableRepo );
- }
- catch ( IndexCreationFailedException e )
- {
- throw new RepositoryException( "Could not create index for repository " + editableRepo.getId( ) + ": " + e.getMessage( ), e );
- }
- }
- }
-
-
- private void updateRemoteRepositoriesFromConfig( )
- {
- try
- {
- List<RemoteRepositoryConfiguration> remoteRepoConfigs =
- configurationHandler.getBaseConfiguration( ).getRemoteRepositories( );
-
- if ( remoteRepoConfigs == null )
- {
- return;
- }
- Set<String> repoIds = new HashSet<>( );
- for ( RemoteRepositoryConfiguration repoConfig : remoteRepoConfigs )
- {
- putRepository( repoConfig, null );
- repoIds.add( repoConfig.getId( ) );
- }
-
- List<String> toRemove = remoteRepositories.keySet( ).stream( ).filter( id -> !repoIds.contains( id ) ).collect( Collectors.toList( ) );
- for ( String id : toRemove )
- {
- RemoteRepository removed = remoteRepositories.remove( id );
- removed.close( );
- }
-
- }
- catch ( Throwable e )
- {
- log.error( "Could not initialize remote repositories from config: {}", e.getMessage( ), e );
- return;
- }
- }
-
- private RemoteRepository createNewRemoteRepository( RepositoryProvider provider, RemoteRepositoryConfiguration cfg ) throws RepositoryException
- {
- log.debug( "Creating remote repo {}", cfg.getId( ) );
- RemoteRepository repo = provider.createRemoteInstance( cfg );
- updateRepositoryReferences( provider, repo, cfg, null );
- return repo;
-
- }
-
- private void updateRepositoryReferences( RepositoryProvider provider, RemoteRepository repo, RemoteRepositoryConfiguration cfg, Configuration configuration ) throws RepositoryException
- {
- if ( repo instanceof EditableRemoteRepository && repo.getContent( ) == null )
- {
- EditableRemoteRepository editableRepo = (EditableRemoteRepository) repo;
- editableRepo.setContent( repositoryContentFactory.getRemoteRepositoryContent( repo ) );
- if ( repo.supportsFeature( IndexCreationFeature.class ) && repo.getIndexingContext( ) == null )
- {
- createIndexingContext( editableRepo );
- }
- }
- repo.registerEventHandler( RepositoryEvent.ANY, this );
- }
-
/**
* Returns all repositories that are registered. There is no defined order of the returned repositories.
rwLock.readLock( ).lock( );
try
{
- return Stream.concat( managedRepositoryHandler.getAll().stream( ), remoteRepositories.values( ).stream( ) ).collect( Collectors.toList( ) );
+ return Stream.concat( managedRepositoryHandler.getAll().stream( ), remoteRepositoryHandler.getAll().stream( ) ).collect( Collectors.toList( ) );
}
finally
{
rwLock.readLock( ).lock( );
try
{
- return uRemoteRepositories.values( );
+ return remote_initialized.get() ? remoteRepositoryHandler.getAll( ) : Collections.emptyList();
}
finally
{
log.debug( "Managed repo" );
return managedRepositoryHandler.get( repoId );
}
- else if ( remoteRepositories.containsKey( repoId ) )
+ else if ( remoteRepositoryHandler.hasRepository( repoId ) )
{
log.debug( "Remote repo" );
- return remoteRepositories.get( repoId );
+ return remoteRepositoryHandler.get( repoId );
}
else if ( groupHandler.hasRepository( repoId ) )
{
rwLock.readLock( ).lock( );
try
{
- return remoteRepositories.get( repoId );
+ return remote_initialized.get() ? remoteRepositoryHandler.get( repoId ) : null;
}
finally
{
public boolean hasRepository( String repoId )
{
return ( managedRepositoryHandler != null && managedRepositoryHandler.hasRepository( repoId ) )
- || ( this.remoteRepositories != null && this.remoteRepositories.containsKey( repoId ) )
+ || ( remoteRepositoryHandler != null && remoteRepositoryHandler.hasRepository( repoId ) )
|| ( this.groupHandler != null && groupHandler.hasRepository( repoId ) );
}
@Override
public boolean hasManagedRepository( String repoId )
{
- return managedRepositoryHandler.hasRepository( repoId );
+ return managedRepositoryHandler!=null && managedRepositoryHandler.hasRepository( repoId );
}
@Override
public boolean hasRemoteRepository( String repoId )
{
- return this.remoteRepositories.containsKey( repoId );
+ return remoteRepositoryHandler!=null && remoteRepositoryHandler.hasRepository( repoId );
}
@Override
}
}
- private void replaceOrAddRepositoryConfig( RemoteRepositoryConfiguration remoteRepositoryConfiguration, Configuration configuration )
- {
- if ( configuration != null )
- {
- RemoteRepositoryConfiguration oldCfg = configuration.findRemoteRepositoryById( remoteRepositoryConfiguration.getId( ) );
- if ( oldCfg != null )
- {
- configuration.removeRemoteRepository( oldCfg );
- }
- configuration.addRemoteRepository( remoteRepositoryConfiguration );
- }
- }
-
- @Override
- public RemoteRepository putRepository( RemoteRepository remoteRepository, Configuration configuration ) throws RepositoryException
- {
- rwLock.writeLock( ).lock( );
- try
- {
- final String id = remoteRepository.getId( );
- if ( managedRepositoryHandler.hasRepository( id ) )
- {
- throw new RepositoryException( "There exists a managed repository with id " + id + ". Could not update with remote repository." );
- }
- RemoteRepository originRepo = remoteRepositories.put( id, remoteRepository );
- RemoteRepositoryConfiguration oldCfg = null;
- RemoteRepositoryConfiguration newCfg;
- try
- {
- if ( originRepo != null && originRepo != remoteRepository )
- {
- originRepo.close( );
- }
- final RepositoryProvider provider = getProvider( remoteRepository.getType( ) );
- newCfg = provider.getRemoteConfiguration( remoteRepository );
- updateRepositoryReferences( provider, remoteRepository, newCfg, configuration );
- oldCfg = configuration.findRemoteRepositoryById( id );
- if ( oldCfg != null )
- {
- configuration.removeRemoteRepository( oldCfg );
- }
- configuration.addRemoteRepository( newCfg );
- if ( remoteRepository != originRepo )
- {
- pushEvent( new LifecycleEvent( LifecycleEvent.REGISTERED, this, remoteRepository ) );
- }
- else
- {
- pushEvent( new LifecycleEvent( LifecycleEvent.UPDATED, this, remoteRepository ) );
- }
- return remoteRepository;
- }
- catch ( Exception e )
- {
- // Rollback
- if ( originRepo != null )
- {
- remoteRepositories.put( id, originRepo );
- }
- else
- {
- remoteRepositories.remove( id );
- }
- if ( oldCfg != null )
- {
- RemoteRepositoryConfiguration cfg = configuration.findRemoteRepositoryById( id );
- if ( cfg != null )
- {
- configuration.removeRemoteRepository( cfg );
- configuration.addRemoteRepository( oldCfg );
- }
- }
- log.error( "Error while adding remote repository {}", e.getMessage( ), e );
- throw new RepositoryException( "Could not save the configuration" + ( e.getMessage( ) == null ? "" : ": " + e.getMessage( ) ) );
- }
- }
- finally
- {
- rwLock.writeLock( ).unlock( );
- }
- }
/**
* Adds a remote repository, or overwrites the repository definition with the same id, if it exists already.
rwLock.writeLock( ).lock( );
try
{
- Configuration configuration = configurationHandler.getBaseConfiguration( );
- try
- {
- RemoteRepository repo = putRepository( remoteRepository, configuration );
- saveConfiguration( configuration );
- return repo;
- }
- catch ( RegistryException | IndeterminateConfigurationException e )
- {
- log.error( "Error while saving remote repository {}", e.getMessage( ), e );
- throw new RepositoryException( "Could not save the configuration" + ( e.getMessage( ) == null ? "" : ": " + e.getMessage( ) ) );
- }
+ return remoteRepositoryHandler.put( remoteRepository );
}
finally
{
rwLock.writeLock( ).lock( );
try
{
- final String id = remoteRepositoryConfiguration.getId( );
- final RepositoryType repositoryType = RepositoryType.valueOf( remoteRepositoryConfiguration.getType( ) );
- Configuration configuration = configurationHandler.getBaseConfiguration( );
- RemoteRepository repo = remoteRepositories.get( id );
- RemoteRepositoryConfiguration oldCfg = repo != null ? getProvider( repositoryType ).getRemoteConfiguration( repo ) : null;
- repo = putRepository( remoteRepositoryConfiguration, configuration );
- try
- {
- saveConfiguration( configuration );
- }
- catch ( IndeterminateConfigurationException | RegistryException e )
- {
- if ( oldCfg != null )
- {
- getProvider( repositoryType ).updateRemoteInstance( (EditableRemoteRepository) repo, oldCfg );
- }
- log.error( "Could not save the configuration for repository {}: {}", id, e.getMessage( ), e );
- throw new RepositoryException( "Could not save the configuration for repository " + id + ": " + e.getMessage( ) );
- }
- return repo;
+ return remoteRepositoryHandler.put( remoteRepositoryConfiguration );
}
finally
{
rwLock.writeLock( ).unlock( );
}
-
}
/**
* @throws RepositoryException if the configuration cannot be saved or updated
*/
@Override
- @SuppressWarnings( "unchecked" )
public RemoteRepository putRepository( RemoteRepositoryConfiguration remoteRepositoryConfiguration, Configuration configuration ) throws RepositoryException
{
rwLock.writeLock( ).lock( );
try
{
- final String id = remoteRepositoryConfiguration.getId( );
- final RepositoryType repoType = RepositoryType.valueOf( remoteRepositoryConfiguration.getType( ) );
- RemoteRepository repo;
- boolean registeredNew = false;
- repo = remoteRepositories.get( id );
- if ( repo != null && repo.isOpen( ) )
- {
- if ( repo instanceof EditableRemoteRepository )
- {
- getProvider( repoType ).updateRemoteInstance( (EditableRemoteRepository) repo, remoteRepositoryConfiguration );
- }
- else
- {
- throw new RepositoryException( "The repository is not editable " + id );
- }
- }
- else
- {
- repo = getProvider( repoType ).createRemoteInstance( remoteRepositoryConfiguration );
- remoteRepositories.put( id, repo );
- registeredNew = true;
- }
- updateRepositoryReferences( getProvider( repoType ), repo, remoteRepositoryConfiguration, configuration );
- replaceOrAddRepositoryConfig( remoteRepositoryConfiguration, configuration );
- if ( registeredNew )
- {
- pushEvent( new LifecycleEvent( LifecycleEvent.REGISTERED, this, repo ) );
- }
- else
- {
- pushEvent( new LifecycleEvent( LifecycleEvent.UPDATED, this, repo ) );
- }
- return repo;
+ return remoteRepositoryHandler.put( remoteRepositoryConfiguration, configuration );
}
finally
{
rwLock.writeLock( ).unlock( );
}
-
-
}
@Override
}
}
- private void doRemoveRepo( RemoteRepository repo, Configuration configuration )
- {
- repo.close( );
- RemoteRepositoryConfiguration cfg = configuration.findRemoteRepositoryById( repo.getId( ) );
- if ( cfg != null )
- {
- configuration.removeRemoteRepository( cfg );
- }
- List<ProxyConnectorConfiguration> proxyConnectors = new ArrayList<>( configuration.getProxyConnectors( ) );
- for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors )
- {
- if ( StringUtils.equals( proxyConnector.getTargetRepoId( ), repo.getId( ) ) )
- {
- configuration.removeProxyConnector( proxyConnector );
- }
- }
- }
-
/**
* Removes the remote repository from the registry and configuration.
* The change is saved to the configuration immediately.
return;
}
final String id = remoteRepository.getId( );
- RemoteRepository repo = getRemoteRepository( id );
- if ( repo != null )
+ if ( remoteRepositoryHandler.hasRepository( id ) )
{
rwLock.writeLock( ).lock( );
try
{
- repo = remoteRepositories.remove( id );
- if ( repo != null )
- {
- Configuration configuration = configurationHandler.getBaseConfiguration( );
- doRemoveRepo( repo, configuration );
- saveConfiguration( configuration );
- }
- pushEvent( new LifecycleEvent( LifecycleEvent.UNREGISTERED, this, repo ) );
- }
- catch ( RegistryException | IndeterminateConfigurationException e )
- {
- // Rollback
- log.error( "Could not save config after repository removal: {}", e.getMessage( ), e );
- remoteRepositories.put( repo.getId( ), repo );
- throw new RepositoryException( "Could not save configuration after repository removal: " + e.getMessage( ) );
+ remoteRepositoryHandler.remove( id );
}
finally
{
return;
}
final String id = remoteRepository.getId( );
- RemoteRepository repo = getRemoteRepository( id );
- if ( repo != null )
+ if ( remoteRepositoryHandler.hasRepository( id ) )
{
rwLock.writeLock( ).lock( );
try
{
- repo = remoteRepositories.remove( id );
- if ( repo != null )
- {
- doRemoveRepo( repo, configuration );
- }
- pushEvent( new LifecycleEvent( LifecycleEvent.UNREGISTERED, this, repo ) );
+ remoteRepositoryHandler.remove( id, configuration );
}
finally
{
rwLock.writeLock( ).unlock( );
}
}
-
}
/**
if (isRegisteredId( newId )) {
throw new RepositoryException( "The new id exists already: " + newId );
}
- EditableManagedRepository newRepo = (EditableManagedRepository) managedRepositoryHandler.clone( repo, newId );
- return newRepo;
+ return managedRepositoryHandler.clone( repo, newId );
+ }
+
+ /**
+ * Creates a new repository instance with the same settings as this one. The cloned repository is not
+ * registered or saved to the configuration.
+ *
+ * @param repo The origin repository
+ * @return The cloned repository.
+ */
+ public RemoteRepository clone( RemoteRepository repo, String newId ) throws RepositoryException
+ {
+ if (isRegisteredId( newId )) {
+ throw new RepositoryException( "The new id exists already: " + newId );
+ }
+ return remoteRepositoryHandler.clone( repo, newId );
}
+ @SuppressWarnings( "unchecked" )
@Override
public <T extends Repository> T clone( T repo, String newId ) throws RepositoryException
{
+ if (isRegisteredId( newId )) {
+ throw new RepositoryException( "The new id exists already: " + newId );
+ }
if ( repo instanceof RemoteRepository )
{
- return (T) this.clone( (RemoteRepository) repo, newId );
+ return (T) remoteRepositoryHandler.clone( (RemoteRepository) repo, newId );
}
else if ( repo instanceof ManagedRepository )
{
- return (T) this.clone( (ManagedRepository) repo, newId );
+ return (T) managedRepositoryHandler.clone( (ManagedRepository) repo, newId );
+ }
+ else if (repo instanceof RepositoryGroup) {
+ return (T) groupHandler.clone( (RepositoryGroup) repo, newId );
}
else
{
}
}
- /**
- * Creates a new repository instance with the same settings as this one. The cloned repository is not
- * registered or saved to the configuration.
- *
- * @param repo The origin repository
- * @return The cloned repository.
- */
- public RemoteRepository clone( RemoteRepository repo, String newId ) throws RepositoryException
- {
- if ( isRegisteredId( newId ) )
- {
- throw new RepositoryException( "The given id exists already " + newId );
- }
- RepositoryProvider provider = getProvider( repo.getType( ) );
- RemoteRepositoryConfiguration cfg = provider.getRemoteConfiguration( repo );
- cfg.setId( newId );
- RemoteRepository cloned = provider.createRemoteInstance( cfg );
- cloned.registerEventHandler( RepositoryEvent.ANY, this );
- return cloned;
- }
@Override
public Repository getRepositoryOfAsset( StorageAsset asset )
@Override
public <R extends Repository> ValidationResponse<R> validateRepository( R repository )
{
- Map<String, List<ValidationError>> errorMap = this.validators.stream( )
+ @SuppressWarnings( "unchecked" ) Map<String, List<ValidationError>> errorMap = this.validators.stream( )
.filter( ( validator ) -> validator.getType( ).equals( RepositoryType.ALL ) || repository.getType( ).equals( validator.getType( ) ) )
.filter( val -> val.isFlavour( repository.getClass( ) ) )
.flatMap( validator -> ( (RepositoryValidator<R>) validator ).apply( repository ).getResult( ).entrySet( ).stream( ) )
.collect( Collectors.toMap(
- entry -> entry.getKey( ),
- entry -> entry.getValue( ),
- ( list1, list2 ) -> ListUtils.union( list1, list2 )
+ Map.Entry::getKey,
+ Map.Entry::getValue,
+ ListUtils::union
) );
- return new ValidationResponse( repository, errorMap );
+ return new ValidationResponse<>( repository, errorMap );
}
@Override
public <R extends Repository> ValidationResponse<R> validateRepositoryForUpdate( R repository )
{
- Map<String, List<ValidationError>> errorMap = this.validators.stream( )
+ @SuppressWarnings( "unchecked" ) Map<String, List<ValidationError>> errorMap = this.validators.stream( )
.filter( ( validator ) -> validator.getType( ).equals( RepositoryType.ALL ) || repository.getType( ).equals( validator.getType( ) ) )
.filter( val -> val.isFlavour( repository.getClass( ) ) )
.flatMap( validator -> ( (RepositoryValidator<R>) validator ).applyForUpdate( repository ).getResult( ).entrySet( ).stream( ) )
.collect( Collectors.toMap(
- entry -> entry.getKey( ),
- entry -> entry.getValue( ),
- ( list1, list2 ) -> ListUtils.union( list1, list2 )
+ Map.Entry::getKey,
+ Map.Entry::getValue,
+ ListUtils::union
) );
- return new ValidationResponse( repository, errorMap );
+ return new ValidationResponse<>( repository, errorMap );
}
@Override
{
if (!ignoreIndexing && !( event.getRepository() instanceof ManagedRepository ))
{
- RepositoryIndexEvent idxEvent = event;
- EditableRepository repo = (EditableRepository) idxEvent.getRepository( );
+ EditableRepository repo = (EditableRepository) event.getRepository( );
if ( repo != null )
{
ArchivaIndexManager idxmgr = getIndexManager( repo.getType( ) );
eventManager.fireEvent( event );
}
- private <R extends Repository, C extends AbstractRepositoryConfiguration> void registerRepositoryHandler( RepositoryHandler<R, C> repositoryHandler )
+ private <R extends Repository, C extends AbstractRepositoryConfiguration> void doRegister( RepositoryHandler<R, C> repositoryHandler )
{
repositoryHandler.setRepositoryProviders( this.repositoryProviders );
repositoryHandler.setRepositoryValidator( this.repositoryValidatorList );
}
+ @SuppressWarnings( "unchecked" )
@Override
public void registerHandler( RepositoryHandler<?, ?> handler )
{
{
registerManagedRepositoryHandler( (RepositoryHandler<ManagedRepository, ManagedRepositoryConfiguration>) handler );
}
+ else if ( handler.getVariant().isAssignableFrom( RemoteRepository.class )) {
+ registerRemoteRepositoryHandler( (RepositoryHandler<RemoteRepository, RemoteRepositoryConfiguration>) handler );
+ }
}
@Override
return hasRepository( id );
}
+ @SuppressWarnings( "unchecked" )
@Override
public <R extends Repository, C extends AbstractRepositoryConfiguration> RepositoryHandler<R, C> getHandler( Class<R> repositoryClazz, Class<C> configurationClazz )
{
{
return (RepositoryHandler<R, C>) this.managedRepositoryHandler;
}
+ else if ( repositoryClazz.isAssignableFrom( RemoteRepository.class )) {
+ return (RepositoryHandler<R, C>) this.remoteRepositoryHandler;
+ }
else
{
return null;
--- /dev/null
+package org.apache.archiva.repository.base;
+/*
+ * 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.
+ */
+
+import org.apache.archiva.repository.base.group.RepositoryGroupHandler;
+import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler;
+import org.apache.archiva.repository.base.remote.RemoteRepositoryHandler;
+import org.springframework.stereotype.Service;
+
+import javax.inject.Inject;
+
+/**
+ * This is just a class that pulls the handler dependencies. It is used by test classes.
+ *
+ * @author Martin Stockhammer <martin_s@apache.org>
+ */
+@Service()
+public class RepositoryHandlerDependencies
+{
+ @Inject
+ ManagedRepositoryHandler managedRepositoryHandler;
+
+ @Inject
+ RemoteRepositoryHandler remoteRepositoryHandler;
+
+ @Inject
+ RepositoryGroupHandler repositoryGroupHandler;
+}
import org.apache.archiva.repository.RepositoryHandler;
import org.apache.archiva.repository.RepositoryHandlerManager;
import org.apache.archiva.repository.RepositoryProvider;
-import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.repository.RepositoryState;
import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.base.AbstractRepositoryHandler;
implements RepositoryHandler<ManagedRepository, ManagedRepositoryConfiguration>
{
private static final Logger log = LoggerFactory.getLogger( ManagedRepositoryHandler.class );
- private final RepositoryHandlerManager repositoryRegistry;
+ private final RepositoryHandlerManager repositoryHandlerManager;
private final RepositoryContentFactory repositoryContentFactory;
IndexManagerFactory indexManagerFactory;
- public ManagedRepositoryHandler( RepositoryHandlerManager repositoryRegistry,
+ public ManagedRepositoryHandler( RepositoryHandlerManager repositoryHandlerManager,
ConfigurationHandler configurationHandler, IndexManagerFactory indexManagerFactory,
@Named( "repositoryContentFactory#default" )
RepositoryContentFactory repositoryContentFactory
)
{
super( ManagedRepository.class, ManagedRepositoryConfiguration.class, configurationHandler );
- this.repositoryRegistry = repositoryRegistry;
+ this.repositoryHandlerManager = repositoryHandlerManager;
this.indexManagerFactory = indexManagerFactory;
this.repositoryContentFactory = repositoryContentFactory;
}
@PostConstruct
public void init( )
{
- log.debug( "Initializing managed repository handler " + repositoryRegistry.toString( ) );
+ log.debug( "Initializing repository handler " + ManagedRepositoryHandler.class );
initializeStorage( );
// We are registering this class on the registry. This is necessary to avoid circular dependencies via injection.
- this.repositoryRegistry.registerHandler( this );
+ this.repositoryHandlerManager.registerHandler( this );
}
private void initializeStorage( )
for ( ManagedRepositoryConfiguration repoConfig : managedRepoConfigs )
{
String id = repoConfig.getId( );
+ if (result.containsKey( id )) {
+ log.error( "There are repositories with the same id in the configuration: {}", id );
+ continue;
+ }
ManagedRepository repo;
if ( currentInstances.containsKey( id ) )
{
{
throw new RepositoryException( "Could not create repository '" + id + "': " + e.getMessage( ) );
}
- repo.registerEventHandler( RepositoryEvent.ANY, repositoryRegistry );
+ repo.registerEventHandler( RepositoryEvent.ANY, repositoryHandlerManager );
updateReferences( repo, null );
repo.setLastState( RepositoryState.REFERENCES_SET );
return repo;
throw new RepositoryException( "Provider not found for repository type: " + repositoryConfiguration.getType( ) );
}
final ManagedRepository repo = provider.createManagedInstance( repositoryConfiguration );
- repo.registerEventHandler( RepositoryEvent.ANY, repositoryRegistry );
+ repo.registerEventHandler( RepositoryEvent.ANY, repositoryHandlerManager );
updateReferences( repo, null );
if ( repo instanceof EditableRepository )
{
}
@Override
- public ManagedRepository put( ManagedRepository managedRepository ) throws RepositoryException
+ public ManagedRepository put( ManagedRepository repository ) throws RepositoryException
{
- final String id = managedRepository.getId( );
+ final String id = repository.getId( );
ManagedRepository originRepo = getRepositories( ).remove( id );
- if ( originRepo == null && repositoryRegistry.isRegisteredId( id ) )
+ if ( originRepo == null && repositoryHandlerManager.isRegisteredId( id ) )
{
throw new RepositoryException( "There exists a repository with id " + id + ". Could not update with managed repository." );
}
try
{
- if ( originRepo != null && managedRepository != originRepo )
+ if ( originRepo != null && repository != originRepo )
{
deactivateRepository( originRepo );
pushEvent( LifecycleEvent.UNREGISTERED, originRepo );
}
- RepositoryProvider provider = getProvider( managedRepository.getType( ) );
- ManagedRepositoryConfiguration newCfg = provider.getManagedConfiguration( managedRepository );
+ RepositoryProvider provider = getProvider( repository.getType( ) );
+ ManagedRepositoryConfiguration newCfg = provider.getManagedConfiguration( repository );
getConfigurationHandler( ).getLock( ).writeLock( ).lock( );
try
{
Configuration configuration = getConfigurationHandler( ).getBaseConfiguration( );
- updateReferences( managedRepository, newCfg );
+ updateReferences( repository, newCfg );
ManagedRepositoryConfiguration oldCfg = configuration.findManagedRepositoryById( id );
if ( oldCfg != null )
{
}
configuration.addManagedRepository( newCfg );
getConfigurationHandler( ).save( configuration, ConfigurationHandler.REGISTRY_EVENT_TAG );
- setLastState( managedRepository, RepositoryState.SAVED );
- activateRepository( managedRepository );
+ setLastState( repository, RepositoryState.SAVED );
+ activateRepository( repository );
}
finally
{
getConfigurationHandler( ).getLock( ).writeLock( ).unlock( );
}
- getRepositories( ).put( id, managedRepository );
- setLastState( managedRepository, RepositoryState.REGISTERED );
- return managedRepository;
+ getRepositories( ).put( id, repository );
+ setLastState( repository, RepositoryState.REGISTERED );
+ return repository;
}
catch ( Exception e )
{
@Override
- public ManagedRepository put( ManagedRepositoryConfiguration managedRepositoryConfiguration ) throws RepositoryException
+ public ManagedRepository put( ManagedRepositoryConfiguration repositoryConfiguration ) throws RepositoryException
{
- final String id = managedRepositoryConfiguration.getId( );
- final RepositoryType repositoryType = RepositoryType.valueOf( managedRepositoryConfiguration.getType( ) );
+ final String id = repositoryConfiguration.getId( );
+ final RepositoryType repositoryType = RepositoryType.valueOf( repositoryConfiguration.getType( ) );
final RepositoryProvider provider = getProvider( repositoryType );
ReentrantReadWriteLock.WriteLock configLock = this.getConfigurationHandler( ).getLock( ).writeLock( );
configLock.lock( );
oldRepository = repo == null ? null : clone( repo, id );
if ( repo == null )
{
- repo = put( managedRepositoryConfiguration, configuration );
+ repo = put( repositoryConfiguration, configuration );
}
else
{
- setManagedRepositoryDefaults( managedRepositoryConfiguration );
- provider.updateManagedInstance( (EditableManagedRepository) repo, managedRepositoryConfiguration );
+ setRepositoryDefaults( repositoryConfiguration );
+ provider.updateManagedInstance( (EditableManagedRepository) repo, repositoryConfiguration );
updated = true;
pushEvent( LifecycleEvent.UPDATED, repo );
}
- registerNewRepository( managedRepositoryConfiguration, repo, configuration, updated );
+ registerNewRepository( repositoryConfiguration, repo, configuration, updated );
}
catch ( IndeterminateConfigurationException | RegistryException e )
{
final String id = repositoryConfiguration.getId( );
final RepositoryType repoType = RepositoryType.valueOf( repositoryConfiguration.getType( ) );
ManagedRepository repo;
- setManagedRepositoryDefaults( repositoryConfiguration );
+ setRepositoryDefaults( repositoryConfiguration );
if ( getRepositories( ).containsKey( id ) )
{
repo = clone( getRepositories( ).get( id ), id );
}
@SuppressWarnings( "unused" )
- private void setManagedRepositoryDefaults( ManagedRepositoryConfiguration repositoryConfiguration )
+ private void setRepositoryDefaults( ManagedRepositoryConfiguration repositoryConfiguration )
{
// We do nothing here
}
ManagedRepositoryConfiguration cfg = provider.getManagedConfiguration( repo );
cfg.setId( id );
ManagedRepository cloned = provider.createManagedInstance( cfg );
- cloned.registerEventHandler( RepositoryEvent.ANY, repositoryRegistry );
+ cloned.registerEventHandler( RepositoryEvent.ANY, repositoryHandlerManager );
setLastState( cloned, RepositoryState.CREATED );
return cloned;
}
createIndexingContext( editableRepo );
}
}
- repo.registerEventHandler( RepositoryEvent.ANY, repositoryRegistry );
+ repo.registerEventHandler( RepositoryEvent.ANY, repositoryHandlerManager );
}
- @Override
- public void close( )
- {
- getRepositories( ).values( ).stream( ).forEach(
- r -> deactivateRepository( r )
- );
- }
-
- @Override
- public void deactivateRepository( ManagedRepository repository )
- {
- repository.close( );
- }
}
import org.apache.archiva.common.filelock.DefaultFileLockManager;
import org.apache.archiva.common.filelock.FileLockManager;
+import org.apache.archiva.repository.EditableRemoteRepository;
import org.apache.archiva.repository.ReleaseScheme;
import org.apache.archiva.repository.RepositoryCapabilities;
import org.apache.archiva.repository.RepositoryState;
import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.StandardCapabilities;
-import org.apache.archiva.repository.storage.fs.FilesystemStorage;
-import org.apache.archiva.repository.storage.RepositoryStorage;
import org.apache.archiva.repository.features.IndexCreationFeature;
import org.apache.archiva.repository.features.RemoteIndexFeature;
+import org.apache.archiva.repository.storage.RepositoryStorage;
+import org.apache.archiva.repository.storage.fs.FilesystemStorage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*
*
*/
-public class BasicRemoteRepository extends AbstractRemoteRepository
+public class BasicRemoteRepository extends AbstractRemoteRepository implements EditableRemoteRepository
{
Logger log = LoggerFactory.getLogger(BasicRemoteRepository.class);
--- /dev/null
+package org.apache.archiva.repository.base.remote;
+/*
+ * 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.
+ */
+
+import org.apache.archiva.components.registry.Registry;
+import org.apache.archiva.components.scheduler.CronExpressionValidator;
+import org.apache.archiva.repository.RemoteRepository;
+import org.apache.archiva.repository.RepositoryRegistry;
+import org.apache.archiva.repository.base.ConfigurationHandler;
+import org.apache.archiva.repository.validation.AbstractRepositoryValidator;
+import org.apache.archiva.repository.validation.RepositoryValidator;
+import org.apache.archiva.repository.validation.ValidationError;
+import org.apache.archiva.repository.validation.ValidationResponse;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import static org.apache.archiva.repository.validation.ErrorKeys.*;
+
+/**
+ * Validator for remote repository data.
+ *
+ * @author Martin Stockhammer <martin_s@apache.org>
+ */
+@Service( "repositoryValidator#common#remote" )
+public class BasicRemoteRepositoryValidator extends AbstractRepositoryValidator<RemoteRepository> implements RepositoryValidator<RemoteRepository>
+{
+ RepositoryRegistry repositoryRegistry;
+ private static final String CATEGORY = "remote_repository";
+ private static final Pattern REPOSITORY_ID_VALID_EXPRESSION_PATTERN = Pattern.compile( REPOSITORY_ID_VALID_EXPRESSION );
+ private static final Pattern REPOSITORY_NAME_VALID_EXPRESSION_PATTERN = Pattern.compile( REPOSITORY_NAME_VALID_EXPRESSION );
+ private static final Pattern REPOSITORY_LOCATION_VALID_EXPRESSION_PATTERN = Pattern.compile( REPOSITORY_LOCATION_VALID_EXPRESSION );
+
+ private final ConfigurationHandler configurationHandler;
+
+
+ public BasicRemoteRepositoryValidator( ConfigurationHandler configurationHandler)
+ {
+ super( CATEGORY );
+ this.configurationHandler = configurationHandler;
+ }
+
+ @Override
+ public ValidationResponse<RemoteRepository> apply( RemoteRepository repository, boolean update )
+ {
+ Map<String, List<ValidationError>> errors = null;
+ if (repository==null) {
+ errors = appendError( errors, "object", ISNULL );
+ return new ValidationResponse<>( repository, errors );
+ }
+ final String repoId = repository.getId( );
+ if ( StringUtils.isBlank( repoId ) ) {
+ errors = appendError( errors, "id", ISEMPTY );
+ }
+
+ if (!update)
+ {
+ if ( repositoryRegistry.hasManagedRepository( repository.getId( ) ) )
+ {
+ errors = appendError( errors, "id", MANAGED_REPOSITORY_EXISTS, repoId );
+ }
+ else if ( repositoryRegistry.hasRemoteRepository( repoId ) )
+ {
+ errors = appendError( errors, "id", REMOTE_REPOSITORY_EXISTS, repoId );
+ }
+ else if ( repositoryRegistry.hasRepositoryGroup( repoId ) )
+ {
+ errors = appendError( errors, "id", REPOSITORY_GROUP_EXISTS, repoId );
+ }
+ }
+
+ if ( !REPOSITORY_ID_VALID_EXPRESSION_PATTERN.matcher( repoId ).matches( ) )
+ {
+ errors = appendError( errors, "id", INVALID_CHARS, repoId, REPOSITORY_ID_ALLOWED );
+ }
+ if ( StringUtils.isBlank( repository.getName() ) )
+ {
+ errors = appendError( errors, "name", ISEMPTY );
+ } else if ( !REPOSITORY_NAME_VALID_EXPRESSION_PATTERN.matcher( repository.getName( ) ).matches( ) )
+ {
+ errors = appendError( errors, "name", INVALID_CHARS, repository.getName( ), REPOSITORY_NAME_ALLOWED );
+ }
+
+ String cronExpression = repository.getSchedulingDefinition( );
+ if ( StringUtils.isNotBlank( cronExpression ) )
+ {
+ CronExpressionValidator validator = new CronExpressionValidator( );
+
+ if ( !validator.validate( cronExpression ) )
+ {
+ errors = appendError( errors, "scheduling_definition", INVALID_SCHEDULING_EXPRESSION, cronExpression );
+ }
+ }
+ // Cron expression may be empty
+
+ String repoLocation = interpolateVars( repository.getLocation( ).toString() );
+
+ if ( !REPOSITORY_LOCATION_VALID_EXPRESSION_PATTERN.matcher( repoLocation ).matches() )
+ {
+ errors = appendError( errors, "location", INVALID_LOCATION, repoLocation, new String[]{"alphanumeric", "=", "?", "!", "&", "/", "\\", "_", ".", ":", "~", "-"} );
+ }
+
+ return new ValidationResponse<>( repository, errors );
+ }
+
+ public String interpolateVars( String directory )
+ {
+ Registry registry = configurationHandler.getArchivaConfiguration( ).getRegistry( );
+ String value = StringUtils.replace( directory, "${appserver.base}",
+ registry.getString( "appserver.base", "${appserver.base}" ) );
+ value = StringUtils.replace( value, "${appserver.home}",
+ registry.getString( "appserver.home", "${appserver.home}" ) );
+ return value;
+ }
+
+
+ @Override
+ public void setRepositoryRegistry( RepositoryRegistry repositoryRegistry )
+ {
+ this.repositoryRegistry = repositoryRegistry;
+ }
+
+ @Override
+ public Class<RemoteRepository> getFlavour( )
+ {
+ return RemoteRepository.class;
+ }
+
+}
--- /dev/null
+package org.apache.archiva.repository.base.remote;
+/*
+ * 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.
+ */
+
+import org.apache.archiva.components.registry.RegistryException;
+import org.apache.archiva.configuration.Configuration;
+import org.apache.archiva.configuration.IndeterminateConfigurationException;
+import org.apache.archiva.configuration.ProxyConnectorConfiguration;
+import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
+import org.apache.archiva.indexer.ArchivaIndexManager;
+import org.apache.archiva.indexer.IndexCreationFailedException;
+import org.apache.archiva.indexer.IndexManagerFactory;
+import org.apache.archiva.repository.EditableRemoteRepository;
+import org.apache.archiva.repository.EditableRepository;
+import org.apache.archiva.repository.RemoteRepository;
+import org.apache.archiva.repository.RepositoryContentFactory;
+import org.apache.archiva.repository.RepositoryException;
+import org.apache.archiva.repository.RepositoryHandler;
+import org.apache.archiva.repository.RepositoryHandlerManager;
+import org.apache.archiva.repository.RepositoryProvider;
+import org.apache.archiva.repository.RepositoryState;
+import org.apache.archiva.repository.RepositoryType;
+import org.apache.archiva.repository.base.AbstractRepositoryHandler;
+import org.apache.archiva.repository.base.ConfigurationHandler;
+import org.apache.archiva.repository.event.LifecycleEvent;
+import org.apache.archiva.repository.event.RepositoryEvent;
+import org.apache.archiva.repository.features.IndexCreationFeature;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import javax.inject.Named;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+/**
+ * @author Martin Stockhammer <martin_s@apache.org>
+ */
+@Service( "remoteRepositoryHandler#default" )
+public class RemoteRepositoryHandler extends AbstractRepositoryHandler<RemoteRepository, RemoteRepositoryConfiguration> implements RepositoryHandler<RemoteRepository, RemoteRepositoryConfiguration>
+{
+ private static final Logger log = LoggerFactory.getLogger( RemoteRepositoryHandler.class );
+ private final RepositoryHandlerManager repositoryHandlerManager;
+ private final RepositoryContentFactory repositoryContentFactory;
+ private final IndexManagerFactory indexManagerFactory;
+
+
+ public RemoteRepositoryHandler( RepositoryHandlerManager repositoryHandlerManager, ConfigurationHandler configurationHandler,
+ IndexManagerFactory indexManagerFactory,
+ @Named( "repositoryContentFactory#default" ) RepositoryContentFactory repositoryContentFactory )
+ {
+ super( RemoteRepository.class, RemoteRepositoryConfiguration.class, configurationHandler );
+ this.repositoryHandlerManager = repositoryHandlerManager;
+ this.repositoryContentFactory = repositoryContentFactory;
+ this.indexManagerFactory = indexManagerFactory;
+ }
+
+ @Override
+ @PostConstruct
+ public void init( )
+ {
+ log.debug( "Initializing repository handler " + RemoteRepositoryHandler.class );
+ initializeStorage( );
+ // We are registering this class on the registry. This is necessary to avoid circular dependencies via injection.
+ this.repositoryHandlerManager.registerHandler( this );
+ }
+
+ private void initializeStorage( )
+ {
+
+ }
+
+ @Override
+ public void initializeFromConfig( )
+ {
+ Map<String, RemoteRepository> currentInstances = new HashMap<>( getRepositories( ) );
+ getRepositories().clear();
+ Map<String, RemoteRepository> newAndUpdated = newOrUpdateInstancesFromConfig( currentInstances );
+ getRepositories( ).putAll( newAndUpdated );
+ currentInstances.entrySet( ).stream( ).filter( entry -> !newAndUpdated.containsKey( entry.getKey( ) ) ).forEach(
+ r ->
+ deactivateRepository( r.getValue() )
+ );
+ for ( RemoteRepository remoteRepository : getRepositories( ).values( ) )
+ {
+ activateRepository( remoteRepository );
+ }
+
+
+ }
+
+ public Map<String, RemoteRepository> newOrUpdateInstancesFromConfig( Map<String, RemoteRepository> currentInstances)
+ {
+ try
+ {
+ List<RemoteRepositoryConfiguration> remoteRepoConfigs =
+ new ArrayList<>(
+ getConfigurationHandler( ).getBaseConfiguration( ).getRemoteRepositories( ) );
+
+ if ( remoteRepoConfigs == null )
+ {
+ return Collections.emptyMap( );
+ }
+
+ Map<String, RemoteRepository> result = new HashMap<>( );
+ for ( RemoteRepositoryConfiguration repoConfig : remoteRepoConfigs )
+ {
+ String id = repoConfig.getId( );
+ if (result.containsKey( id )) {
+ log.error( "There are repositories with the same id in the configuration: {}", id );
+ continue;
+ }
+ RemoteRepository repo;
+ if ( currentInstances.containsKey( id ) )
+ {
+ repo = currentInstances.remove( id );
+ getProvider( repo.getType( ) ).updateRemoteInstance( (EditableRemoteRepository) repo, repoConfig );
+ updateReferences( repo, repoConfig );
+ }
+ else
+ {
+ repo = newInstance( repoConfig );
+ }
+ result.put( id, repo );
+ }
+ return result;
+ }
+ catch ( Throwable e )
+ {
+ log.error( "Could not initialize repositories from config: {}", e.getMessage( ), e );
+ return new HashMap<>( );
+ }
+ }
+
+
+ @Override
+ public Map<String, RemoteRepository> newInstancesFromConfig( )
+ {
+ try
+ {
+ List<RemoteRepositoryConfiguration> remoteRepoConfigs =
+ new ArrayList<>(
+ getConfigurationHandler( ).getBaseConfiguration( ).getRemoteRepositories( ) );
+
+ if ( remoteRepoConfigs == null )
+ {
+ return Collections.emptyMap( );
+ }
+
+ Map<String, RemoteRepository> result = new HashMap<>( );
+ for ( RemoteRepositoryConfiguration repoConfig : remoteRepoConfigs )
+ {
+ RemoteRepository repo = newInstance( repoConfig );
+ result.put( repo.getId( ), repo );
+ }
+ return result;
+ }
+ catch ( Throwable e )
+ {
+ log.error( "Could not initialize repositories from config: {}", e.getMessage( ), e );
+ return new HashMap<>( );
+ }
+ }
+
+ @Override
+ public RemoteRepository newInstance( RepositoryType type, String id ) throws RepositoryException
+ {
+ log.debug( "Creating repo {}", id );
+ RepositoryProvider provider = getProvider( type );
+ EditableRemoteRepository repo;
+ repo = provider.createRemoteInstance( id, id );
+ repo.registerEventHandler( RepositoryEvent.ANY, repositoryHandlerManager );
+ updateReferences( repo, null );
+ repo.setLastState( RepositoryState.REFERENCES_SET );
+ return repo;
+
+ }
+
+
+ @Override
+ public RemoteRepository newInstance( RemoteRepositoryConfiguration repositoryConfiguration ) throws RepositoryException
+ {
+ RepositoryType type = RepositoryType.valueOf( repositoryConfiguration.getType( ) );
+ RepositoryProvider provider = getProvider( type );
+ if ( provider == null )
+ {
+ throw new RepositoryException( "Provider not found for repository type: " + repositoryConfiguration.getType( ) );
+ }
+ final RemoteRepository repo = provider.createRemoteInstance( repositoryConfiguration );
+ repo.registerEventHandler( RepositoryEvent.ANY, repositoryHandlerManager );
+ updateReferences( repo, null );
+ if ( repo instanceof EditableRepository )
+ {
+ ( (EditableRepository) repo ).setLastState( RepositoryState.REFERENCES_SET );
+ }
+ return repo;
+ }
+
+ @Override
+ protected RemoteRepositoryConfiguration findRepositoryConfiguration( Configuration configuration, String id )
+ {
+ return configuration.findRemoteRepositoryById( id );
+ }
+
+ @Override
+ protected void removeRepositoryConfiguration( Configuration configuration, RemoteRepositoryConfiguration repoConfiguration )
+ {
+ configuration.removeRemoteRepository( repoConfiguration );
+ List<ProxyConnectorConfiguration> proxyConnectors = new ArrayList<>( configuration.getProxyConnectors( ) );
+ for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors )
+ {
+ if ( StringUtils.equals( proxyConnector.getTargetRepoId( ), repoConfiguration.getId( ) ) )
+ {
+ configuration.removeProxyConnector( proxyConnector );
+ }
+ }
+ }
+
+ @Override
+ protected void addRepositoryConfiguration( Configuration configuration, RemoteRepositoryConfiguration repoConfiguration )
+ {
+ configuration.addRemoteRepository( repoConfiguration );
+
+ }
+
+
+
+ @Override
+ public RemoteRepository put( RemoteRepository repository ) throws RepositoryException
+ {
+ final String id = repository.getId( );
+ RemoteRepository originRepo = getRepositories( ).remove( id );
+ if ( originRepo == null && repositoryHandlerManager.isRegisteredId( id ) )
+ {
+ throw new RepositoryException( "There exists a repository with id " + id + ". Could not update with managed repository." );
+ }
+ try
+ {
+ if ( originRepo != null && repository != originRepo )
+ {
+ deactivateRepository( originRepo );
+ pushEvent( LifecycleEvent.UNREGISTERED, originRepo );
+ }
+ RepositoryProvider provider = getProvider( repository.getType( ) );
+ RemoteRepositoryConfiguration newCfg = provider.getRemoteConfiguration( repository );
+ getConfigurationHandler( ).getLock( ).writeLock( ).lock( );
+ try
+ {
+ Configuration configuration = getConfigurationHandler( ).getBaseConfiguration( );
+ updateReferences( repository, newCfg );
+ RemoteRepositoryConfiguration oldCfg = configuration.findRemoteRepositoryById( id );
+ if ( oldCfg != null )
+ {
+ configuration.removeRemoteRepository( oldCfg );
+ }
+ configuration.addRemoteRepository( newCfg );
+ getConfigurationHandler( ).save( configuration, ConfigurationHandler.REGISTRY_EVENT_TAG );
+ setLastState( repository, RepositoryState.SAVED );
+ activateRepository( repository );
+ }
+ finally
+ {
+ getConfigurationHandler( ).getLock( ).writeLock( ).unlock( );
+ }
+ getRepositories( ).put( id, repository );
+ setLastState( repository, RepositoryState.REGISTERED );
+ return repository;
+ }
+ catch ( Exception e )
+ {
+ // Rollback only partly, because repository is closed already
+ if ( originRepo != null )
+ {
+ getRepositories( ).put( id, originRepo );
+ }
+ else
+ {
+ getRepositories( ).remove( id );
+ }
+ log.error( "Exception during configuration update {}", e.getMessage( ), e );
+ throw new RepositoryException( "Could not save the configuration" + ( e.getMessage( ) == null ? "" : ": " + e.getMessage( ) ) );
+ }
+
+ }
+
+ @Override
+ public RemoteRepository put( RemoteRepositoryConfiguration repositoryConfiguration ) throws RepositoryException
+ {
+ final String id = repositoryConfiguration.getId( );
+ final RepositoryType repositoryType = RepositoryType.valueOf( repositoryConfiguration.getType( ) );
+ final RepositoryProvider provider = getProvider( repositoryType );
+ ReentrantReadWriteLock.WriteLock configLock = this.getConfigurationHandler( ).getLock( ).writeLock( );
+ configLock.lock( );
+ RemoteRepository repo = null;
+ RemoteRepository oldRepository = null;
+ Configuration configuration = null;
+ try
+ {
+ boolean updated = false;
+ configuration = getConfigurationHandler( ).getBaseConfiguration( );
+ repo = getRepositories( ).get( id );
+ oldRepository = repo == null ? null : clone( repo, id );
+ if ( repo == null )
+ {
+ repo = put( repositoryConfiguration, configuration );
+ }
+ else
+ {
+ setRepositoryDefaults( repositoryConfiguration );
+ provider.updateRemoteInstance( (EditableRemoteRepository) repo, repositoryConfiguration );
+ updated = true;
+ pushEvent( LifecycleEvent.UPDATED, repo );
+ }
+ registerNewRepository( repositoryConfiguration, repo, configuration, updated );
+ }
+ catch ( IndeterminateConfigurationException | RegistryException e )
+ {
+ if ( oldRepository != null )
+ {
+ RemoteRepositoryConfiguration oldCfg = provider.getRemoteConfiguration( oldRepository );
+ provider.updateRemoteInstance( (EditableRemoteRepository) repo, oldCfg );
+ rollback( configuration, oldRepository, e, oldCfg );
+ }
+ else
+ {
+ getRepositories( ).remove( id );
+ }
+ log.error( "Could not save the configuration for repository {}: {}", id, e.getMessage( ), e );
+ throw new RepositoryException( "Could not save the configuration for repository " + id + ": " + e.getMessage( ) );
+ }
+ finally
+ {
+ configLock.unlock( );
+ }
+ return repo;
+
+ }
+
+ @SuppressWarnings( "unused" )
+ private void setRepositoryDefaults( RemoteRepositoryConfiguration repositoryConfiguration )
+ {
+ // We do nothing here
+ }
+
+
+ @Override
+ public RemoteRepository put( RemoteRepositoryConfiguration repositoryConfiguration, Configuration configuration ) throws RepositoryException
+ {
+ final String id = repositoryConfiguration.getId( );
+ final RepositoryType repoType = RepositoryType.valueOf( repositoryConfiguration.getType( ) );
+ RemoteRepository repo;
+ setRepositoryDefaults( repositoryConfiguration );
+ if ( getRepositories( ).containsKey( id ) )
+ {
+ repo = clone( getRepositories( ).get( id ), id );
+ if ( repo instanceof EditableRemoteRepository )
+ {
+ getProvider( repoType ).updateRemoteInstance( (EditableRemoteRepository) repo, repositoryConfiguration );
+ }
+ else
+ {
+ throw new RepositoryException( "The repository is not editable " + id );
+ }
+ }
+ else
+ {
+ repo = getProvider( repoType ).createRemoteInstance( repositoryConfiguration );
+ setLastState( repo, RepositoryState.CREATED );
+ }
+ if ( configuration != null )
+ {
+ replaceOrAddRepositoryConfig( repositoryConfiguration, configuration );
+ }
+ updateReferences( repo, repositoryConfiguration );
+ setLastState( repo, RepositoryState.REFERENCES_SET );
+ return repo;
+
+ }
+
+ @Override
+ public RemoteRepository clone( RemoteRepository repo, String newId ) throws RepositoryException
+ {
+ RepositoryProvider provider = getProvider( repo.getType( ) );
+ RemoteRepositoryConfiguration cfg = provider.getRemoteConfiguration( repo );
+ cfg.setId( newId );
+ RemoteRepository cloned = provider.createRemoteInstance( cfg );
+ cloned.registerEventHandler( RepositoryEvent.ANY, repositoryHandlerManager );
+ setLastState( cloned, RepositoryState.CREATED );
+ return cloned;
+
+ }
+
+ @Override
+ public void updateReferences( RemoteRepository repo, RemoteRepositoryConfiguration repositoryConfiguration ) throws RepositoryException
+ {
+ if ( repo instanceof EditableRemoteRepository && repo.getContent( ) == null )
+ {
+ EditableRemoteRepository editableRepo = (EditableRemoteRepository) repo;
+ editableRepo.setContent( repositoryContentFactory.getRemoteRepositoryContent( repo ) );
+ if ( repo.supportsFeature( IndexCreationFeature.class ) && repo.getIndexingContext( ) == null )
+ {
+ createIndexingContext( editableRepo );
+ }
+ }
+ repo.registerEventHandler( RepositoryEvent.ANY, repositoryHandlerManager );
+
+ }
+
+ private void createIndexingContext( EditableRepository editableRepo ) throws RepositoryException
+ {
+ if ( editableRepo.supportsFeature( IndexCreationFeature.class ) )
+ {
+ ArchivaIndexManager idxManager = getIndexManager( editableRepo.getType( ) );
+ try
+ {
+ editableRepo.setIndexingContext( idxManager.createContext( editableRepo ) );
+ idxManager.updateLocalIndexPath( editableRepo );
+ }
+ catch ( IndexCreationFailedException e )
+ {
+ throw new RepositoryException( "Could not create index for repository " + editableRepo.getId( ) + ": " + e.getMessage( ), e );
+ }
+ }
+ }
+
+ public ArchivaIndexManager getIndexManager( RepositoryType type )
+ {
+ return indexManagerFactory.getIndexManager( type );
+ }
+
+}
import org.apache.archiva.repository.base.managed.BasicManagedRepository;
import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler;
import org.apache.archiva.repository.base.remote.BasicRemoteRepository;
+import org.apache.archiva.repository.base.remote.RemoteRepositoryHandler;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
@Inject
ManagedRepositoryHandler managedRepositoryHandler;
+ @Inject
+ RemoteRepositoryHandler remoteRepositoryHandler;
+
private static final Path userCfg = Paths.get(System.getProperty( "user.home" ), ".m2/archiva.xml");
private static Path cfgCopy;
cfg.setId("central");
cfg.setName("This is central test 002");
repo = repositoryRegistry.putRepository( cfg );
- assertSame( internalRepo, repo );
assertEquals("This is central test 002",repo.getName());
assertEquals(2, repositoryRegistry.getRemoteRepositories().size());
{
Configuration configuration = archivaConfiguration.getConfiguration();
RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration();
+ Configuration newConfiguration = new Configuration( );
+
cfg.setId("test002");
cfg.setName("This is test 002");
- RemoteRepository repo = repositoryRegistry.putRepository( cfg, configuration );
+ RemoteRepository repo = repositoryRegistry.putRepository( cfg, newConfiguration );
assertNotNull(repo);
assertEquals("test002", repo.getId());
assertEquals("This is test 002", repo.getName());
archivaConfiguration.reload();
assertEquals(1, archivaConfiguration.getConfiguration().getRemoteRepositories().size());
Collection<RemoteRepository> repos = repositoryRegistry.getRemoteRepositories();
- assertEquals(2, repos.size());
+ assertEquals(1, repos.size());
+ assertEquals( 1, newConfiguration.getRemoteRepositories( ).size( ) );
RemoteRepository internalRepo = repositoryRegistry.getRemoteRepository( "central" );
cfg = new RemoteRepositoryConfiguration();
cfg.setId("central");
cfg.setName("This is central test 002");
- repo = repositoryRegistry.putRepository( cfg, configuration );
- assertSame( internalRepo, repo );
+ repo = repositoryRegistry.putRepository( cfg, newConfiguration );
assertEquals("This is central test 002",repo.getName());
- assertEquals(2, repositoryRegistry.getRemoteRepositories().size());
+ assertEquals( 2, newConfiguration.getRemoteRepositories( ).size( ) );
repositoryRegistry.reload();
assertEquals(1, repositoryRegistry.getRemoteRepositories().size());
import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.repository.base.ConfigurationHandler;
import org.apache.archiva.repository.base.managed.BasicManagedRepository;
-import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler;
+import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
import org.apache.archiva.repository.mock.ManagedRepositoryContentMock;
import org.apache.archiva.repository.validation.ValidationResponse;
import org.junit.jupiter.api.AfterEach;
@Inject
RepositoryGroupHandler repositoryGroupHandler;
+ @SuppressWarnings( "unused" )
@Inject
- ManagedRepositoryHandler managedRepositoryHandler;
+ RepositoryHandlerDependencies repositoryHandlerDependencies;
Path repoBaseDir;
import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.Configuration;
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
import org.apache.archiva.configuration.RepositoryGroupConfiguration;
import org.apache.archiva.indexer.merger.MergedRemoteIndexesScheduler;
import org.apache.archiva.repository.EditableRepositoryGroup;
import org.apache.archiva.repository.ManagedRepository;
+import org.apache.archiva.repository.RemoteRepository;
import org.apache.archiva.repository.RepositoryException;
import org.apache.archiva.repository.RepositoryGroup;
import org.apache.archiva.repository.RepositoryHandler;
import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
import org.apache.archiva.repository.base.ConfigurationHandler;
import org.apache.archiva.repository.base.managed.BasicManagedRepository;
+import org.apache.archiva.repository.base.remote.BasicRemoteRepository;
import org.apache.archiva.repository.storage.fs.FilesystemStorage;
import org.apache.archiva.repository.validation.CheckedResult;
import org.apache.archiva.repository.validation.ValidationError;
@Mock
RepositoryHandler<ManagedRepository, ManagedRepositoryConfiguration> managedRepositoryHandler;
+ @Mock
+ RepositoryHandler<RemoteRepository, RemoteRepositoryConfiguration> remoteRepositoryHandler;
+
@Inject
ArchivaConfiguration archivaConfiguration;
}
Mockito.when( managedRepositoryHandler.get( ArgumentMatchers.eq("internal") ) ).thenReturn( internalRepo );
repositoryRegistry.registerHandler( managedRepositoryHandler );
+
+ Mockito.when( remoteRepositoryHandler.getVariant( ) ).thenReturn( RemoteRepository.class );
+ final RemoteRepository centralRepo;
+ try
+ {
+ centralRepo = getRemote( "central", "central");
+ }
+ catch ( IOException e )
+ {
+ throw new Error( e );
+ }
+ repositoryRegistry.registerHandler( remoteRepositoryHandler );
+
+
RepositoryGroupHandler groupHandler = new RepositoryGroupHandler( repositoryRegistry, configurationHandler, mergedRemoteIndexesScheduler);
groupHandler.init( );
return groupHandler;
return new BasicManagedRepository( id, name, storage );
}
+ protected RemoteRepository getRemote(String id, String name) throws IOException
+ {
+ Path path = getRepoBaseDir().resolve( "../remote" );
+ FileLockManager lockManager = new DefaultFileLockManager();
+ FilesystemStorage storage = new FilesystemStorage(path.toAbsolutePath(), lockManager);
+ return new BasicRemoteRepository( id, name, storage );
+ }
+
protected EditableRepositoryGroup createRepository( String id, String name, Path location ) throws IOException
{
--- /dev/null
+package org.apache.archiva.repository.base.remote;
+
+/*
+ * 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.
+ */
+
+import org.apache.archiva.common.filelock.DefaultFileLockManager;
+import org.apache.archiva.common.filelock.FileLockManager;
+import org.apache.archiva.repository.EditableManagedRepository;
+import org.apache.archiva.repository.EditableRemoteRepository;
+import org.apache.archiva.repository.EditableRepository;
+import org.apache.archiva.repository.ManagedRepository;
+import org.apache.archiva.repository.RemoteRepository;
+import org.apache.archiva.repository.RepositoryException;
+import org.apache.archiva.repository.RepositoryRegistry;
+import org.apache.archiva.repository.base.ConfigurationHandler;
+import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
+import org.apache.archiva.repository.base.group.RepositoryGroupHandler;
+import org.apache.archiva.repository.base.managed.BasicManagedRepository;
+import org.apache.archiva.repository.base.managed.BasicManagedRepositoryValidator;
+import org.apache.archiva.repository.mock.ManagedRepositoryContentMock;
+import org.apache.archiva.repository.mock.RemoteRepositoryContentMock;
+import org.apache.archiva.repository.storage.fs.FilesystemStorage;
+import org.apache.archiva.repository.validation.ValidationResponse;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+
+import javax.inject.Inject;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+/**
+ * @author Martin Stockhammer <martin_s@apache.org>
+ */
+@ExtendWith( SpringExtension.class)
+@ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" })
+class BasicRemoteRepositoryValidatorTest
+{
+
+ @Inject
+ ConfigurationHandler configurationHandler;
+
+ @Inject
+ RepositoryRegistry repositoryRegistry;
+
+ @Inject
+ RepositoryHandlerDependencies repositoryHandlerDependencies;
+
+ Path repoBaseDir;
+
+ @AfterEach
+ void cleanup() {
+ try
+ {
+ repositoryRegistry.removeRepository( "test" );
+ }
+ catch ( RepositoryException e )
+ {
+ // Ignore this
+ }
+
+ }
+
+ protected EditableRemoteRepository createRepository( String id, String name, Path location ) throws IOException
+ {
+ FileLockManager lockManager = new DefaultFileLockManager();
+ FilesystemStorage storage = new FilesystemStorage(location.toAbsolutePath(), lockManager);
+ BasicRemoteRepository repo = new BasicRemoteRepository(id, name, storage);
+ repo.setLocation( location.toAbsolutePath().toUri());
+ repo.setContent(new RemoteRepositoryContentMock());
+ return repo;
+ }
+
+ private Path getRepoBaseDir() {
+ if (repoBaseDir==null) {
+ try
+ {
+ repoBaseDir = Paths.get(Thread.currentThread( ).getContextClassLoader( ).getResource( "repositories" ).toURI());
+ }
+ catch ( URISyntaxException e )
+ {
+ throw new RuntimeException( "Could not retrieve repository base directory" );
+ }
+ }
+ return repoBaseDir;
+ }
+
+
+ @Test
+ void apply( ) throws IOException
+ {
+ BasicRemoteRepositoryValidator validator = new BasicRemoteRepositoryValidator( configurationHandler );
+ validator.setRepositoryRegistry( repositoryRegistry );
+ Path repoDir = getRepoBaseDir().resolve("test" );
+ EditableRemoteRepository repo = createRepository( "test", "test", repoDir );
+ ValidationResponse<RemoteRepository> result = validator.apply( repo );
+ assertTrue( result.isValid( ) );
+ }
+
+ @Test
+ void applyWithExistingRepo( ) throws IOException, RepositoryException
+ {
+ BasicRemoteRepositoryValidator validator = new BasicRemoteRepositoryValidator( configurationHandler );
+ validator.setRepositoryRegistry( repositoryRegistry );
+ Path repoDir = getRepoBaseDir().resolve("test" );
+ EditableRemoteRepository repo = createRepository( "test", "test", repoDir );
+ Path repoDir2 = getRepoBaseDir().resolve("test2" );
+ EditableRemoteRepository repo2 = createRepository( "test", "test", repoDir2 );
+ repositoryRegistry.putRepository( repo );
+ ValidationResponse<RemoteRepository> result = validator.apply( repo );
+ assertFalse( result.isValid( ) );
+ assertEquals( 1, result.getResult( ).size( ) );
+ assertTrue( result.getResult( ).containsKey( "id" ) );
+ assertEquals( "remote_repository", result.getResult( ).get( "id" ).get( 0 ).getCategory( ) );
+ assertEquals( "remote_repo_exists", result.getResult( ).get( "id" ).get( 0 ).getType( ) );
+ assertEquals( "id", result.getResult( ).get( "id" ).get( 0 ).getAttribute() );
+ }
+
+ @Test
+ void applyUpdateWithExistingRepo( ) throws IOException, RepositoryException
+ {
+ BasicRemoteRepositoryValidator validator = new BasicRemoteRepositoryValidator( configurationHandler );
+ validator.setRepositoryRegistry( repositoryRegistry );
+ Path repoDir = getRepoBaseDir().resolve("test" );
+ EditableRemoteRepository repo = createRepository( "test", "test", repoDir );
+ Path repoDir2 = getRepoBaseDir().resolve("test2" );
+ EditableRemoteRepository repo2 = createRepository( "test", "test", repoDir2 );
+ repositoryRegistry.putRepository( repo );
+ ValidationResponse<RemoteRepository> result = validator.applyForUpdate( repo );
+ assertTrue( result.isValid( ) );
+ assertEquals( 0, result.getResult( ).size( ) );
+ }
+
+ @Test
+ void applyWithNullObject( ) throws IOException
+ {
+ BasicRemoteRepositoryValidator validator = new BasicRemoteRepositoryValidator( configurationHandler );
+ validator.setRepositoryRegistry( repositoryRegistry );
+ ValidationResponse<RemoteRepository> result = validator.apply( null );
+ assertFalse( result.isValid( ) );
+ assertEquals( 1, result.getResult( ).size( ) );
+ assertTrue( result.getResult( ).containsKey( "object" ) );
+ assertEquals( "remote_repository", result.getResult( ).get( "object" ).get( 0 ).getCategory( ) );
+ assertEquals( "isnull", result.getResult( ).get( "object" ).get( 0 ).getType( ) );
+ assertEquals( "object", result.getResult( ).get( "object" ).get( 0 ).getAttribute() );
+ }
+
+ @Test
+ void applyWithEmptyId( ) throws IOException
+ {
+ BasicRemoteRepositoryValidator validator = new BasicRemoteRepositoryValidator( configurationHandler );
+ validator.setRepositoryRegistry( repositoryRegistry );
+ Path repoDir = getRepoBaseDir().resolve("test" );
+ EditableRemoteRepository repo = createRepository( "", "test", repoDir );
+ ValidationResponse<RemoteRepository> result = validator.apply( repo );
+ assertFalse( result.isValid( ) );
+ assertEquals( 1, result.getResult( ).size( ) );
+ assertTrue( result.getResult( ).containsKey( "id" ) );
+ assertEquals( "remote_repository", result.getResult( ).get( "id" ).get( 0 ).getCategory( ) );
+ assertEquals( "empty", result.getResult( ).get( "id" ).get( 0 ).getType( ) );
+ assertEquals( "id", result.getResult( ).get( "id" ).get( 0 ).getAttribute() );
+ }
+
+ @Test
+ void applyWithBadName( ) throws IOException
+ {
+ BasicRemoteRepositoryValidator validator = new BasicRemoteRepositoryValidator( configurationHandler );
+ validator.setRepositoryRegistry( repositoryRegistry );
+ Path repoDir = getRepoBaseDir().resolve("test" );
+ EditableRemoteRepository repo = createRepository( "test", "badtest\\name", repoDir );
+ ValidationResponse<RemoteRepository> result = validator.apply( repo );
+ assertFalse( result.isValid( ) );
+ assertEquals( 1, result.getResult( ).size( ) );
+ assertEquals( "invalid_chars", result.getResult( ).get( "name" ).get( 0 ).getType( ) );
+ }
+
+ @Test
+ void applyWithBadSchedulingExpression( ) throws IOException
+ {
+ BasicRemoteRepositoryValidator validator = new BasicRemoteRepositoryValidator( configurationHandler );
+ validator.setRepositoryRegistry( repositoryRegistry );
+ Path repoDir = getRepoBaseDir().resolve("test" );
+ EditableRemoteRepository repo = createRepository( "test", "test", repoDir );
+ repo.setSchedulingDefinition( "xxxxx" );
+ ValidationResponse<RemoteRepository> result = validator.apply( repo );
+ assertFalse( result.isValid( ) );
+ assertEquals( 1, result.getResult( ).size( ) );
+ assertEquals( "invalid_scheduling_exp", result.getResult( ).get( "scheduling_definition" ).get( 0 ).getType( ) );
+ }
+
+ @Test
+ void applyForUpdate( )
+ {
+ }
+
+ @Test
+ void getFlavour( )
+ {
+ BasicRemoteRepositoryValidator validator = new BasicRemoteRepositoryValidator( configurationHandler );
+ validator.setRepositoryRegistry( repositoryRegistry );
+ assertEquals( RemoteRepository.class, validator.getFlavour( ) );
+ }
+
+ @Test
+ void isFlavour( )
+ {
+ BasicRemoteRepositoryValidator validator = new BasicRemoteRepositoryValidator( configurationHandler );
+ validator.setRepositoryRegistry( repositoryRegistry );
+ assertTrue( validator.isFlavour( RemoteRepository.class ) );
+ assertTrue( validator.isFlavour( BasicRemoteRepository.class ) );
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.apache.archiva.repository.base.remote;
+
+/*
+ * 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.
+ */
+
+import org.apache.archiva.common.filelock.DefaultFileLockManager;
+import org.apache.archiva.common.filelock.FileLockManager;
+import org.apache.archiva.common.utils.FileUtils;
+import org.apache.archiva.configuration.ArchivaConfiguration;
+import org.apache.archiva.configuration.Configuration;
+import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
+import org.apache.archiva.indexer.IndexManagerFactory;
+import org.apache.archiva.repository.EditableRemoteRepository;
+import org.apache.archiva.repository.RemoteRepository;
+import org.apache.archiva.repository.Repository;
+import org.apache.archiva.repository.RepositoryContentFactory;
+import org.apache.archiva.repository.RepositoryException;
+import org.apache.archiva.repository.RepositoryState;
+import org.apache.archiva.repository.RepositoryType;
+import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
+import org.apache.archiva.repository.base.ConfigurationHandler;
+import org.apache.archiva.repository.storage.fs.FilesystemStorage;
+import org.apache.archiva.repository.validation.CheckedResult;
+import org.apache.archiva.repository.validation.RepositoryValidator;
+import org.apache.archiva.repository.validation.ValidationError;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.archiva.repository.validation.ErrorKeys.ISEMPTY;
+import static org.junit.jupiter.api.Assertions.*;
+
+/**
+ * @author Martin Stockhammer <martin_s@apache.org>
+ */
+@ExtendWith( {MockitoExtension.class, SpringExtension.class} )
+@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-remote.xml"} )
+class RemoteRepositoryHandlerTest
+{
+ static {
+ initialize();
+ }
+
+ @Inject
+ @Named( "repositoryRegistry" )
+ ArchivaRepositoryRegistry repositoryRegistry;
+
+ @Inject
+ @Named( "repositoryContentFactory#default" )
+ RepositoryContentFactory repositoryContentFactory;
+
+ @Inject
+ IndexManagerFactory indexManagerFactory;
+
+ @Inject
+ ConfigurationHandler configurationHandler;
+
+ @SuppressWarnings( "unused" )
+ @Inject
+ List<RepositoryValidator<? extends Repository>> repositoryValidatorList;
+
+ @Inject
+ ArchivaConfiguration archivaConfiguration;
+
+ Path repoBaseDir;
+
+
+ private static void initialize() {
+ Path baseDir = Paths.get( FileUtils.getBasedir( ) );
+ Path config = baseDir.resolve( "src/test/resources/archiva-remote.xml" );
+ if ( Files.exists( config ) )
+ {
+ Path destConfig = baseDir.resolve( "target/test-classes/archiva-remote.xml" );
+ try
+ {
+ Files.copy( config, destConfig );
+ }
+ catch ( IOException e )
+ {
+ System.err.println( "Could not copy file: " + e.getMessage( ) );
+ }
+ }
+ }
+
+ // Helper method that removes a repo from the configuration
+ private void removeRepositoryFromConfig( String id) {
+ Configuration configuration = configurationHandler.getBaseConfiguration( );
+ Iterator<RemoteRepositoryConfiguration> iter = configuration.getRemoteRepositories().iterator();
+ while(iter.hasNext()) {
+ RemoteRepositoryConfiguration repo = iter.next( );
+ if (id.equals(repo.getId())) {
+ iter.remove();
+ break;
+ }
+ }
+ try
+ {
+ configurationHandler.save( configuration );
+ }
+ catch ( Throwable e )
+ {
+ System.err.println( "Could not remove repo from config "+id );
+ }
+ }
+
+ private boolean hasRepositoryInConfig( String id) {
+ assertNotNull( configurationHandler.getBaseConfiguration( ).getRemoteRepositories() );
+ return configurationHandler.getBaseConfiguration( ).getRemoteRepositories( ).stream( ).anyMatch( g -> g != null && id.equals( g.getId( ) ) ) ;
+ }
+
+
+ private RemoteRepositoryHandler createHandler( )
+ {
+ RemoteRepositoryHandler repositoryHandler = new RemoteRepositoryHandler( repositoryRegistry, configurationHandler, indexManagerFactory, repositoryContentFactory );
+ repositoryHandler.init( );
+ return repositoryHandler;
+ }
+
+ private Path getRepoBaseDir() throws IOException
+ {
+ if (repoBaseDir==null) {
+ this.repoBaseDir = archivaConfiguration.getRepositoryBaseDir( ).resolve( "remote" );
+ Files.createDirectories( this.repoBaseDir );
+ }
+ return repoBaseDir;
+ }
+
+ protected EditableRemoteRepository createRepository( String id, String name, Path location ) throws IOException
+ {
+ FileLockManager lockManager = new DefaultFileLockManager();
+ FilesystemStorage storage = new FilesystemStorage(location.toAbsolutePath(), lockManager);
+ BasicRemoteRepository repo = new BasicRemoteRepository(id, name, storage);
+ repo.setLocation( location.toAbsolutePath().toUri());
+ return repo;
+ }
+
+ protected EditableRemoteRepository createRepository( String id, String name) throws IOException
+ {
+ Path dir = getRepoBaseDir( ).resolve( id );
+ Files.createDirectories( dir );
+ return createRepository( id, name, dir );
+ }
+
+
+
+
+ @Test
+ void initializeFromConfig( )
+ {
+ RemoteRepositoryHandler repoHandler = createHandler( );
+ repoHandler.initializeFromConfig( );
+ assertEquals( 2, repoHandler.getAll( ).size( ) );
+ assertNotNull( repoHandler.get( "test-repo-01" ) );
+ assertEquals( "Test Remote Repository", repoHandler.get( "test-repo-01" ).getName() );
+ }
+
+ @Test
+ void activateRepository( ) throws RepositoryException
+ {
+ String id = "test-repo-02";
+ RemoteRepositoryHandler repoHandler = createHandler( );
+ RemoteRepository repo = repoHandler.newInstance( RepositoryType.MAVEN, id );
+ repoHandler.activateRepository( repo );
+ assertFalse( hasRepositoryInConfig( id ));
+ assertNull( repoHandler.get( id ) );
+ }
+
+ @Test
+ void newInstancesFromConfig( ) throws RepositoryException
+ {
+ final String id = "test-repo-01";
+ RemoteRepositoryHandler repoHandler = createHandler( );
+ Configuration configuration = new Configuration( );
+ repoHandler.remove( "test-repo-01", configuration );
+ Map<String, RemoteRepository> instances = repoHandler.newInstancesFromConfig( );
+ assertFalse( repoHandler.hasRepository( id ) );
+ assertTrue( instances.containsKey( id ) );
+ assertEquals( RepositoryState.REFERENCES_SET, instances.get( id ).getLastState( ) );
+ }
+
+ @Test
+ void newInstance( ) throws RepositoryException
+ {
+ String id = "test-repo-03";
+ RemoteRepositoryHandler repoHandler = createHandler( );
+ RemoteRepository instance = repoHandler.newInstance( RepositoryType.MAVEN, id );
+ assertNotNull( instance );
+ assertEquals( id, instance.getId( ) );
+ assertFalse( repoHandler.hasRepository( id ) );
+ assertEquals( RepositoryState.REFERENCES_SET, instance.getLastState( ) );
+ assertFalse( hasRepositoryInConfig( id ) );
+ }
+
+
+ @Test
+ void put( ) throws IOException, RepositoryException
+ {
+ final String id = "test-repo-04";
+ try
+ {
+ RemoteRepositoryHandler repoHandler = createHandler( );
+ EditableRemoteRepository repository = createRepository( id, "n-"+id );
+ repoHandler.put( repository );
+ RemoteRepository storedRepository = repoHandler.get( id );
+ assertNotNull( storedRepository );
+ assertEquals( id, storedRepository.getId( ) );
+ assertEquals( "n-"+id, storedRepository.getName( ) );
+
+ EditableRemoteRepository repository2 = createRepository( id, "n2-"+id );
+ repoHandler.put( repository2 );
+ storedRepository = repoHandler.get( id );
+ assertNotNull( storedRepository );
+ assertEquals( id, storedRepository.getId( ) );
+ assertEquals( "n2-"+id, storedRepository.getName( ) );
+
+ assertTrue( hasRepositoryInConfig( id ));
+ } finally {
+ removeRepositoryFromConfig( id );
+ }
+ }
+
+ @Test
+ void putWithConfiguration( ) throws RepositoryException
+ {
+ String id = "test-repo-05";
+
+ try
+ {
+ RemoteRepositoryHandler repoHandler = createHandler( );
+ RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration( );
+ configuration.setId( id );
+ configuration.setName( "n-" + id );
+ repoHandler.put( configuration );
+
+ RemoteRepository repo = repoHandler.get( id );
+ assertNotNull( repo );
+ assertEquals( id, repo.getId( ) );
+ assertEquals( "n-" + id, repo.getName( ) );
+ assertTrue( hasRepositoryInConfig( id ) );
+ }
+ finally
+ {
+ removeRepositoryFromConfig( id );
+ }
+ }
+
+ @Test
+ void testPutWithoutRegister( ) throws RepositoryException
+ {
+ final String id = "test-repo-06";
+ RemoteRepositoryHandler repoHandler = createHandler( );
+ Configuration aCfg = new Configuration( );
+ RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration( );
+ configuration.setId( id );
+ configuration.setName( "n-"+id );
+ repoHandler.put( configuration, aCfg );
+
+ RemoteRepository repo = repoHandler.get( id );
+ assertNull( repo );
+ assertFalse( hasRepositoryInConfig( id ) );
+ assertTrue( aCfg.getRemoteRepositories( ).stream( ).anyMatch( g -> g!=null && id.equals( g.getId( ) ) ) );
+
+ }
+
+ @Test
+ void putWithCheck_invalid( ) throws RepositoryException
+ {
+ final String id = "test-repo-07";
+ final String name = "n-"+id;
+ try
+ {
+ RemoteRepositoryHandler repoHandler = createHandler( );
+ BasicRemoteRepositoryValidator checker = new BasicRemoteRepositoryValidator( configurationHandler );
+ checker.setRepositoryRegistry( repositoryRegistry );
+ RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration();
+ configuration.setId( "" );
+ configuration.setName( name );
+ CheckedResult<RemoteRepository, Map<String, List<ValidationError>>> result = repoHandler.putWithCheck( configuration, checker );
+ assertNull( repoHandler.get( id ) );
+ assertNotNull( result.getResult( ) );
+ assertNotNull( result.getResult( ).get( "id" ) );
+ assertEquals( 2, result.getResult( ).get( "id" ).size( ) );
+ assertEquals( ISEMPTY, result.getResult( ).get( "id" ).get( 0 ).getType( ) );
+ assertFalse( hasRepositoryInConfig( id ) );
+ assertFalse( hasRepositoryInConfig( "" ) );
+ } finally
+ {
+ removeRepositoryFromConfig( id );
+ }
+ }
+
+ @Test
+ void remove( ) throws RepositoryException
+ {
+ final String id = "test-repo-08";
+ RemoteRepositoryHandler repoHandler = createHandler( );
+ RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration( );
+ configuration.setId( id );
+ configuration.setName( "n-"+id );
+ repoHandler.put( configuration );
+ assertTrue( hasRepositoryInConfig( id ) );
+ assertNotNull( repoHandler.get( id ) );
+ repoHandler.remove( id );
+ assertNull( repoHandler.get( id ) );
+ assertFalse( hasRepositoryInConfig( id ) );
+ }
+
+ @Test
+ void removeWithoutSave( ) throws RepositoryException
+ {
+ final String id = "test-repo-09";
+ RemoteRepositoryHandler repoHandler = createHandler( );
+ Configuration aCfg = new Configuration( );
+ RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration( );
+ configuration.setId( id );
+ configuration.setName( "n-"+id );
+ repoHandler.put( configuration, aCfg );
+ assertTrue( aCfg.getRemoteRepositories( ).stream( ).anyMatch( g -> g != null && id.equals( g.getId( ) ) ) );
+ repoHandler.remove( id, aCfg );
+ assertNull( repoHandler.get( id ) );
+ assertTrue( aCfg.getRemoteRepositories( ).stream( ).noneMatch( g -> g != null && id.equals( g.getId( ) ) ) );
+ assertNull( repoHandler.get( id ) );
+
+ }
+
+
+ @Test
+ void validateRepository( ) throws IOException
+ {
+ final String id = "test-repo-10";
+ RemoteRepositoryHandler repoHandler = createHandler( );
+ EditableRemoteRepository repository = createRepository( id, "n-"+id );
+ CheckedResult<RemoteRepository, Map<String, List<ValidationError>>> result = repoHandler.validateRepository( repository );
+ assertNotNull( result );
+ assertEquals( 0, result.getResult( ).size( ) );
+
+ repository = createRepository( id, "n-test-repo-10###" );
+ result = repoHandler.validateRepository( repository );
+ assertNotNull( result );
+ assertEquals( 1, result.getResult( ).size( ) );
+ assertNotNull( result.getResult().get( "name" ) );
+
+ }
+
+ @Test
+ void validateRepositoryIfExisting( ) throws IOException, RepositoryException
+ {
+ final String id = "test-repo-11";
+ try
+ {
+ RemoteRepositoryHandler repoHandler = createHandler( );
+ EditableRemoteRepository repository = createRepository( id, "n-" + id );
+ repoHandler.put( repository );
+ CheckedResult<RemoteRepository, Map<String, List<ValidationError>>> result = repoHandler.validateRepository( repository );
+ assertNotNull( result );
+ assertEquals( 1, result.getResult( ).size( ) );
+ } finally
+ {
+ removeRepositoryFromConfig( id );
+ }
+
+ }
+
+ @Test
+ void validateRepositoryForUpdate( ) throws IOException, RepositoryException
+ {
+ final String id = "test-repo-12";
+ try
+ {
+ RemoteRepositoryHandler repoHandler = createHandler( );
+ EditableRemoteRepository repository = createRepository( id, "n-" + id );
+ repoHandler.put( repository );
+ CheckedResult<RemoteRepository, Map<String, List<ValidationError>>> result = repoHandler.validateRepositoryForUpdate( repository );
+ assertNotNull( result );
+ assertEquals( 0, result.getResult( ).size( ) );
+ } finally
+ {
+ removeRepositoryFromConfig( id );
+ }
+ }
+
+ @Test
+ void has( ) throws IOException, RepositoryException
+ {
+ final String id = "test-repo-13";
+ try
+ {
+ RemoteRepositoryHandler repoHandler = createHandler( );
+ EditableRemoteRepository repository = createRepository( id, "n-" + id );
+ assertFalse( repoHandler.hasRepository( id ) );
+ repoHandler.put( repository );
+ assertTrue( repoHandler.hasRepository( id ) );
+ } finally
+ {
+ removeRepositoryFromConfig( id );
+ }
+ }
+
+}
\ No newline at end of file
--- /dev/null
+<?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>
+ <description>This is internal repository.</description>
+ <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>staging</id>
+ <name>Repository with staging</name>
+ <description>This is repository with staging.</description>
+ <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>
+ <stageRepoNeeded>true</stageRepoNeeded>
+ </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>
+ <timeout>35</timeout>
+ </remoteRepository>
+ <remoteRepository>
+ <id>test-repo-01</id>
+ <name>Test Remote Repository</name>
+ <url>https://repo.maven.apache.org/maven2</url>
+ <layout>default</layout>
+ <timeout>35</timeout>
+ </remoteRepository>
+ </remoteRepositories>
+ <repositoryGroups>
+ <repositoryGroup>
+ <id>test-group-01</id>
+ <name>Test Group 01</name>
+ <type>MAVEN</type>
+ <repositories>
+ <repository>internal</repository>
+ </repositories>
+ </repositoryGroup>
+ </repositoryGroups>
+
+ <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>
--- /dev/null
+<?xml version="1.0"?>
+
+<!--
+ ~ 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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context.xsd"
+ default-lazy-init="true">
+
+ <context:annotation-config/>
+ <context:component-scan base-package="org.apache.archiva.repository.mock"/>
+
+
+ <bean name="commons-configuration" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
+ <property name="initialConfiguration">
+ <value>
+ <![CDATA[
+ <configuration>
+ <system/>
+ <xml fileName="archiva-remote.xml" config-forceCreate="true"
+ config-optional="true"
+ config-name="org.apache.archiva.base" config-at="org.apache.archiva"/>
+ </configuration>
+ ]]>
+ </value>
+ </property>
+ </bean>
+
+
+ <bean name="taskScheduler#mergeRemoteIndexes"
+ class="org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler">
+ <property name="poolSize" value="4"/>
+ <property name="threadGroupName" value="mergeRemoteIndexes"/>
+ </bean>
+
+
+</beans>
\ No newline at end of file
import org.apache.archiva.common.utils.FileUtils;
import org.apache.archiva.indexer.ArchivaIndexingContext;
import org.apache.archiva.indexer.IndexCreationFailedException;
-import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
import org.apache.archiva.repository.RepositoryType;
-import org.apache.archiva.repository.base.group.RepositoryGroupHandler;
-import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler;
+import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
+import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
import org.apache.archiva.repository.features.IndexCreationFeature;
import org.apache.archiva.repository.features.RemoteIndexFeature;
import org.apache.archiva.repository.maven.MavenManagedRepository;
@SuppressWarnings( "unused" )
@Inject
- ManagedRepositoryHandler managedRepositoryHandler;
-
- @SuppressWarnings( "unused" )
- @Inject
- RepositoryGroupHandler groupHandler;
-
+ RepositoryHandlerDependencies repositoryHandlerDependencies;
private Path indexPath;
private MavenManagedRepository repository;
import org.apache.archiva.indexer.search.SearchResultHit;
import org.apache.archiva.indexer.search.SearchResults;
import org.apache.archiva.proxy.ProxyRegistry;
-import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
import org.apache.archiva.repository.Repository;
-import org.apache.archiva.repository.base.group.RepositoryGroupHandler;
-import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler;
+import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
+import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
import org.apache.archiva.repository.features.IndexCreationFeature;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.commons.lang3.SystemUtils;
@SuppressWarnings( "unused" )
@Inject
- ManagedRepositoryHandler managedRepositoryHandler;
-
- @SuppressWarnings( "unused" )
- @Inject
- RepositoryGroupHandler groupHandler;
-
+ RepositoryHandlerDependencies repositoryHandlerDependencies;
@Inject
ProxyRegistry proxyRegistry;
import org.apache.archiva.indexer.search.SearchResultHit;
import org.apache.archiva.indexer.search.SearchResults;
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.repository.base.RepositoryHandlerDependencies;
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Test;
@SuppressWarnings( "unused" )
@Inject
- ManagedRepositoryHandler managedRepositoryHandler;
-
- @SuppressWarnings( "unused" )
- @Inject
- RepositoryGroupHandler groupHandler;
+ RepositoryHandlerDependencies repositoryHandlerDependencies;
@After
import org.apache.archiva.indexer.search.SearchResults;
import org.apache.archiva.indexer.util.SearchUtil;
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.repository.base.RepositoryHandlerDependencies;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.junit.After;
import org.junit.Test;
@SuppressWarnings( "unused" )
@Inject
- ManagedRepositoryHandler managedRepositoryHandler;
-
- @SuppressWarnings( "unused" )
- @Inject
- RepositoryGroupHandler groupHandler;
-
+ RepositoryHandlerDependencies repositoryHandlerDependencies;
@After
public void endTests() {
*/
import net.sf.ehcache.CacheManager;
-import org.apache.archiva.configuration.*;
-import org.apache.archiva.policies.*;
+import org.apache.archiva.configuration.ArchivaConfiguration;
+import org.apache.archiva.configuration.ArchivaRuntimeConfiguration;
+import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.archiva.configuration.ProxyConnectorConfiguration;
+import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
+import org.apache.archiva.policies.CachedFailuresPolicy;
+import org.apache.archiva.policies.ChecksumPolicy;
+import org.apache.archiva.policies.PolicyOption;
+import org.apache.archiva.policies.PropagateErrorsDownloadPolicy;
+import org.apache.archiva.policies.PropagateErrorsOnUpdateDownloadPolicy;
+import org.apache.archiva.policies.ReleasesPolicy;
+import org.apache.archiva.policies.SnapshotsPolicy;
import org.apache.archiva.proxy.model.RepositoryProxyHandler;
-import org.apache.archiva.repository.*;
+import org.apache.archiva.repository.ManagedRepository;
+import org.apache.archiva.repository.ManagedRepositoryContent;
+import org.apache.archiva.repository.RepositoryRegistry;
+import org.apache.archiva.repository.RepositoryType;
+import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
import org.apache.archiva.repository.base.managed.BasicManagedRepository;
-import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler;
import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.maven.wagon.Wagon;
import java.nio.file.attribute.FileTime;
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@SuppressWarnings( "unused" )
@Inject
- ManagedRepositoryHandler managedRepositoryHandler;
-
+ RepositoryHandlerDependencies repositoryHandlerDependencies;
protected static final String ID_PROXIED1 = "proxied1";
import org.apache.archiva.policies.ReleasesPolicy;
import org.apache.archiva.policies.SnapshotsPolicy;
import org.apache.archiva.policies.urlcache.UrlFailureCache;
-import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler;
-import org.apache.archiva.repository.content.BaseRepositoryContentLayout;
import org.apache.archiva.repository.content.Artifact;
+import org.apache.archiva.repository.content.BaseRepositoryContentLayout;
import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.easymock.EasyMock;
import org.apache.archiva.policies.ReleasesPolicy;
import org.apache.archiva.policies.SnapshotsPolicy;
import org.apache.archiva.proxy.model.RepositoryProxyHandler;
-import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler;
-import org.apache.archiva.repository.content.BaseRepositoryContentLayout;
import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.RepositoryRegistry;
+import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
import org.apache.archiva.repository.base.managed.BasicManagedRepository;
import org.apache.archiva.repository.content.Artifact;
+import org.apache.archiva.repository.content.BaseRepositoryContentLayout;
import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.commons.io.FileUtils;
@SuppressWarnings( "unused" )
@Inject
- ManagedRepositoryHandler managedRepositoryHandler;
+ RepositoryHandlerDependencies repositoryHandlerDependencies;
private Server server;
credentials.setPassword(new char[0]);
}
IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get();
- if (cfg.getIndexDir() != null) {
- indexCreationFeature.setIndexPath(getURIFromString(cfg.getIndexDir()));
+ if ( !StringUtils.isEmpty( cfg.getIndexDir( ) ) )
+ {
+ indexCreationFeature.setIndexPath( getURIFromString( cfg.getIndexDir( ) ) );
}
- if (cfg.getPackedIndexDir() != null) {
+ if (!StringUtils.isEmpty( cfg.getPackedIndexDir() )) {
indexCreationFeature.setPackedIndexPath(getURIFromString(cfg.getPackedIndexDir()));
}
log.debug("Updated remote instance {}", repo);
cfg.setPackedIndexDir(convertUriToPath(indexCreationFeature.getPackedIndexPath()));
RemoteIndexFeature remoteIndexFeature = remoteRepository.getFeature(RemoteIndexFeature.class).get();
- if (remoteIndexFeature.getIndexUri() != null) {
+ if ( remoteIndexFeature.getIndexUri( ) == null )
+ {
+ cfg.setRemoteIndexUrl( "" );
+ }
+ else
+ {
cfg.setRemoteIndexUrl(remoteIndexFeature.getIndexUri().toString());
}
cfg.setRemoteDownloadTimeout((int) remoteIndexFeature.getDownloadTimeout().get(ChronoUnit.SECONDS));
cfg.setDownloadRemoteIndexOnStartup(remoteIndexFeature.isDownloadRemoteIndexOnStartup());
cfg.setDownloadRemoteIndex(remoteIndexFeature.isDownloadRemoteIndex());
cfg.setRemoteDownloadNetworkProxyId(remoteIndexFeature.getProxyId());
- if (!StringUtils.isEmpty(remoteIndexFeature.getProxyId())) {
- cfg.setRemoteDownloadNetworkProxyId(remoteIndexFeature.getProxyId());
- } else {
+ if ( StringUtils.isEmpty( remoteIndexFeature.getProxyId( ) ) )
+ {
cfg.setRemoteDownloadNetworkProxyId("");
}
-
-
+ else
+ {
+ cfg.setRemoteDownloadNetworkProxyId(remoteIndexFeature.getProxyId());
+ }
return cfg;
import org.apache.archiva.proxy.maven.WagonFactory;
import org.apache.archiva.proxy.maven.WagonFactoryRequest;
import org.apache.archiva.repository.RepositoryRegistry;
-import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler;
+import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.commons.io.FileUtils;
import org.apache.maven.wagon.Wagon;
@SuppressWarnings( "unused" )
@Inject
- ManagedRepositoryHandler managedRepositoryHandler;
+ RepositoryHandlerDependencies repositoryHandlerDependencies;
private WagonFactory wagonFactory;
import org.apache.archiva.proxy.maven.WagonFactoryRequest;
import org.apache.archiva.repository.ReleaseScheme;
import org.apache.archiva.repository.RepositoryRegistry;
-import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler;
+import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.commons.io.FileUtils;
import org.apache.maven.wagon.Wagon;
@SuppressWarnings( "unused" )
@Inject
- ManagedRepositoryHandler managedRepositoryHandler;
+ RepositoryHandlerDependencies repositoryHandlerDependencies;
private WagonFactory wagonFactory;
import org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException;
import org.apache.archiva.proxy.maven.WagonFactory;
import org.apache.archiva.repository.RepositoryRegistry;
-import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler;
+import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
import org.junit.Before;
import org.junit.Test;
@SuppressWarnings( "unused" )
@Inject
- ManagedRepositoryHandler managedRepositoryHandler;
+ RepositoryHandlerDependencies repositoryHandlerDependencies;
private static final String TEST_REPO_ID = "test";
import org.apache.archiva.metadata.repository.storage.ReadMetadataRequest;
import org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException;
import org.apache.archiva.repository.RepositoryRegistry;
-import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler;
+import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
import org.junit.Before;
import org.junit.Test;
@SuppressWarnings( "unused" )
@Inject
- ManagedRepositoryHandler managedRepositoryHandler;
+ RepositoryHandlerDependencies repositoryHandlerDependencies;
private static final String TEST_REPO_ID = "test";
import org.apache.archiva.proxy.maven.WagonFactory;
import org.apache.archiva.proxy.maven.WagonFactoryRequest;
import org.apache.archiva.repository.RepositoryRegistry;
-import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler;
+import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.commons.io.FileUtils;
import org.apache.maven.wagon.Wagon;
@SuppressWarnings( "unused" )
@Inject
- ManagedRepositoryHandler managedRepositoryHandler;
+ RepositoryHandlerDependencies repositoryHandlerDependencies;
private static final String TEST_REPO_ID = "test";
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.archiva.configuration.ProxyConnectorConfiguration;
import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
-import org.apache.archiva.indexer.ArchivaIndexingContext;
import org.apache.commons.lang3.StringUtils;
import org.modelmapper.ModelMapper;
import org.springframework.stereotype.Service;
return null; //To change body of implemented methods use File | Settings | File Templates.
}
- @Override
- public ArchivaIndexingContext createIndexContext( RemoteRepository repository )
- throws RepositoryAdminException
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
@Override
public List<ManagedRepository> getManagedRepositories()
throws RepositoryAdminException
import junit.framework.TestCase;
import org.apache.archiva.indexer.ArchivaIndexingContext;
import org.apache.archiva.indexer.UnsupportedBaseContextException;
-import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
-import org.apache.archiva.repository.base.managed.BasicManagedRepository;
import org.apache.archiva.repository.ManagedRepository;
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.repository.storage.StorageAsset;
+import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
+import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
+import org.apache.archiva.repository.base.managed.BasicManagedRepository;
import org.apache.archiva.repository.features.IndexCreationFeature;
+import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.maven.index.ArtifactInfo;
@SuppressWarnings( "unused" )
@Inject
- ManagedRepositoryHandler managedRepositoryHandler;
-
- @SuppressWarnings( "unused" )
- @Inject
- RepositoryGroupHandler repositoryGroupHandler;
+ RepositoryHandlerDependencies repositoryHandlerDependencies;
@Inject
private IndexUpdater indexUpdater;
import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.UnsupportedURIException;
-import org.apache.archiva.repository.base.group.RepositoryGroupHandler;
-import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler;
+import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
import org.apache.archiva.repository.features.IndexCreationFeature;
import org.apache.archiva.repository.features.RemoteIndexFeature;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
@SuppressWarnings( "unused" )
@Inject
- ManagedRepositoryHandler managedRepositoryHandler;
-
- @SuppressWarnings( "unused" )
- @Inject
- RepositoryGroupHandler repositoryGroupHandler;
-
+ RepositoryHandlerDependencies repositoryHandlerDependencies;
@Inject
RepositoryProvider repositoryProvider;
import org.apache.archiva.admin.model.beans.RemoteRepository;
import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
import org.apache.archiva.configuration.ArchivaConfiguration;
-import org.apache.archiva.indexer.ArchivaIndexingContext;
import java.util.List;
import java.util.Map;
this.archivaConfiguration = archivaConfiguration;
}
- @Override
- public ArchivaIndexingContext createIndexContext( RemoteRepository repository )
- throws RepositoryAdminException
- {
- return null;
- }
}
import org.apache.archiva.repository.ManagedRepository;
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.base.RepositoryHandlerDependencies;
import org.apache.archiva.scheduler.repository.model.RepositoryTask;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.junit.After;
@SuppressWarnings( "unused" )
@Inject
- ManagedRepositoryHandler managedRepositoryHandler;
-
- @SuppressWarnings( "unused" )
- @Inject
- RepositoryGroupHandler groupHandler;
+ RepositoryHandlerDependencies repositoryHandlerDependencies;
@Inject
@Named( value = "taskExecutor#test-repository-scanning" )
* under the License.
*/
-import com.gargoylesoftware.htmlunit.*;
+import com.gargoylesoftware.htmlunit.HttpMethod;
+import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.WebRequest;
+import com.gargoylesoftware.htmlunit.WebResponse;
import junit.framework.TestCase;
import net.sf.ehcache.CacheManager;
import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.Configuration;
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
-import org.apache.archiva.indexer.ArchivaIndexingContext;
+import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.RepositoryException;
import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
-import org.apache.archiva.repository.ManagedRepository;
-import org.apache.archiva.repository.RepositoryType;
-import org.apache.archiva.repository.base.group.RepositoryGroupHandler;
-import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler;
+import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.archiva.webdav.httpunit.MkColMethodWebRequest;
import org.apache.commons.io.FileUtils;
@SuppressWarnings( "unused" )
@Inject
- RepositoryGroupHandler repositoryGroupHandler;
-
- @SuppressWarnings( "unused" )
- @Inject
- ManagedRepositoryHandler managedRepositoryHandler;
+ RepositoryHandlerDependencies repositoryHandlerDependencies;
@Inject
ArchivaRepositoryRegistry repositoryRegistry;
import org.apache.archiva.configuration.FileTypes;
import org.apache.archiva.configuration.RepositoryGroupConfiguration;
import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
-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.content.MavenContentHelper;
-import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider;
import org.apache.archiva.proxy.ProxyRegistry;
import org.apache.archiva.repository.EditableManagedRepository;
+import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.RemoteRepository;
import org.apache.archiva.repository.RemoteRepositoryContent;
import org.apache.archiva.repository.Repository;
import org.apache.archiva.repository.RepositoryException;
import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.repository.RepositoryType;
+import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
import org.apache.archiva.repository.maven.content.ManagedDefaultRepositoryContent;
+import org.apache.archiva.repository.maven.content.MavenContentHelper;
import org.apache.archiva.repository.maven.content.MavenRepositoryRequestInfo;
+import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.commons.lang3.StringUtils;
import org.apache.jackrabbit.webdav.DavException;
@SuppressWarnings( "unused" )
@Inject
- RepositoryGroupHandler repositoryGroupHandler;
-
- @SuppressWarnings( "unused" )
- @Inject
- ManagedRepositoryHandler managedRepositoryHandler;
+ RepositoryHandlerDependencies repositoryHandlerDependencies;
public Path getProjectBase() {
if (this.projectBase.get()==null) {