From 3ed0571f5dbb1696d089990c0ba74a5948e0c8de Mon Sep 17 00:00:00 2001 From: "e.vinogradovs" Date: Wed, 30 Oct 2019 16:54:17 +0200 Subject: [PATCH] Implemented run date time override for file name. --- .../java/jasquel/run/manager/RunManager.java | 18 ++++++++++++------ .../java/jasquel/server/JasquelServlet.java | 3 ++- src/main/java/jasquel/server/RunRequest.java | 2 ++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/jasquel/run/manager/RunManager.java b/src/main/java/jasquel/run/manager/RunManager.java index 0e9331a..d33cd67 100644 --- a/src/main/java/jasquel/run/manager/RunManager.java +++ b/src/main/java/jasquel/run/manager/RunManager.java @@ -38,16 +38,22 @@ public RunManager(File runDirectory) { runOutputFiles = new HashMap<>(); } - private synchronized File createSharedRunFile(String description) throws IOException { + private synchronized File createSharedRunFile(String description, LocalDateTime runDateTimeOverride) throws IOException { if (description == null) description = ""; else if (description.length() > 0) description = "-" + description.toLowerCase().replaceAll("[^a-z0-9-_\\.]", "_"); - LocalDateTime now = LocalDateTime.now(); + LocalDateTime runDateTime; - String baseName = now.format( + if(runDateTimeOverride != null) { + runDateTime = runDateTimeOverride; + } else { + runDateTime = LocalDateTime.now(); + } + + String baseName = runDateTime.format( DateTimeFormatter.ofPattern("yyyy_MM_dd-HH_mm_ss") ) + "%s%s.run"; @@ -68,13 +74,13 @@ else if (description.length() > 0) } - public ActiveRun startRun(boolean shared, String environment, String description) throws IOException { + public ActiveRun startRun(boolean shared, String environment, String description, LocalDateTime runDateTimeOverride) throws IOException { String id; File file = null; if (shared) { - file = createSharedRunFile(description); + file = createSharedRunFile(description, runDateTimeOverride); id = FilenameUtils.removeExtension(file.getName()); } else id = UUID.randomUUID().toString(); @@ -95,7 +101,7 @@ public ActiveRun startRun(boolean shared, String environment, String description } public ActiveRun startRun(String environment) throws IOException { - return startRun(false, environment, null); + return startRun(false, environment, null, null); } public void finishRun(ActiveRun run) { diff --git a/src/main/java/jasquel/server/JasquelServlet.java b/src/main/java/jasquel/server/JasquelServlet.java index b1a1afd..1737834 100644 --- a/src/main/java/jasquel/server/JasquelServlet.java +++ b/src/main/java/jasquel/server/JasquelServlet.java @@ -387,7 +387,8 @@ else if (!project.getEnvironmentList().contains(runRequest.environment)) ActiveRun run = runManager.startRun( runRequest.shared, runRequest.environment, - runRequest.description + runRequest.description, + runRequest.runDateTimeOverride ); FileRunner runner = new FileRunner( diff --git a/src/main/java/jasquel/server/RunRequest.java b/src/main/java/jasquel/server/RunRequest.java index b970218..dddbfad 100644 --- a/src/main/java/jasquel/server/RunRequest.java +++ b/src/main/java/jasquel/server/RunRequest.java @@ -5,6 +5,7 @@ */ package jasquel.server; +import java.time.LocalDateTime; import java.util.List; /** @@ -18,5 +19,6 @@ public class RunRequest { public int threads; public List paths; boolean shared; + LocalDateTime runDateTimeOverride; }