aboutsummaryrefslogtreecommitdiffstats
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
parent2c12980a3a0a893375f89cd1ac60b8051483a377 (diff)
downloadarchiva-cb38dbbbc6f50f8a7a12adaf0afc42fe2c089599.tar.gz
archiva-cb38dbbbc6f50f8a7a12adaf0afc42fe2c089599.zip
Changing the initialization behaviour of metadata repo factory
-rw-r--r--archiva-modules/archiva-base/archiva-mock/src/main/java/org/apache/archiva/mock/MockRepositorySessionFactory.java20
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryProvider.java4
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryRegistry.java85
-rw-r--r--archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/TestRepositorySessionFactoryBean.java3
-rw-r--r--archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/webtest/memory/TestRepositorySessionFactory.java10
-rw-r--r--archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/AbstractRepositorySessionFactory.java53
-rw-r--r--archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySessionFactory.java4
-rw-r--r--archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySessionFactoryBean.java3
-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
12 files changed, 205 insertions, 69 deletions
diff --git a/archiva-modules/archiva-base/archiva-mock/src/main/java/org/apache/archiva/mock/MockRepositorySessionFactory.java b/archiva-modules/archiva-base/archiva-mock/src/main/java/org/apache/archiva/mock/MockRepositorySessionFactory.java
index d293d5247..3f17ceb23 100644
--- a/archiva-modules/archiva-base/archiva-mock/src/main/java/org/apache/archiva/mock/MockRepositorySessionFactory.java
+++ b/archiva-modules/archiva-base/archiva-mock/src/main/java/org/apache/archiva/mock/MockRepositorySessionFactory.java
@@ -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
}
+
+
}
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryProvider.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryProvider.java
index 9a4c8f1cf..a818da994 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryProvider.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryProvider.java
@@ -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;
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryRegistry.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryRegistry.java
index 23a463d2b..209fd5447 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryRegistry.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryRegistry.java
@@ -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) {
+
+ }
}
diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/TestRepositorySessionFactoryBean.java b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/TestRepositorySessionFactoryBean.java
index 82bd3602d..cc789e1fb 100644
--- a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/TestRepositorySessionFactoryBean.java
+++ b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/TestRepositorySessionFactoryBean.java
@@ -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;
}
diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/webtest/memory/TestRepositorySessionFactory.java b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/webtest/memory/TestRepositorySessionFactory.java
index 31e5a299a..b2aab9de8 100644
--- a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/webtest/memory/TestRepositorySessionFactory.java
+++ b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/webtest/memory/TestRepositorySessionFactory.java
@@ -37,6 +37,16 @@ public class TestRepositorySessionFactory
}
@Override
+ public void open() {
+
+ }
+
+ @Override
+ public boolean isOpen() {
+ return false;
+ }
+
+ @Override
public RepositorySession createSession()
{
return repositorySession != null ? repositorySession : new RepositorySession( new TestMetadataRepository(),
diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/AbstractRepositorySessionFactory.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/AbstractRepositorySessionFactory.java
new file mode 100644
index 000000000..66241cfd6
--- /dev/null
+++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/AbstractRepositorySessionFactory.java
@@ -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();
+ }
+ }
+}
diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySessionFactory.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySessionFactory.java
index ba2c585d8..929c3c1a5 100644
--- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySessionFactory.java
+++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySessionFactory.java
@@ -21,6 +21,10 @@ package org.apache.archiva.metadata.repository;
public interface RepositorySessionFactory
{
+ public void open();
+
+ public boolean isOpen();
+
RepositorySession createSession();
void close();
diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySessionFactoryBean.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySessionFactoryBean.java
index 3312a3cfb..6b398fd2a 100644
--- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySessionFactoryBean.java
+++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySessionFactoryBean.java
@@ -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;
}
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();
}
}