Skip to content

Commit 1b28976

Browse files
committed
feat: add logging of host information and installed packages
- Implemented logging of host system details for better debugging and traceability. - Added output of installed packages to logs for improved environment visibility.
1 parent 5707d57 commit 1b28976

File tree

15 files changed

+193
-12
lines changed

15 files changed

+193
-12
lines changed

changelog.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# qase-java 4.0.12
2+
3+
## What's new
4+
5+
- Logging of host system details to improve debugging and traceability.
6+
- Output of installed packages in logs for better environment visibility.
7+
18
# qase-java 4.0.11
29

310
## What's new

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>io.qase</groupId>
88
<artifactId>qase-java</artifactId>
99
<packaging>pom</packaging>
10-
<version>4.0.11</version>
10+
<version>4.0.12</version>
1111
<modules>
1212
<module>qase-java-commons</module>
1313
<module>qase-api-client</module>

qase-api-client/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>qase-java</artifactId>
77
<groupId>io.qase</groupId>
8-
<version>4.0.11</version>
8+
<version>4.0.12</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

qase-api-v2-client/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.qase</groupId>
88
<artifactId>qase-java</artifactId>
9-
<version>4.0.11</version>
9+
<version>4.0.12</version>
1010
</parent>
1111

1212
<artifactId>qase-api-v2-client</artifactId>

qase-cucumber-v3-reporter/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>qase-java</artifactId>
77
<groupId>io.qase</groupId>
8-
<version>4.0.11</version>
8+
<version>4.0.12</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

qase-cucumber-v4-reporter/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>qase-java</artifactId>
77
<groupId>io.qase</groupId>
8-
<version>4.0.11</version>
8+
<version>4.0.12</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

qase-cucumber-v5-reporter/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>qase-java</artifactId>
77
<groupId>io.qase</groupId>
8-
<version>4.0.11</version>
8+
<version>4.0.12</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

qase-cucumber-v6-reporter/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>qase-java</artifactId>
77
<groupId>io.qase</groupId>
8-
<version>4.0.11</version>
8+
<version>4.0.12</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

qase-cucumber-v7-reporter/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>qase-java</artifactId>
77
<groupId>io.qase</groupId>
8-
<version>4.0.11</version>
8+
<version>4.0.12</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

qase-java-commons/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.qase</groupId>
88
<artifactId>qase-java</artifactId>
9-
<version>4.0.11</version>
9+
<version>4.0.12</version>
1010
</parent>
1111

1212
<artifactId>qase-java-commons</artifactId>

qase-java-commons/src/main/java/io/qase/commons/reporters/CoreReporterFactory.java

+9
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33
import io.qase.commons.config.ConfigFactory;
44
import io.qase.commons.config.QaseConfig;
5+
import io.qase.commons.utils.HostInfo;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
9+
import java.util.Map;
510

611
public class CoreReporterFactory {
12+
private static final Logger logger = LoggerFactory.getLogger(CoreReporterFactory.class);
713
private static CoreReporter instance;
814

915
private CoreReporterFactory() {
@@ -12,6 +18,9 @@ private CoreReporterFactory() {
1218
public static synchronized CoreReporter getInstance() {
1319
if (instance == null) {
1420
QaseConfig config = ConfigFactory.loadConfig();
21+
HostInfo hostInfoCollector = new HostInfo();
22+
Map<String, String> hostInfo = hostInfoCollector.getHostInfo(CoreReporterFactory.class.getPackage().getImplementationVersion());
23+
logger.debug("Using host info: {}", hostInfo.toString());
1524
instance = new CoreReporter(config);
1625
}
1726
return instance;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
package io.qase.commons.utils;
2+
3+
import java.io.*;
4+
import java.net.InetAddress;
5+
6+
import java.nio.file.Files;
7+
import java.nio.file.Paths;
8+
import java.util.*;
9+
10+
import java.util.regex.Matcher;
11+
import java.util.regex.Pattern;
12+
13+
14+
import org.json.JSONObject;
15+
16+
/**
17+
* Class that collects and provides information about the host system and installed packages
18+
*/
19+
public class HostInfo {
20+
21+
/**
22+
* Execute a command and return its output as a string
23+
*
24+
* @param command Command to execute
25+
* @param defaultValue Default value to return on error
26+
* @return Command output or default value
27+
*/
28+
private String execCommand(String command, String defaultValue) {
29+
StringBuilder output = new StringBuilder();
30+
try {
31+
Process process;
32+
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
33+
process = Runtime.getRuntime().exec(new String[]{"cmd.exe", "/c", command});
34+
} else {
35+
process = Runtime.getRuntime().exec(new String[]{"/bin/sh", "-c", command});
36+
}
37+
38+
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
39+
String line;
40+
while ((line = reader.readLine()) != null) {
41+
output.append(line).append("\n");
42+
}
43+
44+
int exitCode = process.waitFor();
45+
if (exitCode != 0) {
46+
System.err.println("Error executing command '" + command + "': Return code " + exitCode);
47+
return defaultValue;
48+
}
49+
50+
return output.toString().trim();
51+
} catch (IOException | InterruptedException e) {
52+
System.err.println("Exception executing command '" + command + "': " + e.getMessage());
53+
return defaultValue;
54+
}
55+
}
56+
57+
/**
58+
* Get detailed OS information based on the platform
59+
*
60+
* @return Detailed OS information
61+
*/
62+
private String getDetailedOsInfo() {
63+
String system = System.getProperty("os.name").toLowerCase();
64+
65+
try {
66+
if (system.contains("windows")) {
67+
return execCommand("ver", "");
68+
} else if (system.contains("mac")) {
69+
return execCommand("sw_vers -productVersion", "");
70+
} else {
71+
// Linux and others
72+
try {
73+
File osReleaseFile = new File("/etc/os-release");
74+
if (osReleaseFile.exists()) {
75+
String osRelease = new String(Files.readAllBytes(Paths.get("/etc/os-release")));
76+
Pattern pattern = Pattern.compile("PRETTY_NAME=\"(.+)\"");
77+
Matcher matcher = pattern.matcher(osRelease);
78+
if (matcher.find()) {
79+
return matcher.group(1);
80+
}
81+
}
82+
} catch (IOException e) {
83+
// Fallback if /etc/os-release doesn't exist or can't be read
84+
}
85+
86+
return System.getProperty("os.version");
87+
}
88+
} catch (Exception e) {
89+
System.err.println("Error getting detailed OS info: " + e.getMessage());
90+
return System.getProperty("os.version");
91+
}
92+
}
93+
94+
/**
95+
* Get information about the current host environment
96+
*
97+
* @param reporterVersion Reporter version to check
98+
* @return Map with host information
99+
*/
100+
public Map<String, String> getHostInfo(String reporterVersion) {
101+
Map<String, String> hostInfo = new HashMap<>();
102+
103+
try {
104+
// Get Java version
105+
String javaVersion = System.getProperty("java.version");
106+
107+
// Get Maven/Gradle version
108+
String buildToolVersion = "";
109+
String mavenOutput = execCommand("mvn --version", "");
110+
if (!mavenOutput.isEmpty()) {
111+
Pattern pattern = Pattern.compile("Apache Maven (\\S+)");
112+
Matcher matcher = pattern.matcher(mavenOutput);
113+
if (matcher.find()) {
114+
buildToolVersion = matcher.group(1);
115+
}
116+
} else {
117+
String gradleOutput = execCommand("gradle --version", "");
118+
if (!gradleOutput.isEmpty()) {
119+
Pattern pattern = Pattern.compile("Gradle (\\S+)");
120+
Matcher matcher = pattern.matcher(gradleOutput);
121+
if (matcher.find()) {
122+
buildToolVersion = matcher.group(1);
123+
}
124+
}
125+
}
126+
127+
hostInfo.put("system", System.getProperty("os.name").toLowerCase());
128+
hostInfo.put("machineName", InetAddress.getLocalHost().getHostName());
129+
hostInfo.put("release", System.getProperty("os.version"));
130+
hostInfo.put("version", getDetailedOsInfo());
131+
hostInfo.put("arch", System.getProperty("os.arch"));
132+
hostInfo.put("java", javaVersion);
133+
hostInfo.put("buildTool", buildToolVersion);
134+
hostInfo.put("reporter", reporterVersion);
135+
} catch (Exception e) {
136+
System.err.println("Error getting host info: " + e.getMessage());
137+
138+
try {
139+
hostInfo.put("system", System.getProperty("os.name").toLowerCase());
140+
hostInfo.put("machineName", InetAddress.getLocalHost().getHostName());
141+
hostInfo.put("release", System.getProperty("os.version"));
142+
hostInfo.put("version", "");
143+
hostInfo.put("arch", System.getProperty("os.arch"));
144+
hostInfo.put("java", "");
145+
hostInfo.put("buildTool", "");
146+
hostInfo.put("reporter", "");
147+
} catch (Exception ex) {
148+
System.err.println("Error creating fallback host info: " + ex.getMessage());
149+
}
150+
}
151+
152+
return hostInfo;
153+
}
154+
155+
/**
156+
* Convert the host info Map to a JSON string
157+
*
158+
* @param hostInfo The host info Map
159+
* @return A JSON string representation
160+
*/
161+
public String toJson(Map<String, String> hostInfo) {
162+
JSONObject json = new JSONObject(hostInfo);
163+
return json.toString(2);
164+
}
165+
}

qase-junit4-reporter/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>qase-java</artifactId>
77
<groupId>io.qase</groupId>
8-
<version>4.0.11</version>
8+
<version>4.0.12</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

qase-junit5-reporter/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>qase-java</artifactId>
77
<groupId>io.qase</groupId>
8-
<version>4.0.11</version>
8+
<version>4.0.12</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

qase-testng-reporter/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>qase-java</artifactId>
77
<groupId>io.qase</groupId>
8-
<version>4.0.11</version>
8+
<version>4.0.12</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

0 commit comments

Comments
 (0)