Skip to content

Commit ca1d280

Browse files
committed
U classpath property processing enhanced for all platforms
1 parent f184c3b commit ca1d280

File tree

8 files changed

+65
-34
lines changed

8 files changed

+65
-34
lines changed

src/main/java/io/github/fvarrui/javapackager/gradle/CreateWindowsExe.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.fvarrui.javapackager.gradle;
22

33
import java.io.File;
4+
import java.util.Arrays;
45
import java.util.HashSet;
56
import java.util.List;
67
import java.util.Set;
@@ -41,10 +42,6 @@ public File apply(Packager packager) throws Exception {
4142
boolean useResourcesAsWorkingDir = windowsPackager.isUseResourcesAsWorkingDir();
4243
boolean bundleJre = windowsPackager.getBundleJre();
4344
String jreDirectoryName = windowsPackager.getJreDirectoryName();
44-
String classpath = windowsPackager.getClasspath();
45-
46-
Set<String> classpathSet = new HashSet<>();
47-
if (classpath != null) classpathSet.add(classpath);
4845

4946
Launch4jLibraryTask l4jTask = createLaunch4jTask();
5047
l4jTask.setHeaderType(winConfig.getHeaderType().toString());
@@ -54,7 +51,7 @@ public File apply(Packager packager) throws Exception {
5451
l4jTask.setIcon(iconFile.getAbsolutePath());
5552
l4jTask.setManifest(manifestFile.getAbsolutePath());
5653
l4jTask.setMainClassName(mainClass);
57-
l4jTask.setClasspath(classpathSet);
54+
l4jTask.setClasspath(new HashSet<>(windowsPackager.getClasspaths()));
5855
l4jTask.setChdir(useResourcesAsWorkingDir ? "." : "");
5956
l4jTask.setBundledJrePath(bundleJre ? jreDirectoryName : "%JAVA_HOME%");
6057
l4jTask.getJvmOptions().addAll(vmArgs);

src/main/java/io/github/fvarrui/javapackager/model/MacConfig.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class MacConfig implements Serializable {
2727
private boolean generateDmg = true;
2828
private boolean generatePkg = true;
2929
private boolean relocateJar = true;
30-
private String appIdentifier;
30+
private String appId;
3131
private String developerId = "-";
3232
private File entitlements;
3333

@@ -167,12 +167,12 @@ public void setRelocateJar(boolean relocateJar) {
167167
this.relocateJar = relocateJar;
168168
}
169169

170-
public String getAppIdentifier() {
171-
return appIdentifier;
170+
public String getAppId() {
171+
return appId;
172172
}
173173

174-
public void setAppIdentifier(String appIdentifier) {
175-
this.appIdentifier = appIdentifier;
174+
public void setAppId(String appId) {
175+
this.appId = appId;
176176
}
177177

178178
public String getDeveloperId() {
@@ -198,7 +198,7 @@ public String toString() {
198198
+ ", iconSize=" + iconSize + ", textSize=" + textSize + ", iconX=" + iconX + ", iconY=" + iconY
199199
+ ", appsLinkIconX=" + appsLinkIconX + ", appsLinkIconY=" + appsLinkIconY + ", volumeIcon=" + volumeIcon
200200
+ ", volumeName=" + volumeName + ", generateDmg=" + generateDmg + ", generatePkg=" + generatePkg
201-
+ ", relocateJar=" + relocateJar + ", appIdentifier=" + appIdentifier + ", developerId=" + developerId
201+
+ ", relocateJar=" + relocateJar + ", appId=" + appId + ", developerId=" + developerId
202202
+ ", entitlements=" + entitlements + "]";
203203
}
204204

@@ -218,6 +218,6 @@ public void setDefaults(Packager packager) {
218218
this.setIconY(defaultIfNull(this.getIconY(), 116));
219219
this.setAppsLinkIconX(defaultIfNull(this.getAppsLinkIconX(), 360));
220220
this.setAppsLinkIconY(defaultIfNull(this.getAppsLinkIconY(), 116));
221-
this.setAppIdentifier(defaultIfNull(this.getAppIdentifier(), packager.getMainClass()));
221+
this.setAppId(defaultIfNull(this.getAppId(), packager.getMainClass()));
222222
}
223223
}

src/main/java/io/github/fvarrui/javapackager/packagers/LinuxPackager.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package io.github.fvarrui.javapackager.packagers;
22

33
import java.io.File;
4+
import java.util.Arrays;
5+
import java.util.stream.Collectors;
6+
7+
import org.apache.commons.lang3.StringUtils;
48

59
import io.github.fvarrui.javapackager.utils.FileUtils;
610
import io.github.fvarrui.javapackager.utils.Logger;
@@ -43,6 +47,15 @@ public File doCreateApp() throws Exception {
4347
// sets executable file
4448
this.executable = new File(appFolder, name);
4549

50+
// process classpath
51+
if (classpath != null) {
52+
classpaths = Arrays.asList(classpath.split("[:;]"));
53+
if (!isUseResourcesAsWorkingDir()) {
54+
classpaths = classpaths.stream().map(cp -> new File(cp).isAbsolute() ? cp : "$SCRIPTPATH/" + cp).collect(Collectors.toList());
55+
}
56+
classpath = StringUtils.join(classpaths, ":");
57+
}
58+
4659
// generates startup.sh script to boot java app
4760
File startupFile = new File(assetsFolder, "startup.sh");
4861
VelocityUtils.render("linux/startup.sh.vtl", startupFile, this);

src/main/java/io/github/fvarrui/javapackager/packagers/MacPackager.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
import java.io.File;
44
import java.io.IOException;
55
import java.util.ArrayList;
6+
import java.util.Arrays;
67
import java.util.List;
8+
import java.util.stream.Collectors;
79

10+
import org.apache.commons.lang3.StringUtils;
811
import org.codehaus.plexus.util.cli.CommandLineException;
912

1013
import io.github.fvarrui.javapackager.model.Platform;
@@ -111,6 +114,14 @@ public File doCreateApp() throws Exception {
111114
return content;
112115
});
113116
appStubFile.setExecutable(true, false);
117+
118+
// process classpath
119+
classpath = (this.macConfig.isRelocateJar() ? "Java/" : "") + this.jarFile.getName() + ":" + classpath;
120+
classpaths = Arrays.asList(classpath.split("[:;]"));
121+
if (!isUseResourcesAsWorkingDir()) {
122+
classpaths = classpaths.stream().map(cp -> new File(cp).isAbsolute() ? cp : "$ResourcesFolder/" + cp).collect(Collectors.toList());
123+
}
124+
classpath = StringUtils.join(classpaths, ":");
114125

115126
// creates and write the Info.plist file
116127
File infoPlistFile = new File(contentsFolder, "Info.plist");

src/main/java/io/github/fvarrui/javapackager/packagers/Packager.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public abstract class Packager extends PackagerSettings {
4242
protected File jarFileDestinationFolder;
4343
protected File jreDestinationFolder;
4444
protected File resourcesDestinationFolder;
45+
46+
// processed classpaths list
47+
protected List<String> classpaths = new ArrayList<>();
4548

4649
// ===============================================
4750

@@ -68,6 +71,10 @@ public File getJarFileDestinationFolder() {
6871
public File getLibsFolder() {
6972
return libsFolder;
7073
}
74+
75+
public List<String> getClasspaths() {
76+
return classpaths;
77+
}
7178

7279
// ===============================================
7380

src/main/java/io/github/fvarrui/javapackager/packagers/WindowsPackager.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package io.github.fvarrui.javapackager.packagers;
22

33
import java.io.File;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
import java.util.stream.Collectors;
7+
8+
import org.apache.commons.lang3.StringUtils;
49

510
import io.github.fvarrui.javapackager.utils.FileUtils;
611
import io.github.fvarrui.javapackager.utils.Logger;
@@ -74,15 +79,27 @@ public File doCreateApp() throws Exception {
7479

7580
// sets executable file
7681
executable = new File(appFolder, name + ".exe");
77-
78-
// invokes launch4j to generate windows executable
7982

83+
// process classpath
84+
if (classpath != null) {
85+
classpaths = Arrays.asList(classpath.split(";"));
86+
if (!isUseResourcesAsWorkingDir()) {
87+
classpaths = classpaths.stream().map(cp -> new File(cp).isAbsolute() ? cp : "%EXEDIR%/" + cp).collect(Collectors.toList());
88+
}
89+
classpath = StringUtils.join(classpaths, ";");
90+
}
91+
92+
// invokes launch4j to generate windows executable
8093
executable = Context.getContext().createWindowsExe(this);
8194

8295
Logger.infoUnindent("Windows EXE file created in " + executable + "!");
8396

8497
return appFolder;
8598
}
86-
8799

100+
public static void main(String[] args) {
101+
String classpath = "plugins/*:addons/*";
102+
List<String> classpaths = Arrays.asList(classpath.split("[:;]"));
103+
System.out.println(classpaths);
104+
}
88105
}

src/main/resources/linux/startup.sh.vtl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,8 @@ JVMOptionsFile="$SCRIPTPATH/${info.name}.l4j.ini"
2121
[ -f $JVMOptionsFile ] && while read -r option; do JVMDefaultOptions+=" $option"; done <<< $(sed "/^#.*$/d" $JVMOptionsFile)
2222

2323
JVMClassPath="$BINARY"
24-
#if ($info.classpath)
25-
#if ($info.useResourcesAsWorkingDir)
26-
JVMClassPath+=":${info.classpath}"
27-
#else
28-
JVMClassPath+=":$SCRIPTPATH/${info.classpath}"
29-
#end
24+
#foreach ($classpath in $info.classpaths)
25+
JVMClassPath+=":${classpath}"
3026
#end
3127

3228
#if ($info.useResourcesAsWorkingDir)

src/main/resources/mac/Info.plist.vtl

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
#if ($info.useResourcesAsWorkingDir)
2-
#set ($classpathPrefix="")
3-
#else
4-
#set ($classpathPrefix="$ResourcesFolder/")
5-
#end
61
<?xml version="1.0" encoding="UTF-8"?>
72
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
83
<plist version="1.0">
@@ -16,7 +11,7 @@
1611
<key>CFBundleIconFile</key>
1712
<string>${info.name}.icns</string>
1813
<key>CFBundleIdentifier</key>
19-
<string>${info.mainClass}</string>
14+
<string>${info.macConfig.appId}</string>
2015
<key>CFBundleDisplayName</key>
2116
<string>${info.displayName}</string>
2217
<key>CFBundleInfoDictionaryVersion</key>
@@ -49,13 +44,8 @@
4944
<string>${info.mainClass}</string>
5045
<key>ClassPath</key>
5146
<array>
52-
#if ($info.macConfig.relocateJar)
53-
<string>${classpathPrefix}Java/${info.jarFile.name}</string>
54-
#else
55-
<string>${classpathPrefix}${info.jarFile.name}</string>
56-
#end
57-
#if ($info.classpath)
58-
<string>${classpathPrefix}${info.classpath}</string>
47+
#foreach ($classpath in $info.classpaths)
48+
<string>$classpath</string>
5949
#end
6050
</array>
6151
#if (!$info.vmArgs.empty)

0 commit comments

Comments
 (0)