Skip to content

Commit

Permalink
added support for custom jdeployHome.
Browse files Browse the repository at this point in the history
Added integration test for launcher
  • Loading branch information
Steve Hannah committed Jul 23, 2024
1 parent 710e2f0 commit 4aa6be0
Show file tree
Hide file tree
Showing 16 changed files with 294 additions and 14 deletions.
45 changes: 44 additions & 1 deletion cli/src/main/java/ca/weblite/jdeploy/JDeploy.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,18 @@ public Map getPackageJsonMap() {
if (packageJsonMap == null) {
try {
JSONParser p = new JSONParser();
packageJsonMap = (Map)p.parseJSON(new StringReader(FileUtils.readFileToString(getPackageJsonFile(), "UTF-8")));
packageJsonMap = (Map)p.parseJSON(
new StringReader(
FileUtils.readFileToString(getPackageJsonFile(),
"UTF-8"
)
)
);
if (packageJsonMap.containsKey("jdeploy")) {
((Map)packageJsonMap.get("jdeploy")).putAll(getJdeployConfigOverrides());
} else {
packageJsonMap.put("jdeploy", getJdeployConfigOverrides());
}
} catch (IOException ex) {
Logger.getLogger(JDeploy.class.getName()).log(Level.SEVERE, null, ex);
throw new RuntimeException(ex);
Expand All @@ -280,6 +291,24 @@ public Map getPackageJsonMap() {
return packageJsonMap;
}

private Map<String,?> getJdeployConfigOverrides() {
Map<String,?> overrides = new HashMap<String,Object>();
if (System.getenv("JDEPLOY_CONFIG") != null) {
System.out.println("Found JDEPLOY_CONFIG environment variable");
System.out.println("Injecting jdeploy config overrides from environment variable");
System.out.println(System.getenv("JDEPLOY_CONFIG"));
try {
JSONParser p = new JSONParser();
Map m = (Map)p.parseJSON(new StringReader(System.getenv("JDEPLOY_CONFIG")));
overrides.putAll(m);
} catch (IOException ex) {
Logger.getLogger(JDeploy.class.getName()).log(Level.SEVERE, null, ex);
}
}

return overrides;
}

/**
* Get package.json root object as a map.
*/
Expand Down Expand Up @@ -1509,6 +1538,20 @@ private void loadAppInfo(AppInfo appInfo) throws IOException {
appInfo.setJVMSpecification(jvmSpec);
}

if (mj().get("jdeployHome") != null) {
System.out.println("Setting jdeployHome to "+rj().getAsString("jdeployHome"));
appInfo.setJdeployHome(rj().getAsString("jdeployHome"));
}
if (mj().get("jdeployHomeLinux") != null) {
appInfo.setLinuxJdeployHome(rj().getAsString("jdeployHomeLinux"));
}
if (mj().get("jdeployHomeMac") != null) {
appInfo.setMacJdeployHome(rj().getAsString("jdeployHomeMac"));
}
if (mj().get("jdeployHomeWindows") != null) {
appInfo.setWindowsJdeployHome(rj().getAsString("jdeployHomeWindows"));
}

String jarPath = getString("jar", null);
if (jarPath != null) {
JarFile jarFile = new JarFile(new File(directory, toNativePath(jarPath)));
Expand Down
51 changes: 50 additions & 1 deletion shared/src/main/java/ca/weblite/jdeploy/app/AppInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ public class AppInfo {
private String windowsInstallerUrl;
private String linuxInstallerUrl;
private String githubRepositoryUrl;

private String macJdeployHome;

private String windowsJdeployHome;

private String linuxJdeployHome;

private String jdeployHome;
private String tagLine;
private String title;
private String description;
Expand Down Expand Up @@ -175,6 +183,38 @@ public void setMacAppBundleId(String macAppBundleId) {
}
}

public void setMacJdeployHome(String macJdeployHome) {
this.macJdeployHome = macJdeployHome;
}

public String getMacJdeployHome() {
return macJdeployHome;
}

public void setWindowsJdeployHome(String windowsJdeployHome) {
this.windowsJdeployHome = windowsJdeployHome;
}

public String getWindowsJdeployHome() {
return windowsJdeployHome;
}

public void setLinuxJdeployHome(String linuxJdeployHome) {
this.linuxJdeployHome = linuxJdeployHome;
}

public String getLinuxJdeployHome() {
return linuxJdeployHome;
}

public void setJdeployHome(String jdeployHome) {
this.jdeployHome = jdeployHome;
}

public String getJdeployHome() {
return jdeployHome;
}

public CodeSignSettings getCodeSignSettings() {
return codeSignSettings;
}
Expand Down Expand Up @@ -1257,6 +1297,11 @@ public AppInfo copy() {
}
}

out.jdeployHome = jdeployHome;
out.macJdeployHome = macJdeployHome;
out.windowsJdeployHome = windowsJdeployHome;
out.linuxJdeployHome = linuxJdeployHome;

return out;
}

Expand Down Expand Up @@ -1354,7 +1399,11 @@ private boolean equalsImpl(AppInfo o) {
macAppBundleId, o.macAppBundleId,
npmPackage, o.npmPackage,
npmVersion, o.npmVersion,
npmAllowPrerelease, o.npmAllowPrerelease
npmAllowPrerelease, o.npmAllowPrerelease,
jdeployHome, o.jdeployHome,
macJdeployHome, o.macJdeployHome,
windowsJdeployHome, o.windowsJdeployHome,
linuxJdeployHome, o.linuxJdeployHome,

});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public class AppDescription {

private File bundleJre;

private String jDeployHome;

private String jDeployHomeWindows;
private String jDeployHomeMac;
private String jDeployHomeLinux;

public AppDescription() {

jars = new ArrayList<Jar>();
Expand Down Expand Up @@ -305,4 +311,38 @@ public void setBundleJre(File bundleJre) {
public File getBundleJre() {
return bundleJre;
}


public String getjDeployHome() {
return jDeployHome;
}

public void setjDeployHome(String jDeployHome) {
this.jDeployHome = jDeployHome;
}

public String getjDeployHomeWindows() {
return jDeployHomeWindows;
}

public void setjDeployHomeWindows(String jDeployHomeWindows) {
this.jDeployHomeWindows = jDeployHomeWindows;
}

public String getjDeployHomeMac() {
return jDeployHomeMac;
}

public void setjDeployHomeMac(String jDeployHomeMac) {
this.jDeployHomeMac = jDeployHomeMac;
}

public String getjDeployHomeLinux() {
return jDeployHomeLinux;
}

public void setjDeployHomeLinux(String jDeployHomeLinux) {
this.jDeployHomeLinux = jDeployHomeLinux;
}

}
14 changes: 14 additions & 0 deletions shared/src/main/java/ca/weblite/jdeploy/appbundler/Bundler.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ private static AppDescription createAppDescription(AppInfo appInfo, String url)
app.setFork(appInfo.isFork());
URL iconURL = URLUtil.url(appInfo.getAppURL(), "icon.png");
app.setIconDataURI(toDataURI(iconURL));
app.setjDeployHome(appInfo.getJdeployHome());
app.setjDeployHomeLinux(appInfo.getLinuxJdeployHome());
app.setjDeployHomeMac(appInfo.getMacJdeployHome());
app.setjDeployHomeWindows(appInfo.getWindowsJdeployHome());

if (url == null) throw new IllegalArgumentException("URL is required. It can be a file: url");

Expand Down Expand Up @@ -228,6 +232,16 @@ private static void setupBundledJVM(AppInfo appInfo, AppDescription app, Target
)
);

if (app.getNpmVersion() != null && !app.getNpmVersion().isEmpty()) {
// Add a qualifier to the version so that auto updates don't go beyond
// what the bundled VM can handle
app.setNpmVersion(app.getNpmVersion() + "[" +
(jvmSpecification.jdk? "jdk" : "jre") +
jvmSpecification.javaVersion +
(jvmSpecification.javafx ? "fx" : "") +
"]");
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
import java.net.URL;
import java.nio.file.Paths;
import java.text.MessageFormat;
import java.util.Iterator;
import java.util.Scanner;
import java.util.*;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
Expand Down Expand Up @@ -238,21 +237,32 @@ private static void processAppXml(AppDescription app, File contentsDir) throws E
app.setIconDataURI("");
}
if (app.getNpmPackage() != null && app.getNpmVersion() != null) {

out.start("app",
"name", app.getName(),
"package", app.getNpmPackage(),
"source", app.getNpmSource(),
"version", app.getNpmVersion(),
"icon", app.getIconDataURI(),
"prerelease", app.isNpmPrerelease() ? "true" : "false",
"fork", ""+app.isFork()
).end();
out.start("app", getNpmAppAttributes(app)).end();
} else {
out.start("app", "name", app.getName(), "url", app.getUrl(), "icon", app.getIconDataURI()).end();
}
out.close();
}

private static String[] getNpmAppAttributes(AppDescription app) {

List<String> atts = new ArrayList<String>(Arrays.asList(new String[] {
"name", app.getName(),
"package", app.getNpmPackage(),
"source", app.getNpmSource(),
"version", app.getNpmVersion(),
"icon", app.getIconDataURI(),
"prerelease", app.isNpmPrerelease() ? "true" : "false",
"fork", ""+app.isFork()
}));

if (app.getjDeployHome() != null || app.getjDeployHomeMac() != null) {
atts.add("jdeploy-home");
atts.add(app.getjDeployHomeMac() == null ? app.getjDeployHome() : app.getjDeployHomeMac());
}

return atts.toArray(new String[0]);
}

private static void createThumbnail(File f, File contentsDir, int size) throws IOException {
Thumbnails.of(f)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added tests/projects/LauncherTest1/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions tests/projects/LauncherTest1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"bin": {
"jdeploy-it-test-project": "jdeploy-bundle/jdeploy.js"
},
"author": "",
"description": "jDeploy Integration Test Project",
"main": "index.js",
"preferGlobal": true,
"repository": "",
"source": "https://github.com/shannah/jdeploy-it-test-project",
"version": "0.0.0-master",
"jdeploy": {
"jdk": false,
"javaVersion": "17",
"jar": "target/jdeploy-it-test-project-1.0-SNAPSHOT.jar",
"javafx": false,
"title": "Jdeploy It Test Project",
"bundles": [
"mac-arm64"
],
"commitHash": "f5ebc668b69b2b0b12e7e2ead2b75d56be3efe3b"
},
"dependencies": {
"command-exists-promise": "^2.0.2",
"node-fetch": "2.6.7",
"shelljs": "^0.8.4",
"tar": "^4.4.8",
"yauzl": "^2.10.0"
},
"license": "ISC",
"name": "jdeploy-it-test-project",
"files": [
"jdeploy-bundle"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
}
}
Binary file added tests/projects/LauncherTest1/target/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 4aa6be0

Please sign in to comment.