Skip to content

Commit

Permalink
Ignore automatically module-info.class when maxJdkVersion < 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlatombe committed Mar 20, 2019
1 parent a48e0cf commit 31350a9
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals = enforcer:enforce
invoker.buildResult = success
48 changes: 48 additions & 0 deletions src/it/enforce-bytecode-version-module-info-jdk8/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>pim.pam.poum</groupId>
<artifactId>smoking</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>@enforcerPluginVersion@</version>
<dependencies>
<dependency>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
</dependency>
</dependencies>
<configuration>
<rules>
<enforceBytecodeVersion>
<maxJdkVersion>1.8</maxJdkVersion>
</enforceBytecodeVersion>
</rules>
</configuration>
<executions>
<execution>
<phase>compile</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.0</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
File file = new File( basedir, "build.log" );
assert file.exists();

String text = file.getText("utf-8");

assert text.contains( '[INFO] Adding ignore: module-info' )
assert text.contains( '[DEBUG] Ignore: module-info maps to regex ^module-info(\\.class)?$' )

return true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals = enforcer:enforce
invoker.buildResult = success
48 changes: 48 additions & 0 deletions src/it/enforce-bytecode-version-module-info-jdk9/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>pim.pam.poum</groupId>
<artifactId>smoking</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>@enforcerPluginVersion@</version>
<dependencies>
<dependency>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
</dependency>
</dependencies>
<configuration>
<rules>
<enforceBytecodeVersion>
<maxJdkVersion>1.9</maxJdkVersion>
</enforceBytecodeVersion>
</rules>
</configuration>
<executions>
<execution>
<phase>compile</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.0</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
File file = new File( basedir, "build.log" );
assert file.exists();

String text = file.getText("utf-8");

assert ! text.contains( '[INFO] Adding ignore: module-info' )

return true;
35 changes: 0 additions & 35 deletions src/it/enforce-bytecode-version-multirelease/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,40 +44,5 @@
<version>2.9.0</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.glassfish.hk2.external</groupId>
<artifactId>asm-all-repackaged</artifactId>
<version>2.5.0-b32</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-util</artifactId>
<version>6.0</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-tree</artifactId>
<version>6.0</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.0</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-analysis</artifactId>
<version>6.0</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
1 change: 1 addition & 0 deletions src/it/enforce-bytecode-version-multirelease/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ assert file.exists();

String text = file.getText("utf-8");

assert text.contains( '[INFO] Adding ignore: module-info' )
assert text.contains( '[DEBUG] log4j-api-2.9.0.jar => ' )

return true;
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ public class EnforceBytecodeVersion
extends AbstractResolveDependencies
{
private static final Map<String, Integer> JDK_TO_MAJOR_VERSION_NUMBER_MAPPING = new LinkedHashMap<String, Integer>();

/**
* Default ignores when validating against jdk < 9 because <code>module-info.class</code> will always have level 1.9.
*/
private static final String[] DEFAULT_CLASSES_IGNORE_BEFORE_JDK_9 = {"module-info"};

private final Pattern MULTIRELEASE = Pattern.compile( "META-INF/versions/(\\d+)/.*" );
private final String MODULE_INFO_CLASS = "module-info.class";

static
{
Expand Down Expand Up @@ -218,6 +221,12 @@ private void computeParameters()
"\"1.7\", \"8\", \"11\", \"12\"" );
}
maxJavaMajorVersionNumber = needle;
if ( needle < 53 )
{
IgnorableDependency ignoreModuleInfoDependency = new IgnorableDependency();
ignoreModuleInfoDependency.applyIgnoreClasses(DEFAULT_CLASSES_IGNORE_BEFORE_JDK_9, false );
ignorableDependencies.add( ignoreModuleInfoDependency );
}
}
if ( maxJavaMajorVersionNumber == -1 )
{
Expand Down Expand Up @@ -322,18 +331,14 @@ private String isBadArtifact( Artifact a )

Matcher matcher = MULTIRELEASE.matcher( entry.getName() );

if ( MODULE_INFO_CLASS.equals( entry.getName() ) ) {
getLog().warn( "Invalid bytecodeVersion for " + entry.getName() + ": expected "
+ maxJavaMajorVersionNumber + ", but was " + major);
}
else if ( matcher.matches() )
if ( matcher.matches() )
{
int expectedMajor = JDK_TO_MAJOR_VERSION_NUMBER_MAPPING.get( matcher.group( 1 ) );

if ( major != expectedMajor )
{
getLog().warn( "Invalid bytecodeVersion for " + entry.getName() + ": expected "
+ expectedMajor + ", but was " + major );
getLog().warn( "Invalid bytecodeVersion for " + a + " : "
+ entry.getName() + ": expected " + expectedMajor + ", but was " + major );
}
}
else
Expand Down

0 comments on commit 31350a9

Please sign in to comment.