Skip to content

Make Module Validation take effect only when the SPI is in the module #34

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![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)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/avaje/avaje-spi-service/blob/master/LICENSE)
[![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)
[![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)
[![Discord](https://img.shields.io/discord/1074074312421683250?color=%237289da&label=discord)](https://discord.gg/Qcqf9R27BR)
# avaje-spi-service
Uses Annotation processing to automatically add `META-INF/services` entries for classes and validate `module-info.java` files.
Expand Down
2 changes: 1 addition & 1 deletion avaje-spi-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<tag>HEAD</tag>
</scm>
<properties>
<avaje.prisms.version>1.31</avaje.prisms.version>
<avaje.prisms.version>1.32</avaje.prisms.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ void read(ModuleInfoReader module) {
}
}
module.provides().forEach(p -> {

final var contract = replace$(p.service());

if (!missingServicesMap.containsKey(contract)) {
return;
}
var impls = p.implementations();
var missing = missingServicesMap.get(contract);
if (missing.size() != impls.size()) {
return;
}

impls.stream().map(ModuleReader::replace$).forEach(missing::remove);
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.avaje.spi.internal;

import static io.avaje.spi.internal.APContext.*;
import static java.util.function.Predicate.not;
import static java.util.stream.Collectors.joining;

import java.io.BufferedReader;
Expand Down Expand Up @@ -422,6 +423,7 @@ void validateModule() {

private void logModuleError(ModuleReader moduleReader) {
moduleReader.missing().forEach((k, v) -> {
v.removeIf(this::isNotSameModule);
if (!v.isEmpty()) {
var contract =
services.keySet().stream()
Expand All @@ -430,6 +432,7 @@ private void logModuleError(ModuleReader moduleReader) {
.orElseThrow();
var missingImpls =
services.get(contract).stream()
.filter(not(this::isNotSameModule))
.map(Utils::fqnFromBinaryType)
.collect(joining(", "));

Expand All @@ -438,6 +441,15 @@ private void logModuleError(ModuleReader moduleReader) {
});
}

private boolean isNotSameModule(String type) {
var element = typeElement(type);
return element == null
|| !elements
.getModuleOf(element)
.getSimpleName()
.contentEquals(moduleElement.getSimpleName());
}

private static boolean buildPluginAvailable() {
return resource("avaje-plugin-exists.txt");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.avaje.inject.events.spi.ObserverManagerPlugin
Loading