From b275092654e08342699c311c8780b67a3613ad30 Mon Sep 17 00:00:00 2001 From: Patrick Ackermann Date: Tue, 19 Nov 2024 10:33:37 +0100 Subject: [PATCH] Revert "Copy models always to temp" This reverts commit 08de82a5e142b870ff0ee49cca965e2dce97383e. --- .../lk2dxf/mapping/ObjectMapper.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/java/ch/geowerkstatt/lk2dxf/mapping/ObjectMapper.java b/src/main/java/ch/geowerkstatt/lk2dxf/mapping/ObjectMapper.java index e484fc8..678a2ef 100644 --- a/src/main/java/ch/geowerkstatt/lk2dxf/mapping/ObjectMapper.java +++ b/src/main/java/ch/geowerkstatt/lk2dxf/mapping/ObjectMapper.java @@ -308,21 +308,17 @@ private static TransferDescription getTransferDescription() throws Ili2cExceptio // prepare path to models from resources var resourceUri = ObjectMapper.class.getResource(MODELS_RESOURCE).toURI(); - tempDir = Files.createTempDirectory("lk2dxf_"); - iliModelsPath = tempDir.toString().replace("\\", "/"); if (resourceUri.getScheme().equals("jar")) { + tempDir = Files.createTempDirectory("lk2dxf_"); try (var fs = FileSystems.newFileSystem(resourceUri, Collections.emptyMap()); var sourceFiles = Files.walk(fs.getPath(MODELS_RESOURCE)).filter(Files::isRegularFile)) { for (var source : sourceFiles.toArray(Path[]::new)) { Files.copy(source, Paths.get(tempDir.toString(), source.getFileName().toString())); } } + iliModelsPath = tempDir.toString().replace("\\", "/"); } else { - try (var sourceFiles = Files.walk(Paths.get(resourceUri))) { - for (var source : sourceFiles.toArray(Path[]::new)) { - Files.copy(source, Paths.get(tempDir.toString(), source.getFileName().toString())); - } - } + iliModelsPath = resourceUri.getPath().replaceFirst("^/", ""); } try { @@ -331,8 +327,10 @@ private static TransferDescription getTransferDescription() throws Ili2cExceptio var ili2cConfig = modelManager.getConfig(requiredModels, 0.0); return Ili2c.runCompiler(ili2cConfig); } finally { - try (var stream = Files.walk(tempDir)) { - stream.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); + if (tempDir != null) { + try (var stream = Files.walk(tempDir)) { + stream.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); + } } } }