Improved BugReporter and moved it into its own separate module
This commit is contained in:
parent
4c6ab95cff
commit
6f9ccd282a
6 changed files with 38 additions and 56 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -5,3 +5,6 @@ classes/
|
||||||
src/main/java/META-INF/
|
src/main/java/META-INF/
|
||||||
dependency-reduced-pom.xml
|
dependency-reduced-pom.xml
|
||||||
/Everest/*
|
/Everest/*
|
||||||
|
/BugReporter/src/META-INF/
|
||||||
|
BugReporter/src/META-INF/
|
||||||
|
out/
|
||||||
|
|
|
@ -14,8 +14,6 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.rohitawate.everest.util;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
@ -28,44 +26,30 @@ public class BugReporter {
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
System.out.println("Everest Bug Reporting Service");
|
System.out.println("Everest Bug Reporting Service");
|
||||||
System.out.println();
|
System.out.println("-----------------------------\n");
|
||||||
System.out.println("Please describe the issue with as much detail and clarity as possible: ");
|
System.out.println("Please describe the issue with as much detail and clarity as possible (no newline): ");
|
||||||
String userMessage = scanner.nextLine();
|
String userMessage = scanner.nextLine();
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
builder.append("\nThank you for your input! The issue was recorded.\n\n");
|
|
||||||
builder.append("With your permission, this service can collect some anonymous, non-personal information about your system.\n");
|
|
||||||
builder.append("This information will help us to better reproduce the issue and fix it quickly.\n");
|
|
||||||
builder.append("This includes:\n");
|
|
||||||
builder.append(" - Operating system details.\n");
|
|
||||||
builder.append(" - Details about your Java Runtime Environment.\n\n");
|
|
||||||
builder.append("Allow? (Y/N)\n>> ");
|
|
||||||
System.out.print(builder.toString());
|
|
||||||
String allowSystemData = scanner.nextLine();
|
|
||||||
|
|
||||||
allowSystemData = allowSystemData.toLowerCase();
|
|
||||||
|
|
||||||
StringBuilder report = new StringBuilder();
|
|
||||||
report.append("Log date: ");
|
|
||||||
report.append(LocalDateTime.now());
|
|
||||||
report.append("\n\n");
|
|
||||||
if (allowSystemData.equals("y") || allowSystemData.equals("yes")) {
|
|
||||||
report.append(generateSystemDetails());
|
|
||||||
System.out.println("\nThat's great! We will include your system details in with the bug report.");
|
|
||||||
} else {
|
|
||||||
System.out.println("\nAlrighty! We will only include Everest's log files in the report.");
|
|
||||||
}
|
|
||||||
|
|
||||||
scanner.close();
|
scanner.close();
|
||||||
report.append("User Message:\n");
|
|
||||||
report.append(userMessage);
|
generateReportFile(generateReport(userMessage));
|
||||||
generateReport(report.toString());
|
|
||||||
generateZipFile();
|
generateZipFile();
|
||||||
|
|
||||||
System.out.println("\nYour issue was successfully reported and will be fixed soon.");
|
System.out.println("\nYour report was submitted successfully reported and will be evaluated soon.");
|
||||||
System.out.println("Thank you! :)");
|
System.out.println("Thank you! :)");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String generateSystemDetails() {
|
private static String generateReport(String userMessage) {
|
||||||
|
StringBuilder report = new StringBuilder();
|
||||||
|
report.append("Report date: ");
|
||||||
|
report.append(LocalDateTime.now());
|
||||||
|
report.append("\n\n");
|
||||||
|
report.append(getSystemDetails());
|
||||||
|
report.append("User Message:\n");
|
||||||
|
report.append(userMessage);
|
||||||
|
return report.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getSystemDetails() {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
String OS = System.getProperty("os.name");
|
String OS = System.getProperty("os.name");
|
||||||
if (OS.equals("Linux")) {
|
if (OS.equals("Linux")) {
|
||||||
|
@ -77,19 +61,18 @@ public class BugReporter {
|
||||||
builder.append(System.getProperty("os.arch"));
|
builder.append(System.getProperty("os.arch"));
|
||||||
builder.append(" ");
|
builder.append(" ");
|
||||||
builder.append(System.getProperty("os.version"));
|
builder.append(System.getProperty("os.version"));
|
||||||
builder.append("\n");
|
builder.append("\nJava VM: ");
|
||||||
builder.append("Java VM: ");
|
|
||||||
builder.append(System.getProperty("java.vm.name"));
|
builder.append(System.getProperty("java.vm.name"));
|
||||||
builder.append(" ");
|
builder.append("\nVM Version: ");
|
||||||
builder.append(System.getProperty("java.version"));
|
builder.append(System.getProperty("java.version"));
|
||||||
builder.append("\nJava VM Vendor: ");
|
builder.append("\nVM Vendor: ");
|
||||||
builder.append(System.getProperty("java.vendor"));
|
builder.append(System.getProperty("java.vendor"));
|
||||||
builder.append("\n\n");
|
builder.append("\n\n");
|
||||||
|
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void generateReport(String reportContents) {
|
private static void generateReportFile(String reportContents) {
|
||||||
String reportFileName = "Report - " + LocalDate.now() + ".txt";
|
String reportFileName = "Report - " + LocalDate.now() + ".txt";
|
||||||
try {
|
try {
|
||||||
BufferedWriter writer = new BufferedWriter(new FileWriter("logs/" + reportFileName));
|
BufferedWriter writer = new BufferedWriter(new FileWriter("logs/" + reportFileName));
|
||||||
|
@ -104,7 +87,7 @@ public class BugReporter {
|
||||||
try {
|
try {
|
||||||
Scanner scanner;
|
Scanner scanner;
|
||||||
FileInputStream fileInputStream;
|
FileInputStream fileInputStream;
|
||||||
ZipOutputStream zipStream = new ZipOutputStream(new FileOutputStream("Logs.zip"), Charset.forName("UTF-8"));
|
ZipOutputStream zipStream = new ZipOutputStream(new FileOutputStream("BugReport-" + LocalDate.now() + ".zip"), Charset.forName("UTF-8"));
|
||||||
File sourceDir = new File("logs/");
|
File sourceDir = new File("logs/");
|
||||||
String[] logFiles = sourceDir.list();
|
String[] logFiles = sourceDir.list();
|
||||||
|
|
||||||
|
@ -132,7 +115,7 @@ public class BugReporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getLinuxDetails() {
|
private static String getLinuxDetails() {
|
||||||
String line = "";
|
String line;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File etcDir = new File("/etc/");
|
File etcDir = new File("/etc/");
|
2
pom.xml
2
pom.xml
|
@ -45,7 +45,7 @@
|
||||||
<!-- add Main-Class to manifest file -->
|
<!-- add Main-Class to manifest file -->
|
||||||
<transformer
|
<transformer
|
||||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
<mainClass>com.rohitawate.everest.main.Main</mainClass>
|
<mainClass>com.rohitawate.everest.Main</mainClass>
|
||||||
</transformer>
|
</transformer>
|
||||||
</transformers>
|
</transformers>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.rohitawate.everest.main;
|
package com.rohitawate.everest;
|
||||||
|
|
||||||
import com.rohitawate.everest.util.EverestUtilities;
|
import com.rohitawate.everest.util.EverestUtilities;
|
||||||
import com.rohitawate.everest.util.Services;
|
import com.rohitawate.everest.util.Services;
|
|
@ -19,12 +19,12 @@ package com.rohitawate.everest.util;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
public class EverestUtilities {
|
public class EverestUtilities {
|
||||||
|
@ -50,19 +50,15 @@ public class EverestUtilities {
|
||||||
*/
|
*/
|
||||||
public static void createBugReporter() {
|
public static void createBugReporter() {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
File bugReporterFile = new File("Everest/BugReporter.jar");
|
InputStream inputStream = EverestUtilities.class.getResourceAsStream("/BugReporter.jar");
|
||||||
if (!bugReporterFile.exists()) {
|
Path bugReporter = Paths.get("Everest/BugReporter.jar");
|
||||||
InputStream inputStream = EverestUtilities.class.getResourceAsStream("/BugReporter.jar");
|
try {
|
||||||
Path bugReporter = Paths.get("Everest/BugReporter.jar");
|
Files.copy(inputStream, bugReporter, StandardCopyOption.REPLACE_EXISTING);
|
||||||
try {
|
} catch (IOException e) {
|
||||||
Files.copy(inputStream, bugReporter);
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
Services.loggingService.logInfo("BugReporter was copied to installation folder.", LocalDateTime.now());
|
|
||||||
} else {
|
|
||||||
Services.loggingService.logInfo("BugReporter was found.", LocalDateTime.now());
|
|
||||||
}
|
}
|
||||||
|
Services.loggingService.logInfo("BugReporter was copied to installation folder.", LocalDateTime.now());
|
||||||
|
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Reference in a new issue