Skip to content

Commit aae67cf

Browse files
authored
Make Module Validation take effect only when the SPI is in the module (#34)
* services should only be module validated if in the same module * Update README.md
1 parent d25264a commit aae67cf

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![Build](https://github.com/avaje/avaje-spi-service/actions/workflows/build.yml/badge.svg)](https://github.com/avaje/avaje-spi-service/actions/workflows/build.yml)
22
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/avaje/avaje-spi-service/blob/master/LICENSE)
3-
[![Maven Central](https://img.shields.io/maven-central/v/io.avaje/avaje-inject.svg?label=Maven%20Central)](https://mvnrepository.com/artifact/io.avaje/avaje-spi-service)
3+
[![Maven Central](https://img.shields.io/maven-central/v/io.avaje/avaje-spi-service.svg?label=Maven%20Central)](https://mvnrepository.com/artifact/io.avaje/avaje-spi-service)
44
[![Discord](https://img.shields.io/discord/1074074312421683250?color=%237289da&label=discord)](https://discord.gg/Qcqf9R27BR)
55
# avaje-spi-service
66
Uses Annotation processing to automatically add `META-INF/services` entries for classes and validate `module-info.java` files.

avaje-spi-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<tag>HEAD</tag>
1414
</scm>
1515
<properties>
16-
<avaje.prisms.version>1.31</avaje.prisms.version>
16+
<avaje.prisms.version>1.32</avaje.prisms.version>
1717
</properties>
1818

1919
<dependencies>

avaje-spi-core/src/main/java/io/avaje/spi/internal/ModuleReader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ void read(ModuleInfoReader module) {
3838
}
3939
}
4040
module.provides().forEach(p -> {
41+
4142
final var contract = replace$(p.service());
43+
4244
if (!missingServicesMap.containsKey(contract)) {
4345
return;
4446
}
4547
var impls = p.implementations();
4648
var missing = missingServicesMap.get(contract);
47-
if (missing.size() != impls.size()) {
48-
return;
49-
}
49+
5050
impls.stream().map(ModuleReader::replace$).forEach(missing::remove);
5151
});
5252
}

avaje-spi-core/src/main/java/io/avaje/spi/internal/ServiceProcessor.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.avaje.spi.internal;
22

33
import static io.avaje.spi.internal.APContext.*;
4+
import static java.util.function.Predicate.not;
45
import static java.util.stream.Collectors.joining;
56

67
import java.io.BufferedReader;
@@ -422,6 +423,7 @@ void validateModule() {
422423

423424
private void logModuleError(ModuleReader moduleReader) {
424425
moduleReader.missing().forEach((k, v) -> {
426+
v.removeIf(this::isNotSameModule);
425427
if (!v.isEmpty()) {
426428
var contract =
427429
services.keySet().stream()
@@ -430,6 +432,7 @@ private void logModuleError(ModuleReader moduleReader) {
430432
.orElseThrow();
431433
var missingImpls =
432434
services.get(contract).stream()
435+
.filter(not(this::isNotSameModule))
433436
.map(Utils::fqnFromBinaryType)
434437
.collect(joining(", "));
435438

@@ -438,6 +441,15 @@ private void logModuleError(ModuleReader moduleReader) {
438441
});
439442
}
440443

444+
private boolean isNotSameModule(String type) {
445+
var element = typeElement(type);
446+
return element == null
447+
|| !elements
448+
.getModuleOf(element)
449+
.getSimpleName()
450+
.contentEquals(moduleElement.getSimpleName());
451+
}
452+
441453
private static boolean buildPluginAvailable() {
442454
return resource("avaje-plugin-exists.txt");
443455
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
io.avaje.inject.events.spi.ObserverManagerPlugin

0 commit comments

Comments
 (0)