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) {
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] : "";

View File

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

View File

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

View File

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

View File

@ -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")) {

View File

@ -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(
"<html><center>%s files<br/>%s</center></html>",
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
public static HwPlatform getHardwareKind() {
String bundle = BundleUtil.readBundleFullNameNotNull();
String bundle = BundleUtil.readBundleFullNameNotNull().getTarget();
if (bundle.contains("h7"))
return HwPlatform.H7;
if (bundle.contains("f7"))