-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds tests to verify module-info.class files in releasable artifacts
- Loading branch information
Showing
5 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...fy/src/test/java/nl/jqno/equalsverifier/verify_release/jar/helper/ModuleInfoAsserter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package nl.jqno.equalsverifier.verify_release.jar.helper; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.*; | ||
|
||
import net.bytebuddy.jar.asm.*; | ||
|
||
public class ModuleInfoAsserter { | ||
|
||
private String moduleName; | ||
private final Set<String> exports = new HashSet<>(); | ||
private final Map<String, String> requires = new HashMap<>(); | ||
|
||
public static ModuleInfoAsserter parse(byte[] moduleinfo) { | ||
var result = new ModuleInfoAsserter(); | ||
|
||
new ClassReader(moduleinfo).accept(new ClassVisitor(Opcodes.ASM9) { | ||
@Override | ||
public ModuleVisitor visitModule(String name, int access, String version) { | ||
result.moduleName = name; | ||
return new ModuleVisitor(Opcodes.ASM9) { | ||
@Override | ||
public void visitExport(String packaze, int access, String... modules) { | ||
result.exports.add(packaze); | ||
} | ||
|
||
@Override | ||
public void visitRequire(String module, int access, String version) { | ||
var modifiers = ""; | ||
if ((access & Opcodes.ACC_TRANSITIVE) != 0) | ||
modifiers += "transitive"; | ||
result.requires.put(module, modifiers); | ||
} | ||
}; | ||
} | ||
}, 0); | ||
|
||
return result; | ||
} | ||
|
||
public void assertName(String name) { | ||
assertThat(moduleName).isEqualTo(name); | ||
} | ||
|
||
public void assertExports(String... names) { | ||
assertThat(exports).containsOnly(names); | ||
} | ||
|
||
public void assertRequires(String require, String modifier) { | ||
assertThat(requires).containsEntry(require, modifier); | ||
} | ||
|
||
public void assertDoesNotRequire(String require) { | ||
assertThat(requires).doesNotContainKey(require); | ||
} | ||
|
||
} |