]> source.dussan.org Git - archiva.git/commitdiff
Merge branch 'feature/jcr_oak'
authorolivier lamy <olamy@apache.org>
Sat, 19 Aug 2017 11:37:35 +0000 (21:37 +1000)
committerolivier lamy <olamy@apache.org>
Sat, 19 Aug 2017 11:37:35 +0000 (21:37 +1000)
12 files changed:
1  2 
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java
archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/pom.xml
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutor.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java
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/java/org/apache/archiva/metadata/repository/stats/JcrRepositoryStatisticsGatheringTest.java
archiva-modules/plugins/repository-statistics/pom.xml
pom.xml

index 8e71c4c89da218eb5b56140a0cc38c4a613be8be,43522a0cd635dc680f46cfa50fddddf6a205aa4c..60901138777b69db075ff403d53577f100b128eb
            </instructions>
          </configuration>
        </plugin>
++      <plugin>
++        <groupId>org.apache.maven.plugins</groupId>
++        <artifactId>maven-surefire-plugin</artifactId>
++        <configuration>
++          <systemPropertyVariables>
++            <appserver.base>${project.build.directory}/jcr/repo</appserver.base>
++          </systemPropertyVariables>
++        </configuration>
++      </plugin>
      </plugins>
    </build>
  </project>
index f8393b888f50ddb40b01a1b135f0e10a460fec7b,2bf94063fa4bda127ee56264881c23752c994e93..9fca6b84882cfea835f5716335f312511e02fd71
@@@ -36,10 -35,10 +36,12 @@@ import org.apache.archiva.metadata.mode
  import org.apache.archiva.metadata.repository.MetadataRepository;
  import org.apache.archiva.metadata.repository.MetadataRepositoryException;
  import org.apache.archiva.metadata.repository.MetadataResolutionException;
 +import org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics;
 +import org.apache.archiva.metadata.repository.stats.model.RepositoryStatisticsProvider;
  import org.apache.commons.lang.StringUtils;
  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.LoggerFactory;
  
