Skip to content

Commit

Permalink
CreateManifest supports the --cache-dir parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
edvin committed May 7, 2016
1 parent 9234bc6 commit 66bb5e0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
15 changes: 12 additions & 3 deletions src/main/java/fxlauncher/CreateManifest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

Expand All @@ -22,17 +23,25 @@ public static void main(String[] args) throws IOException {
if (args.length > 3) {
// Parse named parameters
List<String> rawParams = new ArrayList<>();
for (int i = 3; i < args.length; i++)
rawParams.add(args[i]);
rawParams.addAll(Arrays.asList(args).subList(3, args.length));
ParametersImpl params = new ParametersImpl(rawParams);
Map<String, String> named = params.getNamed();

// Configure cacheDir
if (named != null && named.containsKey("cache-dir"))
manifest.cacheDir = named.get("cache-dir");

// Append the rest as manifest parameters
StringBuilder rest = new StringBuilder();
for (String raw : params.getRaw()) {
if (raw.startsWith("--cache-dir=")) continue;
if (rest.length() > 0) rest.append(" ");
rest.append(raw);
}

// Add the raw parameter string to the manifest
manifest.parameters = args[3];
if (rest.length() > 0)
manifest.parameters = rest.toString();
}

JAXB.marshal(manifest, appPath.resolve("app.xml").toFile());
Expand Down
21 changes: 13 additions & 8 deletions src/main/java/fxlauncher/FXManifest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,28 @@ public Path resolveCacheDir(Map<String, String> namedParams) {

Path path;

if (cacheDir.startsWith("USERLIB/")) {
if (cacheDir.contains("USERLIB")) {
String replacement;
switch (OS.current) {
case mac:
path = Paths.get(System.getProperty("user.home"))
replacement = Paths.get(System.getProperty("user.home"))
.resolve("Library")
.resolve("Application Support")
.resolve(cacheDir.substring(8));
.resolve(cacheDir.substring(8))
.toString();
break;
case win:
path = Paths.get(System.getProperty("user.home"))
replacement = Paths.get(System.getProperty("user.home"))
.resolve("AppData")
.resolve(cacheDir.substring(8));
.resolve(cacheDir.substring(8))
.toString();
break;
default:
path = Paths.get(System.getProperty("user.home"))
.resolve("." + cacheDir.substring(8));
replacement = Paths.get(System.getProperty("user.home"))
.resolve("." + cacheDir.substring(8))
.toString();
}
path = Paths.get(replacement);
} else {
path = Paths.get(cacheDir);
}
Expand All @@ -88,7 +93,7 @@ public Path resolveCacheDir(Map<String, String> namedParams) {
}
}

return Paths.get(cacheDir);
return path;
}

public boolean equals(Object o) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/fxlauncher/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public void start(Stage primaryStage) throws Exception {
updateManifest();
createUpdateWrapper();
Path cacheDir = manifest.resolveCacheDir(getParameters().getNamed());
log.info(String.format("Using cache dir %s", cacheDir));
syncFiles(cacheDir);
} catch (Exception ex) {
log.log(Level.WARNING, String.format("Error during %s phase", phase), ex);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fxlauncher/LauncherParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public LauncherParams(Application.Parameters delegate, FXManifest manifest) {
if (arg.startsWith("--") && arg.contains("=")) {
String argname = arg.substring(0, arg.indexOf("="));
if (rawArgs.stream().filter(a -> a.startsWith(argname)).findAny().isPresent())
continue;
continue;
}

rawArgs.add(arg);
Expand Down

0 comments on commit 66bb5e0

Please sign in to comment.