diff options
author | Brett Porter <brett@apache.org> | 2010-12-22 03:12:51 +0000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2010-12-22 03:12:51 +0000 |
commit | eff60e10de7d8c60b79e56f8cb8f8d01414a45a5 (patch) | |
tree | 54a6b68d1b01374430dfb8138b043bb9ff9c44d4 | |
parent | badcc9e925b9351d2e1d2b198d082245960ee40a (diff) | |
download | archiva-eff60e10de7d8c60b79e56f8cb8f8d01414a45a5.tar.gz archiva-eff60e10de7d8c60b79e56f8cb8f8d01414a45a5.zip |
[MRM-1327] instantiate the repository via Spring and avoid hard-coding
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1051741 13f79535-47bb-0310-9956-ffa450edef68
4 files changed, 68 insertions, 28 deletions
diff --git a/archiva-modules/plugins/metadata-store-jcr/pom.xml b/archiva-modules/plugins/metadata-store-jcr/pom.xml index 72ee07e42..20df6c76f 100644 --- a/archiva-modules/plugins/metadata-store-jcr/pom.xml +++ b/archiva-modules/plugins/metadata-store-jcr/pom.xml @@ -58,23 +58,29 @@ </dependency> <dependency> <groupId>org.apache.jackrabbit</groupId> + <artifactId>jackrabbit-jcr-commons</artifactId> + <version>${jackrabbit.version}</version> + </dependency> + <dependency> + <groupId>org.apache.jackrabbit</groupId> <artifactId>jackrabbit-core</artifactId> <version>${jackrabbit.version}</version> - <!-- TODO: trim more, or look for a lighter container? --> + <scope>test</scope> + <!-- could trim more, but since it's just for test we don't need to worry --> <exclusions> <exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion> - <exclusion> - <groupId>org.apache.derby</groupId> - <artifactId>derby</artifactId> - </exclusion> - <exclusion> - <groupId>org.apache.jackrabbit</groupId> - <artifactId>jackrabbit-text-extractors</artifactId> - </exclusion> </exclusions> </dependency> </dependencies> + <build> + <testResources> + <testResource> + <directory>src/test/filtered-resources</directory> + <filtering>true</filtering> + </testResource> + </testResources> + </build> </project> diff --git a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java index 0bbdb48b3..cd21eeb3e 100644 --- a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java +++ b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java @@ -36,11 +36,9 @@ import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.MetadataRepositoryException; import org.apache.archiva.metadata.repository.MetadataResolutionException; import org.apache.jackrabbit.commons.JcrUtils; -import org.apache.jackrabbit.core.TransientRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; @@ -91,25 +89,26 @@ public class JcrMetadataRepository private static final Logger log = LoggerFactory.getLogger( JcrMetadataRepository.class ); - private static Repository repository; + /** + * @plexus.requirement + */ + private Repository repository; private Session session; public JcrMetadataRepository() { + } + + public void login() + { // TODO: need to close this at the end - do we need to add it in the API? try { - // TODO: push this in from the test, and make it possible from the webapp - if ( repository == null ) - { - repository = new TransientRepository( new File( "src/test/repository.xml" ), new File( "target/jcr" ) ); - } // TODO: shouldn't do this in constructor since it's a singleton session = repository.login( new SimpleCredentials( "username", "password".toCharArray() ) ); - // TODO: try moving this into the repo instantiation Workspace workspace = session.getWorkspace(); workspace.getNamespaceRegistry().registerNamespace( "archiva", "http://archiva.apache.org/jcr/" ); diff --git a/archiva-modules/plugins/metadata-store-jcr/src/test/filtered-resources/META-INF/spring-context.xml b/archiva-modules/plugins/metadata-store-jcr/src/test/filtered-resources/META-INF/spring-context.xml new file mode 100644 index 000000000..43f6d0829 --- /dev/null +++ b/archiva-modules/plugins/metadata-store-jcr/src/test/filtered-resources/META-INF/spring-context.xml @@ -0,0 +1,32 @@ +<?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. + --> + +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> + + <bean id="repository" class="org.apache.jackrabbit.core.RepositoryImpl" destroy-method="shutdown"> + <constructor-arg ref="config"/> + </bean> + <bean id="config" class="org.apache.jackrabbit.core.config.RepositoryConfig" factory-method="create"> + <constructor-arg value="${basedir}/src/test/repository.xml"/> + <constructor-arg value="${project.build.directory}/jcr"/> + </bean> +</beans>
\ No newline at end of file diff --git a/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepositoryTest.java b/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepositoryTest.java index e3b2c92f8..e62d56a19 100644 --- a/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepositoryTest.java +++ b/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepositoryTest.java @@ -21,6 +21,7 @@ package org.apache.archiva.metadata.repository.jcr; import org.apache.archiva.metadata.model.MetadataFacetFactory; import org.apache.archiva.metadata.repository.AbstractMetadataRepositoryTest; +import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.commons.io.FileUtils; import java.util.Map; @@ -40,18 +41,11 @@ public class JcrMetadataRepositoryTest Map<String, MetadataFacetFactory> factories = createTestMetadataFacetFactories(); - jcrMetadataRepository = new JcrMetadataRepository(); + jcrMetadataRepository = (JcrMetadataRepository) lookup( MetadataRepository.class ); jcrMetadataRepository.setMetadataFacetFactories( factories ); + jcrMetadataRepository.login(); - this.repository = jcrMetadataRepository; - } - - @Override - protected void tearDown() - throws Exception - { - super.tearDown(); - + // removing content is faster than deleting and re-copying the files from target/jcr try { jcrMetadataRepository.getJcrSession().getRootNode().getNode( "repositories" ).remove(); @@ -61,6 +55,15 @@ public class JcrMetadataRepositoryTest // ignore } + this.repository = jcrMetadataRepository; + } + + @Override + protected void tearDown() + throws Exception + { jcrMetadataRepository.close(); + + super.tearDown(); } } |