Skip to content

Commit a3be88a

Browse files
committed
adds marker file
1 parent 3e3bdb6 commit a3be88a

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

prism-core/src/main/java/io/avaje/prism/internal/APContext.java

+28
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
import java.io.BufferedReader;
66
import java.io.IOException;
77
import java.io.InputStreamReader;
8+
import java.net.URI;
9+
import java.nio.file.Path;
810
import java.util.Collection;
911
import java.util.Optional;
1012
import java.util.Set;
13+
import java.util.UUID;
1114
import java.util.stream.Stream;
1215

1316
import javax.annotation.processing.Filer;
@@ -346,4 +349,29 @@ public static BufferedReader getModuleInfoReader() throws IOException {
346349
.openStream();
347350
return new BufferedReader(new InputStreamReader(inputStream));
348351
}
352+
353+
/**
354+
* Given the relative path, gets a {@link Path} from the Maven {@code target}/Gradle {@code build} folder.
355+
* @param path the relative path of the file in the target/build folder
356+
*
357+
* @return the file object
358+
* @throws IOException if unable to retrieve the file
359+
*/
360+
public static Path getBuildResource(String path) throws IOException {
361+
362+
var id = UUID.randomUUID().toString();
363+
final var uri =
364+
filer()
365+
.createResource(StandardLocation.CLASS_OUTPUT, "", path + id)
366+
.toUri()
367+
.toString()
368+
.replaceFirst(id, "")
369+
.replaceFirst("/classes", "")
370+
.replaceFirst("/classes/java/main", "");
371+
var updatedPath = Path.of(URI.create(uri));
372+
if (path.contains("/")) {
373+
updatedPath.getParent().toFile().mkdirs();
374+
}
375+
return updatedPath;
376+
}
349377
}

prism-core/src/main/java/io/avaje/prism/internal/PrismGenerator.java

+11
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
4242
import java.io.IOException;
4343
import java.io.PrintWriter;
4444
import java.io.UncheckedIOException;
45+
import java.nio.file.Files;
4546
import java.util.ArrayDeque;
4647
import java.util.ArrayList;
4748
import java.util.Collection;
@@ -76,6 +77,8 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
7677
import javax.lang.model.util.Elements;
7778
import javax.lang.model.util.Types;
7879
import javax.tools.Diagnostic;
80+
81+
import io.avaje.inject.generator.APContext;
7982
import io.avaje.spi.ServiceProvider;
8083
/**
8184
* An AnnotationProcessor for generating prisms. Do not use this class directly.
@@ -113,6 +116,14 @@ public synchronized void init(ProcessingEnvironment env) {
113116
this.elements = env.getElementUtils();
114117
this.types = env.getTypeUtils();
115118
APContext.init(env);
119+
// write a note in target so that other apts can know prisms was running
120+
try {
121+
122+
var file = APContext.getBuildResource("avaje-processors/avaje-prism-core");
123+
Files.writeString(file, "avaje-prism-core initialized");
124+
} catch (IOException e) {
125+
// not an issue worth failing over
126+
}
116127
}
117128

118129
@Override

0 commit comments

Comments
 (0)