From 7172e65bd7fca736384de2078c55cf171b77552c Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sat, 2 Dec 2017 12:28:08 +0200 Subject: [PATCH] Added System information to Debug page and removed /plan m dump command & related utilities --- .../plan/command/commands/ManageCommand.java | 1 - .../commands/manage/ManageDumpCommand.java | 63 ---- .../webserver/response/DebugPageResponse.java | 28 +- .../plan/utilities/file/dump/DumpLog.java | 95 ------ .../plan/utilities/file/dump/DumpUtils.java | 306 ------------------ .../file/{dump => export}/Hastebin.java | 2 +- .../plan/utilities/dump/DumpLogTest.java | 41 --- .../{dump => export}/HastebinTest.java | 4 +- 8 files changed, 30 insertions(+), 510 deletions(-) delete mode 100644 Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageDumpCommand.java delete mode 100644 Plan/src/main/java/com/djrapitops/plan/utilities/file/dump/DumpLog.java delete mode 100644 Plan/src/main/java/com/djrapitops/plan/utilities/file/dump/DumpUtils.java rename Plan/src/main/java/com/djrapitops/plan/utilities/file/{dump => export}/Hastebin.java (98%) delete mode 100644 Plan/test/main/java/com/djrapitops/plan/utilities/dump/DumpLogTest.java rename Plan/test/main/java/com/djrapitops/plan/utilities/{dump => export}/HastebinTest.java (95%) diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/ManageCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/ManageCommand.java index bbc9d6907..bd64bdc2c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/ManageCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/ManageCommand.java @@ -43,7 +43,6 @@ public class ManageCommand extends TreeCommand { new ManageImportCommand(plugin), new ManageRemoveCommand(plugin), new ManageClearCommand(plugin), - new ManageDumpCommand(plugin), new ManageSetupCommand(plugin), new ManageDisableCommand() ); diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageDumpCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageDumpCommand.java deleted file mode 100644 index 6130d3679..000000000 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageDumpCommand.java +++ /dev/null @@ -1,63 +0,0 @@ -package main.java.com.djrapitops.plan.command.commands.manage; - -import com.djrapitops.plugin.command.CommandType; -import com.djrapitops.plugin.command.ISender; -import com.djrapitops.plugin.command.SubCommand; -import com.djrapitops.plugin.task.AbsRunnable; -import com.djrapitops.plugin.task.RunnableFactory; -import main.java.com.djrapitops.plan.Plan; -import main.java.com.djrapitops.plan.settings.Permissions; -import main.java.com.djrapitops.plan.settings.locale.Locale; -import main.java.com.djrapitops.plan.settings.locale.Msg; -import main.java.com.djrapitops.plan.utilities.file.dump.DumpUtils; - -/** - * This manage subcommand is used to dump important data to pastebin, so it's - * easier to write an issue. - * - * @author Fuzzlemann - * @since 3.7.0 - */ -public class ManageDumpCommand extends SubCommand { - - private final Plan plugin; - - /** - * Class Constructor. - * - * @param plugin Current instance of Plan - */ - public ManageDumpCommand(Plan plugin) { - super("dump", - CommandType.CONSOLE, - Permissions.MANAGE.getPermission(), - Locale.get(Msg.CMD_USG_MANAGE_DUMP).toString()); - - this.plugin = plugin; - } - - @Override - public String[] addHelp() { - return Locale.get(Msg.CMD_HELP_MANAGE_DUMP).toArray(); - } - - @Override - public boolean onCommand(ISender sender, String commandLabel, String[] args) { - dump(sender); - return true; - } - - private void dump(ISender sender) { - RunnableFactory.createNew(new AbsRunnable("DumpTask") { - @Override - public void run() { - try { - sender.sendLink("Link to the Dump", DumpUtils.dump(plugin)); - sender.sendLink("Report Issues here", "https://github.com/Rsl1122/Plan-PlayerAnalytics/issues/new"); - } finally { - this.cancel(); - } - } - }).runTaskAsynchronously(); - } -} diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/response/DebugPageResponse.java b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/response/DebugPageResponse.java index 8c8919f2d..894498a74 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/response/DebugPageResponse.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/response/DebugPageResponse.java @@ -1,4 +1,4 @@ -/* +/* * Licence is provided in the jar as license.yml also here: * https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml */ @@ -18,6 +18,8 @@ import main.java.com.djrapitops.plan.utilities.html.Html; import java.io.File; import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; import java.nio.charset.Charset; import java.sql.SQLException; import java.util.*; @@ -79,6 +81,30 @@ public class DebugPageResponse extends ErrorResponse { } catch (SQLException e) { Log.toLog(this.getClass().getName(), e); } + content.append("

"); + + RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean(); + Properties properties = System.getProperties(); + + String osName = properties.getProperty("os.name"); + String osVersion = properties.getProperty("os.version"); + String osArch = properties.getProperty("os.arch"); + + String javaVendor = properties.getProperty("java.vendor"); + String javaVersion = properties.getProperty("java.version"); + + String javaVMVendor = properties.getProperty("java.vm.vendor"); + String javaVMName = properties.getProperty("java.vm.name"); + String javaVMVersion = properties.getProperty("java.vm.version"); + List javaVMFlags = runtimeMxBean.getInputArguments(); + + content.append("**Operating System:** ").append(osName).append(" (").append(osArch) + .append(") version ").append(osVersion).append("
"); + + content.append("**Java Version:** ").append(javaVersion).append(", ").append(javaVendor).append("
"); + content.append("**Java VM Version:** ").append(javaVMName).append(" version ").append(javaVMVersion) + .append(", ").append(javaVMVendor).append("
"); + content.append("**Java VM Flags:** ").append(javaVMFlags).append("
"); content.append(""); } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/file/dump/DumpLog.java b/Plan/src/main/java/com/djrapitops/plan/utilities/file/dump/DumpLog.java deleted file mode 100644 index 6d83af7cb..000000000 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/file/dump/DumpLog.java +++ /dev/null @@ -1,95 +0,0 @@ -package main.java.com.djrapitops.plan.utilities.file.dump; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * @author Fuzzlemann - * @since 3.6.2 - */ -public class DumpLog { - - private final List lines = new ArrayList<>(); - - /** - * Writes a header - * - * @param header The name of the header - */ - public void addHeader(String header) { - addLines("", "--- " + header + " ---"); - } - - /** - * Adds a String {@code value} to a String {@code key} - * - * @param key The key - * @param value The value - */ - public void add(String key, String value) { - addLine(key + ": " + value); - } - - /** - * Adds a boolean {@code value} to a String {@code key} - * - * @param key The key - * @param value The value - */ - public void add(String key, boolean value) { - addLine(key + ": " + value); - } - - /** - * Adds multiple {@link CharSequence CharSequences} stored in an {@link Iterable} - * to a String {@code key} - * - * @param key The key - * @param value The CharSequences stored in an Iterable - */ - public void add(String key, Iterable value) { - addLine(key + ": " + String.join(", ", value)); - } - - /** - * Adds multiple lines - * - * @param lines The CharSequences stored in an Iterable - */ - public void addLines(Iterable lines) { - lines.forEach(this::addLine); - } - - /** - * Adds multiple lines - * - * @param lines The lines - */ - public void addLines(CharSequence... lines) { - Arrays.stream(lines).forEach(this::addLine); - } - - /** - * Adds one line - * - * @param line The content of the line - */ - public void addLine(CharSequence line) { - lines.add(line == null ? "\n" : line.toString()); - } - - /** - * Uploads the dump log to Hastebin using HTTPS and POST - * - * @return The link to the Dump Log - */ - String upload() { - return Hastebin.safeUpload(this.toString()); - } - - @Override - public String toString() { - return String.join("\n", lines); - } -} diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/file/dump/DumpUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/file/dump/DumpUtils.java deleted file mode 100644 index 11796e840..000000000 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/file/dump/DumpUtils.java +++ /dev/null @@ -1,306 +0,0 @@ -package main.java.com.djrapitops.plan.utilities.file.dump; - -import com.djrapitops.plugin.api.Benchmark; -import com.djrapitops.plugin.api.utility.log.Log; -import com.djrapitops.plugin.utilities.Verify; -import main.java.com.djrapitops.plan.Plan; -import main.java.com.djrapitops.plan.settings.Settings; -import main.java.com.djrapitops.plan.utilities.file.FileUtil; -import org.bukkit.Server; -import org.bukkit.plugin.Plugin; - -import java.io.File; -import java.io.IOException; -import java.lang.management.ManagementFactory; -import java.lang.management.RuntimeMXBean; -import java.nio.charset.Charset; -import java.nio.charset.MalformedInputException; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.Date; -import java.util.List; -import java.util.Properties; -import java.util.stream.Collectors; - -/** - * @author Fuzzlemann - * @since 3.6.2 - */ -public class DumpUtils { - - /** - * Constructor used to hide the public constructor - */ - private DumpUtils() { - throw new IllegalStateException("Utility Class"); - } - - /** - * Dumps the following things to Hastebin - *
    - *
  • The current time with the time zone
  • - *
  • The system details
  • - *
  • The server details
  • - *
  • The Plan details
  • - *
  • Some important Configuration details
  • - *
  • The Plan timings
  • - *
  • The error log (if present)
  • - *
  • The debug log (if present)
  • - *
- * - * @param plugin The Plan instance - * @return The link to the Dump Log - */ - public static String dump(Plan plugin) { - DumpLog log = new DumpLog(); - - addTime(log); - addSystemDetails(log); - addServerDetails(log, plugin); - addPlanDetails(log, plugin); - addConfigurationDetails(log, plugin); - addTimings(log, plugin); - try { - addErrorLog(log, plugin); - addDebugLog(log, plugin); - } catch (IOException e) { - Log.toLog("DumpUtils.dump", e); - return "Error"; - } - - return log.upload(); - } - - /** - * Adds the current time to the Dump log - *

- * The format of the time is "dd.MM.yyy HH:mm:ss z" - * - * @param log The log - */ - private static void addTime(DumpLog log) { - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss z"); - String time = simpleDateFormat.format(new Date()); - - log.add("Time", time); - } - - /** - * Adds the following system details to the Dump log - *

    - *
  • The Operating System Name
  • - *
  • The Operating System Version
  • - *
  • The Operating System Architecture
  • - *
  • The Java Vendor
  • - *
  • The Java Version
  • - *
  • The JVM Vendor
  • - *
  • The JVM Version
  • - *
  • The JVM Name
  • - *
  • The JVM Flags
  • - *
- * - * @param log The log - */ - private static void addSystemDetails(DumpLog log) { - RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean(); - Properties properties = System.getProperties(); - - String osName = properties.getProperty("os.name"); - String osVersion = properties.getProperty("os.version"); - String osArch = properties.getProperty("os.arch"); - - String javaVendor = properties.getProperty("java.vendor"); - String javaVersion = properties.getProperty("java.version"); - - String javaVMVendor = properties.getProperty("java.vm.vendor"); - String javaVMName = properties.getProperty("java.vm.name"); - String javaVMVersion = properties.getProperty("java.vm.version"); - List javaVMFlags = runtimeMxBean.getInputArguments(); - - log.addHeader("System Details"); - - log.add("Operating System ", osName + " (" + osArch + ") version " + osVersion); - - log.add("Java Version", javaVersion + ", " + javaVendor); - log.add("Java VM Version", javaVMName + " version " + javaVMVersion + ", " + javaVMVendor); - log.add("Java VM Flags", javaVMFlags); - } - - /** - * Adds the following server details to the Dump log - *
    - *
  • The Minecraft Version
  • - *
  • The Server Type
  • - *
  • The installed plugins with the version
  • - *
- * - * @param log The log - * @param plan The Plan instance - */ - private static void addServerDetails(DumpLog log, Plan plan) { - Server server = plan.getServer(); - - String minecraftVersion = server.getVersion(); - String serverType = server.getName(); - - List plugins = Arrays.stream(server.getPluginManager().getPlugins()) - .map(Plugin::getDescription) - .map(description -> description.getName() + " " + description.getVersion()) - .sorted(String::compareToIgnoreCase) - .collect(Collectors.toList()); - - log.addHeader("Server Details"); - - log.add("Minecraft Version", minecraftVersion); - log.add("Server Type", serverType); - - log.addHeader("Plugins"); - log.addLines(plugins); - } - - /** - * Adds the following Plan details to the Dump log - *
    - *
  • The Plan Version
  • - *
  • The Abstract Plugin Framework Version
  • - *
- * - * @param log The log - * @param plan The Plan instance - */ - private static void addPlanDetails(DumpLog log, Plan plan) { - String planVersion = plan.getVersion(); - - log.addHeader("Plan Details"); - - log.add("Plan Version", planVersion); - } - - /** - * Adds the following Configuration Details to the Dump Log - *
    - *
  • WebServer enabled
  • - *
  • HTTPS used
  • - *
  • Analysis on enable refresh
  • - *
  • Analysis Export
  • - *
  • Alternative Server IP usage
  • - *
  • Chat Gathering
  • - *
  • Kill Gathering
  • - *
  • Command Gathering
  • - *
  • Alias Combining
  • - *
  • Unknown Command Logging
  • - *
  • The locale
  • - *
  • The DB Type
  • - *
- * - * @param log The log - * @param plan The Plan instance - */ - private static void addConfigurationDetails(DumpLog log, Plan plan) { - boolean usingHTTPS = plan.getWebServer().isUsingHTTPS(); - boolean analysisExport = Settings.ANALYSIS_EXPORT.isTrue(); - boolean usingAlternativeServerIP = Settings.SHOW_ALTERNATIVE_IP.isTrue(); - - boolean combineAliases = Settings.COMBINE_COMMAND_ALIASES.isTrue(); - boolean unknownCommandLogging = Settings.LOG_UNKNOWN_COMMANDS.isTrue(); - - String locale = Settings.LOCALE.toString(); - String dbType = Settings.DB_TYPE.toString(); - - log.addHeader("Plan Configuration"); - - log.add("Webserver HTTPS", usingHTTPS); - log.add("Analysis Export", analysisExport); - log.add("Alternative Server IP", usingAlternativeServerIP); - - log.add("Combine Aliases", combineAliases); - log.add("Unknown Command Logging", unknownCommandLogging); - log.add("Locale", locale); - - log.add("Database Type", dbType); - } - - /** - * Adds the timings to the Dump log - * - * @param log The log - * @param plan The Plan instance - */ - private static void addTimings(DumpLog log, Plan plan) { - String[] timings = Benchmark.getAverages().asStringArray(); - - log.addHeader("Timings"); - log.addLines(timings); - } - - /** - * Adds the error log to the Dump Log if present - * - * @param log The log - * @param plan The Plan instance - * @throws IOException when an error while reading occurred - */ - private static void addErrorLog(DumpLog log, Plan plan) throws IOException { - File errorFile = new File(plan.getDataFolder(), Log.ERROR_FILE_NAME); - - if (!Verify.exists(errorFile)) { - return; - } - - List lines = readLines(errorFile); - - log.addHeader("Error Log"); - log.addLines(lines); - } - - /** - * Adds the debug log to the Dump Log if present - * - * @param log The log - * @param plan The Plan instance - * @throws IOException when an error while reading occurred - */ - private static void addDebugLog(DumpLog log, Plan plan) throws IOException { - File debugFile = new File(plan.getDataFolder(), Log.DEBUG_FILE_NAME); - - if (!Verify.exists(debugFile)) { - return; - } - - List lines = readLines(debugFile); - - log.addHeader("Debug Log"); - log.addLines(lines); - } - - /** - * Reads the lines of a file - * - * @param file The file - * @return The lines - * @throws IOException when an error while reading occurred - */ - private static List readLines(File file) throws IOException { - for (Charset charset : Charset.availableCharsets().values()) { - try { - return readLines(file, charset); - } catch (MalformedInputException ignored) { - /* Ignores MalformedInputException, just trying the next charset */ - } - } - - throw new IOException("No applicable Charset found"); - } - - /** - * Reads the lines of a file with that specific charset - * - * @param file The file - * @param charset The CharSet - * @return The lines - * @throws IOException when an error while reading occurred - */ - private static List readLines(File file, Charset charset) throws IOException { - return FileUtil.lines(file, charset); - } -} diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/file/dump/Hastebin.java b/Plan/src/main/java/com/djrapitops/plan/utilities/file/export/Hastebin.java similarity index 98% rename from Plan/src/main/java/com/djrapitops/plan/utilities/file/dump/Hastebin.java rename to Plan/src/main/java/com/djrapitops/plan/utilities/file/export/Hastebin.java index 4d72d540f..2eabc3869 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/file/dump/Hastebin.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/file/export/Hastebin.java @@ -1,4 +1,4 @@ -package main.java.com.djrapitops.plan.utilities.file.dump; +package main.java.com.djrapitops.plan.utilities.file.export; import com.djrapitops.plugin.api.utility.log.Log; import com.google.common.base.Splitter; diff --git a/Plan/test/main/java/com/djrapitops/plan/utilities/dump/DumpLogTest.java b/Plan/test/main/java/com/djrapitops/plan/utilities/dump/DumpLogTest.java deleted file mode 100644 index 3e0ebfaff..000000000 --- a/Plan/test/main/java/com/djrapitops/plan/utilities/dump/DumpLogTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package main.java.com.djrapitops.plan.utilities.dump; - -import main.java.com.djrapitops.plan.utilities.file.dump.DumpLog; -import org.junit.Test; - -import java.util.Arrays; - -import static junit.framework.TestCase.assertEquals; - -/** - * @author Fuzzlemann - */ -public class DumpLogTest { - - @Test - public void testDumpLogCreation() { - DumpLog testLog = new DumpLog(); - - testLog.addHeader("Test Header"); - testLog.add("StringValue", "Test"); - testLog.add("BooleanValue", true); - testLog.add("IterableValue", Arrays.asList("Iterable 1", "Iterable 2")); - - testLog.addLine(new StringBuilder("CharSequence Test")); - testLog.addLines(new StringBuilder("CharSequences Test"), new StringBuilder("CharSequences Test")); - testLog.addLines(Arrays.asList("Iterable 1", "Iterable 2")); - - String expResult = "\n--- Test Header ---\n" + - "StringValue: Test\n" + - "BooleanValue: true\n" + - "IterableValue: Iterable 1, Iterable 2\n" + - "CharSequence Test\n" + - "CharSequences Test\n" + - "CharSequences Test\n" + - "Iterable 1\n" + - "Iterable 2"; - String result = testLog.toString(); - - assertEquals(expResult, result); - } -} diff --git a/Plan/test/main/java/com/djrapitops/plan/utilities/dump/HastebinTest.java b/Plan/test/main/java/com/djrapitops/plan/utilities/export/HastebinTest.java similarity index 95% rename from Plan/test/main/java/com/djrapitops/plan/utilities/dump/HastebinTest.java rename to Plan/test/main/java/com/djrapitops/plan/utilities/export/HastebinTest.java index 5d015c9db..48cc17de0 100644 --- a/Plan/test/main/java/com/djrapitops/plan/utilities/dump/HastebinTest.java +++ b/Plan/test/main/java/com/djrapitops/plan/utilities/export/HastebinTest.java @@ -1,10 +1,10 @@ -package main.java.com.djrapitops.plan.utilities.dump; +package main.java.com.djrapitops.plan.utilities.export; import com.djrapitops.plugin.StaticHolder; import com.djrapitops.plugin.api.utility.log.Log; import com.google.common.collect.Iterables; import main.java.com.djrapitops.plan.utilities.MiscUtils; -import main.java.com.djrapitops.plan.utilities.file.dump.Hastebin; +import main.java.com.djrapitops.plan.utilities.file.export.Hastebin; import org.bukkit.plugin.java.JavaPlugin; import org.json.simple.parser.ParseException; import org.junit.Before;