Skip to content

Commit 2149662

Browse files
authored
Merge pull request #209 from keastrid/overridable_resources
Allow universalJavaAppStub and Why launcher to be overridden by user …
2 parents c7984af + 0bf73aa commit 2149662

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected File doApply(WindowsPackager packager) throws Exception {
5353
FileUtils.copyFileToFile(iconFile, getGenericIcon());
5454

5555
// creates generic exe
56-
FileUtils.copyResourceToFile("/windows/JavaLauncher.exe", getGenericExe());
56+
FileUtils.copyResourceToFile("/windows/JavaLauncher.exe", getGenericExe(), packager);
5757

5858
// copies rcedit command line tool (needed to manipulate exe)
5959
File rcedit = new File(getOutputFolder(), "rcedit.exe");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public File doCreateApp() throws Exception {
113113

114114
// copies universalJavaApplicationStub startup file to boot java app
115115
File appStubFile = new File(macOSFolder, "universalJavaApplicationStub");
116-
FileUtils.copyResourceToFile("/mac/universalJavaApplicationStub", appStubFile, true);
116+
FileUtils.copyResourceToFile("/mac/universalJavaApplicationStub", appStubFile, true, this);
117117
FileUtils.processFileContent(appStubFile, content -> {
118118
if (!macConfig.isRelocateJar()) {
119119
content = content.replaceAll("/Contents/Resources/Java", "/Contents/Resources");

src/main/java/io/github/fvarrui/javapackager/utils/FileUtils.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
import java.net.URL;
1818
import java.nio.charset.StandardCharsets;
1919
import java.nio.file.Files;
20+
import java.nio.file.Path;
2021
import java.nio.file.StandardCopyOption;
2122
import java.util.Arrays;
2223
import java.util.List;
2324
import java.util.function.Function;
2425
import java.util.regex.Pattern;
2526
import java.util.stream.Collectors;
2627

28+
import io.github.fvarrui.javapackager.packagers.Packager;
2729
import org.apache.commons.io.IOUtils;
2830
import org.apache.commons.lang3.StringUtils;
2931

@@ -191,9 +193,13 @@ private static void copyStreamToFile(InputStream is, File dest) throws Exception
191193
throw new Exception("Could not copy input stream to " + dest, ex);
192194
}
193195
}
194-
195-
public static void copyResourceToFile(String resource, File dest, boolean unixStyleNewLines) throws Exception {
196-
copyResourceToFile(resource, dest);
196+
197+
public static void copyResourceToFile(String resource, File dest, boolean unixStyleNewLines) throws Exception {
198+
copyResourceToFile(resource, dest, unixStyleNewLines, null);
199+
}
200+
201+
public static void copyResourceToFile(String resource, File dest, boolean unixStyleNewLines, Packager packager) throws Exception {
202+
copyResourceToFile(resource, dest, packager);
197203
if (unixStyleNewLines) {
198204
try {
199205
processFileContent(dest, c -> c.replaceAll("\\r\\n", "\n").replaceAll("\\r", "\n"));
@@ -208,8 +214,22 @@ public static void processFileContent(File dest, Function<String, String> functi
208214
content = function.apply(content);
209215
writeStringToFile(dest, content, StandardCharsets.UTF_8);
210216
}
211-
212-
public static void copyResourceToFile(String resource, File dest) throws Exception {
217+
218+
public static void copyResourceToFile(String resource, File dest) throws Exception {
219+
copyResourceToFile(resource, dest, null);
220+
}
221+
222+
public static void copyResourceToFile(String resource, File dest, Packager packager) throws Exception {
223+
if (packager != null) {
224+
String rsc = resource.startsWith("/") ? resource.substring(1) : resource;
225+
Path asset = packager.getAssetsDir().toPath().resolve(rsc);
226+
if (Files.exists(asset)) {
227+
Logger.info("Copying resource [" + asset + "] to file [" + dest + "]");
228+
copyFileToFile(asset.toFile(), dest);
229+
return;
230+
}
231+
}
232+
213233
Logger.info("Copying resource [" + resource + "] to file [" + dest + "]");
214234
copyStreamToFile(FileUtils.class.getResourceAsStream(resource), dest);
215235
}

0 commit comments

Comments
 (0)