Adding jcr oak implementation

This commit is contained in:
Martin Stockhammer 2017-06-21 23:52:17 +02:00 committed by olivier lamy
parent 42df217cd0
commit 7d2cc26b4b
20 changed files with 537 additions and 209 deletions

View File

@ -66,10 +66,30 @@
<dependency> <dependency>
<groupId>commons-io</groupId> <groupId>commons-io</groupId>
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queryparser</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-common</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.maven.indexer</groupId> <groupId>org.apache.maven.indexer</groupId>
<artifactId>indexer-core</artifactId> <artifactId>indexer-core</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queryparser</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-common</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>javax.inject</groupId> <groupId>javax.inject</groupId>
@ -110,21 +130,6 @@
<artifactId>metadata-store-jcr</artifactId> <artifactId>metadata-store-jcr</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-core</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency> <dependency>
<groupId>xerces</groupId> <groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId> <artifactId>xercesImpl</artifactId>

View File

@ -59,6 +59,7 @@
<alias name="roleManager#test" alias="roleManager"/> <alias name="roleManager#test" alias="roleManager"/>
<!--
<bean id="jcr-config" class="org.apache.archiva.metadata.repository.jcr.ArchivaJcrRepositoryConfig" factory-method="create"> <bean id="jcr-config" class="org.apache.archiva.metadata.repository.jcr.ArchivaJcrRepositoryConfig" factory-method="create">
<constructor-arg value="${appserver.base}/conf/repository.xml"/> <constructor-arg value="${appserver.base}/conf/repository.xml"/>
<constructor-arg value="${appserver.base}/data/jcr"/> <constructor-arg value="${appserver.base}/data/jcr"/>
@ -67,7 +68,7 @@
<bean id="jcr-repository" class="org.apache.jackrabbit.core.RepositoryImpl" destroy-method="shutdown" lazy-init="true"> <bean id="jcr-repository" class="org.apache.jackrabbit.core.RepositoryImpl" destroy-method="shutdown" lazy-init="true">
<constructor-arg ref="jcr-config"/> <constructor-arg ref="jcr-config"/>
</bean> </bean>
-->
</beans> </beans>

View File

@ -85,6 +85,16 @@
<dependency> <dependency>
<groupId>org.apache.maven.indexer</groupId> <groupId>org.apache.maven.indexer</groupId>
<artifactId>indexer-core</artifactId> <artifactId>indexer-core</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queryparser</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-common</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.eclipse.sisu</groupId> <groupId>org.eclipse.sisu</groupId>

View File

@ -58,6 +58,16 @@
<dependency> <dependency>
<groupId>org.apache.maven.indexer</groupId> <groupId>org.apache.maven.indexer</groupId>
<artifactId>indexer-core</artifactId> <artifactId>indexer-core</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queryparser</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-common</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.codehaus.plexus</groupId> <groupId>org.codehaus.plexus</groupId>

View File

@ -73,6 +73,14 @@
<groupId>com.google.code.atinject</groupId> <groupId>com.google.code.atinject</groupId>
<artifactId>atinject</artifactId> <artifactId>atinject</artifactId>
</exclusion> </exclusion>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queryparser</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-common</artifactId>
</exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -44,6 +44,16 @@
<dependency> <dependency>
<groupId>org.apache.maven.indexer</groupId> <groupId>org.apache.maven.indexer</groupId>
<artifactId>indexer-core</artifactId> <artifactId>indexer-core</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queryparser</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-common</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>

View File

@ -328,22 +328,6 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-core</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency> <dependency>
<groupId>org.apache.lucene</groupId> <groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId> <artifactId>lucene-core</artifactId>

View File

@ -368,21 +368,6 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-core</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency> <dependency>
<groupId>org.assertj</groupId> <groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId> <artifactId>assertj-core</artifactId>

View File

@ -130,29 +130,6 @@
<artifactId>metadata-store-cassandra</artifactId> <artifactId>metadata-store-cassandra</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-jcr-commons</artifactId>
</dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-core</artifactId>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency> <dependency>
<groupId>commons-configuration</groupId> <groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId> <artifactId>commons-configuration</artifactId>

View File

@ -37,6 +37,7 @@
<util:properties id="archivaRuntimeProperties" location="classpath:application.properties" /> <util:properties id="archivaRuntimeProperties" location="classpath:application.properties" />
<!--
<bean id="jcr-repository" class="org.apache.jackrabbit.core.RepositoryImpl" destroy-method="shutdown" lazy-init="true"> <bean id="jcr-repository" class="org.apache.jackrabbit.core.RepositoryImpl" destroy-method="shutdown" lazy-init="true">
<constructor-arg ref="jcr-config"/> <constructor-arg ref="jcr-config"/>
</bean> </bean>
@ -46,7 +47,7 @@
<constructor-arg value="${appserver.base}/conf/repository.xml"/> <constructor-arg value="${appserver.base}/conf/repository.xml"/>
<constructor-arg value="${appserver.base}/data/jcr"/> <constructor-arg value="${appserver.base}/data/jcr"/>
</bean> </bean>
-->
<jee:jndi-lookup id="dataSource" jndi-name="java:/comp/env/jdbc/users" /> <jee:jndi-lookup id="dataSource" jndi-name="java:/comp/env/jdbc/users" />

View File

@ -94,16 +94,6 @@
<groupId>org.apache.archiva</groupId> <groupId>org.apache.archiva</groupId>
<artifactId>archiva-filelock</artifactId> <artifactId>archiva-filelock</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-webdav</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency> <dependency>
<groupId>joda-time</groupId> <groupId>joda-time</groupId>
<artifactId>joda-time</artifactId> <artifactId>joda-time</artifactId>
@ -298,8 +288,6 @@
org.apache.archiva.metadata.repository.storage;version=${project.version}, org.apache.archiva.metadata.repository.storage;version=${project.version},
org.apache.commons.io;version="[1.4,2)", org.apache.commons.io;version="[1.4,2)",
org.apache.commons.lang;version="[2.4,3)", org.apache.commons.lang;version="[2.4,3)",
org.apache.jackrabbit.util;version="[1,3)",
org.apache.jackrabbit.webdav*;version="[1,3)",
org.joda.time*;version="[1.5,2)", org.joda.time*;version="[1.5,2)",
org.springframework*;version="[3,4)", org.springframework*;version="[3,4)",
org.apache.maven.index*, org.apache.maven.index*,

View File

@ -28,6 +28,9 @@
<artifactId>metadata-store-jcr</artifactId> <artifactId>metadata-store-jcr</artifactId>
<packaging>bundle</packaging> <packaging>bundle</packaging>
<name>Archiva Core Plugins :: JCR Storage for Metadata</name> <name>Archiva Core Plugins :: JCR Storage for Metadata</name>
<properties>
<jcr-oak.version>1.7.1</jcr-oak.version>
</properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.apache.archiva</groupId> <groupId>org.apache.archiva</groupId>
@ -48,6 +51,12 @@
<artifactId>archiva-test-utils</artifactId> <artifactId>archiva-test-utils</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<scope>test</scope> <scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>javax.jcr</groupId> <groupId>javax.jcr</groupId>
@ -55,24 +64,41 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.jackrabbit</groupId> <groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-jcr-commons</artifactId> <artifactId>oak-jcr</artifactId>
<version>${jcr-oak.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.jackrabbit</groupId> <groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-core</artifactId> <artifactId>oak-segment-tar</artifactId>
<scope>provided</scope> <version>${jcr-oak.version}</version>
<!-- could trim more, but since it's just for test we don't need to worry --> </dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>oak-lucene</artifactId>
<version>${jcr-oak.version}</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
<groupId>org.slf4j</groupId> <groupId>org.apache.lucene</groupId>
<artifactId>jcl-over-slf4j</artifactId> <artifactId>lucene-misc</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-facet</artifactId>
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId> <artifactId>log4j-jcl</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId> <artifactId>spring-test</artifactId>
@ -98,6 +124,51 @@
<artifactId>xercesImpl</artifactId> <artifactId>xercesImpl</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-misc</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-facet</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-codecs</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queryparser</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-sandbox</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-highlighter</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-memory</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-common</artifactId>
<version>${lucene.version}</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<testResources> <testResources>
@ -126,8 +197,6 @@
org.apache.archiva.metadata.model;version=${project.version}, org.apache.archiva.metadata.model;version=${project.version},
org.apache.archiva.metadata.repository;version=${project.version}, org.apache.archiva.metadata.repository;version=${project.version},
org.apache.commons.lang;version="[2.4,3)", org.apache.commons.lang;version="[2.4,3)",
org.apache.jackrabbit.commons;version="[2.3,3)",
org.apache.jackrabbit.core.config,
org.springframework*;version="[3,4)", org.springframework*;version="[3,4)",
org.slf4j;resolution:=optional, org.slf4j;resolution:=optional,
org.apache.commons.lang.time org.apache.commons.lang.time

View File

@ -1,64 +0,0 @@
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.jackrabbit.core.config.ConfigurationException;
import org.apache.jackrabbit.core.config.RepositoryConfig;
import org.slf4j.LoggerFactory;
import java.io.File;
/**
* @author Olivier Lamy
* @since 1.4-M1
*/
public class ArchivaJcrRepositoryConfig
{
// Recommended to avoid inconsistencies caused by race conditions.
static
{
if ( !System.getProperties( ).containsKey( "org.apache.jackrabbit.core.state.validatehierarchy" ) )
{
System.setProperty( "org.apache.jackrabbit.core.state.validatehierarchy", "true" );
}
}
public static RepositoryConfig create( String file, String home )
throws ConfigurationException
{
File homeFile = new File( home );
if ( !homeFile.exists( ) )
{
homeFile.mkdirs( );
}
File configurationFile = new File( file );
if ( !configurationFile.exists( ) )
{
String resourcePath = "org/apache/archiva/metadata/repository/jcr/repository.xml";
LoggerFactory.getLogger( ArchivaJcrRepositoryConfig.class ).info(
"no repository.xml file in path {} so use default from resources path {}", file, resourcePath );
// use bundled repository.xml
return RepositoryConfig.create(
Thread.currentThread( ).getContextClassLoader( ).getResourceAsStream( resourcePath ), home );
}
return RepositoryConfig.create( file, home );
}
}

View File

@ -37,6 +37,8 @@ import org.apache.archiva.metadata.repository.MetadataRepositoryException;
import org.apache.archiva.metadata.repository.MetadataResolutionException; import org.apache.archiva.metadata.repository.MetadataResolutionException;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.jackrabbit.commons.JcrUtils; import org.apache.jackrabbit.commons.JcrUtils;
import org.apache.jackrabbit.oak.plugins.index.IndexUtils;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -139,6 +141,8 @@ public class JcrMetadataRepository
registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.FACET_NODE_TYPE ); registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.FACET_NODE_TYPE );
registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.DEPENDENCY_NODE_TYPE ); registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.DEPENDENCY_NODE_TYPE );
} }
private static void registerMixinNodeType( NodeTypeManager nodeTypeManager, String name ) private static void registerMixinNodeType( NodeTypeManager nodeTypeManager, String name )
@ -156,6 +160,8 @@ public class JcrMetadataRepository
} }
} }
@Override @Override
public void updateProject( String repositoryId, ProjectMetadata project ) public void updateProject( String repositoryId, ProjectMetadata project )
throws MetadataRepositoryException throws MetadataRepositoryException
@ -755,6 +761,10 @@ public class JcrMetadataRepository
{ {
throw new MetadataRepositoryException( e.getMessage(), e ); throw new MetadataRepositoryException( e.getMessage(), e );
} }
log.info("Artifacts found {}", artifacts.size());
for (ArtifactMetadata meta : artifacts) {
log.info("Artifact: "+meta.getVersion()+" "+meta.getFacetList());
}
return artifacts; return artifacts;
} }
@ -1418,11 +1428,9 @@ public class JcrMetadataRepository
} }
@Override @Override
public List<ArtifactMetadata> searchArtifacts( String key, String text, String repositoryId, boolean exact ) public List<ArtifactMetadata> searchArtifacts( String key, String text, String repositoryId, boolean e )
throws MetadataRepositoryException throws MetadataRepositoryException
{ {
// we can't do exact search in any property (*), we need a key
boolean e = exact && key != null;
String theKey = key == null ? "*" : "[" + key + "]"; String theKey = key == null ? "*" : "[" + key + "]";
String projectVersionCondition = String projectVersionCondition =
e ? "(projectVersion." + theKey + " = $value)" : "contains([projectVersion]." + theKey + ", $value)"; e ? "(projectVersion." + theKey + " = $value)" : "contains([projectVersion]." + theKey + ", $value)";
@ -1432,7 +1440,6 @@ public class JcrMetadataRepository
+ ARTIFACT_NODE_TYPE + "] AS artifact ON ISCHILDNODE(artifact, projectVersion) LEFT OUTER JOIN [" + ARTIFACT_NODE_TYPE + "] AS artifact ON ISCHILDNODE(artifact, projectVersion) LEFT OUTER JOIN ["
+ FACET_NODE_TYPE + "] AS facet ON ISCHILDNODE(facet, projectVersion) WHERE (" + FACET_NODE_TYPE + "] AS facet ON ISCHILDNODE(facet, projectVersion) WHERE ("
+ projectVersionCondition + " OR " + facetCondition + ")"; + projectVersionCondition + " OR " + facetCondition + ")";
return runJcrQuery( repositoryId, q, ImmutableMap.of( "value", text ) ); return runJcrQuery( repositoryId, q, ImmutableMap.of( "value", text ) );
} }
@ -1555,7 +1562,7 @@ public class JcrMetadataRepository
private static String getRepositoryContentPath( String repositoryId ) private static String getRepositoryContentPath( String repositoryId )
{ {
return getRepositoryPath( repositoryId ) + "/content/"; return getRepositoryPath( repositoryId ) + "/content";
} }
private static String getFacetPath( String repositoryId, String facetId ) private static String getFacetPath( String repositoryId, String facetId )
@ -1565,7 +1572,7 @@ public class JcrMetadataRepository
private static String getNamespacePath( String repositoryId, String namespace ) private static String getNamespacePath( String repositoryId, String namespace )
{ {
return getRepositoryContentPath( repositoryId ) + namespace.replace( '.', '/' ); return getRepositoryContentPath( repositoryId ) + "/" + namespace.replace( '.', '/' );
} }
private static String getProjectPath( String repositoryId, String namespace, String projectId ) private static String getProjectPath( String repositoryId, String namespace, String projectId )
@ -1594,6 +1601,7 @@ public class JcrMetadataRepository
private Node getOrAddNodeByPath( Node baseNode, String name, String nodeType ) private Node getOrAddNodeByPath( Node baseNode, String name, String nodeType )
throws RepositoryException throws RepositoryException
{ {
log.debug("getOrAddNodeByPath"+baseNode+" "+name+" "+nodeType);
Node node = baseNode; Node node = baseNode;
for ( String n : name.split( "/" ) ) for ( String n : name.split( "/" ) )
{ {
@ -1614,8 +1622,10 @@ public class JcrMetadataRepository
private Node getOrAddRepositoryNode( String repositoryId ) private Node getOrAddRepositoryNode( String repositoryId )
throws RepositoryException throws RepositoryException
{ {
log.debug("getOrAddRepositoryNode "+repositoryId);
Node root = getJcrSession().getRootNode(); Node root = getJcrSession().getRootNode();
Node node = JcrUtils.getOrAddNode( root, "repositories" ); Node node = JcrUtils.getOrAddNode( root, "repositories" );
log.debug("Repositories "+node);
node = JcrUtils.getOrAddNode( node, repositoryId ); node = JcrUtils.getOrAddNode( node, repositoryId );
return node; return node;
} }

View File

@ -0,0 +1,285 @@
package org.apache.archiva.metadata.repository.jcr;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.util.concurrent.MoreExecutors;
import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.oak.Oak;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.jcr.Jcr;
import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
import org.apache.jackrabbit.oak.plugins.index.IndexUtils;
import org.apache.jackrabbit.oak.plugins.index.lucene.ExtractedTextCache;
import org.apache.jackrabbit.oak.plugins.index.lucene.IndexCopier;
import org.apache.jackrabbit.oak.plugins.index.lucene.IndexTracker;
import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorProvider;
import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexProvider;
import org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.DocumentQueue;
import org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.ExternalObserverBuilder;
import org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.LocalIndexObserver;
import org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.NRTIndexFactory;
import org.apache.jackrabbit.oak.plugins.index.lucene.reader.DefaultIndexReaderFactory;
import org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneInitializerHelper;
import org.apache.jackrabbit.oak.segment.SegmentNodeStore;
import org.apache.jackrabbit.oak.segment.SegmentNodeStoreBuilders;
import org.apache.jackrabbit.oak.segment.file.FileStore;
import org.apache.jackrabbit.oak.segment.file.FileStoreBuilder;
import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
import org.apache.jackrabbit.oak.spi.commit.Observer;
import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
import org.apache.jackrabbit.oak.spi.mount.MountInfoProvider;
import org.apache.jackrabbit.oak.spi.mount.Mounts;
import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeStore;
import org.apache.jackrabbit.oak.stats.StatisticsProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
import javax.jcr.Repository;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME;
import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.INCLUDE_PROPERTY_TYPES;
/**
* Created by martin on 14.06.17.
*
* @author Martin Stockhammer
* @since 3.0.0
*/
public class RepositoryFactory
{
Logger log = LoggerFactory.getLogger( RepositoryFactory.class );
public static final String SEGMENT_FILE_TYPE = "oak-segment-tar";
public static final String IN_MEMORY_TYPE = "oak-memory";
String storeType = SEGMENT_FILE_TYPE;
Path repositoryPath = Paths.get( "repository" );
public Repository createRepository( ) throws IOException, InvalidFileStoreVersionException
{
NodeStore nodeStore;
if ( SEGMENT_FILE_TYPE.equals( storeType ) )
{
FileStore fs = FileStoreBuilder.fileStoreBuilder( repositoryPath.toFile( ) ).build( );
nodeStore = SegmentNodeStoreBuilders.builder( fs ).build( );
} else if (IN_MEMORY_TYPE.equals(storeType)) {
nodeStore = null;
} else {
throw new IllegalArgumentException( "Store type "+storeType+" not recognized" );
}
Oak oak = nodeStore==null ? new Oak() : new Oak(nodeStore);
oak.with( new RepositoryInitializer( )
{
@Override
public void initialize( @Nonnull NodeBuilder root )
{
log.info("Creating index ");
NodeBuilder lucene = IndexUtils.getOrCreateOakIndex( root ).child("lucene");
lucene.setProperty( JcrConstants.JCR_PRIMARYTYPE, "oak:QueryIndexDefinition", Type.NAME);
lucene.setProperty("compatVersion", 2);
lucene.setProperty("type", "lucene");
// lucene.setProperty("async", "async");
lucene.setProperty(INCLUDE_PROPERTY_TYPES,
ImmutableSet.of("String"), Type.STRINGS);
// lucene.setProperty("refresh",true);
lucene.setProperty("async",ImmutableSet.of("async", "sync"), Type.STRINGS);
NodeBuilder rules = lucene.child("indexRules").
setProperty(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED, Type.NAME);
rules.setProperty(":childOrder",ImmutableSet.of("archiva:projectVersion","archiva:artifact",
"archiva:facet","archiva:namespace", "archiva:project"), Type.STRINGS);
NodeBuilder allProps = rules.child("archiva:projectVersion")
.child("properties").setProperty( JcrConstants.JCR_PRIMARYTYPE,
"nt:unstructured", Type.NAME)
.setProperty( ":childOrder", ImmutableSet.of("allProps"), Type.STRINGS )
.setProperty("indexNodeName",true)
.child("allProps").setProperty(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED, Type.NAME);
allProps.setProperty("name", ".*");
allProps.setProperty("isRegexp", true);
allProps.setProperty("nodeScopeIndex", true);
allProps.setProperty("index",true);
allProps.setProperty("analyzed",true);
// allProps.setProperty("propertyIndex",true);
allProps = rules.child("archiva:artifact")
.child("properties").setProperty( JcrConstants.JCR_PRIMARYTYPE,
"nt:unstructured", Type.NAME)
.setProperty( ":childOrder", ImmutableSet.of("allProps"), Type.STRINGS )
.setProperty("indexNodeName",true)
.child("allProps").setProperty(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED, Type.NAME);
allProps.setProperty("name", ".*");
allProps.setProperty("isRegexp", true);
allProps.setProperty("nodeScopeIndex", true);
allProps.setProperty("index",true);
allProps.setProperty("analyzed",true);
allProps = rules.child("archiva:facet")
.child("properties").setProperty( JcrConstants.JCR_PRIMARYTYPE,
"nt:unstructured", Type.NAME)
.setProperty( ":childOrder", ImmutableSet.of("allProps"), Type.STRINGS )
.setProperty("indexNodeName",true)
.child("allProps").setProperty(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED, Type.NAME);
allProps.setProperty("name", ".*");
allProps.setProperty("isRegexp", true);
allProps.setProperty("nodeScopeIndex", true);
allProps.setProperty("index",true);
allProps.setProperty("analyzed",true);
allProps = rules.child("archiva:namespace")
.child("properties").setProperty( JcrConstants.JCR_PRIMARYTYPE,
"nt:unstructured", Type.NAME)
.setProperty( ":childOrder", ImmutableSet.of("allProps"), Type.STRINGS )
.setProperty("indexNodeName",true)
.child("allProps").setProperty(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED, Type.NAME);
allProps.setProperty("name", ".*");
allProps.setProperty("isRegexp", true);
allProps.setProperty("nodeScopeIndex", true);
allProps.setProperty("index",true);
allProps.setProperty("analyzed",true);
allProps = rules.child("archiva:project")
.child("properties").setProperty( JcrConstants.JCR_PRIMARYTYPE,
"nt:unstructured", Type.NAME)
.setProperty( ":childOrder", ImmutableSet.of("allProps"), Type.STRINGS )
.setProperty("indexNodeName",true)
.child("allProps").setProperty(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED, Type.NAME);
allProps.setProperty("name", ".*");
allProps.setProperty("isRegexp", true);
allProps.setProperty("nodeScopeIndex", true);
allProps.setProperty("index",true);
allProps.setProperty("analyzed",true);
log.info("Index: "+lucene+" myIndex "+lucene.getChildNode( "myIndex" ));
log.info("myIndex "+lucene.getChildNode( "myIndex" ).getProperties());
// IndexUtils.createIndexDefinition( )
}
} );
ExecutorService executorService = createExecutor();
StatisticsProvider statsProvider = StatisticsProvider.NOOP;
int queueSize = Integer.getInteger("queueSize", 10000);
File indexDir = Files.createTempDirectory( "archiva_index" ).toFile();
log.info("Queue Index "+indexDir.toString());
IndexCopier indexCopier = new IndexCopier( executorService, indexDir, true );
NRTIndexFactory nrtIndexFactory = new NRTIndexFactory( indexCopier, statsProvider);
MountInfoProvider mountInfoProvider = Mounts.defaultMountInfoProvider( );
IndexTracker tracker = new IndexTracker(new DefaultIndexReaderFactory( mountInfoProvider, indexCopier ), nrtIndexFactory);
DocumentQueue queue = new DocumentQueue(queueSize, tracker, executorService, statsProvider);
LocalIndexObserver localIndexObserver = new LocalIndexObserver( queue, statsProvider);
LuceneIndexProvider provider = new LuceneIndexProvider(tracker);
// ExternalObserverBuilder builder = new ExternalObserverBuilder(queue, tracker, statsProvider,
// executorService, queueSize);
// Observer observer = builder.build();
// builder.getBackgroundObserver();
LuceneIndexEditorProvider editorProvider = new LuceneIndexEditorProvider(null,
tracker, new ExtractedTextCache(0, 0), null, mountInfoProvider);
editorProvider.setIndexingQueue(queue);
log.info("Oak: "+oak+" with nodeStore "+nodeStore);
Jcr jcr = new Jcr(oak).with( editorProvider ).with( (Observer) provider )
.with(localIndexObserver)
// .with(observer)
.with( ( QueryIndexProvider) provider )
.withAsyncIndexing("async",5 );
Repository r = jcr.createRepository();
try
{
Thread.currentThread().sleep(1000);
}
catch ( InterruptedException e )
{
e.printStackTrace( );
}
return r;
}
public String getStoreType( )
{
return storeType;
}
public void setStoreType( String storeType )
{
this.storeType = storeType;
}
public Path getRepositoryPath( )
{
return repositoryPath;
}
public void setRepositoryPath( Path repositoryPath )
{
this.repositoryPath = repositoryPath;
}
public void setRepositoryPath( String repositoryPath )
{
this.repositoryPath = Paths.get( repositoryPath );
if ( !Files.exists( this.repositoryPath ) )
{
try
{
Files.createDirectories( this.repositoryPath );
}
catch ( IOException e )
{
e.printStackTrace( );
}
}
}
private ExecutorService createExecutor() {
ThreadPoolExecutor executor = new ThreadPoolExecutor(0, 5, 60L, TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>(), new ThreadFactory() {
private final AtomicInteger counter = new AtomicInteger();
private final Thread.UncaughtExceptionHandler handler = new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
log.warn("Error occurred in asynchronous processing ", e);
}
};
@Override
public Thread newThread(@Nonnull Runnable r) {
Thread thread = new Thread(r, createName());
thread.setDaemon(true);
thread.setPriority(Thread.MIN_PRIORITY);
thread.setUncaughtExceptionHandler(handler);
return thread;
}
private String createName() {
return "oak-lucene-" + counter.getAndIncrement();
}
});
executor.setKeepAliveTime(1, TimeUnit.MINUTES);
executor.allowCoreThreadTimeOut(true);
return executor;
}
}

View File

@ -0,0 +1,42 @@
<?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.
-->
<configuration status="debug">
<appenders>
<Console name="console" target="SYSTEM_OUT">
<!--PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/-->
<PatternLayout pattern="%highlight{%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n}" />
</Console>
</appenders>
<loggers>
<logger name="org.apache.jackrabbit" level="trace"/>
<root level="debug" includeLocation="true">
<appender-ref ref="console"/>
</root>
</loggers>
</configuration>

View File

@ -19,14 +19,14 @@
--> -->
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<bean id="repository" class="org.apache.jackrabbit.core.RepositoryImpl" destroy-method="shutdown"> <bean id="repositoryFactory" class="org.apache.archiva.metadata.repository.jcr.RepositoryFactory" >
<constructor-arg ref="config"/> <property name="storeType" value="oak-segment-tar" />
</bean> </bean>
<bean id="config" class="org.apache.jackrabbit.core.config.RepositoryConfig" factory-method="create">
<constructor-arg value="${basedir}/src/test/repository.xml"/> <bean id="repository" class="org.apache.archiva.metadata.repository.jcr.RepositoryFactory" factory-method="createRepository"
<constructor-arg value="${project.build.directory}/jcr"/> factory-bean="repositoryFactory">
</bean> </bean>
</beans> </beans>

View File

@ -0,0 +1,42 @@
<?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.
-->
<configuration status="debug">
<appenders>
<Console name="console" target="SYSTEM_OUT">
<!--PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/-->
<PatternLayout pattern="%highlight{%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n}" />
</Console>
</appenders>
<loggers>
<logger name="org.apache.jackrabbit" level="trace"/>
<root level="debug" includeLocation="true">
<appender-ref ref="console"/>
</root>
</loggers>
</configuration>

View File

@ -44,10 +44,6 @@
<groupId>javax.jcr</groupId> <groupId>javax.jcr</groupId>
<artifactId>jcr</artifactId> <artifactId>jcr</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-jcr-commons</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.apache.archiva</groupId> <groupId>org.apache.archiva</groupId>
<artifactId>archiva-test-utils</artifactId> <artifactId>archiva-test-utils</artifactId>
@ -59,17 +55,6 @@
<artifactId>log4j-jcl</artifactId> <artifactId>log4j-jcl</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-core</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-all</artifactId>
@ -96,7 +81,6 @@
<Import-Package> <Import-Package>
javax.jcr, javax.jcr,
javax.jcr.query, javax.jcr.query,
org.apache.jackrabbit.commons;version="[2.3,3)",
org.apache.archiva.metadata.model;version=${project.version}, org.apache.archiva.metadata.model;version=${project.version},
org.apache.archiva.metadata.repository;version=${project.version}, org.apache.archiva.metadata.repository;version=${project.version},
org.apache.archiva.metadata.repository.storage.maven2;version=${project.version}, org.apache.archiva.metadata.repository.storage.maven2;version=${project.version},

31
pom.xml
View File

@ -51,7 +51,7 @@
<commons-codec.version>1.6</commons-codec.version> <commons-codec.version>1.6</commons-codec.version>
<commons-collections.version>3.2.1</commons-collections.version> <commons-collections.version>3.2.1</commons-collections.version>
<commons-fileupload.version>1.2.2</commons-fileupload.version> <commons-fileupload.version>1.2.2</commons-fileupload.version>
<commons-io.version>2.4</commons-io.version> <commons-io.version>2.5</commons-io.version>
<commons-lang.version>2.6</commons-lang.version> <commons-lang.version>2.6</commons-lang.version>
<maven3x.version>3.0.5</maven3x.version> <maven3x.version>3.0.5</maven3x.version>
@ -59,7 +59,8 @@
<aether.version>1.13.1</aether.version> <aether.version>1.13.1</aether.version>
<maven-model-converter.version>2.1</maven-model-converter.version> <maven-model-converter.version>2.1</maven-model-converter.version>
<maven.indexer.version>5.1.1</maven.indexer.version> <!-- TODO: Before Release 3.0 check, if stable version will be released -->
<maven.indexer.version>6.0-SNAPSHOT</maven.indexer.version>
<wagon.version>2.9</wagon.version> <wagon.version>2.9</wagon.version>
<redback.version>3.0.0-SNAPSHOT</redback.version> <redback.version>3.0.0-SNAPSHOT</redback.version>
<redback.cache.version>2.2</redback.cache.version> <redback.cache.version>2.2</redback.cache.version>
@ -75,7 +76,7 @@
<javax.jcr.version>2.0</javax.jcr.version> <javax.jcr.version>2.0</javax.jcr.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<surefire.redirectTestOutputToFile>true</surefire.redirectTestOutputToFile> <surefire.redirectTestOutputToFile>true</surefire.redirectTestOutputToFile>
<lucene.version>3.6.2</lucene.version> <lucene.version>4.10.4</lucene.version>
<jackrabbit.version>2.14.1</jackrabbit.version> <jackrabbit.version>2.14.1</jackrabbit.version>
<cxf.version>3.0.3</cxf.version> <cxf.version>3.0.3</cxf.version>
@ -126,17 +127,6 @@
<version>1.7.1</version> <version>1.7.1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-webdav</artifactId>
<version>${jackrabbit.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency> <dependency>
<groupId>xerces</groupId> <groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId> <artifactId>xercesImpl</artifactId>
@ -1317,16 +1307,7 @@
<artifactId>jcr</artifactId> <artifactId>jcr</artifactId>
<version>${javax.jcr.version}</version> <version>${javax.jcr.version}</version>
</dependency> </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>
</dependency>
<!-- Transitive versions to manage --> <!-- Transitive versions to manage -->
<dependency> <dependency>
@ -1623,7 +1604,7 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<configuration> <configuration>
<argLine>@{jacocoproperty}</argLine> <argLine></argLine>
<redirectTestOutputToFile>${surefire.redirectTestOutputToFile}</redirectTestOutputToFile> <redirectTestOutputToFile>${surefire.redirectTestOutputToFile}</redirectTestOutputToFile>
<runOrder>alphabetical</runOrder> <runOrder>alphabetical</runOrder>
<systemPropertyVariables> <systemPropertyVariables>