Skip to content

Commit 16d787a

Browse files
committed
Merge branch 'issue-120'
2 parents a629589 + c2c9a14 commit 16d787a

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,17 @@ protected File doApply(Packager packager) throws Exception {
6969

7070
// copies JRE folder to bundle
7171
FileUtils.copyFolderContentToFolder(specificJreFolder, destinationFolder);
72-
72+
7373
// sets execution permissions on executables in jre
7474
File binFolder = new File(destinationFolder, "bin");
7575
Arrays.asList(binFolder.listFiles()).forEach(f -> f.setExecutable(true, false));
76+
77+
// sets execution permissions on jspawnhelper in jre
78+
File libFolder = new File(destinationFolder, "lib");
79+
File jshFile = new File(libFolder, "jspawnhelper");
80+
if (jshFile.exists()) {
81+
jshFile.setExecutable(true, false);
82+
}
7683

7784
} else if (JavaUtils.getJavaMajorVersion() <= 8) {
7885

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,35 @@
3232
*/
3333
public class FileUtils {
3434

35+
/**
36+
* Creates a directory if it doesn't exist
37+
* @param dir Directory to be created
38+
* @return Created directory or existing one
39+
*/
3540
public static File mkdir(File dir) {
3641
if (!dir.exists()) {
3742
dir.mkdirs();
3843
}
3944
return dir;
4045
}
4146

47+
/**
48+
* Creates a directory inside an exiting one
49+
* @param parent Parent directory
50+
* @param name New directory name
51+
* @return Created directory
52+
*/
4253
public static File mkdir(File parent, String name) {
4354
File dir = new File(parent, name);
4455
return mkdir(dir);
4556
}
4657

58+
/**
59+
* Copies a file
60+
* @param source Source file
61+
* @param dest Destination file
62+
* @throws Exception If the file cannot be copied
63+
*/
4764
public static void copyFileToFile(File source, File dest) throws Exception {
4865
Logger.info("Copying file [" + source + "] to file [" + dest + "]");
4966
try {
@@ -53,6 +70,12 @@ public static void copyFileToFile(File source, File dest) throws Exception {
5370
}
5471
}
5572

73+
/**
74+
* Copies a file inside an existing folder
75+
* @param source File to be copied
76+
* @param destFolder Destination folder
77+
* @throws Exception If the file cannot be copied
78+
*/
5679
public static void copyFileToFolder(File source, File destFolder) throws Exception {
5780
Logger.info("Copying file [" + source + "] to folder [" + destFolder + "]");
5881
if (new File(destFolder, source.getName()).exists()) return;
@@ -63,6 +86,12 @@ public static void copyFileToFolder(File source, File destFolder) throws Excepti
6386
}
6487
}
6588

89+
/**
90+
* Concatenates several files into a new one
91+
* @param dest Destination file
92+
* @param sources Source files array
93+
* @throws Exception If a file cannot be writen to the destination
94+
*/
6695
public static void concat(File dest, File ... sources) throws Exception {
6796
Logger.info("Concatenating files [" + StringUtils.join(sources, ",") + "] into file [" + dest + "]");
6897
try {
@@ -188,18 +217,35 @@ public static void removeFolder(File folder) throws Exception {
188217
}
189218
}
190219

220+
/**
221+
* Renames a file
222+
* @param file File to be renamed
223+
* @param newName New file name
224+
*/
191225
public static void rename(File file, String newName) {
192226
Logger.info("Renaming file [" + file + "] to [" + newName + "]");
193227
file.renameTo(new File(file.getParentFile(), newName));
194228
}
195229

230+
/**
231+
* Finds all files in folder that matches the regular expression
232+
* @param searchFolder Searching folder
233+
* @param regex Regular expression
234+
* @return List of found files or an empty list if nothing matches
235+
*/
196236
public static List<File> findFiles(File searchFolder, String regex) {
197237
return Arrays.asList(searchFolder.listFiles((dir, name) -> Pattern.matches(regex, name)))
198238
.stream()
199239
.map(f -> new File(f.getName()))
200240
.collect(Collectors.toList());
201241
}
202242

243+
/**
244+
* Finds the first file in folder that matches the regular expression
245+
* @param searchFolder Searching folder
246+
* @param regex Regular expression
247+
* @return Found file or null if nothing matches
248+
*/
203249
public static File findFirstFile(File searchFolder, String regex) {
204250
return Arrays.asList(searchFolder.listFiles((dir, name) -> Pattern.matches(regex, name)))
205251
.stream()
@@ -208,15 +254,32 @@ public static File findFirstFile(File searchFolder, String regex) {
208254
.get();
209255
}
210256

257+
/**
258+
* Download a resource from an URL to a file
259+
* @param url URL to download
260+
* @param file File to copy the downloaded resource
261+
* @throws IOException Resource cannot be copied/downloaded
262+
*/
211263
public static void downloadFromUrl(URL url, File file) throws IOException {
212264
org.apache.commons.io.FileUtils.copyURLToFile(url, file);
213265
Logger.info("File downloaded from [" + url + "] to [" + file.getAbsolutePath() + "]");
214266
}
215267

268+
/**
269+
* Checks if a file exists or is not null
270+
* @param file File
271+
* @return true if file exits, false if doesn't or is null
272+
*/
216273
public static boolean exists(File file) {
217274
return file != null && file.exists();
218275
}
219276

277+
/**
278+
* Checks if a folder contains a file
279+
* @param folder Searching folder
280+
* @param filename Searched file name
281+
* @return true if folder contains file
282+
*/
220283
public static boolean folderContainsFile(File folder, String filename) {
221284
return new File(folder, filename).exists();
222285
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private static Map<String, String> getRelease(File jdkPath) throws FileNotFoundE
3838
* Checks if the platform specified in the "release" file matches the required platform
3939
* @param platform
4040
* @param jdkPath
41-
* @return
41+
* @return true if JDK is for platform
4242
* @throws FileNotFoundException
4343
* @throws IOException
4444
*/

0 commit comments

Comments
 (0)