aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/plugins
diff options
context:
space:
mode:
authorMartin Stockhammer <martin.stockhammer@ars.de>2017-10-21 14:42:32 +0200
committerMartin Stockhammer <martin.stockhammer@ars.de>2017-10-21 14:42:32 +0200
commitcb38dbbbc6f50f8a7a12adaf0afc42fe2c089599 (patch)
treed0fc0cc3b27a6fb233b89eb1cf0e6d8c25b113a3 /archiva-modules/plugins
parent2c12980a3a0a893375f89cd1ac60b8051483a377 (diff)
downloadarchiva-cb38dbbbc6f50f8a7a12adaf0afc42fe2c089599.tar.gz
archiva-cb38dbbbc6f50f8a7a12adaf0afc42fe2c089599.zip
Changing the initialization behaviour of metadata repo factory
Diffstat (limited to 'archiva-modules/plugins')
-rw-r--r--archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java23
-rw-r--r--archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraRepositorySessionFactory.java16
-rw-r--r--archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileRepositorySessionFactory.java18
-rw-r--r--archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrRepositorySessionFactory.java35
4 files changed, 48 insertions, 44 deletions
diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java
index 0df46964b..c2a7ac709 100644
--- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java
+++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java
@@ -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);
}
diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraRepositorySessionFactory.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraRepositorySessionFactory.java
index 2e434fc6e..56bdaf058 100644
--- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraRepositorySessionFactory.java
+++ b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraRepositorySessionFactory.java
@@ -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();
- }
}
diff --git a/archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileRepositorySessionFactory.java b/archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileRepositorySessionFactory.java
index ce640fe1d..fadd4e7d3 100644
--- a/archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileRepositorySessionFactory.java
+++ b/archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileRepositorySessionFactory.java
@@ -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 =
@@ -72,6 +68,11 @@ public class FileRepositorySessionFactory
}
@Override
+ protected void shutdown() {
+ // do nothing
+ }
+
+ @Override
public RepositorySession createSession()
{
MetadataRepository metadataRepository = new FileMetadataRepository( metadataFacetFactories, configuration );
@@ -79,9 +80,4 @@ public class FileRepositorySessionFactory
return new RepositorySession( metadataRepository, metadataResolver );
}
- @Override
- public void close()
- {
- // no op
- }
}
diff --git a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrRepositorySessionFactory.java b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrRepositorySessionFactory.java
index 0b775c796..6a4d793fa 100644
--- a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrRepositorySessionFactory.java
+++ b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrRepositorySessionFactory.java
@@ -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();
}
}