Skip to content

Commit

Permalink
fixed Java 8 support on Windows #131
Browse files Browse the repository at this point in the history
This also adds some new integration tests for installers
  • Loading branch information
shannah committed Jul 14, 2024
1 parent f072d2b commit 17a0195
Show file tree
Hide file tree
Showing 32 changed files with 805 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ installer/jdeploy-bundle
cli/bin
tests/projects/*/jdeploy
./jdeploy
#./installer/tests/*/mock_launcher*
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ public File findInstallFilesDir() {
}

System.out.println("Found client4.launcher.path property: "+launcherPath);
cachedInstallFilesDir = findInstallFilesDir(new File(launcherPath));
if (System.getProperty("client4j.appxml.path") != null) {
cachedInstallFilesDir = findInstallFilesDir(new File(System.getProperty("client4j.appxml.path")).getParentFile());
} else {
cachedInstallFilesDir = findInstallFilesDir(new File(launcherPath));
}

return cachedInstallFilesDir;
} else {
System.out.println("client4j.launcher.path is not set");
Expand Down Expand Up @@ -261,6 +266,9 @@ private String getDefaultWebsiteUrl(String packageName, String source) throws Un


public File findAppXml() {
if (System.getProperty("client4j.appxml.path") != null) {
return new File(System.getProperty("client4j.appxml.path"));
}
File installFilesDir = findInstallFilesDir();
if (installFilesDir == null) {
return null;
Expand Down
44 changes: 30 additions & 14 deletions installer/src/main/java/ca/weblite/jdeploy/installer/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ private void loadThemeByName(String themeName) throws IOException, ClassNotFound


private void loadNPMPackageInfo() throws IOException {
//System.out.println("Loading NPMPackageInfo");
if (installationSettings.getNpmPackageVersion() == null) {
if (appInfo() == null) {
throw new IllegalStateException("App Info must be loaded before loading the package info");
Expand Down Expand Up @@ -144,12 +143,20 @@ private void loadNPMPackageInfo() throws IOException {
appInfo().setDocumentTypeEditor(documentTypeAssociation.getExtension());
}
}
//System.out.println("Checking npm package for URL schemes: ");
for (String scheme : npmPackageVersion().getUrlSchemes()) {
//System.out.println("Found scheme "+scheme);
appInfo().addUrlScheme(scheme);
}

if (Platform.getSystemPlatform().isWindows() && "8".equals(npmPackageVersion().getJavaVersion())) {
// In Windows with Java 8, we need to use a private JVM because OpenJDK 8 didn't support the use
// of shared JVMs very well. Share JVMs needed to be registered in the registry, which would override
// for all applications using a shard JVM - there is no way to allow the app to be a good citizen
// with a shared JVM.
// However it does allow the use of a private JVM if the app resided in a directory named "bin"
// and the JVM is in a directory named "jre" which is a sibling of the "bin" directory.
appInfo().setUsePrivateJVM(true);
}

// Update labels for the combobox with nice examples to show exactly which versions will be auto-updated
// to with the given setting.
AutoUpdateSettings.MinorOnly.setLabel(
Expand Down Expand Up @@ -326,17 +333,20 @@ public static void main(String[] args) {
headlessInstall = true;
}

File logFile = new File(System.getProperty("user.home") + File.separator + ".jdeploy" + File.separator + "log" + File.separator + "jdeploy-installer.log");
logFile.getParentFile().mkdirs();
try {
PrintStream originalOut = System.out;
System.setOut(new PrintStream(new FileOutputStream(logFile)));
originalOut.println("Redirecting output to "+logFile);
System.setErr(System.out);
} catch (IOException ex) {
System.err.println("Failed to redirect output to "+logFile);
ex.printStackTrace(System.err);
if (!headlessInstall) {
File logFile = new File(System.getProperty("user.home") + File.separator + ".jdeploy" + File.separator + "log" + File.separator + "jdeploy-installer.log");
logFile.getParentFile().mkdirs();
try {
PrintStream originalOut = System.out;
System.setOut(new PrintStream(new FileOutputStream(logFile)));
originalOut.println("Redirecting output to "+logFile);
System.setErr(System.out);
} catch (IOException ex) {
System.err.println("Failed to redirect output to "+logFile);
ex.printStackTrace(System.err);
}
}

Main main = headlessInstall ? new Main(new HeadlessInstallationSettings()) :new Main();
main.run();
}
Expand Down Expand Up @@ -510,7 +520,13 @@ private void run0() throws Exception {
if (appInfo().getNpmVersion() != null && appInfo().getNpmVersion().startsWith("0.0.0-")) {
version = appInfo().getNpmVersion();
}
UninstallWindows uninstallWindows = new UninstallWindows(appInfo().getNpmPackage(), appInfo().getNpmSource(), version, appInfo().getTitle(), installer);
UninstallWindows uninstallWindows = new UninstallWindows(
appInfo().getNpmPackage(),
appInfo().getNpmSource(),
version,
appInfo().getTitle(),
installer
);
uninstallWindows.uninstall();
System.out.println("Uninstall complete");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.ArrayList;

public class NPMPackageVersion {
private static final String DEFAULT_JAVA_VERSION = "11";
private final NPMPackage npmPackage;
private final String version;
private final JSONObject packageJson;
Expand Down Expand Up @@ -36,7 +37,12 @@ public String getVersion() {
return version;
}


public String getJavaVersion() {
if (jdeploy().has("javaVersion")) {
return jdeploy().getString("javaVersion");
}
return DEFAULT_JAVA_VERSION;
}

private JSONObject jdeploy() {
return packageJson.getJSONObject("jdeploy");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,13 @@ private void registerFileExtension(String ext) {
if (mimetype != null) {
registrySetStringValue(HKEY_CURRENT_USER, key, "ContentType", mimetype);
if (mimetype.contains("/")) {
registrySetStringValue(HKEY_CURRENT_USER, key, "PerceivedType", mimetype.substring(0, mimetype.indexOf("/")));
registrySetStringValue(
HKEY_CURRENT_USER,
key,
"PerceivedType",
mimetype.substring(0, mimetype.indexOf("/")
)
);
}
}
}
Expand Down Expand Up @@ -458,7 +464,8 @@ public static void rollback(File backupLog) throws IOException {
Scanner scanner = new Scanner(backupLog, "UTF-8");
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
// If we added a key, we wrote them to the log file as comments of the form ;CREATE key where key is like Software\Classes\...
// If we added a key, we wrote them to the log file as comments of the form
// ;CREATE key where key is like Software\Classes\...
if (line.startsWith(";CREATE ")) {
deleteKeyRecursive(line.substring(line.indexOf(" ")+1));
}
Expand Down Expand Up @@ -667,7 +674,12 @@ public void register() throws IOException {
}

// Register the application
registrySetStringValue(HKEY_CURRENT_USER, "Software\\RegisteredApplications", getRegisteredAppName(), getCapabilitiesPath());
registrySetStringValue(
HKEY_CURRENT_USER,
"Software\\RegisteredApplications",
getRegisteredAppName(),
getCapabilitiesPath()
);

// Now to register the uninstaller

Expand All @@ -679,7 +691,12 @@ public void register() throws IOException {
registrySetStringValue(HKEY_CURRENT_USER, getUninstallKey(), "DisplayVersion", appInfo.getVersion());
registrySetLongValue(HKEY_CURRENT_USER, getUninstallKey(), 1);
registrySetStringValue(HKEY_CURRENT_USER, getUninstallKey(), "Publisher", appInfo.getVendor());
registrySetStringValue(HKEY_CURRENT_USER, getUninstallKey(), "UninstallString", "\""+getUninstallerPath().getAbsolutePath()+"\" uninstall");
registrySetStringValue(
HKEY_CURRENT_USER,
getUninstallKey(),
"UninstallString",
"\"" + getUninstallerPath().getAbsolutePath() + "\" uninstall"
);

String installerPath = System.getProperty("client4j.launcher.path");
if (installerPath == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ private Iterable<File> getVersionDirectories() {
List<File> out = new ArrayList<>();
if (version == null && getPackagePath().exists()) {
for (File child : getPackagePath().listFiles()) {
if (child.isDirectory() && !child.getName().isEmpty() && Character.isDigit(child.getName().charAt(0))) {
if (
child.isDirectory() &&
!child.getName().isEmpty() &&
Character.isDigit(child.getName().charAt(0)) &&
!child.getName().startsWith("0.0.0-")
) {
out.add(child);
}
}
Expand All @@ -133,13 +138,37 @@ private Iterable<File> getVersionDirectories() {
private void deletePackage() throws IOException {
for (File versionDir : getVersionDirectories()) {
if (versionDir.exists()) {
System.out.println("Deleting version dir: "+versionDir.getAbsolutePath());
FileUtils.deleteDirectory(versionDir);
}
}
}

private void cleanupPackageDir() throws IOException {
File packageDir = getPackagePath();
if (version != null) {
packageDir = packageDir.getParentFile();
}
if (packageDir.getName().equals("packages")) {
return;
}
if (packageDir.exists()) {
int numVersionDirectoriesRemaining = 0;
for (File child : packageDir.listFiles()) {
if (child.isDirectory()) {
numVersionDirectoriesRemaining++;
}
}
if (numVersionDirectoriesRemaining == 0) {
System.out.println("Deleting package dir: "+packageDir.getAbsolutePath());
FileUtils.deleteDirectory(packageDir);
}
}
}

private void deleteApp() throws IOException {
if (getAppDirPath().exists()) {
System.out.println("Deleting app dir: "+getAppDirPath().getAbsolutePath());
FileUtils.deleteDirectory(getAppDirPath());
}
}
Expand All @@ -159,18 +188,21 @@ private void scheduleDeleteUninstaller() throws IOException {

private void removeDesktopAlias() {
if (getDesktopLink().exists()) {
System.out.println("Deleting desktop link: "+getDesktopLink().getAbsolutePath());
getDesktopLink().delete();
}
}

private void removeStartMenuLink() {
if (getStartMenuLink().exists()) {
System.out.println("Deleting start menu link: "+getStartMenuLink().getAbsolutePath());
getStartMenuLink().delete();
}
}

private void removeProgramsMenuLink() {
if (getProgramsMenuLink().exists()) {
System.out.println("Deleting programs menu link: "+getProgramsMenuLink().getAbsolutePath());
getProgramsMenuLink().delete();
}
}
Expand All @@ -181,6 +213,7 @@ public void uninstall() throws IOException {
removeProgramsMenuLink();
removeStartMenuLink();
deletePackage();
cleanupPackageDir();
deleteApp();
installWindowsRegistry.unregister(null);
File uninstallerJDeployFiles = new File(getUninstallerPath().getParentFile(), ".jdeploy-files");
Expand Down
15 changes: 15 additions & 0 deletions installer/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -e
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
function test_shellmarks() {
cd $SCRIPTPATH
bash test_install_single_project.sh shellmarks --build --smoke --uninstall --uninstall-smoke
}

function test_snapcodejava() {
cd $SCRIPTPATH
bash test_install_single_project.sh snapcodejava --smoke --uninstall --uninstall-smoke
}

test_shellmarks
test_snapcodejava
Loading

0 comments on commit 17a0195

Please sign in to comment.