From 40090f8cb26aee41e9c9fa529d8c72a47479bfb4 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Tue, 7 Jan 2025 19:52:41 -0500 Subject: [PATCH] release self-identification to become release.txt #7229 only:uaefi --- .../com/rusefi/autoupdate/Autoupdate.java | 8 +-- .../java/com/rusefi/core/ui/FrameHelper.java | 2 +- .../java/com/rusefi/core/io/BundleUtil.java | 66 +++++++++++-------- .../com/rusefi/core/io/BundleUtilTest.java | 8 ++- .../main/java/com/rusefi/ui/LogoHelper.java | 2 +- .../main/java/com/rusefi/StartupFrame.java | 4 +- .../main/java/com/rusefi/UiBundleUtil.java | 29 -------- .../com/rusefi/maintenance/StLinkFlasher.java | 2 +- 8 files changed, 52 insertions(+), 69 deletions(-) delete mode 100644 java_console/ui/src/main/java/com/rusefi/UiBundleUtil.java 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 73f476e11e..c80730a0fa 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 @@ -69,15 +69,11 @@ public class Autoupdate { } private static void autoupdate(String[] args) { - String bundleFullName = BundleUtil.readBundleFullName(); - if (bundleFullName == null) { + BundleUtil.BundleInfo bundleInfo = BundleUtil.readBundleFullNameNotNull(); + if (BundleUtil.BundleInfo.isUndefined(bundleInfo)) { log.error("ERROR: Autoupdate: unable to perform without bundleFullName (check parent folder name)"); System.exit(-1); } - log.info("Handling parent folder name [" + bundleFullName + "]"); - - BundleUtil.BundleInfo bundleInfo = BundleUtil.parse(bundleFullName); - // todo: huh unused? String branchName = bundleInfo.getBranchName(); @NotNull String firstArgument = args.length > 0 ? args[0] : ""; diff --git a/java_console/core_ui/src/main/java/com/rusefi/core/ui/FrameHelper.java b/java_console/core_ui/src/main/java/com/rusefi/core/ui/FrameHelper.java index 289a9b98ec..d2d96cb105 100644 --- a/java_console/core_ui/src/main/java/com/rusefi/core/ui/FrameHelper.java +++ b/java_console/core_ui/src/main/java/com/rusefi/core/ui/FrameHelper.java @@ -32,7 +32,7 @@ public class FrameHelper { @NotNull public static String appendBundleName(String title) { - String bundleName = BundleUtil.readBundleFullNameNotNull(); + String bundleName = BundleUtil.readBundleFullNameNotNull().getUiLabel(); return title + " " + bundleName; } diff --git a/java_console/shared_io/src/main/java/com/rusefi/core/io/BundleUtil.java b/java_console/shared_io/src/main/java/com/rusefi/core/io/BundleUtil.java index 78823930b6..87b217ba84 100644 --- a/java_console/shared_io/src/main/java/com/rusefi/core/io/BundleUtil.java +++ b/java_console/shared_io/src/main/java/com/rusefi/core/io/BundleUtil.java @@ -2,62 +2,66 @@ package com.rusefi.core.io; import com.devexperts.logging.Logging; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.nio.file.Path; -import java.nio.file.Paths; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; import java.nio.file.InvalidPathException; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; import static com.devexperts.logging.Logging.getLogging; public class BundleUtil { private static final Logging log = getLogging(BundleUtil.class); - private static final char BUNDLE_TOKEN_SEPARATOR = '.'; private static final String SNAPSHOT = "snapshot"; + private static final String BRANCH_REF_FILE = "release.txt"; /** * @return null in case of error */ - @Nullable - public static String readBundleFullName() { + public static List<@NotNull String> readBundleFullName() { + File f = new File(BRANCH_REF_FILE); + if (!f.exists()) { + log.error(BRANCH_REF_FILE + " not found"); + return null; + } try { - Path path = Paths.get("").toAbsolutePath(); - String fullName = path.getParent().getFileName().toString(); - if (fullName.length() < 3) - return null; // just paranoia check - return fullName; - } catch (InvalidPathException e) { + return Files.readAllLines(f.toPath()); + } catch (InvalidPathException | IOException e) { log.error("Error reading bundle name", e); return null; } } @NotNull - public static String readBundleFullNameNotNull() { - String bundle = readBundleFullName(); - bundle = bundle == null ? "unknown bundle" : bundle; - return bundle; + public static BundleInfo readBundleFullNameNotNull() { + List<@NotNull String> info = readBundleFullName(); + if (info == null) + return BundleInfo.UNKNOWN; + return parse(info); } public static String getBundleTarget() { - return getBundleTarget(readBundleFullName()); + return readBundleFullNameNotNull().getTarget(); } - public static BundleInfo parse(String bundleFullName) { - String[] bundleFullNameSplit = bundleFullName.split("\\" + BundleUtil.BUNDLE_TOKEN_SEPARATOR); - if (bundleFullNameSplit.length != 3) - throw new IllegalStateException("Unexpected parent folder name/bundleFullName [" + bundleFullName + "] exactly two dots expected"); - String branchName = bundleFullNameSplit[1]; - String target = bundleFullNameSplit[2]; + public static BundleInfo parse(List<@NotNull String> info) { + Map keyValues = new TreeMap(String.CASE_INSENSITIVE_ORDER); + for (String line : info) { + String pair[] = line.split("=", 2); + keyValues.put(pair[0], pair[1]); + } + String target = keyValues.get("target"); + String branchName = keyValues.get("release"); return new BundleInfo(branchName, target); } - public static String getBundleTarget(String s) { - return parse(s).getTarget(); - } - public static class BundleInfo { + static final BundleInfo UNKNOWN = new BundleInfo("unknown", "unknown"); + private final String branchName; private final String target; @@ -66,6 +70,10 @@ public class BundleUtil { this.target = target; } + public static boolean isUndefined(BundleInfo bundleInfo) { + return bundleInfo == UNKNOWN; + } + public String getBranchName() { return branchName; } @@ -85,5 +93,9 @@ public class BundleUtil { ", target='" + target + '\'' + '}'; } + + public String getUiLabel() { + return target + "." + branchName; + } } } diff --git a/java_console/shared_io/src/test/java/com/rusefi/core/io/BundleUtilTest.java b/java_console/shared_io/src/test/java/com/rusefi/core/io/BundleUtilTest.java index c4166f4e6a..5c59749f70 100644 --- a/java_console/shared_io/src/test/java/com/rusefi/core/io/BundleUtilTest.java +++ b/java_console/shared_io/src/test/java/com/rusefi/core/io/BundleUtilTest.java @@ -3,11 +3,15 @@ package com.rusefi.core.io; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.util.Arrays; + public class BundleUtilTest { @Test public void testExtractBundleTarget() { - Assertions.assertEquals("proteus_f7", BundleUtil.getBundleTarget("rusefi.snapshot.proteus_f7")); - Assertions.assertEquals("snapshot", BundleUtil.parse("rusefi.snapshot.proteus_f7").getBranchName()); + BundleUtil.BundleInfo info = BundleUtil.parse(Arrays.asList("target=proteus_f7", "release=development")); + + Assertions.assertEquals("proteus_f7", info.getTarget()); + Assertions.assertEquals("development", info.getBranchName()); } } diff --git a/java_console/trigger-ui/src/main/java/com/rusefi/ui/LogoHelper.java b/java_console/trigger-ui/src/main/java/com/rusefi/ui/LogoHelper.java index f00d2fa7aa..27e4e57352 100644 --- a/java_console/trigger-ui/src/main/java/com/rusefi/ui/LogoHelper.java +++ b/java_console/trigger-ui/src/main/java/com/rusefi/ui/LogoHelper.java @@ -26,7 +26,7 @@ public class LogoHelper { @Nullable public static ImageIcon getBundleSpecificIcon() { - String bundle = BundleUtil.readBundleFullNameNotNull(); + String bundle = BundleUtil.readBundleFullNameNotNull().getTarget(); String logoName; // these should be about 213px wide if (bundle.contains("proteus")) { diff --git a/java_console/ui/src/main/java/com/rusefi/StartupFrame.java b/java_console/ui/src/main/java/com/rusefi/StartupFrame.java index 2fcad20f1c..3f28680c8d 100644 --- a/java_console/ui/src/main/java/com/rusefi/StartupFrame.java +++ b/java_console/ui/src/main/java/com/rusefi/StartupFrame.java @@ -199,7 +199,7 @@ public class StartupFrame { JPanel rightPanel = new JPanel(new VerticalFlowLayout()); - if (BundleUtil.readBundleFullNameNotNull().contains("proteus_f7")) { + if (BundleUtil.readBundleFullNameNotNull().getTarget().contains("proteus_f7")) { String text = "WARNING: Proteus F7"; URLLabel urlLabel = new URLLabel(text, "https://github.com/rusefi/rusefi/wiki/F7-requires-full-erase"); new Timer(500, new ActionListener() { @@ -245,7 +245,7 @@ public class StartupFrame { jLabel.setForeground(Color.red); } else { final Date binaryModificationDate = new Date(binaryModificationTimestamp); - final String branchNameToDisplay = UiBundleUtil.readBranchNameToDisplay(); + final String branchNameToDisplay = BundleUtil.readBundleFullNameNotNull().getTarget(); jLabel = new JLabel(String.format( "
%s files
%s
", branchNameToDisplay, diff --git a/java_console/ui/src/main/java/com/rusefi/UiBundleUtil.java b/java_console/ui/src/main/java/com/rusefi/UiBundleUtil.java deleted file mode 100644 index 45b9961379..0000000000 --- a/java_console/ui/src/main/java/com/rusefi/UiBundleUtil.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.rusefi; - -import com.devexperts.logging.Logging; -import com.rusefi.core.io.BundleUtil; -import org.jetbrains.annotations.Nullable; - -import static com.devexperts.logging.Logging.getLogging; - -public class UiBundleUtil { - private static final Logging log = getLogging(BundleUtil.class); - /** - * @return null in case of error - */ - @Nullable - public static String readBranchNameToDisplay() { - final String bundleFullName = BundleUtil.readBundleFullName(); - if (bundleFullName != null) { - try { - final BundleUtil.BundleInfo bundleInfo = BundleUtil.parse(bundleFullName); - // TODO: get rid of the pornography below: - // we should use `development` instead of `snapshot` for master branch in bundle name. - return (bundleInfo.isMaster() ? "development" : bundleInfo.getBranchName()); - } catch (Throwable e) { - log.warn(String.format("We failed to parse bundle full name `%s`", bundleFullName), e); - } - } - return null; - } -} diff --git a/java_console/ui/src/main/java/com/rusefi/maintenance/StLinkFlasher.java b/java_console/ui/src/main/java/com/rusefi/maintenance/StLinkFlasher.java index 3c85b55d90..ad77c0c6f9 100644 --- a/java_console/ui/src/main/java/com/rusefi/maintenance/StLinkFlasher.java +++ b/java_console/ui/src/main/java/com/rusefi/maintenance/StLinkFlasher.java @@ -75,7 +75,7 @@ public class StLinkFlasher { @NotNull public static HwPlatform getHardwareKind() { - String bundle = BundleUtil.readBundleFullNameNotNull(); + String bundle = BundleUtil.readBundleFullNameNotNull().getTarget(); if (bundle.contains("h7")) return HwPlatform.H7; if (bundle.contains("f7"))