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
11 changes: 9 additions & 2 deletions blackbox-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,25 @@
<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-inject</artifactId>
<version>9.12</version>
<version>10.0-RC9</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>


<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-jsonb-generator</artifactId>
<version>2.0-RC3</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-inject-generator</artifactId>
<version>10.0-RC9</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<!-- test dependencies -->

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion jsonb-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<name>jsonb generator</name>
<description>annotation processor generating source code json adapters for avaje-jsonb</description>
<properties>
<avaje.prisms.version>1.27</avaje.prisms.version>
<avaje.prisms.version>1.28</avaje.prisms.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
import io.avaje.prism.GenerateAPContext;
import io.avaje.prism.GenerateModuleInfoReader;

import static java.util.stream.Collectors.joining;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Stream;
Expand Down Expand Up @@ -53,6 +57,22 @@ public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
ProcessingContext.init(processingEnv);
this.componentWriter = new SimpleComponentWriter(metaData);
// write a note in target so that other apts can know inject is running
try {
var file = APContext.getBuildResource("avaje-processors.txt");
var addition = new StringBuilder();
if (file.toFile().exists()) {
var result = Stream.concat(Files.lines(file), Stream.of("avaje-jsonb-generator"))
.distinct()
.collect(joining("\n"));
addition.append(result);
} else {
addition.append("avaje-jsonb-generator");
}
Files.writeString(file, addition, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
} catch (IOException e) {
// not an issue worth failing over
}
}

/**
Expand Down Expand Up @@ -94,30 +114,24 @@ private void registerCustomAdapters(Set<? extends Element> elements) {
final var type = typeElement.getQualifiedName().toString();
if (CustomAdapterPrism.getInstanceOn(typeElement).isGeneric()) {
ElementFilter.fieldsIn(typeElement.getEnclosedElements()).stream()
.filter(isStaticFactory())
.findFirst()
.ifPresentOrElse(
x -> {},
() ->
logError(
typeElement,
"Generic adapters require a public static JsonAdapter.Factory FACTORY field"));
.filter(isStaticFactory())
.findFirst()
.ifPresentOrElse(
x -> {},
() -> logError(typeElement, "Generic adapters require a public static JsonAdapter.Factory FACTORY field"));

metaData.addFactory(type);
} else {
ElementFilter.constructorsIn(typeElement.getEnclosedElements()).stream()
.filter(m -> m.getModifiers().contains(Modifier.PUBLIC))
.filter(m -> m.getParameters().size() == 1)
.map(m -> m.getParameters().get(0).asType().toString())
.map(Util::trimAnnotations)
.filter("io.avaje.jsonb.Jsonb"::equals)
.findAny()
.ifPresentOrElse(
x -> {},
() ->
logError(
typeElement,
"Non-Generic adapters must have a public constructor with a single Jsonb parameter"));
.filter(m -> m.getModifiers().contains(Modifier.PUBLIC))
.filter(m -> m.getParameters().size() == 1)
.map(m -> m.getParameters().get(0).asType().toString())
.map(Util::trimAnnotations)
.filter("io.avaje.jsonb.Jsonb"::equals)
.findAny()
.ifPresentOrElse(
x -> {},
() -> logError(typeElement, "Non-Generic adapters must have a public constructor with a single Jsonb parameter"));

metaData.add(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,8 @@ static List<SubTypePrism> importedSubtypes(TypeElement type) {
}

private static boolean buildPluginAvailable() {
return resourceExists("target/avaje-plugin-exists.txt")
|| resourceExists("build/avaje-plugin-exists.txt");
}

private static boolean resourceExists(String relativeName) {
try {
final String resource =
filer()
.getResource(StandardLocation.CLASS_OUTPUT, "", relativeName)
.toUri()
.toString()
.replaceFirst("/target/classes", "")
.replaceFirst("/build/classes/java/main", "");
return Paths.get(new URI(resource)).toFile().exists();
return APContext.getBuildResource("avaje-plugin-exists.txt").toFile().exists();
} catch (final Exception e) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<properties>
<surefire.useModulePath>false</surefire.useModulePath>
<nexus.staging.autoReleaseAfterClose>true</nexus.staging.autoReleaseAfterClose>
<spi.version>2.0</spi.version>
<spi.version>2.1</spi.version>
</properties>

<modules>
Expand Down