]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1327] instantiate the repository via Spring and avoid hard-coding
authorBrett Porter <brett@apache.org>
Wed, 22 Dec 2010 03:12:51 +0000 (03:12 +0000)
committerBrett Porter <brett@apache.org>
Wed, 22 Dec 2010 03:12:51 +0000 (03:12 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1051741 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/plugins/metadata-store-jcr/pom.xml
archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java
archiva-modules/plugins/metadata-store-jcr/src/test/filtered-resources/META-INF/spring-context.xml [new file with mode: 0644]
archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepositoryTest.java

index 72ee07e429e2ba66dd8ade995f23b9da5676f784..20df6c76f7d9a329b77f9b728dc18cf0377da925 100644 (file)
       <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>
index 0bbdb48b33994798f8464e28da85c76ac539bb6d..cd21eeb3e4647d80361c16cfc1aa2cbe37ff3888 100644 (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/" );
 
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 (file)
index 0000000..43f6d08
--- /dev/null
@@ -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
index e3b2c92f87fcd938aeba80e422ac8c6eb1e135ea..e62d56a1974058dddb6d15116972a51eb7590c57 100644 (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();
     }
 }