You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2026/09/25 22:44:48 UTC
(maven-indexer) branch agent/mindexer-668-reader-classnames created (now 20bc0a4)
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a change to branch agent/mindexer-668-reader-classnames
in repository https://gitbox.apache.org/repos/asf/maven-indexer.git
at 20bc0a4 Read class names from the field indexer-core writes
This branch includes the following new commits:
new 20bc0a4 Read class names from the field indexer-core writes
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(maven-indexer) 01/01: Read class names from the field indexer-core writes
Posted by sl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch agent/mindexer-668-reader-classnames
in repository https://gitbox.apache.org/repos/asf/maven-indexer.git
commit 20bc0a462956ba63ef29e2a78c4aa9db581c61d0
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Sat Sep 26 00:44:42 2026 +0200
Read class names from the field indexer-core writes
indexer-core stores class names only in field "c", one per line; "classnames"
is indexed but never stored, so it never reaches an index file. Keep reading
"classnames" as a fallback for indexes written by older indexer-reader.
Fixes #668
---
.../apache/maven/index/reader/RecordCompactor.java | 6 +-
.../apache/maven/index/reader/RecordExpander.java | 8 ++-
.../apache/maven/index/reader/ClassNamesTest.java | 76 ++++++++++++++++++++++
3 files changed, 88 insertions(+), 2 deletions(-)
diff --git a/indexer-reader/src/main/java/org/apache/maven/index/reader/RecordCompactor.java b/indexer-reader/src/main/java/org/apache/maven/index/reader/RecordCompactor.java
index 012eec4..c5325d7 100644
--- a/indexer-reader/src/main/java/org/apache/maven/index/reader/RecordCompactor.java
+++ b/indexer-reader/src/main/java/org/apache/maven/index/reader/RecordCompactor.java
@@ -114,7 +114,11 @@ public class RecordCompactor implements Function<Record, Map<String, String>> {
putIfNotNull(record.getString(Record.SHA1), result, "1");
// Jar file contents (optional)
- putIfNotNullAsStringArray(record.getStringArray(Record.CLASSNAMES), result, "classnames");
+ String[] classNames = record.getStringArray(Record.CLASSNAMES);
+ if (classNames != null && classNames.length > 0) {
+ // same field and format as indexer-core JarFileContentsIndexCreator: "c", one class name per line
+ result.put("c", String.join("\n", classNames));
+ }
// Maven Plugin (optional)
putIfNotNull(record.getString(Record.PLUGIN_PREFIX), result, "px");
diff --git a/indexer-reader/src/main/java/org/apache/maven/index/reader/RecordExpander.java b/indexer-reader/src/main/java/org/apache/maven/index/reader/RecordExpander.java
index ebe9a96..bdeebb9 100644
--- a/indexer-reader/src/main/java/org/apache/maven/index/reader/RecordExpander.java
+++ b/indexer-reader/src/main/java/org/apache/maven/index/reader/RecordExpander.java
@@ -133,7 +133,13 @@ public class RecordExpander implements Function<Map<String, String>, Record> {
putIfNotNull(raw, "1", result, Record.SHA1);
// Jar file contents (optional)
- putIfNotNullAsStringArray(raw, "classnames", result, Record.CLASSNAMES);
+ // indexer-core stores class names as "c", one per line; "classnames" was written by older indexer-reader
+ String classNames = raw.get("c");
+ if (classNames != null && !classNames.isBlank()) {
+ result.put(Record.CLASSNAMES, classNames.trim().split("\n"));
+ } else {
+ putIfNotNullAsStringArray(raw, "classnames", result, Record.CLASSNAMES);
+ }
// Maven Plugin (optional)
putIfNotNull(raw, "px", result, Record.PLUGIN_PREFIX);
diff --git a/indexer-reader/src/test/java/org/apache/maven/index/reader/ClassNamesTest.java b/indexer-reader/src/test/java/org/apache/maven/index/reader/ClassNamesTest.java
new file mode 100644
index 0000000..984d876
--- /dev/null
+++ b/indexer-reader/src/test/java/org/apache/maven/index/reader/ClassNamesTest.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.index.reader;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+/**
+ * Class names are stored by indexer-core JarFileContentsIndexCreator in field "c", one class name per line.
+ */
+public class ClassNamesTest {
+ private static final String[] CLASS_NAMES = {
+ "/com/thoughtworks/qdox/ant/AbstractQdoxTask", "/com/thoughtworks/qdox/directorywalker/DirectoryScanner"
+ };
+
+ private static Map<String, String> artifact() {
+ Map<String, String> raw = new HashMap<>();
+ raw.put("u", "qdox|qdox|1.5|NA|jar");
+ raw.put("i", "jar|1180422566000|154327|0|0|0|jar");
+ return raw;
+ }
+
+ @Test
+ public void expandIndexerCoreClassNames() {
+ Map<String, String> raw = artifact();
+ // as written by indexer-core, including the trailing newline
+ raw.put("c", String.join("\n", CLASS_NAMES) + "\n");
+
+ Record record = new RecordExpander().apply(raw);
+
+ assertArrayEquals(CLASS_NAMES, record.getStringArray(Record.CLASSNAMES));
+ }
+
+ @Test
+ public void expandLegacyClassNames() {
+ Map<String, String> raw = artifact();
+ raw.put("classnames", String.join("|", CLASS_NAMES));
+
+ Record record = new RecordExpander().apply(raw);
+
+ assertArrayEquals(CLASS_NAMES, record.getStringArray(Record.CLASSNAMES));
+ }
+
+ @Test
+ public void compactWritesIndexerCoreFormat() {
+ Map<String, String> raw = artifact();
+ raw.put("c", String.join("\n", CLASS_NAMES));
+
+ Map<String, String> compacted = new RecordCompactor().apply(new RecordExpander().apply(raw));
+
+ assertEquals(String.join("\n", CLASS_NAMES), compacted.get("c"));
+ assertFalse(compacted.containsKey("classnames"));
+ }
+}