import java.util.Date;
import java.util.List;
+// TODO: remove, it does nothing
public class TestMetadataRepository
implements MetadataRepository
{
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;
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;
testConsumer = (TestConsumer) lookup( KnownRepositoryContentConsumer.class, "test-consumer" );
metadataRepository = mock( MetadataRepository.class );
+
+ TestRepositorySessionFactory factory = (TestRepositorySessionFactory) lookup( RepositorySessionFactory.class );
+ factory.setRepository( metadataRepository );
}
protected void tearDown()
return artifact;
}
+ // TODO: replace with mockito
private class MetadataRepositoryMock
implements MetadataRepository
{
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();
return artifacts;
}
+ public void save()
+ {
+ }
+
+ public void close()
+ {
+ }
+
+ public void revert()
+ {
+ throw new UnsupportedOperationException();
+ }
+
public List<ArtifactMetadata> getArtifacts( String repositoryId )
{
return artifacts;
import java.util.Date;
import java.util.List;
+// TODO: remove - it does nothing
public class TestMetadataRepository
implements MetadataRepository
{
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;
Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId,
String projectVersion )
throws MetadataResolutionException;
+
+ void save()
+ throws MetadataRepositoryException;
+
+ void close();
+
+ void revert()
+ throws MetadataRepositoryException;
}
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;
}
save();
}
- // FIXME
+ repository.close();
}
public void markDirty()
{
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
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;
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() + ":";
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-spring</artifactId>
- <scope>test</scope>
</dependency>
<!-- FIXME: dependency management -->
<dependency>
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;
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
*/
{
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 )
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 )
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 )
--- /dev/null
+package org.apache.archiva.metadata.repository.jcr;
+
+/*
+ * 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.
+ */
+
+import org.apache.archiva.metadata.model.MetadataFacetFactory;
+import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.apache.archiva.metadata.repository.MetadataResolver;
+import org.apache.archiva.metadata.repository.RepositorySession;
+import org.apache.archiva.metadata.repository.RepositorySessionFactory;
+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="jcr"
+ */
+public class JcrRepositorySessionFactory
+ implements RepositorySessionFactory, Initializable
+{
+ /**
+ * @plexus.requirement role="org.apache.archiva.metadata.model.MetadataFacetFactory"
+ */
+ private Map<String, MetadataFacetFactory> metadataFacetFactories;
+
+ /**
+ * @plexus.requirement
+ */
+ private Repository repository;
+
+ /**
+ * @plexus.requirement
+ */
+ private MetadataResolver metadataResolver;
+
+ public RepositorySession createSession()
+ {
+ 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 );
+ }
+ }
+
+ 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();
+ }
+ }
+ }
+}
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
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 )
{
</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>