Signed-off-by: Olivier Lamy <olamy@apache.org>master-maven-indexer-6.0.1
active = activeContexts.add( ctxPath ); | active = activeContexts.add( ctxPath ); | ||||
try | try | ||||
{ | { | ||||
Thread.currentThread( ).sleep( WAIT_TIME ); | |||||
Thread.currentThread().sleep(WAIT_TIME); | |||||
} | } | ||||
catch ( InterruptedException e ) | catch ( InterruptedException e ) | ||||
{ | { | ||||
DefaultScannerListener listener = new DefaultScannerListener( indexingContext, indexerEngine, true, null ); | DefaultScannerListener listener = new DefaultScannerListener( indexingContext, indexerEngine, true, null ); | ||||
ScanningRequest request = new ScanningRequest( indexingContext, listener ); | ScanningRequest request = new ScanningRequest( indexingContext, listener ); | ||||
ScanningResult result = scanner.scan( request ); | ScanningResult result = scanner.scan( request ); | ||||
if ( result.hasExceptions( ) ) | |||||
if (result.hasExceptions() && log.isErrorEnabled()) | |||||
{ | { | ||||
log.error( "Exceptions occured during index scan of " + context.getId( ) ); | log.error( "Exceptions occured during index scan of " + context.getId( ) ); | ||||
result.getExceptions( ).stream( ).map( e -> e.getMessage( ) ).distinct( ).limit( 5 ).forEach( | |||||
s -> log.error( "Message: " + s ) | |||||
result.getExceptions().stream().map(Throwable::getMessage) | |||||
.distinct().limit(5) | |||||
.forEach(s -> log.error("Message: {}", s) | |||||
); | ); | ||||
} | } | ||||
httpMethodConfiguration.setUsePreemptive( true ); | httpMethodConfiguration.setUsePreemptive( true ); | ||||
httpMethodConfiguration.setReadTimeout( readTimeout ); | httpMethodConfiguration.setReadTimeout( readTimeout ); | ||||
httpConfiguration.setGet( httpMethodConfiguration ); | httpConfiguration.setGet( httpMethodConfiguration ); | ||||
AbstractHttpClientWagon.class.cast( wagon ).setHttpConfiguration( httpConfiguration ); | |||||
((AbstractHttpClientWagon)wagon).setHttpConfiguration(httpConfiguration ); | |||||
} | } | ||||
wagon.addTransferListener( new DownloadListener( ) ); | wagon.addTransferListener( new DownloadListener( ) ); | ||||
private static final class DownloadListener | private static final class DownloadListener | ||||
implements TransferListener | implements TransferListener | ||||
{ | { | ||||
private Logger log = LoggerFactory.getLogger( getClass( ) ); | |||||
private final Logger log = LoggerFactory.getLogger( getClass( ) ); | |||||
private String resourceName; | private String resourceName; | ||||
@Override | @Override | ||||
public InputStream retrieve(String name ) | public InputStream retrieve(String name ) | ||||
throws IOException, FileNotFoundException | |||||
throws IOException | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
} | } | ||||
catch ( ResourceDoesNotExistException e ) | catch ( ResourceDoesNotExistException e ) | ||||
{ | { | ||||
FileNotFoundException fnfe = new FileNotFoundException( e.getMessage( ) ); | |||||
fnfe.initCause( e ); | |||||
FileNotFoundException fnfe = new FileNotFoundException(e.getMessage( )); | |||||
fnfe.initCause(e); | |||||
throw fnfe; | throw fnfe; | ||||
} | } | ||||
} | } |
import org.apache.archiva.indexer.UnsupportedBaseContextException; | import org.apache.archiva.indexer.UnsupportedBaseContextException; | ||||
import org.apache.archiva.indexer.search.ArtifactInfoFilter; | import org.apache.archiva.indexer.search.ArtifactInfoFilter; | ||||
import org.apache.archiva.maven.indexer.search.NoClassifierArtifactInfoFilter; | |||||
import org.apache.archiva.indexer.search.RepositorySearch; | import org.apache.archiva.indexer.search.RepositorySearch; | ||||
import org.apache.archiva.indexer.search.RepositorySearchException; | import org.apache.archiva.indexer.search.RepositorySearchException; | ||||
import org.apache.archiva.indexer.search.SearchFields; | import org.apache.archiva.indexer.search.SearchFields; | ||||
public class MavenRepositorySearch | public class MavenRepositorySearch | ||||
implements RepositorySearch | implements RepositorySearch | ||||
{ | { | ||||
private Logger log = LoggerFactory.getLogger( getClass() ); | |||||
private final Logger log = LoggerFactory.getLogger( getClass() ); | |||||
private Indexer indexer; | private Indexer indexer; | ||||
throw new RepositorySearchException( "No search fields set." ); | throw new RepositorySearchException( "No search fields set." ); | ||||
} | } | ||||
if (qu.clauses()!=null) { | if (qu.clauses()!=null) { | ||||
log.debug("CLAUSES ", qu.clauses()); | |||||
log.debug("CLAUSES {}", qu.clauses()); | |||||
for (BooleanClause cl : qu.clauses()) { | for (BooleanClause cl : qu.clauses()) { | ||||
log.debug("Clause ",cl); | |||||
log.debug("Clause {}",cl); | |||||
} | } | ||||
} | } | ||||
return search( limits, qu, indexingContextIds, Collections.<ArtifactInfoFilter>emptyList(), | |||||
return search( limits, qu, indexingContextIds, Collections.emptyList(), | |||||
searchFields.getRepositories(), searchFields.isIncludePomArtifacts() ); | searchFields.getRepositories(), searchFields.isIncludePomArtifacts() ); | ||||
} | } | ||||
{ | { | ||||
log.warn( "RepositorySearchException occured while accessing index of repository '{}' : {}", repo, | log.warn( "RepositorySearchException occured while accessing index of repository '{}' : {}", repo, | ||||
e.getMessage() ); | e.getMessage() ); | ||||
continue; | |||||
} catch (UnsupportedBaseContextException e) { | } catch (UnsupportedBaseContextException e) { | ||||
log.error("Fatal situation: Maven repository without IndexingContext found."); | log.error("Fatal situation: Maven repository without IndexingContext found."); | ||||
continue; | |||||
} | } | ||||
} | } | ||||
import org.apache.archiva.repository.base.RepositoryHandlerDependencies; | import org.apache.archiva.repository.base.RepositoryHandlerDependencies; | ||||
import org.apache.archiva.repository.features.IndexCreationFeature; | import org.apache.archiva.repository.features.IndexCreationFeature; | ||||
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; | import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; | ||||
import org.apache.commons.lang3.SystemUtils; | |||||
import org.apache.maven.index.ArtifactContext; | import org.apache.maven.index.ArtifactContext; | ||||
import org.apache.maven.index.ArtifactContextProducer; | import org.apache.maven.index.ArtifactContextProducer; | ||||
import org.apache.maven.index.ArtifactScanningListener; | import org.apache.maven.index.ArtifactScanningListener; | ||||
StringBuilder sb = new StringBuilder(); | StringBuilder sb = new StringBuilder(); | ||||
for ( SearchResultHit hit : searchResults.getHits() ) | for ( SearchResultHit hit : searchResults.getHits() ) | ||||
{ | { | ||||
sb.append( hit.toString() ).append( SystemUtils.LINE_SEPARATOR ); | |||||
sb.append( hit.toString() ).append( System.lineSeparator() ); | |||||
} | } | ||||
return sb.toString(); | return sb.toString(); | ||||
} | } |
{ | { | ||||
createSimpleIndex( false ); | createSimpleIndex( false ); | ||||
List<String> selectedRepos = Arrays.asList( TEST_REPO_1 ); | |||||
List<String> selectedRepos = Collections.singletonList(TEST_REPO_1); | |||||
// search artifactId | // search artifactId | ||||
when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) ); | when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) ); | ||||
{ | { | ||||
createIndexContainingMoreArtifacts( true ); | createIndexContainingMoreArtifacts( true ); | ||||
List<String> selectedRepos = Arrays.asList( TEST_REPO_1 ); | |||||
List<String> selectedRepos = Collections.singletonList(TEST_REPO_1); | |||||
SearchFields searchFields = new SearchFields(); | SearchFields searchFields = new SearchFields(); | ||||
searchFields.setClassName( "com.classname.search.App" ); | searchFields.setClassName( "com.classname.search.App" ); | ||||
{ | { | ||||
createIndexContainingMoreArtifacts( true ); | createIndexContainingMoreArtifacts( true ); | ||||
List<String> selectedRepos = Arrays.asList( TEST_REPO_1 ); | |||||
List<String> selectedRepos = Collections.singletonList(TEST_REPO_1); | |||||
SearchFields searchFields = new SearchFields(); | SearchFields searchFields = new SearchFields(); | ||||
searchFields.setClassName( "SomeClass" ); | searchFields.setClassName( "SomeClass" ); | ||||
{ | { | ||||
createIndexContainingMoreArtifacts( true ); | createIndexContainingMoreArtifacts( true ); | ||||
List<String> selectedRepos = Arrays.asList( TEST_REPO_1 ); | |||||
List<String> selectedRepos = Collections.singletonList(TEST_REPO_1); | |||||
when( archivaConfig.getConfiguration() ).thenReturn( config ); | when( archivaConfig.getConfiguration() ).thenReturn( config ); | ||||
{ | { | ||||
createIndexContainingMoreArtifacts( true ); | createIndexContainingMoreArtifacts( true ); | ||||
List<String> selectedRepos = Arrays.asList( "foo" ); | |||||
List<String> selectedRepos = Collections.singletonList("foo"); | |||||
SearchFields searchFields = new SearchFields(); | SearchFields searchFields = new SearchFields(); | ||||
searchFields.setClassName( "SomeClass" ); | searchFields.setClassName( "SomeClass" ); | ||||
SearchFields searchFields = new SearchFields(); | SearchFields searchFields = new SearchFields(); | ||||
searchFields.setGroupId("org.example"); | searchFields.setGroupId("org.example"); | ||||
searchFields.setRepositories(Arrays.asList(REPO_RELEASE)); | |||||
searchFields.setRepositories(Collections.singletonList(REPO_RELEASE)); | |||||
searchResults = search.search(null, searchFields, limits); | searchResults = search.search(null, searchFields, limits); | ||||
*/ | */ | ||||
private void executeUpdateFunction( ArchivaIndexingContext context, IndexUpdateConsumer function ) throws IndexUpdateFailedException | private void executeUpdateFunction( ArchivaIndexingContext context, IndexUpdateConsumer function ) throws IndexUpdateFailedException | ||||
{ | { | ||||
IndexingContext indexingContext = null; | |||||
IndexingContext indexingContext; | |||||
try | try | ||||
{ | { | ||||
indexingContext = getMvnContext( context ); | indexingContext = getMvnContext( context ); | ||||
DefaultScannerListener listener = new DefaultScannerListener( indexingContext, indexerEngine, true, null ); | DefaultScannerListener listener = new DefaultScannerListener( indexingContext, indexerEngine, true, null ); | ||||
ScanningRequest request = new ScanningRequest( indexingContext, listener ); | ScanningRequest request = new ScanningRequest( indexingContext, listener ); | ||||
ScanningResult result = scanner.scan( request ); | ScanningResult result = scanner.scan( request ); | ||||
if ( result.hasExceptions( ) ) | |||||
if (result.hasExceptions() && log.isErrorEnabled()) | |||||
{ | { | ||||
log.error( "Exceptions occured during index scan of " + context.getId( ) ); | |||||
result.getExceptions( ).stream( ).map( e -> e.getMessage( ) ).distinct( ).limit( 5 ).forEach( | |||||
s -> log.error( "Message: " + s ) | |||||
log.error("Exceptions occured during index scan of {}", context.getId()); | |||||
result.getExceptions().stream() | |||||
.map(Throwable::getMessage).distinct() | |||||
.limit(5).forEach(s -> log.error( "Message: {}", s ) | |||||
); | ); | ||||
} | } | ||||
private static final class DownloadListener | private static final class DownloadListener | ||||
implements TransferListener | implements TransferListener | ||||
{ | { | ||||
private Logger log = LoggerFactory.getLogger( getClass( ) ); | |||||
private final Logger log = LoggerFactory.getLogger( getClass( ) ); | |||||
private String resourceName; | private String resourceName; | ||||