mirror of https://github.com/apache/archiva.git
[MRM-1501] add unit for searching with osgi query
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1158021 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f8aa5f9e78
commit
c1abddcaf9
|
@ -34,6 +34,7 @@ import org.apache.maven.index.FlatSearchRequest;
|
||||||
import org.apache.maven.index.FlatSearchResponse;
|
import org.apache.maven.index.FlatSearchResponse;
|
||||||
import org.apache.maven.index.MAVEN;
|
import org.apache.maven.index.MAVEN;
|
||||||
import org.apache.maven.index.NexusIndexer;
|
import org.apache.maven.index.NexusIndexer;
|
||||||
|
import org.apache.maven.index.OSGI;
|
||||||
import org.apache.maven.index.context.IndexingContext;
|
import org.apache.maven.index.context.IndexingContext;
|
||||||
import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
|
import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
|
||||||
import org.apache.maven.index.expr.StringSearchExpression;
|
import org.apache.maven.index.expr.StringSearchExpression;
|
||||||
|
@ -41,12 +42,12 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RepositorySearch implementation which uses the Nexus Indexer for searching.
|
* RepositorySearch implementation which uses the Nexus Indexer for searching.
|
||||||
|
@ -121,27 +122,62 @@ public class NexusRepositorySearch
|
||||||
BooleanQuery q = new BooleanQuery();
|
BooleanQuery q = new BooleanQuery();
|
||||||
if ( StringUtils.isNotBlank( searchFields.getGroupId() ) )
|
if ( StringUtils.isNotBlank( searchFields.getGroupId() ) )
|
||||||
{
|
{
|
||||||
q.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( searchFields.getGroupId() ) ), Occur.MUST );
|
q.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( searchFields.getGroupId() ) ),
|
||||||
|
Occur.MUST );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( StringUtils.isNotBlank( searchFields.getArtifactId() ) )
|
if ( StringUtils.isNotBlank( searchFields.getArtifactId() ) )
|
||||||
{
|
{
|
||||||
q.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( searchFields.getArtifactId() ) ), Occur.MUST );
|
q.add(
|
||||||
|
indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( searchFields.getArtifactId() ) ),
|
||||||
|
Occur.MUST );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( StringUtils.isNotBlank( searchFields.getVersion() ) )
|
if ( StringUtils.isNotBlank( searchFields.getVersion() ) )
|
||||||
{
|
{
|
||||||
q.add( indexer.constructQuery( MAVEN.VERSION, new StringSearchExpression( searchFields.getVersion() ) ), Occur.MUST );
|
q.add( indexer.constructQuery( MAVEN.VERSION, new StringSearchExpression( searchFields.getVersion() ) ),
|
||||||
|
Occur.MUST );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( StringUtils.isNotBlank( searchFields.getPackaging() ) )
|
if ( StringUtils.isNotBlank( searchFields.getPackaging() ) )
|
||||||
{
|
{
|
||||||
q.add( indexer.constructQuery( MAVEN.PACKAGING, new StringSearchExpression( searchFields.getPackaging() ) ), Occur.MUST );
|
q.add( indexer.constructQuery( MAVEN.PACKAGING, new StringSearchExpression( searchFields.getPackaging() ) ),
|
||||||
|
Occur.MUST );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( StringUtils.isNotBlank( searchFields.getClassName() ) )
|
if ( StringUtils.isNotBlank( searchFields.getClassName() ) )
|
||||||
{
|
{
|
||||||
q.add( indexer.constructQuery( MAVEN.CLASSNAMES, new StringSearchExpression( searchFields.getClassName( ) ) ), Occur.MUST );
|
q.add(
|
||||||
|
indexer.constructQuery( MAVEN.CLASSNAMES, new StringSearchExpression( searchFields.getClassName() ) ),
|
||||||
|
Occur.MUST );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( StringUtils.isNotBlank( searchFields.getBundleSymbolicName() ) )
|
||||||
|
{
|
||||||
|
q.add( indexer.constructQuery( OSGI.SYMBOLIC_NAME,
|
||||||
|
new StringSearchExpression( searchFields.getBundleSymbolicName() ) ),
|
||||||
|
Occur.MUST );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( StringUtils.isNotBlank( searchFields.getBundleVersion() ) )
|
||||||
|
{
|
||||||
|
q.add(
|
||||||
|
indexer.constructQuery( OSGI.VERSION, new StringSearchExpression( searchFields.getBundleVersion() ) ),
|
||||||
|
Occur.MUST );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( StringUtils.isNotBlank( searchFields.getBundleExportPackage() ) )
|
||||||
|
{
|
||||||
|
q.add( indexer.constructQuery( OSGI.EXPORT_PACKAGE,
|
||||||
|
new StringSearchExpression( searchFields.getBundleExportPackage() ) ),
|
||||||
|
Occur.MUST );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( StringUtils.isNotBlank( searchFields.getBundleExportService() ) )
|
||||||
|
{
|
||||||
|
q.add( indexer.constructQuery( OSGI.SYMBOLIC_NAME,
|
||||||
|
new StringSearchExpression( searchFields.getBundleExportService() ) ),
|
||||||
|
Occur.MUST );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( q.getClauses() == null || q.getClauses().length <= 0 )
|
if ( q.getClauses() == null || q.getClauses().length <= 0 )
|
||||||
|
@ -199,7 +235,7 @@ public class NexusRepositorySearch
|
||||||
private void constructQuery( String term, BooleanQuery q )
|
private void constructQuery( String term, BooleanQuery q )
|
||||||
{
|
{
|
||||||
q.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( term ) ), Occur.SHOULD );
|
q.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( term ) ), Occur.SHOULD );
|
||||||
q.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( term ) ), Occur.SHOULD );
|
q.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( term ) ), Occur.SHOULD );
|
||||||
q.add( indexer.constructQuery( MAVEN.VERSION, new StringSearchExpression( term ) ), Occur.SHOULD );
|
q.add( indexer.constructQuery( MAVEN.VERSION, new StringSearchExpression( term ) ), Occur.SHOULD );
|
||||||
q.add( indexer.constructQuery( MAVEN.PACKAGING, new StringSearchExpression( term ) ), Occur.SHOULD );
|
q.add( indexer.constructQuery( MAVEN.PACKAGING, new StringSearchExpression( term ) ), Occur.SHOULD );
|
||||||
q.add( indexer.constructQuery( MAVEN.CLASSNAMES, new StringSearchExpression( term ) ), Occur.SHOULD );
|
q.add( indexer.constructQuery( MAVEN.CLASSNAMES, new StringSearchExpression( term ) ), Occur.SHOULD );
|
||||||
|
@ -228,7 +264,7 @@ public class NexusRepositorySearch
|
||||||
indexDirectory = new File( repoConfig.getLocation(), ".indexer" );
|
indexDirectory = new File( repoConfig.getLocation(), ".indexer" );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (indexer.getIndexingContexts().containsKey( repoConfig.getId() ))
|
if ( indexer.getIndexingContexts().containsKey( repoConfig.getId() ) )
|
||||||
{
|
{
|
||||||
// alreday here so no need to record it again
|
// alreday here so no need to record it again
|
||||||
log.info( "index with id {} already exists skip adding it", repoConfig.getId() );
|
log.info( "index with id {} already exists skip adding it", repoConfig.getId() );
|
||||||
|
|
|
@ -48,17 +48,46 @@ public class SearchFields
|
||||||
* class name or package name
|
* class name or package name
|
||||||
*/
|
*/
|
||||||
private String className;
|
private String className;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* repositories
|
* repositories
|
||||||
*/
|
*/
|
||||||
private List<String> repositories = new ArrayList<String>();
|
private List<String> repositories = new ArrayList<String>();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* contains osgi metadata Bundle-Version if available
|
||||||
|
*
|
||||||
|
* @since 1.4
|
||||||
|
*/
|
||||||
|
private String bundleVersion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* contains osgi metadata Bundle-SymbolicName if available
|
||||||
|
*
|
||||||
|
* @since 1.4
|
||||||
|
*/
|
||||||
|
private String bundleSymbolicName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* contains osgi metadata Export-Package if available
|
||||||
|
*
|
||||||
|
* @since 1.4
|
||||||
|
*/
|
||||||
|
private String bundleExportPackage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* contains osgi metadata Export-Service if available
|
||||||
|
*
|
||||||
|
* @since 1.4
|
||||||
|
*/
|
||||||
|
private String bundleExportService;
|
||||||
|
|
||||||
public SearchFields()
|
public SearchFields()
|
||||||
{
|
{
|
||||||
|
// no op
|
||||||
}
|
}
|
||||||
|
|
||||||
public SearchFields( String groupId, String artifactId, String version, String packaging, String className,
|
public SearchFields( String groupId, String artifactId, String version, String packaging, String className,
|
||||||
List<String> repositories )
|
List<String> repositories )
|
||||||
{
|
{
|
||||||
|
@ -69,7 +98,7 @@ public class SearchFields
|
||||||
this.className = className;
|
this.className = className;
|
||||||
this.repositories = repositories;
|
this.repositories = repositories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getGroupId()
|
public String getGroupId()
|
||||||
{
|
{
|
||||||
return groupId;
|
return groupId;
|
||||||
|
@ -129,4 +158,45 @@ public class SearchFields
|
||||||
{
|
{
|
||||||
this.repositories = repositories;
|
this.repositories = repositories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getBundleVersion()
|
||||||
|
{
|
||||||
|
return bundleVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBundleVersion( String bundleVersion )
|
||||||
|
{
|
||||||
|
this.bundleVersion = bundleVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBundleSymbolicName()
|
||||||
|
{
|
||||||
|
return bundleSymbolicName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBundleSymbolicName( String bundleSymbolicName )
|
||||||
|
{
|
||||||
|
this.bundleSymbolicName = bundleSymbolicName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBundleExportPackage()
|
||||||
|
{
|
||||||
|
return bundleExportPackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBundleExportPackage( String bundleExportPackage )
|
||||||
|
{
|
||||||
|
this.bundleExportPackage = bundleExportPackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBundleExportService()
|
||||||
|
{
|
||||||
|
return bundleExportService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBundleExportService( String bundleExportService )
|
||||||
|
{
|
||||||
|
this.bundleExportService = bundleExportService;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,190 @@
|
||||||
|
package org.apache.archiva.indexer.search;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.common.plexusbridge.PlexusSisuBridge;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.apache.maven.archiva.common.utils.ArchivaNexusIndexerUtil;
|
||||||
|
import org.apache.maven.archiva.common.utils.FileUtil;
|
||||||
|
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||||
|
import org.apache.maven.archiva.configuration.Configuration;
|
||||||
|
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
|
||||||
|
import org.apache.maven.index.ArtifactContext;
|
||||||
|
import org.apache.maven.index.ArtifactContextProducer;
|
||||||
|
import org.apache.maven.index.NexusIndexer;
|
||||||
|
import org.apache.maven.index.artifact.IllegalArtifactCoordinateException;
|
||||||
|
import org.apache.maven.index.context.IndexingContext;
|
||||||
|
import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
|
||||||
|
import org.easymock.MockControl;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Olivier Lamy
|
||||||
|
*/
|
||||||
|
@RunWith( SpringJUnit4ClassRunner.class )
|
||||||
|
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
|
||||||
|
public abstract class AbstractNexusRepositorySearch
|
||||||
|
extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
public static String TEST_REPO_1 = "nexus-search-test-repo";
|
||||||
|
|
||||||
|
public static String TEST_REPO_2 = "nexus-search-test-repo-2";
|
||||||
|
|
||||||
|
RepositorySearch search;
|
||||||
|
|
||||||
|
ArchivaConfiguration archivaConfig;
|
||||||
|
|
||||||
|
ArtifactContextProducer artifactContextProducer;
|
||||||
|
|
||||||
|
MockControl archivaConfigControl;
|
||||||
|
|
||||||
|
Configuration config;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
PlexusSisuBridge plexusSisuBridge;
|
||||||
|
|
||||||
|
NexusIndexer nexusIndexer;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
|
||||||
|
FileUtils.deleteDirectory(
|
||||||
|
new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ) );
|
||||||
|
assertFalse( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ).exists() );
|
||||||
|
|
||||||
|
FileUtils.deleteDirectory(
|
||||||
|
new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ) );
|
||||||
|
assertFalse( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ).exists() );
|
||||||
|
|
||||||
|
archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class );
|
||||||
|
|
||||||
|
archivaConfig = (ArchivaConfiguration) archivaConfigControl.getMock();
|
||||||
|
|
||||||
|
search = new NexusRepositorySearch( plexusSisuBridge, archivaConfig );
|
||||||
|
|
||||||
|
nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class );
|
||||||
|
|
||||||
|
artifactContextProducer = plexusSisuBridge.lookup( ArtifactContextProducer.class );
|
||||||
|
|
||||||
|
config = new Configuration();
|
||||||
|
config.addManagedRepository( createRepositoryConfig( TEST_REPO_1 ) );
|
||||||
|
config.addManagedRepository( createRepositoryConfig( TEST_REPO_2 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
for ( IndexingContext indexingContext : nexusIndexer.getIndexingContexts().values() )
|
||||||
|
{
|
||||||
|
nexusIndexer.removeIndexingContext( indexingContext, true );
|
||||||
|
}
|
||||||
|
|
||||||
|
FileUtils.deleteDirectory(
|
||||||
|
new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ) );
|
||||||
|
assertFalse( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ).exists() );
|
||||||
|
|
||||||
|
FileUtils.deleteDirectory(
|
||||||
|
new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ) );
|
||||||
|
assertFalse( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ).exists() );
|
||||||
|
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ManagedRepositoryConfiguration createRepositoryConfig( String repository )
|
||||||
|
{
|
||||||
|
ManagedRepositoryConfiguration repositoryConfig = new ManagedRepositoryConfiguration();
|
||||||
|
repositoryConfig.setId( repository );
|
||||||
|
repositoryConfig.setLocation( FileUtil.getBasedir() + "/target/test-classes/" + repository );
|
||||||
|
repositoryConfig.setLayout( "default" );
|
||||||
|
repositoryConfig.setName( repository );
|
||||||
|
repositoryConfig.setScanned( true );
|
||||||
|
repositoryConfig.setSnapshots( false );
|
||||||
|
repositoryConfig.setReleases( true );
|
||||||
|
|
||||||
|
return repositoryConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void createIndex( String repository, List<File> filesToBeIndexed, boolean scan )
|
||||||
|
throws IOException, UnsupportedExistingLuceneIndexException
|
||||||
|
{
|
||||||
|
|
||||||
|
File indexerDirectory = new File( FileUtil.getBasedir(), "/target/test-classes/" + repository + "/.indexer" );
|
||||||
|
|
||||||
|
if ( indexerDirectory.exists() )
|
||||||
|
{
|
||||||
|
FileUtils.deleteDirectory( indexerDirectory );
|
||||||
|
}
|
||||||
|
|
||||||
|
assertFalse( indexerDirectory.exists() );
|
||||||
|
|
||||||
|
File lockFile =
|
||||||
|
new File( FileUtil.getBasedir(), "/target/test-classes/" + repository + "/.indexer/write.lock" );
|
||||||
|
if ( lockFile.exists() )
|
||||||
|
{
|
||||||
|
lockFile.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
assertFalse( lockFile.exists() );
|
||||||
|
|
||||||
|
File repo = new File( FileUtil.getBasedir(), "/target/test-classes/" + repository );
|
||||||
|
File indexDirectory = new File( FileUtil.getBasedir(), "/target/test-classes/" + repository + "/.indexer" );
|
||||||
|
|
||||||
|
IndexingContext context = nexusIndexer.addIndexingContext( repository, repository, repo, indexDirectory,
|
||||||
|
repo.toURI().toURL().toExternalForm(),
|
||||||
|
indexDirectory.toURI().toURL().toString(),
|
||||||
|
ArchivaNexusIndexerUtil.FULL_INDEX );
|
||||||
|
|
||||||
|
List<ArtifactContext> artifactContexts = new ArrayList<ArtifactContext>( filesToBeIndexed.size() );
|
||||||
|
for ( File artifactFile : filesToBeIndexed )
|
||||||
|
{
|
||||||
|
ArtifactContext ac = artifactContextProducer.getArtifactContext( context, artifactFile );
|
||||||
|
artifactContexts.add( ac );
|
||||||
|
}
|
||||||
|
|
||||||
|
context.setSearchable( true );
|
||||||
|
|
||||||
|
if ( filesToBeIndexed != null && !filesToBeIndexed.isEmpty() )
|
||||||
|
{
|
||||||
|
nexusIndexer.addArtifactsToIndex( artifactContexts, context );
|
||||||
|
}
|
||||||
|
if ( scan )
|
||||||
|
{
|
||||||
|
nexusIndexer.scan( context, false );
|
||||||
|
}
|
||||||
|
assertTrue( new File( FileUtil.getBasedir(), "/target/test-classes/" + repository + "/.indexer" ).exists() );
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
package org.apache.archiva.indexer.search;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Olivier Lamy
|
||||||
|
*/
|
||||||
|
public class NexusRepositorySearchOSGITest
|
||||||
|
extends AbstractNexusRepositorySearch
|
||||||
|
{
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void searchFelixWithSymbolicName()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
createIndex( TEST_REPO_1, Collections.<File>emptyList(), true );
|
||||||
|
|
||||||
|
List<String> selectedRepos = Arrays.asList( TEST_REPO_1 );
|
||||||
|
|
||||||
|
// search artifactId
|
||||||
|
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
|
||||||
|
|
||||||
|
archivaConfigControl.replay();
|
||||||
|
|
||||||
|
SearchFields searchFields = new SearchFields( );
|
||||||
|
searchFields.setBundleSymbolicName( "org.apache.felix.bundlerepository" );
|
||||||
|
searchFields.setBundleVersion( "1.6.6" );
|
||||||
|
searchFields.setRepositories( selectedRepos );
|
||||||
|
|
||||||
|
SearchResults results = search.search( "user", searchFields, null );
|
||||||
|
|
||||||
|
archivaConfigControl.verify();
|
||||||
|
|
||||||
|
assertNotNull( results );
|
||||||
|
assertEquals( 1, results.getTotalHits() );
|
||||||
|
|
||||||
|
SearchResultHit hit = results.getHits().get( 0 );
|
||||||
|
assertEquals( "org.apache.felix", hit.getGroupId() );
|
||||||
|
assertEquals( "org.apache.felix.bundlerepository", hit.getArtifactId() );
|
||||||
|
assertEquals( "1.6.6", hit.getVersions().get( 0 ) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -44,6 +44,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
@ -51,59 +52,9 @@ import javax.inject.Inject;
|
||||||
@RunWith( SpringJUnit4ClassRunner.class )
|
@RunWith( SpringJUnit4ClassRunner.class )
|
||||||
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
|
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
|
||||||
public class NexusRepositorySearchTest
|
public class NexusRepositorySearchTest
|
||||||
extends TestCase
|
extends AbstractNexusRepositorySearch
|
||||||
{
|
{
|
||||||
private RepositorySearch search;
|
|
||||||
|
|
||||||
private ArchivaConfiguration archivaConfig;
|
|
||||||
|
|
||||||
//private DefaultIndexingContext context;
|
|
||||||
|
|
||||||
//private IndexerEngine indexerEngine;
|
|
||||||
|
|
||||||
private ArtifactContextProducer artifactContextProducer;
|
|
||||||
|
|
||||||
private MockControl archivaConfigControl;
|
|
||||||
|
|
||||||
private Configuration config;
|
|
||||||
|
|
||||||
private static String TEST_REPO_1 = "nexus-search-test-repo";
|
|
||||||
|
|
||||||
private static String TEST_REPO_2 = "nexus-search-test-repo-2";
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
PlexusSisuBridge plexusSisuBridge;
|
|
||||||
|
|
||||||
NexusIndexer nexusIndexer;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
super.setUp();
|
|
||||||
|
|
||||||
FileUtils.deleteDirectory(
|
|
||||||
new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ) );
|
|
||||||
assertFalse( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ).exists() );
|
|
||||||
|
|
||||||
FileUtils.deleteDirectory(
|
|
||||||
new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ) );
|
|
||||||
assertFalse( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ).exists() );
|
|
||||||
|
|
||||||
archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class );
|
|
||||||
|
|
||||||
archivaConfig = (ArchivaConfiguration) archivaConfigControl.getMock();
|
|
||||||
|
|
||||||
search = new NexusRepositorySearch( plexusSisuBridge, archivaConfig );
|
|
||||||
|
|
||||||
nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class );
|
|
||||||
|
|
||||||
artifactContextProducer = plexusSisuBridge.lookup( ArtifactContextProducer.class );
|
|
||||||
|
|
||||||
config = new Configuration();
|
|
||||||
config.addManagedRepository( createRepositoryConfig( TEST_REPO_1 ) );
|
|
||||||
config.addManagedRepository( createRepositoryConfig( TEST_REPO_2 ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createSimpleIndex( boolean scan )
|
private void createSimpleIndex( boolean scan )
|
||||||
throws IOException, UnsupportedExistingLuceneIndexException, IllegalArtifactCoordinateException
|
throws IOException, UnsupportedExistingLuceneIndexException, IllegalArtifactCoordinateException
|
||||||
|
@ -154,94 +105,13 @@ public class NexusRepositorySearchTest
|
||||||
createIndex( TEST_REPO_1, files, scan );
|
createIndex( TEST_REPO_1, files, scan );
|
||||||
}
|
}
|
||||||
|
|
||||||
private ManagedRepositoryConfiguration createRepositoryConfig( String repository )
|
|
||||||
{
|
|
||||||
ManagedRepositoryConfiguration repositoryConfig = new ManagedRepositoryConfiguration();
|
|
||||||
repositoryConfig.setId( repository );
|
|
||||||
repositoryConfig.setLocation( FileUtil.getBasedir() + "/target/test-classes/" + repository );
|
|
||||||
repositoryConfig.setLayout( "default" );
|
|
||||||
repositoryConfig.setName( repository );
|
|
||||||
repositoryConfig.setScanned( true );
|
|
||||||
repositoryConfig.setSnapshots( false );
|
|
||||||
repositoryConfig.setReleases( true );
|
|
||||||
|
|
||||||
return repositoryConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
|
|
||||||
for ( IndexingContext indexingContext : nexusIndexer.getIndexingContexts().values() )
|
|
||||||
{
|
|
||||||
nexusIndexer.removeIndexingContext( indexingContext, true );
|
|
||||||
}
|
|
||||||
|
|
||||||
FileUtils.deleteDirectory(
|
|
||||||
new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ) );
|
|
||||||
assertFalse( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ).exists() );
|
|
||||||
|
|
||||||
FileUtils.deleteDirectory(
|
|
||||||
new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ) );
|
|
||||||
assertFalse( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ).exists() );
|
|
||||||
|
|
||||||
super.tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createIndex( String repository, List<File> filesToBeIndexed, boolean scan )
|
|
||||||
throws IOException, UnsupportedExistingLuceneIndexException, IllegalArtifactCoordinateException
|
|
||||||
{
|
|
||||||
|
|
||||||
File indexerDirectory = new File( FileUtil.getBasedir(), "/target/test-classes/" + repository + "/.indexer" );
|
|
||||||
|
|
||||||
if ( indexerDirectory.exists() )
|
|
||||||
{
|
|
||||||
FileUtils.deleteDirectory( indexerDirectory );
|
|
||||||
}
|
|
||||||
|
|
||||||
assertFalse( indexerDirectory.exists() );
|
|
||||||
|
|
||||||
File lockFile =
|
|
||||||
new File( FileUtil.getBasedir(), "/target/test-classes/" + repository + "/.indexer/write.lock" );
|
|
||||||
if ( lockFile.exists() )
|
|
||||||
{
|
|
||||||
lockFile.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
assertFalse( lockFile.exists() );
|
|
||||||
|
|
||||||
File repo = new File( FileUtil.getBasedir(), "/target/test-classes/" + repository );
|
|
||||||
File indexDirectory = new File( FileUtil.getBasedir(), "/target/test-classes/" + repository + "/.indexer" );
|
|
||||||
|
|
||||||
IndexingContext context = nexusIndexer.addIndexingContext( repository, repository, repo, indexDirectory,
|
|
||||||
repo.toURI().toURL().toExternalForm(),
|
|
||||||
indexDirectory.toURI().toURL().toString(),
|
|
||||||
ArchivaNexusIndexerUtil.FULL_INDEX );
|
|
||||||
|
|
||||||
List<ArtifactContext> artifactContexts = new ArrayList<ArtifactContext>( filesToBeIndexed.size() );
|
|
||||||
for ( File artifactFile : filesToBeIndexed )
|
|
||||||
{
|
|
||||||
ArtifactContext ac = artifactContextProducer.getArtifactContext( context, artifactFile );
|
|
||||||
artifactContexts.add( ac );
|
|
||||||
}
|
|
||||||
|
|
||||||
nexusIndexer.addArtifactsToIndex( artifactContexts, context );
|
|
||||||
if ( scan )
|
|
||||||
{
|
|
||||||
nexusIndexer.scan( context );
|
|
||||||
}
|
|
||||||
assertTrue( new File( FileUtil.getBasedir(), "/target/test-classes/" + repository + "/.indexer" ).exists() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testQuickSearch()
|
public void testQuickSearch()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
createSimpleIndex( false );
|
createSimpleIndex( false );
|
||||||
|
|
||||||
List<String> selectedRepos = new ArrayList<String>();
|
List<String> selectedRepos = Arrays.asList( TEST_REPO_1 );
|
||||||
selectedRepos.add( TEST_REPO_1 );
|
|
||||||
|
|
||||||
// search artifactId
|
// search artifactId
|
||||||
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
|
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
|
||||||
|
@ -351,7 +221,7 @@ public class NexusRepositorySearchTest
|
||||||
|
|
||||||
assertNotNull( results );
|
assertNotNull( results );
|
||||||
assertEquals( 1, results.getHits().size() );
|
assertEquals( 1, results.getHits().size() );
|
||||||
assertEquals( "total hits not 5 for page1 " + results, 5, results.getTotalHits() );
|
assertEquals( "total hits not 6 for page1 " + results, 6, results.getTotalHits() );
|
||||||
assertEquals( "returned hits not 1 for page1 " + results, 1, results.getReturnedHitsCount() );
|
assertEquals( "returned hits not 1 for page1 " + results, 1, results.getReturnedHitsCount() );
|
||||||
assertEquals( limits, results.getLimits() );
|
assertEquals( limits, results.getLimits() );
|
||||||
|
|
||||||
|
@ -372,7 +242,7 @@ public class NexusRepositorySearchTest
|
||||||
assertNotNull( results );
|
assertNotNull( results );
|
||||||
|
|
||||||
assertEquals( "hits not 1", 1, results.getHits().size() );
|
assertEquals( "hits not 1", 1, results.getHits().size() );
|
||||||
assertEquals( "total hits not 5 for page 2 " + results, 5, results.getTotalHits() );
|
assertEquals( "total hits not 6 for page 2 " + results, 6, results.getTotalHits() );
|
||||||
assertEquals( "returned hits not 1 for page2 " + results, 1, results.getReturnedHitsCount() );
|
assertEquals( "returned hits not 1 for page2 " + results, 1, results.getReturnedHitsCount() );
|
||||||
assertEquals( limits, results.getLimits() );
|
assertEquals( limits, results.getLimits() );
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -0,0 +1,138 @@
|
||||||
|
<!--
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<parent>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>felix-parent</artifactId>
|
||||||
|
<version>2.1</version>
|
||||||
|
<relativePath>../pom/pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<packaging>bundle</packaging>
|
||||||
|
<name>Apache Felix Bundle Repository</name>
|
||||||
|
<description>Bundle repository service.</description>
|
||||||
|
<artifactId>org.apache.felix.bundlerepository</artifactId>
|
||||||
|
<version>1.6.6</version>
|
||||||
|
<scm>
|
||||||
|
<connection>scm:svn:http://svn.apache.org/repos/asf/felix/releases/org.apache.felix.bundlerepository-1.6.6</connection>
|
||||||
|
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/felix/releases/org.apache.felix.bundlerepository-1.6.6</developerConnection>
|
||||||
|
<url>http://svn.apache.org/repos/asf/felix/releases/org.apache.felix.bundlerepository-1.6.6</url>
|
||||||
|
</scm>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>org.apache.felix.utils</artifactId>
|
||||||
|
<version>1.1.0</version>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>org.osgi.service.obr</artifactId>
|
||||||
|
<version>1.0.2</version>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>org.apache.felix.shell</artifactId>
|
||||||
|
<version>1.4.1</version>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.sf.kxml</groupId>
|
||||||
|
<artifactId>kxml2</artifactId>
|
||||||
|
<version>2.3.0</version>
|
||||||
|
<optional>true</optional>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>xmlpull</groupId>
|
||||||
|
<artifactId>xmlpull</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.osgi</groupId>
|
||||||
|
<artifactId>org.osgi.compendium</artifactId>
|
||||||
|
<version>4.0.0</version>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.osgi</groupId>
|
||||||
|
<artifactId>org.osgi.core</artifactId>
|
||||||
|
<version>4.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.woodstox</groupId>
|
||||||
|
<artifactId>woodstox-core-asl</artifactId>
|
||||||
|
<version>4.0.7</version>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.easymock</groupId>
|
||||||
|
<artifactId>easymock</artifactId>
|
||||||
|
<version>2.4</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-bundle-plugin</artifactId>
|
||||||
|
<version>2.3.4</version>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
<configuration>
|
||||||
|
<instructions>
|
||||||
|
<Export-Package>org.apache.felix.bundlerepository;version="2.0"</Export-Package>
|
||||||
|
<Private-Package>
|
||||||
|
org.kxml2.io,
|
||||||
|
org.xmlpull.v1,
|
||||||
|
org.apache.felix.bundlerepository.impl.*,
|
||||||
|
org.apache.felix.utils.*
|
||||||
|
</Private-Package>
|
||||||
|
<Import-Package>!javax.xml.parsers,!org.xml.sax,org.osgi.service.log;resolution:=optional,org.osgi.service.obr;resolution:=optional,javax.xml.stream;resolution:=optional,*</Import-Package>
|
||||||
|
<DynamicImport-Package>org.apache.felix.shell</DynamicImport-Package>
|
||||||
|
<Bundle-Activator>${project.artifactId}.impl.Activator</Bundle-Activator>
|
||||||
|
<Bundle-DocURL>http://felix.apache.org/site/apache-felix-osgi-bundle-repository.html</Bundle-DocURL>
|
||||||
|
<Bundle-Url>http://felix.apache.org/site/downloads.cgi</Bundle-Url>
|
||||||
|
<Bundle-Source>http://felix.apache.org/site/downloads.cgi</Bundle-Source>
|
||||||
|
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||||
|
<Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor>
|
||||||
|
<Export-Service>org.apache.felix.bundlerepository.RepositoryAdmin,org.osgi.service.obr.RepositoryAdmin</Export-Service>
|
||||||
|
<_versionpolicy>[$(version;==;$(@)),$(version;+;$(@)))</_versionpolicy>
|
||||||
|
<Include-Resource>META-INF/LICENSE=LICENSE,META-INF/LICENSE.kxml2=LICENSE.kxml2,META-INF/NOTICE=NOTICE,META-INF/DEPENDENCIES=DEPENDENCIES</Include-Resource>
|
||||||
|
</instructions>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.rat</groupId>
|
||||||
|
<artifactId>apache-rat-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<excludeSubProjects>false</excludeSubProjects>
|
||||||
|
<useEclipseDefaultExcludes>true</useEclipseDefaultExcludes>
|
||||||
|
<useMavenDefaultExcludes>true</useMavenDefaultExcludes>
|
||||||
|
<excludes>
|
||||||
|
<param>doc/*</param>
|
||||||
|
<param>maven-eclipse.xml</param>
|
||||||
|
<param>.checkstyle</param>
|
||||||
|
<param>.externalToolBuilders/*</param>
|
||||||
|
</excludes>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
Loading…
Reference in New Issue