org.apache.maven.index.context.IndexingContext Java Examples
The following examples show how to use
org.apache.maven.index.context.IndexingContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RepositoryIndexerListener.java From netbeans with Apache License 2.0 | 6 votes |
@Messages({ "# {0} - repo name", "LBL_indexing_repo=Indexing Maven repository: {0}", "LBL_findIndexableDirs=Counting indexable directories..." }) @Override public void scanningStarted(IndexingContext ctx) { if (handle != null) { handle.finish(); } expectedDirs.clear(); encounteredDirs.clear(); handle = ProgressHandle.createHandle(Bundle.LBL_indexing_repo(ri != null ? ri.getName() : indexingContext.getId()), this); handle.start(); handle.progress(Bundle.LBL_findIndexableDirs()); findIndexableDirs(ctx.getRepository()); handle.switchToDeterminate(expectedDirs.size()); }
Example #2
Source File: NexusRepositoryIndexerImpl.java From netbeans with Apache License 2.0 | 6 votes |
private ResultImplementation<NBVersionInfo> getVersions(final String groupId, final String artifactId, final ResultImpl<NBVersionInfo> result, List<RepositoryInfo> repos, final boolean skipUnIndexed) { final List<NBVersionInfo> infos = new ArrayList<NBVersionInfo>(result.getResults()); final SkippedAction skipAction = new SkippedAction(result); iterate(repos, new RepoAction() { @Override public void run(RepositoryInfo repo, IndexingContext context) throws IOException { BooleanQuery bq = new BooleanQuery(); String id = groupId + ArtifactInfo.FS + artifactId + ArtifactInfo.FS; bq.add(new BooleanClause(setBooleanRewrite(new PrefixQuery(new Term(ArtifactInfo.UINFO, id))), BooleanClause.Occur.MUST)); IteratorSearchResponse response = repeatedPagedSearch(bq, Collections.singletonList(context), MAX_RESULT_COUNT); if (response != null) { try { for (ArtifactInfo ai : response.iterator()) { infos.add(convertToNBVersionInfo(ai)); } } finally { result.addReturnedResultCount(response.getTotalProcessedArtifactInfoCount()); result.addTotalResultCount(response.getTotalHitsCount()); response.close(); } } } }, skipAction, skipUnIndexed); doSortIssue226100(infos); result.setResults(infos); return result; }
Example #3
Source File: NexusRepositoryIndexerImpl.java From netbeans with Apache License 2.0 | 6 votes |
private ResultImplementation<String> getArtifacts(final String groupId, final ResultImpl<String> result, final List<RepositoryInfo> repos, final boolean skipUnIndexed) { final Set<String> artifacts = new TreeSet<String>(result.getResults()); final SkippedAction skipAction = new SkippedAction(result); iterate(repos, new RepoAction() { @Override public void run(RepositoryInfo repo, IndexingContext context) throws IOException { BooleanQuery bq = new BooleanQuery(); String id = groupId + ArtifactInfo.FS; bq.add(new BooleanClause(setBooleanRewrite(new PrefixQuery(new Term(ArtifactInfo.UINFO, id))), BooleanClause.Occur.MUST)); //mkleint: this is not capped, because only a string is collected (and collapsed), the rest gets CGed fast IteratorSearchResponse response = repeatedPagedSearch(bq, Collections.singletonList(context), NO_CAP_RESULT_COUNT); if (response != null) { try { for (ArtifactInfo artifactInfo : response.getResults()) { artifacts.add(artifactInfo.getArtifactId()); } } finally { response.close(); } } } }, skipAction, skipUnIndexed); result.setResults(artifacts); return result; }
Example #4
Source File: MavenRepositorySearch.java From archiva with Apache License 2.0 | 6 votes |
@Override public Collection<String> getAllGroupIds( String principal, List<String> selectedRepos ) throws RepositorySearchException { List<IndexingContext> indexContexts = getIndexingContexts( selectedRepos ); if ( indexContexts == null || indexContexts.isEmpty() ) { return Collections.emptyList(); } try { Set<String> allGroupIds = new HashSet<>(); for ( IndexingContext indexingContext : indexContexts ) { allGroupIds.addAll( indexingContext.getAllGroups() ); } return allGroupIds; } catch ( IOException e ) { throw new RepositorySearchException( e.getMessage(), e ); } }
Example #5
Source File: NexusRepositoryIndexerImpl.java From netbeans with Apache License 2.0 | 6 votes |
private ResultImplementation<NBVersionInfo> findDependencyUsage(String groupId, String artifactId, String version, final ResultImpl<NBVersionInfo> result, @NullAllowed List<RepositoryInfo> repos, final boolean skipUnIndexed) { final Query q = ArtifactDependencyIndexCreator.query(groupId, artifactId, version); final List<NBVersionInfo> infos = new ArrayList<NBVersionInfo>(result.getResults()); final SkippedAction skipAction = new SkippedAction(result); iterate(repos, new RepoAction() { @Override public void run(RepositoryInfo repo, IndexingContext context) throws IOException { IteratorSearchResponse response = repeatedPagedSearch(q, Collections.singletonList(context), MAX_RESULT_COUNT); if (response != null) { try { for (ArtifactInfo ai : response.iterator()) { infos.add(convertToNBVersionInfo(ai)); } } finally { result.addReturnedResultCount(response.getTotalProcessedArtifactInfoCount()); result.addTotalResultCount(response.getTotalHitsCount()); response.close(); } } } }, skipAction, skipUnIndexed); result.setResults(infos); return result; }
Example #6
Source File: MavenRepositorySearch.java From archiva with Apache License 2.0 | 6 votes |
private IndexingContext getIndexingContext(String id) { String repoId; if (StringUtils.startsWith(id, "remote-")) { repoId = StringUtils.substringAfter(id, "remote-"); } else { repoId = id; } Repository repo = repositoryRegistry.getRepository(repoId); if (repo==null) { return null; } else { if (repo.getIndexingContext()!=null) { try { return repo.getIndexingContext().getBaseContext(IndexingContext.class); } catch (UnsupportedBaseContextException e) { return null; } } else { return null; } } }
Example #7
Source File: NexusRepositoryIndexerImpl.java From netbeans with Apache License 2.0 | 6 votes |
private ResultImplementation<String> filterPluginGroupIds(final String prefix, ResultImpl<String> result, List<RepositoryInfo> repos, final boolean skipUnIndexed) { final Set<String> artifacts = new TreeSet<String>(result.getResults()); final SkippedAction skipAction = new SkippedAction(result); iterate(repos, new RepoAction() { @Override public void run(RepositoryInfo repo, IndexingContext context) throws IOException { BooleanQuery bq = new BooleanQuery(); bq.add(new BooleanClause(new TermQuery(new Term(ArtifactInfo.PACKAGING, "maven-plugin")), BooleanClause.Occur.MUST)); if (prefix.length() > 0) { //heap out of memory otherwise bq.add(new BooleanClause(setBooleanRewrite(new PrefixQuery(new Term(ArtifactInfo.GROUP_ID, prefix))), BooleanClause.Occur.MUST)); } //mkleint: this is not capped, because only a string is collected (and collapsed), the rest gets CGed fast IteratorSearchResponse response = repeatedPagedSearch(bq, Collections.singletonList(context), NO_CAP_RESULT_COUNT); if (response != null) { try { for (ArtifactInfo artifactInfo : response.getResults()) { artifacts.add(artifactInfo.getGroupId()); } } finally { response.close(); } } } }, skipAction, skipUnIndexed); result.setResults(artifacts); return result; }
Example #8
Source File: NexusRepositoryIndexerImpl.java From netbeans with Apache License 2.0 | 6 votes |
private ResultImplementation<String> filterPluginArtifactIds(final String groupId, final String prefix, ResultImpl<String> result, List<RepositoryInfo> repos, final boolean skipUnIndexed) { final Set<String> artifacts = new TreeSet<String>(result.getResults()); final SkippedAction skipAction = new SkippedAction(result); iterate(repos, new RepoAction() { @Override public void run(RepositoryInfo repo, IndexingContext context) throws IOException { BooleanQuery bq = new BooleanQuery(); String id = groupId + ArtifactInfo.FS + prefix; bq.add(new BooleanClause(new TermQuery(new Term(ArtifactInfo.PACKAGING, "maven-plugin")), BooleanClause.Occur.MUST)); bq.add(new BooleanClause(setBooleanRewrite(new PrefixQuery(new Term(ArtifactInfo.UINFO, id))), BooleanClause.Occur.MUST)); //mkleint: this is not capped, because only a string is collected (and collapsed), the rest gets CGed fast IteratorSearchResponse response = repeatedPagedSearch(bq, Collections.singletonList(context), NO_CAP_RESULT_COUNT); if (response != null) { try { for (ArtifactInfo artifactInfo : response.getResults()) { artifacts.add(artifactInfo.getArtifactId()); } } finally { response.close(); } } } }, skipAction, skipUnIndexed); result.setResults(artifacts); return result; }
Example #9
Source File: MavenIndexManagerTest.java From archiva with Apache License 2.0 | 6 votes |
@Test public void removeArtifactsFromIndex() throws Exception { ArchivaIndexingContext ctx = createTestContext(); Path destDir = repository.getRoot().getFilePath().resolve("org/apache/archiva/archiva-search/1.0"); Path srcDir = Paths.get("src/test/maven-search-test-repo/org/apache/archiva/archiva-search/1.0"); org.apache.commons.io.FileUtils.copyDirectory(srcDir.toFile(), destDir.toFile()); List<URI> uriList = new ArrayList<>(); uriList.add(destDir.resolve("archiva-search-1.0.jar").toUri()); uriList.add(destDir.resolve("archiva-search-1.0-sources.jar").toUri()); mavenIndexManager.addArtifactsToIndex(ctx, uriList); IndexingContext mvnCtx = mavenIndexManager.getMvnContext(ctx); String term = "org.apache.archiva"; Query q = new BooleanQuery.Builder().add( queryCreator.constructQuery( MAVEN.GROUP_ID, new UserInputSearchExpression( term ) ), BooleanClause.Occur.SHOULD ).build(); assertEquals(2, mvnCtx.acquireIndexSearcher().count(q)); uriList.remove(0); mavenIndexManager.removeArtifactsFromIndex(ctx, uriList); assertEquals(1, mvnCtx.acquireIndexSearcher().count(q)); }
Example #10
Source File: MavenIndexManagerTest.java From archiva with Apache License 2.0 | 6 votes |
@Test public void addArtifactsToIndex() throws Exception { ArchivaIndexingContext ctx = createTestContext(); try { Path destDir = repository.getRoot().getFilePath().resolve("org/apache/archiva/archiva-search/1.0"); Path srcDir = Paths.get("src/test/maven-search-test-repo/org/apache/archiva/archiva-search/1.0"); org.apache.commons.io.FileUtils.copyDirectory(srcDir.toFile(), destDir.toFile()); List<URI> uriList = new ArrayList<>(); uriList.add(destDir.resolve("archiva-search-1.0.jar").toUri()); uriList.add(destDir.resolve("archiva-search-1.0-sources.jar").toUri()); mavenIndexManager.addArtifactsToIndex(ctx, uriList); IndexingContext mvnCtx = mavenIndexManager.getMvnContext(ctx); String term = "org.apache.archiva"; Query q = new BooleanQuery.Builder().add(queryCreator.constructQuery(MAVEN.GROUP_ID, new UserInputSearchExpression(term)), BooleanClause.Occur.SHOULD).build(); assertEquals(2, mvnCtx.acquireIndexSearcher().count(q)); } finally { try { ctx.close(true); } catch (IOException e) { // Ignore } } }
Example #11
Source File: MavenRepositorySearch.java From archiva with Apache License 2.0 | 6 votes |
private List<IndexingContext> getIndexingContexts( List<String> ids ) { List<IndexingContext> contexts = new ArrayList<>( ids.size() ); for ( String id : ids ) { IndexingContext context = getIndexingContext(id); if ( context != null ) { contexts.add( context ); } else { log.warn( "context with id {} not exists", id ); } } return contexts; }
Example #12
Source File: NexusRepositoryIndexerImpl.java From netbeans with Apache License 2.0 | 6 votes |
private ResultImplementation<NBVersionInfo> findBySHA1(final String sha1, final ResultImpl<NBVersionInfo> result, List<RepositoryInfo> repos, final boolean skipUnIndexed) { final List<NBVersionInfo> infos = new ArrayList<NBVersionInfo>(result.getResults()); final SkippedAction skipAction = new SkippedAction(result); iterate(repos, new RepoAction() { @Override public void run(RepositoryInfo repo, IndexingContext context) throws IOException { BooleanQuery bq = new BooleanQuery(); bq.add(new BooleanClause((setBooleanRewrite(constructQuery(MAVEN.SHA1, sha1))), BooleanClause.Occur.SHOULD)); IteratorSearchResponse response = repeatedPagedSearch(bq, Collections.singletonList(context), MAX_RESULT_COUNT); if (response != null) { try { for (ArtifactInfo ai : response.iterator()) { infos.add(convertToNBVersionInfo(ai)); } } finally { result.addReturnedResultCount(response.getTotalProcessedArtifactInfoCount()); result.addTotalResultCount(response.getTotalHitsCount()); response.close(); } } } }, skipAction, skipUnIndexed); doSortIssue226100(infos); result.setResults(infos); return result; }
Example #13
Source File: MavenIndexManager.java From archiva with Apache License 2.0 | 6 votes |
private IndexingContext getIndexingContext( Repository repository, String contextKey, Path repoDir, StorageAsset indexDirectory, String indexUrl ) throws IOException { try { if (!Files.exists(indexDirectory.getFilePath())) { Files.createDirectories(indexDirectory.getFilePath()); } return indexer.createIndexingContext( contextKey, repository.getId( ), repoDir.toFile( ), indexDirectory.getFilePath( ).toFile( ), repository.getLocation( ) == null ? null : repository.getLocation( ).toString( ), indexUrl, true, false, indexCreators ); } catch (Exception e) { log.error("Could not create index for asset {}", indexDirectory); throw new IOException(e); } }
Example #14
Source File: ArchivaIndexManagerMock.java From archiva with Apache License 2.0 | 5 votes |
private IndexingContext getIndexingContext( Repository repository, String contextKey, Path repoDir, StorageAsset indexDirectory, String indexUrl ) throws IOException { return indexer.createIndexingContext( contextKey, repository.getId( ), repoDir.toFile( ), indexDirectory.getFilePath().toFile( ), repository.getLocation( ) == null ? null : repository.getLocation( ).toString( ), indexUrl, true, false, indexCreators ); }
Example #15
Source File: MavenIndexManager.java From archiva with Apache License 2.0 | 5 votes |
@Override public ArchivaIndexingContext createContext( Repository repository ) throws IndexCreationFailedException { log.debug("Creating context for repo {}, type: {}", repository.getId(), repository.getType()); if ( repository.getType( ) != RepositoryType.MAVEN ) { throw new UnsupportedRepositoryTypeException( repository.getType( ) ); } IndexingContext mvnCtx = null; try { if ( repository instanceof RemoteRepository ) { mvnCtx = createRemoteContext( (RemoteRepository) repository ); } else if ( repository instanceof ManagedRepository ) { mvnCtx = createManagedContext( (ManagedRepository) repository ); } } catch ( IOException e ) { log.error( "IOException during context creation " + e.getMessage( ), e ); throw new IndexCreationFailedException( "Could not create index context for repository " + repository.getId( ) + ( StringUtils.isNotEmpty( e.getMessage( ) ) ? ": " + e.getMessage( ) : "" ), e ); } return new MavenIndexContext( repository, mvnCtx ); }
Example #16
Source File: ArchivaIndexManagerMock.java From archiva with Apache License 2.0 | 5 votes |
@Override public ArchivaIndexingContext createContext( Repository repository ) throws IndexCreationFailedException { log.debug("Creating context for repo {}, type: {}", repository.getId(), repository.getType()); if ( repository.getType( ) != RepositoryType.MAVEN ) { throw new UnsupportedRepositoryTypeException( repository.getType( ) ); } IndexingContext mvnCtx = null; try { if ( repository instanceof RemoteRepository ) { mvnCtx = createRemoteContext( (RemoteRepository) repository ); } else if ( repository instanceof ManagedRepository ) { mvnCtx = createManagedContext( (ManagedRepository) repository ); } } catch ( IOException e ) { log.error( "IOException during context creation " + e.getMessage( ), e ); throw new IndexCreationFailedException( "Could not create index context for repository " + repository.getId( ) + ( StringUtils.isNotEmpty( e.getMessage( ) ) ? ": " + e.getMessage( ) : "" ), e ); } MavenIndexContextMock context = new MavenIndexContextMock( repository, mvnCtx ); return context; }
Example #17
Source File: ArchivaIndexManagerMock.java From archiva with Apache License 2.0 | 5 votes |
public static IndexingContext getMvnContext(ArchivaIndexingContext context ) throws UnsupportedBaseContextException { if ( !context.supports( IndexingContext.class ) ) { log.error( "The provided archiva index context does not support the maven IndexingContext" ); throw new UnsupportedBaseContextException( "The context does not support the Maven IndexingContext" ); } return context.getBaseContext( IndexingContext.class ); }
Example #18
Source File: MavenIndexContextMock.java From archiva with Apache License 2.0 | 5 votes |
@SuppressWarnings( "unchecked" ) @Override public <T> T getBaseContext(Class<T> clazz) throws UnsupportedOperationException { if (IndexingContext.class.equals(clazz)) { return (T) delegate; } else { throw new UnsupportedOperationException("The class "+clazz+" is not supported by the maven indexer"); } }
Example #19
Source File: MavenIndexContextMock.java From archiva with Apache License 2.0 | 5 votes |
MavenIndexContextMock(Repository repository, IndexingContext delegate) { this.delegate = delegate; this.repository = repository; try { this.filesystemStorage = new FilesystemStorage(delegate.getIndexDirectoryFile().toPath(), new DefaultFileLockManager()); } catch (IOException e) { e.printStackTrace(); } }
Example #20
Source File: DownloadRemoteIndexTaskTest.java From archiva with Apache License 2.0 | 5 votes |
@Test public void downloadAndMergeRemoteIndexInEmptyIndex() throws Exception { Path repoDirectory = Paths.get( FileUtils.getBasedir( ), "target/repo-" + Long.toString( System.currentTimeMillis( ) ) ); RemoteRepository remoteRepository = getRemoteRepository(repoDirectory); repositoryRegistry.putRepository( remoteRepository); repositoryRegistry.reload(); downloadRemoteIndexScheduler.startup(); downloadRemoteIndexScheduler.scheduleDownloadRemote( "test-repo-re", true, true ); ( (ThreadPoolTaskScheduler) downloadRemoteIndexScheduler.getTaskScheduler() ).getScheduledExecutor().awaitTermination( 10, TimeUnit.SECONDS ); repositoryRegistry.removeRepository( "test-repo-re" ); // search BooleanQuery.Builder iQuery = new BooleanQuery.Builder(); iQuery.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( "commons-logging" ) ), BooleanClause.Occur.SHOULD ); remoteRepository = getRemoteRepository( repoDirectory ); FlatSearchRequest rq = new FlatSearchRequest( iQuery.build() ); rq.setContexts( Arrays.asList( remoteRepository.getIndexingContext().getBaseContext(IndexingContext.class) ) ); FlatSearchResponse response = indexer.searchFlat(rq); log.info( "returned hit count:{}", response.getReturnedHitsCount() ); Assertions.assertThat( response.getReturnedHitsCount() ).isEqualTo( 8 ); }
Example #21
Source File: MavenIndexManagerTest.java From archiva with Apache License 2.0 | 5 votes |
@Test public void scan() throws Exception { createTestContext(); Path destDir = repository.getRoot().getFilePath().resolve("org/apache/archiva/archiva-webapp/1.0"); Path srcDir = Paths.get("src/test/maven-search-test-repo/org/apache/archiva/archiva-webapp/1.0"); org.apache.commons.io.FileUtils.copyDirectory(srcDir.toFile(),destDir.toFile()); mavenIndexManager.scan(ctx); IndexingContext mvnCtx = mavenIndexManager.getMvnContext(ctx); String term = "org.apache.archiva"; Query q = new BooleanQuery.Builder().add( queryCreator.constructQuery( MAVEN.GROUP_ID, new UserInputSearchExpression( term ) ), BooleanClause.Occur.SHOULD ).build(); assertEquals(4, mvnCtx.acquireIndexSearcher().count(q)); }
Example #22
Source File: MavenIndexManager.java From archiva with Apache License 2.0 | 5 votes |
public static IndexingContext getMvnContext( ArchivaIndexingContext context ) throws UnsupportedBaseContextException { if (context!=null) { if ( !context.supports( IndexingContext.class ) ) { log.error( "The provided archiva index context does not support the maven IndexingContext" ); throw new UnsupportedBaseContextException( "The context does not support the Maven IndexingContext" ); } return context.getBaseContext( IndexingContext.class ); } else { return null; } }
Example #23
Source File: ArchivaIndexingTaskExecutorTest.java From archiva with Apache License 2.0 | 5 votes |
@Test public void testUpdateArtifactInIndex() throws Exception { Path basePath = repo.getRoot().getFilePath(); Path artifactFile = basePath.resolve( "org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" ); ArtifactIndexingTask task = new ArtifactIndexingTask( repo, artifactFile, ArtifactIndexingTask.Action.ADD, repo.getIndexingContext() ); indexingExecutor.executeTask( task ); indexingExecutor.executeTask( task ); BooleanQuery.Builder qb = new BooleanQuery.Builder(); qb.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( "org.apache.archiva" ) ), BooleanClause.Occur.SHOULD ); qb.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ), BooleanClause.Occur.SHOULD ); IndexingContext ctx = getIndexingContext(); IndexSearcher searcher = ctx.acquireIndexSearcher(); TopDocs topDocs = searcher.search( qb.build(), 10 ); //searcher.close(); ctx.releaseIndexSearcher( searcher ); assertTrue( Files.exists(basePath.resolve(".indexer" )) ); assertTrue( Files.exists(basePath.resolve(".index" )) ); // should only return 1 hit! assertEquals( 1, topDocs.totalHits ); }
Example #24
Source File: MavenRepositorySearch.java From archiva with Apache License 2.0 | 5 votes |
@Override public Set<String> getRemoteIndexingContextIds( String managedRepoId ) throws RepositorySearchException { Set<String> ids = new HashSet<>(); List<ProxyConnector> proxyConnectors = null; proxyConnectors = proxyRegistry.getProxyConnectorAsMap( ).get( managedRepoId ); if ( proxyConnectors == null || proxyConnectors.isEmpty() ) { return ids; } for ( ProxyConnector proxyConnector : proxyConnectors ) { String remoteId = "remote-" + proxyConnector.getTargetRepository().getId(); RemoteRepository repo = repositoryRegistry.getRemoteRepository(proxyConnector.getTargetRepository().getId()); if (repo.getType()==RepositoryType.MAVEN) { try { IndexingContext context = repo.getIndexingContext() != null ? repo.getIndexingContext().getBaseContext(IndexingContext.class) : null; if (context!=null && context.isSearchable()) { ids.add(remoteId); } } catch (UnsupportedBaseContextException e) { // Ignore this one } } } return ids; }
Example #25
Source File: DefaultIndexUpdateSideEffect.java From archiva with Apache License 2.0 | 5 votes |
@Override public void updateIndex( Directory directory, IndexingContext indexingContext, boolean b ) { LOGGER.info( "updating index: {} with directory: {}", // indexingContext.getId(), // directory.toString() ); }
Example #26
Source File: ArchivaIndexManagerMock.java From archiva with Apache License 2.0 | 5 votes |
private IndexingContext getIndexingContext( Repository repository, String contextKey, Path repoDir, StorageAsset indexDirectory, String indexUrl ) throws IOException { return indexer.createIndexingContext( contextKey, repository.getId( ), repoDir.toFile( ), indexDirectory.getFilePath().toFile( ), repository.getLocation( ) == null ? null : repository.getLocation( ).toString( ), indexUrl, true, false, indexCreators ); }
Example #27
Source File: ArchivaIndexManagerMock.java From archiva with Apache License 2.0 | 5 votes |
public static IndexingContext getMvnContext(ArchivaIndexingContext context ) throws UnsupportedBaseContextException { if ( !context.supports( IndexingContext.class ) ) { log.error( "The provided archiva index context does not support the maven IndexingContext" ); throw new UnsupportedBaseContextException( "The context does not support the Maven IndexingContext" ); } return context.getBaseContext( IndexingContext.class ); }
Example #28
Source File: ClassDependencyIndexCreator.java From netbeans with Apache License 2.0 | 5 votes |
static void search(String className, Indexer indexer, Collection<IndexingContext> contexts, List<? super ClassUsage> results) throws IOException { String searchString = crc32base64(className.replace('.', '/')); Query refClassQuery = indexer.constructQuery(ClassDependencyIndexCreator.FLD_NB_DEPENDENCY_CLASS.getOntology(), new StringSearchExpression(searchString)); TopScoreDocCollector collector = TopScoreDocCollector.create(NexusRepositoryIndexerImpl.MAX_RESULT_COUNT, null); for (IndexingContext context : contexts) { IndexSearcher searcher = context.acquireIndexSearcher(); try { searcher.search(refClassQuery, collector); ScoreDoc[] hits = collector.topDocs().scoreDocs; LOG.log(Level.FINER, "for {0} ~ {1} found {2} hits", new Object[] {className, searchString, hits.length}); for (ScoreDoc hit : hits) { int docId = hit.doc; Document d = searcher.doc(docId); String fldValue = d.get(ClassDependencyIndexCreator.NB_DEPENDENCY_CLASSES); LOG.log(Level.FINER, "{0} uses: {1}", new Object[] {className, fldValue}); Set<String> refClasses = parseField(searchString, fldValue, d.get(ArtifactInfo.NAMES)); if (!refClasses.isEmpty()) { ArtifactInfo ai = IndexUtils.constructArtifactInfo(d, context); if (ai != null) { ai.setRepository(context.getRepositoryId()); List<NBVersionInfo> version = NexusRepositoryIndexerImpl.convertToNBVersionInfo(Collections.singleton(ai)); if (!version.isEmpty()) { results.add(new ClassUsage(version.get(0), refClasses)); } } } } } finally { context.releaseIndexSearcher(searcher); } } }
Example #29
Source File: ArchivaIndexManagerMock.java From archiva with Apache License 2.0 | 5 votes |
private IndexingContext getIndexingContext( Repository repository, String contextKey, Path repoDir, StorageAsset indexDirectory, String indexUrl ) throws IOException { return indexer.createIndexingContext( contextKey, repository.getId( ), repoDir.toFile( ), indexDirectory.getFilePath().toFile( ), repository.getLocation( ) == null ? null : repository.getLocation( ).toString( ), indexUrl, true, false, indexCreators ); }
Example #30
Source File: ArchivaIndexManagerMock.java From archiva with Apache License 2.0 | 5 votes |
@Override public ArchivaIndexingContext createContext( Repository repository ) throws IndexCreationFailedException { log.debug("Creating context for repo {}, type: {}", repository.getId(), repository.getType()); if ( repository.getType( ) != RepositoryType.MAVEN ) { throw new UnsupportedRepositoryTypeException( repository.getType( ) ); } IndexingContext mvnCtx = null; try { if ( repository instanceof RemoteRepository ) { mvnCtx = createRemoteContext( (RemoteRepository) repository ); } else if ( repository instanceof ManagedRepository ) { mvnCtx = createManagedContext( (ManagedRepository) repository ); } } catch ( IOException e ) { log.error( "IOException during context creation " + e.getMessage( ), e ); throw new IndexCreationFailedException( "Could not create index context for repository " + repository.getId( ) + ( StringUtils.isNotEmpty( e.getMessage( ) ) ? ": " + e.getMessage( ) : "" ), e ); } MavenIndexContextMock context = new MavenIndexContextMock( repository, mvnCtx ); return context; }