Skip to content

Commit 41c2647

Browse files
ctruedenhinerm
authored andcommitted
WIP: Refactor how sysprop fallback values are done
1 parent 0b6b0b1 commit 41c2647

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/main/java/net/imagej/ui/swing/updater/LauncherMigrator.java

+18-15
Original file line numberDiff line numberDiff line change
@@ -317,29 +317,28 @@ private void switchToNewLauncher() {
317317
// In order to trigger it successfully, we need to set various properties:
318318

319319
File appConfigFile = new File(configDir, appSlug + ".toml");
320-
File appUserConfigFile = new File(configDir, appSlug + ".cfg");
321320
List<String> lines;
322321
try {
323322
lines = Files.readAllLines(appConfigFile.toPath());
324323
}
325324
catch (IOException exc) {
326325
log.debug(exc);
327-
// Couldn't read from the config file; define some fallback values.
328-
lines = Arrays.asList(
329-
"-Dscijava.app.java-links='https://downloads.imagej.net/java/jdk-urls.txt',",
330-
"-Dscijava.app.java-version-minimum=8,",
331-
"-Dscijava.app.java-version-recommended=21,",
332-
"-Dscijava.app.config-file='" + appUserConfigFile.getPath() + "',"
333-
);
326+
// Couldn't read from the config file.
327+
lines = new ArrayList<>();
334328
}
329+
335330
setPropertyIfNull("scijava.app.name", appTitle);
331+
336332
Path splashImage = appDir.toPath().resolve("images").resolve("icon.png");
337333
setPropertyIfNull("scijava.app.splash-image", splashImage.toString());
338-
extractAndSetProperty("scijava.app.java-links", lines);
339-
extractAndSetProperty("scijava.app.java-version-minimum", lines);
340-
extractAndSetProperty("scijava.app.java-version-recommended", lines);
341-
extractAndSetProperty("scijava.app.config-file", lines);
342-
setPropertyIfNull("scijava.app.config-file", appUserConfigFile.getPath());
334+
335+
extractAndSetProperty("scijava.app.java-links", lines,
336+
"https://downloads.imagej.net/java/jdk-urls.txt");
337+
extractAndSetProperty("scijava.app.java-version-minimum", lines, "8");
338+
extractAndSetProperty("scijava.app.java-version-recommended", lines, "21");
339+
extractAndSetProperty("scijava.app.config-file", lines,
340+
new File(configDir, appSlug + ".cfg").getPath());
341+
343342
String platform = UpdaterUtil.getPlatform();
344343
// FIXME: I think the macOS platform will be wrong here. It needs -arm64 suffix!
345344
setPropertyIfNull("scijava.app.java-platform", platform);
@@ -509,13 +508,17 @@ private static void setPropertyIfNull(String name, String value) {
509508
if (System.getProperty(name) == null) System.setProperty(name, value);
510509
}
511510

512-
private static void extractAndSetProperty(String name, List<String> lines) {
511+
private static void extractAndSetProperty(
512+
String name,
513+
List<String> lines,
514+
String fallbackValue)
515+
{
513516
// No, the following replacement does not escape all problematic regex
514517
// characters. But the properties we're working with here are only
515518
// alphameric with dot separators, so it's OK. Hooray for pragmatism!
516519
String escaped = name.replaceAll("\\.", "\\\\.");
517520
Pattern p = Pattern.compile(".*'-D" + escaped + "=['\"]?(.*?)['\"]?,$");
518-
String value = null;
521+
String value = fallbackValue;
519522
for (String line : lines) {
520523
Matcher m = p.matcher(line);
521524
if (m.matches()) {

0 commit comments

Comments
 (0)