fix: don't try to recreate the routemap file

This commit is contained in:
zaaarf 2024-01-24 16:32:10 +01:00
parent f5bff65ba8
commit 324d7e24e5
No known key found for this signature in database
GPG key ID: 102E445F4C3F829B

View file

@ -29,6 +29,11 @@ import java.util.stream.Collectors;
@SupportedSourceVersion(SourceVersion.RELEASE_8)
public class RouteCompass extends AbstractProcessor {
/**
* The filename of the output.
*/
private static final String ROUTE_MAP_FILENAME = "route_map";
/**
* A {@link Map} tying each component class to the routes it contains.
*/
@ -85,11 +90,23 @@ public class RouteCompass extends AbstractProcessor {
}
try {
FileObject serviceProvider = this.processingEnv.getFiler().createResource(
StandardLocation.SOURCE_OUTPUT, "", "route_map"
CharSequence startingContents;
try {
FileObject existingRouteMap = this.processingEnv.getFiler().getResource(
StandardLocation.SOURCE_OUTPUT, "", ROUTE_MAP_FILENAME
);
startingContents = existingRouteMap.getCharContent(true);
existingRouteMap.delete();
} catch (IOException ex) {
startingContents = "";
}
FileObject routeMap = this.processingEnv.getFiler().createResource(
StandardLocation.SOURCE_OUTPUT, "", ROUTE_MAP_FILENAME
);
PrintWriter out = new PrintWriter(serviceProvider.openWriter());
PrintWriter out = new PrintWriter(routeMap.openWriter());
out.println(startingContents); //print with an extra newline
for(String componentClass : this.foundRoutes.keySet()) {
out.println(componentClass + ":");
@ -152,7 +169,10 @@ public class RouteCompass extends AbstractProcessor {
String parent = this.getFullRoute(a, e)[0];
for(int i = 0; i < routes.length; i++) {
StringBuilder sb = new StringBuilder(parent);
if(!parent.endsWith("/")) sb.append("/");
if(!parent.endsWith("/") && !routes[i].startsWith("/"))
sb.append("/");
if(parent.endsWith("/") && routes[i].startsWith("/"))
sb.deleteCharAt(sb.length() - 1);
sb.append(routes[i]);
routes[i] = sb.toString();
}