From 0f00ad177133cc5d1e18e14dd6b405200cbaf256 Mon Sep 17 00:00:00 2001 From: Speiger Date: Wed, 20 Jan 2021 04:30:18 +0100 Subject: [PATCH] Logging improvements. -Added: Improved Logging to parsing & Building --- .../java/speiger/src/builder/base/ConditionedSegment.java | 6 +++--- src/main/java/speiger/src/builder/base/Template.java | 5 +++-- src/main/java/speiger/src/builder/processor/BuildTask.java | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/speiger/src/builder/base/ConditionedSegment.java b/src/main/java/speiger/src/builder/base/ConditionedSegment.java index ba65c72..f00723d 100644 --- a/src/main/java/speiger/src/builder/base/ConditionedSegment.java +++ b/src/main/java/speiger/src/builder/base/ConditionedSegment.java @@ -37,7 +37,7 @@ public class ConditionedSegment return builder.length() - length; } - public static int parse(String currentLine, List lines, int currentIndex, int startIndex, List segments) throws IllegalStateException + public static int parse(String fileName, String currentLine, List lines, int currentIndex, int startIndex, List segments) throws IllegalStateException { ConditionedSegment segment = new ConditionedSegment(startIndex); ICondition condition = ICondition.parse(currentLine); @@ -71,13 +71,13 @@ public class ConditionedSegment } else if(trimmed.startsWith("#if")) { - i += parse(trimmed.substring(3).trim(), lines, i, segmentText.length(), childSegments); + i += parse(fileName, trimmed.substring(3).trim(), lines, i, segmentText.length(), childSegments); } continue; } segmentText.add(s); } - throw new IllegalStateException("Unclosed #If found!"); + throw new IllegalStateException("Unclosed #If found in ["+fileName+"] at line ["+startIndex+"]"); } } diff --git a/src/main/java/speiger/src/builder/base/Template.java b/src/main/java/speiger/src/builder/base/Template.java index 05567ea..b5222e3 100644 --- a/src/main/java/speiger/src/builder/base/Template.java +++ b/src/main/java/speiger/src/builder/base/Template.java @@ -58,6 +58,7 @@ public class Template public static Template parse(Path file) throws IOException { + String fileName = FileUtils.getFileName(file.getFileName()); List segments = new ArrayList(); StringJoiner joiner = new StringJoiner("\n"); List lines = Files.readAllLines(file); @@ -69,7 +70,7 @@ public class Template { if(trimmed.startsWith("#if")) { - i += ConditionedSegment.parse(s.trim().substring(3).trim(), lines, i, joiner.length(), segments); + i += ConditionedSegment.parse(fileName, s.trim().substring(3).trim(), lines, i, joiner.length(), segments); continue; } else if(trimmed.startsWith("#symlink")) @@ -79,6 +80,6 @@ public class Template } joiner.add(s); } - return new Template(FileUtils.getFileName(file.getFileName()), joiner.toString(), segments); + return new Template(fileName, joiner.toString(), segments); } } diff --git a/src/main/java/speiger/src/builder/processor/BuildTask.java b/src/main/java/speiger/src/builder/processor/BuildTask.java index c4114cc..034f411 100644 --- a/src/main/java/speiger/src/builder/processor/BuildTask.java +++ b/src/main/java/speiger/src/builder/processor/BuildTask.java @@ -26,7 +26,7 @@ public class BuildTask implements Runnable @Override public void run() { - String s = template.build(process.parsePool, process.mappers, mappers != null, mappers[1]); + String s = template.build(process.parsePool, process.mappers, mappers != null, mappers != null ? mappers[1] : null); if(mappers != null) { mappers[0].addAll(process.mappers); @@ -38,6 +38,7 @@ public class BuildTask implements Runnable } catch(Exception e) { + e.printStackTrace(); } try(BufferedWriter writer = Files.newBufferedWriter(path)) {