org.apache.maven.index.updater.IndexUpdateRequest Java Examples

The following examples show how to use org.apache.maven.index.updater.IndexUpdateRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArchivaIndexingTaskExecutorTest.java    From archiva with Apache License 2.0 4 votes vote down vote up
@Test
public void testPackagedIndex()
    throws Exception
{

    Path basePath = repo.getRoot().getFilePath();
    IndexCreationFeature icf = repo.getFeature( IndexCreationFeature.class ).get();
    StorageAsset packedIndexDirectory = icf.getLocalPackedIndexPath();
    StorageAsset indexerDirectory = icf.getLocalIndexPath();

    for (StorageAsset dir : new StorageAsset[] { packedIndexDirectory, indexerDirectory }) {
        if (dir.getFilePath()!=null)
        {
            Path localDirPath = dir.getFilePath();
            Files.list( localDirPath ).filter( path -> path.getFileName( ).toString( ).startsWith( "nexus-maven-repository-index" ) )
                .forEach( path ->
                {
                    try
                    {
                        System.err.println( "Deleting " + path );
                        Files.delete( path );
                    }
                    catch ( IOException e )
                    {
                        e.printStackTrace( );
                    }
                } );
        }
    }




    Path artifactFile = basePath.resolve(
                                  "org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" );
    ArtifactIndexingTask task =
        new ArtifactIndexingTask( repo, artifactFile, ArtifactIndexingTask.Action.ADD,
                                  repo.getIndexingContext() );
    task.setExecuteOnEntireRepo( false );

    indexingExecutor.executeTask( task );

    task = new ArtifactIndexingTask( repo, null, ArtifactIndexingTask.Action.FINISH,
                                     repo.getIndexingContext() );

    task.setExecuteOnEntireRepo( false );

    indexingExecutor.executeTask( task );

    assertTrue( Files.exists(packedIndexDirectory.getFilePath()) );
    assertTrue( Files.exists(indexerDirectory.getFilePath()) );

    // test packed index file creation
    //no more zip
    //Assertions.assertThat(new File( indexerDirectory, "nexus-maven-repository-index.zip" )).exists();
    Assertions.assertThat( Files.exists(packedIndexDirectory.getFilePath().resolve("nexus-maven-repository-index.properties" ) ));
    Assertions.assertThat( Files.exists(packedIndexDirectory.getFilePath().resolve("nexus-maven-repository-index.gz" ) ));
    assertFalse( Files.exists(packedIndexDirectory.getFilePath().resolve("nexus-maven-repository-index.1.gz" )  ));

    // unpack .zip index
    //unzipIndex( indexerDirectory.getPath(), destDir.getPath() );

    DefaultIndexUpdater.FileFetcher fetcher = new DefaultIndexUpdater.FileFetcher( packedIndexDirectory.getFilePath().toFile() );
    IndexUpdateRequest updateRequest = new IndexUpdateRequest( getIndexingContext(), fetcher );
    //updateRequest.setLocalIndexCacheDir( indexerDirectory );
    indexUpdater.fetchAndUpdateIndex( updateRequest );

    BooleanQuery.Builder qb = new BooleanQuery.Builder();
    qb.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( "org.apache.archiva" ) ),
           BooleanClause.Occur.SHOULD );
    qb.add(
        indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ),
        BooleanClause.Occur.SHOULD );

    FlatSearchRequest request = new FlatSearchRequest( qb.build(), getIndexingContext() );
    FlatSearchResponse response = indexer.searchFlat( request );

    assertEquals( 1, response.getTotalHitsCount() );
    Set<ArtifactInfo> results = response.getResults();

    ArtifactInfo artifactInfo = results.iterator().next();
    assertEquals( "org.apache.archiva", artifactInfo.getGroupId() );
    assertEquals( "archiva-index-methods-jar-test", artifactInfo.getArtifactId() );
    assertEquals( "test-repo", artifactInfo.getRepository() );


}