archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1053630 - in /archiva/trunk/archiva-modules: archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/ archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/ archiva-web...
Date Wed, 29 Dec 2010 13:03:00 GMT
Author: brett
Date: Wed Dec 29 13:02:59 2010
New Revision: 1053630

URL: http://svn.apache.org/viewvc?rev=1053630&view=rev
Log:
[MRM-1327] hook save()/close()/revert() methods to the repository implementation

Added:
    archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrRepositorySessionFactory.java
      - copied, changed from r1053542, archiva/trunk/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileRepositorySessionFactory.java
Modified:
    archiva/trunk/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java
    archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutorTest.java
    archiva/trunk/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java
    archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java
    archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySession.java
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java
    archiva/trunk/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
    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
    archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/test/repository.xml

Modified: archiva/trunk/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java?rev=1053630&r1=1053629&r2=1053630&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java
(original)
+++ archiva/trunk/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java
Wed Dec 29 13:02:59 2010
@@ -30,6 +30,7 @@ import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 
+// TODO: remove, it does nothing
 public class TestMetadataRepository
     implements MetadataRepository
 {
@@ -160,6 +161,21 @@ public class TestMetadataRepository
         return null;  //To change body of implemented methods use File | Settings | File
Templates.
     }
 
+    public void save()
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void close()
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void revert()
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
     public List<ArtifactMetadata> getArtifacts( String repositoryId )
     {
         return null;

Modified: archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutorTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutorTest.java?rev=1053630&r1=1053629&r2=1053630&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutorTest.java
(original)
+++ archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutorTest.java
Wed Dec 29 13:02:59 2010
@@ -21,6 +21,8 @@ package org.apache.archiva.scheduler.rep
 
 import org.apache.archiva.metadata.repository.MetadataRepository;
 import org.apache.archiva.metadata.repository.MetadataRepositoryException;
+import org.apache.archiva.metadata.repository.RepositorySessionFactory;
+import org.apache.archiva.metadata.repository.TestRepositorySessionFactory;
 import org.apache.archiva.metadata.repository.stats.RepositoryStatistics;
 import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
@@ -114,6 +116,9 @@ public class ArchivaRepositoryScanningTa
         testConsumer = (TestConsumer) lookup( KnownRepositoryContentConsumer.class, "test-consumer"
);
 
         metadataRepository = mock( MetadataRepository.class );
+
+        TestRepositorySessionFactory factory = (TestRepositorySessionFactory) lookup( RepositorySessionFactory.class
);
+        factory.setRepository( metadataRepository );
     }
 
     protected void tearDown()

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java?rev=1053630&r1=1053629&r2=1053630&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java
Wed Dec 29 13:02:59 2010
@@ -117,6 +117,7 @@ public class NewArtifactsRssFeedProcesso
         return artifact;
     }
 
+    // TODO: replace with mockito
     private class MetadataRepositoryMock
         implements MetadataRepository
     {
@@ -215,6 +216,21 @@ public class NewArtifactsRssFeedProcesso
             throw new UnsupportedOperationException();
         }
 
+        public void save()
+        {
+            throw new UnsupportedOperationException();
+        }
+
+        public void close()
+        {
+            throw new UnsupportedOperationException();
+        }
+
+        public void revert()
+        {
+            throw new UnsupportedOperationException();
+        }
+
         public Collection<String> getNamespaces( String arg0, String arg1 )
         {
             throw new UnsupportedOperationException();

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java?rev=1053630&r1=1053629&r2=1053630&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java
Wed Dec 29 13:02:59 2010
@@ -200,6 +200,19 @@ public class TestMetadataRepository
         return artifacts;
     }
 
+    public void save()
+    {
+    }
+
+    public void close()
+    {
+    }
+
+    public void revert()
+    {
+        throw new UnsupportedOperationException();
+    }
+
     public List<ArtifactMetadata> getArtifacts( String repositoryId )
     {
         return artifacts;

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java?rev=1053630&r1=1053629&r2=1053630&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java
Wed Dec 29 13:02:59 2010
@@ -30,6 +30,7 @@ import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 
+// TODO: remove - it does nothing
 public class TestMetadataRepository
     implements MetadataRepository
 {
@@ -160,6 +161,21 @@ public class TestMetadataRepository
         return null;  //To change body of implemented methods use File | Settings | File
Templates.
     }
 
+    public void save()
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void close()
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void revert()
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
     public List<ArtifactMetadata> getArtifacts( String repositoryId )
     {
         return null;

Modified: archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java?rev=1053630&r1=1053629&r2=1053630&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java
(original)
+++ archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java
Wed Dec 29 13:02:59 2010
@@ -133,4 +133,12 @@ public interface MetadataRepository
     Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String
projectId,
                                                String projectVersion )
         throws MetadataResolutionException;
+
+    void save()
+        throws MetadataRepositoryException;
+
+    void close();
+
+    void revert()
+        throws MetadataRepositoryException;
 }

