[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
This commit is contained in:
Brett Porter 2010-12-22 03:12:51 +00:00
parent badcc9e925
commit eff60e10de
4 changed files with 68 additions and 28 deletions

View File

@ -56,25 +56,31 @@
<artifactId>jcr</artifactId>
<version>2.0</version>
</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>

View File

@ -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/" );

View File

@ -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>

View File

@ -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();
}
}