import org.apache.archiva.common.plexusbridge.MavenIndexerUtils;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
+import org.apache.commons.lang.StringUtils;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
-import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.index.ArtifactContext;
import org.apache.maven.index.ArtifactContextProducer;
import org.apache.maven.index.DefaultArtifactContextProducer;
* ArchivaIndexingTaskExecutor Executes all indexing tasks. Adding, updating and removing artifacts from the index are
* all performed by this executor. Add and update artifact in index tasks are added in the indexing task queue by the
* NexusIndexerConsumer while remove artifact from index tasks are added by the LuceneCleanupRemoveIndexedConsumer.
- *
*/
@Service( "taskExecutor#indexing" )
public class ArchivaIndexingTaskExecutor
context.optimize();
-
File managedRepository = new File( repository.getLocation() );
- final File indexLocation = new File( managedRepository, ".index" );
+ String indexDirectory = repository.getIndexDirectory();
+ final File indexLocation = StringUtils.isBlank( indexDirectory )
+ ? new File( managedRepository, ".indexer" )
+ : new File( indexDirectory );
IndexPackingRequest request = new IndexPackingRequest( context, indexLocation );
indexPacker.packIndex( request );
Occur.SHOULD );
assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
- assertTrue( new File( repositoryConfig.getLocation(), ".index" ).exists() );
+ assertFalse( new File( repositoryConfig.getLocation(), ".index" ).exists() );
flatSearchRequest = new FlatSearchRequest( q, getIndexingContext() );
indexingExecutor.executeTask( task );
assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
- assertTrue( new File( repositoryConfig.getLocation(), ".index" ).exists() );
// unpack .zip index
- File destDir = new File( repositoryConfig.getLocation(), ".index/tmp" );
- unzipIndex( new File( repositoryConfig.getLocation(), ".index" ).getPath(), destDir.getPath() );
+ File destDir = new File( repositoryConfig.getLocation(), ".indexer/tmp" );
+ unzipIndex( new File( repositoryConfig.getLocation(), ".indexer" ).getPath(), destDir.getPath() );
BooleanQuery q = new BooleanQuery();
q.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( "org.apache.archiva" ) ),
import org.apache.archiva.rest.api.model.SearchRequest;
import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
import org.apache.archiva.rest.api.services.SearchService;
-import org.apache.commons.io.FileUtils;
import org.junit.Test;
import java.io.File;
assertTrue(
" not 1 results for Bundle Symbolic Name org.apache.karaf.features.command but " + artifacts.size() + ":"
+ artifacts, artifacts.size() == 1 );
- log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts );
deleteTestRepo( testRepoId, targetRepo );
}
assertTrue(
" not 2 results for Bundle Symbolic Name org.apache.karaf.features.core but " + artifacts.size() + ":"
+ artifacts, artifacts.size() == 2 );
- log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts );
+
+ deleteTestRepo( testRepoId, targetRepo );
+ }
+
+ @Test
+ public void searchWithSearchRequestExportPackageOneVersion()
+ throws Exception
+ {
+
+ String testRepoId = "test-repo";
+ // force guest user creation if not exists
+ if ( getUserService( authorizationHeader ).getGuestUser() == null )
+ {
+ assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
+ }
+
+ File targetRepo = createAndIndexRepo( testRepoId );
+
+ SearchService searchService = getSearchService( authorizationHeader );
+
+ SearchRequest searchRequest = new SearchRequest();
+ searchRequest.setBundleExportPackage( "org.apache.karaf.features.command.completers" );
+
+ List<Artifact> artifacts = searchService.searchArtifacts( searchRequest );
+
+ assertNotNull( artifacts );
+ assertTrue( " not 1 results for Bundle ExportPackage org.apache.karaf.features.command.completers but "
+ + artifacts.size() + ":" + artifacts, artifacts.size() == 1 );
deleteTestRepo( testRepoId, targetRepo );
}
{
getManagedRepositoriesService( authorizationHeader ).deleteManagedRepository( testRepoId, true );
}
- File targetRepo = new File( System.getProperty( "targetDir", "./target" ), "test-repo" );
- cleanupFiles( targetRepo );
-
- File sourceRepo = new File( "src/test/repo-with-osgi" );
-
- FileUtils.copyDirectory( sourceRepo, targetRepo );
+ File targetRepo = new File( "src/test/repo-with-osgi" );
ManagedRepository managedRepository = new ManagedRepository();
managedRepository.setId( testRepoId );
managedRepository.setName( "test repo" );
managedRepository.setLocation( targetRepo.getPath() );
- managedRepository.setIndexDirectory( targetRepo.getPath() + "/index-" + Long.toString( new Date().getTime() ) );
+ managedRepository.setIndexDirectory( "target/.index-" + Long.toString( new Date().getTime() ) );
ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
service.addManagedRepository( managedRepository );
{
if ( getManagedRepositoriesService( authorizationHeader ).getManagedRepository( id ) != null )
{
- getManagedRepositoriesService( authorizationHeader ).deleteManagedRepository( id, true );
+ getManagedRepositoriesService( authorizationHeader ).deleteManagedRepository( id, false );
}
- cleanupFiles( targetRepo );
}
- private void cleanupFiles( File targetRepo )
- throws Exception
- {
-
- File indexerDir = new File( targetRepo, ".indexer" );
-
- if ( targetRepo.exists() )
- {
- FileUtils.deleteDirectory( targetRepo );
- }
-
- if ( indexerDir.exists() )
- {
- FileUtils.deleteDirectory( indexerDir );
- }
-
- File lockFile = new File( indexerDir, "write.lock" );
- if ( lockFile.exists() )
- {
- FileUtils.forceDelete( lockFile );
- }
-
- assertFalse( targetRepo.exists() );
- assertFalse( indexerDir.exists() );
- assertFalse( lockFile.exists() );
- }
}