Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 57 additions & 21 deletions cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,29 @@
</executions>
</plugin>


<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>src/test/java/</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
<version>3.0.0-M8</version>
</plugin>


</plugins>
</build>
<dependencies>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.14</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.14</version>
</dependency>


<dependency>
<groupId>ca.weblite</groupId>
<artifactId>jdeploy-shared</artifactId>
Expand Down Expand Up @@ -172,7 +172,7 @@
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20211205</version>
<version>20231013</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.codeworth/PanelMatic -->
Expand Down Expand Up @@ -234,17 +234,42 @@

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.2.0</version>
<artifactId>junit-jupiter</artifactId>
<version>5.9.3</version>
<scope>test</scope>
</dependency>

<!-- JUnit Vintage Engine to run JUnit 4 tests -->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.9.3</version>
<scope>test</scope>
</dependency>

<!-- JUnit 4 (for JUnit 4 tests) -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>

<!-- Mockito Core -->
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.2.0</version>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.11.0</version>
<scope>test</scope>
</dependency>

<!-- Mockito JUnit Jupiter Integration -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>4.11.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcpkix-jdk15on -->
<dependency>
<groupId>org.bouncycastle</groupId>
Expand Down Expand Up @@ -285,7 +310,18 @@
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
<url>file://${basedir}/../maven-repository</url>
<url>file://${project.basedir}/../maven-repository</url>
</repository>
<repository>
<id>central</id>
<name>Maven Central</name>
<url>https://repo.maven.apache.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>sci-java</id>
Expand Down
10 changes: 10 additions & 0 deletions cli/src/main/java/ca/weblite/jdeploy/BundleConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ca.weblite.jdeploy;

