Skip to content

Commit

Permalink
added dmg command
Browse files Browse the repository at this point in the history
  • Loading branch information
shannah committed Oct 4, 2024
1 parent a46e8d1 commit 73f9370
Show file tree
Hide file tree
Showing 19 changed files with 528 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ installer/jdeploy-bundle
cli/bin
tests/projects/*/jdeploy
./jdeploy
./.idea
./.idea/jarRepositories.xml
./.idea/vcs.xml
#./installer/tests/*/mock_launcher*
147 changes: 123 additions & 24 deletions cli/src/main/java/ca/weblite/jdeploy/JDeploy.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import ca.weblite.jdeploy.app.AppInfo;
import ca.weblite.jdeploy.app.JVMSpecification;
import ca.weblite.jdeploy.appbundler.Bundler;
import ca.weblite.jdeploy.appbundler.BundlerCall;
import ca.weblite.jdeploy.appbundler.BundlerResult;
import ca.weblite.jdeploy.appbundler.BundlerSettings;
import ca.weblite.jdeploy.appbundler.mac.DmgCreator;
import ca.weblite.jdeploy.cli.controllers.*;
import ca.weblite.jdeploy.di.JDeployModule;
import ca.weblite.jdeploy.factories.JDeployKeyProviderFactory;
Expand All @@ -19,6 +22,7 @@
import ca.weblite.jdeploy.npm.NPM;
import ca.weblite.jdeploy.services.*;
import ca.weblite.tools.io.*;
import ca.weblite.tools.platform.Platform;
import ca.weblite.tools.security.KeyProvider;
import com.codename1.io.JSONParser;
import com.codename1.processing.Result;
Expand All @@ -34,6 +38,7 @@
import java.nio.file.attribute.PosixFilePermission;
import java.util.*;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
Expand Down Expand Up @@ -83,6 +88,8 @@ public class JDeploy {

private static final String BUNDLE_MAC_X64 = "mac-x64";
private static final String BUNDLE_MAC_ARM64 = "mac-arm64";
private static final String BUNDLE_MAC_X64_DMG = "mac-x64-dmg";
private static final String BUNDLE_MAC_ARM64_DMG = "mac-arm64-dmg";
private static final String BUNDLE_WIN = "win";
private static final String BUNDLE_LINUX = "linux";

Expand Down Expand Up @@ -1609,44 +1616,104 @@ private void loadAppInfo(AppInfo appInfo) throws IOException {

}

public void macIntelBundle(BundlerSettings bundlerSettings) throws Exception {
bundle(BUNDLE_MAC_X64, bundlerSettings);
public BundlerResult macIntelBundle(BundlerSettings bundlerSettings) throws Exception {
return bundle(BUNDLE_MAC_X64, bundlerSettings);
}

public void macArmBundle(BundlerSettings bundlerSettings) throws Exception {
bundle(BUNDLE_MAC_ARM64, bundlerSettings);
public BundlerResult macIntelBundle(
BundlerSettings bundlerSettings,
String overrideDestDir,
String overrideReleaseDir
) throws Exception {
return bundle(BUNDLE_MAC_X64, bundlerSettings, overrideDestDir, overrideReleaseDir);
}

public void windowsBundle(BundlerSettings bundlerSettings) throws Exception {
bundle("win", bundlerSettings);
public BundlerResult macArmBundle(BundlerSettings bundlerSettings) throws Exception {
return bundle(BUNDLE_MAC_ARM64, bundlerSettings);
}
public void linuxBundle(BundlerSettings bundlerSettings) throws Exception {
bundle("linux", bundlerSettings);

public BundlerResult macArmBundle(
BundlerSettings bundlerSettings,
String overrideDestDir,
String overrideReleaseDir
) throws Exception {
return bundle(BUNDLE_MAC_ARM64, bundlerSettings, overrideDestDir, overrideReleaseDir);
}

public void macArmDmg(BundlerSettings bundlerSettings, File destDir) throws Exception {
dmg(bundlerSettings, destDir, ".aarch64.dmg", (bundlerSettings1, bundleDestDir, bundleReleaseDir) -> {
return macArmBundle(bundlerSettings1, bundleDestDir, bundleReleaseDir);
});
}

public void macIntelDmg(BundlerSettings bundlerSettings, File destDir) throws Exception {
dmg(bundlerSettings, destDir, "-x86_64.dmg", (bundlerSettings1, bundleDestDir, bundleReleaseDir) -> {
return macIntelBundle(bundlerSettings1, bundleDestDir, bundleReleaseDir);
});
}

public void dmg(
BundlerSettings bundlerSettings,
File destDir,
String suffix,
BundlerCall bundlerCall
) throws Exception {
File tmpDir = File.createTempFile("jdeploy", "dmg");
tmpDir.delete();
tmpDir.mkdirs();
try {

BundlerResult bundleResult = bundlerCall.bundle(
bundlerSettings,
tmpDir.getAbsolutePath(),
tmpDir.getAbsolutePath()
);
String appName = bundleResult.getOutputFile().getName();
String appNameWithoutExtension = appName.substring(0, appName.lastIndexOf("."));
String dmgName = appNameWithoutExtension + suffix;
DmgCreator.createDmg(
bundleResult.getOutputFile().getAbsolutePath(),
new File(destDir, dmgName).getAbsolutePath()
);

} finally {
FileUtils.deleteDirectory(tmpDir);
}
}

public void windowsInstallerBundle(BundlerSettings bundlerSettings) throws Exception {
bundle("win-installer", bundlerSettings);

public BundlerResult windowsBundle(BundlerSettings bundlerSettings) throws Exception {
return bundle("win", bundlerSettings);
}
public BundlerResult linuxBundle(BundlerSettings bundlerSettings) throws Exception {
return bundle("linux", bundlerSettings);
}

public BundlerResult windowsInstallerBundle(BundlerSettings bundlerSettings) throws Exception {
return bundle("win-installer", bundlerSettings);
}

public void linuxInstallerBundle(BundlerSettings bundlerSettings) throws Exception {
bundle("linux-installer", bundlerSettings);
public BundlerResult linuxInstallerBundle(BundlerSettings bundlerSettings) throws Exception {
return bundle("linux-installer", bundlerSettings);
}

public void allBundles(BundlerSettings bundlerSettings) throws Exception {
public Map<String,BundlerResult> allBundles(BundlerSettings bundlerSettings) throws Exception {
Set<String> bundles = bundles();
Map<String, BundlerResult> results = new HashMap<>();
if (bundles.contains("mac") || bundles.contains(BUNDLE_MAC_X64)) {
macIntelBundle(bundlerSettings);
results.put(BUNDLE_MAC_X64, macIntelBundle(bundlerSettings));
}
if (bundles.contains(BUNDLE_MAC_ARM64)) {
macArmBundle(bundlerSettings);
results.put(BUNDLE_MAC_ARM64, macArmBundle(bundlerSettings));
}
if (bundles.contains(BUNDLE_WIN)) {
windowsBundle(bundlerSettings);
results.put(BUNDLE_WIN, windowsBundle(bundlerSettings));
}
if (bundles.contains(BUNDLE_LINUX)) {
linuxBundle(bundlerSettings);
results.put(BUNDLE_LINUX, linuxBundle(bundlerSettings));
}

return results;
}

public void allInstallers() throws Exception {
Expand All @@ -1665,23 +1732,36 @@ public void allInstallers(BundlerSettings bundlerSettings) throws Exception {
}
}

public void bundle(String target) throws Exception {
bundle(target, new BundlerSettings());
public BundlerResult bundle(String target) throws Exception {
return bundle(target, new BundlerSettings());
}

public void bundle(String target, BundlerSettings bundlerSettings) throws Exception {
public BundlerResult bundle(
String target,
BundlerSettings bundlerSettings
) throws Exception {
return bundle(target, bundlerSettings, null, null);
}

public BundlerResult bundle(
String target,
BundlerSettings bundlerSettings,
String overrideDestDir,
String overrideReleaseDir
) throws Exception {
AppInfo appInfo = new AppInfo();
loadAppInfo(appInfo);
if (bundlerSettings.getSource() != null) {
appInfo.setNpmSource(bundlerSettings.getSource());
}

Bundler.runit(
return Bundler.runit(
bundlerSettings,
appInfo,
appInfo.getAppURL().toString(),
target, "jdeploy" + File.separator + "bundles",
"jdeploy" + File.separator + "releases"
target,
overrideDestDir == null ? "jdeploy" + File.separator + "bundles" : overrideDestDir,
overrideReleaseDir == null ? "jdeploy" + File.separator + "releases" : overrideReleaseDir
);
}

Expand Down Expand Up @@ -1728,6 +1808,22 @@ public void installer(String target, String version, BundlerSettings bundlerSett
_newName = _newName.replace("${{ platform }}", BUNDLE_MAC_ARM64);
installerZip = new File(installerDir, _newName + ".tar");
FileUtils.copyInputStreamToFile(JDeploy.class.getResourceAsStream("/jdeploy-installer-mac-arm64.tar"), installerZip);
} else if (target.equals(BUNDLE_MAC_ARM64_DMG)) {
if (!Platform.getSystemPlatform().isMac()) {
out.println("DMG bundling is only supported on macOS. Skipping DMG generation");
return;
}

macArmDmg(bundlerSettings, installerDir);
return;
} else if (target.equals(BUNDLE_MAC_X64_DMG)) {
if (!Platform.getSystemPlatform().isMac()) {
out.println("DMG bundling is only supported on macOS. Skipping DMG generation");
return;
}

macIntelDmg(bundlerSettings, installerDir);
return;
} else if (target.equals(BUNDLE_WIN)) {
_newName = _newName.replace("${{ platform }}", "win-x64");
installerZip = new File(installerDir, _newName + ".exe");
Expand Down Expand Up @@ -2607,7 +2703,10 @@ public static void main(String[] args) {
}
}

if ("cheerpj".equals(args[0])) {
if ("dmg".equals(args[0])) {
prog.overrideInstallers(BUNDLE_MAC_X64_DMG, BUNDLE_MAC_ARM64_DMG);
prog.allInstallers();
} else if ("cheerpj".equals(args[0])) {
String[] cheerpjArgs = new String[args.length-1];
System.arraycopy(args, 1, cheerpjArgs, 0, cheerpjArgs.length);
prog.cheerpjCLI(cheerpjArgs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class AppDescription {
private String macBundleId;
private boolean enableMacCodeSigning;
private boolean enableMacNotarization;

private String macCertificateName;
private String macDeveloperID;
private String macNotarizationPassword;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ca.weblite.jdeploy.appbundler;

public interface BundlerCall {
public BundlerResult bundle(BundlerSettings settings, String destDir, String releaseDir) throws Exception;
}
Loading

0 comments on commit 73f9370

Please sign in to comment.