Skip to content

Commit 62ed1b7

Browse files
committed
improved log messages. renamed methods.
1 parent 88b18b1 commit 62ed1b7

File tree

2 files changed

+29
-30
lines changed

2 files changed

+29
-30
lines changed

src/main/java/de/doubleslash/keeptime/common/BrowserHelper.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package de.doubleslash.keeptime.common;
1818

19+
import java.util.Arrays;
20+
1921
import org.slf4j.Logger;
2022
import org.slf4j.LoggerFactory;
2123

@@ -29,35 +31,33 @@ public static void openURL(final String url) {
2931
final Runtime rt = Runtime.getRuntime();
3032

3133
if (OS.isWindows()) {
32-
executeCommandWindows(rt, url);
34+
openUrlWindows(rt, url);
3335
} else if (OS.isLinux()) {
34-
executeCommandLinux(rt, url);
36+
openUrlLinux(rt, url);
3537
} else {
3638
LOG.warn("OS is not supported");
3739
}
3840
}
3941

40-
private static void executeCommandWindows(final Runtime rt, final String url) {
42+
private static void openUrlWindows(final Runtime rt, final String url) {
43+
final String command = "rundll32 url.dll,FileProtocolHandler " + url;
4144
try {
42-
final String command = "rundll32 url.dll,FileProtocolHandler " + url;
43-
LOG.debug("execute command: {}", command);
44-
45+
LOG.debug("Executing command: {}", command);
4546
rt.exec(command);
4647
} catch (final Exception e) {
47-
LOG.error(e.getMessage());
48+
LOG.error("Could not open url '" + url + "' with command '" + command + "'.", e);
4849
}
4950
}
5051

51-
private static void executeCommandLinux(final Runtime rt, final String url) {
52+
private static void openUrlLinux(final Runtime rt, final String url) {
53+
final String[] command = {
54+
"xdg-open", url
55+
};
5256
try {
53-
final String command = url;
54-
LOG.debug("execute command: xdg-open {}", command);
55-
56-
rt.exec(new String[] {
57-
"xdg-open", command
58-
});
57+
LOG.debug("Executing command: {}", Arrays.toString(command));
58+
rt.exec(command);
5959
} catch (final Exception e) {
60-
LOG.warn(e.getMessage());
60+
LOG.error("Could not open url '" + url + "' with command '" + Arrays.toString(command) + "'.", e);
6161
}
6262
}
6363
}

src/main/java/de/doubleslash/keeptime/common/FileOpenHelper.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package de.doubleslash.keeptime.common;
1818

1919
import java.io.File;
20+
import java.util.Arrays;
2021

2122
import org.slf4j.Logger;
2223
import org.slf4j.LoggerFactory;
@@ -27,15 +28,15 @@ public class FileOpenHelper {
2728

2829
private FileOpenHelper() {}
2930

30-
public static boolean openFile(final String fileString) {
31-
final File file = new File(fileString);
31+
public static boolean openFile(final String filePath) {
32+
final File file = new File(filePath);
3233
final Runtime rt = Runtime.getRuntime();
3334

3435
if (file.exists() && file.isFile()) {
3536
if (OS.isWindows()) {
36-
executeCommandWindows(rt, file);
37+
openFileWindows(rt, file);
3738
} else if (OS.isLinux()) {
38-
executeCommandLinux(rt, fileString);
39+
openFileLinux(rt, filePath);
3940
} else {
4041
LOG.warn("OS is not supported");
4142
}
@@ -45,27 +46,25 @@ public static boolean openFile(final String fileString) {
4546
}
4647
}
4748

48-
private static void executeCommandWindows(final Runtime rt, final File file) {
49+
private static void openFileWindows(final Runtime rt, final File file) {
50+
final String command = "rundll32 url.dll,FileProtocolHandler " + file;
4951
try {
50-
final String command = "rundll32 url.dll,FileProtocolHandler " + file;
5152
LOG.debug("executing command: {}", command);
52-
5353
rt.exec(command);
5454
} catch (final Exception e) {
55-
LOG.error(e.getMessage());
55+
LOG.error("Could not open file '" + file + "' with command '" + command + "'.", e);
5656
}
5757
}
5858

59-
private static void executeCommandLinux(final Runtime rt, final String fileString) {
59+
private static void openFileLinux(final Runtime rt, final String filePath) {
60+
final String[] command = {
61+
"xdg-open", filePath
62+
};
6063
try {
61-
final String[] command = {
62-
"xdg-open", fileString
63-
};
64-
LOG.debug("executing command: {} {}", command[0], command[1]);
65-
64+
LOG.debug("executing command: {}", Arrays.toString(command));
6665
rt.exec(command);
6766
} catch (final Exception e) {
68-
LOG.error(e.getMessage());
67+
LOG.error("Could not open file '" + filePath + "' with command '" + Arrays.toString(command) + "'.", e);
6968
}
7069
}
7170
}

0 commit comments

Comments
 (0)