Skip to content

Commit 31350a9

Browse files
committed
Ignore automatically module-info.class when maxJdkVersion < 1.9
Context: mojohaus#46, mojohaus#36, mojohaus#75
1 parent a48e0cf commit 31350a9

File tree

9 files changed

+132
-44
lines changed

9 files changed

+132
-44
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
invoker.goals = enforcer:enforce
2+
invoker.buildResult = success
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>pim.pam.poum</groupId>
6+
<artifactId>smoking</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
9+
<build>
10+
<plugins>
11+
<plugin>
12+
<artifactId>maven-enforcer-plugin</artifactId>
13+
<version>@enforcerPluginVersion@</version>
14+
<dependencies>
15+
<dependency>
16+
<groupId>@project.groupId@</groupId>
17+
<artifactId>@project.artifactId@</artifactId>
18+
<version>@project.version@</version>
19+
</dependency>
20+
</dependencies>
21+
<configuration>
22+
<rules>
23+
<enforceBytecodeVersion>
24+
<maxJdkVersion>1.8</maxJdkVersion>
25+
</enforceBytecodeVersion>
26+
</rules>
27+
</configuration>
28+
<executions>
29+
<execution>
30+
<phase>compile</phase>
31+
</execution>
32+
</executions>
33+
</plugin>
34+
</plugins>
35+
</build>
36+
<properties>
37+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
38+
</properties>
39+
40+
<dependencies>
41+
<dependency>
42+
<groupId>org.ow2.asm</groupId>
43+
<artifactId>asm</artifactId>
44+
<version>6.0</version>
45+
<scope>runtime</scope>
46+
</dependency>
47+
</dependencies>
48+
</project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
File file = new File( basedir, "build.log" );
2+
assert file.exists();
3+
4+
String text = file.getText("utf-8");
5+
6+
assert text.contains( '[INFO] Adding ignore: module-info' )
7+
assert text.contains( '[DEBUG] Ignore: module-info maps to regex ^module-info(\\.class)?$' )
8+
9+
return true;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
invoker.goals = enforcer:enforce
2+
invoker.buildResult = success
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>pim.pam.poum</groupId>
6+
<artifactId>smoking</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
9+
<build>
10+
<plugins>
11+
<plugin>
12+
<artifactId>maven-enforcer-plugin</artifactId>
13+
<version>@enforcerPluginVersion@</version>
14+
<dependencies>
15+
<dependency>
16+
<groupId>@project.groupId@</groupId>
17+
<artifactId>@project.artifactId@</artifactId>
18+
<version>@project.version@</version>
19+
</dependency>
20+
</dependencies>
21+
<configuration>
22+
<rules>
23+
<enforceBytecodeVersion>
24+
<maxJdkVersion>1.9</maxJdkVersion>
25+
</enforceBytecodeVersion>
26+
</rules>
27+
</configuration>
28+
<executions>
29+
<execution>
30+
<phase>compile</phase>
31+
</execution>
32+
</executions>
33+
</plugin>
34+
</plugins>
35+
</build>
36+
<properties>
37+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
38+
</properties>
39+
40+
<dependencies>
41+
<dependency>
42+
<groupId>org.ow2.asm</groupId>
43+
<artifactId>asm</artifactId>
44+
<version>6.0</version>
45+
<scope>runtime</scope>
46+
</dependency>
47+
</dependencies>
48+
</project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
File file = new File( basedir, "build.log" );
2+
assert file.exists();
3+
4+
String text = file.getText("utf-8");
5+
6+
assert ! text.contains( '[INFO] Adding ignore: module-info' )
7+
8+
return true;

src/it/enforce-bytecode-version-multirelease/pom.xml

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -44,40 +44,5 @@
4444
<version>2.9.0</version>
4545
<scope>runtime</scope>
4646
</dependency>
47-
48-
<dependency>
49-
<groupId>org.glassfish.hk2.external</groupId>
50-
<artifactId>asm-all-repackaged</artifactId>
51-
<version>2.5.0-b32</version>
52-
<scope>runtime</scope>
53-
</dependency>
54-
55-
<dependency>
56-
<groupId>org.ow2.asm</groupId>
57-
<artifactId>asm-util</artifactId>
58-
<version>6.0</version>
59-
<scope>runtime</scope>
60-
</dependency>
61-
62-
<dependency>
63-
<groupId>org.ow2.asm</groupId>
64-
<artifactId>asm-tree</artifactId>
65-
<version>6.0</version>
66-
<scope>runtime</scope>
67-
</dependency>
68-
69-
<dependency>
70-
<groupId>org.ow2.asm</groupId>
71-
<artifactId>asm</artifactId>
72-
<version>6.0</version>
73-
<scope>runtime</scope>
74-
</dependency>
75-
76-
<dependency>
77-
<groupId>org.ow2.asm</groupId>
78-
<artifactId>asm-analysis</artifactId>
79-
<version>6.0</version>
80-
<scope>runtime</scope>
81-
</dependency>
8247
</dependencies>
8348
</project>

src/it/enforce-bytecode-version-multirelease/verify.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ assert file.exists();
33

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

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

89
return true;

src/main/java/org/apache/maven/plugins/enforcer/EnforceBytecodeVersion.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ public class EnforceBytecodeVersion
5757
extends AbstractResolveDependencies
5858
{
5959
private static final Map<String, Integer> JDK_TO_MAJOR_VERSION_NUMBER_MAPPING = new LinkedHashMap<String, Integer>();
60-
60+
/**
61+
* Default ignores when validating against jdk < 9 because <code>module-info.class</code> will always have level 1.9.
62+
*/
63+
private static final String[] DEFAULT_CLASSES_IGNORE_BEFORE_JDK_9 = {"module-info"};
64+
6165
private final Pattern MULTIRELEASE = Pattern.compile( "META-INF/versions/(\\d+)/.*" );
62-
private final String MODULE_INFO_CLASS = "module-info.class";
6366

6467
static
6568
{
@@ -218,6 +221,12 @@ private void computeParameters()
218221
"\"1.7\", \"8\", \"11\", \"12\"" );
219222
}
220223
maxJavaMajorVersionNumber = needle;
224+
if ( needle < 53 )
225+
{
226+
IgnorableDependency ignoreModuleInfoDependency = new IgnorableDependency();
227+
ignoreModuleInfoDependency.applyIgnoreClasses(DEFAULT_CLASSES_IGNORE_BEFORE_JDK_9, false );
228+
ignorableDependencies.add( ignoreModuleInfoDependency );
229+
}
221230
}
222231
if ( maxJavaMajorVersionNumber == -1 )
223232
{
@@ -322,18 +331,14 @@ private String isBadArtifact( Artifact a )
322331

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

325-
if ( MODULE_INFO_CLASS.equals( entry.getName() ) ) {
326-
getLog().warn( "Invalid bytecodeVersion for " + entry.getName() + ": expected "
327-
+ maxJavaMajorVersionNumber + ", but was " + major);
328-
}
329-
else if ( matcher.matches() )
334+
if ( matcher.matches() )
330335
{
331336
int expectedMajor = JDK_TO_MAJOR_VERSION_NUMBER_MAPPING.get( matcher.group( 1 ) );
332337

333338
if ( major != expectedMajor )
334339
{
335-
getLog().warn( "Invalid bytecodeVersion for " + entry.getName() + ": expected "
336-
+ expectedMajor + ", but was " + major );
340+
getLog().warn( "Invalid bytecodeVersion for " + a + " : "
341+
+ entry.getName() + ": expected " + expectedMajor + ", but was " + major );
337342
}
338343
}
339344
else

0 commit comments

Comments
 (0)