@@ -19,18 +19,14 @@ package org.apache.archiva.mock; | |||
* under the License. | |||
*/ | |||
import org.apache.archiva.metadata.repository.AbstractMetadataRepository; | |||
import org.apache.archiva.metadata.repository.MetadataRepository; | |||
import org.apache.archiva.metadata.repository.MetadataResolver; | |||
import org.apache.archiva.metadata.repository.RepositorySession; | |||
import org.apache.archiva.metadata.repository.RepositorySessionFactory; | |||
import org.apache.archiva.metadata.repository.*; | |||
import org.springframework.stereotype.Service; | |||
/** | |||
* @author Olivier Lamy | |||
*/ | |||
@Service( "repositorySessionFactory#mock" ) | |||
public class MockRepositorySessionFactory | |||
public class MockRepositorySessionFactory extends AbstractRepositorySessionFactory | |||
implements RepositorySessionFactory | |||
{ | |||
private MetadataRepository repository = new AbstractMetadataRepository() | |||
@@ -75,8 +71,14 @@ public class MockRepositorySessionFactory | |||
} | |||
@Override | |||
public void close() | |||
{ | |||
// no op | |||
protected void initialize() { | |||
// noop | |||
} | |||
@Override | |||
protected void shutdown() { | |||
// noop | |||
} | |||
} |
@@ -34,6 +34,10 @@ public interface RepositoryProvider | |||
{ | |||
Set<RepositoryType> provides(); | |||
EditableManagedRepository createManagedInstance(String id, String name); | |||
EditableRemoteRepository createRemoteInstance(String id, String name); | |||
ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration) throws RepositoryException; | |||
ManagedRepository createStagingInstance(ManagedRepositoryConfiguration baseConfiguration) throws RepositoryException; |
@@ -19,11 +19,7 @@ package org.apache.archiva.repository; | |||
* under the License. | |||
*/ | |||
import org.apache.archiva.configuration.ArchivaConfiguration; | |||
import org.apache.archiva.configuration.Configuration; | |||
import org.apache.archiva.configuration.IndeterminateConfigurationException; | |||
import org.apache.archiva.configuration.ManagedRepositoryConfiguration; | |||
import org.apache.archiva.configuration.RemoteRepositoryConfiguration; | |||
import org.apache.archiva.configuration.*; | |||
import org.apache.archiva.redback.components.registry.RegistryException; | |||
import org.apache.archiva.repository.features.StagingRepositoryFeature; | |||
import org.slf4j.Logger; | |||
@@ -32,13 +28,7 @@ import org.springframework.stereotype.Service; | |||
import javax.annotation.PostConstruct; | |||
import javax.inject.Inject; | |||
import java.util.Collection; | |||
import java.util.Collections; | |||
import java.util.HashMap; | |||
import java.util.LinkedHashMap; | |||
import java.util.List; | |||
import java.util.ListIterator; | |||
import java.util.Map; | |||
import java.util.*; | |||
import java.util.concurrent.locks.ReentrantReadWriteLock; | |||
import java.util.stream.Collectors; | |||
import java.util.stream.Stream; | |||
@@ -51,8 +41,7 @@ import java.util.stream.Stream; | |||
* configuration save fails the changes are rolled back. | |||
*/ | |||
@Service( "repositoryRegistry" ) | |||
public class RepositoryRegistry | |||
{ | |||
public class RepositoryRegistry implements ConfigurationListener { | |||
private static final Logger log = LoggerFactory.getLogger( RepositoryRegistry.class ); | |||
@@ -86,6 +75,8 @@ public class RepositoryRegistry | |||
managedRepositories.putAll( getManagedRepositoriesFromConfig( ) ); | |||
remoteRepositories.clear( ); | |||
remoteRepositories.putAll( getRemoteRepositoriesFromConfig( ) ); | |||
// archivaConfiguration.addChangeListener(this); | |||
archivaConfiguration.addListener(this); | |||
} | |||
finally | |||
{ | |||
@@ -160,7 +151,7 @@ public class RepositoryRegistry | |||
StagingRepositoryFeature feature = repo.getFeature( StagingRepositoryFeature.class ).get( ); | |||
if ( feature.isStageRepoNeeded( ) ) | |||
{ | |||
ManagedRepository stageRepo = getStageRepository( provider, cfg ); | |||
ManagedRepository stageRepo = getStagingRepository( provider, cfg ); | |||
feature.setStagingRepository( stageRepo ); | |||
} | |||
} | |||
@@ -172,7 +163,7 @@ public class RepositoryRegistry | |||
} | |||
private ManagedRepository getStageRepository( RepositoryProvider provider, ManagedRepositoryConfiguration baseRepoCfg ) throws RepositoryException | |||
private ManagedRepository getStagingRepository(RepositoryProvider provider, ManagedRepositoryConfiguration baseRepoCfg ) throws RepositoryException | |||
{ | |||
ManagedRepository stageRepo = getManagedRepository( baseRepoCfg.getId( ) + StagingRepositoryFeature.STAGING_REPO_POSTFIX ); | |||
if ( stageRepo == null ) | |||
@@ -183,6 +174,8 @@ public class RepositoryRegistry | |||
} | |||
private Map<String, RemoteRepository> getRemoteRepositoriesFromConfig( ) | |||
{ | |||
try | |||
@@ -528,4 +521,64 @@ public class RepositoryRegistry | |||
} | |||
/** | |||
* 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 ManagedRepository clone(ManagedRepository repo, String newId) throws RepositoryException | |||
{ | |||
if (managedRepositories.containsKey(newId) || remoteRepositories.containsKey(newId)) { | |||
throw new RepositoryException("The given id exists already "+newId); | |||
} | |||
RepositoryProvider provider = getProvider(repo.getType()); | |||
ManagedRepositoryConfiguration cfg = provider.getManagedConfiguration(repo); | |||
cfg.setId(newId); | |||
ManagedRepository cloned = provider.createManagedInstance(cfg); | |||
return cloned; | |||
} | |||
public <T extends Repository> Repository clone(T repo, String newId) throws RepositoryException { | |||
if (repo instanceof RemoteRepository) { | |||
return this.clone((RemoteRepository)repo, newId); | |||
} else if (repo instanceof ManagedRepository) { | |||
return this.clone((ManagedRepository)repo, newId); | |||
} else { | |||
throw new RepositoryException("This repository class is not supported "+ repo.getClass().getName()); | |||
} | |||
} | |||
/** | |||
* 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 (managedRepositories.containsKey(newId) || remoteRepositories.containsKey(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); | |||
return cloned; | |||
} | |||
public EditableManagedRepository createNewManaged(RepositoryType type, String id, String name) throws RepositoryException { | |||
return getProvider(type).createManagedInstance(id, name); | |||
} | |||
public EditableRemoteRepository createNewRemote(RepositoryType type, String id, String name) throws RepositoryException { | |||
return getProvider(type).createRemoteInstance(id, name); | |||
} | |||
@Override | |||
public void configurationEvent(ConfigurationEvent event) { | |||
} | |||
} |
@@ -56,6 +56,9 @@ public class TestRepositorySessionFactoryBean | |||
RepositorySessionFactory repositorySessionFactory = | |||
getBeanFactory().getBean( "repositorySessionFactory#" + this.beanId, RepositorySessionFactory.class ); | |||
logger.info( "create RepositorySessionFactory instance of {}", repositorySessionFactory.getClass().getName() ); | |||
if (!repositorySessionFactory.isOpen()) { | |||
repositorySessionFactory.open(); | |||
} | |||
return repositorySessionFactory; | |||
} | |||
@@ -36,6 +36,16 @@ public class TestRepositorySessionFactory | |||
this.repositorySession = repositorySession; | |||
} | |||
@Override | |||
public void open() { | |||
} | |||
@Override | |||
public boolean isOpen() { | |||
return false; | |||
} | |||
@Override | |||
public RepositorySession createSession() | |||
{ |
@@ -0,0 +1,53 @@ | |||
package org.apache.archiva.metadata.repository; | |||
/* | |||
* 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 java.util.concurrent.atomic.AtomicBoolean; | |||
/** | |||
* Implements just the open/close methods in a concurrent safe manner. | |||
*/ | |||
public abstract class AbstractRepositorySessionFactory implements RepositorySessionFactory { | |||
AtomicBoolean open = new AtomicBoolean(); | |||
protected abstract void initialize(); | |||
protected abstract void shutdown(); | |||
@Override | |||
public void open() { | |||
if (open.compareAndSet(false,true)) { | |||
initialize(); | |||
} | |||
} | |||
@Override | |||
public boolean isOpen() { | |||
return open.get(); | |||
} | |||
@Override | |||
public void close() { | |||
if(open.compareAndSet(true,false)) { | |||
shutdown(); | |||
} | |||
} | |||
} |
@@ -21,6 +21,10 @@ package org.apache.archiva.metadata.repository; | |||
public interface RepositorySessionFactory | |||
{ | |||
public void open(); | |||
public boolean isOpen(); | |||
RepositorySession createSession(); | |||
void close(); |
@@ -68,6 +68,9 @@ public class RepositorySessionFactoryBean | |||
logger.info( "create RepositorySessionFactory with id {} instance of {}", // | |||
id, // | |||
repositorySessionFactory.getClass().getName() ); | |||
if (!repositorySessionFactory.isOpen()) { | |||
repositorySessionFactory.open(); | |||
} | |||
return repositorySessionFactory; | |||
} | |||
@@ -22,21 +22,12 @@ package org.apache.archiva.repository.maven2; | |||
import org.apache.archiva.configuration.AbstractRepositoryConfiguration; | |||
import org.apache.archiva.configuration.ManagedRepositoryConfiguration; | |||
import org.apache.archiva.configuration.RemoteRepositoryConfiguration; | |||
import org.apache.archiva.repository.EditableRepository; | |||
import org.apache.archiva.repository.ManagedRepository; | |||
import org.apache.archiva.repository.PasswordCredentials; | |||
import org.apache.archiva.repository.ReleaseScheme; | |||
import org.apache.archiva.repository.RemoteRepository; | |||
import org.apache.archiva.repository.RepositoryCredentials; | |||
import org.apache.archiva.repository.RepositoryException; | |||
import org.apache.archiva.repository.RepositoryProvider; | |||
import org.apache.archiva.repository.RepositoryType; | |||
import org.apache.archiva.repository.*; | |||
import org.apache.archiva.repository.features.ArtifactCleanupFeature; | |||
import org.apache.archiva.repository.features.IndexCreationFeature; | |||
import org.apache.archiva.repository.features.RemoteIndexFeature; | |||
import org.apache.archiva.repository.features.StagingRepositoryFeature; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.apache.http.auth.UsernamePasswordCredentials; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.springframework.stereotype.Service; | |||
@@ -49,7 +40,6 @@ import java.time.Duration; | |||
import java.time.Period; | |||
import java.time.temporal.ChronoUnit; | |||
import java.util.HashSet; | |||
import java.util.Locale; | |||
import java.util.Set; | |||
/** | |||
@@ -72,6 +62,16 @@ public class MavenRepositoryProvider implements RepositoryProvider | |||
return TYPES; | |||
} | |||
@Override | |||
public EditableManagedRepository createManagedInstance(String id, String name) { | |||
return new MavenManagedRepository(id, name); | |||
} | |||
@Override | |||
public EditableRemoteRepository createRemoteInstance(String id, String name) { | |||
return new MavenRemoteRepository(id, name); | |||
} | |||
private URI getURIFromString( String uriStr) throws RepositoryException { | |||
URI uri; | |||
try { | |||
@@ -110,7 +110,6 @@ public class MavenRepositoryProvider implements RepositoryProvider | |||
repo.setSchedulingDefinition(cfg.getRefreshCronExpression()); | |||
repo.setBlocksRedeployment( cfg.isBlockRedeployments() ); | |||
repo.setScanned( cfg.isScanned() ); | |||
Set<ReleaseScheme> schemes = new HashSet<>( ); | |||
if (cfg.isReleases()) { | |||
repo.addActiveReleaseScheme(ReleaseScheme.RELEASE); | |||
} |
@@ -21,6 +21,7 @@ package org.apache.archiva.metadata.repository.cassandra; | |||
import org.apache.archiva.configuration.ArchivaConfiguration; | |||
import org.apache.archiva.metadata.model.MetadataFacetFactory; | |||
import org.apache.archiva.metadata.repository.AbstractRepositorySessionFactory; | |||
import org.apache.archiva.metadata.repository.MetadataResolver; | |||
import org.apache.archiva.metadata.repository.RepositorySession; | |||
import org.apache.archiva.metadata.repository.RepositorySessionFactory; | |||
@@ -33,13 +34,14 @@ import javax.inject.Inject; | |||
import javax.inject.Named; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import java.util.concurrent.atomic.AtomicBoolean; | |||
/** | |||
* @author Olivier Lamy | |||
* @since 2.0.0 | |||
*/ | |||
@Service("repositorySessionFactory#cassandra") | |||
public class CassandraRepositorySessionFactory | |||
public class CassandraRepositorySessionFactory extends AbstractRepositorySessionFactory | |||
implements RepositorySessionFactory | |||
{ | |||
@@ -58,7 +60,6 @@ public class CassandraRepositorySessionFactory | |||
@Inject | |||
private CassandraArchivaManager cassandraArchivaManager; | |||
@PostConstruct | |||
public void initialize() | |||
{ | |||
Map<String, MetadataFacetFactory> tmpMetadataFacetFactories = | |||
@@ -73,6 +74,11 @@ public class CassandraRepositorySessionFactory | |||
} | |||
} | |||
@Override | |||
protected void shutdown() { | |||
cassandraArchivaManager.shutdown(); | |||
} | |||
@Override | |||
public RepositorySession createSession() | |||
@@ -82,10 +88,4 @@ public class CassandraRepositorySessionFactory | |||
return new RepositorySession( metadataRepository, metadataResolver ); | |||
} | |||
@Override | |||
public void close() | |||
{ | |||
cassandraArchivaManager.shutdown(); | |||
} | |||
} |
@@ -20,10 +20,7 @@ package org.apache.archiva.metadata.repository.file; | |||
*/ | |||
import org.apache.archiva.metadata.model.MetadataFacetFactory; | |||
import org.apache.archiva.metadata.repository.MetadataRepository; | |||
import org.apache.archiva.metadata.repository.MetadataResolver; | |||
import org.apache.archiva.metadata.repository.RepositorySession; | |||
import org.apache.archiva.metadata.repository.RepositorySessionFactory; | |||
import org.apache.archiva.metadata.repository.*; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.apache.archiva.configuration.ArchivaConfiguration; | |||
import org.springframework.context.ApplicationContext; | |||
@@ -39,7 +36,7 @@ import java.util.Map; | |||
* | |||
*/ | |||
@Service( "repositorySessionFactory#file" ) | |||
public class FileRepositorySessionFactory | |||
public class FileRepositorySessionFactory extends AbstractRepositorySessionFactory | |||
implements RepositorySessionFactory | |||
{ | |||
private Map<String, MetadataFacetFactory> metadataFacetFactories; | |||
@@ -54,7 +51,6 @@ public class FileRepositorySessionFactory | |||
@Inject | |||
private ApplicationContext applicationContext; | |||
@PostConstruct | |||
public void initialize() | |||
{ | |||
Map<String, MetadataFacetFactory> tmpMetadataFacetFactories = | |||
@@ -71,6 +67,11 @@ public class FileRepositorySessionFactory | |||
} | |||
@Override | |||
protected void shutdown() { | |||
// do nothing | |||
} | |||
@Override | |||
public RepositorySession createSession() | |||
{ | |||
@@ -79,9 +80,4 @@ public class FileRepositorySessionFactory | |||
return new RepositorySession( metadataRepository, metadataResolver ); | |||
} | |||
@Override | |||
public void close() | |||
{ | |||
// no op | |||
} | |||
} |
@@ -20,23 +20,20 @@ package org.apache.archiva.metadata.repository.jcr; | |||
*/ | |||
import org.apache.archiva.metadata.model.MetadataFacetFactory; | |||
import org.apache.archiva.metadata.repository.MetadataRepository; | |||
import org.apache.archiva.metadata.repository.MetadataResolver; | |||
import org.apache.archiva.metadata.repository.RepositorySession; | |||
import org.apache.archiva.metadata.repository.RepositorySessionFactory; | |||
import org.apache.archiva.metadata.repository.RepositorySessionFactoryBean; | |||
import org.apache.archiva.metadata.repository.*; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.apache.commons.lang.time.StopWatch; | |||
import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.springframework.context.ApplicationContext; | |||
import org.springframework.stereotype.Service; | |||
import javax.annotation.PostConstruct; | |||
import javax.annotation.PreDestroy; | |||
import javax.inject.Inject; | |||
import javax.jcr.Repository; | |||
import javax.jcr.RepositoryException; | |||
import java.io.IOException; | |||
import java.nio.file.Path; | |||
import java.nio.file.Paths; | |||
import java.util.HashMap; | |||
@@ -46,7 +43,7 @@ import java.util.Map; | |||
* | |||
*/ | |||
@Service( "repositorySessionFactory#jcr" ) | |||
public class JcrRepositorySessionFactory | |||
public class JcrRepositorySessionFactory extends AbstractRepositorySessionFactory | |||
implements RepositorySessionFactory | |||
{ | |||
@@ -98,13 +95,11 @@ public class JcrRepositorySessionFactory | |||
return this.metadataResolver; | |||
} | |||
@PostConstruct | |||
public void initialize() | |||
throws Exception | |||
{ | |||
// skip initialisation if not jcr | |||
if ( !StringUtils.equals( repositorySessionFactoryBean.getId(), "jcr" ) ) | |||
if ( repositorySessionFactoryBean!=null && !StringUtils.equals( repositorySessionFactoryBean.getId(), "jcr" ) ) | |||
{ | |||
return; | |||
} | |||
@@ -134,7 +129,12 @@ public class JcrRepositorySessionFactory | |||
// FIXME this need to be configurable | |||
Path directoryPath = Paths.get( System.getProperty( "appserver.base" ), "data/jcr" ); | |||
repositoryFactory.setRepositoryPath( directoryPath ); | |||
repository = repositoryFactory.createRepository(); | |||
try { | |||
repository = repositoryFactory.createRepository(); | |||
} catch (InvalidFileStoreVersionException | IOException e) { | |||
logger.error("Repository creation failed {}", e.getMessage()); | |||
throw new RuntimeException("Fatal error. Could not create metadata repository."); | |||
} | |||
metadataRepository = new JcrMetadataRepository( metadataFacetFactories, repository ); | |||
JcrMetadataRepository.initialize( metadataRepository.getJcrSession() ); | |||
} | |||
@@ -146,7 +146,11 @@ public class JcrRepositorySessionFactory | |||
{ | |||
if ( metadataRepository != null ) | |||
{ | |||
metadataRepository.close(); | |||
try { | |||
metadataRepository.close(); | |||
} catch (MetadataRepositoryException e) { | |||
logger.error("Close of metadata repository failed {}", e.getMessage()); | |||
} | |||
} | |||
} | |||
@@ -154,9 +158,14 @@ public class JcrRepositorySessionFactory | |||
logger.info( "time to initialize JcrRepositorySessionFactory: {}", stopWatch.getTime() ); | |||
} | |||
@Override | |||
protected void shutdown() { | |||
repositoryFactory.close(); | |||
} | |||
@PreDestroy | |||
public void close() | |||
{ | |||
repositoryFactory.close(); | |||
super.close(); | |||
} | |||
} |