public void testSearchTerm_Org()
throws Exception
- {
+ {
CrossRepositorySearch search = lookupCrossRepositorySearch();
String expectedRepos[] = new String[] {
"org","org2","org3","org4","org5","org6","org7"
};
- assertSearchResults( expectedRepos, expectedResults, search, "org", null );
+ assertSearchResults( expectedRepos, expectedResults, search, "org", null, false );
}
public void testSearchTerm_Junit()
throws Exception
- {
+ {
CrossRepositorySearch search = lookupCrossRepositorySearch();
String expectedRepos[] = new String[] {
"junit","junit2","junit3"
};
- assertSearchResults( expectedRepos, expectedResults, search, "junit", null );
+ assertSearchResults( expectedRepos, expectedResults, search, "junit", null, false );
}
public void testSearchInvalidTerm()
throws Exception
- {
+ {
CrossRepositorySearch search = lookupCrossRepositorySearch();
String expectedRepos[] = new String[] {
// Nothing.
};
- assertSearchResults( expectedRepos, expectedResults, search, "monosodium", null );
+ assertSearchResults( expectedRepos, expectedResults, search, "monosodium", null, false );
}
public void testSearchWithinSearchResults()
throws Exception
- {
+ {
CrossRepositorySearch search = lookupCrossRepositorySearch();
String expectedRepos[] = new String[] {
};
// first search
- assertSearchResults( expectedRepos, expectedResults, search, "org", null );
+ assertSearchResults( expectedRepos, expectedResults, search, "org", null, false );
List<String> previousSearchTerms = new ArrayList<String>();
previousSearchTerms.add( "org" );
"org.apache.maven.archiva.record", "org.apache.maven.archiva.record2",
"org.apache.maven.archiva.record3", "org.apache.maven.archiva.record4",
"org.apache.maven.archiva.record5", "org.apache.maven.archiva.record6",
- "org.apache.maven.archiva.record7"
+ "org.apache.maven.archiva.record7"
};
//second search
assertSearchResults( expectedRepos, secondSearchExpectedResults, search, "org.apache.maven.archiva.record",
- previousSearchTerms );
+ previousSearchTerms, false );
previousSearchTerms.add( "org.apache.maven.archiva.record" );
String thirdSearchExpectedResults[] = new String[] {
};
//third search
- assertSearchResults( expectedRepos, thirdSearchExpectedResults, search, "junit", previousSearchTerms );
+ assertSearchResults( expectedRepos, thirdSearchExpectedResults, search, "junit", previousSearchTerms, false );
+ }
+
+ public void testSearchForClassesAndPackages()
+ throws Exception
+ {
+ CrossRepositorySearch search = lookupCrossRepositorySearch();
+
+ String expectedRepos[] = new String[] {
+ TEST_DEFAULT_REPO_ID
+ };
+
+ String expectedResults[] = new String[] {
+ "archiva-common-1.0.jar"
+ };
+
+ // class with packagename search
+ assertSearchResults( expectedRepos, expectedResults, search,
+ "org.apache.maven.archiva.common.utils.BaseFile", null, true );
+ // class name search
+ assertSearchResults( expectedRepos, expectedResults, search,
+ "BaseFile", null, true );
+
+ String expectedMethodSearchResults[] = new String[] {
+ "continuum-webapp-1.0.3-SNAPSHOT.war"
+ };
+
+ // method search
+ assertSearchResults( expectedRepos, expectedMethodSearchResults, search,
+ "org.apache.maven.continuum.web.action.BuildDefinitionAction.isBuildFresh", null, true );
}
private void assertSearchResults( String expectedRepos[], String expectedResults[], CrossRepositorySearch search,
- String term, List<String> previousSearchTerms )
+ String term, List<String> previousSearchTerms, boolean bytecode )
throws Exception
{
SearchResultLimits limits = new SearchResultLimits( 0 );
SearchResults results = null;
if( previousSearchTerms == null )
{
- results = search.searchForTerm( "guest", selectedRepos, term, limits );
+ if( bytecode )
+ {
+ results = search.searchForBytecode( "guest", selectedRepos, term, limits );
+ }
+ else
+ {
+ results = search.searchForTerm( "guest", selectedRepos, term, limits );
+ }
}
else
{
private String completeQueryString;
private static final String COMPLETE_QUERY_STRING_SEPARATOR = ";";
+
+ private static final String[] BYTECODE_KEYWORDS = new String[] { "class:", "package:", "method:" };
public String quickSearch()
throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException
return GlobalResults.ACCESS_TO_NO_REPOS;
}
- if( searchResultsOnly && !completeQueryString.equals( "" ) )
- {
- results = crossRepoSearch.searchForTerm( getPrincipal(), selectedRepos, q, limits, parseCompleteQueryString() );
+ if( isBytecodeSearch( q ) )
+ {
+ results = crossRepoSearch.searchForBytecode( getPrincipal(), selectedRepos, removeKeywords( q ), limits );
}
else
{
- completeQueryString = "";
- results = crossRepoSearch.searchForTerm( getPrincipal(), selectedRepos, q, limits );
+ if( searchResultsOnly && !completeQueryString.equals( "" ) )
+ {
+ results = crossRepoSearch.searchForTerm( getPrincipal(), selectedRepos, q, limits, parseCompleteQueryString() );
+ }
+ else
+ {
+ completeQueryString = "";
+ results = crossRepoSearch.searchForTerm( getPrincipal(), selectedRepos, q, limits );
+ }
}
if ( results.isEmpty() )
{
this.completeQueryString = completeQueryString;
}
+
+ private boolean isBytecodeSearch( String queryString )
+ {
+ if( queryString.startsWith( BYTECODE_KEYWORDS[0] ) || queryString.startsWith( BYTECODE_KEYWORDS[1] ) ||
+ queryString.startsWith( BYTECODE_KEYWORDS[2] ) )
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ private String removeKeywords( String queryString )
+ {
+ String qString = StringUtils.uncapitalize( queryString );
+ qString = StringUtils.removeStart( queryString, BYTECODE_KEYWORDS[0] );
+ qString = StringUtils.removeStart( qString, BYTECODE_KEYWORDS[1] );
+ qString = StringUtils.removeStart( qString, BYTECODE_KEYWORDS[2] );
+
+ return qString;
+ }
}