Modified: archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySession.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySession.java?rev=1053630&r1=1053629&r2=1053630&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySession.java
(original)
+++ archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySession.java
Wed Dec 29 13:02:59 2010
@@ -61,14 +61,30 @@ public class RepositorySession
 
     public void save()
     {
-        // FIXME
+        try
+        {
+            repository.save();
+        }
+        catch ( MetadataRepositoryException e )
+        {
+            // FIXME
+            throw new RuntimeException( e );
+        }
 
         dirty = false;
     }
 
     public void revert()
     {
-        // FIXME
+        try
+        {
+            repository.revert();
+        }
+        catch ( MetadataRepositoryException e )
+        {
+            // FIXME
+            throw new RuntimeException( e );
+        }
 
         dirty = false;
     }
@@ -86,7 +102,7 @@ public class RepositorySession
             save();
         }
 
-        // FIXME
+        repository.close();
     }
 
     public void markDirty()

Modified: archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java?rev=1053630&r1=1053629&r2=1053630&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java
(original)
+++ archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java
Wed Dec 29 13:02:59 2010
@@ -177,4 +177,19 @@ public class TestMetadataRepository
     {
         return null;  //To change body of implemented methods use File | Settings | File
Templates.
     }
+
+    public void save()
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void close()
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void revert()
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
 }
\ No newline at end of file

Modified: archiva/trunk/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java?rev=1053630&r1=1053629&r2=1053630&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
(original)
+++ archiva/trunk/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
Wed Dec 29 13:02:59 2010
@@ -33,6 +33,7 @@ import org.apache.archiva.metadata.model
 import org.apache.archiva.metadata.model.ProjectVersionReference;
 import org.apache.archiva.metadata.model.Scm;
 import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.apache.archiva.metadata.repository.MetadataRepositoryException;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
@@ -530,6 +531,23 @@ public class FileMetadataRepository
         return artifacts.values();
     }
 
+    public void save()
+        throws MetadataRepositoryException
+    {
+        // it's all instantly persisted
+    }
+
+    public void close()
+    {
+        // nothing additional to close
+    }
+
+    public void revert()
+        throws MetadataRepositoryException
+    {
+        log.warn( "Attempted to revert a session, but the file-based repository storage doesn't
support it" );
+    }
+
     private void updateArtifactFacets( ArtifactMetadata artifact, Properties properties )
     {
         String propertyPrefix = "artifact:facet:" + artifact.getId() + ":";

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=1053630&r1=1053629&r2=1053630&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 29 13:02:59 2010
@@ -48,7 +48,6 @@
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-spring</artifactId>
-      <scope>test</scope>
     </dependency>
     <!-- FIXME: dependency management -->
     <dependency>

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=1053630&r1=1053629&r2=1053630&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 29 13:02:59 2010
@@ -50,7 +50,7 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import javax.jcr.LoginException;
+import javax.jcr.NamespaceRegistry;
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 import javax.jcr.PathNotFoundException;
@@ -67,7 +67,6 @@ import javax.jcr.query.Query;
 import javax.jcr.query.QueryResult;
 
 /**
- * @plexus.component role="org.apache.archiva.metadata.repository.MetadataRepository"
  * @todo below: revise storage format for project version metadata
  * @todo revise reference storage
  */
@@ -76,56 +75,50 @@ public class JcrMetadataRepository
 {
     private static final String JCR_LAST_MODIFIED = "jcr:lastModified";
 
-    private static final String ARTIFACT_NODE_TYPE = "archiva:artifact";
+    static final String ARTIFACT_NODE_TYPE = "archiva:artifact";
 
-    private static final String FACET_NODE_TYPE = "archiva:facet";
+    static final String FACET_NODE_TYPE = "archiva:facet";
 
     private static final String QUERY_ARTIFACTS = "SELECT * FROM [" + ARTIFACT_NODE_TYPE
+ "]";
 
-    /**
-     * @plexus.requirement role="org.apache.archiva.metadata.model.MetadataFacetFactory"
-     */
-    private Map<String, MetadataFacetFactory> metadataFacetFactories;
+    private final Map<String, MetadataFacetFactory> metadataFacetFactories;
 
     private static final Logger log = LoggerFactory.getLogger( JcrMetadataRepository.class
);
 
-    /**
-     * @plexus.requirement
-     */
     private Repository repository;
 
     private Session session;
 
-    public JcrMetadataRepository()
+    public JcrMetadataRepository( Map<String, MetadataFacetFactory> metadataFacetFactories,
Repository repository )
+        throws RepositoryException
     {
+        this.metadataFacetFactories = metadataFacetFactories;
+        this.repository = repository;
+
+        session = repository.login( new SimpleCredentials( "username", "password".toCharArray()
) );
     }
 
-    public void login()
+    static void initialize( Session session )
+        throws RepositoryException
     {
-        // FIXME: need to close this at the end - do we need to add it in the API?
-
-        try
-        {
-            // FIXME: shouldn't do this in constructor since it's a singleton
-            session = repository.login( new SimpleCredentials( "username", "password".toCharArray()
) );
+        // TODO: consider using namespaces for facets instead of the current approach:
+        // (if used, check if actually called by normal injection)
+//        for ( String facetId : metadataFacetFactories.keySet() )
+//        {
+//            session.getWorkspace().getNamespaceRegistry().registerNamespace( facetId, facetId
);
+//        }
 
-            Workspace workspace = session.getWorkspace();
-            workspace.getNamespaceRegistry().registerNamespace( "archiva", "http://archiva.apache.org/jcr/"
);
+        Workspace workspace = session.getWorkspace();
+        NamespaceRegistry registry = workspace.getNamespaceRegistry();
 
-            NodeTypeManager nodeTypeManager = workspace.getNodeTypeManager();
-            registerMixinNodeType( nodeTypeManager, ARTIFACT_NODE_TYPE );
-            registerMixinNodeType( nodeTypeManager, FACET_NODE_TYPE );
-        }
-        catch ( LoginException e )
-        {
-            // FIXME
-            throw new RuntimeException( e );
-        }
-        catch ( RepositoryException e )
+        if ( !Arrays.asList( registry.getPrefixes() ).contains( "archiva" ) )
         {
-            // FIXME
-            throw new RuntimeException( e );
+            registry.registerNamespace( "archiva", "http://archiva.apache.org/jcr/" );
         }
+
+        NodeTypeManager nodeTypeManager = workspace.getNodeTypeManager();
+        registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.ARTIFACT_NODE_TYPE
);
+        registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.FACET_NODE_TYPE );
     }
 
     private static void registerMixinNodeType( NodeTypeManager nodeTypeManager, String name
)
@@ -134,7 +127,13 @@ public class JcrMetadataRepository
         NodeTypeTemplate nodeType = nodeTypeManager.createNodeTypeTemplate();
         nodeType.setMixin( true );
         nodeType.setName( name );
