Skip to content

Commit

Permalink
MINDEXER-47: SubPath reindex fixes
Browse files Browse the repository at this point in the history
Reindexing one GAV (subpath of it) of a GA removes other existing GA versions from index.

Patch provided by Marvin Froeder. Thanks.

git-svn-id: https://svn.apache.org/repos/asf/maven/indexer/trunk@1210517 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
cstamas committed Dec 5, 2011
1 parent 71051a2 commit f705acd
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 4 deletions.
Expand Up @@ -48,7 +48,7 @@ public ScanningResult scan( ScanningRequest request )
{
request.getArtifactScanningListener().scanningStarted( request.getIndexingContext() );

ScanningResult result = new ScanningResult();
ScanningResult result = new ScanningResult( request );

scanDirectory( request.getStartingDirectory(), request );

Expand Down
Expand Up @@ -166,7 +166,7 @@ public void scanningFinished( IndexingContext ctx, ScanningResult result )

if ( update && !context.isReceivingUpdates() )
{
removeDeletedArtifacts( context, result );
removeDeletedArtifacts( context, result, result.getRequest().getStartingPath() );
}
}
catch ( IOException ex )
Expand Down Expand Up @@ -232,7 +232,7 @@ private void initialize( IndexingContext ctx )
}
}

private void removeDeletedArtifacts( IndexingContext context, ScanningResult result )
private void removeDeletedArtifacts( IndexingContext context, ScanningResult result, String contextPath )
throws IOException
{
int deleted = 0;
Expand Down Expand Up @@ -272,7 +272,11 @@ private void removeDeletedArtifacts( IndexingContext context, ScanningResult res

for ( int i = 0; i < collector.getTotalHits(); i++ )
{
indexerEngine.remove( context, ac );
if ( contextPath == null
|| context.getGavCalculator().gavToPath( ac.getGav() ).startsWith( contextPath ) )
{
indexerEngine.remove( context, ac );
}

deleted++;
}
Expand Down
Expand Up @@ -35,6 +35,13 @@ public class ScanningResult

private List<Exception> exceptions = new ArrayList<Exception>();

private final ScanningRequest request;

public ScanningResult( ScanningRequest request )
{
this.request = request;
}

public void setTotalFiles( int totalFiles )
{
this.totalFiles = totalFiles;
Expand Down Expand Up @@ -70,4 +77,9 @@ public List<Exception> getExceptions()
return exceptions;
}

public ScanningRequest getRequest()
{
return request;
}

}
@@ -0,0 +1,73 @@
package org.apache.maven.index;

/*
* 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 java.io.File;
import java.util.Collection;
import java.util.Set;

public class Nexus4674GavPathReindexTest
extends AbstractNexusIndexerTest
{
protected File repo = new File( getBasedir(), "src/test/repo" );

@Override
protected void prepareNexusIndexer( NexusIndexer nexusIndexer )
throws Exception
{
context = nexusIndexer.addIndexingContext( "test-minimal", "test", repo, indexDir, null, null, MIN_CREATORS );

nexusIndexer.scan( context, "/org/slf4j/slf4j-api", null, false );
nexusIndexer.scan( context, "/org/slf4j/slf4j-api/1.4.1", null, true );
}

public void testRootGroups()
throws Exception
{
Set<String> rootGroups = context.getRootGroups();
assertEquals( rootGroups.toString(), 1, rootGroups.size() );

assertGroup( 4, "org", context );

assertGroup( 4, "org.slf4j", context );
}

public void testIdentify()
throws Exception
{
Collection<ArtifactInfo> ais;
File artifact;

// Using a file: this one should be unknown
artifact = new File( repo, "qdox/qdox/1.5/qdox-1.5.jar" );

ais = nexusIndexer.identify( artifact );

assertTrue( "Should not be able to identify it!", ais.isEmpty() );

// Using a file: this one should be known
artifact = new File( repo, "org/slf4j/slf4j-api/1.4.2/slf4j-api-1.4.2.jar" );

ais = nexusIndexer.identify( artifact );

assertEquals( "Should not be able to identify it!", 1, ais.size() );
}

}

0 comments on commit f705acd

Please sign in to comment.