# NetBeans IDE HG Patch # This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /work/src/netbeans-jm # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: maven.indexer/manifest.mf --- maven.indexer/manifest.mf +++ maven.indexer/manifest.mf @@ -1,6 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/maven/indexer/Bundle.properties AutoUpdate-Show-In-Client: false -OpenIDE-Module-Specification-Version: 2.37 +OpenIDE-Module-Specification-Version: 2.38 OpenIDE-Module: org.netbeans.modules.maven.indexer/2 Index: maven.indexer/nbproject/project.xml --- maven.indexer/nbproject/project.xml +++ maven.indexer/nbproject/project.xml @@ -168,6 +168,7 @@ org.netbeans.modules.maven.refactoring org.netbeans.modules.maven.repository org.netbeans.modules.maven.search + ro.emilianbold.modules.maven.search.remote org.apache.lucene org.apache.lucene.analysis org.apache.lucene.analysis.standard @@ -185,8 +186,7 @@ org.apache.lucene.util org.apache.lucene.util.cache org.netbeans.modules.maven.indexer.api - org.netbeans.modules.maven.indexer.api.ui - org.netbeans.modules.maven.indexer.spi.ui + org.netbeans.modules.maven.indexer.spi org.netbeans.modules.maven.indexer.spi.impl Index: maven.indexer/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImpl.java --- maven.indexer/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImpl.java +++ maven.indexer/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImpl.java @@ -102,7 +102,6 @@ import org.codehaus.plexus.util.FileUtils; import org.netbeans.api.annotations.common.CheckForNull; import org.netbeans.api.annotations.common.NullAllowed; -import org.netbeans.api.annotations.common.SuppressWarnings; import org.netbeans.modules.maven.embedder.EmbedderFactory; import org.netbeans.modules.maven.embedder.MavenEmbedder; import org.netbeans.modules.maven.indexer.api.NBArtifactInfo; @@ -111,7 +110,6 @@ import org.netbeans.modules.maven.indexer.api.QueryField; import org.netbeans.modules.maven.indexer.api.RepositoryInfo; import org.netbeans.modules.maven.indexer.api.RepositoryPreferences; -import org.netbeans.modules.maven.indexer.api.RepositoryQueries.Result; import org.netbeans.modules.maven.indexer.spi.ArchetypeQueries; import org.netbeans.modules.maven.indexer.spi.BaseQueries; import org.netbeans.modules.maven.indexer.spi.ChecksumQueries; @@ -120,8 +118,9 @@ import org.netbeans.modules.maven.indexer.spi.ContextLoadedQuery; import org.netbeans.modules.maven.indexer.spi.DependencyInfoQueries; import org.netbeans.modules.maven.indexer.spi.GenericFindQuery; -import org.netbeans.modules.maven.indexer.spi.Redo; -import org.netbeans.modules.maven.indexer.spi.RepositoryIndexerImplementation; +import org.netbeans.modules.maven.indexer.spi.impl.RepositoryIndexerImplementation; +import org.netbeans.modules.maven.indexer.spi.ResultImplementation; +import org.netbeans.modules.maven.indexer.spi.impl.Redo; import org.netbeans.modules.maven.indexer.spi.impl.IndexingNotificationProvider; import org.openide.modules.Places; import org.openide.util.BaseUtilities; @@ -133,59 +132,16 @@ import org.openide.util.lookup.ServiceProvider; import org.openide.util.lookup.ServiceProviders; import org.openide.util.NbBundle.Messages; +import org.netbeans.modules.maven.indexer.spi.RepositoryIndexQueryProvider; @ServiceProviders({ @ServiceProvider(service=RepositoryIndexerImplementation.class), - @ServiceProvider(service=BaseQueries.class), - @ServiceProvider(service=ChecksumQueries.class), - @ServiceProvider(service=ArchetypeQueries.class), - @ServiceProvider(service=DependencyInfoQueries.class), - @ServiceProvider(service=ClassesQuery.class), - @ServiceProvider(service=ClassUsageQuery.class), - @ServiceProvider(service=GenericFindQuery.class), - @ServiceProvider(service=ContextLoadedQuery.class) + @ServiceProvider(service=RepositoryIndexQueryProvider.class, position = Integer.MAX_VALUE) }) -public class NexusRepositoryIndexerImpl implements RepositoryIndexerImplementation, +public class NexusRepositoryIndexerImpl implements RepositoryIndexerImplementation, RepositoryIndexQueryProvider, BaseQueries, ChecksumQueries, ArchetypeQueries, DependencyInfoQueries, ClassesQuery, ClassUsageQuery, GenericFindQuery, ContextLoadedQuery { - - public static abstract class Accessor { - - @SuppressWarnings("MS_SHOULD_BE_FINAL") - public static Accessor ACCESSOR; - - protected Accessor() { - ACCESSOR = this; - } - - public abstract void addSkipped(Result result, Collection infos); - - public abstract List getSkipped(Result result); - - public abstract void setStringResults(Result result, Collection newResults); - - public abstract void setVersionResults(Result result, Collection newResults); - - public abstract void addSkipped(Result result, RepositoryInfo info); - - public abstract Result createStringResult(Redo redo); - - public abstract Result createVersionResult(Redo redo); - - public abstract Result createGroupResult(Redo redo); - - public abstract void setGroupResults(Result result, Collection newResults); - - public abstract Result createClassResult(Redo redo); - - public abstract void setClassResults(Result result, Collection newResults); - - public abstract void addTotalResults(Result result, int moreResults); - - public abstract void addReturnedResults(Result result, int moreResults); - } - private static final Logger LOGGER = Logger.getLogger(NexusRepositoryIndexerImpl.class.getName()); static { @@ -216,6 +172,53 @@ private static final Set indexingMutexes = new HashSet(); private static final RequestProcessor RP = new RequestProcessor("indexing", 1); + @Override + public boolean handlesRepository(RepositoryInfo repo) { + // should always come as last when looked up + // handles all remote repos + return true; + } + + @Override + public BaseQueries getBaseQueries() { + return this; + } + + @Override + public ChecksumQueries getChecksumQueries() { + return this; + } + + @Override + public ArchetypeQueries getArchetypeQueries() { + return this; + } + + @Override + public DependencyInfoQueries getDependencyInfoQueries() { + return this; + } + + @Override + public ClassesQuery getClassesQuery() { + return this; + } + + @Override + public ClassUsageQuery getClassUsageQuery() { + return this; + } + + @Override + public GenericFindQuery getGenericFindQuery() { + return this; + } + + @Override + public ContextLoadedQuery getContextLoadedQuery() { + return this; + } + private Mutex getRepoMutex(RepositoryInfo repo) { return getRepoMutex(repo.getId()); } @@ -914,7 +917,7 @@ } @Override - public RepositoryQueries.Result getGroups(List repos) { + public ResultImplementation getGroups(List repos) { return filterGroupIds("", repos); } @@ -971,18 +974,18 @@ } } + private ResultImplementation filterGroupIds(final String prefix, final List repos) { + Redo redo = new Redo() { @Override - public RepositoryQueries.Result filterGroupIds(final String prefix, final List repos) { - RepositoryQueries.Result result = Accessor.ACCESSOR.createStringResult(new Redo() { - @Override - public void run(Result result) { - filterGroupIds(prefix, result, Accessor.ACCESSOR.getSkipped(result), false); + public void run(ResultImpl result) { + filterGroupIds(prefix, result, result.getSkipped(), false); } - }); + }; + ResultImpl result = new ResultImpl(redo); return filterGroupIds(prefix, result, repos, true); } - private RepositoryQueries.Result filterGroupIds(final String prefix, final RepositoryQueries.Result result, + private ResultImplementation filterGroupIds(final String prefix, final ResultImpl result, final List repos, final boolean skipUnIndexed) { final Set groups = new TreeSet(result.getResults()); final List slowCheck = new ArrayList(); @@ -1025,22 +1028,22 @@ // } // }, skipAction, skipUnIndexed); - Accessor.ACCESSOR.setStringResults(result, groups); + result.setResults(groups); return result; } @Override - public Result getGAVsForPackaging(final String packaging, List repos) { - RepositoryQueries.Result result = Accessor.ACCESSOR.createStringResult(new Redo() { + public ResultImplementation getGAVsForPackaging(final String packaging, List repos) { + ResultImpl result = new ResultImpl<>(new Redo() { @Override - public void run(Result result) { - getGAVsForPackaging(packaging, result, Accessor.ACCESSOR.getSkipped(result), false); + public void run(ResultImpl result) { + getGAVsForPackaging(packaging, result, result.getSkipped(), false); } }); return getGAVsForPackaging(packaging,result, repos, true); } - private Result getGAVsForPackaging(final String packaging, final Result result, + private ResultImplementation getGAVsForPackaging(final String packaging, final ResultImpl result, List repos, final boolean skipUnIndexed) { final List infos = new ArrayList(result.getResults()); final SkippedAction skipAction = new SkippedAction(result); @@ -1058,30 +1061,29 @@ } } } finally { - Accessor.ACCESSOR.addReturnedResults(result, response.getTotalProcessedArtifactInfoCount()); - Accessor.ACCESSOR.addTotalResults(result, response.getTotalHitsCount()); + result.addReturnedResultCount(response.getTotalProcessedArtifactInfoCount()); + result.addTotalResultCount(response.getTotalHitsCount()); response.close(); } } } }, skipAction, skipUnIndexed); - Accessor.ACCESSOR.setStringResults(result, infos); + result.setResults(infos); return result; } - @Override - public Result getRecords(final String groupId, final String artifactId, final String version, List repos) { - RepositoryQueries.Result result = Accessor.ACCESSOR.createVersionResult(new Redo() { + public ResultImplementation getRecords(final String groupId, final String artifactId, final String version, List repos) { + ResultImpl result = new ResultImpl<>(new Redo() { @Override - public void run(Result result) { - getRecords(groupId, artifactId, version, result, Accessor.ACCESSOR.getSkipped(result), false); + public void run(ResultImpl result) { + getRecords(groupId, artifactId, version, result, result.getSkipped(), false); } }); return getRecords(groupId, artifactId, version, result, repos, true); } - private Result getRecords(final String groupId, final String artifactId, final String version, final Result result, + private ResultImplementation getRecords(final String groupId, final String artifactId, final String version, final ResultImpl result, List repos, final boolean skipUnIndexed) { final List infos = new ArrayList(result.getResults()); final SkippedAction skipAction = new SkippedAction(result); @@ -1097,30 +1099,30 @@ infos.add(convertToNBVersionInfo(ai)); } } finally { - Accessor.ACCESSOR.addReturnedResults(result, response.getTotalProcessedArtifactInfoCount()); - Accessor.ACCESSOR.addTotalResults(result, response.getTotalHitsCount()); + result.addReturnedResultCount(response.getTotalProcessedArtifactInfoCount()); + result.addTotalResultCount(response.getTotalHitsCount()); response.close(); } } } }, skipAction, skipUnIndexed); doSortIssue226100(infos); - Accessor.ACCESSOR.setVersionResults(result, infos); + result.setResults(infos); return result; } @Override - public RepositoryQueries.Result getArtifacts(final String groupId, final List repos) { - RepositoryQueries.Result result = Accessor.ACCESSOR.createStringResult(new Redo() { + public ResultImplementation getArtifacts(final String groupId, final List repos) { + ResultImpl result = new ResultImpl<>(new Redo() { @Override - public void run(Result result) { - getArtifacts(groupId, result, Accessor.ACCESSOR.getSkipped(result), false); + public void run(ResultImpl result) { + getArtifacts(groupId, result, result.getSkipped(), false); } }); return getArtifacts(groupId, result, repos, true); } - private RepositoryQueries.Result getArtifacts(final String groupId, final Result result, final List repos, final boolean skipUnIndexed) { + private ResultImplementation getArtifacts(final String groupId, final ResultImpl result, final List repos, final boolean skipUnIndexed) { final Set artifacts = new TreeSet(result.getResults()); final SkippedAction skipAction = new SkippedAction(result); iterate(repos, new RepoAction() { @@ -1141,21 +1143,21 @@ } } }, skipAction, skipUnIndexed); - Accessor.ACCESSOR.setStringResults(result, artifacts); + result.setResults(artifacts); return result; } @Override - public RepositoryQueries.Result getVersions(final String groupId, final String artifactId, List repos) { - RepositoryQueries.Result result = Accessor.ACCESSOR.createVersionResult(new Redo() { + public ResultImplementation getVersions(final String groupId, final String artifactId, List repos) { + ResultImpl result = new ResultImpl<>(new Redo() { @Override - public void run(Result result) { - getVersions(groupId, artifactId, result, Accessor.ACCESSOR.getSkipped(result), false); + public void run(ResultImpl result) { + getVersions(groupId, artifactId, result, result.getSkipped(), false); } }); return getVersions(groupId, artifactId, result, repos, true); } - private RepositoryQueries.Result getVersions(final String groupId, final String artifactId, final Result result, List repos, final boolean skipUnIndexed) { + private ResultImplementation getVersions(final String groupId, final String artifactId, final ResultImpl result, List repos, final boolean skipUnIndexed) { final List infos = new ArrayList(result.getResults()); final SkippedAction skipAction = new SkippedAction(result); iterate(repos, new RepoAction() { @@ -1170,30 +1172,30 @@ infos.add(convertToNBVersionInfo(ai)); } } finally { - Accessor.ACCESSOR.addReturnedResults(result, response.getTotalProcessedArtifactInfoCount()); - Accessor.ACCESSOR.addTotalResults(result, response.getTotalHitsCount()); + result.addReturnedResultCount(response.getTotalProcessedArtifactInfoCount()); + result.addTotalResultCount(response.getTotalHitsCount()); response.close(); } } } }, skipAction, skipUnIndexed); doSortIssue226100(infos); - Accessor.ACCESSOR.setVersionResults(result, infos); + result.setResults(infos); return result; } @Override - public RepositoryQueries.Result findVersionsByClass(final String className, List repos) { - RepositoryQueries.Result result = Accessor.ACCESSOR.createVersionResult(new Redo() { + public ResultImplementation findVersionsByClass(final String className, List repos) { + ResultImpl result = new ResultImpl(new Redo() { @Override - public void run(Result result) { - findVersionsByClass(className, result, Accessor.ACCESSOR.getSkipped(result), false); + public void run(ResultImpl result) { + findVersionsByClass(className, result, result.getSkipped(), false); } }); return findVersionsByClass(className, result, repos, true); } - private RepositoryQueries.Result findVersionsByClass(final String className, final Result result, List repos, final boolean skipUnIndexed) { + private ResultImplementation findVersionsByClass(final String className, final ResultImpl result, List repos, final boolean skipUnIndexed) { final List infos = new ArrayList(result.getResults()); final SkippedAction skipAction = new SkippedAction(result); iterate(repos, new RepoAction() { @@ -1215,31 +1217,31 @@ infos.addAll(postProcessClasses(response.getResults(), clsname)); } finally { //?? really count in this case? - Accessor.ACCESSOR.addReturnedResults(result, response.getTotalProcessedArtifactInfoCount()); - Accessor.ACCESSOR.addTotalResults(result, response.getTotalHitsCount()); + result.addReturnedResultCount(response.getTotalProcessedArtifactInfoCount()); + result.addTotalResultCount(response.getTotalHitsCount()); response.close(); } } } }, skipAction, skipUnIndexed); doSortIssue226100(infos); - Accessor.ACCESSOR.setVersionResults(result, infos); + result.setResults(infos); return result; } @Override - public RepositoryQueries.Result findClassUsages(final String className, @NullAllowed List repos) { - RepositoryQueries.Result result = Accessor.ACCESSOR.createClassResult(new Redo() { + public ResultImplementation findClassUsages(final String className, @NullAllowed List repos) { + ResultImpl result = new ResultImpl<>(new Redo() { @Override - public void run(Result result) { - findClassUsages(className, result, Accessor.ACCESSOR.getSkipped(result), false); + public void run(ResultImpl result) { + findClassUsages(className, result, result.getSkipped(), false); } }); return findClassUsages(className, result, repos, true); } - private RepositoryQueries.Result findClassUsages(final String className, Result result, @NullAllowed List repos, final boolean skipUnIndexed) { + private ResultImplementation findClassUsages(final String className, ResultImpl result, @NullAllowed List repos, final boolean skipUnIndexed) { List localRepos = new ArrayList(); if (repos == null) { repos = RepositoryPreferences.getInstance().getRepositoryInfos(); @@ -1261,21 +1263,21 @@ return r1.getArtifact().compareTo(r2.getArtifact()); } }); - Accessor.ACCESSOR.setClassResults(result, results); + result.setResults(results); return result; } @Override - public RepositoryQueries.Result findDependencyUsage(final String groupId, final String artifactId, final String version, @NullAllowed List repos) { - RepositoryQueries.Result result = Accessor.ACCESSOR.createVersionResult(new Redo() { + public ResultImplementation findDependencyUsage(final String groupId, final String artifactId, final String version, @NullAllowed List repos) { + ResultImpl result = new ResultImpl<>(new Redo() { @Override - public void run(Result result) { - findDependencyUsage(groupId, artifactId, version, result, Accessor.ACCESSOR.getSkipped(result), false); + public void run(ResultImpl result) { + findDependencyUsage(groupId, artifactId, version, result, result.getSkipped(), false); } }); return findDependencyUsage(groupId, artifactId, version, result, repos, true); } - private RepositoryQueries.Result findDependencyUsage(String groupId, String artifactId, String version, final Result result, @NullAllowed List repos, final boolean skipUnIndexed) { + private ResultImplementation findDependencyUsage(String groupId, String artifactId, String version, final ResultImpl result, @NullAllowed List repos, final boolean skipUnIndexed) { final Query q = ArtifactDependencyIndexCreator.query(groupId, artifactId, version); final List infos = new ArrayList(result.getResults()); final SkippedAction skipAction = new SkippedAction(result); @@ -1288,37 +1290,37 @@ infos.add(convertToNBVersionInfo(ai)); } } finally { - Accessor.ACCESSOR.addReturnedResults(result, response.getTotalProcessedArtifactInfoCount()); - Accessor.ACCESSOR.addTotalResults(result, response.getTotalHitsCount()); + result.addReturnedResultCount(response.getTotalProcessedArtifactInfoCount()); + result.addTotalResultCount(response.getTotalHitsCount()); response.close(); } } } }, skipAction, skipUnIndexed); - Accessor.ACCESSOR.setVersionResults(result, infos); + result.setResults(infos); return result; } @Override - public Result findDependencyUsageGroups(final String groupId, final String artifactId, final String version, List repos) { - RepositoryQueries.Result result = Accessor.ACCESSOR.createGroupResult(new Redo() { + public ResultImplementation findDependencyUsageGroups(final String groupId, final String artifactId, final String version, List repos) { + ResultImpl result = new ResultImpl<>(new Redo() { @Override - public void run(Result result) { - findDependencyUsageGroups(groupId, artifactId, version, result, Accessor.ACCESSOR.getSkipped(result), false); + public void run(ResultImpl result) { + findDependencyUsageGroups(groupId, artifactId, version, result, result.getSkipped(), false); } }); return findDependencyUsageGroups(groupId, artifactId, version, result, repos, true); } - private Result findDependencyUsageGroups(String groupId, String artifactId, String version, Result result, List repos, final boolean skipUnIndexed) { + private ResultImplementation findDependencyUsageGroups(String groupId, String artifactId, String version, ResultImpl result, List repos, final boolean skipUnIndexed) { //tempmaps Map groupMap = new HashMap(); Map artifactMap = new HashMap(); List groupInfos = new ArrayList(result.getResults()); - Result res = Accessor.ACCESSOR.createVersionResult(new Redo() { + ResultImpl res = new ResultImpl(new Redo() { @Override - public void run(Result result) { + public void run(ResultImpl result) { //noop will not be called } }); @@ -1326,9 +1328,9 @@ convertToNBGroupInfo(res.getResults(), groupMap, artifactMap, groupInfos); if (res.isPartial()) { - Accessor.ACCESSOR.addSkipped(result, Accessor.ACCESSOR.getSkipped(res)); + result.addSkipped(res.getSkipped()); } - Accessor.ACCESSOR.setGroupResults(result, groupInfos); + result.setResults(groupInfos); return result; } @@ -1360,17 +1362,17 @@ @Override - public RepositoryQueries.Result findBySHA1(final String sha1, List repos) { - RepositoryQueries.Result result = Accessor.ACCESSOR.createVersionResult(new Redo() { + public ResultImplementation findBySHA1(final String sha1, List repos) { + ResultImpl result = new ResultImpl<>(new Redo() { @Override - public void run(Result result) { - findBySHA1(sha1, result, Accessor.ACCESSOR.getSkipped(result), false); + public void run(ResultImpl result) { + findBySHA1(sha1, result, result.getSkipped(), false); } }); return findBySHA1(sha1, result, repos, true); } - private RepositoryQueries.Result findBySHA1(final String sha1, final Result result, List repos, final boolean skipUnIndexed) { + private ResultImplementation findBySHA1(final String sha1, final ResultImpl result, List repos, final boolean skipUnIndexed) { final List infos = new ArrayList(result.getResults()); final SkippedAction skipAction = new SkippedAction(result); iterate(repos, new RepoAction() { @@ -1384,30 +1386,30 @@ infos.add(convertToNBVersionInfo(ai)); } } finally { - Accessor.ACCESSOR.addReturnedResults(result, response.getTotalProcessedArtifactInfoCount()); - Accessor.ACCESSOR.addTotalResults(result, response.getTotalHitsCount()); + result.addReturnedResultCount(response.getTotalProcessedArtifactInfoCount()); + result.addTotalResultCount(response.getTotalHitsCount()); response.close(); } } } }, skipAction, skipUnIndexed); doSortIssue226100(infos); - Accessor.ACCESSOR.setVersionResults(result, infos); + result.setResults(infos); return result; } @Override - public RepositoryQueries.Result findArchetypes(List repos) { - RepositoryQueries.Result result = Accessor.ACCESSOR.createVersionResult(new Redo() { + public ResultImplementation findArchetypes(List repos) { + ResultImpl result = new ResultImpl<>(new Redo() { @Override - public void run(Result result) { - findArchetypes( result, Accessor.ACCESSOR.getSkipped(result), false); + public void run(ResultImpl result) { + findArchetypes( result, result.getSkipped(), false); } }); return findArchetypes( result, repos, true); } - private RepositoryQueries.Result findArchetypes(final Result result, List repos, final boolean skipUnIndexed) { + private ResultImplementation findArchetypes(final ResultImpl result, List repos, final boolean skipUnIndexed) { final List infos = new ArrayList(result.getResults()); final SkippedAction skipAction = new SkippedAction(result); iterate(repos, new RepoAction() { @@ -1426,30 +1428,30 @@ infos.add(convertToNBVersionInfo(ai)); } } finally { - Accessor.ACCESSOR.addReturnedResults(result, response.getTotalProcessedArtifactInfoCount()); - Accessor.ACCESSOR.addTotalResults(result, response.getTotalHitsCount()); + result.addReturnedResultCount(response.getTotalProcessedArtifactInfoCount()); + result.addTotalResultCount(response.getTotalHitsCount()); response.close(); } } } }, skipAction, skipUnIndexed); doSortIssue226100(infos); - Accessor.ACCESSOR.setVersionResults(result, infos); + result.setResults(infos); return result; } @Override - public RepositoryQueries.Result filterPluginArtifactIds(final String groupId, final String prefix, List repos) { - RepositoryQueries.Result result = Accessor.ACCESSOR.createStringResult(new Redo() { + public ResultImplementation filterPluginArtifactIds(final String groupId, final String prefix, List repos) { + ResultImpl result = new ResultImpl<>(new Redo() { @Override - public void run(Result result) { - filterPluginArtifactIds(groupId, prefix, result, Accessor.ACCESSOR.getSkipped(result), false); + public void run(ResultImpl result) { + filterPluginArtifactIds(groupId, prefix, result, result.getSkipped(), false); } }); return filterPluginArtifactIds(groupId, prefix, result, repos, true); } - private RepositoryQueries.Result filterPluginArtifactIds(final String groupId, final String prefix, Result result, List repos, final boolean skipUnIndexed) { + private ResultImplementation filterPluginArtifactIds(final String groupId, final String prefix, ResultImpl result, List repos, final boolean skipUnIndexed) { final Set artifacts = new TreeSet(result.getResults()); final SkippedAction skipAction = new SkippedAction(result); iterate(repos, new RepoAction() { @@ -1471,22 +1473,22 @@ } } }, skipAction, skipUnIndexed); - Accessor.ACCESSOR.setStringResults(result, artifacts); + result.setResults(artifacts); return result; } @Override - public RepositoryQueries.Result filterPluginGroupIds(final String prefix, List repos) { - RepositoryQueries.Result result = Accessor.ACCESSOR.createStringResult(new Redo() { + public ResultImplementation filterPluginGroupIds(final String prefix, List repos) { + ResultImpl result = new ResultImpl<>(new Redo() { @Override - public void run(Result result) { - filterPluginGroupIds( prefix, result, Accessor.ACCESSOR.getSkipped(result), false); + public void run(ResultImpl result) { + filterPluginGroupIds( prefix, result, result.getSkipped(), false); } }); return filterPluginGroupIds( prefix, result, repos, true); } - private RepositoryQueries.Result filterPluginGroupIds(final String prefix, Result result, List repos, final boolean skipUnIndexed) { + private ResultImplementation filterPluginGroupIds(final String prefix, ResultImpl result, List repos, final boolean skipUnIndexed) { final Set artifacts = new TreeSet(result.getResults()); final SkippedAction skipAction = new SkippedAction(result); iterate(repos, new RepoAction() { @@ -1509,56 +1511,21 @@ } } }, skipAction, skipUnIndexed); - Accessor.ACCESSOR.setStringResults(result, artifacts); + result.setResults(artifacts); return result; } @Override - public RepositoryQueries.Result filterArtifactIdForGroupId(final String groupId, final String prefix, List repos) { - RepositoryQueries.Result result = Accessor.ACCESSOR.createStringResult(new Redo() { + public ResultImplementation find(final List fields, List repos) { + ResultImpl result = new ResultImpl<>(new Redo() { @Override - public void run(Result result) { - filterArtifactIdForGroupId( groupId, prefix, result, Accessor.ACCESSOR.getSkipped(result), false); + public void run(ResultImpl result) { + find( fields, result, result.getSkipped(), false); } }); - return filterArtifactIdForGroupId( groupId, prefix, result, repos, true); - } - private RepositoryQueries.Result filterArtifactIdForGroupId(final String groupId, final String prefix, Result result, List repos, final boolean skipUnIndexed) { - final Set artifacts = new TreeSet(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(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.artifactId); - } - } finally { - response.close(); - } - } - } - }, skipAction, skipUnIndexed); - Accessor.ACCESSOR.setStringResults(result, artifacts); - return result; - } - - @Override - public RepositoryQueries.Result find(final List fields, List repos) { - RepositoryQueries.Result result = Accessor.ACCESSOR.createVersionResult(new Redo() { - @Override - public void run(Result result) { - find( fields, result, Accessor.ACCESSOR.getSkipped(result), false); - } - }); return find(fields, result, repos, true); } - private RepositoryQueries.Result find(final List fields, final Result result, List repos, final boolean skipUnIndexed) { + private ResultImplementation find(final List fields, final ResultImpl result, List repos, final boolean skipUnIndexed) { final List infos = new ArrayList(result.getResults()); final SkippedAction skipAction = new SkippedAction(result); iterate(repos, new RepoAction() { @@ -1636,15 +1603,15 @@ infos.add(convertToNBVersionInfo(ai)); } } finally { - Accessor.ACCESSOR.addReturnedResults(result, resp.getTotalProcessedArtifactInfoCount()); - Accessor.ACCESSOR.addTotalResults(result, resp.getTotalHitsCount()); + result.addReturnedResultCount(resp.getTotalProcessedArtifactInfoCount()); + result.addTotalResultCount(resp.getTotalHitsCount()); resp.close(); } } } }, skipAction, skipUnIndexed); doSortIssue226100(infos); - Accessor.ACCESSOR.setVersionResults(result, infos); + result.setResults(infos); return result; } @@ -1781,16 +1748,16 @@ private static class SkippedAction implements RepoAction { - private final Result result; + private final ResultImpl result; - private SkippedAction(Result result) { + private SkippedAction(ResultImpl result) { this.result = result; } @Override public void run(RepositoryInfo repo, IndexingContext context) throws IOException { //indexing context is always null here.. - Accessor.ACCESSOR.addSkipped(result, repo); + result.addSkipped(repo); } } Index: maven.indexer/src/org/netbeans/modules/maven/indexer/OnStop.java --- maven.indexer/src/org/netbeans/modules/maven/indexer/OnStop.java +++ maven.indexer/src/org/netbeans/modules/maven/indexer/OnStop.java @@ -44,7 +44,7 @@ import java.util.logging.Level; import java.util.logging.Logger; -import org.netbeans.modules.maven.indexer.spi.RepositoryIndexerImplementation; +import org.netbeans.modules.maven.indexer.spi.impl.RepositoryIndexerImplementation; import org.openide.util.Lookup; @org.openide.modules.OnStop Index: maven.indexer/src/org/netbeans/modules/maven/indexer/ResultImpl.java --- maven.indexer/src/org/netbeans/modules/maven/indexer/ResultImpl.java +++ maven.indexer/src/org/netbeans/modules/maven/indexer/ResultImpl.java @@ -0,0 +1,152 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2016 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2016 Sun Microsystems, Inc. + */ +package org.netbeans.modules.maven.indexer; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import org.netbeans.modules.maven.indexer.api.RepositoryInfo; +import org.netbeans.modules.maven.indexer.spi.ResultImplementation; +import org.netbeans.modules.maven.indexer.spi.impl.Redo; +import org.netbeans.modules.project.spi.intern.ProjectIDEServices; + +/** + * + * @author Tomas Stupka + */ +public class ResultImpl implements ResultImplementation { + private final List skipped = new ArrayList<>(); + private final List results = new ArrayList<>(); + private final Redo redoAction; + + private int totalResults = 0; + private int returnedResults = 0; + + /** + * used internally by the repository indexing/searching engine(s) + */ + public ResultImpl(Redo redo) { + redoAction = redo; + } + + /** + * returns true is one or more indexes were skipped, eg because the indexing was taking place. + * @return + */ + @Override + public synchronized boolean isPartial() { + return !skipped.isEmpty(); + } + + /** + * used internally by the repository indexing/searching engine(s) to mark the result as partially skipped + */ + synchronized void addSkipped(RepositoryInfo info) { + skipped.add(info); + } + + /** + * waits for currently unaccessible indexes to finish, not to be called in AWT thread. + */ + @Override + public void waitForSkipped() { + assert !ProjectIDEServices.isEventDispatchThread(); + redoAction.run(this); + synchronized (this) { + skipped.clear(); + } + } + + synchronized void setResults(Collection newResults) { + results.clear(); + results.addAll(newResults); + } + + @Override + public synchronized List getResults() { + return Collections.unmodifiableList(results); + } + + + /** + * used internally by the repository indexing/searching engine(s) to mark the result as partially skipped + */ + synchronized void addSkipped(Collection infos) { + skipped.addAll(infos); + } + + /** + * used internally by the repository indexing/searching engine(s) to mark the result as partially skipped + */ + synchronized List getSkipped() { + return Collections.unmodifiableList(skipped); + } + + /** + * total number of hits + * @return + * @since 2.20 + */ + @Override + public int getTotalResultCount() { + return totalResults; + } + + void addTotalResultCount(int moreTotalResults) { + totalResults += moreTotalResults; + } + /** + * in some cases not entirely accurate number of processed and returned hits, typically should be less or equals to totalResultCount + * @return + * @since 2.20 + */ + @Override + public int getReturnedResultCount() { + return returnedResults; + } + + void addReturnedResultCount(int moreReturnedResults) { + returnedResults = moreReturnedResults + returnedResults; + } + +} Index: maven.indexer/src/org/netbeans/modules/maven/indexer/api/RepositoryIndexer.java --- maven.indexer/src/org/netbeans/modules/maven/indexer/api/RepositoryIndexer.java +++ maven.indexer/src/org/netbeans/modules/maven/indexer/api/RepositoryIndexer.java @@ -43,9 +43,10 @@ import java.util.Collection; import org.apache.maven.artifact.Artifact; -import org.netbeans.api.annotations.common.NonNull; -import org.netbeans.modules.maven.indexer.spi.RepositoryIndexerImplementation; +import org.netbeans.modules.maven.indexer.NexusRepositoryIndexerImpl; +import org.netbeans.modules.maven.indexer.spi.impl.RepositoryIndexerImplementation; import org.openide.util.Lookup; +import org.netbeans.modules.maven.indexer.spi.RepositoryIndexQueryProvider; /** * @@ -55,27 +56,47 @@ public static void indexRepo(RepositoryInfo repo) { assert repo != null; - findImplementation().indexRepo(repo); + RepositoryIndexerImplementation impl = findImplementation(repo); + if(impl != null) { + // fires + impl.indexRepo(repo); + } else { + repo.fireIndexChange(); } + } public static void updateIndexWithArtifacts(RepositoryInfo repo, Collection artifacts) { assert repo != null; if (artifacts == null || artifacts.isEmpty()) { return; } - findImplementation().updateIndexWithArtifacts(repo, artifacts); + RepositoryIndexerImplementation impl = findImplementation(repo); + if(impl != null) { + impl.updateIndexWithArtifacts(repo, artifacts); } + } public static void deleteArtifactFromIndex(RepositoryInfo repo, Artifact artifact) { assert repo != null; if (artifact == null) { return; } - findImplementation().deleteArtifactFromIndex(repo, artifact); + RepositoryIndexerImplementation impl = findImplementation(repo); + if(impl != null) { + impl.deleteArtifactFromIndex(repo, artifact); } + } - static @NonNull RepositoryIndexerImplementation findImplementation() { - return Lookup.getDefault().lookup(RepositoryIndexerImplementation.class); + static RepositoryIndexerImplementation findImplementation(RepositoryInfo repo) { + Lookup l = Lookup.getDefault(); + Collection queryProviders = l.lookupAll(RepositoryIndexQueryProvider.class); + for (RepositoryIndexQueryProvider queryProvider : queryProviders) { + if(!(queryProvider instanceof NexusRepositoryIndexerImpl) && queryProvider.handlesRepository(repo)) { + // skip if + return null; } + } + return l.lookup(RepositoryIndexerImplementation.class); + } } Index: maven.indexer/src/org/netbeans/modules/maven/indexer/api/RepositoryQueries.java --- maven.indexer/src/org/netbeans/modules/maven/indexer/api/RepositoryQueries.java +++ maven.indexer/src/org/netbeans/modules/maven/indexer/api/RepositoryQueries.java @@ -46,18 +46,32 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; +import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; +import org.apache.lucene.search.BooleanQuery; import org.netbeans.api.annotations.common.NonNull; import org.netbeans.api.annotations.common.NullAllowed; -import org.netbeans.modules.maven.indexer.NexusRepositoryIndexerImpl; -import org.netbeans.modules.maven.indexer.spi.*; +import org.netbeans.modules.maven.indexer.ResultImpl; +import org.netbeans.modules.maven.indexer.spi.ArchetypeQueries; +import org.netbeans.modules.maven.indexer.spi.BaseQueries; +import org.netbeans.modules.maven.indexer.spi.ChecksumQueries; +import org.netbeans.modules.maven.indexer.spi.ClassUsageQuery; +import org.netbeans.modules.maven.indexer.spi.ClassesQuery; +import org.netbeans.modules.maven.indexer.spi.ContextLoadedQuery; +import org.netbeans.modules.maven.indexer.spi.DependencyInfoQueries; +import org.netbeans.modules.maven.indexer.spi.GenericFindQuery; +import org.netbeans.modules.maven.indexer.spi.NullResultImpl; +import org.netbeans.modules.maven.indexer.spi.ResultImplementation; import org.netbeans.modules.project.spi.intern.ProjectIDEServices; import org.openide.util.Lookup; +import org.netbeans.modules.maven.indexer.spi.RepositoryIndexQueryProvider; /** * Searches Maven repositories in various ways. @@ -71,176 +85,116 @@ /** * query result set + * @param * @since 2.9 */ public final static class Result { - private final List skipped = new ArrayList(); - private List results = new ArrayList(); - private final Redo redoAction; - int totalResults = 0; - int returnedResults = 0; + private final ResultImplementation impl; /** - * used internally by the repository indexing/searching engine(s) + * Creates a Result instance. + * @param impl */ - Result(Redo redo) { - redoAction = redo; + public Result(ResultImplementation impl) { + this.impl = impl; } /** - * returns true is one or more indexes were skipped, eg because the indexing was taking place. + * Returns true is one or more indexes were skipped, e.g. because the indexing was taking place. * @return */ public synchronized boolean isPartial() { - return !skipped.isEmpty(); + return impl.isPartial(); } /** - * used internally by the repository indexing/searching engine(s) to mark the result as partially skipped + * Waits for currently unaccessible indexes to finish, not to be called in AWT thread. */ - synchronized void addSkipped(RepositoryInfo info) { - skipped.add(info); - } - - /** - * waits for currently unaccessible indexes to finish, not to be called in AWT thread. - */ public void waitForSkipped() { assert !ProjectIDEServices.isEventDispatchThread(); - redoAction.run(this); - synchronized (this) { - skipped.clear(); + impl.waitForSkipped(); } - } - synchronized void setResults(Collection newResults) { - results.clear(); - results.addAll(newResults); - } - - public synchronized List getResults() { - return Collections.unmodifiableList(results); - } - - /** - * used internally by the repository indexing/searching engine(s) to mark the result as partially skipped + * Returns a list of results + * @return */ - synchronized void addSkipped(Collection infos) { - skipped.addAll(infos); + public synchronized List getResults() { + return impl.getResults(); } /** - * used internally by the repository indexing/searching engine(s) to mark the result as partially skipped - */ - synchronized List getSkipped() { - return Collections.unmodifiableList(skipped); - } - /** - * total number of hits + * Total number of hits * @return * @since 2.20 */ public int getTotalResultCount() { - return totalResults; + return impl.getTotalResultCount(); } - void addTotalResultCount(int moreTotalResults) { - totalResults = totalResults + moreTotalResults; - } /** * in some cases not entirely accurate number of processed and returned hits, typically should be less or equals to totalResultCount * @return * @since 2.20 */ public int getReturnedResultCount() { - return returnedResults; + return impl.getReturnedResultCount(); } - - void addReturnedResultCount(int moreReturnedResults) { - returnedResults = returnedResults + moreReturnedResults; } + private final static class CompositeResult implements ResultImplementation { + private final List> results; + public CompositeResult(List> results) { + this.results = results; } - - static { - new AccessorImpl(); - } - - - - static class AccessorImpl extends NexusRepositoryIndexerImpl.Accessor { - @Override - public void addSkipped(Result result, Collection infos) { - result.addSkipped(infos); + public boolean isPartial() { + for (ResultImplementation result : results) { + if(result.isPartial()) { + return true; } - - @Override - public List getSkipped(Result result) { - return result.getSkipped(); } - - @Override - public void addSkipped(Result result, RepositoryInfo info) { - result.addSkipped(info); + return false; } @Override - public Result createStringResult(Redo redo) { - return new Result(redo); + public void waitForSkipped() { + for (ResultImplementation result : results) { + result.waitForSkipped(); } - - @Override - public Result createVersionResult(Redo redo) { - return new Result(redo); } @Override - public void setStringResults(Result result, Collection newResults) { - result.setResults(newResults); + public List getResults() { + List ret = new LinkedList<>(); + for (ResultImplementation result : results) { + ret.addAll(result.getResults()); } - - @Override - public void setVersionResults(Result result, Collection newResults) { - result.setResults(newResults); + return ret; } @Override - public Result createGroupResult(Redo redo) { - return new Result(redo); + public int getTotalResultCount() { + int ret = 0; + for (ResultImplementation result : results) { + ret += result.getTotalResultCount(); } - - @Override - public void setGroupResults(Result result, Collection newResults) { - result.setResults(newResults); + return ret; } @Override - public Result createClassResult(Redo redo) { - return new Result(redo); + public int getReturnedResultCount() { + int ret = 0; + for (ResultImplementation result : results) { + ret += result.getReturnedResultCount(); } - - @Override - public void setClassResults(Result result, Collection newResults) { - result.setResults(newResults); + return ret; } - - @Override - public void addTotalResults(Result result, int moreResults) { - result.addTotalResultCount(moreResults); } - @Override - public void addReturnedResults(Result result, int moreResults) { - result.addReturnedResultCount(moreResults); - } - } - - /** * One usage result. */ @@ -268,33 +222,55 @@ } } + private static interface QueryCall { + ResultImplementation call(RepositoryIndexQueryProvider queryProvider, List providerRepos); + } - private static @NonNull BaseQueries findBaseQueries() { - return Lookup.getDefault().lookup(BaseQueries.class); + private static Result getQueryResult(List repos, QueryCall c) { + List> results = new LinkedList<>(); + if (repos == null) { + repos = RepositoryPreferences.getInstance().getRepositoryInfos(); } + Map> qp2Repo = getQueryProvider2Repo(repos); + for(Map.Entry> e : qp2Repo.entrySet()) { + results.add(c.call(e.getKey(), e.getValue())); + } + return new Result<>(new CompositeResult<>(results)); + } - /** - * - * @param repos - * @return - * @since 2.9 - */ - public static Result getGroupsResult(@NullAllowed List repos) { - return findBaseQueries().getGroups(repos); + private static Map> getQueryProvider2Repo(List repos) { + Collection idxs = Lookup.getDefault().lookupAll(RepositoryIndexQueryProvider.class); + Map> qp2Repo = new HashMap<>(); + for (RepositoryInfo repo : repos) { + for (RepositoryIndexQueryProvider idx : idxs) { + if(idx.handlesRepository(repo)) { + List mappedRepos = qp2Repo.get(idx); + if(mappedRepos == null) { + mappedRepos = new LinkedList<>(); + qp2Repo.put(idx, mappedRepos); } + mappedRepos.add(repo); + break; + } + } + } + return qp2Repo; + } /** * - * @param prefix * @param repos * @return * @since 2.9 */ - public static Result filterGroupIdsResult(String prefix, @NullAllowed List repos) { - return findBaseQueries().filterGroupIds(prefix, repos); + public static Result getGroupsResult(@NullAllowed List repos) { + return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List providerRepos) -> { + BaseQueries baseQueries = queryProvider.getBaseQueries(); + assert baseQueries != null: "RepositoryIndexQueryProvider.getBaseQueries not allowed to return null"; + return baseQueries.getGroups(providerRepos); + }); } - /** * * @param groupId @@ -305,7 +281,11 @@ * @since 2.9 */ public static Result getRecordsResult(String groupId, String artifactId, String version, @NullAllowed List repos) { - return findBaseQueries().getRecords(groupId, artifactId, version, repos); + return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List providerRepos) -> { + BaseQueries baseQueries = queryProvider.getBaseQueries(); + assert baseQueries != null: "RepositoryIndexQueryProvider.getBaseQueries not allowed to return null"; + return baseQueries.getRecords(groupId, artifactId, version, providerRepos); + }); } /** @@ -316,10 +296,13 @@ * @since 2.28 */ public static Result getGAVsForPackaging(String packaging, @NullAllowed List repos) { - return findBaseQueries().getGAVsForPackaging(packaging, repos); + return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List providerRepos) -> { + BaseQueries baseQueries = queryProvider.getBaseQueries(); + assert baseQueries != null: "RepositoryIndexQueryProvider.getBaseQueries not allowed to return null"; + return baseQueries.getGAVsForPackaging(packaging, providerRepos); + }); } - /** * * @param groupId @@ -328,10 +311,13 @@ * @since 2.9 */ public static Result getArtifactsResult(String groupId, @NullAllowed List repos) { - return findBaseQueries().getArtifacts(groupId, repos); + return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List providerRepos) -> { + BaseQueries baseQueries = queryProvider.getBaseQueries(); + assert baseQueries != null: "RepositoryIndexQueryProvider.getBaseQueries not allowed to return null"; + return baseQueries.getArtifacts(groupId, providerRepos); + }); } - /** * * @param groupId @@ -341,14 +327,13 @@ * @since 2.9 */ public static Result getVersionsResult(String groupId, String artifactId, @NullAllowed List repos) { - return findBaseQueries().getVersions(groupId, artifactId, repos); + return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List providerRepos) -> { + BaseQueries baseQueries = queryProvider.getBaseQueries(); + assert baseQueries != null: "RepositoryIndexQueryProvider.getBaseQueries not allowed to return null"; + return baseQueries.getVersions(groupId, artifactId, providerRepos); + }); } - - private static @NonNull DependencyInfoQueries findDIQ() { - return Lookup.getDefault().lookup(DependencyInfoQueries.class); - } - /** * * @param groupId @@ -359,10 +344,14 @@ * @since 2.9 */ public static Result findDependencyUsageResult(String groupId, String artifactId, String version, @NullAllowed List repos) { - return findDIQ().findDependencyUsageGroups(groupId, artifactId, version, repos); + return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List providerRepos) -> { + DependencyInfoQueries dependencyInfoQueries = queryProvider.getDependencyInfoQueries(); + return dependencyInfoQueries != null ? + dependencyInfoQueries.findDependencyUsageGroups(groupId, artifactId, version, providerRepos) : + new NullResultImpl<>(); + }); } - /** * * @param file @@ -377,26 +366,18 @@ } catch (IOException ex) { Logger.getLogger(RepositoryQueries.class.getName()).log(Level.INFO, "Could not determine SHA-1 of " + file, ex); } - return NexusRepositoryIndexerImpl.Accessor.ACCESSOR.createVersionResult(new Redo() { - @Override - public void run(Result result) { - //noop + return new Result<>(new NullResultImpl<>()); } - }); - } - - private static ChecksumQueries findChecksumQueries() { - return Lookup.getDefault().lookup(ChecksumQueries.class); - } - private static Result findBySHA1(String sha1, @NullAllowed List repos) { - return findChecksumQueries().findBySHA1(sha1, repos); + return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List providerRepos) -> { + ChecksumQueries checksumQueries = queryProvider.getChecksumQueries(); + return checksumQueries != null ? + checksumQueries.findBySHA1(sha1, providerRepos) : + new NullResultImpl<>(); + }); } - private static @NonNull ClassesQuery findClassesQueries() { - return Lookup.getDefault().lookup(ClassesQuery.class); - } /** * * @param className @@ -411,7 +392,12 @@ * @since 2.9 */ public static Result findVersionsByClassResult(final String className, @NullAllowed List repos) { - return findClassesQueries().findVersionsByClass(className, repos); + return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List providerRepos) -> { + ClassesQuery classesQuery = queryProvider.getClassesQuery(); + return classesQuery != null ? + classesQuery.findVersionsByClass(className, providerRepos) : + new NullResultImpl<>(); + }); } /** @@ -438,9 +424,15 @@ //TODO first process the loaded ones, index and wait for finish of indexing of the unloaded ones.. for (Iterator it1 = query.getRepositories().iterator(); it1.hasNext();) { RepositoryInfo repositoryInfo = it1.next(); - List repositoryInfoL = new ArrayList(1); + List repositoryInfoL = new ArrayList<>(1); repositoryInfoL.add(repositoryInfo); - query.addResults(findClassesQueries().findVersionsByClass(query.getClassName(), repositoryInfoL).getResults(), !it1.hasNext()); + Result queryResult = getQueryResult(repositoryInfoL, (RepositoryIndexQueryProvider queryProvider, List providerRepos) -> { + ClassesQuery classesQuery = queryProvider.getClassesQuery(); + return classesQuery != null ? + classesQuery.findVersionsByClass(query.getClassName(), providerRepos) : + new NullResultImpl<>(); + }); + query.addResults(queryResult.getResults(), !it1.hasNext()); // still someone waiting for results? if (query.countObservers() == 0) return; @@ -449,10 +441,6 @@ query.addResults(null, true); } - private static @NonNull ClassUsageQuery findClassUsageQuery() { - return Lookup.getDefault().lookup(ClassUsageQuery.class); - } - /** * Finds all usages of a given class. * The implementation may not provide results within the same artifact, or on classes in the JRE. @@ -462,14 +450,14 @@ * @since 2.9 */ public static Result findClassUsagesResult(String className, @NullAllowed List repos) { - return findClassUsageQuery().findClassUsages(className, repos); + return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List providerRepos) -> { + ClassUsageQuery classUsageQuery = queryProvider.getClassUsageQuery(); + return classUsageQuery != null ? + classUsageQuery.findClassUsages(className, repos) : + new NullResultImpl<>(); + }); } - - private static @NonNull ArchetypeQueries findArchetypeQueries() { - return Lookup.getDefault().lookup(ArchetypeQueries.class); - } - /** * * @param repos @@ -477,11 +465,14 @@ * @since 2.9 */ public static Result findArchetypesResult(@NullAllowed List repos) { - return findArchetypeQueries().findArchetypes(repos); + return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List providerRepos) -> { + ArchetypeQueries archetypeQueries = queryProvider.getArchetypeQueries(); + return archetypeQueries != null ? + archetypeQueries.findArchetypes(repos) : + new NullResultImpl<>(); + }); } - - /** * * @param groupId @@ -491,10 +482,13 @@ * @since 2.9 */ public static Result filterPluginArtifactIdsResult(String groupId, String prefix, @NullAllowed List repos) { - return findBaseQueries().filterPluginArtifactIds(groupId, prefix, repos); + return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List providerRepos) -> { + BaseQueries baseQueries = queryProvider.getBaseQueries(); + assert baseQueries != null: "RepositoryIndexQueryProvider.getBaseQueries not allowed to return null"; + return baseQueries.filterPluginArtifactIds(groupId, prefix, providerRepos); + }); } - /** * * @param prefix @@ -503,14 +497,13 @@ * @since 2.9 */ public static Result filterPluginGroupIdsResult(String prefix, @NullAllowed List repos) { - return findBaseQueries().filterPluginGroupIds(prefix, repos); + return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List providerRepos) -> { + BaseQueries baseQueries = queryProvider.getBaseQueries(); + assert baseQueries != null: "RepositoryIndexQueryProvider.getBaseQueries not allowed to return null"; + return baseQueries.filterPluginGroupIds(prefix, providerRepos); + }); } - - private static @NonNull GenericFindQuery findFindQuery() { - return Lookup.getDefault().lookup(GenericFindQuery.class); - } - /** * @throws BooleanQuery.TooManyClauses This runtime exception can be thrown if given query is too * general and such search can't be executed as it would probably end with @@ -525,7 +518,12 @@ * @since 2.9 */ public static Result findResult(List fields, @NullAllowed List repos) { - return findFindQuery().find(fields, repos); + return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List providerRepos) -> { + GenericFindQuery genericFindQuery = queryProvider.getGenericFindQuery(); + return genericFindQuery != null ? + genericFindQuery.find(fields, providerRepos) : + new NullResultImpl<>(); + }); } /** @@ -551,9 +549,16 @@ public static void find(QueryRequest query) { for (Iterator it1 = query.getRepositories().iterator(); it1.hasNext();) { RepositoryInfo repositoryInfo = it1.next(); - List repositoryInfoL = new ArrayList(1); + List repositoryInfoL = new ArrayList<>(1); repositoryInfoL.add(repositoryInfo); - query.addResults(findFindQuery().find(query.getQueryFields(), repositoryInfoL).getResults(), !it1.hasNext()); + Result qeuryResult = + getQueryResult(repositoryInfoL, (RepositoryIndexQueryProvider queryProvider, List providerRepos) -> { + GenericFindQuery genericFindQuery = queryProvider.getGenericFindQuery(); + return genericFindQuery != null ? + genericFindQuery.find(query.getQueryFields(), providerRepos) : + new NullResultImpl<>(); + }); + query.addResults(qeuryResult.getResults(), !it1.hasNext()); // still someone waiting for results? if (query.countObservers() == 0) return; @@ -563,16 +568,15 @@ } public static @NonNull List getLoadedContexts() { - List toRet = new ArrayList(); - ContextLoadedQuery clq = Lookup.getDefault().lookup(ContextLoadedQuery.class); + List toRet = new ArrayList<>(); + List repos = RepositoryPreferences.getInstance().getRepositoryInfos(); + Map> i2r = getQueryProvider2Repo(repos); + for(Entry> e : i2r.entrySet()) { + ContextLoadedQuery clq = e.getKey().getContextLoadedQuery(); assert clq != null; - toRet.addAll(clq.getLoaded(RepositoryPreferences.getInstance().getRepositoryInfos())); + toRet.addAll(clq.getLoaded(repos)); + } return toRet; } - - public static Result filterArtifactIdForGroupIdResult(String groupId, String prefix, @NullAllowed List repos) { - return findBaseQueries().filterArtifactIdForGroupId(groupId, prefix, repos); } - -} Index: maven.indexer/src/org/netbeans/modules/maven/indexer/spi/ArchetypeQueries.java --- maven.indexer/src/org/netbeans/modules/maven/indexer/spi/ArchetypeQueries.java +++ maven.indexer/src/org/netbeans/modules/maven/indexer/spi/ArchetypeQueries.java @@ -53,6 +53,6 @@ */ public interface ArchetypeQueries { - RepositoryQueries.Result findArchetypes(List repos); + ResultImplementation findArchetypes(List repos); } Index: maven.indexer/src/org/netbeans/modules/maven/indexer/spi/BaseQueries.java --- maven.indexer/src/org/netbeans/modules/maven/indexer/spi/BaseQueries.java +++ maven.indexer/src/org/netbeans/modules/maven/indexer/spi/BaseQueries.java @@ -44,30 +44,82 @@ import java.util.List; import org.netbeans.modules.maven.indexer.api.NBVersionInfo; import org.netbeans.modules.maven.indexer.api.RepositoryInfo; -import org.netbeans.modules.maven.indexer.api.RepositoryQueries; /** * The basic set of queries. To be implemented by all index managers. + * + *

