You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by br...@apache.org on 2010/12/22 04:12:52 UTC

svn commit: r1051741 - in /archiva/trunk/archiva-modules/plugins/metadata-store-jcr: ./ src/main/java/org/apache/archiva/metadata/repository/jcr/ src/test/filtered-resources/ src/test/filtered-resources/META-INF/ src/test/java/org/apache/archiva/metada...

Author: brett
Date: Wed Dec 22 03:12:51 2010
New Revision: 1051741

URL: http://svn.apache.org/viewvc?rev=1051741&view=rev
Log:
[MRM-1327] instantiate the repository via Spring and avoid hard-coding

Added:
    archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/test/filtered-resources/
    archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/test/filtered-resources/META-INF/
    archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/test/filtered-resources/META-INF/spring-context.xml
Modified:
    archiva/trunk/archiva-modules/plugins/metadata-store-jcr/pom.xml
    archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java
    archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepositoryTest.java

Modified: archiva/trunk/archiva-modules/plugins/metadata-store-jcr/pom.xml
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/metadata-store-jcr/pom.xml?rev=1051741&r1=1051740&r2=1051741&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/plugins/metadata-store-jcr/pom.xml (original)
+++ archiva/trunk/archiva-modules/plugins/metadata-store-jcr/pom.xml Wed Dec 22 03:12:51 2010
@@ -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>

Modified: archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java?rev=1051741&r1=1051740&r2=1051741&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java (original)
+++ archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java Wed Dec 22 03:12:51 2010
@@ -36,11 +36,9 @@ import org.apache.archiva.metadata.repos
 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/" );
 

Added: archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/test/filtered-resources/META-INF/spring-context.xml
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/test/filtered-resources/META-INF/spring-context.xml?rev=1051741&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/test/filtered-resources/META-INF/spring-context.xml (added)
+++ archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/test/filtered-resources/META-INF/spring-context.xml Wed Dec 22 03:12:51 2010
@@ -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

Modified: archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepositoryTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepositoryTest.java?rev=1051741&r1=1051740&r2=1051741&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepositoryTest.java (original)
+++ archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepositoryTest.java Wed Dec 22 03:12:51 2010
@@ -21,6 +21,7 @@ package org.apache.archiva.metadata.repo
 
 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();
     }
 }