Skip to content

Commit 1aa42b3

Browse files
committed
Merge branch 'devel' of https://github.com/fvarrui/JavaPackager into devel
2 parents d20169c + 26e5417 commit 1aa42b3

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ It was born while teaching to my students how to build and distribute their Java
1515

1616
- [AstroImageJ](http://astroimagej.com/)
1717
- [Astro Pixel Processor](https://www.astropixelprocessor.com/)
18+
- [Drifty](https://github.com/SaptarshiSarkar12/Drifty)
1819
- [GistFX](https://github.com/RedmondSims/GistFX)
1920
- [Spektar Design Lab](https://spektar.io/)
2021

src/main/java/io/github/fvarrui/javapackager/maven/ResolveLicenseFromPOM.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected File doApply(Packager packager) {
4444
} catch (URISyntaxException | MalformedURLException e) {
4545
Logger.error("Invalid license URL specified: " + urlStr);
4646
licenseFile = null;
47-
} catch (IOException e) {
47+
} catch (Exception e) {
4848
Logger.error("Cannot download license from " + urlStr);
4949
licenseFile = null;
5050
}

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.io.File;
77
import java.util.Arrays;
8+
import java.util.Optional;
89

910
import org.apache.commons.lang3.StringUtils;
1011

@@ -99,13 +100,13 @@ protected File doApply(MacPackager packager) throws Exception {
99100
// mounts image
100101
Logger.info("Mounting image: " + tempDmgFile.getAbsolutePath());
101102
String result = execute("hdiutil", "attach", "-readwrite", "-noverify", "-noautoopen", tempDmgFile);
102-
String deviceName = Arrays.asList(result.split("\n"))
103-
.stream()
104-
.filter(s -> s.contains(mountFolder.getAbsolutePath()))
105-
.map(s -> StringUtils.normalizeSpace(s))
106-
.map(s -> s.split(" ")[0])
107-
.findFirst().get();
108-
Logger.info("- Device name: " + deviceName);
103+
Optional<String> optDeviceName = Arrays.asList(result.split("\n"))
104+
.stream()
105+
.filter(s -> s.contains(mountFolder.getAbsolutePath()))
106+
.map(s -> StringUtils.normalizeSpace(s))
107+
.map(s -> s.split(" ")[0])
108+
.findFirst();
109+
optDeviceName.ifPresent(deviceName -> Logger.info("- Device name: " + deviceName));
109110

110111
// pause to prevent occasional "Can't get disk" (-1728) issues
111112
// https://github.com/seltzered/create-dmg/commit/5fe7802917bb85b40c0630b026d33e421db914ea

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

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,9 @@ public static List<File> findFiles(File searchFolder, String regex) {
305305
*/
306306
public static File findFirstFile(File searchFolder, String regex) {
307307
return Arrays.asList(searchFolder.listFiles((dir, name) -> Pattern.matches(regex, name))).stream()
308-
.map(f -> new File(f.getName())).findFirst().get();
308+
.map(f -> new File(f.getName()))
309+
.findFirst()
310+
.orElse(null);
309311
}
310312

311313
/**
@@ -315,8 +317,9 @@ public static File findFirstFile(File searchFolder, String regex) {
315317
* @param file File to copy the downloaded resource
316318
* @throws IOException Resource cannot be copied/downloaded
317319
*/
318-
public static void downloadFromUrl(URL url, File file) throws IOException {
319-
org.apache.commons.io.FileUtils.copyURLToFile(url, file);
320+
public static void downloadFromUrl(URL url, File file) throws Exception {
321+
// org.apache.commons.io.FileUtils.copyURLToFile(url, file);
322+
copyUrlToFile(url,file);
320323
Logger.info("File downloaded from [" + url + "] to [" + file.getAbsolutePath() + "]");
321324
}
322325

@@ -369,4 +372,36 @@ public static void writeStringToFileWithBOM(File output, String data) throws Exc
369372
fileOutputStream.close();
370373
}
371374

375+
/**
376+
*
377+
* @param url URL to download
378+
* @param file File to copy the downloaded resource
379+
* @throws Exception if something goes wrong
380+
*/
381+
public static void copyUrlToFile(URL url,File file) throws Exception {
382+
copyUrlToFile(url,file,30000);
383+
}
384+
385+
/**
386+
*
387+
* @param url URL to download
388+
* @param file File to copy the downloaded resource
389+
* @param timeout Download timeout (ms)
390+
* @throws Exception if something goes wrong
391+
*/
392+
public static void copyUrlToFile(URL url,File file,int timeout) throws Exception {
393+
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
394+
connection.setConnectTimeout(timeout);
395+
connection.setReadTimeout(timeout);
396+
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
397+
try (InputStream in = connection.getInputStream();
398+
FileOutputStream out = new FileOutputStream(file)) {
399+
IOUtils.copy(in, out);
400+
}
401+
} else {
402+
Logger.warn("Failed to download the file. Response code: " + connection.getResponseCode());
403+
}
404+
connection.disconnect();
405+
}
406+
372407
}

0 commit comments

Comments
 (0)