release self-identification to become release.txt #7229

only:uaefi
This commit is contained in:
rusefillc 2025-01-07 19:52:41 -05:00 committed by rusefillc
parent 6c3a286b71
commit 40090f8cb2
8 changed files with 52 additions and 69 deletions

View File

@ -69,15 +69,11 @@ public class Autoupdate {
} }
private static void autoupdate(String[] args) { private static void autoupdate(String[] args) {
String bundleFullName = BundleUtil.readBundleFullName(); BundleUtil.BundleInfo bundleInfo = BundleUtil.readBundleFullNameNotNull();
if (bundleFullName == null) { if (BundleUtil.BundleInfo.isUndefined(bundleInfo)) {
log.error("ERROR: Autoupdate: unable to perform without bundleFullName (check parent folder name)"); log.error("ERROR: Autoupdate: unable to perform without bundleFullName (check parent folder name)");
System.exit(-1); 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] : ""; @NotNull String firstArgument = args.length > 0 ? args[0] : "";

View File

@ -32,7 +32,7 @@ public class FrameHelper {
@NotNull @NotNull
public static String appendBundleName(String title) { public static String appendBundleName(String title) {
String bundleName = BundleUtil.readBundleFullNameNotNull(); String bundleName = BundleUtil.readBundleFullNameNotNull().getUiLabel();
return title + " " + bundleName; return title + " " + bundleName;
} }

View File

@ -2,62 +2,66 @@ package com.rusefi.core.io;
import com.devexperts.logging.Logging; import com.devexperts.logging.Logging;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.nio.file.Path; import java.io.File;
import java.nio.file.Paths; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.InvalidPathException; import java.nio.file.InvalidPathException;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import static com.devexperts.logging.Logging.getLogging; import static com.devexperts.logging.Logging.getLogging;
public class BundleUtil { public class BundleUtil {
private static final Logging log = getLogging(BundleUtil.class); 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 SNAPSHOT = "snapshot";
private static final String BRANCH_REF_FILE = "release.txt";
/** /**
* @return null in case of error * @return null in case of error
*/ */
@Nullable public static List<@NotNull String> readBundleFullName() {
public static String readBundleFullName() { File f = new File(BRANCH_REF_FILE);
if (!f.exists()) {
log.error(BRANCH_REF_FILE + " not found");
return null;
}
try { try {
Path path = Paths.get("").toAbsolutePath(); return Files.readAllLines(f.toPath());
String fullName = path.getParent().getFileName().toString(); } catch (InvalidPathException | IOException e) {
if (fullName.length() < 3)
return null; // just paranoia check
return fullName;
} catch (InvalidPathException e) {
log.error("Error reading bundle name", e); log.error("Error reading bundle name", e);
return null; return null;
} }
} }
@NotNull @NotNull
public static String readBundleFullNameNotNull() { public static BundleInfo readBundleFullNameNotNull() {
String bundle = readBundleFullName(); List<@NotNull String> info = readBundleFullName();
bundle = bundle == null ? "unknown bundle" : bundle; if (info == null)
return bundle; return BundleInfo.UNKNOWN;
return parse(info);
} }
public static String getBundleTarget() { public static String getBundleTarget() {
return getBundleTarget(readBundleFullName()); return readBundleFullNameNotNull().getTarget();
} }
public static BundleInfo parse(String bundleFullName) { public static BundleInfo parse(List<@NotNull String> info) {
String[] bundleFullNameSplit = bundleFullName.split("\\" + BundleUtil.BUNDLE_TOKEN_SEPARATOR); Map<String, String> keyValues = new TreeMap(String.CASE_INSENSITIVE_ORDER);
if (bundleFullNameSplit.length != 3) for (String line : info) {
throw new IllegalStateException("Unexpected parent folder name/bundleFullName [" + bundleFullName + "] exactly two dots expected"); String pair[] = line.split("=", 2);
String branchName = bundleFullNameSplit[1]; keyValues.put(pair[0], pair[1]);
String target = bundleFullNameSplit[2]; }
String target = keyValues.get("target");
String branchName = keyValues.get("release");
return new BundleInfo(branchName, target); return new BundleInfo(branchName, target);
} }
public static String getBundleTarget(String s) {
return parse(s).getTarget();
}
public static class BundleInfo { public static class BundleInfo {
static final BundleInfo UNKNOWN = new BundleInfo("unknown", "unknown");
private final String branchName; private final String branchName;
private final String target; private final String target;
@ -66,6 +70,10 @@ public class BundleUtil {
this.target = target; this.target = target;
} }
public static boolean isUndefined(BundleInfo bundleInfo) {
return bundleInfo == UNKNOWN;
}
public String getBranchName() { public String getBranchName() {
return branchName; return branchName;
} }
@ -85,5 +93,9 @@ public class BundleUtil {
", target='" + target + '\'' + ", target='" + target + '\'' +
'}'; '}';
} }
public String getUiLabel() {
return target + "." + branchName;
}
} }
} }

View File

@ -3,11 +3,15 @@ package com.rusefi.core.io;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.Arrays;
public class BundleUtilTest { public class BundleUtilTest {
@Test @Test
public void testExtractBundleTarget() { public void testExtractBundleTarget() {
Assertions.assertEquals("proteus_f7", BundleUtil.getBundleTarget("rusefi.snapshot.proteus_f7")); BundleUtil.BundleInfo info = BundleUtil.parse(Arrays.asList("target=proteus_f7", "release=development"));
Assertions.assertEquals("snapshot", BundleUtil.parse("rusefi.snapshot.proteus_f7").getBranchName());
Assertions.assertEquals("proteus_f7", info.getTarget());
Assertions.assertEquals("development", info.getBranchName());
} }
} }

View File

@ -26,7 +26,7 @@ public class LogoHelper {
@Nullable @Nullable
public static ImageIcon getBundleSpecificIcon() { public static ImageIcon getBundleSpecificIcon() {
String bundle = BundleUtil.readBundleFullNameNotNull(); String bundle = BundleUtil.readBundleFullNameNotNull().getTarget();
String logoName; String logoName;
// these should be about 213px wide // these should be about 213px wide
if (bundle.contains("proteus")) { if (bundle.contains("proteus")) {

View File

@ -199,7 +199,7 @@ public class StartupFrame {
JPanel rightPanel = new JPanel(new VerticalFlowLayout()); JPanel rightPanel = new JPanel(new VerticalFlowLayout());
if (BundleUtil.readBundleFullNameNotNull().contains("proteus_f7")) { if (BundleUtil.readBundleFullNameNotNull().getTarget().contains("proteus_f7")) {
String text = "WARNING: Proteus F7"; String text = "WARNING: Proteus F7";
URLLabel urlLabel = new URLLabel(text, "https://github.com/rusefi/rusefi/wiki/F7-requires-full-erase"); URLLabel urlLabel = new URLLabel(text, "https://github.com/rusefi/rusefi/wiki/F7-requires-full-erase");
new Timer(500, new ActionListener() { new Timer(500, new ActionListener() {
@ -245,7 +245,7 @@ public class StartupFrame {
jLabel.setForeground(Color.red); jLabel.setForeground(Color.red);
} else { } else {
final Date binaryModificationDate = new Date(binaryModificationTimestamp); final Date binaryModificationDate = new Date(binaryModificationTimestamp);
final String branchNameToDisplay = UiBundleUtil.readBranchNameToDisplay(); final String branchNameToDisplay = BundleUtil.readBundleFullNameNotNull().getTarget();
jLabel = new JLabel(String.format( jLabel = new JLabel(String.format(
"<html><center>%s files<br/>%s</center></html>", "<html><center>%s files<br/>%s</center></html>",
branchNameToDisplay, branchNameToDisplay,

View File

@ -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;
}
}

View File

@ -75,7 +75,7 @@ public class StLinkFlasher {
@NotNull @NotNull
public static HwPlatform getHardwareKind() { public static HwPlatform getHardwareKind() {
String bundle = BundleUtil.readBundleFullNameNotNull(); String bundle = BundleUtil.readBundleFullNameNotNull().getTarget();
if (bundle.contains("h7")) if (bundle.contains("h7"))
return HwPlatform.H7; return HwPlatform.H7;
if (bundle.contains("f7")) if (bundle.contains("f7"))