diff --git a/.gitignore b/.gitignore index 089ca50..a7c8a4f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,7 @@ classes/ src/main/java/META-INF/ dependency-reduced-pom.xml -/Everest/* \ No newline at end of file +/Everest/* +/BugReporter/src/META-INF/ +BugReporter/src/META-INF/ +out/ diff --git a/src/main/java/com/rohitawate/everest/util/BugReporter.java b/BugReporter/src/BugReporter.java similarity index 72% rename from src/main/java/com/rohitawate/everest/util/BugReporter.java rename to BugReporter/src/BugReporter.java index ecc0b45..61be43f 100644 --- a/src/main/java/com/rohitawate/everest/util/BugReporter.java +++ b/BugReporter/src/BugReporter.java @@ -14,8 +14,6 @@ * limitations under the License. */ -package com.rohitawate.everest.util; - import java.io.*; import java.nio.charset.Charset; import java.time.LocalDate; @@ -28,44 +26,30 @@ public class BugReporter { public static void main(String args[]) { Scanner scanner = new Scanner(System.in); System.out.println("Everest Bug Reporting Service"); - System.out.println(); - System.out.println("Please describe the issue with as much detail and clarity as possible: "); + System.out.println("-----------------------------\n"); + System.out.println("Please describe the issue with as much detail and clarity as possible (no newline): "); 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(); - report.append("User Message:\n"); - report.append(userMessage); - generateReport(report.toString()); + + generateReportFile(generateReport(userMessage)); 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! :)"); } - 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(); String OS = System.getProperty("os.name"); if (OS.equals("Linux")) { @@ -77,19 +61,18 @@ public class BugReporter { builder.append(System.getProperty("os.arch")); builder.append(" "); builder.append(System.getProperty("os.version")); - builder.append("\n"); - builder.append("Java VM: "); + builder.append("\nJava VM: "); builder.append(System.getProperty("java.vm.name")); - builder.append(" "); + builder.append("\nVM Version: "); builder.append(System.getProperty("java.version")); - builder.append("\nJava VM Vendor: "); + builder.append("\nVM Vendor: "); builder.append(System.getProperty("java.vendor")); builder.append("\n\n"); return builder.toString(); } - private static void generateReport(String reportContents) { + private static void generateReportFile(String reportContents) { String reportFileName = "Report - " + LocalDate.now() + ".txt"; try { BufferedWriter writer = new BufferedWriter(new FileWriter("logs/" + reportFileName)); @@ -104,7 +87,7 @@ public class BugReporter { try { Scanner scanner; 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/"); String[] logFiles = sourceDir.list(); @@ -132,7 +115,7 @@ public class BugReporter { } private static String getLinuxDetails() { - String line = ""; + String line; try { File etcDir = new File("/etc/"); diff --git a/pom.xml b/pom.xml index f71e7e0..accc1d1 100644 --- a/pom.xml +++ b/pom.xml @@ -45,7 +45,7 @@ - com.rohitawate.everest.main.Main + com.rohitawate.everest.Main diff --git a/src/main/java/com/rohitawate/everest/main/Main.java b/src/main/java/com/rohitawate/everest/Main.java similarity index 98% rename from src/main/java/com/rohitawate/everest/main/Main.java rename to src/main/java/com/rohitawate/everest/Main.java index 71976b8..889ad90 100644 --- a/src/main/java/com/rohitawate/everest/main/Main.java +++ b/src/main/java/com/rohitawate/everest/Main.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.rohitawate.everest.main; +package com.rohitawate.everest; import com.rohitawate.everest.util.EverestUtilities; import com.rohitawate.everest.util.Services; diff --git a/src/main/java/com/rohitawate/everest/util/EverestUtilities.java b/src/main/java/com/rohitawate/everest/util/EverestUtilities.java index 8b06948..6e8eb11 100644 --- a/src/main/java/com/rohitawate/everest/util/EverestUtilities.java +++ b/src/main/java/com/rohitawate/everest/util/EverestUtilities.java @@ -19,12 +19,12 @@ package com.rohitawate.everest.util; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; -import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; import java.time.LocalDateTime; public class EverestUtilities { @@ -50,19 +50,15 @@ public class EverestUtilities { */ public static void createBugReporter() { new Thread(() -> { - File bugReporterFile = new File("Everest/BugReporter.jar"); - if (!bugReporterFile.exists()) { - InputStream inputStream = EverestUtilities.class.getResourceAsStream("/BugReporter.jar"); - Path bugReporter = Paths.get("Everest/BugReporter.jar"); - try { - Files.copy(inputStream, bugReporter); - } 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()); + InputStream inputStream = EverestUtilities.class.getResourceAsStream("/BugReporter.jar"); + Path bugReporter = Paths.get("Everest/BugReporter.jar"); + try { + Files.copy(inputStream, bugReporter, StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + e.printStackTrace(); } + Services.loggingService.logInfo("BugReporter was copied to installation folder.", LocalDateTime.now()); + }).start(); } } diff --git a/src/main/resources/BugReporter.jar b/src/main/resources/BugReporter.jar index be670cf..bdde1bf 100644 Binary files a/src/main/resources/BugReporter.jar and b/src/main/resources/BugReporter.jar differ