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
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected File doApply(WindowsPackager packager) throws Exception {
FileUtils.copyFileToFile(iconFile, getGenericIcon());

// creates generic exe
FileUtils.copyResourceToFile("/windows/JavaLauncher.exe", getGenericExe());
FileUtils.copyResourceToFile("/windows/JavaLauncher.exe", getGenericExe(), packager);

// copies rcedit command line tool (needed to manipulate exe)
File rcedit = new File(getOutputFolder(), "rcedit.exe");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public File doCreateApp() throws Exception {

// copies universalJavaApplicationStub startup file to boot java app
File appStubFile = new File(macOSFolder, "universalJavaApplicationStub");
FileUtils.copyResourceToFile("/mac/universalJavaApplicationStub", appStubFile, true);
FileUtils.copyResourceToFile("/mac/universalJavaApplicationStub", appStubFile, true, this);
FileUtils.processFileContent(appStubFile, content -> {
if (!macConfig.isRelocateJar()) {
content = content.replaceAll("/Contents/Resources/Java", "/Contents/Resources");
Expand Down
30 changes: 25 additions & 5 deletions src/main/java/io/github/fvarrui/javapackager/utils/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import io.github.fvarrui.javapackager.packagers.Packager;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;

Expand Down Expand Up @@ -191,9 +193,13 @@ private static void copyStreamToFile(InputStream is, File dest) throws Exception
throw new Exception("Could not copy input stream to " + dest, ex);
}
}

public static void copyResourceToFile(String resource, File dest, boolean unixStyleNewLines) throws Exception {
copyResourceToFile(resource, dest);

public static void copyResourceToFile(String resource, File dest, boolean unixStyleNewLines) throws Exception {
copyResourceToFile(resource, dest, unixStyleNewLines, null);
}

public static void copyResourceToFile(String resource, File dest, boolean unixStyleNewLines, Packager packager) throws Exception {
copyResourceToFile(resource, dest, packager);
if (unixStyleNewLines) {
try {
processFileContent(dest, c -> c.replaceAll("\\r\\n", "\n").replaceAll("\\r", "\n"));
Expand All @@ -208,8 +214,22 @@ public static void processFileContent(File dest, Function<String, String> functi
content = function.apply(content);
writeStringToFile(dest, content, StandardCharsets.UTF_8);
}

public static void copyResourceToFile(String resource, File dest) throws Exception {

public static void copyResourceToFile(String resource, File dest) throws Exception {
copyResourceToFile(resource, dest, null);
}

public static void copyResourceToFile(String resource, File dest, Packager packager) throws Exception {
if (packager != null) {
String rsc = resource.startsWith("/") ? resource.substring(1) : resource;
Path asset = packager.getAssetsDir().toPath().resolve(rsc);
if (Files.exists(asset)) {
Logger.info("Copying resource [" + asset + "] to file [" + dest + "]");
copyFileToFile(asset.toFile(), dest);
return;
}
}

Logger.info("Copying resource [" + resource + "] to file [" + dest + "]");
copyStreamToFile(FileUtils.class.getResourceAsStream(resource), dest);
}
Expand Down