only:refactoring BundleInfo

This commit is contained in:
rusefillc 2024-05-30 10:37:19 -04:00
parent e96b678213
commit 431210dc00
3 changed files with 48 additions and 17 deletions

View File

@ -55,22 +55,20 @@ public class Autoupdate {
}
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];
BundleUtil.BundleInfo bundleInfo = BundleUtil.parse(bundleFullName);
String branchName = bundleInfo.getBranchName();
if (args.length > 0 && args[0].equalsIgnoreCase("release")) {
System.out.println("Release update requested");
downloadAndUnzipAutoupdate(bundleFullNameSplit, UpdateMode.ALWAYS, ConnectionAndMeta.BASE_URL_RELEASE);
downloadAndUnzipAutoupdate(bundleInfo, UpdateMode.ALWAYS, ConnectionAndMeta.BASE_URL_RELEASE);
} else {
UpdateMode mode = getMode();
if (mode != UpdateMode.NEVER) {
System.out.println("Snapshot requested");
if (branchName.equals("snapshot")) {
downloadAndUnzipAutoupdate(bundleFullNameSplit, mode, ConnectionAndMeta.getBaseUrl());
downloadAndUnzipAutoupdate(bundleInfo, mode, ConnectionAndMeta.getBaseUrl());
} else {
downloadAndUnzipAutoupdate(bundleFullNameSplit, mode, String.format(ConnectionAndMeta.BASE_URL_LTS, branchName));
downloadAndUnzipAutoupdate(bundleInfo, mode, String.format(ConnectionAndMeta.BASE_URL_LTS, branchName));
}
} else {
System.out.println("Update mode: NEVER");
@ -104,11 +102,10 @@ public class Autoupdate {
}
}
private static void downloadAndUnzipAutoupdate(String[] bundleFullNameSplit, UpdateMode mode, String baseUrl) {
private static void downloadAndUnzipAutoupdate(BundleUtil.BundleInfo info, UpdateMode mode, String baseUrl) {
try {
String boardName = bundleFullNameSplit[2];
String suffix = FindFileHelper.isObfuscated() ? "_obfuscated_public" : "";
String zipFileName = "rusefi_bundle_" + boardName + suffix + "_autoupdate" + ".zip";
String zipFileName = "rusefi_bundle_" + info.getTarget() + suffix + "_autoupdate" + ".zip";
ConnectionAndMeta connectionAndMeta = new ConnectionAndMeta(zipFileName).invoke(baseUrl);
System.out.println("Remote file " + zipFileName);
System.out.println("Server has " + connectionAndMeta.getCompleteFileSize() + " from " + new Date(connectionAndMeta.getLastModified()));
@ -128,7 +125,7 @@ public class Autoupdate {
long completeFileSize = connectionAndMeta.getCompleteFileSize();
long lastModified = connectionAndMeta.getLastModified();
System.out.println(Arrays.toString(bundleFullNameSplit) + " " + completeFileSize + " bytes, last modified " + new Date(lastModified));
System.out.println(info + " " + completeFileSize + " bytes, last modified " + new Date(lastModified));
AutoupdateUtil.downloadAutoupdateFile(zipFileName, connectionAndMeta, TITLE);

View File

@ -12,6 +12,8 @@ import java.nio.file.InvalidPathException;
import java.util.Date;
public class BundleUtil {
private static final char BUNDLE_TOKEN_SEPARATOR = '.';
/**
* @return null in case of error
*/
@ -40,12 +42,42 @@ public class BundleUtil {
return getBundleTarget(readBundleFullName());
}
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];
return new BundleInfo(branchName, target);
}
public static String getBundleTarget(String s) {
if (s == null)
return null;
int lastDot = s.lastIndexOf('.');
if (lastDot == -1)
throw new IllegalStateException("Dot expected somewhere in [" + s + "]");
return s.substring(lastDot + 1);
return parse(s).getTarget();
}
public static class BundleInfo {
private final String branchName;
private final String target;
public BundleInfo(String branchName, String target) {
this.branchName = branchName;
this.target = target;
}
public String getBranchName() {
return branchName;
}
public String getTarget() {
return target;
}
@Override
public String toString() {
return "BundleInfo{" +
"branchName='" + branchName + '\'' +
", target='" + target + '\'' +
'}';
}
}
}

View File

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