From ec95eaf67413431237831f184ea1e2f5ce0bc858 Mon Sep 17 00:00:00 2001 From: dgelessus <dgelessus@users.noreply.github.com> Date: Fri, 10 Jan 2025 12:04:54 +0100 Subject: [PATCH] Get and convert paths only once --- .../hhu/stups/sablecc/gradle/SableCCTask.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/hhu/stups/sablecc/gradle/SableCCTask.java b/src/main/java/de/hhu/stups/sablecc/gradle/SableCCTask.java index 8979639..09f84e6 100644 --- a/src/main/java/de/hhu/stups/sablecc/gradle/SableCCTask.java +++ b/src/main/java/de/hhu/stups/sablecc/gradle/SableCCTask.java @@ -3,6 +3,7 @@ package de.hhu.stups.sablecc.gradle; import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; @@ -103,10 +104,13 @@ public abstract class SableCCTask extends SourceTask { @TaskAction void execute() throws IOException { + Path destinationJavaPath = this.getDestinationJavaDir().getAsFile().toPath(); + Path destinationResourcesPath = this.getDestinationResourcesDir().getAsFile().toPath(); + // Delete any previously generated source files, so that no longer existing token and node classes aren't kept around. - this.getFs().delete(spec -> spec.delete(this.getDestinationJavaDir(), this.getDestinationResourcesDir())); - Files.createDirectories(this.getDestinationJavaDir().getAsFile().toPath()); - Files.createDirectories(this.getDestinationResourcesDir().getAsFile().toPath()); + this.getFs().delete(spec -> spec.delete(destinationJavaPath, destinationResourcesPath)); + Files.createDirectories(destinationJavaPath); + Files.createDirectories(destinationResourcesPath); // Call SableCC to generate the source files. this.getExecOperations().javaexec(spec -> { @@ -115,7 +119,7 @@ public abstract class SableCCTask extends SourceTask { spec.getMainClass().set("org.sablecc.sablecc.SableCC"); final List<String> args = new ArrayList<>(); args.add("-d"); - args.add(destinationJavaDir.get().getAsFile().getPath()); + args.add(destinationJavaPath.toString()); for (final File file : this.getSource().getFiles()) { args.add(file.getPath()); } @@ -124,13 +128,13 @@ public abstract class SableCCTask extends SourceTask { // Move generated dat files from Java source directory to resources directory. this.getFs().copy(spec -> { - spec.from(this.getDestinationJavaDir()); - spec.into(this.getDestinationResourcesDir()); + spec.from(destinationJavaPath); + spec.into(destinationResourcesPath); spec.include("**/*.dat"); }); this.getFs().delete(spec -> { ConfigurableFileTree fileTree = this.objectFactory.fileTree(); - fileTree.from(this.getDestinationJavaDir()); + fileTree.from(destinationJavaPath); fileTree.include("**/*.dat"); spec.delete(fileTree); }); -- GitLab