</dependency>
</dependencies>
<build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>cobertura-maven-plugin</artifactId>
- <configuration>
- <check>
- <!-- TODO: increase coverage -->
- <totalLineRate>80</totalLineRate>
- <totalBranchRate>80</totalBranchRate>
- </check>
- </configuration>
- </plugin>
- </plugins>
<pluginManagement>
<plugins>
<plugin>
<artifactId>apache-rat-plugin</artifactId>
<configuration>
<excludes>
- <exclude>src/test/resources/nexus-search-test-repo*/**</exclude>
+ <exclude>src/test/nexus-search-test-repo*/**</exclude>
</excludes>
</configuration>
</plugin>
if ( StringUtils.isNotBlank( searchFields.getClassifier() ) )
{
- q.add( indexer.constructQuery( MAVEN.CLASSIFIER, new StringSearchExpression( searchFields.getClassifier() ) ),
- Occur.MUST );
+ q.add(
+ indexer.constructQuery( MAVEN.CLASSIFIER, new StringSearchExpression( searchFields.getClassifier() ) ),
+ Occur.MUST );
}
if ( q.getClauses() == null || q.getClauses().length <= 0 )
private SearchResults search( SearchResultLimits limits, BooleanQuery q, List<String> indexingContextIds )
throws RepositorySearchException
{
+
try
{
FlatSearchRequest request = new FlatSearchRequest( q );
{
log.warn( "IO error occured while accessing index of repository '" + repo + "' : " + e.getMessage() );
continue;
- } catch ( RepositoryAdminException e )
+ }
+ catch ( RepositoryAdminException e )
{
- log.warn( "RepositoryAdminException occured while accessing index of repository '" + repo + "' : " + e.getMessage() );
+ log.warn( "RepositoryAdminException occured while accessing index of repository '" + repo + "' : "
+ + e.getMessage() );
continue;
}
}
for ( ArtifactInfo artifactInfo : artifactInfos )
{
- String id = SearchUtil.getHitId( artifactInfo.groupId, artifactInfo.artifactId );
+ String id = SearchUtil.getHitId( artifactInfo.groupId, artifactInfo.artifactId, artifactInfo.classifier,
+ artifactInfo.packaging );
Map<String, SearchResultHit> hitsMap = results.getHitsMap();
SearchResultHit hit = hitsMap.get( id );
SearchResultHit hit = results.getHits().get( ( offset + i ) );
if ( hit != null )
{
- String id = SearchUtil.getHitId( hit.getGroupId(), hit.getArtifactId() );
+ String id = SearchUtil.getHitId( hit.getGroupId(), hit.getArtifactId(), hit.getClassifier(),
+ hit.getPackaging() );
paginated.addHit( id, hit );
}
else
return sb.toString();
}
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o )
+ {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() )
+ {
+ return false;
+ }
+
+ SearchResultHit that = (SearchResultHit) o;
+
+ if ( artifactId != null ? !artifactId.equals( that.artifactId ) : that.artifactId != null )
+ {
+ return false;
+ }
+ if ( classifier != null ? !classifier.equals( that.classifier ) : that.classifier != null )
+ {
+ return false;
+ }
+ if ( groupId != null ? !groupId.equals( that.groupId ) : that.groupId != null )
+ {
+ return false;
+ }
+ if ( packaging != null ? !packaging.equals( that.packaging ) : that.packaging != null )
+ {
+ return false;
+ }
+
+ return true;
+ }
+ @Override
+ public int hashCode()
+ {
+ int result = groupId != null ? groupId.hashCode() : 0;
+ result = 31 * result + ( artifactId != null ? artifactId.hashCode() : 0 );
+ result = 31 * result + ( packaging != null ? packaging.hashCode() : 0 );
+ result = 31 * result + ( classifier != null ? classifier.hashCode() : 0 );
+ return result;
+ }
}
/**
- * SearchResults
+ * SearchResults
*
* @version $Id: SearchResults.java 742859 2009-02-10 05:35:05Z jdumay $
*/
// for new RepositorySearch
public void addHit( String id, SearchResultHit hit )
- {
+ {
hits.put( id, hit );
}
/**
* Get the list of {@link SearchResultHit} objects.
- *
+ *
* @return the list of {@link SearchResultHit} objects.
*/
public List<SearchResultHit> getHits()
{
return new ArrayList<SearchResultHit>( hits.values() );
}
-
+
+ /**
+ * see SearchUtil on how to generate the key
+ *
+ * @param key
+ * @return
+ */
+ public SearchResultHit getSearchResultHit( String key )
+ {
+ return hits.get( key );
+ }
+
public Map<String, SearchResultHit> getHitsMap()
{
return hits;
}
/**
- * @since 1.4
* @return
+ * @since 1.4
*/
public int getReturnedHitsCount()
{
}
/**
- * @since 1.4
* @param returnedHitsCount
+ * @since 1.4
*/
public void setReturnedHitsCount( int returnedHitsCount )
{
* under the License.
*/
+import org.apache.commons.lang.StringUtils;
+
/**
* SearchUtil - utility class for search.
*/
public class SearchUtil
{
- public static String getHitId( String groupId, String artifactId )
+ public static String getHitId( String groupId, String artifactId, String classifier, String packaging )
{
- return groupId + ":" + artifactId;
+ return ( StringUtils.isBlank( groupId ) ? "" : StringUtils.trim( groupId ) ) + ":"
+ + ( StringUtils.isBlank( artifactId ) ? "" : StringUtils.trim( artifactId ) ) + ":"
+ + ( StringUtils.isBlank( classifier ) ? "" : StringUtils.trim( classifier ) ) + ":" + ( StringUtils.isBlank(
+ packaging ) ? "" : StringUtils.trim( packaging ) );
}
}
import javax.inject.Inject;
import java.io.File;
-import java.util.ArrayList;
import java.util.List;
/**
nexusIndexer.removeIndexingContext( indexingContext, true );
}
+ FileUtils.deleteDirectory( new File( FileUtil.getBasedir(), "/target/repos/" + TEST_REPO_1 ) );
+ assertFalse( new File( FileUtil.getBasedir(), "/target/repos/" + TEST_REPO_1 ).exists() );
+
+ FileUtils.deleteDirectory( new File( FileUtil.getBasedir(), "/target/repos/" + TEST_REPO_2 ) );
+ assertFalse( new File( FileUtil.getBasedir(), "/target/repos/" + TEST_REPO_2 ).exists() );
+
super.tearDown();
}
assertFalse( lockFile.exists() );
- File repo = new File( FileUtil.getBasedir(), "/target/repos/" + repository );
- File indexDirectory = new File( FileUtil.getBasedir(), "/target/repos/" + repository + "/.indexer" );
+ File repo = new File( FileUtil.getBasedir(), "src/test/" + repository );
+ assertTrue( repo.exists() );
+ File indexDirectory =
+ new File( FileUtil.getBasedir(), "target/index/test-" + Long.toString( System.currentTimeMillis() ) );
+ indexDirectory.deleteOnExit();
+ FileUtils.deleteDirectory( indexDirectory );
context = nexusIndexer.addIndexingContext( repository, repository, repo, indexDirectory,
repo.toURI().toURL().toExternalForm(),
indexDirectory.toURI().toURL().toString(),
search.getAllIndexCreators() );
- List<ArtifactContext> artifactContexts = new ArrayList<ArtifactContext>( filesToBeIndexed.size() );
+ // minimize datas in memory
+ context.getIndexWriter().setMaxBufferedDocs( -1 );
+ context.getIndexWriter().setRAMBufferSizeMB( 1 );
for ( File artifactFile : filesToBeIndexed )
{
+ assertTrue( "file not exists " + artifactFile.getPath(), artifactFile.exists() );
ArtifactContext ac = artifactContextProducer.getArtifactContext( context, artifactFile );
- artifactContexts.add( ac );
+ nexusIndexer.addArtifactToIndex( ac, context );
+ context.updateTimestamp( true );
}
- if ( filesToBeIndexed != null && !filesToBeIndexed.isEmpty() )
- {
- nexusIndexer.addArtifactsToIndex( artifactContexts, context );
-
- while ( context.isReceivingUpdates() )
- {
- Thread.sleep( 10 );
- }
- }
if ( scan )
{
nexusIndexer.scan( context, new ArtifactScanListener(), false );
}
-
+ // force flushing
+ context.getIndexWriter().commit();
+ context.getIndexWriter().close( true );
+ // wait for io flush ....
+ //Thread.sleep( 2000 );
context.setSearchable( true );
- assertTrue( new File( FileUtil.getBasedir(), "/target/repos/" + repository + "/.indexer" ).exists() );
}
static class ArtifactScanListener
* under the License.
*/
+import org.apache.archiva.indexer.util.SearchUtil;
import org.apache.maven.archiva.common.utils.FileUtil;
-import org.apache.maven.index.artifact.IllegalArtifactCoordinateException;
-import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.File;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
throws Exception
{
List<File> files = new ArrayList<File>();
- files.add( new File( FileUtil.getBasedir(), "src/test" + TEST_REPO_1
+ files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
+ "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
+ "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ) );
- files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ files.add( new File( FileUtil.getBasedir(), "/src/test/" + TEST_REPO_1
+ "/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ) );
createIndex( TEST_REPO_1, files, scan );
+ "/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ) );
files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
+ "/org/apache/archiva/archiva-webapp/1.0/archiva-webapp-1.0.war" ) );
- files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
- + "/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar" ) );
+ files.add( new File( FileUtil.getBasedir(),
+ "src/test/" + TEST_REPO_1 + "/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar" ) );
files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
+ "/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar" ) );
- files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
- + "/com/classname-search/1.0/classname-search-1.0.jar" ) );
+ files.add( new File( FileUtil.getBasedir(),
+ "src/test/" + TEST_REPO_1 + "/com/classname-search/1.0/classname-search-1.0.jar" ) );
createIndex( TEST_REPO_1, files, scan );
}
archivaConfigControl.verify();
assertNotNull( results );
- assertEquals( 1, results.getTotalHits() );
- SearchResultHit hit = results.getHits().get( 0 );
+ SearchResultHit hit =
+ results.getSearchResultHit( SearchUtil.getHitId( "org.apache.archiva", "archiva-search", null, "jar" ) );
+ assertNotNull( "hit null in result " + results.getHits(), hit );
assertEquals( "org.apache.archiva", hit.getGroupId() );
assertEquals( "archiva-search", hit.getArtifactId() );
assertEquals( "1.0", hit.getVersions().get( 0 ) );
public void testMultipleArtifactsSameVersionWithClassifier()
throws Exception
{
- createIndexContainingMultipleArtifactsSameVersion( false );
+ createIndexContainingMultipleArtifactsSameVersion( true );
List<String> selectedRepos = new ArrayList<String>();
selectedRepos.add( TEST_REPO_1 );
archivaConfigControl.replay();
+ // wait lucene flush.....
+ Thread.sleep( 2000 );
+
SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null );
archivaConfigControl.verify();
assertNotNull( results );
- assertEquals( 4, results.getTotalHits() );
- SearchResultHit hit = results.getHits().get( 0 );
+ SearchResultHit hit =
+ results.getSearchResultHit( SearchUtil.getHitId( "org.apache.archiva", "archiva-search", null, "jar" ) );
assertEquals( "org.apache.archiva", hit.getGroupId() );
assertEquals( "archiva-search", hit.getArtifactId() );
- assertEquals("not 2 version for hit " + hit, 2, hit.getVersions().size() );
+ assertEquals( "not 2 version for hit " + hit + "::" + niceDisplay( results ), 2, hit.getVersions().size() );
assertTrue( hit.getVersions().contains( "1.0" ) );
assertTrue( hit.getVersions().contains( "1.1" ) );
throws Exception
{
List<File> files = new ArrayList<File>();
- files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
- + "/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar" ) );
+ files.add( new File( FileUtil.getBasedir(),
+ "src/test/" + TEST_REPO_1 + "/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar" ) );
files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
+ "/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar" ) );
createIndex( TEST_REPO_1, files, true );
{
createIndexContainingMoreArtifacts( true );
- List<String> selectedRepos = new ArrayList<String>();
- selectedRepos.add( TEST_REPO_1 );
+ List<String> selectedRepos = Arrays.asList( TEST_REPO_1 );
SearchFields searchFields = new SearchFields();
searchFields.setClassName( "com.classname.search.App" );
nexusIndexer.addArtifactToIndex( ac, context );
}
- //nexusIndexer.scan( context, true );
-
context.updateTimestamp();
// close the context if not a repo scan request