diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogPluginManagement.java b/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogPluginManagement.java index 859d37ba..91c6344c 100644 --- a/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogPluginManagement.java +++ b/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogPluginManagement.java @@ -16,6 +16,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.logging.Level; @@ -99,7 +100,7 @@ private void writeDiagnosticFlare(OutputStream out) throws IOException { zipOut.closeEntry(); zipOut.putNextEntry(new ZipEntry(contributor.getFilename() + ".error")); - zipOut.write(ExceptionUtils.getStackTrace(e).getBytes()); + zipOut.write(ExceptionUtils.getStackTrace(e).getBytes(StandardCharsets.UTF_8)); } finally { zipOut.closeEntry(); } diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/flare/ExceptionsFlare.java b/src/main/java/org/datadog/jenkins/plugins/datadog/flare/ExceptionsFlare.java index 26ed031e..c77c1bc2 100644 --- a/src/main/java/org/datadog/jenkins/plugins/datadog/flare/ExceptionsFlare.java +++ b/src/main/java/org/datadog/jenkins/plugins/datadog/flare/ExceptionsFlare.java @@ -5,9 +5,9 @@ import org.apache.commons.lang3.tuple.Pair; import org.datadog.jenkins.plugins.datadog.DatadogUtilities; -import java.io.IOException; import java.io.OutputStream; import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; @@ -16,8 +16,6 @@ @Extension public class ExceptionsFlare implements FlareContributor { - public static final DateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z"); - @Override public String getFilename() { return "exceptions.txt"; @@ -27,13 +25,14 @@ public String getFilename() { public void writeFileContents(OutputStream out) { // Print writer is not closed intentionally, to avoid closing out. // Auto-flush set to true ensures everything is witten - PrintWriter printWriter = new PrintWriter(out, true); + PrintWriter printWriter = new PrintWriter(out, true, StandardCharsets.UTF_8); + DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z"); BlockingQueue> exceptionsBuffer = DatadogUtilities.getExceptionsBuffer(); for (Pair p : exceptionsBuffer) { Date date = p.getKey(); Throwable exception = p.getValue(); - printWriter.println(DATE_FORMATTER.format(date) + ": " + ExceptionUtils.getStackTrace(exception)); + printWriter.println(dateFormatter.format(date) + ": " + ExceptionUtils.getStackTrace(exception)); } } } diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/flare/FlareContributor.java b/src/main/java/org/datadog/jenkins/plugins/datadog/flare/FlareContributor.java index 2a084620..fedda600 100644 --- a/src/main/java/org/datadog/jenkins/plugins/datadog/flare/FlareContributor.java +++ b/src/main/java/org/datadog/jenkins/plugins/datadog/flare/FlareContributor.java @@ -1,7 +1,6 @@ package org.datadog.jenkins.plugins.datadog.flare; import java.io.IOException; -import java.io.InputStream; import java.io.OutputStream; public interface FlareContributor { diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/flare/JenkinsLogsFlare.java b/src/main/java/org/datadog/jenkins/plugins/datadog/flare/JenkinsLogsFlare.java index 0362ff78..4b6da55a 100644 --- a/src/main/java/org/datadog/jenkins/plugins/datadog/flare/JenkinsLogsFlare.java +++ b/src/main/java/org/datadog/jenkins/plugins/datadog/flare/JenkinsLogsFlare.java @@ -6,6 +6,7 @@ import java.io.OutputStream; import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; import java.util.List; import java.util.ListIterator; import java.util.logging.Formatter; @@ -31,7 +32,7 @@ public String getFilename() { public void writeFileContents(OutputStream out) { // Print writer is not closed intentionally, to avoid closing out. // Auto-flush set to true ensures everything is witten - PrintWriter printWriter = new PrintWriter(out, true); + PrintWriter printWriter = new PrintWriter(out, true, StandardCharsets.UTF_8); List logRecords = Jenkins.logRecords; ListIterator it = logRecords.listIterator(logRecords.size()); diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/flare/PluginLogsFlare.java b/src/main/java/org/datadog/jenkins/plugins/datadog/flare/PluginLogsFlare.java index d858fa70..c9a87b62 100644 --- a/src/main/java/org/datadog/jenkins/plugins/datadog/flare/PluginLogsFlare.java +++ b/src/main/java/org/datadog/jenkins/plugins/datadog/flare/PluginLogsFlare.java @@ -11,6 +11,7 @@ import java.io.OutputStream; import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; import java.util.ListIterator; @@ -62,7 +63,7 @@ public String getFilename() { public void writeFileContents(OutputStream out) { // Print writer is not closed intentionally, to avoid closing out. // Auto-flush set to true ensures everything is witten - PrintWriter printWriter = new PrintWriter(out, true); + PrintWriter printWriter = new PrintWriter(out, true, StandardCharsets.UTF_8); Jenkins jenkins = Jenkins.get(); LogRecorderManager logRecorderManager = jenkins.getLog(); diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/flare/RuntimeInfoFlare.java b/src/main/java/org/datadog/jenkins/plugins/datadog/flare/RuntimeInfoFlare.java index b429ff16..1c0fa508 100644 --- a/src/main/java/org/datadog/jenkins/plugins/datadog/flare/RuntimeInfoFlare.java +++ b/src/main/java/org/datadog/jenkins/plugins/datadog/flare/RuntimeInfoFlare.java @@ -27,7 +27,7 @@ public void writeFileContents(OutputStream out) throws IOException { payload.put("os-architecture", System.getProperty("os.arch")); payload.put("os-name", System.getProperty("os.name")); payload.put("os-version", System.getProperty("os.version")); - payload.put("jenkins-version", Jenkins.getVersion().toString()); + payload.put("jenkins-version", String.valueOf(Jenkins.getVersion())); payload.put("plugin-version", DatadogUtilities.getDatadogPluginVersion()); String payloadString = payload.toString(2); diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/flare/ThreadDumpFlare.java b/src/main/java/org/datadog/jenkins/plugins/datadog/flare/ThreadDumpFlare.java index 3a7e7b60..5eb609be 100644 --- a/src/main/java/org/datadog/jenkins/plugins/datadog/flare/ThreadDumpFlare.java +++ b/src/main/java/org/datadog/jenkins/plugins/datadog/flare/ThreadDumpFlare.java @@ -2,9 +2,9 @@ import hudson.Extension; -import java.io.IOException; import java.io.OutputStream; import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; import java.util.Map; @Extension @@ -19,7 +19,7 @@ public String getFilename() { public void writeFileContents(OutputStream out) { // Print writer is not closed intentionally, to avoid closing out. // Auto-flush set to true ensures everything is witten - PrintWriter printWriter = new PrintWriter(out, true); + PrintWriter printWriter = new PrintWriter(out, true, StandardCharsets.UTF_8); Map allStackTraces = Thread.getAllStackTraces(); for (Map.Entry entry : allStackTraces.entrySet()) {