From b8a94478e606b1e717828adf392a8939e1ff60a4 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 17 Apr 2023 08:35:33 +0200 Subject: [PATCH] [Minor] code cleanup --- .../li/strolch/utils/helper/TexHelper.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/utils/src/main/java/li/strolch/utils/helper/TexHelper.java b/utils/src/main/java/li/strolch/utils/helper/TexHelper.java index 1a79dc425..84f2f5ec8 100644 --- a/utils/src/main/java/li/strolch/utils/helper/TexHelper.java +++ b/utils/src/main/java/li/strolch/utils/helper/TexHelper.java @@ -67,12 +67,15 @@ public class TexHelper { } // clean old builds - Arrays.asList(texPath.toFile().listFiles( - file -> (System.currentTimeMillis() - file.lastModified()) > TimeUnit.MINUTES.toMillis(1))) - .forEach(file -> { - logger.info("Deleting old path " + file); - FileHelper.deleteFile(file, false); - }); + File[] texFiles = texPath.toFile() + .listFiles( + file -> (System.currentTimeMillis() - file.lastModified()) > TimeUnit.MINUTES.toMillis(1)); + if (texFiles == null) + throw new IllegalStateException("No tex files found!"); + Arrays.asList(texFiles).forEach(file -> { + logger.info("Deleting old path " + file); + FileHelper.deleteFile(file, false); + }); // prepare a temporary directory by copying tex files File tmpPathF = texPath.resolve(StringHelper.getUniqueId()).toFile(); @@ -82,8 +85,8 @@ public class TexHelper { if (!FileHelper.copy(templatePath.getParentFile().listFiles(), tmpPathF, false)) throw new RuntimeException( - "Failed to copy " + templatePath.getParentFile().getAbsolutePath() + " to tmpPath " + tmpPathF - .getAbsolutePath()); + "Failed to copy " + templatePath.getParentFile().getAbsolutePath() + " to tmpPath " + + tmpPathF.getAbsolutePath()); // then write TEX file String texFileName = fileName + ".tex"; @@ -95,8 +98,8 @@ public class TexHelper { // do PDF generation String cmd = "pdflatex"; - ProcessHelper.ProcessResult processResult = ProcessHelper - .runCommand(tmpPathF, cmd, "-halt-on-error", "-file-line-error", texFileName); + ProcessHelper.ProcessResult processResult = ProcessHelper.runCommand(tmpPathF, cmd, "-halt-on-error", + "-file-line-error", texFileName); if (processResult.returnValue != 0) { logger.error(processResult.processOutput); throw new RuntimeException(