index 63bfffb6fe15f955dd92d92cad9edfb90c2c3161,0000000000000000000000000000000000000000..be07e2e7361eba3ff43b091d33c7495006f438ea
mode 100644,000000..100644
--- /dev/null
@@@ -1,220 -1,0 +1,219 @@@
- import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
 +package org.apache.archiva.metadata.repository.stats;
 +
 +/*
 + * 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 junit.framework.TestCase;
 +import org.apache.archiva.metadata.model.MetadataFacetFactory;
 +import org.apache.archiva.metadata.repository.AbstractMetadataRepositoryTest;
 +import org.apache.archiva.metadata.repository.RepositorySessionFactory;
 +import org.apache.archiva.metadata.repository.jcr.JcrMetadataRepository;
++import org.apache.archiva.metadata.repository.jcr.RepositoryFactory;
 +import org.apache.archiva.metadata.repository.stats.model.DefaultRepositoryStatistics;
- import org.apache.jackrabbit.core.TransientRepository;
- import org.apache.jackrabbit.core.config.RepositoryConfig;
- import org.apache.regexp.RE;
 +import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
 +import org.apache.commons.io.FileUtils;
 +import org.apache.jackrabbit.commons.JcrUtils;
- import org.junit.Assert;
++import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
 +import org.junit.After;
- import javax.inject.Named;
 +import org.junit.Before;
++import org.junit.BeforeClass;
 +import org.junit.Test;
 +import org.junit.runner.RunWith;
 +import org.springframework.context.ApplicationContext;
 +import org.springframework.test.context.ContextConfiguration;
 +
 +import javax.inject.Inject;
- import javax.jcr.NamespaceRegistry;
 +import javax.jcr.ImportUUIDBehavior;
- import javax.jcr.SimpleCredentials;
- import javax.jcr.Workspace;
 +import javax.jcr.Node;
 +import javax.jcr.Repository;
 +import javax.jcr.RepositoryException;
 +import javax.jcr.Session;
- import static org.junit.Assert.assertEquals;
 +import javax.jcr.nodetype.NodeTypeManager;
 +import javax.jcr.nodetype.NodeTypeTemplate;
 +import java.io.File;
 +import java.io.IOException;
 +import java.util.Calendar;
 +import java.util.Date;
 +import java.util.Map;
 +import java.util.zip.GZIPInputStream;
 +
 +@RunWith( ArchivaSpringJUnit4ClassRunner.class )
 +@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
 +public class JcrRepositoryStatisticsGatheringTest extends TestCase
-     @Inject
-     @Named("repository")
-     Repository jcrRepository;
 +{
 +    private static final int TOTAL_FILE_COUNT = 1000;
 +
 +    private static final int NEW_FILE_COUNT = 500;
 +
 +    private static final String TEST_REPO = "test-repo";
 +
 +    JcrMetadataRepository repository;
 +
 +    @Inject
 +    private RepositorySessionFactory repositorySessionFactory;
 +
 +    @Inject
 +    private ApplicationContext applicationContext;
 +
-     @Before
-     public void setUp()
-         throws Exception
 +    Session session;
 +
 +
++    private static Repository jcrRepository;
 +
++    @BeforeClass
++    public static void setupSpec() throws IOException, InvalidFileStoreVersionException
 +    {
 +        File directory = new File( "target/test-repositories" );
 +        if ( directory.exists() )
 +        {
 +            FileUtils.deleteDirectory( directory );
 +        }
++        RepositoryFactory factory = new RepositoryFactory();
++        factory.setRepositoryPath( directory.getPath() );
++        factory.setStoreType( RepositoryFactory.StoreType.IN_MEMORY_TYPE );
++        jcrRepository = factory.createRepository();
++    }
++
++
++    @Before
++    public void setUp()
++        throws Exception
++    {
 +
 +        Map<String, MetadataFacetFactory> factories = AbstractMetadataRepositoryTest.createTestMetadataFacetFactories();
 +
 +        assertNotNull( jcrRepository );
 +        // TODO: probably don't need to use Spring for this
 +        JcrMetadataRepository jcrMetadataRepository = new JcrMetadataRepository( factories, jcrRepository );
 +
++
++        session = jcrMetadataRepository.getJcrSession();
++
 +        try
 +        {
 +            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 )
 +        {
 +            // ignore
 +        }
 +
 +        this.repository = jcrMetadataRepository;
 +    }
 +
 +    private static void registerMixinNodeType( NodeTypeManager nodeTypeManager, String type )
 +        throws RepositoryException
 +    {
 +        NodeTypeTemplate nodeType = nodeTypeManager.createNodeTypeTemplate();
 +        nodeType.setMixin( true );
 +        nodeType.setName( type );
 +        nodeTypeManager.registerNodeType( nodeType, false );
 +    }
 +
 +    @After
 +    public void tearDown()
 +        throws Exception
 +    {
 +        if (repository!=null)
 +        {
 +            repository.close( );
 +        }
 +
 +    }
 +
 +    @Test
 +    public void testJcrStatisticsQuery()
 +        throws Exception
 +    {
 +        Calendar cal = Calendar.getInstance();
 +        Date endTime = cal.getTime();
 +        cal.add( Calendar.HOUR, -1 );
 +        Date startTime = cal.getTime();
 +
 +        loadContentIntoRepo( TEST_REPO );
 +        loadContentIntoRepo( "another-repo" );
 +
 +        DefaultRepositoryStatistics testedStatistics = new DefaultRepositoryStatistics();
 +        testedStatistics.setNewFileCount( NEW_FILE_COUNT );
 +        testedStatistics.setTotalFileCount( TOTAL_FILE_COUNT );
 +        testedStatistics.setScanStartTime( startTime );
 +        testedStatistics.setScanEndTime( endTime );
 +
 +        repository.populateStatistics( repository, TEST_REPO, testedStatistics );
 +
 +        DefaultRepositoryStatistics expectedStatistics = new DefaultRepositoryStatistics();
 +        expectedStatistics.setNewFileCount( NEW_FILE_COUNT );
 +        expectedStatistics.setTotalFileCount( TOTAL_FILE_COUNT );
 +        expectedStatistics.setScanEndTime( endTime );
 +        expectedStatistics.setScanStartTime( startTime );
 +        expectedStatistics.setTotalArtifactFileSize( 95954585 );
 +        expectedStatistics.setTotalArtifactCount( 269 );
 +        expectedStatistics.setTotalGroupCount( 1 );
 +        expectedStatistics.setTotalProjectCount( 43 );
 +        expectedStatistics.setTotalCountForType( "zip", 1 );
 +        expectedStatistics.setTotalCountForType( "gz", 1 ); // FIXME: should be tar.gz
 +        expectedStatistics.setTotalCountForType( "java-source", 10 );
 +        expectedStatistics.setTotalCountForType( "jar", 108 );
 +        expectedStatistics.setTotalCountForType( "xml", 3 );
 +        expectedStatistics.setTotalCountForType( "war", 2 );
 +        expectedStatistics.setTotalCountForType( "pom", 144 );
 +        expectedStatistics.setRepositoryId( TEST_REPO );
 +
 +        System.out.println(testedStatistics.getTotalCountForType());
 +
 +        assertEquals( NEW_FILE_COUNT, testedStatistics.getNewFileCount());
 +        assertEquals( TOTAL_FILE_COUNT, testedStatistics.getTotalFileCount() );
 +        assertEquals( endTime, testedStatistics.getScanEndTime() );
 +        assertEquals( startTime, testedStatistics.getScanStartTime() );
 +        assertEquals( 95954585, testedStatistics.getTotalArtifactFileSize() );
 +        assertEquals( 269, testedStatistics.getTotalArtifactCount() );
 +        assertEquals( 1, testedStatistics.getTotalGroupCount() );
 +        assertEquals( 43, testedStatistics.getTotalProjectCount() );
 +        assertEquals( 1, testedStatistics.getTotalCountForType( "zip" ) );
 +        assertEquals( 1, testedStatistics.getTotalCountForType( "gz" ) );
 +        assertEquals( 10, testedStatistics.getTotalCountForType( "java-source" ) );
 +        assertEquals( 108, testedStatistics.getTotalCountForType( "jar" ) );
 +        assertEquals( 3, testedStatistics.getTotalCountForType( "xml" ) );
 +        assertEquals( 2, testedStatistics.getTotalCountForType( "war" ) );
 +        assertEquals( 144, testedStatistics.getTotalCountForType( "pom" ) );
 +        assertEquals( 10, testedStatistics.getTotalCountForType( "java-source" ) );
 +
 +
 +    }
 +
 +    private void loadContentIntoRepo( String repoId )
 +        throws RepositoryException, IOException
 +    {
 +        Node n = JcrUtils.getOrAddNode( session.getRootNode(), "repositories" );
 +        n = JcrUtils.getOrAddNode( n, repoId );
 +        n = JcrUtils.getOrAddNode( n, "content" );
 +        n = JcrUtils.getOrAddNode( n, "org" );
 +        n = JcrUtils.getOrAddNode( n, "apache" );
 +
 +        GZIPInputStream inputStream = new GZIPInputStream( getClass().getResourceAsStream( "/artifacts.xml.gz" ) );
 +        session.importXML( n.getPath(), inputStream, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW );
 +        session.save();
 +    }
 +}
diff --cc pom.xml
Simple merge