only:refactoring BundleInfo
This commit is contained in:
parent
e96b678213
commit
431210dc00
|
@ -55,22 +55,20 @@ public class Autoupdate {
|
||||||
}
|
}
|
||||||
System.out.println("Handling parent folder name [" + bundleFullName + "]");
|
System.out.println("Handling parent folder name [" + bundleFullName + "]");
|
||||||
|
|
||||||
String[] bundleFullNameSplit = bundleFullName.split("\\.");
|
BundleUtil.BundleInfo bundleInfo = BundleUtil.parse(bundleFullName);
|
||||||
if (bundleFullNameSplit.length != 3)
|
String branchName = bundleInfo.getBranchName();
|
||||||
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")) {
|
if (args.length > 0 && args[0].equalsIgnoreCase("release")) {
|
||||||
System.out.println("Release update requested");
|
System.out.println("Release update requested");
|
||||||
downloadAndUnzipAutoupdate(bundleFullNameSplit, UpdateMode.ALWAYS, ConnectionAndMeta.BASE_URL_RELEASE);
|
downloadAndUnzipAutoupdate(bundleInfo, UpdateMode.ALWAYS, ConnectionAndMeta.BASE_URL_RELEASE);
|
||||||
} else {
|
} else {
|
||||||
UpdateMode mode = getMode();
|
UpdateMode mode = getMode();
|
||||||
if (mode != UpdateMode.NEVER) {
|
if (mode != UpdateMode.NEVER) {
|
||||||
System.out.println("Snapshot requested");
|
System.out.println("Snapshot requested");
|
||||||
if (branchName.equals("snapshot")) {
|
if (branchName.equals("snapshot")) {
|
||||||
downloadAndUnzipAutoupdate(bundleFullNameSplit, mode, ConnectionAndMeta.getBaseUrl());
|
downloadAndUnzipAutoupdate(bundleInfo, mode, ConnectionAndMeta.getBaseUrl());
|
||||||
} else {
|
} else {
|
||||||
downloadAndUnzipAutoupdate(bundleFullNameSplit, mode, String.format(ConnectionAndMeta.BASE_URL_LTS, branchName));
|
downloadAndUnzipAutoupdate(bundleInfo, mode, String.format(ConnectionAndMeta.BASE_URL_LTS, branchName));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Update mode: NEVER");
|
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 {
|
try {
|
||||||
String boardName = bundleFullNameSplit[2];
|
|
||||||
String suffix = FindFileHelper.isObfuscated() ? "_obfuscated_public" : "";
|
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);
|
ConnectionAndMeta connectionAndMeta = new ConnectionAndMeta(zipFileName).invoke(baseUrl);
|
||||||
System.out.println("Remote file " + zipFileName);
|
System.out.println("Remote file " + zipFileName);
|
||||||
System.out.println("Server has " + connectionAndMeta.getCompleteFileSize() + " from " + new Date(connectionAndMeta.getLastModified()));
|
System.out.println("Server has " + connectionAndMeta.getCompleteFileSize() + " from " + new Date(connectionAndMeta.getLastModified()));
|
||||||
|
@ -128,7 +125,7 @@ public class Autoupdate {
|
||||||
long completeFileSize = connectionAndMeta.getCompleteFileSize();
|
long completeFileSize = connectionAndMeta.getCompleteFileSize();
|
||||||
long lastModified = connectionAndMeta.getLastModified();
|
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);
|
AutoupdateUtil.downloadAutoupdateFile(zipFileName, connectionAndMeta, TITLE);
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@ import java.nio.file.InvalidPathException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class BundleUtil {
|
public class BundleUtil {
|
||||||
|
private static final char BUNDLE_TOKEN_SEPARATOR = '.';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return null in case of error
|
* @return null in case of error
|
||||||
*/
|
*/
|
||||||
|
@ -40,12 +42,42 @@ public class BundleUtil {
|
||||||
return getBundleTarget(readBundleFullName());
|
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) {
|
public static String getBundleTarget(String s) {
|
||||||
if (s == null)
|
return parse(s).getTarget();
|
||||||
return null;
|
}
|
||||||
int lastDot = s.lastIndexOf('.');
|
|
||||||
if (lastDot == -1)
|
public static class BundleInfo {
|
||||||
throw new IllegalStateException("Dot expected somewhere in [" + s + "]");
|
private final String branchName;
|
||||||
return s.substring(lastDot + 1);
|
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 + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,5 +7,7 @@ public class BundleUtilTest {
|
||||||
@Test
|
@Test
|
||||||
public void testExtractBundleTarget() {
|
public void testExtractBundleTarget() {
|
||||||
Assertions.assertEquals("proteus_f7", BundleUtil.getBundleTarget("rusefi.snapshot.proteus_f7"));
|
Assertions.assertEquals("proteus_f7", BundleUtil.getBundleTarget("rusefi.snapshot.proteus_f7"));
|
||||||
|
Assertions.assertEquals("snapshot", BundleUtil.parse("rusefi.snapshot.proteus_f7").getBranchName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue