Skip to content
Snippets Groups Projects
Commit ec95eaf6 authored by dgelessus's avatar dgelessus
Browse files

Get and convert paths only once

parent 4c7736b6
No related branches found
No related tags found
No related merge requests found
......@@ -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);
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment