Skip to content

Commit 9f81ee8

Browse files
authored
preserveExisting does not duplicate 'provides' entries (#164)
1 parent 158aa7e commit 9f81ee8

File tree

4 files changed

+85
-55
lines changed

4 files changed

+85
-55
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Extra Java Module Info Gradle Plugin - Changelog
22

3+
## Version 1.10.1
4+
* [Fix] [#164](https://github.com/gradlex-org/extra-java-module-info/pull/164) - fix: 'preserveExisting' does not duplicate 'provides' entries
5+
36
## Version 1.10
47
* [New] [#160](https://github.com/gradlex-org/extra-java-module-info/pull/160) - Add 'preserveExisting' option to patch real modules
58
* [New] [#140](https://github.com/gradlex-org/extra-java-module-info/pull/140) - Add 'removePackage' option to deal with duplicated packages

src/main/java/org/gradlex/javamodule/moduleinfo/ExtraJavaModuleInfoTransform.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ public ModuleVisitor visitModule(String name, int access, String version) {
396396
return new ModuleVisitor(Opcodes.ASM9, moduleVisitor) {
397397
@Override
398398
public void visitEnd() {
399-
addModuleInfoEntires(moduleInfo, providers, autoExportedPackages, this);
399+
addModuleInfoEntires(moduleInfo, Collections.emptyMap(), autoExportedPackages, this);
400400
super.visitEnd();
401401
}
402402
};

src/test/groovy/org/gradlex/javamodule/moduleinfo/test/RealModuleJarPatchingFunctionalTest.groovy

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.gradlex.javamodule.moduleinfo.test
22

33
import org.gradlex.javamodule.moduleinfo.test.fixture.GradleBuild
4-
import spock.lang.IgnoreIf
54
import spock.lang.Specification
65

76
class RealModuleJarPatchingFunctionalTest extends Specification {
@@ -200,57 +199,4 @@ class RealModuleJarPatchingFunctionalTest extends Specification {
200199
out.output.contains("Patching of real modules must be explicitly enabled with 'patchRealModule()' and can only be done with 'module()'")
201200
}
202201

203-
@IgnoreIf({ GradleBuild.gradleVersionUnderTest?.matches("[67]\\..*") }) // requires Gradle to support Java 17
204-
def "a real module cannot be extended"() {
205-
given:
206-
buildFile << '''
207-
tasks.withType<JavaCompile>().configureEach {
208-
options.compilerArgs.add("-Xlint:all")
209-
options.compilerArgs.add("-Werror")
210-
}
211-
dependencies {
212-
implementation("org.apache.logging.log4j:log4j-api:2.24.3")
213-
214-
// required because not declared in LOG4J metadata
215-
compileOnly("com.google.errorprone:error_prone_annotations:2.36.0")
216-
compileOnly("com.github.spotbugs:spotbugs-annotations:4.9.0")
217-
compileOnly("biz.aQute.bnd:biz.aQute.bnd.annotation:7.1.0")
218-
compileOnly("org.osgi:osgi.annotation:8.1.0") // this includes 'org.osgi.annotation.bundle'
219-
}
220-
extraJavaModuleInfo {
221-
failOnMissingModuleInfo.set(false) // transitive dependencies of annotation libs
222-
223-
module("org.apache.logging.log4j:log4j-api", "org.apache.logging.log4j") {
224-
preserveExisting()
225-
requiresStatic("com.google.errorprone.annotations")
226-
requiresStatic("com.github.spotbugs.annotations")
227-
requiresStatic("biz.aQute.bnd.annotation")
228-
requiresStatic("org.osgi.annotation")
229-
}
230-
module("biz.aQute.bnd:biz.aQute.bnd.annotation", "biz.aQute.bnd.annotation") {
231-
requiresStatic("org.osgi.annotation")
232-
exportAllPackages()
233-
}
234-
module("org.osgi:osgi.annotation", "org.osgi.annotation")
235-
}
236-
'''
237-
file("src/main/java/module-info.java") << """
238-
module org.example {
239-
requires org.apache.logging.log4j;
240-
}
241-
"""
242-
file("src/main/java/org/example/Main.java") << """
243-
package org.example;
244-
public class Main {
245-
org.apache.logging.log4j.message.ParameterizedMessage m; // needs errorprone
246-
org.apache.logging.log4j.status.StatusData d; // needs spotbugs
247-
org.apache.logging.log4j.util.SystemPropertiesPropertySource s; // needs aQute.bnd
248-
org.apache.logging.log4j.util.Activator a; // needs osgi
249-
}
250-
"""
251-
252-
expect:
253-
build()
254-
}
255-
256202
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package org.gradlex.javamodule.moduleinfo.test
2+
3+
import org.gradlex.javamodule.moduleinfo.test.fixture.GradleBuild
4+
import spock.lang.IgnoreIf
5+
import spock.lang.Specification
6+
7+
class RealModuleJarPreservePatchingFunctionalTest extends Specification {
8+
9+
@Delegate
10+
GradleBuild build = new GradleBuild()
11+
12+
def setup() {
13+
settingsFile << 'rootProject.name = "test-project"'
14+
buildFile << '''
15+
plugins {
16+
id("application")
17+
id("org.gradlex.extra-java-module-info")
18+
}
19+
application {
20+
mainModule.set("org.example")
21+
mainClass.set("org.example.Main")
22+
}
23+
'''
24+
}
25+
26+
@IgnoreIf({ GradleBuild.gradleVersionUnderTest?.matches("[67]\\..*") }) // requires Gradle to support Java 17
27+
def "a real module cannot be extended via preserveExisting"() {
28+
given:
29+
buildFile << '''
30+
tasks.withType<JavaCompile>().configureEach {
31+
options.compilerArgs.add("-Xlint:all")
32+
options.compilerArgs.add("-Werror")
33+
}
34+
dependencies {
35+
implementation("org.apache.logging.log4j:log4j-api:2.24.3")
36+
37+
// required because not declared in LOG4J metadata
38+
compileOnly("com.google.errorprone:error_prone_annotations:2.36.0")
39+
compileOnly("com.github.spotbugs:spotbugs-annotations:4.9.0")
40+
compileOnly("biz.aQute.bnd:biz.aQute.bnd.annotation:7.1.0")
41+
compileOnly("org.osgi:osgi.annotation:8.1.0") // this includes 'org.osgi.annotation.bundle'
42+
}
43+
extraJavaModuleInfo {
44+
failOnMissingModuleInfo.set(false) // transitive dependencies of annotation libs
45+
46+
module("org.apache.logging.log4j:log4j-api", "org.apache.logging.log4j") {
47+
preserveExisting()
48+
requiresStatic("com.google.errorprone.annotations")
49+
requiresStatic("com.github.spotbugs.annotations")
50+
requiresStatic("biz.aQute.bnd.annotation")
51+
requiresStatic("org.osgi.annotation")
52+
}
53+
module("biz.aQute.bnd:biz.aQute.bnd.annotation", "biz.aQute.bnd.annotation") {
54+
requiresStatic("org.osgi.annotation")
55+
exportAllPackages()
56+
}
57+
module("org.osgi:osgi.annotation", "org.osgi.annotation")
58+
}
59+
'''
60+
file("src/main/java/module-info.java") << """
61+
module org.example {
62+
requires org.apache.logging.log4j;
63+
}
64+
"""
65+
file("src/main/java/org/example/Main.java") << """
66+
package org.example;
67+
public class Main {
68+
org.apache.logging.log4j.message.ParameterizedMessage m; // needs errorprone
69+
org.apache.logging.log4j.status.StatusData d; // needs spotbugs
70+
org.apache.logging.log4j.util.SystemPropertiesPropertySource s; // needs aQute.bnd
71+
org.apache.logging.log4j.util.Activator a; // needs osgi
72+
73+
public static void main(String[] args) {}
74+
}
75+
"""
76+
77+
expect:
78+
run()
79+
}
80+
81+
}

0 commit comments

Comments
 (0)