Copilot commented on code in PR #158:
URL: https://github.com/apache/maven-shared-jar/pull/158#discussion_r4082141252
##########
src/main/java/org/apache/maven/shared/jar/identification/exposers/TextFileExposer.java:
##########
@@ -64,13 +64,15 @@ private List<String> findTextFileVersions(JarAnalyzer
jarAnalyzer) {
try (InputStream is = jarAnalyzer.getEntryInputStream(entry)) {
BufferedReader br = new BufferedReader(new
InputStreamReader(is));
- String line = br.readLine();
// TODO: check for key=value pair.
// TODO: maybe even for groupId entries.
- logger.debug(line);
- if (line != null && !line.isEmpty()) {
- textVersions.add(line);
+ String line;
+ while ((line = br.readLine()) != null) {
+ logger.debug(line);
Review Comment:
This logs every line at debug level, which can be noisy and adds overhead
when scanning JARs with large version-like files. Consider guarding with
logger.isDebugEnabled() and/or logging a summary (e.g., number of lines
captured and entry name) instead of the full content.
##########
src/main/java/org/apache/maven/shared/jar/identification/exposers/TextFileExposer.java:
##########
@@ -64,13 +64,15 @@ private List<String> findTextFileVersions(JarAnalyzer
jarAnalyzer) {
try (InputStream is = jarAnalyzer.getEntryInputStream(entry)) {
BufferedReader br = new BufferedReader(new
InputStreamReader(is));
Review Comment:
InputStreamReader is constructed without an explicit charset, so behavior
depends on the platform default encoding. Since version files are typically
UTF-8 (and your new test writes UTF-8), pass an explicit charset (e.g.,
StandardCharsets.UTF_8) to InputStreamReader to avoid mis-decoding on non-UTF-8
platforms.
##########
src/test/java/org/apache/maven/shared/jar/identification/exposers/TextFileExposerTest.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.shared.jar.identification.exposers;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+
+import org.apache.maven.shared.jar.JarAnalyzer;
+import org.apache.maven.shared.jar.identification.JarIdentification;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Test Case for {@link TextFileExposer}.
+ */
+class TextFileExposerTest {
+
+ @Test
+ void readsAllLinesOfVersionFile() throws Exception {
+ File jar = createJarWithVersionFile("META-INF/VERSION",
"1.2.3\nrelease\n");
Review Comment:
These tests hardcode '\\n' line endings. On Windows, consuming code may
encounter '\\r\\n' and the current implementation (BufferedReader.readLine)
will strip both, but the test doesn’t cover that. Consider adding a case using
'\\r\\n' to ensure consistent behavior across line endings.
##########
src/test/java/org/apache/maven/shared/jar/identification/exposers/TextFileExposerTest.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.shared.jar.identification.exposers;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+
+import org.apache.maven.shared.jar.JarAnalyzer;
+import org.apache.maven.shared.jar.identification.JarIdentification;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Test Case for {@link TextFileExposer}.
+ */
+class TextFileExposerTest {
+
+ @Test
+ void readsAllLinesOfVersionFile() throws Exception {
+ File jar = createJarWithVersionFile("META-INF/VERSION",
"1.2.3\nrelease\n");
+
+ JarIdentification identification = new JarIdentification();
+ TextFileExposer exposer = new TextFileExposer();
+ exposer.expose(identification, new JarAnalyzer(jar));
+
+ List<String> versions = identification.getPotentialVersions();
+ assertEquals(Arrays.asList("1.2.3", "release"), versions);
+ }
+
+ @Test
+ void readsAllLinesOfVersionPropertiesFile() throws Exception {
+ File jar = createJarWithVersionFile(
+ "META-INF/version.properties",
"Implementation-Version=2.0.0\nBuild-Number=42\n");
Review Comment:
These tests hardcode '\\n' line endings. On Windows, consuming code may
encounter '\\r\\n' and the current implementation (BufferedReader.readLine)
will strip both, but the test doesn’t cover that. Consider adding a case using
'\\r\\n' to ensure consistent behavior across line endings.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]