-        nodeTypeManager.registerNodeType( nodeType, false );
+
+        // for now just don't re-create - but in future if we change the definition, make
sure to remove first as an
+        // upgrade path
+        if ( !nodeTypeManager.hasNodeType( name ) )
+        {
+            nodeTypeManager.registerNodeType( nodeType, false );
+        }
     }
 
     public void updateProject( String repositoryId, ProjectMetadata project )
@@ -997,31 +996,35 @@ public class JcrMetadataRepository
         return artifacts;
     }
 
-    void close()
+    public void save()
+        throws MetadataRepositoryException
     {
         try
         {
-            // FIXME: this shouldn't be here! Repository may need a context
             session.save();
         }
         catch ( RepositoryException e )
         {
-            // FIXME
-            throw new RuntimeException( e );
+            throw new MetadataRepositoryException( e.getMessage(), e );
         }
-        session.logout();
     }
 
-    public void setMetadataFacetFactories( Map<String, MetadataFacetFactory> metadataFacetFactories
)
+    public void revert()
+        throws MetadataRepositoryException
     {
-        this.metadataFacetFactories = metadataFacetFactories;
+        try
+        {
+            session.refresh( false );
+        }
+        catch ( RepositoryException e )
+        {
+            throw new MetadataRepositoryException( e.getMessage(), e );
+        }
+    }
 
-        // TODO: consider using namespaces for facets instead of the current approach:
-        // (if used, check if actually called by normal injection)
-//        for ( String facetId : metadataFacetFactories.keySet() )
-//        {
-//            session.getWorkspace().getNamespaceRegistry().registerNamespace( facetId, facetId
);
-//        }
+    public void close()
+    {
+        session.logout();
     }
 
     private ArtifactMetadata getArtifactFromNode( String repositoryId, Node artifactNode
)

Copied: archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrRepositorySessionFactory.java
(from r1053542, archiva/trunk/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileRepositorySessionFactory.java)
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrRepositorySessionFactory.java?p2=archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrRepositorySessionFactory.java&p1=archiva/trunk/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileRepositorySessionFactory.java&r1=1053542&r2=1053630&rev=1053630&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileRepositorySessionFactory.java
(original)
+++ archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrRepositorySessionFactory.java
Wed Dec 29 13:02:59 2010
@@ -1,4 +1,4 @@
-package org.apache.archiva.metadata.repository.file;
+package org.apache.archiva.metadata.repository.jcr;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -24,15 +24,18 @@ import org.apache.archiva.metadata.repos
 import org.apache.archiva.metadata.repository.MetadataResolver;
 import org.apache.archiva.metadata.repository.RepositorySession;
 import org.apache.archiva.metadata.repository.RepositorySessionFactory;
