From b11520e8176d2968520b06954d30f8588fd93d86 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Mon, 1 Apr 2024 19:35:19 -0400 Subject: [PATCH] only: better logging and better error handling --- .../com/rusefi/autoupdate/Autoupdate.java | 30 +++++++++++-------- .../java/com/rusefi/core/FindFileHelper.java | 2 +- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/java_console/autoupdate/src/main/java/com/rusefi/autoupdate/Autoupdate.java b/java_console/autoupdate/src/main/java/com/rusefi/autoupdate/Autoupdate.java index 8b554bdb01..3e4dd9c893 100644 --- a/java_console/autoupdate/src/main/java/com/rusefi/autoupdate/Autoupdate.java +++ b/java_console/autoupdate/src/main/java/com/rusefi/autoupdate/Autoupdate.java @@ -31,24 +31,28 @@ public class Autoupdate { public static void main(String[] args) { String bundleFullName = BundleUtil.readBundleFullName(); + if (bundleFullName == null) { + System.err.println("ERROR: Autoupdate: unable to perform without bundleFullName (parent folder name)"); + System.exit(-1); + } + System.out.println("Handling parent folder name" + bundleFullName); + + String[] bundleFullNameSplit = bundleFullName.split("\\."); + if (bundleFullNameSplit.length != 3) + throw new IllegalStateException("Unexpected parent folder name/bundleFullName [" + bundleFullName + "] exactly two dots expected"); + String branchName = bundleFullNameSplit[1]; if (args.length > 0 && args[0].equalsIgnoreCase("release")) { System.out.println("Release update requested"); - downloadAndUnzipAutoupdate(bundleFullName, UpdateMode.ALWAYS, ConnectionAndMeta.BASE_URL_RELEASE); + downloadAndUnzipAutoupdate(bundleFullNameSplit, UpdateMode.ALWAYS, ConnectionAndMeta.BASE_URL_RELEASE); } else { UpdateMode mode = getMode(); if (mode != UpdateMode.NEVER) { System.out.println("Snapshot requested"); - if (bundleFullName != null) { - System.out.println("Handling " + bundleFullName); - String branchName = bundleFullName.split("\\.")[1]; - if (branchName.equals("snapshot")) { - downloadAndUnzipAutoupdate(bundleFullName, mode, ConnectionAndMeta.BASE_URL_LATEST); - } else { - downloadAndUnzipAutoupdate(bundleFullName, mode, String.format(ConnectionAndMeta.BASE_URL_LTS, branchName)); - } + if (branchName.equals("snapshot")) { + downloadAndUnzipAutoupdate(bundleFullNameSplit, mode, ConnectionAndMeta.BASE_URL_LATEST); } else { - System.err.println("ERROR: Autoupdate: unable to perform without bundleFullName"); + downloadAndUnzipAutoupdate(bundleFullNameSplit, mode, String.format(ConnectionAndMeta.BASE_URL_LTS, branchName)); } } else { System.out.println("Update mode: NEVER"); @@ -82,9 +86,9 @@ public class Autoupdate { } } - private static void downloadAndUnzipAutoupdate(String bundleFullName, UpdateMode mode, String baseUrl) { + private static void downloadAndUnzipAutoupdate(String[] bundleFullNameSplit, UpdateMode mode, String baseUrl) { try { - String boardName = bundleFullName.split("\\.")[2]; + String boardName = bundleFullNameSplit[2]; String suffix = isObfuscated() ? "_obfuscated_public" : ""; String zipFileName = "rusefi_bundle_" + boardName + suffix + "_autoupdate" + ".zip"; ConnectionAndMeta connectionAndMeta = new ConnectionAndMeta(zipFileName).invoke(baseUrl); @@ -106,7 +110,7 @@ public class Autoupdate { long completeFileSize = connectionAndMeta.getCompleteFileSize(); long lastModified = connectionAndMeta.getLastModified(); - System.out.println(bundleFullName + " " + completeFileSize + " bytes, last modified " + new Date(lastModified)); + System.out.println(Arrays.toString(bundleFullNameSplit) + " " + completeFileSize + " bytes, last modified " + new Date(lastModified)); AutoupdateUtil.downloadAutoupdateFile(zipFileName, connectionAndMeta, TITLE); diff --git a/java_console/shared_io/src/main/java/com/rusefi/core/FindFileHelper.java b/java_console/shared_io/src/main/java/com/rusefi/core/FindFileHelper.java index 6e00b2a5fe..dfc43a78cb 100644 --- a/java_console/shared_io/src/main/java/com/rusefi/core/FindFileHelper.java +++ b/java_console/shared_io/src/main/java/com/rusefi/core/FindFileHelper.java @@ -13,7 +13,7 @@ public class FindFileHelper { File dir = new File(fileDirectory); if (!dir.isDirectory()) return null; - System.out.println("Searching for " + prefix + "*" + suffix + " in " + fileDirectory); + System.out.println("Searching for " + prefix + "*" + suffix + " in " + dir.getAbsolutePath()); for (String file : Objects.requireNonNull(dir.list())) { if (file.contains(" ")) continue; // spaces not acceptable