Skip to content

Commit 7e0edb1

Browse files
authored
Merge branch 'devel' into macos
2 parents a967a45 + 8438f45 commit 7e0edb1

File tree

7 files changed

+116
-39
lines changed

7 files changed

+116
-39
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Add the following `plugin` tag to your `pom.xml`:
3030
<plugin>
3131
<groupId>io.github.fvarrui</groupId>
3232
<artifactId>javapackager</artifactId>
33-
<version>1.6.7</version>
33+
<version>1.7.0-SNAPSHOT</version>
3434
<executions>
3535
<execution>
3636
<phase>package</phase>
@@ -78,7 +78,7 @@ buildscript {
7878
mavenCentral()
7979
}
8080
dependencies {
81-
classpath 'io.github.fvarrui:javapackager:1.6.7'
81+
classpath 'io.github.fvarrui:javapackager:1.7.0-SNAPSHOT'
8282
}
8383
}
8484

build.gradle

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ dependencies {
4646
implementation 'org.apache.maven:maven-plugin-api:3.6.0'
4747
implementation 'org.codehaus.plexus:plexus-utils:3.1.1'
4848
implementation 'org.twdata.maven:mojo-executor:2.3.0'
49-
implementation 'commons-io:commons-io:2.6'
49+
implementation 'commons-io:commons-io:2.7'
5050
implementation 'org.apache.commons:commons-lang3:3.9'
5151
implementation 'org.apache.commons:commons-collections4:4.1'
5252
implementation 'org.apache.commons:commons-compress:1.21'
53-
implementation 'org.apache.velocity:velocity-engine-core:2.0'
53+
implementation 'org.apache.velocity:velocity-engine-core:2.3'
5454
implementation 'org.vafer:jdeb:1.9'
5555
implementation 'net.jsign:jsign-core:3.1'
5656
implementation 'org.redline-rpm:redline:1.2.10'
5757
implementation 'io.github.fvarrui:launch4j:2.5.2'
5858

59-
testImplementation 'junit:junit:4.12'
59+
testImplementation 'junit:junit:4.13.1'
6060

6161
compileOnly 'org.apache.maven.plugin-tools:maven-plugin-annotations:3.6.0'
6262

@@ -70,8 +70,8 @@ dependencies {
7070
}
7171

7272
group = 'io.github.fvarrui'
73-
version = '1.6.7'
74-
description = 'Hybrid Maven/Gradle plugin to package Java applications as native Windows, MacOS or GNU/Linux executables and create installers for them'
73+
version = '1.7.0-SNAPSHOT'
74+
description = 'Hybrid Maven/Gradle plugin to package Java applications as native Windows, Mac OS X or GNU/Linux executables and create installers for them'
7575

7676
sourceCompatibility = JavaVersion.VERSION_1_8
7777
targetCompatibility = JavaVersion.VERSION_1_8
@@ -86,6 +86,11 @@ publishing {
8686
}
8787
}
8888