-import org.apache.maven.archiva.configuration.ArchivaConfiguration;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
 
 import java.util.Map;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
 
 /**
- * @plexus.component role="org.apache.archiva.metadata.repository.RepositorySessionFactory"
role-hint="file"
+ * @plexus.component role="org.apache.archiva.metadata.repository.RepositorySessionFactory"
role-hint="jcr"
  */
-public class FileRepositorySessionFactory
-    implements RepositorySessionFactory
+public class JcrRepositorySessionFactory
+    implements RepositorySessionFactory, Initializable
 {
     /**
      * @plexus.requirement role="org.apache.archiva.metadata.model.MetadataFacetFactory"
@@ -42,7 +45,7 @@ public class FileRepositorySessionFactor
     /**
      * @plexus.requirement
      */
-    private ArchivaConfiguration configuration;
+    private Repository repository;
 
     /**
      * @plexus.requirement
@@ -51,8 +54,43 @@ public class FileRepositorySessionFactor
 
     public RepositorySession createSession()
     {
-        MetadataRepository metadataRepository = new FileMetadataRepository( metadataFacetFactories,
configuration );
+        try
+        {
+            // FIXME: is this the right separation? or should a JCR session object contain
the JCR session information?
+            //  such a change might allow us to avoid creating two objects for each request.
It would also clear up
+            //  the ambiguities in the API where session & repository are the inverse
of JCR; and the resolver is
+            //  retrieved from the session but must have it passed in. These should be reviewed
before finalising the
+            //  API.
+            MetadataRepository metadataRepository = new JcrMetadataRepository( metadataFacetFactories,
repository );
+
+            return new RepositorySession( metadataRepository, metadataResolver );
+        }
+        catch ( RepositoryException e )
+        {
+            // FIXME: a custom exception requires refactoring for callers to handle it
+            throw new RuntimeException( e );
+        }
+    }
 
-        return new RepositorySession( metadataRepository, metadataResolver );
+    public void initialize()
+        throws InitializationException
+    {
+        JcrMetadataRepository metadataRepository = null;
+        try
+        {
+            metadataRepository = new JcrMetadataRepository( metadataFacetFactories, repository
);
+            JcrMetadataRepository.initialize( metadataRepository.getJcrSession() );
+        }
+        catch ( RepositoryException e )
+        {
+            throw new InitializationException( e.getMessage(), e );
+        }
+        finally
+        {
+            if ( metadataRepository != null )
+            {
+                metadataRepository.close();
+            }
+        }
     }
 }

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=1053630&r1=1053629&r2=1053630&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 29 13:02:59 2010
@@ -21,11 +21,12 @@ 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;
+import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 
 public class JcrMetadataRepositoryTest
     extends AbstractMetadataRepositoryTest
@@ -41,14 +42,19 @@ public class JcrMetadataRepositoryTest
 
         Map<String, MetadataFacetFactory> factories = createTestMetadataFacetFactories();
 
-        jcrMetadataRepository = (JcrMetadataRepository) lookup( MetadataRepository.class
);
-        jcrMetadataRepository.setMetadataFacetFactories( factories );
-        jcrMetadataRepository.login();
+        // TODO: probably don't need to use Spring for this
+        Repository repository = (Repository) lookup( Repository.class );
+        jcrMetadataRepository = new JcrMetadataRepository( factories, repository );
 
-        // removing content is faster than deleting and re-copying the files from target/jcr
         try
         {
-            jcrMetadataRepository.getJcrSession().getRootNode().getNode( "repositories" ).remove();
+            Session session = jcrMetadataRepository.getJcrSession();
+
+            // set up namespaces, etc.
+            JcrMetadataRepository.initialize( session );
+
+            // removing content is faster than deleting and re-copying the files from target/jcr
+            session.getRootNode().getNode( "repositories" ).remove();
         }
         catch ( RepositoryException e )
         {

Modified: archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/test/repository.xml
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/test/repository.xml?rev=1053630&r1=1053629&r2=1053630&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/test/repository.xml (original)
+++ archiva/trunk/archiva-modules/plugins/metadata-store-jcr/src/test/repository.xml Wed Dec
29 13:02:59 2010
@@ -32,8 +32,6 @@
   </Security>
   <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default"/>
   <Workspace name="${wsp.name}">
-    <!--<FileSystem class="org.apache.jackrabbit.core.fs.mem.MemoryFileSystem"/>-->
-    <!--<PersistenceManager class="org.apache.jackrabbit.core.persistence.mem.InMemPersistenceManager"/>-->
     <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
       <param name="path" value="${wsp.home}"/>
     </FileSystem>



Mime
View raw message