Skip to content

Commit 6ea22dc

Browse files
SentryManrbygrave
andauthored
Generate Meta-INF/services entry for inject-events (#704)
* generate events meta-inf services * Update pom.xml * update error * Format only change for ProcessingContext.validateModule() --------- Co-authored-by: Rob Bygrave <[email protected]>
1 parent d1e5763 commit 6ea22dc

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

inject-events/src/main/resources/META-INF/services/io.avaje.inject.spi.InjectExtension

Lines changed: 0 additions & 1 deletion
This file was deleted.

inject-generator/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<dependency>
3838
<groupId>io.avaje</groupId>
3939
<artifactId>avaje-spi-service</artifactId>
40-
<version>2.6</version>
40+
<version>2.7</version>
4141
</dependency>
4242
<!-- test dependencies -->
4343
<dependency>

inject-generator/src/main/java/io/avaje/inject/generator/ProcessingContext.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
final class ProcessingContext {
2121

22+
private static final String EVENTS_SPI = "io.avaje.inject.events.spi.ObserverManagerPlugin";
2223
private static final ThreadLocal<Ctx> CTX = new ThreadLocal<>();
2324
private static boolean processingOver;
2425
private ProcessingContext() {}
@@ -42,6 +43,17 @@ void registerProvidedTypes(Set<String> moduleFileProvided) {
4243
static void init(Set<String> moduleFileProvided, boolean performModuleValidation) {
4344
CTX.set(new Ctx());
4445
CTX.get().registerProvidedTypes(moduleFileProvided);
46+
addEventSPI();
47+
}
48+
49+
private static void addEventSPI() {
50+
try {
51+
if (typeElement(EVENTS_SPI) != null || Class.forName(EVENTS_SPI) != null) {
52+
addInjectSPI(EVENTS_SPI);
53+
}
54+
} catch (final ClassNotFoundException e) {
55+
// nothing
56+
}
4557
}
4658

4759
static String loadMetaInfServices() {
@@ -140,8 +152,10 @@ static void addImportedAspects(Map<String, AspectImportPrism> importedMap) {
140152
}
141153

142154
static void validateModule() {
143-
APContext.moduleInfoReader().ifPresent(reader ->
144-
reader.validateServices("io.avaje.inject.spi.InjectExtension", CTX.get().spiServices));
155+
APContext.moduleInfoReader().ifPresent(reader -> {
156+
CTX.get().spiServices.remove(EVENTS_SPI);
157+
reader.validateServices("io.avaje.inject.spi.InjectExtension", CTX.get().spiServices);
158+
});
145159
}
146160

147161
static Optional<AspectImportPrism> getImportedAspect(String type) {

inject/src/main/java/io/avaje/inject/DBeanScopeBuilder.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,11 @@ public BeanScope build() {
287287
if (moduleNames.isEmpty()) {
288288
log.log(
289289
Level.ERROR,
290-
"Could not find any AvajeModule instances to wire. Possible Causes: \n1. No beans have been defined.\n2. The avaje-inject-generator depedency was not available during compilation\n3. Perhaps using Gradle and a misconfigured IDE? Refer to https://avaje.io/inject#gradle");
290+
"Could not find any AvajeModule instances to wire. Possible Causes: \n"
291+
+ "1. No beans have been defined.\n"
292+
+ "2. The avaje-inject-generator depedency was not available during compilation\n"
293+
+ "3. Perhaps using Gradle and a misconfigured IDE? Refer to https://avaje.io/inject#gradle"
294+
+ "4. Perhaps this is a fat jar and you have not configured your maven asembly/shade or gradle build task to merge META-INF/services");
291295
}
292296

293297
postConstructList.forEach(builder::addPostConstruct);

0 commit comments

Comments
 (0)