Skip to content

Writes a file to signal the generator's presence #226

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 1, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ build/
*.factorypath
validator-generator/.factorypath
validator-generator/io.avaje.validation.spi.ValidationExtension
validator-generator/avaje-processors.txt
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<maven.compiler.release>17</maven.compiler.release>
<inject.version>10.0-RC9</inject.version>
<http.version>2.0-RC2</http.version>
<spi.version>2.0</spi.version>
<spi.version>2.1</spi.version>
</properties>

<modules>
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.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 @@ -108,21 +108,9 @@ static void validateModule() {
}

private static boolean buildPluginAvailable() {
return resource("target/avaje-plugin-exists.txt", "/target/classes")
|| resource("build/avaje-plugin-exists.txt", "/build/classes/java/main");
}

private static boolean resource(String relativeName, String replace) {
try (var inputStream =
new URI(filer().getResource(StandardLocation.CLASS_OUTPUT, "", relativeName)
.toUri()
.toString()
.replace(replace, ""))
.toURL()
.openStream()) {

return inputStream.available() > 0;
} catch (IOException | URISyntaxException e) {
try {
return APContext.getBuildResource("avaje-plugin-exists.txt").toFile().exists();
} catch (final Exception e) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package io.avaje.validation.generator;

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

import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Stream;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment;
Expand Down Expand Up @@ -61,6 +69,25 @@ public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
ProcessingContext.init(processingEnv);
this.componentWriter = new SimpleComponentWriter(metaData);

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-validator-generator"))
.distinct()
.collect(joining("\n"));
addition.append(result);
} else {
addition.append("avaje-validator-generator");
}
Files.writeString(file, addition, StandardOpenOption.CREATE, StandardOpenOption.WRITE);

} catch (IOException e) {
// not an issue worth failing over
}
}

/** Read the existing metadata from the generated component (if exists). */
Expand Down
Loading