Skip to content

Commit f432d8d

Browse files
author
Martin Plieske
committed
modified class BrowserHelper; added class OS; added class FileOpenHelper; added enum Licenses; added functionallity doubleclick on tablerow and license opens
1 parent 141e0a0 commit f432d8d

File tree

8 files changed

+318
-53
lines changed

8 files changed

+318
-53
lines changed

assembly.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
3+
4+
<id>bin</id>
5+
6+
<formats>
7+
<format>zip</format>
8+
</formats>
9+
10+
<includeBaseDirectory>false</includeBaseDirectory>
11+
12+
<fileSets>
13+
<fileSet>
14+
<directory>${project.basedir}/src/main/resources/licenses</directory>
15+
<outputDirectory>\licenses</outputDirectory>
16+
</fileSet>
17+
</fileSets>
18+
19+
<dependencySets>
20+
<dependencySet>
21+
<includes>
22+
<include>de.doubleslash:keeptime</include>
23+
</includes>
24+
</dependencySet>
25+
</dependencySets>
26+
</assembly>

pom.xml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,14 @@
6969
<artifactId>commons-lang3</artifactId>
7070
<version>3.8</version>
7171
</dependency>
72-
72+
73+
<!-- maven assembly plugin -->
74+
<dependency>
75+
<groupId>org.apache.maven.plugins</groupId>
76+
<artifactId>maven-assembly-plugin</artifactId>
77+
<version>3.1.1</version>
78+
<type>maven-plugin</type>
79+
</dependency>
7380
</dependencies>
7481

7582
<build>
@@ -78,6 +85,26 @@
7885
<groupId>org.springframework.boot</groupId>
7986
<artifactId>spring-boot-maven-plugin</artifactId>
8087
</plugin>
88+
<plugin>
89+
<artifactId>maven-assembly-plugin</artifactId>
90+
<executions>
91+
<execution>
92+
<id>create-keeptime-zip</id>
93+
<phase>package</phase>
94+
<goals>
95+
<goal>single</goal>
96+
</goals>
97+
<configuration>
98+
<descriptors>
99+
<descriptor>./assembly.xml</descriptor>
100+
</descriptors>
101+
<finalName>keeptime</finalName>
102+
</configuration>
103+
</execution>
104+
</executions>
105+
</plugin>
106+
107+
81108
</plugins>
82109
</build>
83110

@@ -107,7 +134,6 @@
107134
<suppressionFile>dependency-check-report_suppressions.xml</suppressionFile>
108135
</configuration>
109136
</plugin>
110-
111137
</plugins>
112138
</reporting>
113139
</project>
Lines changed: 92 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,112 @@
11
package de.doubleslash.keeptime.common;
22

3+
import java.net.MalformedURLException;
4+
import java.net.URL;
5+
36
import org.slf4j.Logger;
47
import org.slf4j.LoggerFactory;
58

