Skip to content
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 pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<surefire.useModulePath>false</surefire.useModulePath>
<nexus.staging.autoReleaseAfterClose>true</nexus.staging.autoReleaseAfterClose>
<maven.compiler.release>17</maven.compiler.release>
<inject.version>12.0</inject.version>
<inject.version>12.1-RC6</inject.version>
<spi.version>2.13</spi.version>
<project.build.outputTimestamp>2025-12-01T15:48:59Z</project.build.outputTimestamp>
</properties>
Expand Down
2 changes: 1 addition & 1 deletion validator-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<name>validator generator</name>
<description>annotation processor generating validation adapters</description>
<properties>
<avaje.prisms.version>1.44-RC4</avaje.prisms.version>
<avaje.prisms.version>2.0-RC1</avaje.prisms.version>
<io.jstach.version>1.3.7</io.jstach.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.avaje.validation.generator;

import static io.avaje.validation.generator.APContext.filer;
import static io.avaje.validation.generator.APContext.getModuleInfoReader;
import static io.avaje.validation.generator.APContext.getProjectModuleElement;
import static io.avaje.validation.generator.APContext.logWarn;
import static java.util.stream.Collectors.toSet;
Expand All @@ -14,11 +13,10 @@

import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.Element;
import javax.lang.model.element.ModuleElement.RequiresDirective;
import javax.tools.FileObject;
import javax.tools.StandardLocation;

import io.avaje.validation.generator.ModuleInfoReader.Requires;

final class ProcessingContext {

private static final ThreadLocal<Ctx> CTX = new ThreadLocal<>();
Expand Down Expand Up @@ -64,44 +62,44 @@ static boolean isImported(Element element) {

static void validateModule() {
var module = getProjectModuleElement();
if (module != null && !module.isUnnamed()) {
var injectPresent = CTX.get().injectPresent;
var warnHttp = CTX.get().warnHttp;

try (var reader = getModuleInfoReader()) {
var moduleInfo = new ModuleInfoReader(module, reader);

moduleInfo.validateServices("io.avaje.validation.spi.ValidationExtension", CTX.get().serviceSet);

var buildPluginAvailable = buildPluginAvailable();
var requireSet =
moduleInfo.requires().stream()
.map(Requires::getDependency)
.map(m -> m.getQualifiedName().toString())
.collect(toSet());

boolean noHttpPlugin =
injectPresent
&& (!buildPluginAvailable || !requireSet.contains("io.avaje.http.api"))
&& warnHttp
&& !moduleInfo.containsOnModulePath("io.avaje.validation.http");

boolean noInjectPlugin =
noHttpPlugin
&& injectPresent
&& (!buildPluginAvailable || !requireSet.contains("io.avaje.validation"))
&& !moduleInfo.containsOnModulePath("io.avaje.validation.plugin");

if (noHttpPlugin) {
logWarn(module, "`requires io.avaje.validation.http` must be explicity added or else avaje-inject may fail to detect the default http validator, validator, and method AOP validator");
} else if (noInjectPlugin) {
logWarn(module, "`requires io.avaje.validation.plugin` must be explicity added or else avaje-inject may fail to detect the default validator and method AOP validator");
}

} catch (Exception e) {
// can't read module
}
}
var injectPresent = CTX.get().injectPresent;
var warnHttp = CTX.get().warnHttp;

APContext.moduleInfoReader()
.ifPresent(
moduleInfo -> {
moduleInfo.validateServices(
"io.avaje.validation.spi.ValidationExtension", CTX.get().serviceSet);

var buildPluginAvailable = buildPluginAvailable();
var requireSet =
moduleInfo.requires().stream()
.map(RequiresDirective::getDependency)
.map(m -> m.getQualifiedName().toString())
.collect(toSet());

boolean noHttpPlugin =
injectPresent
&& (!buildPluginAvailable || !requireSet.contains("io.avaje.http.api"))
&& warnHttp
&& !moduleInfo.containsOnModulePath("io.avaje.validation.http");

boolean noInjectPlugin =
noHttpPlugin
&& injectPresent
&& (!buildPluginAvailable || !requireSet.contains("io.avaje.validation"))
&& !moduleInfo.containsOnModulePath("io.avaje.validation.plugin");

if (noHttpPlugin) {
logWarn(
module,
"`requires io.avaje.validation.http` must be explicity added or else avaje-inject may fail to detect the default http validator, validator, and method AOP validator");
} else if (noInjectPlugin) {
logWarn(
module,
"`requires io.avaje.validation.plugin` must be explicity added or else avaje-inject may fail to detect the default validator and method AOP validator");
}
});
}

private static boolean buildPluginAvailable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@
import javax.tools.FileObject;

import io.avaje.prism.GenerateAPContext;
import io.avaje.prism.GenerateModuleInfoReader;
import io.avaje.prism.GenerateUtils;

@GenerateUtils
@GenerateAPContext
@GenerateModuleInfoReader
@SupportedAnnotationTypes({
AvajeValidPrism.PRISM_TYPE,
ImportValidPojoPrism.PRISM_TYPE,
Expand Down Expand Up @@ -115,6 +113,10 @@ private void readModule() {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment round) {
if (generateComponent || round.errorRaised()) {
if (round.processingOver()) {
ProcessingContext.validateModule();
ProcessingContext.clear();
}
return false;
}
generateComponent = rounds++ > 0;
Expand Down Expand Up @@ -302,11 +304,8 @@ private void writeComponent(boolean processingOver) {
writer.write();
}
writeMetaInf();
ProcessingContext.validateModule();
} catch (final IOException e) {
logError("Error writing component", e);
} finally {
ProcessingContext.clear();
}
}
}
Expand Down
Loading