From 2cb900c69ff005b052e5bbe718b387daf4bf4289 Mon Sep 17 00:00:00 2001 From: melloware Date: Mon, 11 Nov 2024 10:54:36 -0500 Subject: [PATCH] Fix #167: Allow source folder to be any Path --- .../deployment/JasperReportsProcessor.java | 30 ++++++++++++------- .../deployment/item/ReportRootBuildItem.java | 12 ++++++-- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/deployment/src/main/java/io/quarkiverse/jasperreports/deployment/JasperReportsProcessor.java b/deployment/src/main/java/io/quarkiverse/jasperreports/deployment/JasperReportsProcessor.java index 13b4077..6612a96 100644 --- a/deployment/src/main/java/io/quarkiverse/jasperreports/deployment/JasperReportsProcessor.java +++ b/deployment/src/main/java/io/quarkiverse/jasperreports/deployment/JasperReportsProcessor.java @@ -466,9 +466,9 @@ void ignoreJacksonDeserialize(CombinedIndexBuildItem combinedIndex, @BuildStep ReportRootBuildItem defaultReportRoot(ReportBuildTimeConfig config) { if (config.build().enable()) { - return new ReportRootBuildItem(config.build().source().toString()); + return new ReportRootBuildItem(config.build().source()); } - return new ReportRootBuildItem(Constants.DEFAULT_SOURCE_PATH); + return new ReportRootBuildItem(Path.of(Constants.DEFAULT_SOURCE_PATH)); } /** @@ -489,15 +489,23 @@ void collectReportFiles(List reportRoots, BuildProducer compiledReportFileProducer, OutputTargetBuildItem outputTarget) { final AtomicInteger count = new AtomicInteger(0); for (ReportRootBuildItem reportRoot : reportRoots) { - final Path projectRoot = findProjectRoot(outputTarget.getOutputDirectory()); - if (projectRoot == null) { - Log.warnf("JasperReport Source Directory does not exist!"); - continue; + Path startDir = null; + // #167 allow an external directory so check if the core path exists first + if (Files.exists(reportRoot.getOriginalPath())) { + Log.debugf("JasperReport Source Directory: %s", reportRoot.getOriginalPath()); + startDir = reportRoot.getOriginalPath(); } - final Path startDir = projectRoot.resolve(Paths.get(reportRoot.getPath())).normalize(); - if (!Files.exists(startDir)) { - Log.warnf("JasperReport Source Directory: %s does not exist!", startDir); - continue; + if (startDir == null) { + final Path projectRoot = findProjectRoot(outputTarget.getOutputDirectory()); + if (projectRoot == null) { + Log.warnf("JasperReport Source Directory does not exist!"); + continue; + } + startDir = projectRoot.resolve(Paths.get(reportRoot.getPath())).normalize(); + if (!Files.exists(startDir)) { + Log.warnf("JasperReport Source Directory: %s does not exist!", startDir); + continue; + } } try { @@ -758,4 +766,4 @@ private static Path findProjectRoot(Path outputDirectory) { } } while (true); } -} +} \ No newline at end of file diff --git a/deployment/src/main/java/io/quarkiverse/jasperreports/deployment/item/ReportRootBuildItem.java b/deployment/src/main/java/io/quarkiverse/jasperreports/deployment/item/ReportRootBuildItem.java index 3a58040..bb94b37 100644 --- a/deployment/src/main/java/io/quarkiverse/jasperreports/deployment/item/ReportRootBuildItem.java +++ b/deployment/src/main/java/io/quarkiverse/jasperreports/deployment/item/ReportRootBuildItem.java @@ -1,5 +1,7 @@ package io.quarkiverse.jasperreports.deployment.item; +import java.nio.file.Path; + import io.quarkus.builder.item.MultiBuildItem; /** @@ -12,16 +14,22 @@ */ public final class ReportRootBuildItem extends MultiBuildItem { + private final Path originalPath; private final String path; - public ReportRootBuildItem(String path) { - this.path = normalize(path); + public ReportRootBuildItem(Path path) { + this.originalPath = path; + this.path = normalize(path.toString()); } public String getPath() { return path; } + public Path getOriginalPath() { + return originalPath; + } + static String normalize(String path) { path = path.strip(); if (path.startsWith("/")) {