69
public class BrowserHelper {
10+
711
public static final Logger LOG = LoggerFactory.getLogger(BrowserHelper.class);
812

9-
private BrowserHelper() {
13+
private URL urlToOpen;
14+
15+
public BrowserHelper() {}
16+
17+
public BrowserHelper(final String url) {
18+
this.urlToOpen = getURLfromString(url);
19+
}
20+
21+
public BrowserHelper(final URL url) {
22+
this.urlToOpen = url;
23+
}
24+
25+
public void openURL(final URL url) {
26+
executeCommand(url);
27+
}
28+
29+
public void openURL(final String urlString) {
30+
final URL url = getURLfromString(urlString);
31+
32+
executeCommand(url);
33+
}
34+
35+
public void openURL() {
36+
executeCommand();
37+
}
1038

39+
public void setURL(final URL url) {
40+
this.urlToOpen = url;
1141
}
1242

13-
public static void openURL(final String url) {
43+
public void setURL(final String url) {
44+
this.urlToOpen = getURLfromString(url);
45+
}
46+
47+
private void executeCommand() {
1448
final Runtime rt = Runtime.getRuntime();
15-
if (System.getProperty("os.name").contains("Windows")) {
16-
try {
17-
rt.exec("rundll32 start " + url);
18-
} catch (final Exception e) {
19-
LOG.error(e.getMessage());
20-
}
21-
} else if (System.getProperty("os.name").contains("Linux")) {
22-
try {
23-
rt.exec("xdg-open " + url);
24-
} catch (final Exception e) {
25-
LOG.error(e.getMessage());
26-
}
49+
50+
if (OS.isWindows()) {
51+
executeCommandWindows(rt);
52+
} else if (OS.isLinux()) {
53+
executeCommandLinux(rt);
2754
} else {
28-
try {
29-
rt.exec("open " + url);
30-
} catch (final Exception e) {
31-
LOG.error(e.getMessage());
32-
}
55+
LOG.warn("OS is not supported");
3356
}
3457
}
3558

36-
public static void openFileInEditor(final String path) {
59+
private void executeCommand(final URL url) {
3760
final Runtime rt = Runtime.getRuntime();
3861

62+
if (OS.isWindows()) {
63+
executeCommandWindows(rt, url);
64+
} else if (OS.isLinux()) {
65+
executeCommandLinux(rt, url);
66+
} else {
67+
LOG.warn("OS is not supported");
68+
}
69+
}
70+
71+
private void executeCommandWindows(final Runtime rt) {
72+
try {
73+
rt.exec("rundll32 url.dll,FileProtocolHandler " + urlToOpen);
74+
} catch (final Exception e) {
75+
LOG.error(e.getMessage());
76+
}
77+
}
78+
79+
private void executeCommandWindows(final Runtime rt, final URL url) {
80+
try {
81+
rt.exec("rundll32 url.dll,FileProtocolHandler " + url);
82+
} catch (final Exception e) {
83+
LOG.error(e.getMessage());
84+
}
85+
}
86+
87+
private void executeCommandLinux(final Runtime rt) {
88+
try {
89+
rt.exec("xdg-open " + urlToOpen);
90+
} catch (final Exception e) {
91+
LOG.error(e.getMessage());
92+
}
93+
}
94+
95+
private void executeCommandLinux(final Runtime rt, final URL url) {
96+
try {
97+
rt.exec("xdg-open " + url);
98+
} catch (final Exception e) {
99+
LOG.warn(e.getMessage());
100+
}
101+
}
102+
103+
private URL getURLfromString(final String urlString) {
104+
try {
105+
return new URL(urlString);
106+
} catch (final MalformedURLException e) {
107+
LOG.error(e.getMessage());
108+
}
109+
110+
return null;
39111
}
40112
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package de.doubleslash.keeptime.common;
2+
3+
import java.io.File;
4+
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
8+
public class FileOpenHelper {
9+
10+
private static final Logger LOG = LoggerFactory.getLogger(FileOpenHelper.class);
11+
12+
private File fileToOpen;
13+
14+
public FileOpenHelper() {}
15+
16+
public FileOpenHelper(final File file) {
17+
this.fileToOpen = file;
18+
}
19+
20+
public FileOpenHelper(final String file) {
21+
this.fileToOpen = new File(file);
22+
}
23+
24+
public void openFile() {
25+
executeCommand();
26+
}
27+
28+
public void openFile(final File file) {
29+
executeCommand(file);
30+
}
31+
32+
public void openFile(final String fileString) {
33+
final File file = new File(fileString);
34+
35+
executeCommand(file);
36+
}
37+
38+
public void setFile(final File file) {
39+
this.fileToOpen = file;
40+
}
41+
42+
public void setFile(final String fileString) {
43+
this.fileToOpen = new File(fileString);
44+
}
45+
46+
private void executeCommand() {
47+
final Runtime rt = Runtime.getRuntime();
48+
49+
if (OS.isWindows()) {
50+
executeCommandWindows(rt);
51+
} else if (OS.isLinux()) {
52+
executeCommandLinux(rt);
53+
} else {
54+
LOG.warn("OS is not supported");
55+
}
56+
}
57+
58+
private void executeCommand(final File file) {
59+
final Runtime rt = Runtime.getRuntime();
60+
61+
if (OS.isWindows()) {
62+
executeCommandWindows(rt, file);
63+
} else if (OS.isLinux()) {
64+
executeCommandLinux(rt, file);
65+
} else {
66+
LOG.warn("OS is not supported");
67+
}
68+
}
69+
70+
private void executeCommandWindows(final Runtime rt) {
71+
try {
72+
rt.exec("rundll32 url.dll,FileProtocolHandler " + fileToOpen);
73+
} catch (final Exception e) {
74+
LOG.error(e.getMessage());
75+
}
76+
}
77+
78+
private void executeCommandWindows(final Runtime rt, final File file) {
79+
try {
80+
rt.exec("rundll32 url.dll,FileProtocolHandler " + file);
81+
} catch (final Exception e) {
82+
LOG.error(e.getMessage());
83+
}
84+
}
85+
86+
private void executeCommandLinux(final Runtime rt) {
87+
try {
88+
rt.exec("xdg-open " + fileToOpen);
89+
} catch (final Exception e) {
90+
LOG.error(e.getMessage());
91+
}
92+
}
93+
94+
private void executeCommandLinux(final Runtime rt, final File file) {
95+
try {
96+
rt.exec("xdg-open " + file);
97+
} catch (final Exception e) {
98+
LOG.error(e.getMessage());
99+
}
100+
}
101+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package de.doubleslash.keeptime.common;
2+
3+
public enum Licenses {
4+
5+
GPLV3("./licenses/GNU General Public License (GPL), Version 3.0.txt"),
6+
EPLV1("./licenses/EPL 1.0.txt"),
7+
APACHEV2("./licenses/Apache License, Version 2.0.txt"),
8+
LGPLV3("./licenses/GNU Lesser General Public License (LGPL), Version 3.0.txt"),
9+
MIT("./licenses/The MIT License.txt");
10+
11+
private final String path;
12+
13+
Licenses(final String licensePath) {
14+
path = licensePath;
15+
}
16+
17+
public String getPath() {
18+
return path;
19+
}
20+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package de.doubleslash.keeptime.common;
2+
3+
public class OS {
4+
5+
private OS() {
6+
7+
}
8+
9+
public static boolean isWindows() {
10+
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
11+
return true;
12+
}
13+
14+
return false;
15+
}
16+
17+
public static boolean isLinux() {
18+
if (System.getProperty("os.name").toLowerCase().contains("linux")) {
19+
return true;
20+
}
21+
22+
return false;
23+
}
24+
25+
}

src/main/java/de/doubleslash/keeptime/model/LicenceTableRow.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package de.doubleslash.keeptime.model;
22

3+
import de.doubleslash.keeptime.common.Licenses;
4+
35
public class LicenceTableRow {
46
private String name;
5-
private String license;
7+
private Licenses license;
68

7-
public LicenceTableRow(final String softwareName, final String licenceName) {
9+
public LicenceTableRow(final String softwareName, final Licenses licenceName) {
810
this.license = licenceName;
911
this.name = softwareName;
1012
}
@@ -17,11 +19,11 @@ public void setName(final String name) {
1719
this.name = name;
1820
}
1921

20-
public String getLicense() {
22+
public Licenses getLicense() {
2123
return license;
2224
}
2325

24-
public void setLicense(final String license) {
26+
public void setLicense(final Licenses license) {
2527
this.license = license;
2628
}
2729
}

0 commit comments

Comments
 (0)