-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathSystemUtil.java
More file actions
119 lines (103 loc) · 3.07 KB
/
Copy pathSystemUtil.java
File metadata and controls
119 lines (103 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* © Copyright IBM Corporation 2016.
* © Copyright HCL Technologies Ltd. 2017.
* LICENSE: Apache License, Version 2.0 https://www.apache.org/licenses/LICENSE-2.0
*/
package com.hcl.appscan.sdk.utils;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class SystemUtil {
private static final String DEFAULT_SERVER = "https://appscan.ibmcloud.com"; //$NON-NLS-1$
private static final String TIMESTAMP_FORMAT = "yyyy-MM-dd_HH-mm-ss"; //$NON-NLS-1$
/** Gets a timestamp using the default format.
* @return The current timestamp.
*/
public static String getTimeStamp() {
return getTimeStamp(TIMESTAMP_FORMAT);
}
/**
* Gets a timestamp using the given format.
* @param format The format of the timestamp.
* @return The current timestamp.
*/
public static String getTimeStamp(String format) {
Date date = new Date();
SimpleDateFormat sdf;
try {
sdf = new SimpleDateFormat(format);
} catch(NullPointerException | IllegalArgumentException e) {
sdf = new SimpleDateFormat(TIMESTAMP_FORMAT);
}
return sdf.format(date);
}
/**
* Adds all properties specified in APPSCAN_OPTS to the system properties.
*/
public static void setSystemProperties() {
String opts = System.getenv("APPSCAN_OPTS"); //$NON-NLS-1$
if(opts == null || opts.isEmpty())
return;
String[] properties = opts.split(" "); //$NON-NLS-1$
for(String property : properties) {
if(property == null || property.trim().length() == 0)
continue;
if(property.startsWith("-D")) //$NON-NLS-1$
property = property.substring(2);
String[] prop = property.split("="); //$NON-NLS-1$
if(prop.length == 2)
System.setProperty(prop[0], prop[1]);
else
System.setProperty(property, ""); //$NON-NLS-1$
}
}
/**
* Gets the operating system.
*
* @return A string representing the OS name. One of "win", "mac", or "linux".
*/
public static String getOS() {
String os = System.getProperty("os.name"); //$NON-NLS-1$
if(os.startsWith("Windows")) //$NON-NLS-1$
os = "win"; //$NON-NLS-1$
else if(os.startsWith("Mac")) //$NON-NLS-1$
os = "mac"; //$NON-NLS-1$
else
os = "linux"; //$NON-NLS-1$
return os;
}
/**
* Determine if running on Windows.
*
* @return True if running on Windows.
*/
public static boolean isWindows() {
return System.getProperty("os.name").startsWith("Windows"); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
* Determine if running on Mac OS.
*
* @return True if running on Mac OS.
*/
public static boolean isMac() {
return System.getProperty("os.name").startsWith("Mac"); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
* Gets the server url.
*
* @return
*/
public static String getDefaultServer() {
setSystemProperties();
String server = System.getProperty("BLUEMIX_SERVER"); //$NON-NLS-1$
return server != null ? server : DEFAULT_SERVER;
}
/**
* Get the system locale.
*
* @return A string representation of the system's locale.
*/
public static String getLocale() {
return Locale.getDefault().toString().replace('_', '-'); //$NON-NLS-1$ //$NON-NLS-2$
}
}