Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maven remote index migration and refactoring #7976

Merged
merged 2 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private static boolean isArchiveFile(File jar) throws IOException {
static void search(String className, Indexer indexer, Collection<IndexingContext> contexts, List<? super ClassUsage> results) throws IOException {
String searchString = crc32base32(className.replace('.', '/'));
Query refClassQuery = indexer.constructQuery(FLD_NB_DEPENDENCY_CLASS.getOntology(), new StringSearchExpression(searchString));
TopScoreDocCollector collector = TopScoreDocCollector.create(NexusRepositoryIndexerImpl.MAX_RESULT_COUNT, Integer.MAX_VALUE);
TopScoreDocCollector collector = TopScoreDocCollector.create(NexusRepositoryIndexManager.MAX_RESULT_COUNT, Integer.MAX_VALUE);
for (IndexingContext context : contexts) {
IndexSearcher searcher = context.acquireIndexSearcher();
try {
Expand All @@ -185,7 +185,7 @@ static void search(String className, Indexer indexer, Collection<IndexingContext
ArtifactInfo ai = IndexUtils.constructArtifactInfo(d, context);
if (ai != null) {
ai.setRepository(context.getRepositoryId());
List<NBVersionInfo> version = NexusRepositoryIndexerImpl.convertToNBVersionInfo(List.of(ai));
List<NBVersionInfo> version = NexusRepositoryQueries.convertToNBVersionInfo(List.of(ai));
if (!version.isEmpty()) {
results.add(new ClassUsage(version.get(0), refClasses));
}
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void run() {
}
}
for (RepositoryIndexerImplementation rii : Lookup.getDefault().lookupAll(RepositoryIndexerImplementation.class)) {
if (rii instanceof NexusRepositoryIndexerImpl impl) {
if (rii instanceof NexusRepositoryIndexManager impl) {
impl.shutdownAll();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.openide.util.Cancellable;
import org.openide.util.NbBundle.Messages;

public class RemoteIndexTransferListener implements TransferListener, Cancellable {
public class RemoteIndexTransferListener implements TransferListener, Cancellable, AutoCloseable {

private static final Logger LOG = Logger.getLogger(RemoteIndexTransferListener.class.getName());

Expand Down Expand Up @@ -167,7 +167,8 @@ void unpackingProgress(String label) {
handle.progress(label);
}

void close() {
@Override
public void close() {
handle.finish();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import java.util.Collection;
import org.apache.maven.artifact.Artifact;
import org.netbeans.modules.maven.indexer.NexusRepositoryIndexerImpl;
import org.netbeans.modules.maven.indexer.NexusRepositoryIndexManager;
import org.netbeans.modules.maven.indexer.spi.impl.RepositoryIndexerImplementation;
import org.openide.util.Lookup;
import org.netbeans.modules.maven.indexer.spi.RepositoryIndexQueryProvider;
Expand Down Expand Up @@ -71,7 +71,7 @@ static RepositoryIndexerImplementation findImplementation(RepositoryInfo repo) {
Lookup l = Lookup.getDefault();
Collection<? extends RepositoryIndexQueryProvider> queryProviders = l.lookupAll(RepositoryIndexQueryProvider.class);
for (RepositoryIndexQueryProvider queryProvider : queryProviders) {
if(!(queryProvider instanceof NexusRepositoryIndexerImpl) && queryProvider.handlesRepository(repo)) {
if(!(queryProvider instanceof NexusRepositoryIndexManager) && queryProvider.handlesRepository(repo)) {
// skip if
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
*
* 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
* Implementation of repository indexer (repository manager).
* There is one implementation based on apache indexer.
*
* @author Milos Kleint
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.netbeans.modules.maven.indexer.api.NBVersionInfo;
import org.netbeans.modules.maven.indexer.api.RepositoryInfo;
import org.netbeans.modules.maven.indexer.api.RepositoryQueries.ClassUsage;
import org.netbeans.modules.maven.indexer.spi.ClassUsageQuery;
import org.netbeans.modules.maven.indexer.spi.ClassesQuery;
import org.openide.filesystems.FileUtil;
import org.openide.util.test.JarBuilder;
import org.openide.util.test.TestFileUtils;
Expand Down Expand Up @@ -87,21 +89,22 @@ public void testFindClassUsages() throws Exception {
nrii.indexRepo(info);
List<RepositoryInfo> repo = List.of(info);

List<ClassUsage> list = nrii.findClassUsages("mod1.API", repo).getResults();
ClassUsageQuery query = nrii.getClassUsageQuery();
List<ClassUsage> list = query.findClassUsages("mod1.API", repo).getResults();
assertEquals("[test:mod2:0:test[mod2.Client, mod2.OtherClient], test:mod3:0:test[mod3.Client]]", list.toString());

list = nrii.findClassUsages("mod1.Util", repo).getResults();
list = query.findClassUsages("mod1.Util", repo).getResults();
assertEquals("[test:mod4:0:test[mod4.Install]]", list.toString());
assertEquals("jar", list.get(0).getArtifact().getType());

list = nrii.findClassUsages("mod1.Stuff", repo).getResults();
list = query.findClassUsages("mod1.Stuff", repo).getResults();
assertEquals("[test:mod5:0:test[mod5.Install]]", list.toString());
assertEquals("jar", list.get(0).getArtifact().getType());

assertEquals("[]", nrii.findClassUsages("java.lang.Object", repo).getResults().toString());
assertEquals("[test:mod2:0:test[mod2.Outer]]", nrii.findClassUsages("mod1.Outer", repo).getResults().toString());
assertEquals("[test:mod2:0:test[mod2.Outer]]", nrii.findClassUsages("mod1.Outer$Inner", repo).getResults().toString());
assertEquals("[]", nrii.findClassUsages("mod1.Outer$Unused", repo).getResults().toString());
assertEquals("[]", query.findClassUsages("java.lang.Object", repo).getResults().toString());
assertEquals("[test:mod2:0:test[mod2.Outer]]", query.findClassUsages("mod1.Outer", repo).getResults().toString());
assertEquals("[test:mod2:0:test[mod2.Outer]]", query.findClassUsages("mod1.Outer$Inner", repo).getResults().toString());
assertEquals("[]", query.findClassUsages("mod1.Outer$Unused", repo).getResults().toString());
// XXX InnerClass attribute will produce spurious references to outer classes even when just an inner is used
}

Expand Down Expand Up @@ -129,18 +132,19 @@ public void testFindVersionsByClass() throws Exception {
nrii.indexRepo(info);
List<RepositoryInfo> repo = List.of(info);

ClassesQuery query = nrii.getClassesQuery();
// single version
List<NBVersionInfo> list = nrii.findVersionsByClass("mod1.API", repo).getResults();
List<NBVersionInfo> list = query.findVersionsByClass("mod1.API", repo).getResults();
assertEquals("[test:mod1:42:test]", list.toString());

list = nrii.findVersionsByClass("mod1.Util", repo).getResults();
list = query.findVersionsByClass("mod1.Util", repo).getResults();
assertEquals("[test:mod1:42:test]", list.toString());

// two versions
list = nrii.findVersionsByClass("mod2.API2", repo).getResults();
list = query.findVersionsByClass("mod2.API2", repo).getResults();
assertEquals("[test:mod2:43:test, test:mod2:42:test]", list.toString());

list = nrii.findVersionsByClass("mod2.Util2", repo).getResults();
list = query.findVersionsByClass("mod2.Util2", repo).getResults();
assertEquals("[test:mod2:43:test]", list.toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void testFind() throws Exception {
qf.setValue("stuff");
qf.setOccur(QueryField.OCCUR_MUST);
qf.setMatch(QueryField.MATCH_EXACT);
assertEquals("[test:plugin:0:test]", nrii.find(List.of(qf), List.of(info)).getResults().toString());
assertEquals("[test:plugin:0:test]", nrii.getGenericFindQuery().find(List.of(qf), List.of(info)).getResults().toString());
}

public void testLastUpdated() throws Exception { // #197670
Expand All @@ -65,7 +65,7 @@ public void testLastUpdated() throws Exception { // #197670
install(empty, "test", "art", "0", "pom.lastUpdated");
install(empty, "test", "art", "0", "jar.lastUpdated");
nrii.indexRepo(info);
List<NBVersionInfo> versions = nrii.getVersions("test", "art", List.of(info)).getResults();
List<NBVersionInfo> versions = nrii.getBaseQueries().getVersions("test", "art", List.of(info)).getResults();
assertEquals(1, versions.size());
NBVersionInfo v = versions.get(0);
assertEquals("test:art:0:test", v.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected NexusTestBase(String n) {
private MavenEmbedder embedder;
private ArtifactInstaller artifactInstaller;
protected RepositoryInfo info;
protected NexusRepositoryIndexerImpl nrii;
protected NexusRepositoryIndexManager nrii;

@Override protected void setUp() throws Exception {
clearWorkDir();
Expand All @@ -57,7 +57,7 @@ protected NexusTestBase(String n) {
artifactInstaller = embedder.lookupComponent(ArtifactInstaller.class);
info = new RepositoryInfo("test", "Test", repo.getAbsolutePath(), null);
RepositoryPreferences.getInstance().addOrModifyRepositoryInfo(info);
nrii = Lookup.getDefault().lookup(NexusRepositoryIndexerImpl.class);
nrii = Lookup.getDefault().lookup(NexusRepositoryIndexManager.class);
}

@Override protected Level logLevel() {
Expand Down
Loading