diff options
author | zaaarf <me@zaaarf.foo> | 2024-01-24 16:32:10 +0100 |
---|---|---|
committer | zaaarf <me@zaaarf.foo> | 2024-01-24 16:32:10 +0100 |
commit | 324d7e24e5f02f0328a2ab35501238aea5674755 (patch) | |
tree | dd39f450ebd0e11ab87171492aeecf9fa506b833 /src | |
parent | f5bff65ba86f38157404da7c7844b287361a883a (diff) |
fix: don't try to recreate the routemap file
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/foo/zaaarf/routecompass/RouteCompass.java | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/main/java/foo/zaaarf/routecompass/RouteCompass.java b/src/main/java/foo/zaaarf/routecompass/RouteCompass.java index 7279fbe..269dfb1 100644 --- a/src/main/java/foo/zaaarf/routecompass/RouteCompass.java +++ b/src/main/java/foo/zaaarf/routecompass/RouteCompass.java @@ -30,6 +30,11 @@ import java.util.stream.Collectors; 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. */ private final Map<String, List<Route>> foundRoutes = new HashMap<>(); @@ -38,7 +43,7 @@ public class RouteCompass extends AbstractProcessor { * A {@link Set} containing all the supported annotation classes. */ private final Set<Class<? extends Annotation>> annotationClasses = new HashSet<>(); - + /** * Default constructor, it only initialises {@link #annotationClasses}. */ @@ -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(); } |