Skip to content

Commit eb47248

Browse files
committed
WIP: Refactor how sysprop fallback values are done
1 parent 6cfcad4 commit eb47248

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
@@ -316,29 +316,28 @@ private void switchToNewLauncher() {
316316
// In order to trigger it successfully, we need to set various properties:
317317

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

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

0 commit comments

Comments
 (0)