Note that all calls might be made from the IDE-s user interface and + * even if the return time isn't crucial for the UI responsivity, it still should be + * "reasonably" fast.

+ * * @author Milos Kleint */ public interface BaseQueries { - RepositoryQueries.Result getGroups(List repos); + /** + * Returns all group id-s available. + * + * @param repos repositories to search in + * @return groupId-s + */ + ResultImplementation getGroups(List repos); - RepositoryQueries.Result filterGroupIds(String prefix, List repos); + /** + * Returns versions given by GAV. + * + * @param groupId + * @param artifactId + * @param version + * @param repos repositories to search in + * @return NBVersionInfo-s + */ + ResultImplementation getRecords(String groupId, String artifactId, String version, List repos); - RepositoryQueries.Result getRecords(String groupId, String artifactId, String version, List repos); + /** + * Returns versions given by a groupId, artifactId. + * + * @param groupId + * @param artifactId + * @param repos repositories to search in + * @return NBVersionInfo-s + */ + ResultImplementation getVersions(String groupId, String artifactId, List repos); - RepositoryQueries.Result getArtifacts(String groupId, List repos); + /** + * Returns all artifactId-s given by a groupId. + * + * @param groupId + * @param repos repositories to search in + * @return artifactId-s + */ + ResultImplementation getArtifacts(String groupId, List repos); - RepositoryQueries.Result getVersions(String groupId, String artifactId, List repos); + /** + * Returns all artifactId-s given by a groupId and artifactId prefix. + * + * @param groupId + * @param artifactIdPrefix + * @param repos repositories to search in + * @return artifactId-s + */ + ResultImplementation filterPluginArtifactIds(String groupId, String artifactIdPrefix, List repos); - RepositoryQueries.Result filterPluginArtifactIds(String groupId, String prefix, List repos); + /** + * Returns all groupId-s given by a groupId prefix. + * + * @param prefix + * @param repos repositories to search in + * @return groupId-s + */ + ResultImplementation filterPluginGroupIds(String prefix, List repos); - RepositoryQueries.Result filterPluginGroupIds(String prefix, List repos); + /** + * Return all GAV-s given by a packaging. + * + * @param packaging + * @param repos repositories to search in + * @return GAV-s + */ + ResultImplementation getGAVsForPackaging(String packaging, List repos); - RepositoryQueries.Result filterArtifactIdForGroupId(String groupId, String prefix, List repos); - - RepositoryQueries.Result getGAVsForPackaging(String packaging, List repos); - } Index: maven.indexer/src/org/netbeans/modules/maven/indexer/spi/ChecksumQueries.java --- maven.indexer/src/org/netbeans/modules/maven/indexer/spi/ChecksumQueries.java +++ maven.indexer/src/org/netbeans/modules/maven/indexer/spi/ChecksumQueries.java @@ -51,5 +51,5 @@ * @author Milos Kleint */ public interface ChecksumQueries { - RepositoryQueries.Result findBySHA1(String sha1, List repos); + ResultImplementation findBySHA1(String sha1, List repos); \ No newline at end of file } Index: maven.indexer/src/org/netbeans/modules/maven/indexer/spi/ClassUsageQuery.java --- maven.indexer/src/org/netbeans/modules/maven/indexer/spi/ClassUsageQuery.java +++ maven.indexer/src/org/netbeans/modules/maven/indexer/spi/ClassUsageQuery.java @@ -59,6 +59,6 @@ * @param repos repositories of this type to search in * @return result object with a list of usages */ - RepositoryQueries.Result findClassUsages(String className, List repos); + ResultImplementation findClassUsages(String className, List repos); } Index: maven.indexer/src/org/netbeans/modules/maven/indexer/spi/ClassesQuery.java --- maven.indexer/src/org/netbeans/modules/maven/indexer/spi/ClassesQuery.java +++ maven.indexer/src/org/netbeans/modules/maven/indexer/spi/ClassesQuery.java @@ -43,9 +43,9 @@ package org.netbeans.modules.maven.indexer.spi; import java.util.List; +import org.apache.lucene.search.BooleanQuery; import org.netbeans.modules.maven.indexer.api.NBVersionInfo; import org.netbeans.modules.maven.indexer.api.RepositoryInfo; -import org.netbeans.modules.maven.indexer.api.RepositoryQueries; /** * Query to find artifacts information from class names. @@ -61,5 +61,5 @@ * accordingly, for example by telling user that entered text for * search is too general. */ - public RepositoryQueries.Result findVersionsByClass(final String className, List repos); + public ResultImplementation findVersionsByClass(final String className, List repos); } Index: maven.indexer/src/org/netbeans/modules/maven/indexer/spi/DependencyInfoQueries.java --- maven.indexer/src/org/netbeans/modules/maven/indexer/spi/DependencyInfoQueries.java +++ maven.indexer/src/org/netbeans/modules/maven/indexer/spi/DependencyInfoQueries.java @@ -45,7 +45,6 @@ import org.netbeans.modules.maven.indexer.api.NBGroupInfo; import org.netbeans.modules.maven.indexer.api.NBVersionInfo; import org.netbeans.modules.maven.indexer.api.RepositoryInfo; -import org.netbeans.modules.maven.indexer.api.RepositoryQueries; /** * Query to find dependency information of artifacts.Non mandatory for repository managers. @@ -53,8 +52,8 @@ */ public interface DependencyInfoQueries { - RepositoryQueries.Result findDependencyUsage(String groupId, String artifactId, String version, List repoIds); + ResultImplementation findDependencyUsage(String groupId, String artifactId, String version, List repoIds); - RepositoryQueries.Result findDependencyUsageGroups(String groupId, String artifactId, String version, List repoIds); + ResultImplementation findDependencyUsageGroups(String groupId, String artifactId, String version, List repoIds); } Index: maven.indexer/src/org/netbeans/modules/maven/indexer/spi/GenericFindQuery.java --- maven.indexer/src/org/netbeans/modules/maven/indexer/spi/GenericFindQuery.java +++ maven.indexer/src/org/netbeans/modules/maven/indexer/spi/GenericFindQuery.java @@ -43,10 +43,10 @@ package org.netbeans.modules.maven.indexer.spi; import java.util.List; +import org.apache.lucene.search.BooleanQuery; import org.netbeans.modules.maven.indexer.api.NBVersionInfo; import org.netbeans.modules.maven.indexer.api.QueryField; import org.netbeans.modules.maven.indexer.api.RepositoryInfo; -import org.netbeans.modules.maven.indexer.api.RepositoryQueries; /** * non mandatory query to for generic searching within the repository. @@ -63,6 +63,6 @@ * accordingly, for example by telling user that entered text for * search is too general. */ - public RepositoryQueries.Result find(List fields, List repos); + public ResultImplementation find(List fields, List repos); } Index: maven.indexer/src/org/netbeans/modules/maven/indexer/spi/NullResultImpl.java --- maven.indexer/src/org/netbeans/modules/maven/indexer/spi/NullResultImpl.java +++ maven.indexer/src/org/netbeans/modules/maven/indexer/spi/NullResultImpl.java @@ -0,0 +1,79 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2016 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2016 Sun Microsystems, Inc. + */ +package org.netbeans.modules.maven.indexer.spi; + +import java.util.Collections; +import java.util.List; + +/** + * Convenience class. + * + * @author Tomas Stupka + * @param + */ +public final class NullResultImpl implements ResultImplementation { + + @Override + public boolean isPartial() { + return false; + } + + @Override + public void waitForSkipped() { + + } + + @Override + public List getResults() { + return Collections.EMPTY_LIST; + } + + @Override + public int getTotalResultCount() { + return 0; + } + + @Override + public int getReturnedResultCount() { + return 0; + } +} Index: maven.indexer/src/org/netbeans/modules/maven/indexer/spi/Redo.java --- maven.indexer/src/org/netbeans/modules/maven/indexer/spi/Redo.java +++ maven.indexer/src/org/netbeans/modules/maven/indexer/spi/Redo.java @@ -1,53 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2012 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - * - * Contributor(s): - * - * Portions Copyrighted 2012 Sun Microsystems, Inc. - */ -package org.netbeans.modules.maven.indexer.spi; - -import org.netbeans.modules.maven.indexer.api.RepositoryQueries; - -/** - * used internally by the repository indexing/searching engine(s) - * @author mkleint - */ -public interface Redo { - void run(RepositoryQueries.Result result); -} - Index: maven.indexer/src/org/netbeans/modules/maven/indexer/spi/RepositoryIndexQueryProvider.java --- maven.indexer/src/org/netbeans/modules/maven/indexer/spi/RepositoryIndexQueryProvider.java +++ maven.indexer/src/org/netbeans/modules/maven/indexer/spi/RepositoryIndexQueryProvider.java @@ -0,0 +1,130 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2016 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2016 Sun Microsystems, Inc. + */ +package org.netbeans.modules.maven.indexer.spi; + +import org.netbeans.api.annotations.common.CheckForNull; +import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.api.annotations.common.NullAllowed; +import org.netbeans.modules.maven.indexer.api.RepositoryInfo; + +/** + * Provides repository queries.
+ * Register via @ServiceProvider(service=RepositoryIndexQueryProvider.class) + * + * @author Tomas Stupka + * @since 2.38 + */ +public interface RepositoryIndexQueryProvider { + + /** + * Determines if queries for the given repository are handled by this provider or not. + * + * @param repo the repository + * @return true if the given repository is handled by this provider, otherwise false + * @since 2.38 + */ + boolean handlesRepository(RepositoryInfo repo); + + /** + * Returns a {@link ArchetypeQueries} implementation. + * + * @return ArchetypeQueries or null if not provided + * @since 2.38 + */ + @CheckForNull ArchetypeQueries getArchetypeQueries(); + + /** + * Returns a {@link BaseQueries} implementation. + * + * @return BaseQueries + * @since 2.38 + */ + @NonNull BaseQueries getBaseQueries(); + + /** + * Returns a {@link ChecksumQueries} implementation. + * + * @return ChecksumQueries or null if not provided + * @since 2.38 + */ + @CheckForNull ChecksumQueries getChecksumQueries(); + + /** + * Returns a {@link ClassUsageQuery} implementation. + * + * @return ClassUsageQuery or null if not provided + * @since 2.38 + */ + @CheckForNull ClassUsageQuery getClassUsageQuery(); + + /** + * Returns a {@link ClassesQuery} implementation. + * + * @return ClassesQuery or null if not provided + * @since 2.38 + */ + @CheckForNull ClassesQuery getClassesQuery(); + + /** + * Returns a {@link ContextLoadedQuery} implementation. + * + * @return ContextLoadedQuery or null if not provided + * @since 2.38 + */ + @CheckForNull ContextLoadedQuery getContextLoadedQuery(); + + /** + * Returns a {@link DependencyInfoQueries} implementation. + * + * @return DependencyInfoQueries or null if not provided + * @since 2.38 + */ + @CheckForNull DependencyInfoQueries getDependencyInfoQueries(); + + /** + * Returns a {@link GenericFindQuery} implementation. + * + * @return GenericFindQuery or null if not provided + * @since 2.38 + */ + @CheckForNull GenericFindQuery getGenericFindQuery(); +} Index: maven.indexer/src/org/netbeans/modules/maven/indexer/spi/RepositoryIndexerImplementation.java --- maven.indexer/src/org/netbeans/modules/maven/indexer/spi/RepositoryIndexerImplementation.java +++ maven.indexer/src/org/netbeans/modules/maven/indexer/spi/RepositoryIndexerImplementation.java @@ -1,67 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2010 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - * - * Contributor(s): - * - * Portions Copyrighted 2008 Sun Microsystems, Inc. - */ -package org.netbeans.modules.maven.indexer.spi; - -import java.util.Collection; -import org.apache.maven.artifact.Artifact; -import org.netbeans.modules.maven.indexer.api.RepositoryInfo; - -/** - * Implementation of repository indexer (repository manager). Apart from basic - * indexing features also serves as provider of various index queries. - * There is one implementation based on apache indexer - * - * @author Milos Kleint - */ -public interface RepositoryIndexerImplementation { - - /** - * Index local repository or retrieve remote prepopulated index for local use. - * @param repo - */ - void indexRepo(RepositoryInfo repo); - - void updateIndexWithArtifacts(RepositoryInfo repo, Collection artifacts); - - void deleteArtifactFromIndex(RepositoryInfo repo, Artifact artifact); - -} Index: maven.indexer/src/org/netbeans/modules/maven/indexer/spi/ResultImplementation.java --- maven.indexer/src/org/netbeans/modules/maven/indexer/spi/ResultImplementation.java +++ maven.indexer/src/org/netbeans/modules/maven/indexer/spi/ResultImplementation.java @@ -0,0 +1,94 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2016 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2016 Sun Microsystems, Inc. + */ +package org.netbeans.modules.maven.indexer.spi; + +import java.util.List; + +/** + * Implement to provide a maven index query result. + * + * @author Tomas Stupka + * @param + * @since 2.38 + * @see org.netbeans.modules.maven.indexer.api.RepositoryQueries.Result + */ +public interface ResultImplementation { + /** + * Returns true is one or more indexes were skipped, e.g. because the indexing was taking place. + * + * @return true if the result is partial, otherwise false + * @since 2.38 + */ + public boolean isPartial(); + + /** + * Waits for currently unaccessible indexes to finish, not to be called in AWT thread. + * + * @since 2.38 + */ + public void waitForSkipped(); + + /** + * Returns the results. + * + * @return a list of results + * @since 2.38 + */ + public List getResults(); + + /** + * Total number of hits. + * + * @return the total number of hits + * @since 2.38 + */ + public int getTotalResultCount(); + + /** + * In some cases not entirely accurate number of processed and returned hits, + * typically should be less or equal to {@link #getReturnedResultCount()}. + * + * @return the returned result count + * @since 2.38 + */ + public int getReturnedResultCount(); +} Index: maven.indexer/src/org/netbeans/modules/maven/indexer/spi/impl/Redo.java --- maven.indexer/src/org/netbeans/modules/maven/indexer/spi/impl/Redo.java +++ maven.indexer/src/org/netbeans/modules/maven/indexer/spi/impl/Redo.java @@ -0,0 +1,53 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.maven.indexer.spi.impl; + +import org.netbeans.modules.maven.indexer.ResultImpl; + +/** + * used internally by the repository indexing/searching engine(s) + * @author mkleint + */ +public interface Redo { + void run(ResultImpl result); +} + Index: maven.indexer/src/org/netbeans/modules/maven/indexer/spi/impl/RepositoryIndexerImplementation.java --- maven.indexer/src/org/netbeans/modules/maven/indexer/spi/impl/RepositoryIndexerImplementation.java +++ maven.indexer/src/org/netbeans/modules/maven/indexer/spi/impl/RepositoryIndexerImplementation.java @@ -0,0 +1,72 @@ +package org.netbeans.modules.maven.indexer.spi.impl; + +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + + +import java.util.Collection; +import org.apache.maven.artifact.Artifact; +import org.netbeans.modules.maven.indexer.api.RepositoryInfo; + +/** + * + * Used internally. + * + * Implementation of repository indexer (repository manager). Apart from basic + * indexing features also serves as provider of various index queries. + * There is one implementation based on apache indexer + * + * @author Milos Kleint + */ +public interface RepositoryIndexerImplementation { + + /** + * Index local repository or retrieve remote prepopulated index for local use. + * @param repo + */ + void indexRepo(RepositoryInfo repo); + + void updateIndexWithArtifacts(RepositoryInfo repo, Collection artifacts); + + void deleteArtifactFromIndex(RepositoryInfo repo, Artifact artifact); + +} Index: maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImplTest.java --- maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImplTest.java +++ maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImplTest.java @@ -46,8 +46,11 @@ import java.util.Collections; import java.util.List; import org.apache.maven.index.ArtifactInfo; +import org.netbeans.junit.MockServices; +import org.netbeans.modules.maven.indexer.api.AbstractTestQueryProvider.TestIndexer1; import org.netbeans.modules.maven.indexer.api.NBVersionInfo; import org.netbeans.modules.maven.indexer.api.QueryField; +import org.netbeans.modules.maven.indexer.api.RepositoryQueries; import org.openide.util.test.TestFileUtils; public class NexusRepositoryIndexerImplTest extends NexusTestBase { @@ -56,10 +59,15 @@ super(n); } - public void testFilterGroupIds() throws Exception { + public void testFilterPluginGroupIdsRepositoryQueries() throws Exception { + // add an alternative QueryProvider _not_ handlig our request + MockServices.setServices(TestIndexer1.class); + install(File.createTempFile("whatever", ".txt", getWorkDir()), "test", "spin", "1.1", "txt"); nrii.indexRepo(info); - assertEquals("[test]", nrii.filterGroupIds("", Collections.singletonList(info)).getResults().toString()); + // RepositoryQueries should handle the query via our NexusRepositoryIndexerImpl + RepositoryQueries.Result res = RepositoryQueries.getArtifactsResult("test", Collections.singletonList(info)); + assertEquals("[spin]", res.getResults().toString()); } public void testFind() throws Exception { Index: maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/NexusTestBase.java --- maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/NexusTestBase.java +++ maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/NexusTestBase.java @@ -49,6 +49,7 @@ import org.netbeans.modules.maven.indexer.api.RepositoryInfo; import org.netbeans.modules.maven.indexer.api.RepositoryPreferences; import org.openide.modules.api.PlacesTestUtils; +import org.openide.util.Lookup; import org.openide.util.Utilities; import org.openide.util.test.TestFileUtils; @@ -75,7 +76,7 @@ artifactInstaller = embedder.lookupComponent(ArtifactInstaller.class); info = new RepositoryInfo("test", "Test", repo.getAbsolutePath(), null); RepositoryPreferences.getInstance().addOrModifyRepositoryInfo(info); - nrii = new NexusRepositoryIndexerImpl(); + nrii = Lookup.getDefault().lookup(NexusRepositoryIndexerImpl.class); } @Override protected Level logLevel() { Index: maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/api/AbstractTestQueryProvider.java --- maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/api/AbstractTestQueryProvider.java +++ maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/api/AbstractTestQueryProvider.java @@ -0,0 +1,181 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2016 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2016 Sun Microsystems, Inc. + */ +package org.netbeans.modules.maven.indexer.api; + +import java.net.URISyntaxException; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import org.apache.maven.artifact.Artifact; +import org.netbeans.modules.maven.indexer.spi.ArchetypeQueries; +import org.netbeans.modules.maven.indexer.spi.BaseQueries; +import org.netbeans.modules.maven.indexer.spi.ChecksumQueries; +import org.netbeans.modules.maven.indexer.spi.ClassUsageQuery; +import org.netbeans.modules.maven.indexer.spi.ClassesQuery; +import org.netbeans.modules.maven.indexer.spi.ContextLoadedQuery; +import org.netbeans.modules.maven.indexer.spi.DependencyInfoQueries; +import org.netbeans.modules.maven.indexer.spi.GenericFindQuery; +import org.netbeans.modules.maven.indexer.spi.ResultImplementation; +import org.openide.util.Exceptions; +import org.netbeans.modules.maven.indexer.spi.RepositoryIndexQueryProvider; + +/** + * + * @author tomas + */ +public abstract class AbstractTestQueryProvider implements RepositoryIndexQueryProvider { + + private static final String TESTREPO = "testrepo"; + + public static class TestIndexer1 extends AbstractTestQueryProvider { + public static final String ID = TESTREPO + ".1"; + public static RepositoryInfo REPO; + static { + try {REPO = new RepositoryInfo(ID, ID, null, "http://test1"); } catch (URISyntaxException ex) { Exceptions.printStackTrace(ex); } + } + public TestIndexer1() { + this.repos = new RepositoryInfo[] {REPO}; + } + protected String getID() { + return ID; + } + } + public static class TestIndexer2 extends AbstractTestQueryProvider { + public static final String ID = TESTREPO + ".2"; + public static RepositoryInfo REPO; + static { + try {REPO = new RepositoryInfo(ID, ID, null, "http://test1"); } catch (URISyntaxException ex) { Exceptions.printStackTrace(ex); } + } + public TestIndexer2() { + this.repos = new RepositoryInfo[] {REPO}; + } + + protected String getID() { + return ID; + } + } + + protected RepositoryInfo[] repos; + public AbstractTestQueryProvider() { + } + + @Override + public boolean handlesRepository(RepositoryInfo repo) { + for (RepositoryInfo r : repos) { + if(repo.getId().equals(r.getId())) { + return true; + } + } + return false; + } + + abstract protected String getID(); + + @Override + public ArchetypeQueries getArchetypeQueries() { + return new ArchetypeQueries() { + @Override + public ResultImplementation findArchetypes(List repos) { + return new ResultImplementation() { + @Override + public boolean isPartial() { + return false; + } + + @Override + public void waitForSkipped() { } + + @Override + public List getResults() { + return Arrays.asList(new NBVersionInfo(getID(), getID(), getID(), "1.0", "jar", "jar", "test", "test", null)); + } + + @Override + public int getTotalResultCount() { + return 1; + } + + @Override + public int getReturnedResultCount() { + return 1; + } + }; + } + }; + } + + @Override + public BaseQueries getBaseQueries() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public ChecksumQueries getChecksumQueries() { + return null; + } + + @Override + public ClassUsageQuery getClassUsageQuery() { + return null; + } + + @Override + public ClassesQuery getClassesQuery() { + return null; + } + + @Override + public ContextLoadedQuery getContextLoadedQuery() { + return null; + } + + @Override + public DependencyInfoQueries getDependencyInfoQueries() { + return null; + } + + @Override + public GenericFindQuery getGenericFindQuery() { + return null; + } + +} Index: maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/api/RepositoryQueriesTest.java --- maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/api/RepositoryQueriesTest.java +++ maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/api/RepositoryQueriesTest.java @@ -0,0 +1,144 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2010 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.maven.indexer.api; + +import java.io.File; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import org.netbeans.junit.MockServices; +import org.netbeans.junit.NbTestCase; +import org.netbeans.modules.maven.indexer.api.AbstractTestQueryProvider.TestIndexer1; +import org.netbeans.modules.maven.indexer.api.AbstractTestQueryProvider.TestIndexer2; +import org.netbeans.modules.maven.indexer.spi.ArchetypeQueries; +import org.openide.util.Exceptions; + +public class RepositoryQueriesTest extends NbTestCase { + + public RepositoryQueriesTest(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + public void testAlternativeQueryProvider() throws URISyntaxException { + + } + + public void testAlternativeResult() throws URISyntaxException { + MockServices.setServices(TestIndexer1.class); + + RepositoryQueries.Result result = RepositoryQueries.findArchetypesResult(Arrays.asList(TestIndexer1.REPO)); + assertEquals(TestIndexer1.ID, result.getResults().get(0).getArtifactId()); + assertEquals(1, result.getTotalResultCount()); + assertEquals(1, result.getReturnedResultCount()); + } + + public void testTwoReposTwoQueryProviders() throws URISyntaxException { + MockServices.setServices(TestIndexer1.class, TestIndexer2.class); + + RepositoryQueries.Result result = RepositoryQueries.findArchetypesResult(Arrays.asList(TestIndexer1.REPO, TestIndexer2.REPO)); + assertEquals(2, result.getTotalResultCount()); + assertEquals(2, result.getReturnedResultCount()); + assertArtefactIds(result.getResults(), new String[] {TestIndexer1.ID, TestIndexer2.ID}); + } + + public void testTwoReposOneAccepted() throws URISyntaxException { + MockServices.setServices(TestIndexer1.class); + + RepositoryQueries.Result result = RepositoryQueries.findArchetypesResult(Arrays.asList(TestIndexer1.REPO, TestIndexer2.REPO)); + assertEquals(1, result.getTotalResultCount()); + assertEquals(1, result.getReturnedResultCount()); + assertArtefactIds(result.getResults(), new String[] {TestIndexer1.ID}); + } + + public void testNullResult() throws URISyntaxException { + MockServices.setServices(NullQueryProvider.class); + List repos = Arrays.asList(NullQueryProvider.REPO); + assertEquals(0, RepositoryQueries.findArchetypesResult(repos).getTotalResultCount()); + assertEquals(0, RepositoryQueries.findBySHA1Result(new File(""), Arrays.asList(NullQueryProvider.REPO)).getTotalResultCount()); + assertEquals(0, RepositoryQueries.findClassUsagesResult("", repos).getTotalResultCount()); + assertEquals(0, RepositoryQueries.findDependencyUsageResult("","","", repos).getTotalResultCount()); + assertEquals(0, RepositoryQueries.findResult(Collections.EMPTY_LIST, repos).getTotalResultCount()); + assertEquals(0, RepositoryQueries.findVersionsByClassResult("", repos).getTotalResultCount()); + assertEquals(0, RepositoryQueries.getLoadedContexts().size()); + } + + private void assertArtefactIds(List infos, String[] ids) { + assertEquals(ids.length, infos.size()); + List returnedIds = new ArrayList<>(infos.size()); + infos.stream().forEach((info) -> returnedIds.add(info.getArtifactId())); + for (String id : ids) { + assertTrue(returnedIds.contains(id)); + } + } + + public static class NullQueryProvider extends AbstractTestQueryProvider { + static final String ID = "nullrepo"; + static RepositoryInfo REPO; + static { + try { + REPO = new RepositoryInfo(ID, ID, null, "http://test1"); + } catch (URISyntaxException ex) { + Exceptions.printStackTrace(ex); + } + } + + public NullQueryProvider() { + this.repos = new RepositoryInfo[] {REPO}; + } + protected String getID() { + return ID; + } + @Override + public ArchetypeQueries getArchetypeQueries() { + return null; + } + } + +}