Skip to content

Commit d20169c

Browse files
committed
refactoring and fixing deprecatations
1 parent 8affe57 commit d20169c

File tree

5 files changed

+466
-432
lines changed

5 files changed

+466
-432
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.io.File;
44
import java.io.IOException;
55
import java.net.MalformedURLException;
6+
import java.net.URI;
7+
import java.net.URISyntaxException;
68
import java.net.URL;
79
import java.util.List;
810

@@ -36,10 +38,10 @@ protected File doApply(Packager packager) {
3638
String urlStr = null;
3739
try {
3840
urlStr = licenses.get(0).getUrl();
39-
URL licenseUrl = new URL(urlStr);
41+
URL licenseUrl = new URI(urlStr).toURL();
4042
licenseFile = new File(assetsFolder, "LICENSE");
4143
FileUtils.downloadFromUrl(licenseUrl, licenseFile);
42-
} catch (MalformedURLException e) {
44+
} catch (URISyntaxException | MalformedURLException e) {
4345
Logger.error("Invalid license URL specified: " + urlStr);
4446
licenseFile = null;
4547
} catch (IOException e) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static Charset getCommandLineCharset(){
2222

2323
private static Charset chcp() {
2424
try{
25-
String result = CommandUtils.run("cmd /k chcp");
25+
String result = CommandUtils.run("cmd", "/k", "chcp");
2626
String code = StringUtils.find("\\d+", result);
2727
Logger.debug("'chcp' code found: " + code);
2828
switch (code){

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static ExecutionResult executeWithResult(File workingDirectory, String ex
7777
return result;
7878
}
7979

80-
public static String run(String command) throws IOException {
80+
public static String run(String ... command) throws IOException {
8181
Process p = Runtime.getRuntime().exec(command);
8282
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
8383
String result = br.readLine();

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import java.io.FileOutputStream;
1515
import java.io.IOException;
1616
import java.io.InputStream;
17+
import java.net.URI;
18+
import java.net.URISyntaxException;
1719
import java.net.URL;
1820
import java.nio.charset.StandardCharsets;
1921
import java.nio.file.Files;
@@ -324,9 +326,10 @@ public static void downloadFromUrl(URL url, File file) throws IOException {
324326
* @param url URL to download
325327
* @param file File to copy the downloaded resource
326328
* @throws IOException Resource cannot be copied/downloaded
329+
* @throws URISyntaxException
327330
*/
328-
public static void downloadFromUrl(String url, File file) throws IOException {
329-
downloadFromUrl(new URL(url), file);
331+
public static void downloadFromUrl(String url, File file) throws IOException, URISyntaxException {
332+
downloadFromUrl(new URI(url).toURL(), file);
330333
}
331334

332335
/**

0 commit comments

Comments
 (0)