From 354b38039509004be4de7c27098d3a4d106229fa Mon Sep 17 00:00:00 2001
From: Francisco Vargas Ruiz <4354486+fvarrui@users.noreply.github.com>
Date: Sun, 30 Jun 2024 13:48:20 +0100
Subject: [PATCH 1/4] Update build.gradle

---
 build.gradle | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/build.gradle b/build.gradle
index 454b9f65..9e2b7dcc 100644
--- a/build.gradle
+++ b/build.gradle
@@ -64,7 +64,7 @@ dependencies {
 }
 
 group = 'io.github.fvarrui'
-version = '1.7.6'
+version = '1.7.7-SNAPSHOT'
 description = 'Hybrid Maven/Gradle plugin to package Java applications as native Windows, Mac OS X or GNU/Linux executables and create installers for them'
 
 sourceCompatibility = JavaVersion.VERSION_1_8

From 9af05b3822737d717ca000c0439c7c6126592627 Mon Sep 17 00:00:00 2001
From: Francisco Vargas Ruiz <4354486+fvarrui@users.noreply.github.com>
Date: Wed, 3 Jul 2024 20:25:34 +0100
Subject: [PATCH 2/4] refactoring

---
 .../fvarrui/javapackager/utils/CommandUtils.java  | 11 +++++------
 .../fvarrui/javapackager/utils/Commandline.java   | 15 ++++++++++++---
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/src/main/java/io/github/fvarrui/javapackager/utils/CommandUtils.java b/src/main/java/io/github/fvarrui/javapackager/utils/CommandUtils.java
index 9d6b3931..9ffde958 100644
--- a/src/main/java/io/github/fvarrui/javapackager/utils/CommandUtils.java
+++ b/src/main/java/io/github/fvarrui/javapackager/utils/CommandUtils.java
@@ -37,15 +37,14 @@ public static String execute(String executable, List<Object> arguments) throws I
 	public static ExecutionResult executeWithResult(File workingDirectory, String executable, Object... arguments) throws IOException, CommandLineException {
 		ExecutionResult result = new ExecutionResult();
 		
-		StringBuffer outputBuffer = new StringBuffer();
-		StringBuffer errorBuffer = new StringBuffer();
+		StringBuilder outputBuffer = new StringBuilder();
+		StringBuilder errorBuffer = new StringBuilder();
 		
 		Commandline command = new Commandline();
 		command.setWorkingDirectory(workingDirectory);
 		command.setExecutable(executable);
 		command.createArguments(arguments);
-		command.toString();
-		
+
 		String commandLine = command.getCommandLineAsString();
 
 		Logger.info("Executing command: " + commandLine);
@@ -58,12 +57,12 @@ public static ExecutionResult executeWithResult(File workingDirectory, String ex
 			if (output.ready()) {
 				String outputLine = output.readLine();
 				Logger.info(outputLine);
-				outputBuffer.append(outputLine + "\n");
+				outputBuffer.append(outputLine).append("\n");
 			}
 			if (error.ready()) {
 				String errorLine = error.readLine();
 				Logger.error(errorLine);					
-				errorBuffer.append(errorLine + "\n");
+				errorBuffer.append(errorLine).append("\n");
 			}
 		}
 		output.close();
diff --git a/src/main/java/io/github/fvarrui/javapackager/utils/Commandline.java b/src/main/java/io/github/fvarrui/javapackager/utils/Commandline.java
index c275fdd1..abf2a7e0 100644
--- a/src/main/java/io/github/fvarrui/javapackager/utils/Commandline.java
+++ b/src/main/java/io/github/fvarrui/javapackager/utils/Commandline.java
@@ -1,6 +1,7 @@
 package io.github.fvarrui.javapackager.utils;
 
 import java.io.File;
+import java.util.Collection;
 
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.SystemUtils;
@@ -28,12 +29,20 @@ public void createArguments(Object... arguments) {
 			
 			if (argument == null)
 				continue;
-			
+
+			// expands collections
+			if (argument instanceof Collection) {
+				createArguments(((Collection<?>) argument).toArray(new Object[0]));
+				continue;
+			}
+
+			// expands array
 			if (argument.getClass().isArray()) {
-				createArguments((Object[])argument);
+                createArguments((Object[])argument);
 				continue;
 			}
-			
+
+			// process file argument
 			if (argument instanceof File) {
 				
 				File argFile = (File) argument;

From 7311b4d22a763d094eb073b9afb15d03789cc3aa Mon Sep 17 00:00:00 2001
From: Francisco Vargas Ruiz <4354486+fvarrui@users.noreply.github.com>
Date: Wed, 3 Jul 2024 20:25:58 +0100
Subject: [PATCH 3/4] include libs folder and jar file when calling jdeps

---
 .../javapackager/packagers/BundleJre.java     | 23 +++++++++++--------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/src/main/java/io/github/fvarrui/javapackager/packagers/BundleJre.java b/src/main/java/io/github/fvarrui/javapackager/packagers/BundleJre.java
index ba686814..9b5cd112 100644
--- a/src/main/java/io/github/fvarrui/javapackager/packagers/BundleJre.java
+++ b/src/main/java/io/github/fvarrui/javapackager/packagers/BundleJre.java
@@ -139,7 +139,8 @@ protected File doApply(Packager packager) throws Exception {
 			
 			// gets JDK release info 
 			Map<String,String> releaseMap = JDKUtils.getRelease(jdkPath);
-			String releaseInfo = "add:IMAGE_TYPE=\"JRE\":OS_ARCH=\"" + releaseMap.get("OS_ARCH") + "\":OS_NAME=\"" + releaseMap.get("OS_NAME") + "\"";
+            assert releaseMap != null;
+            String releaseInfo = "add:IMAGE_TYPE=\"JRE\":OS_ARCH=\"" + releaseMap.get("OS_ARCH") + "\":OS_NAME=\"" + releaseMap.get("OS_NAME") + "\"";
 
 			// full path to jlink command
 			File jlink = new File(currentJdk, "/bin/jlink");
@@ -222,7 +223,7 @@ protected String getRequiredModules(File packagingJdk, File libsFolder, boolean
 			modulesList = 
 				defaultModules
 					.stream()
-					.map(module -> module.trim())
+					.map(String::trim)
 					.collect(Collectors.toList());
 		
 		} else if (VersionUtils.getJavaMajorVersion() >= 13) { 
@@ -235,13 +236,14 @@ protected String getRequiredModules(File packagingJdk, File libsFolder, boolean
 					"--ignore-missing-deps",
 					"--print-module-deps",
 					"--add-modules=ALL-MODULE-PATH",
-					"--module-path=" + StringUtils.join(modulePaths, File.pathSeparator)				
+					"--module-path=" + StringUtils.join(modulePaths, File.pathSeparator),
+					libsFolder,
+					jarFile
 				);
 			
 			modulesList = 
-				Arrays.asList(modules.split(","))
-					.stream()
-					.map(module -> module.trim())
+				Arrays.stream(modules.split(","))
+					.map(String::trim)
 					.filter(module -> !module.isEmpty())
 					.collect(Collectors.toList());
 			
@@ -255,13 +257,14 @@ protected String getRequiredModules(File packagingJdk, File libsFolder, boolean
 					"--ignore-missing-deps",					
 					"--list-deps",
 					"--add-modules=ALL-MODULE-PATH",
-					"--module-path=" + StringUtils.join(modulePaths, File.pathSeparator)				
+					"--module-path=" + StringUtils.join(modulePaths, File.pathSeparator),
+					libsFolder,
+					jarFile
 				);
 
 			modulesList = 
-				Arrays.asList(modules.split("\n"))
-					.stream()
-					.map(module -> module.trim())
+				Arrays.stream(modules.split("\n"))
+					.map(String::trim)
 					.map(module -> (module.contains("/") ? module.split("/")[0] : module))
 					.filter(module -> !module.isEmpty())
 					.filter(module -> !module.startsWith("JDK removed internal"))

From 3818d4add95e7137607754a081c425520982a1b4 Mon Sep 17 00:00:00 2001
From: Sven <dev@svenkl.net>
Date: Sun, 24 Nov 2024 12:57:49 +0100
Subject: [PATCH 4/4] Added support for adding default launch arguments

---
 README.md                                          |  3 ++-
 .../fvarrui/javapackager/gradle/PackageTask.java   | 13 +++++++++++++
 .../fvarrui/javapackager/maven/PackageMojo.java    |  7 +++++++
 .../javapackager/packagers/PackagerSettings.java   | 14 ++++++++++++++
 src/main/resources/linux/startup.sh.vtl            |  7 +++++--
 src/main/resources/mac/Info.plist.vtl              |  8 ++++++++
 6 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index 757fd9cf..0081560e 100644
--- a/README.md
+++ b/README.md
@@ -145,7 +145,7 @@ By default it will generate next artifacts in `${outputDirectory} ` folder:
 ### Plugin configuration properties
 
 | Property                   | Mandatory          | Default value                                                                                                                                      | Description                                                                                                                                                                               |
-| -------------------------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+|----------------------------|--------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
 | `additionalModulePaths`    | :x:                | `[]`                                                                                                                                               | Additional module paths for `jdeps`.                                                                                                                                                      |
 | `additionalModules`        | :x:                | `[]`                                                                                                                                               | Additional modules to the ones identified by `jdeps` or the specified with `modules` property.                                                                                            |
 | `additionalResources`      | :x:                | `[]`                                                                                                                                               | Additional files and folders to include in the bundled app.                                                                                                                               |
@@ -186,6 +186,7 @@ By default it will generate next artifacts in `${outputDirectory} ` folder:
 | `useResourcesAsWorkingDir` | :x:                | `true`                                                                                                                                             | Uses app resources folder as default working directory (always `true` on MacOS).                                                                                                          |
 | `version`                  | :x:                | `${project.version}`                                                                                                                               | App version.                                                                                                                                                                              |
 | `vmArgs`                   | :x:                | `[]`                                                                                                                                               | VM arguments.                                                                                                                                                                             |
+| `appArgs`                  | :x:                | `[]`                                                                                                                                               | Additional arguments when launching the application.                                                                                                                                      |
 
 > [!IMPORTANT]
 > Some default values depends on the used building tool.
diff --git a/src/main/java/io/github/fvarrui/javapackager/gradle/PackageTask.java b/src/main/java/io/github/fvarrui/javapackager/gradle/PackageTask.java
index ce6a321a..4f4120f8 100644
--- a/src/main/java/io/github/fvarrui/javapackager/gradle/PackageTask.java
+++ b/src/main/java/io/github/fvarrui/javapackager/gradle/PackageTask.java
@@ -445,6 +445,18 @@ public void setVmArgs(List<String> vmArgs) {
 		this.vmArgs = vmArgs;
 	}
 
+	@Input
+	@Optional
+	private List<String> appArgs;
+
+	public List<String> getAppArgs() {
+		return appArgs;
+	}
+
+	public void setAppArgs(List<String> appArgs) {
+		this.appArgs = appArgs;
+	}
+
 	@Input
 	@Optional
 	private WindowsConfig winConfig;
@@ -656,6 +668,7 @@ protected Packager createPackager() throws Exception {
 					.url(defaultIfNull(url, extension.getUrl()))
 					.version(defaultIfNull(version, extension.getVersion(), getProject().getVersion().toString()))
 					.vmArgs(defaultIfNull(vmArgs, extension.getVmArgs()))
+					.appArgs(defaultIfNull(appArgs, extension.getAppArgs()))
 					.winConfig(defaultIfNull(winConfig, extension.getWinConfig()));
 
 	}
diff --git a/src/main/java/io/github/fvarrui/javapackager/maven/PackageMojo.java b/src/main/java/io/github/fvarrui/javapackager/maven/PackageMojo.java
index 78d54203..2e8ca21a 100644
--- a/src/main/java/io/github/fvarrui/javapackager/maven/PackageMojo.java
+++ b/src/main/java/io/github/fvarrui/javapackager/maven/PackageMojo.java
@@ -199,6 +199,12 @@ public class PackageMojo extends AbstractMojo {
 	 */	
 	@Parameter(property = "vmArgs", required = false)
 	private List<String> vmArgs;
+
+	/**
+	 * Additional arguments to provide to the application
+	 */
+	@Parameter(property = "appArgs", readonly = false)
+	private List<String> appArgs;
 	
 	/**
 	 * Provide your own runnable .jar (for example, a shaded .jar) instead of letting this plugin create one via
@@ -387,6 +393,7 @@ public void execute() throws MojoExecutionException {
 						.url(url)
 						.version(version)
 						.vmArgs(vmArgs)
+						.appArgs(appArgs)
 						.winConfig(winConfig);
 			
 			// generate app, installers and bundles
diff --git a/src/main/java/io/github/fvarrui/javapackager/packagers/PackagerSettings.java b/src/main/java/io/github/fvarrui/javapackager/packagers/PackagerSettings.java
index 4d560031..88d7ff81 100644
--- a/src/main/java/io/github/fvarrui/javapackager/packagers/PackagerSettings.java
+++ b/src/main/java/io/github/fvarrui/javapackager/packagers/PackagerSettings.java
@@ -48,6 +48,7 @@ public class PackagerSettings {
 	protected Platform platform;
 	protected String envPath;
 	protected List<String> vmArgs;
+	protected List<String> appArgs;
 	protected File runnableJar;
 	protected Boolean copyDependencies;
 	protected String jreDirectoryName;
@@ -279,6 +280,14 @@ public List<String> getVmArgs() {
 		return vmArgs;
 	}
 
+	/**
+	 * Get application args
+	 * @return Application args
+	 */
+	public List<String> getAppArgs() {
+		return appArgs;
+	}
+
 	/**
 	 * Get runnable JAR
 	 * @return Runnable JAR
@@ -685,6 +694,11 @@ public PackagerSettings vmArgs(List<String> vmArgs) {
 		return this;
 	}
 
+	public PackagerSettings appArgs(List<String> appArgs) {
+		this.appArgs = new ArrayList<>(appArgs);
+		return this;
+	}
+
 	/**
 	 * Set runnable JAR
 	 * @param runnableJar Runnable JAR
diff --git a/src/main/resources/linux/startup.sh.vtl b/src/main/resources/linux/startup.sh.vtl
index f6cb133f..14ad084a 100644
--- a/src/main/resources/linux/startup.sh.vtl
+++ b/src/main/resources/linux/startup.sh.vtl
@@ -1,4 +1,5 @@
 #set ($vmArgs = $StringUtils.join($info.vmArgs, " "))
+#set ($appArgs = $StringUtils.join($info.appArgs, " "))
 #!/usr/bin/env bash
 # GNU/Linux startup script generated by JavaPackager plugin
 
@@ -72,6 +73,8 @@ JVMClassPath="$BINARY"
 JVMClassPath+=":${classpath}"
 #end
 
+AppArguments="${appArgs}"
+
 #if ($info.useResourcesAsWorkingDir)
 cd "$SCRIPTPATH"
 #end
@@ -82,8 +85,8 @@ Bootstrap="$SCRIPTPATH/scripts/${info.bootstrapFile.name}" && [ -x "$Bootstrap"
 #end
 
 #if ($info.administratorRequired)
-pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY GDKBACKEND=x11 "${JAVA}" ${JVMDefaultOptions} -jar "${JVMClassPath}" $@
+pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY GDKBACKEND=x11 "${JAVA}" ${JVMDefaultOptions} -jar "${JVMClassPath}" ${AppArguments} $@
 #else
-"${JAVA}" ${JVMDefaultOptions} -jar "${JVMClassPath}" $@
+"${JAVA}" ${JVMDefaultOptions} -jar "${JVMClassPath}" ${AppArguments} $@
 #end
 exit 0
diff --git a/src/main/resources/mac/Info.plist.vtl b/src/main/resources/mac/Info.plist.vtl
index 31ca5905..b98e668c 100644
--- a/src/main/resources/mac/Info.plist.vtl
+++ b/src/main/resources/mac/Info.plist.vtl
@@ -124,6 +124,14 @@
 			<false/>
 #end
 		</dict>
+#if ($info.appArgs)
+        <key>Arguments</key>
+        <array>
+#foreach ($appArg in $info.appArgs)
+            <string>$appArg</string>
+#end
+        </array>
+#end
 		<key>LSEnvironment</key>
 		<dict>
 #if ($info.bundleJre)
