Skip to content

Commit 9124a96

Browse files
authored
Writes a file to signal the generator's presence (#254)
* write marker file * write all processors into a file * dedup txt * properly dedup * Update pom.xml * Format only changes
1 parent 83042b4 commit 9124a96

File tree

5 files changed

+46
-37
lines changed

5 files changed

+46
-37
lines changed

blackbox-test/pom.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,25 @@
3939
<dependency>
4040
<groupId>io.avaje</groupId>
4141
<artifactId>avaje-inject</artifactId>
42-
<version>9.12</version>
42+
<version>10.0-RC9</version>
4343
<scope>provided</scope>
4444
<optional>true</optional>
4545
</dependency>
4646

47+
4748
<dependency>
4849
<groupId>io.avaje</groupId>
4950
<artifactId>avaje-jsonb-generator</artifactId>
5051
<version>2.0-RC3</version>
5152
<scope>provided</scope>
5253
</dependency>
53-
54+
<dependency>
55+
<groupId>io.avaje</groupId>
56+
<artifactId>avaje-inject-generator</artifactId>
57+
<version>10.0-RC9</version>
58+
<scope>provided</scope>
59+
<optional>true</optional>
60+
</dependency>
5461
<!-- test dependencies -->
5562

5663
<dependency>

jsonb-generator/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<name>jsonb generator</name>
1212
<description>annotation processor generating source code json adapters for avaje-jsonb</description>
1313
<properties>
14-
<avaje.prisms.version>1.27</avaje.prisms.version>
14+
<avaje.prisms.version>1.28</avaje.prisms.version>
1515
</properties>
1616

1717
<dependencies>

jsonb-generator/src/main/java/io/avaje/jsonb/generator/JsonbProcessor.java

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
import io.avaje.prism.GenerateAPContext;
1717
import io.avaje.prism.GenerateModuleInfoReader;
1818

19+
import static java.util.stream.Collectors.joining;
20+
1921
import java.io.IOException;
22+
import java.nio.file.Files;
23+
import java.nio.file.StandardOpenOption;
2024
import java.util.*;
2125
import java.util.function.Predicate;
2226
import java.util.stream.Stream;
@@ -53,6 +57,22 @@ public synchronized void init(ProcessingEnvironment processingEnv) {
5357
super.init(processingEnv);
5458
ProcessingContext.init(processingEnv);
5559
this.componentWriter = new SimpleComponentWriter(metaData);
60+
// write a note in target so that other apts can know inject is running
61+
try {
62+
var file = APContext.getBuildResource("avaje-processors.txt");
63+
var addition = new StringBuilder();
64+
if (file.toFile().exists()) {
65+
var result = Stream.concat(Files.lines(file), Stream.of("avaje-jsonb-generator"))
66+
.distinct()
67+
.collect(joining("\n"));
68+
addition.append(result);
69+
} else {
70+
addition.append("avaje-jsonb-generator");
71+
}
72+
Files.writeString(file, addition, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
73+
} catch (IOException e) {
74+
// not an issue worth failing over
75+
}
5676
}
5777

5878
/**
@@ -94,30 +114,24 @@ private void registerCustomAdapters(Set<? extends Element> elements) {
94114
final var type = typeElement.getQualifiedName().toString();
95115
if (CustomAdapterPrism.getInstanceOn(typeElement).isGeneric()) {
96116
ElementFilter.fieldsIn(typeElement.getEnclosedElements()).stream()
97-
.filter(isStaticFactory())
98-
.findFirst()
99-
.ifPresentOrElse(
100-
x -> {},
101-
() ->
102-
logError(
103-
typeElement,
104-
"Generic adapters require a public static JsonAdapter.Factory FACTORY field"));
117+
.filter(isStaticFactory())
118+
.findFirst()
119+
.ifPresentOrElse(
120+
x -> {},
121+
() -> logError(typeElement, "Generic adapters require a public static JsonAdapter.Factory FACTORY field"));
105122

106123
metaData.addFactory(type);
107124
} else {
108125
ElementFilter.constructorsIn(typeElement.getEnclosedElements()).stream()
109-
.filter(m -> m.getModifiers().contains(Modifier.PUBLIC))
110-
.filter(m -> m.getParameters().size() == 1)
111-
.map(m -> m.getParameters().get(0).asType().toString())
112-
.map(Util::trimAnnotations)
113-
.filter("io.avaje.jsonb.Jsonb"::equals)
114-
.findAny()
115-
.ifPresentOrElse(
116-
x -> {},
117-
() ->
118-
logError(
119-
typeElement,
120-
"Non-Generic adapters must have a public constructor with a single Jsonb parameter"));
126+
.filter(m -> m.getModifiers().contains(Modifier.PUBLIC))
127+
.filter(m -> m.getParameters().size() == 1)
128+
.map(m -> m.getParameters().get(0).asType().toString())
129+
.map(Util::trimAnnotations)
130+
.filter("io.avaje.jsonb.Jsonb"::equals)
131+
.findAny()
132+
.ifPresentOrElse(
133+
x -> {},
134+
() -> logError(typeElement, "Non-Generic adapters must have a public constructor with a single Jsonb parameter"));
121135

122136
metaData.add(type);
123137
}

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,8 @@ static List<SubTypePrism> importedSubtypes(TypeElement type) {
7878
}
7979

8080
private static boolean buildPluginAvailable() {
81-
return resourceExists("target/avaje-plugin-exists.txt")
82-
|| resourceExists("build/avaje-plugin-exists.txt");
83-
}
84-
85-
private static boolean resourceExists(String relativeName) {
8681
try {
87-
final String resource =
88-
filer()
89-
.getResource(StandardLocation.CLASS_OUTPUT, "", relativeName)
90-
.toUri()
91-
.toString()
92-
.replaceFirst("/target/classes", "")
93-
.replaceFirst("/build/classes/java/main", "");
94-
return Paths.get(new URI(resource)).toFile().exists();
82+
return APContext.getBuildResource("avaje-plugin-exists.txt").toFile().exists();
9583
} catch (final Exception e) {
9684
return false;
9785
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<properties>
2525
<surefire.useModulePath>false</surefire.useModulePath>
2626
<nexus.staging.autoReleaseAfterClose>true</nexus.staging.autoReleaseAfterClose>
27-
<spi.version>2.0</spi.version>
27+
<spi.version>2.1</spi.version>
2828
</properties>
2929

3030
<modules>

0 commit comments

Comments
 (0)