public interface BundleConstants {
public static final String BUNDLE_MAC_X64 = "mac-x64";
public static final String BUNDLE_MAC_ARM64 = "mac-arm64";
public static final String BUNDLE_MAC_X64_DMG = "mac-x64-dmg";
public static final String BUNDLE_MAC_ARM64_DMG = "mac-arm64-dmg";
public static final String BUNDLE_WIN = "win";
public static final String BUNDLE_LINUX = "linux";
}
142 changes: 48 additions & 94 deletions cli/src/main/java/ca/weblite/jdeploy/JDeploy.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import ca.weblite.jdeploy.factories.JDeployKeyProviderFactory;
import ca.weblite.jdeploy.gui.JDeployMainMenu;
import ca.weblite.jdeploy.gui.JDeployProjectEditor;
import ca.weblite.jdeploy.helpers.GithubReleaseNotesMutator;
import ca.weblite.jdeploy.helpers.PackageInfoBuilder;
import ca.weblite.jdeploy.helpers.PrereleaseHelper;
import ca.weblite.jdeploy.npm.NPM;
Expand All @@ -38,7 +39,6 @@
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 @@ -78,21 +78,14 @@
*
* @author shannah
*/
public class JDeploy {
public class JDeploy implements BundleConstants {
static {
System.setProperty("apple.laf.useScreenMenuBar", "true");
System.setProperty("apple.eawt.quitStrategy", "CLOSE_ALL_WINDOWS");
}

private static final int DEFAULT_JAVA_VERSION = 11;

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";

private boolean alwaysClean = !Boolean.getBoolean("jdeploy.doNotClean");
private boolean alwaysPackageOnPublish = !Boolean.getBoolean("jdeploy.doNotPackage");
private boolean doNotStripJavaFXFiles;
Expand Down Expand Up @@ -1642,22 +1635,23 @@ public BundlerResult macArmBundle(
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) -> {
public BundlerResult macArmDmg(BundlerSettings bundlerSettings, File destDir, String suffix) throws Exception {
return dmg(bundlerSettings, destDir, suffix, BUNDLE_MAC_ARM64_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) -> {
public BundlerResult macIntelDmg(BundlerSettings bundlerSettings, File destDir, String suffix) throws Exception {
return dmg(bundlerSettings, destDir, suffix, BUNDLE_MAC_X64_DMG, (bundlerSettings1, bundleDestDir, bundleReleaseDir) -> {
return macIntelBundle(bundlerSettings1, bundleDestDir, bundleReleaseDir);
});
}

public void dmg(
public BundlerResult dmg(
BundlerSettings bundlerSettings,
File destDir,
String suffix,
String bundleType,
BundlerCall bundlerCall
) throws Exception {
if (bundlerSettings.getSource() == null && System.getenv("JDEPLOY_SOURCE") != null){
Expand All @@ -1677,10 +1671,16 @@ public void dmg(
String appName = bundleResult.getOutputFile().getName();
String appNameWithoutExtension = appName.substring(0, appName.lastIndexOf("."));
String dmgName = appNameWithoutExtension + suffix;
File dmgFile = new File(destDir, dmgName);
DmgCreator.createDmg(
bundleResult.getOutputFile().getAbsolutePath(),
new File(destDir, dmgName).getAbsolutePath()
dmgFile.getAbsolutePath()
);
BundlerResult newResult = new BundlerResult(bundleType);
newResult.setOutputFile(dmgFile);
bundleResult.setResultForType(bundleType, newResult);

return bundleResult;

} finally {
FileUtils.deleteDirectory(tmpDir);
Expand Down Expand Up @@ -1806,13 +1806,15 @@ public void installer(String target, String version, BundlerSettings bundlerSett
installerDir.mkdirs();

String _newName = appInfo.getTitle() + " Installer-${{ platform }}";
String dmgSuffix = "-${{ platform }}";
String versionStr = appInfo.getNpmVersion();
if (versionStr.startsWith("0.0.0-")) {
versionStr = "@" + versionStr.substring("0.0.0-".length());
}
if (appInfo.getJdeployBundleCode() != null) {
_newName += "-"+versionStr+"_"+appInfo.getJdeployBundleCode();
}
dmgSuffix += "-"+versionStr + ".dmg";

File installerZip;
if (target.equals("mac") || target.equals(BUNDLE_MAC_X64)) {
Expand All @@ -1828,16 +1830,17 @@ public void installer(String target, String version, BundlerSettings bundlerSett
out.println("DMG bundling is only supported on macOS. Skipping DMG generation");
return;
}

macArmDmg(bundlerSettings, installerDir);
dmgSuffix = dmgSuffix.replace("${{ platform }}", BUNDLE_MAC_ARM64);
macArmDmg(bundlerSettings, installerDir, dmgSuffix);
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);
dmgSuffix = dmgSuffix.replace("${{ platform }}", BUNDLE_MAC_X64);
macIntelDmg(bundlerSettings, installerDir, dmgSuffix);
return;
} else if (target.equals(BUNDLE_WIN)) {
_newName = _newName.replace("${{ platform }}", "win-x64");
Expand Down Expand Up @@ -2133,82 +2136,7 @@ private File getGithubReleaseFilesDir() {
}

private String createGithubReleaseNotes() {
final String repo = System.getenv("GITHUB_REPOSITORY");
final String releasesPrefix = "/releases/download/";
final String branchTag = System.getenv("GITHUB_REF_NAME");
final String refType = System.getenv("GITHUB_REF_TYPE");
final File releaseFilesDir = getGithubReleaseFilesDir();
final Optional<File> macIntelBundle = Arrays.asList(
releaseFilesDir.listFiles((dir, name) -> name.contains(BUNDLE_MAC_X64))
).stream().findFirst();
final Optional<File> macArmBundle = Arrays.asList(
releaseFilesDir.listFiles((dir, name) -> name.contains(BUNDLE_MAC_ARM64))
).stream().findFirst();
final Optional<File> winBundle = Arrays.asList(
releaseFilesDir.listFiles((dir, name) -> name.contains(BUNDLE_WIN))
).stream().findFirst();
final Optional<File> linuxBundle = Arrays.asList(
releaseFilesDir.listFiles((dir, name) -> name.contains(BUNDLE_LINUX))
).stream().findFirst();
StringBuilder notes = new StringBuilder();
notes.append("## Application Installers");
if ("branch".equals(refType)) {
notes.append(" for latest snapshot of ").append(branchTag).append(" branch");
} else {
notes.append(" latest release");
}
notes.append("\n\n");

if (macArmBundle.isPresent()) {
notes.append("* [Mac (Apple Silicon)](https://github.com/")
.append(repo).append(releasesPrefix).append(branchTag).append("/")
.append(urlencodeFileNameForGithubRelease(macArmBundle.get().getName())).append(")\n");
}
if (macIntelBundle.isPresent()) {
notes.append("* [Mac (Intel)](https://github.com/")
.append(repo).append(releasesPrefix).append(branchTag).append("/")
.append(urlencodeFileNameForGithubRelease(macIntelBundle.get().getName())).append(")\n");
}
if (winBundle.isPresent()) {
notes.append("* [Windows (x64)](https://github.com/")
.append(repo).append(releasesPrefix).append(branchTag).append("/")
.append(urlencodeFileNameForGithubRelease(winBundle.get().getName())).append(")\n");
}
if (linuxBundle.isPresent()) {
notes.append("* [Linux (x64)](https://github.com/")
.append(repo).append(releasesPrefix).append(branchTag).append("/")
.append(urlencodeFileNameForGithubRelease(linuxBundle.get().getName())).append(")\n");
}

if ("branch".equals(refType)) {
notes.append("\nOr launch app installer via command-line on Linux, Mac, or Windows:\n\n");
notes.append("```bash\n");
notes.append("/bin/bash -c \"$(curl -fsSL https://www.jdeploy.com/gh/")
.append(repo).append("/").append(branchTag).append("/install.sh)\"\n");
notes.append("```\n");
notes.append("\nSee [download page](https://www.jdeploy.com/gh/").append(repo).append("/").append(branchTag).append(") for more download options.\n\n");
} else {
notes.append("\nOr launch app installer via command-line on Linux, Mac, or Windows:\n\n");
notes.append("```bash\n");
notes.append("/bin/bash -c \"$(curl -fsSL https://www.jdeploy.com/gh/").append(repo).append("/install.sh)\"\n");
notes.append("```\n");
notes.append("\nSee [download page](https://www.jdeploy.com/gh/").append(repo).append(") for more download options.\n\n");
}



return notes.toString();
}

private String urlencodeFileNameForGithubRelease(String str) {
str = str.replace(" ", ".");
try {
return URLEncoder.encode(str, "UTF-8");
} catch (Exception ex) {
err.println("Failed to encode string "+str);
ex.printStackTrace(err);
return str;
}
return new GithubReleaseNotesMutator(directory, err).createGithubReleaseNotes();
}

private void saveGithubReleaseFiles() throws IOException {
Expand Down Expand Up @@ -2415,6 +2343,10 @@ public String injectGithubReleaseNotes(String originalNotes, String jdeployRelea
return sb.toString();
}

public int updateReleaseLinks(String[] args) {
return new UpdateReleaseLinksCLIController(directory, err, out).run(args);
}

/**
* Prepares a self-publish release.
* @throws IOException
Expand Down Expand Up @@ -2755,6 +2687,9 @@ public static void main(String[] args) {
System.exit(1);
}
System.out.println(prog.injectGithubReleaseNotes(oldBody, jdeployReleaseNotes));
} else if ("github-update-release-links".equals(args[0])) {
int result = prog.updateReleaseLinks(subArray(args,1 ));
System.exit(result);
} else if ("scan".equals(args[0])) {
prog.scan();
} else if ("run".equals(args[0])) {
Expand Down Expand Up @@ -2858,6 +2793,15 @@ private static boolean isWithAutoUpdateEnabled(String[] args) {
return true;
}

private static boolean isForGithubRelease(String[] args) {
for (String arg : args) {
if ("--for-github-release".equals(arg)) {
return true;
}
}
return false;
}

private static String[] stripFlags(String[] args) {
List<String> out = new ArrayList<>();
for (String arg : args) {
Expand All @@ -2868,4 +2812,14 @@ private static String[] stripFlags(String[] args) {
}
return out.toArray(new String[out.size()]);
}

private static String[] subArray(String[] args, int offset, int length) {
String[] out = new String[length];
System.arraycopy(args, offset, out, 0, length);
return out;
}

private static String[] subArray(String[] args, int offset) {
return subArray(args, offset, args.length-offset);
}
}
Loading
Loading