89+
java {
90+
withSourcesJar()
91+
// and/or analogously use “withJavadocJar()� to get a “javadocJar� task
92+
}
93+
8994
install.repositories.mavenInstaller.pom.with {
9095
groupId = project.group
9196
artifactId = project.name

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public class MacConfig implements Serializable {
3434
private String developerId = "-";
3535
private File entitlements;
3636
private File provisionProfile;
37+
private File customLauncher;
38+
private File customInfoPlist;
3739
private boolean codesignApp = true;
3840
private InfoPlist infoPlist = new InfoPlist();
3941
private boolean hardenedCodesign = true;
@@ -191,6 +193,22 @@ public void setDeveloperId(String developerId) {
191193
this.developerId = developerId;
192194
}
193195

196+
public File getCustomLauncher() {
197+
return customLauncher;
198+
}
199+
200+
public void setCustomLauncher(File customLauncher) {
201+
this.customLauncher = customLauncher;
202+
}
203+
204+
public File getCustomInfoPlist() {
205+
return customInfoPlist;
206+
}
207+
208+
public void setCustomInfoPlist(File customInfoPlist) {
209+
this.customInfoPlist = customInfoPlist;
210+
}
211+
194212
public File getProvisionProfile() {
195213
return provisionProfile;
196214
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class WindowsConfig implements Serializable {
3939
private boolean generateSetup = true;
4040
private boolean generateMsi = true;
4141
private boolean generateMsm = false;
42+
private boolean setupMutex = true;
4243
private String msiUpgradeCode;
4344
private boolean wrapJar = true;
4445
private LinkedHashMap<String, String> setupLanguages = new LinkedHashMap<>();
@@ -281,6 +282,14 @@ public boolean isDisableWelcomePage() {
281282
return disableWelcomePage;
282283
}
283284

285+
public boolean isSetupMutex() {
286+
return setupMutex;
287+
}
288+
289+
public void setSetupMutex(boolean setupMutex) {
290+
this.setupMutex = setupMutex;
291+
}
292+
284293
public boolean isRemoveOldLibs() {
285294
return removeOldLibs;
286295
}

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

Lines changed: 73 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.apache.commons.lang3.StringUtils;
1010
import org.apache.commons.lang3.SystemUtils;
1111

12+
import io.github.fvarrui.javapackager.model.MacStartup;
1213
import io.github.fvarrui.javapackager.model.Platform;
1314
import io.github.fvarrui.javapackager.utils.CommandUtils;
1415
import io.github.fvarrui.javapackager.utils.FileUtils;
@@ -91,37 +92,50 @@ public File doCreateApp() throws Exception {
9192
// copies jarfile to Java folder
9293
FileUtils.copyFileToFolder(jarFile, javaFolder);
9394

95+
processStartupScript();
96+
97+
processClasspath();
98+
99+
processInfoPlistFile();
100+
101+
processProvisionProfileFile();
102+
103+
codesign();
104+
105+
return appFile;
106+
}
107+
108+
private void processStartupScript() throws Exception {
109+
94110
if (this.administratorRequired) {
95111

112+
// We need a helper script ("startup") in this case,
113+
// which invokes the launcher script/ executable with administrator rights.
114+
// TODO: admin script depends on launcher file name 'universalJavaApplicationStub'
115+
96116
// sets startup file
97117
this.executable = new File(macOSFolder, "startup");
98118

99119
// creates startup file to boot java app
100120
VelocityUtils.render("mac/startup.vtl", executable, this);
101-
executable.setExecutable(true, false);
102-
Logger.info("Startup script file created in " + executable.getAbsolutePath());
103-
121+
104122
} else {
105123

106-
// sets startup file
107-
this.executable = new File(macOSFolder, "universalJavaApplicationStub");
108-
Logger.info("Using " + executable.getAbsolutePath() + " as startup script");
109-
110-
}
111-
112-
// copies universalJavaApplicationStub startup file to boot java app
113-
File appStubFile = new File(macOSFolder, "universalJavaApplicationStub");
114-
String universalJavaApplicationStubResource = null;
115-
switch (macConfig.getMacStartup()) {
116-
case UNIVERSAL: universalJavaApplicationStubResource = "universalJavaApplicationStub"; break;
117-
case X86_64: universalJavaApplicationStubResource = "universalJavaApplicationStub.x86_64"; break;
118-
case ARM64: universalJavaApplicationStubResource = "universalJavaApplicationStub.arm64"; break;
119-
case SCRIPT: universalJavaApplicationStubResource = "universalJavaApplicationStub.sh"; break;
124+
File launcher = macConfig.getCustomLauncher();
125+
if(launcher != null && launcher.canRead() && launcher.isFile()){
126+
FileUtils.copyFileToFolder(launcher, macOSFolder);
127+
this.executable = new File(macOSFolder, launcher.getName());
128+
} else {
129+
this.executable = preparePrecompiledStartupStub();
130+
}
120131
}
121-
FileUtils.copyResourceToFile("/mac/" + universalJavaApplicationStubResource, appStubFile);
122-
appStubFile.setExecutable(true, false);
132+
133+
executable.setExecutable(true, false);
134+
Logger.info("Startup script file created in " + executable.getAbsolutePath());
135+
}
123136

124-
// process classpath
137+
private void processClasspath() {
138+
// TODO: Why are we doing this here? I do not see any usage of 'classpath' or 'classpaths' here.
125139
classpath = (this.macConfig.isRelocateJar() ? "Java/" : "") + this.jarFile.getName() + (classpath != null ? ":" + classpath : "");
126140
classpaths = Arrays.asList(classpath.split("[:;]"));
127141
if (!isUseResourcesAsWorkingDir()) {
@@ -131,29 +145,57 @@ public File doCreateApp() throws Exception {
131145
.collect(Collectors.toList());
132146
}
133147
classpath = StringUtils.join(classpaths, ":");
148+
}
134149

135-
// creates and write the Info.plist file
150+
/**
151+
* Creates and writes the Info.plist file if no custom file is specified.
152+
* @throws Exception if anything goes wrong
153+
*/
154+
private void processInfoPlistFile() throws Exception {
136155
File infoPlistFile = new File(contentsFolder, "Info.plist");
137-
VelocityUtils.render("mac/Info.plist.vtl", infoPlistFile, this);
138-
XMLUtils.prettify(infoPlistFile);
139-
Logger.info("Info.plist file created in " + infoPlistFile.getAbsolutePath());
140-
141-
// copy provisionprofile
142-
if(macConfig.getProvisionProfile() != null) {
143-
// file name must be 'embedded.provisionprofile'
144-
FileUtils.copyFileToFile(macConfig.getProvisionProfile(), new File(contentsFolder, "embedded.provisionprofile"));
156+
if(macConfig.getCustomInfoPlist() != null && macConfig.getCustomInfoPlist().isFile() && macConfig.getCustomInfoPlist().canRead()){
157+
FileUtils.copyFileToFile(macConfig.getCustomInfoPlist(), infoPlistFile);
158+
} else {
159+
VelocityUtils.render("mac/Info.plist.vtl", infoPlistFile, this);
160+
XMLUtils.prettify(infoPlistFile);
145161
}
162+
Logger.info("Info.plist file created in " + infoPlistFile.getAbsolutePath());
163+
}
146164

147-
// codesigns app folder
165+
private void codesign() throws Exception {
148166
if (!Platform.mac.isCurrentPlatform()) {
149167
Logger.warn("Generated app could not be signed due to current platform is " + Platform.getCurrentPlatform());
150168
} else if (!getMacConfig().isCodesignApp()) {
151169
Logger.warn("App codesigning disabled");
152170
} else {
153171
codesign(this.macConfig.getDeveloperId(), this.macConfig.getEntitlements(), this.appFile);
154172
}
173+
}
155174

156-
return appFile;
175+
private void processProvisionProfileFile() throws Exception {
176+
if (macConfig.getProvisionProfile() != null && macConfig.getProvisionProfile().isFile() && macConfig.getProvisionProfile().canRead()) {
177+
// file name must be 'embedded.provisionprofile'
178+
File provisionProfile = new File(contentsFolder, "embedded.provisionprofile");
179+
FileUtils.copyFileToFile(macConfig.getProvisionProfile(), provisionProfile);
180+
Logger.info("Provision profile file created from " + "\n" +
181+
macConfig.getProvisionProfile() + " to \n" +
182+
provisionProfile.getAbsolutePath());
183+
}
184+
}
185+
186+
private File preparePrecompiledStartupStub() throws Exception {
187+
// sets startup file
188+
File appStubFile = new File(macOSFolder, "universalJavaApplicationStub");
189+
String universalJavaApplicationStubResource = null;
190+
switch (macConfig.getMacStartup()) {
191+
case UNIVERSAL: universalJavaApplicationStubResource = "universalJavaApplicationStub"; break;
192+
case X86_64: universalJavaApplicationStubResource = "universalJavaApplicationStub.x86_64"; break;
193+
case ARM64: universalJavaApplicationStubResource = "universalJavaApplicationStub.arm64"; break;
194+
case SCRIPT: universalJavaApplicationStubResource = "universalJavaApplicationStub.sh"; break;
195+
}
196+
// unixStyleNewLinux=true if startup is a script (this will replace '\r\n' with '\n')
197+
FileUtils.copyResourceToFile("/mac/" + universalJavaApplicationStubResource, appStubFile, macConfig.getMacStartup() == MacStartup.SCRIPT);
198+
return appStubFile;
157199
}
158200

159201
private void codesign(String developerId, File entitlements, File appFile) throws Exception {

src/main/resources/mac/startup.vtl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
22
# MacOS startup script generated by JavaPackager plugin
33
SCRIPTPATH=`cd "$(dirname "$0")" ; pwd`
4-
osascript -e "do shell script quoted form of \"$SCRIPTPATH\" & \"/universalJavaApplicationStub $@\" with administrator privileges" &
4+
osascript -e "do shell script quoted form of \"$SCRIPTPATH\" & \"/universalJavaApplicationStub $@\" with administrator privileges" &

src/main/resources/windows/iss.vtl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ PrivilegesRequiredOverridesAllowed=commandline
4747
#else
4848
PrivilegesRequiredOverridesAllowed=commandline dialog
4949
#end
50+
#if ($info.winConfig.setupMutex)
51+
SetupMutex=SetupMutex{#SetupSetting("AppId")}
52+
#end
5053
LicenseFile={#MyAppLicense}
5154
SetupIconFile={#MyAppIcon}
5255
UninstallDisplayIcon={app}\{#MyAppExeName}

0 commit comments

Comments
 (0)