Skip to content
Snippets Groups Projects
Commit dd4d7dfe authored by René Schöne's avatar René Schöne
Browse files

Resolve problem with relative paths.

- some files were not found, because their relative path was not correctly resolved
parent effb5d3c
No related branches found
No related tags found
No related merge requests found
Pipeline #6569 failed
...@@ -9,9 +9,7 @@ import org.gradle.api.tasks.SourceSetContainer; ...@@ -9,9 +9,7 @@ import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.TaskAction;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.*;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
...@@ -165,22 +163,23 @@ public class RelastTest extends DefaultTask { ...@@ -165,22 +163,23 @@ public class RelastTest extends DefaultTask {
return option != null && !option.isEmpty(); return option != null && !option.isEmpty();
} }
private String[] genSuffixes = {".ast", ".jadd", "RefResolver.jadd", "ResolverStubs.jrag", "Serializer.jadd"}; private final String[] genSuffixes = {".ast", ".jadd", "RefResolver.jadd", "ResolverStubs.jrag", "Serializer.jadd"};
@TaskAction @TaskAction
void runTest() throws IOException { void runTest() throws IOException {
setGroup("verification"); setGroup("verification");
setDescription("Runs a relast test"); setDescription("Runs a relast test");
Project project = getProject(); Project project = getProject();
String absoluteProjectPath = project.getProjectDir().getAbsolutePath();
if (isVerbose()) { if (isVerbose()) {
System.out.println("Running relast test"); System.out.println("Running relast test in " + project.getDisplayName());
System.out.println("relast files: " + getRelastFiles()); System.out.println("relast files: " + getRelastFiles());
System.out.println("Deleting files"); System.out.println("Deleting files");
} }
// first, delete generated files // first, delete generated files
List<String> genFiles = new ArrayList<>(); List<Path> genFiles = new ArrayList<>();
for (String suffix : genSuffixes) { for (String suffix : genSuffixes) {
genFiles.add(getGrammarName() + suffix); genFiles.add(Paths.get(absoluteProjectPath, getGrammarName() + suffix));
} }
if (isVerbose()) { if (isVerbose()) {
System.out.println("gen files: " + genFiles); System.out.println("gen files: " + genFiles);
...@@ -235,14 +234,14 @@ public class RelastTest extends DefaultTask { ...@@ -235,14 +234,14 @@ public class RelastTest extends DefaultTask {
System.out.println("Start relast with args: " + args); System.out.println("Start relast with args: " + args);
} }
javaExecSpec.args(args); javaExecSpec.args(args);
}); }).assertNormalExitValue();
}); });
if (isRunJastAdd()) { if (isRunJastAdd()) {
if (isVerbose()) { if (isVerbose()) {
System.out.println("Compile with JastAdd"); System.out.println("Compile with JastAdd");
} }
// check which files were actually generated // check which files were actually generated
genFiles.removeIf(s -> !Paths.get(s).toFile().exists()); genFiles.removeIf(this::verboseFileNotExists);
// finally, compile generated files // finally, compile generated files
project.getPlugins().withType(JavaPlugin.class, javaPlugin -> { project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {
SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets"); SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets");
...@@ -267,9 +266,30 @@ public class RelastTest extends DefaultTask { ...@@ -267,9 +266,30 @@ public class RelastTest extends DefaultTask {
} }
} }
private String fileExtension(String filename) {
int indexOfDot = filename.lastIndexOf('.');
return indexOfDot == -1 ? filename : filename.substring(indexOfDot + 1);
}
private boolean verboseFileNotExists(Path path) {
boolean fileDoesNotExist = !Files.exists(path);
if (fileDoesNotExist && isVerbose()) {
System.out.println("Do not include " + path);
}
return fileDoesNotExist;
}
private void createDirectory(Path path) throws IOException { private void createDirectory(Path path) throws IOException {
if (Files.exists(path) && Files.isDirectory(path)) {
return;
}
if (isVerbose()) {
System.out.println("Creating " + path.toAbsolutePath());
}
try { try {
Files.createDirectories(path); Files.createDirectories(path);
} catch (FileAlreadyExistsException e) {
System.err.println("Skipping creation of already existing " + path);
} catch (IOException e) { } catch (IOException e) {
System.err.println("Could not create output directory " + path); System.err.println("Could not create output directory " + path);
throw e; throw e;
......
...@@ -98,3 +98,7 @@ task compileExampleTest(type: RelastTest) { ...@@ -98,3 +98,7 @@ task compileExampleTest(type: RelastTest) {
test.dependsOn compileExampleTest test.dependsOn compileExampleTest
compileExampleTest.dependsOn preprocessExampleTest compileExampleTest.dependsOn preprocessExampleTest
clean {
delete 'src/test/02-after-ros2rag/example/', 'src/test/03-after-relast/example/'
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment