This is an automated email from the ASF dual-hosted git repository.

mbien pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 4fe23db270 update to maven-indexer 7.0.3.
     new a7b73e5800 Merge pull request #6089 from mbien/indexer703_optimizations
4fe23db270 is described below

commit 4fe23db2707ae7a23860b58bafdd6852b13b7f50
Author: Michael Bien <mbie...@gmail.com>
AuthorDate: Sat Jun 17 10:39:19 2023 +0200

    update to maven-indexer 7.0.3.
    
    upstream indexer changes provide:
    
     - significantly improved incremental update performance
     - other index creation optimizations
    
    group cache rebuild improvements and some code cleanup
    
     - deprecation fixes
     - improved logging
     - code cleanup and optimizations
    
    ClassDependencyIndexCreator
    
     - CRC computation should be thread safe
---
 java/maven.indexer/external/binaries-list          |  6 +-
 ...-license.txt => indexer-core-7.0.3-license.txt} |  4 +-
 ....2-notice.txt => indexer-core-7.0.3-notice.txt} |  0
 java/maven.indexer/nbproject/project.properties    |  6 +-
 java/maven.indexer/nbproject/project.xml           | 12 +--
 .../indexer/ArtifactDependencyIndexCreator.java    |  2 +-
 .../maven/indexer/ClassDependencyIndexCreator.java | 23 +++---
 .../maven/indexer/NexusRepositoryIndexerImpl.java  | 94 +++++++++++++---------
 .../modules/maven/indexer/api/NBArtifactInfo.java  |  1 +
 .../modules/maven/indexer/api/NBGroupInfo.java     |  1 +
 .../modules/maven/indexer/api/RepositoryUtil.java  | 30 ++-----
 .../indexer/ClassDependencyIndexCreatorTest.java   |  5 +-
 .../indexer/NexusRepositoryIndexerImplTest.java    |  7 +-
 .../maven/indexer/api/RepositoryQueriesTest.java   | 10 +--
 14 files changed, 96 insertions(+), 105 deletions(-)

diff --git a/java/maven.indexer/external/binaries-list 
b/java/maven.indexer/external/binaries-list
index 02a0f1941a..90524f0108 100644
--- a/java/maven.indexer/external/binaries-list
+++ b/java/maven.indexer/external/binaries-list
@@ -14,9 +14,9 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-C02F9C34FBC4C698BEF9D5074966545122908D06 
org.apache.maven.indexer:indexer-core:7.0.2
-20AE1ED178C812FAA78DC83C9BF218D047FD01D0 
org.apache.maven.indexer:search-api:7.0.2
-5967AEFBE9281C46155E73BBFC1E2BC4054CC92F 
org.apache.maven.indexer:search-backend-smo:7.0.2
+D9086E551E71DC953FC989754500E9905AF3FB1B 
org.apache.maven.indexer:indexer-core:7.0.3
+C3C93EF8FEAB7CE50FEFB3C3947A2F6A27E6B3F0 
org.apache.maven.indexer:search-api:7.0.3
+BD0EAC88D46ED462BB62D074D8EA3227905C7391 
org.apache.maven.indexer:search-backend-smo:7.0.3
 2C08C7A491E9D033BB4806E0A45496E3A0667217 org.apache.lucene:lucene-core:9.6.0
 A4819CA127C46A2759FDF091F41512C56C441FA7 
org.apache.lucene:lucene-backward-codecs:9.6.0
 B9E14451C73FA0BC8E71A2CFE12A442F37A53C69 
org.apache.lucene:lucene-highlighter:9.6.0
diff --git a/java/maven.indexer/external/indexer-core-7.0.2-license.txt 
b/java/maven.indexer/external/indexer-core-7.0.3-license.txt
similarity index 99%
rename from java/maven.indexer/external/indexer-core-7.0.2-license.txt
rename to java/maven.indexer/external/indexer-core-7.0.3-license.txt
index b23fed39ef..c50a347c13 100644
--- a/java/maven.indexer/external/indexer-core-7.0.2-license.txt
+++ b/java/maven.indexer/external/indexer-core-7.0.3-license.txt
@@ -1,11 +1,11 @@
 Name: Maven Indexer
 Description: Maven remote repository indexing engine.
-Version: 7.0.2
+Version: 7.0.3
 Origin: Apache Software Foundation
 License: Apache-2.0
 URL: https://repo1.maven.org/maven2/org/apache/maven/indexer/
 Source: https://github.com/apache/maven-indexer
-Files: indexer-core-7.0.2.jar search-api-7.0.2.jar search-backend-smo-7.0.2.jar
+Files: indexer-core-7.0.3.jar search-api-7.0.3.jar search-backend-smo-7.0.3.jar
 
                                  Apache License
                            Version 2.0, January 2004
diff --git a/java/maven.indexer/external/indexer-core-7.0.2-notice.txt 
b/java/maven.indexer/external/indexer-core-7.0.3-notice.txt
similarity index 100%
rename from java/maven.indexer/external/indexer-core-7.0.2-notice.txt
rename to java/maven.indexer/external/indexer-core-7.0.3-notice.txt
diff --git a/java/maven.indexer/nbproject/project.properties 
b/java/maven.indexer/nbproject/project.properties
index fda5aa1a25..84ee23cbdc 100644
--- a/java/maven.indexer/nbproject/project.properties
+++ b/java/maven.indexer/nbproject/project.properties
@@ -20,9 +20,9 @@ is.autoload=true
 javac.source=11
 javac.target=11
 javac.compilerargs=-Xlint -Xlint:-serial
-release.external/indexer-core-7.0.2.jar=modules/ext/maven/indexer-core-7.0.2.jar
-release.external/search-api-7.0.2.jar=modules/ext/maven/search-api-7.0.2.jar
-release.external/search-backend-smo-7.0.2.jar=modules/ext/maven/search-backend-smo-7.0.2.jar
+release.external/indexer-core-7.0.3.jar=modules/ext/maven/indexer-core-7.0.3.jar
+release.external/search-api-7.0.3.jar=modules/ext/maven/search-api-7.0.3.jar
+release.external/search-backend-smo-7.0.3.jar=modules/ext/maven/search-backend-smo-7.0.3.jar
 release.external/gson-2.10.1.jar=modules/ext/maven/gson-2.10.1.jar
 release.external/lucene-core-9.6.0.jar=modules/ext/maven/lucene-core-9.6.0.jar
 
release.external/lucene-backward-codecs-9.6.0.jar=modules/ext/maven/lucene-backward-codecs-9.6.0.jar
diff --git a/java/maven.indexer/nbproject/project.xml 
b/java/maven.indexer/nbproject/project.xml
index fc2f00355b..19c22e0642 100644
--- a/java/maven.indexer/nbproject/project.xml
+++ b/java/maven.indexer/nbproject/project.xml
@@ -175,16 +175,16 @@
                 <package>org.netbeans.modules.maven.indexer.spi.impl</package>
             </friend-packages>
             <class-path-extension>
-                
<runtime-relative-path>ext/maven/indexer-core-7.0.2.jar</runtime-relative-path>
-                <binary-origin>external/indexer-core-7.0.2.jar</binary-origin>
+                
<runtime-relative-path>ext/maven/indexer-core-7.0.3.jar</runtime-relative-path>
+                <binary-origin>external/indexer-core-7.0.3.jar</binary-origin>
             </class-path-extension>
             <class-path-extension>
-                
<runtime-relative-path>ext/maven/search-api-7.0.2.jar</runtime-relative-path>
-                <binary-origin>external/search-api-7.0.2.jar</binary-origin>
+                
<runtime-relative-path>ext/maven/search-api-7.0.3.jar</runtime-relative-path>
+                <binary-origin>external/search-api-7.0.3.jar</binary-origin>
             </class-path-extension>
             <class-path-extension>
-                
<runtime-relative-path>ext/maven/search-backend-smo-7.0.2.jar</runtime-relative-path>
-                
<binary-origin>external/search-backend-smo-7.0.2.jar</binary-origin>
+                
<runtime-relative-path>ext/maven/search-backend-smo-7.0.3.jar</runtime-relative-path>
+                
<binary-origin>external/search-backend-smo-7.0.3.jar</binary-origin>
             </class-path-extension>
             <class-path-extension>
                 
<runtime-relative-path>ext/maven/lucene-core-9.6.0.jar</runtime-relative-path>
diff --git 
a/java/maven.indexer/src/org/netbeans/modules/maven/indexer/ArtifactDependencyIndexCreator.java
 
