This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-project-info-reports-plugin.git
commit 2e63a88b2edc14f5910f40a07606198dc81d7aff Author: Sylwester Lachiewicz <[email protected]> AuthorDate: Thu Nov 26 07:52:29 2026 +0000 Assert debug information in the dependency file details --- .../renderer/DependenciesRendererTest.java | 48 ++++++++++++++++++++++ .../dependencies/renderer/JarFixtures.java | 43 ++++++++++++++++--- 2 files changed, 86 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRendererTest.java b/src/test/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRendererTest.java index ef953e7..de71942 100644 --- a/src/test/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRendererTest.java +++ b/src/test/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRendererTest.java @@ -267,6 +267,50 @@ class DependenciesRendererTest { } } + /** + * The debug information cell says "Yes" for a jar whose classes have line numbers, "No" for one without, and the + * summary counts the jars that have it, per scope. + */ + @Test + void debugInformationIsReportedPerJarAndCountedInTheSummary() throws Exception { + Artifact withDebug = + artifact("compile", "with-debug", jar("with-debug.jar", 2_000, debugClass("p/WithDebug", 52))); + Artifact withoutDebug = + artifact("compile", "without-debug", jar("without-debug.jar", 2_000, clazz("p/Plain", 52))); + + String html = render(true, withDebug, withoutDebug); + + assertRows( + html, + row( + left("with-debug.jar"), + right("2 kB"), + right("2"), + right("1"), + right("1"), + center("1.8"), + center("Yes")), + row( + left("without-debug.jar"), + right("2 kB"), + right("2"), + right("1"), + right("1"), + center("1.8"), + center("No"))); + assertRows( + html, + row(right("2"), right("4 kB"), right("4"), right("2"), right("2"), center("1.8"), right("1")), + row( + right("compile: 2"), + right("compile: 4 kB"), + right("compile: 4"), + right("compile: 2"), + right("compile: 2"), + center("1.8"), + right("compile: 1"))); + } + /** * MPIR-407: a license name that has a mapping is shown under the mapped name in the dependency tables, the * dependency details and the license listing; one without a mapping is left alone. @@ -316,6 +360,10 @@ class DependenciesRendererTest { return artifact; } + private static Entry debugClass(String internalName, int major) throws Exception { + return Entry.classFileWithDebugInfo(internalName + ".class", internalName, major); + } + private static Entry clazz(String internalName, int major) throws Exception { return Entry.classFile(internalName + ".class", internalName, major); } diff --git a/src/test/java/org/apache/maven/report/projectinfo/dependencies/renderer/JarFixtures.java b/src/test/java/org/apache/maven/report/projectinfo/dependencies/renderer/JarFixtures.java index 4b1a700..ed5aa4b 100644 --- a/src/test/java/org/apache/maven/report/projectinfo/dependencies/renderer/JarFixtures.java +++ b/src/test/java/org/apache/maven/report/projectinfo/dependencies/renderer/JarFixtures.java @@ -46,12 +46,17 @@ final class JarFixtures { /** A class file; {@code internalName} is e.g. {@code p/Foo}, {@code major} 52 is Java 8. */ static Entry classFile(String path, String internalName, int major) throws IOException { - return new Entry(path, classBytes(internalName, major, false)); + return new Entry(path, classBytes(internalName, major, false, false)); + } + + /** A class file whose one method has a line number table, which the jar analysis reports as debug information. */ + static Entry classFileWithDebugInfo(String path, String internalName, int major) throws IOException { + return new Entry(path, classBytes(internalName, major, false, true)); } /** A {@code module-info.class}. */ static Entry moduleInfo(String path, int major) throws IOException { - return new Entry(path, classBytes("module-info", major, true)); + return new Entry(path, classBytes("module-info", major, true, false)); } static Entry manifest(String... lines) { @@ -109,7 +114,7 @@ final class JarFixtures { } /** The smallest valid class file: no fields, no methods, only a name and {@code java/lang/Object}. */ - private static byte[] classBytes(String internalName, int major, boolean module) throws IOException { + private static byte[] classBytes(String internalName, int major, boolean module, boolean debug) throws IOException { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(bytes); out.writeInt(0xCAFEBABE); @@ -147,7 +152,8 @@ final class JarFixtures { out.writeShort(0); // provides } else { // 1 Utf8 name, 2 Class, 3 Utf8 java/lang/Object, 4 Class - out.writeShort(5); + // with debug information: 5 Utf8 m, 6 Utf8 ()V, 7 Utf8 Code, 8 Utf8 LineNumberTable + out.writeShort(debug ? 9 : 5); out.writeByte(1); out.writeUTF(internalName); out.writeByte(7); @@ -156,12 +162,39 @@ final class JarFixtures { out.writeUTF("java/lang/Object"); out.writeByte(7); out.writeShort(3); + if (debug) { + for (String utf8 : new String[] {"m", "()V", "Code", "LineNumberTable"}) { + out.writeByte(1); + out.writeUTF(utf8); + } + } out.writeShort(0x0021); // public super out.writeShort(2); // this_class out.writeShort(4); // super_class out.writeShort(0); // interfaces out.writeShort(0); // fields - out.writeShort(0); // methods + if (debug) { + out.writeShort(1); // methods + out.writeShort(0x0009); // public static + out.writeShort(5); // name + out.writeShort(6); // descriptor + out.writeShort(1); // attributes: Code + out.writeShort(7); + out.writeInt(25); + out.writeShort(0); // max_stack + out.writeShort(0); // max_locals + out.writeInt(1); // code_length + out.writeByte(0xB1); // return + out.writeShort(0); // exception table + out.writeShort(1); // attributes: LineNumberTable + out.writeShort(8); + out.writeInt(6); + out.writeShort(1); // one entry + out.writeShort(0); // start_pc + out.writeShort(1); // line_number + } else { + out.writeShort(0); // methods + } out.writeShort(0); // attributes } out.flush();
