From 5e34af0d191344cd55e09098f7898648a9a1d5cb Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Mon, 18 Mar 2019 19:04:06 -0400 Subject: [PATCH] Report artifact info When an error occurs, this information is provided by handleArtifacts. For warnings, the only information is the information provided by the getLog().warn() call itself. Without this change, the following output is common: [INFO] --- maven-enforcer-plugin:3.0.0-M2:enforce (display-info) @ acceptance-test-harness --- [WARNING] Invalid bytecodeVersion for module-info.class: expected 52, but was 53 [WARNING] Invalid bytecodeVersion for module-info.class: expected 52, but was 53 [WARNING] Invalid bytecodeVersion for module-info.class: expected 52, but was 53 [WARNING] Invalid bytecodeVersion for module-info.class: expected 52, but was 53 [WARNING] Invalid bytecodeVersion for module-info.class: expected 52, but was 53 [WARNING] Invalid bytecodeVersion for module-info.class: expected 52, but was 53 [WARNING] Invalid bytecodeVersion for module-info.class: expected 52, but was 53 --- .../maven/plugins/enforcer/EnforceBytecodeVersion.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/enforcer/EnforceBytecodeVersion.java b/src/main/java/org/apache/maven/plugins/enforcer/EnforceBytecodeVersion.java index bed2c810..1ba1a497 100644 --- a/src/main/java/org/apache/maven/plugins/enforcer/EnforceBytecodeVersion.java +++ b/src/main/java/org/apache/maven/plugins/enforcer/EnforceBytecodeVersion.java @@ -299,6 +299,8 @@ private String isBadArtifact( Artifact a ) jarFile = new JarFile( f ); getLog().debug( f.getName() + " => " + f.getPath() ); byte[] magicAndClassFileVersion = new byte[8]; + StringBuilder artifactInfo = new StringBuilder(); + artifactInfo.append( "(" ).append( a.getGroupId() ).append( ":" ).append( a.getArtifactId() ).append( ") " ); JAR: for ( Enumeration e = jarFile.entries(); e.hasMoreElements(); ) { JarEntry entry = e.nextElement(); @@ -351,7 +353,7 @@ private String isBadArtifact( Artifact a ) if ( MODULE_INFO_CLASS.equals( entry.getName() ) ) { if ( major > maxJavaMajorVersionNumber ) { - getLog().warn("Invalid bytecodeVersion for " + MODULE_INFO_CLASS + ": expected " + getLog().warn( artifactInfo + "Invalid bytecodeVersion for " + MODULE_INFO_CLASS + ": expected " + maxJavaMajorVersionNumber + ", but was " + major); } } @@ -365,8 +367,8 @@ else if ( matcher.matches() ) } else if ( major != expectedMajor ) { - getLog().warn( "Invalid bytecodeVersion for " + a + " : " - + entry.getName() + ": expected " + expectedMajor + ", but was " + major ); + getLog().warn( artifactInfo + "Invalid bytecodeVersion for " + entry.getName() + ": expected " + + expectedMajor + ", but was " + major ); } } else