b/java/maven.indexer/src/org/netbeans/modules/maven/indexer/ArtifactDependencyIndexCreator.java
index 52964bf717..60b3c58021 100644
--- 
a/java/maven.indexer/src/org/netbeans/modules/maven/indexer/ArtifactDependencyIndexCreator.java
+++ 
b/java/maven.indexer/src/org/netbeans/modules/maven/indexer/ArtifactDependencyIndexCreator.java
@@ -114,7 +114,7 @@ class ArtifactDependencyIndexCreator extends 
AbstractIndexCreator {
     }
 
     @Override public Collection<IndexerField> getIndexerFields() {
-        return Arrays.asList(FLD_NB_DEPENDENCY_GROUP, 
FLD_NB_DEPENDENCY_ARTIFACT, FLD_NB_DEPENDENCY_VERSION);
+        return List.of(FLD_NB_DEPENDENCY_GROUP, FLD_NB_DEPENDENCY_ARTIFACT, 
FLD_NB_DEPENDENCY_VERSION);
     }
 
     private MavenProject load(ArtifactInfo ai) {
diff --git 
a/java/maven.indexer/src/org/netbeans/modules/maven/indexer/ClassDependencyIndexCreator.java
 
b/java/maven.indexer/src/org/netbeans/modules/maven/indexer/ClassDependencyIndexCreator.java
index 08a4bd8be8..3fc430635f 100644
--- 
a/java/maven.indexer/src/org/netbeans/modules/maven/indexer/ClassDependencyIndexCreator.java
+++ 
b/java/maven.indexer/src/org/netbeans/modules/maven/indexer/ClassDependencyIndexCreator.java
@@ -27,7 +27,6 @@ import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -43,6 +42,7 @@ import java.util.stream.Stream;
 import java.util.zip.CRC32;
 import org.apache.commons.codec.binary.Base32;
 import org.apache.lucene.document.Document;
+import org.apache.lucene.index.StoredFields;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.ScoreDoc;
@@ -172,11 +172,12 @@ class ClassDependencyIndexCreator extends 
AbstractIndexCreator {
         for (IndexingContext context : contexts) {
             IndexSearcher searcher = context.acquireIndexSearcher();
             try {
+                StoredFields storedFields = searcher.storedFields();
                 searcher.search(refClassQuery, collector);
                 ScoreDoc[] hits = collector.topDocs().scoreDocs;
                 LOG.log(Level.FINER, "for {0} ~ {1} found {2} hits", new 
Object[] {className, searchString, hits.length});
                 for (ScoreDoc hit : hits) {
-                    Document d = searcher.doc(hit.doc);
+                    Document d = storedFields.document(hit.doc);
                     String fldValue = d.get(NB_DEPENDENCY_CLASSES);
                     LOG.log(Level.FINER, "{0} uses: {1}", new Object[] 
{className, fldValue});
                     Set<String> refClasses = parseField(searchString, 
fldValue, d.get(ArtifactInfo.NAMES));
@@ -184,7 +185,7 @@ class ClassDependencyIndexCreator extends 
AbstractIndexCreator {
                         ArtifactInfo ai = IndexUtils.constructArtifactInfo(d, 
context);
                         if (ai != null) {
                             ai.setRepository(context.getRepositoryId());
-                            List<NBVersionInfo> version = 
NexusRepositoryIndexerImpl.convertToNBVersionInfo(Collections.singleton(ai));
+                            List<NBVersionInfo> version = 
NexusRepositoryIndexerImpl.convertToNBVersionInfo(List.of(ai));
                             if (!version.isEmpty()) {
                                 results.add(new ClassUsage(version.get(0), 
refClasses));
                             }
@@ -196,7 +197,9 @@ class ClassDependencyIndexCreator extends 
AbstractIndexCreator {
             }
         }
     }
+
     private static Set<String> parseField(String refereeCRC, String field, 
String referrersNL) {
+        assert refereeCRC.length() == 7;
         Set<String> referrers = new TreeSet<>();
         int p = 0;
         for (String referrer : referrersNL.split("\n")) {
@@ -205,7 +208,7 @@ class ClassDependencyIndexCreator extends 
AbstractIndexCreator {
                     p++;
                     break;
                 }
-                if (field.substring(p, p + 7).equals(refereeCRC)) {
+                if (field.regionMatches(p, refereeCRC, 0, 
refereeCRC.length())) {
                     referrers.add(referrer.substring(1).replace('/', '.'));
                 }
                 p += 8;
@@ -269,12 +272,7 @@ class ClassDependencyIndexCreator extends 
AbstractIndexCreator {
         int shell = referrer.indexOf('$', referrer.lastIndexOf('/') + 1);
         String referrerTopLevel = shell == -1 ? referrer : 
referrer.substring(0, shell);
 
-        Set<String> tmp = depsMap.get(referrerTopLevel);
-        if (tmp == null) {
-            tmp = new HashSet<>();
-            depsMap.put(referrerTopLevel, tmp);
-        }
-        Set<String> referees = tmp;
+        Set<String> referees = depsMap.computeIfAbsent(referrerTopLevel, k -> 
new HashSet<>());
 
         dependenciesOf(classData)
             .filter((referee) -> !referrer.equals(referee))
@@ -366,7 +364,7 @@ class ClassDependencyIndexCreator extends 
AbstractIndexCreator {
                 
.stream().unordered().map(ClassName::getInternalName).distinct();
     }
 
-    static final List<IndexerField> INDEXER_FIELDS = 
Collections.singletonList(FLD_NB_DEPENDENCY_CLASS);
+    static final List<IndexerField> INDEXER_FIELDS = 
List.of(FLD_NB_DEPENDENCY_CLASS);
     @Override
     public Collection<IndexerField> getIndexerFields() {
         return INDEXER_FIELDS;
@@ -377,7 +375,7 @@ class ClassDependencyIndexCreator extends 
AbstractIndexCreator {
      * @return the CRC-32 of its UTF-8 representation, as big-endian Base-32 
without padding (so seven chars), lower case (to not confuse maven-indexer)
      */
     static String crc32base32(String s) {
-        crc.reset();
+        CRC32 crc = new CRC32();
         crc.update(s.getBytes(StandardCharsets.UTF_8));
         long v = crc.getValue();
         byte[] b32 = base32.encode(new byte[] {(byte) (v >> 24 & 0xFF), (byte) 
(v >> 16 & 0xFF), (byte) (v >> 8 & 0xFF), (byte) (v & 0xFF)});
@@ -386,7 +384,6 @@ class ClassDependencyIndexCreator extends 
AbstractIndexCreator {
         return new String(b32, 0, 7, 
StandardCharsets.ISO_8859_1).toLowerCase();
     }
 
-    private static final CRC32 crc = new CRC32();
     private static final Base32 base32 = new Base32();
 
 }
diff --git 
a/java/maven.indexer/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImpl.java
 
b/java/maven.indexer/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImpl.java
index a603cefb68..2402b12e48 100644
--- 
a/java/maven.indexer/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImpl.java
+++ 
b/java/maven.indexer/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImpl.java
@@ -69,6 +69,7 @@ import 
org.apache.maven.index.creator.MavenPluginArtifactInfoIndexCreator;
 import org.apache.maven.index.creator.MinimalArtifactInfoIndexCreator;
 import org.apache.maven.index.expr.StringSearchExpression;
 import org.apache.maven.index.updater.IndexUpdateRequest;
+import org.apache.maven.index.updater.IndexUpdateResult;
 import org.apache.maven.index.updater.IndexUpdater;
 import org.apache.maven.index.updater.ResourceFetcher;
 import org.apache.maven.search.SearchRequest;
@@ -134,6 +135,7 @@ 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;
+
 import static 
org.apache.maven.index.creator.MinimalArtifactInfoIndexCreator.FLD_LAST_MODIFIED;
 
 
@@ -230,18 +232,13 @@ public class NexusRepositoryIndexerImpl implements 
RepositoryIndexerImplementati
         return this;
     }
     
-    private Mutex getRepoMutex(RepositoryInfo repo) {
+    private static Mutex getRepoMutex(RepositoryInfo repo) {
         return getRepoMutex(repo.getId());
     }
     
-    private Mutex getRepoMutex(String repoId) {
+    private static Mutex getRepoMutex(String repoId) {
         synchronized (repoMutexMap) {
-            Mutex m = repoMutexMap.get(repoId);
-            if (m == null) {
-                m = new Mutex();
-                repoMutexMap.put(repoId, m);
-            }
-            return m;
+            return repoMutexMap.computeIfAbsent(repoId, k -> new Mutex());
         }
     }
     
@@ -309,28 +306,13 @@ public class NexusRepositoryIndexerImpl implements 
RepositoryIndexerImplementati
                 /* indexers */ indexers);
 
         // The allGroups and rootGroups properties of the IndexingContext are
-        // not persistent anymore, so need to be save outside the context
-        boolean needGroupCacheRebuild = false;
+        // not persistent anymore, so need to be saved outside the context
         try {
             
context.setAllGroups(Files.readAllLines(getAllGroupCacheFile(repo)));
-        } catch (IOException ex) {
-            needGroupCacheRebuild = true;
-        }
-        try {
             
context.setRootGroups(Files.readAllLines(getRootGroupCacheFile(repo)));
         } catch (IOException ex) {
-            needGroupCacheRebuild = true;
-        }
-        // At least one of the group caches could not be loaded, so rebuild it
-        if(needGroupCacheRebuild) {
-            RP_LOCAL.submit(() -> {
-                try {
-                    context.rebuildGroups();
-                    storeGroupCache(repo, context);
-                } catch (IOException ex) {
-                    LOGGER.log(Level.WARNING, "Failed to store group caches 
for repo: " + repo.getId(), ex);
-                }
-            });
+            // At least one of the group caches could not be loaded, so 
rebuild it
+            rebuildGroupCache(repo, context);
         }
         indexingContexts.put(context.getId(), context);
         return context;
@@ -503,6 +485,7 @@ public class NexusRepositoryIndexerImpl implements 
RepositoryIndexerImplementati
         }
         boolean fetchFailed = false;
         long t = System.currentTimeMillis();
+        IndexUpdateResult fetchUpdateResult = null;
         RemoteIndexTransferListener listener = null;
         try {
             IndexingContext indexingContext = 
getIndexingContexts().get(repo.getId());
@@ -583,9 +566,8 @@ public class NexusRepositoryIndexerImpl implements 
RepositoryIndexerImplementati
                         nic.start(listener);
                     }
                     try {
-                        Files.deleteIfExists(getAllGroupCacheFile(repo));
-                        Files.deleteIfExists(getRootGroupCacheFile(repo));
-                        remoteIndexUpdater.fetchAndUpdateIndex(iur);
+                        removeGroupCache(repo);
+                        fetchUpdateResult = 
remoteIndexUpdater.fetchAndUpdateIndex(iur);
                         storeGroupCache(repo, indexingContext);
                     } catch (IOException | AlreadyClosedException | 
IllegalArgumentException ex) {
                         // AlreadyClosedException can happen in low storage 
situations when lucene is trying to handle IOEs
@@ -595,6 +577,7 @@ public class NexusRepositoryIndexerImpl implements 
RepositoryIndexerImplementati
                     } catch (RuntimeException ex) {
                         // thread pools, like the one used in maven-indexer's 
IndexDataReader, may suppress cancellation exceptions
                         // lets try to find them again
+                        fetchFailed = true;
                         if (isCancellation(ex)) {
                             Cancellation cancellation = new Cancellation();
                             cancellation.addSuppressed(ex);
@@ -625,8 +608,7 @@ public class NexusRepositoryIndexerImpl implements 
RepositoryIndexerImplementati
                     RepositoryIndexerListener repoListener = new 
RepositoryIndexerListener(indexingContext);
                     try {
                         // Ensure no stale cache files are left
-                        Files.deleteIfExists(getAllGroupCacheFile(repo));
-                        Files.deleteIfExists(getRootGroupCacheFile(repo));
+                        removeGroupCache(repo);
                         scan(indexingContext, null, repoListener, updateLocal);
                         storeGroupCache(repo, indexingContext);
                     } finally {
@@ -667,7 +649,13 @@ public class NexusRepositoryIndexerImpl implements 
RepositoryIndexerImplementati
         } catch (ComponentLookupException x) {
             throw new IOException("could not find protocol handler for " + 
repo.getRepositoryUrl(), x);
         } finally {
-            LOGGER.log(Level.INFO, "Indexing of {0} took {1}s.", new 
Object[]{repo.getId(), String.format("%.2f", (System.currentTimeMillis() - 
t)/1000.0f)});
+            String kind;
+            if (fetchUpdateResult != null) {
+                kind = fetchUpdateResult.isFullUpdate() ? "download, create" : 
"incremental download, update";
+            } else {
+                kind = "scan";
+            }
+            LOGGER.log(Level.INFO, "Indexing [{0}] of {1} took {2}s.", new 
Object[]{kind, repo.getId(), String.format("%.2f", (System.currentTimeMillis() 
- t)/1000.0f)});
             synchronized (indexingMutexes) {
                 indexingMutexes.remove(mutex);
             }
@@ -820,7 +808,7 @@ public class NexusRepositoryIndexerImpl implements 
RepositoryIndexerImplementati
         if (!tmpDir.mkdirs()) {
             throw new IOException( "Cannot create temporary directory: " + 
tmpDir );
         }
-        File tmpFile = new File(tmpDir, context.getId() + "-tmp");
+        File tmpFile = new File(tmpDir, context.getId() + "-tmp"); // TODO: 
purpose of file?
  
         IndexingContext tmpContext = null;
         try {
@@ -1811,23 +1799,49 @@ public class NexusRepositoryIndexerImpl implements 
RepositoryIndexerImplementati
         return getIndexDirectory(info).resolve(GROUP_CACHE_ROOT_PREFIX + "." + 
GROUP_CACHE_ROOT_SUFFIX);
     }
 
-    private void storeGroupCache(RepositoryInfo repoInfo, IndexingContext ic) 
throws IOException {
-
-        Path indexDir = getIndexDirectory(repoInfo);
+    private static void storeGroupCache(RepositoryInfo repo, IndexingContext 
context) throws IOException {
+        Path indexDir = getIndexDirectory(repo);
         Path tempAllCache = Files.createTempFile(indexDir, 
GROUP_CACHE_ALL_PREFIX, GROUP_CACHE_ALL_SUFFIX);
         Path tempRootCache = Files.createTempFile(indexDir, 
GROUP_CACHE_ROOT_PREFIX, GROUP_CACHE_ROOT_SUFFIX);
         try {
-            Files.write(tempAllCache, ic.getAllGroups());
-            Files.move(tempAllCache, getAllGroupCacheFile(repoInfo), 
StandardCopyOption.REPLACE_EXISTING);
+            Files.write(tempAllCache, context.getAllGroups());
+            Files.move(tempAllCache, getAllGroupCacheFile(repo), 
StandardCopyOption.REPLACE_EXISTING);
 
-            Files.write(tempRootCache, ic.getRootGroups());
-            Files.move(tempRootCache, getRootGroupCacheFile(repoInfo), 
StandardCopyOption.REPLACE_EXISTING);
+            Files.write(tempRootCache, context.getRootGroups());
+            Files.move(tempRootCache, getRootGroupCacheFile(repo), 
StandardCopyOption.REPLACE_EXISTING);
         } finally {
             Files.deleteIfExists(tempAllCache);
             Files.deleteIfExists(tempRootCache);
         }
     }
 
+    private static void removeGroupCache(RepositoryInfo repo) throws 
IOException {
+        Files.deleteIfExists(getAllGroupCacheFile(repo));
+        Files.deleteIfExists(getRootGroupCacheFile(repo));
+    }
+
+    private static void rebuildGroupCache(RepositoryInfo repo, IndexingContext 
context) throws IOException {
+        removeGroupCache(repo);
+        (repo.isLocal() ? RP_LOCAL : RP_REMOTE).submit(() -> {
+            getRepoMutex(repo).writeAccess(() -> {
+                Path allGroupsPath = getAllGroupCacheFile(repo);
+                Path rootGroupsPath = getRootGroupCacheFile(repo);
+                if (Files.exists(allGroupsPath) && 
Files.exists(rootGroupsPath)) {
+                    return; // already rebuilt
+                }
+                try {
+                    LOGGER.log(Level.FINE, "Rebuilding group cache for {0}", 
repo.getId());
+                    long start = System.currentTimeMillis();
+                    context.rebuildGroups();
+                    storeGroupCache(repo, context);
+                    LOGGER.log(Level.INFO, "Group cache rebuilding of {0} took 
{1}s.", new Object[] {repo.getId(), (System.currentTimeMillis()-start)});
+                } catch (IOException e) {
+                    LOGGER.log(Level.WARNING, "Failed to rebuild groups for 
repo: " + repo.getId(), e);
+                }
+            });
+        });
+    }
+
     // somewhat based on maven-indexer impl (in WagonHelper) prior to removal 
in maven-indexer 7.0.0
     private static class WagonFetcher implements ResourceFetcher {
 
diff --git 
a/java/maven.indexer/src/org/netbeans/modules/maven/indexer/api/NBArtifactInfo.java
 
b/java/maven.indexer/src/org/netbeans/modules/maven/indexer/api/NBArtifactInfo.java
index ebc9e40f22..3f63663f7d 100644
--- 
a/java/maven.indexer/src/org/netbeans/modules/maven/indexer/api/NBArtifactInfo.java
+++ 
b/java/maven.indexer/src/org/netbeans/modules/maven/indexer/api/NBArtifactInfo.java
@@ -40,6 +40,7 @@ public class NBArtifactInfo {
         this.name = name;
     }
 
+    @SuppressWarnings("element-type-mismatch")
     public boolean removeVersionInfo(Object o) {
         return versionInfos.remove(o);
     }
diff --git 
a/java/maven.indexer/src/org/netbeans/modules/maven/indexer/api/NBGroupInfo.java
 
b/java/maven.indexer/src/org/netbeans/modules/maven/indexer/api/NBGroupInfo.java
index 8912a61d7b..ab8b179741 100644
--- 
a/java/maven.indexer/src/org/netbeans/modules/maven/indexer/api/NBGroupInfo.java
+++ 
b/java/maven.indexer/src/org/netbeans/modules/maven/indexer/api/NBGroupInfo.java
@@ -39,6 +39,7 @@ public class NBGroupInfo {
         this.name = name;
     }
 
+    @SuppressWarnings("element-type-mismatch")
     public void removeArtifactInfo(Object o) {
          artifactInfos.remove(o);
     }
diff --git 
a/java/maven.indexer/src/org/netbeans/modules/maven/indexer/api/RepositoryUtil.java
 
b/java/maven.indexer/src/org/netbeans/modules/maven/indexer/api/RepositoryUtil.java
index 6ad907f3c1..2eb247e179 100644
--- 
a/java/maven.indexer/src/org/netbeans/modules/maven/indexer/api/RepositoryUtil.java
+++ 
b/java/maven.indexer/src/org/netbeans/modules/maven/indexer/api/RepositoryUtil.java
@@ -22,13 +22,11 @@
 package org.netbeans.modules.maven.indexer.api;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.math.BigInteger;
+import java.nio.file.Files;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
-import java.util.Collections;
 import java.util.List;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -93,40 +91,26 @@ public final class RepositoryUtil {
         List<ArtifactRepository> remotes;
         RepositoryInfo repo = 
RepositoryPreferences.getInstance().getRepositoryInfoById(info.getRepoId());
         if (repo != null && repo.isRemoteDownloadable()) {
-            remotes = 
Collections.singletonList(online.createRemoteRepository(repo.getRepositoryUrl(),
 repo.getId()));
+            remotes = 
List.of(online.createRemoteRepository(repo.getRepositoryUrl(), repo.getId()));
         } else {
-            remotes = 
Collections.singletonList(online.createRemoteRepository(RepositorySystem.DEFAULT_REMOTE_REPO_URL,
 RepositorySystem.DEFAULT_REMOTE_REPO_ID));
+            remotes = 
List.of(online.createRemoteRepository(RepositorySystem.DEFAULT_REMOTE_REPO_URL, 
RepositorySystem.DEFAULT_REMOTE_REPO_ID));
         }
         online.resolve(a, remotes, online.getLocalRepository());
         return a.getFile();
     }
     
     public static String calculateSHA1Checksum(File file) throws IOException {
-        byte[] buffer = readFile(file);
+        if (!file.exists() || !file.isFile()) {
+            throw new IOException("file '"+file+"' does not exist or is not a 
valid file");
+        }
         MessageDigest digest;
         try {
             digest = MessageDigest.getInstance("SHA-1");
         } catch (NoSuchAlgorithmException x) {
             throw new IOException(x);
         }
-        digest.update(buffer);
+        digest.update(Files.readAllBytes(file.toPath()));
         return String.format("%040x", new BigInteger(1, digest.digest()));
     }
 
-    private static byte[] readFile(File file) throws IOException {
-
-        byte[] bytes = new byte[(int) file.length()];
-        try (InputStream is = new FileInputStream(file)) {
-
-            int offset = 0;
-            int numRead = 0;
-
-            while (offset < bytes.length && (numRead = is.read(bytes, offset, 
bytes.length - offset)) != -1) {
-                offset += numRead;
-            }
-        }
-
-        return bytes;
-    }
-
 }
diff --git 
a/java/maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/ClassDependencyIndexCreatorTest.java
 
b/java/maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/ClassDependencyIndexCreatorTest.java
index 3e029a602e..83c3f102e9 100644
--- 
a/java/maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/ClassDependencyIndexCreatorTest.java
+++ 
b/java/maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/ClassDependencyIndexCreatorTest.java
@@ -23,7 +23,6 @@ import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.InputStream;
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -86,7 +85,7 @@ public class ClassDependencyIndexCreatorTest extends 
NexusTestBase {
 
         // repo set up, now index and query:
         nrii.indexRepo(info);
-        List<RepositoryInfo> repo = Collections.singletonList(info);
+        List<RepositoryInfo> repo = List.of(info);
 
         List<ClassUsage> list = nrii.findClassUsages("mod1.API", 
repo).getResults();
         assertEquals("[test:mod2:0:test[mod2.Client, mod2.OtherClient], 
test:mod3:0:test[mod3.Client]]", list.toString());
@@ -128,7 +127,7 @@ public class ClassDependencyIndexCreatorTest extends 
NexusTestBase {
         install(mod2v2, "test", "mod2", "43", "jar");
 
         nrii.indexRepo(info);
-        List<RepositoryInfo> repo = Collections.singletonList(info);
+        List<RepositoryInfo> repo = List.of(info);
 
         // single version
         List<NBVersionInfo> list = nrii.findVersionsByClass("mod1.API", 
repo).getResults();
diff --git 
a/java/maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImplTest.java
 
b/java/maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImplTest.java
index b704c9898c..536091b321 100644
--- 
a/java/maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImplTest.java
+++ 
b/java/maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImplTest.java
@@ -20,7 +20,6 @@
 package org.netbeans.modules.maven.indexer;
 
 import java.io.File;
-import java.util.Collections;
 import java.util.List;
 import org.apache.maven.index.ArtifactInfo;
 import org.netbeans.junit.MockServices;
@@ -43,7 +42,7 @@ public class NexusRepositoryIndexerImplTest extends 
NexusTestBase {
         install(File.createTempFile("whatever", ".txt", getWorkDir()), "test", 
"spin", "1.1", "txt");
         nrii.indexRepo(info);
         // RepositoryQueries should handle the query via our 
NexusRepositoryIndexerImpl
-        RepositoryQueries.Result<String> res = 
RepositoryQueries.getArtifactsResult("test", Collections.singletonList(info));  
      
+        RepositoryQueries.Result<String> res = 
RepositoryQueries.getArtifactsResult("test", List.of(info));
         assertEquals("[spin]", res.getResults().toString());
     }
 
@@ -56,7 +55,7 @@ public class NexusRepositoryIndexerImplTest extends 
NexusTestBase {
         qf.setValue("stuff");
         qf.setOccur(QueryField.OCCUR_MUST);
         qf.setMatch(QueryField.MATCH_EXACT);
-        assertEquals("[test:plugin:0:test]", 
nrii.find(Collections.singletonList(qf), 
Collections.singletonList(info)).getResults().toString());
+        assertEquals("[test:plugin:0:test]", nrii.find(List.of(qf), 
List.of(info)).getResults().toString());
     }
 
     public void testLastUpdated() throws Exception { // #197670
@@ -66,7 +65,7 @@ public class NexusRepositoryIndexerImplTest extends 
NexusTestBase {
         install(empty, "test", "art", "0", "pom.lastUpdated");
         install(empty, "test", "art", "0", "jar.lastUpdated");
         nrii.indexRepo(info);
-        List<NBVersionInfo> versions = nrii.getVersions("test", "art", 
Collections.singletonList(info)).getResults();
+        List<NBVersionInfo> versions = nrii.getVersions("test", "art", 
List.of(info)).getResults();
         assertEquals(1, versions.size());
         NBVersionInfo v = versions.get(0);
         assertEquals("test:art:0:test", v.toString());
diff --git 
a/java/maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/api/RepositoryQueriesTest.java
 
b/java/maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/api/RepositoryQueriesTest.java
index 23405e1383..6fd97331a5 100644
--- 
a/java/maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/api/RepositoryQueriesTest.java
+++ 
b/java/maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/api/RepositoryQueriesTest.java
@@ -42,11 +42,7 @@ public class RepositoryQueriesTest extends NbTestCase {
     protected void setUp() throws Exception {
         super.setUp();
     }
-    
-    public void testAlternativeQueryProvider() throws URISyntaxException {
-        
-    }
-    
+
     public void testAlternativeResult() throws URISyntaxException {
         MockServices.setServices(TestIndexer1.class);
         
@@ -59,7 +55,7 @@ public class RepositoryQueriesTest extends NbTestCase {
     public void testTwoReposTwoQueryProviders() throws URISyntaxException {
         MockServices.setServices(TestIndexer1.class, TestIndexer2.class);
 
-        RepositoryQueries.Result<NBVersionInfo> result = 
RepositoryQueries.findArchetypesResult(Arrays.asList(TestIndexer1.REPO, 
TestIndexer2.REPO));
+        RepositoryQueries.Result<NBVersionInfo> result = 
RepositoryQueries.findArchetypesResult(List.of(TestIndexer1.REPO, 
TestIndexer2.REPO));
         assertEquals(2, result.getTotalResultCount());
         assertEquals(2, result.getReturnedResultCount());
         assertArtefactIds(result.getResults(), new String[] {TestIndexer1.ID, 
TestIndexer2.ID});
@@ -68,7 +64,7 @@ public class RepositoryQueriesTest extends NbTestCase {
     public void testTwoReposOneAccepted() throws URISyntaxException {
         MockServices.setServices(TestIndexer1.class);
         
-        RepositoryQueries.Result<NBVersionInfo> result = 
RepositoryQueries.findArchetypesResult(Arrays.asList(TestIndexer1.REPO, 
TestIndexer2.REPO));
+        RepositoryQueries.Result<NBVersionInfo> result = 
RepositoryQueries.findArchetypesResult(List.of(TestIndexer1.REPO, 
TestIndexer2.REPO));
         assertEquals(1, result.getTotalResultCount());
         assertEquals(1, result.getReturnedResultCount());
         assertArtefactIds(result.getResults(), new String[] {TestIndexer1.ID});


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Reply via email to