From fdfa6e28610e24dd6e4944ab6f1644487805deae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Vaissi=C3=A8re?= Date: Sun, 17 Sep 2017 18:06:23 +0200 Subject: [PATCH] rename PluginConfig to KeepStdioConfig as it is more explicit. --- .../java/hudson/tasks/junit/CaseResult.java | 12 +-- .../java/hudson/tasks/junit/JUnitParser.java | 12 +-- .../tasks/junit/JUnitResultArchiver.java | 2 +- .../hudson/tasks/junit/KeepStdioConfig.java | 86 +++++++++++++++++++ .../java/hudson/tasks/junit/PluginConfig.java | 85 ------------------ .../java/hudson/tasks/junit/SuiteResult.java | 10 +-- .../java/hudson/tasks/junit/TestResult.java | 14 +-- .../hudson/tasks/junit/TrimStdioTest.java | 10 +-- 8 files changed, 116 insertions(+), 115 deletions(-) create mode 100644 src/main/java/hudson/tasks/junit/KeepStdioConfig.java delete mode 100644 src/main/java/hudson/tasks/junit/PluginConfig.java diff --git a/src/main/java/hudson/tasks/junit/CaseResult.java b/src/main/java/hudson/tasks/junit/CaseResult.java index 234f789b6..52af6ccf0 100644 --- a/src/main/java/hudson/tasks/junit/CaseResult.java +++ b/src/main/java/hudson/tasks/junit/CaseResult.java @@ -94,17 +94,17 @@ private static float parseTime(Element testCase) { } /** - * @deprecated in favor of {@link #CaseResult(SuiteResult, Element, String, PluginConfig)}. + * @deprecated in favor of {@link #CaseResult(SuiteResult, Element, String, KeepStdioConfig)}. */ @Deprecated CaseResult(SuiteResult parent, Element testCase, String testClassName, boolean keepLongStdio) { - this(parent, testCase, testClassName, PluginConfig.defaults(keepLongStdio)); + this(parent, testCase, testClassName, KeepStdioConfig.defaults(keepLongStdio)); } /** * @since 1.23 */ - CaseResult(SuiteResult parent, Element testCase, String testClassName, PluginConfig config) { + CaseResult(SuiteResult parent, Element testCase, String testClassName, KeepStdioConfig config) { // schema for JUnit report XML format is not available in Ant, // so I don't know for sure what means what. // reports in http://www.nabble.com/difference-in-junit-publisher-and-ant-junitreport-tf4308604.html#a12265700 @@ -141,7 +141,7 @@ private static float parseTime(Element testCase) { stderr = possiblyTrimStdio(_this, config, testCase.elementText("system-err")); } - static String possiblyTrimStdio(Collection results, PluginConfig config, String stdio) { // HUDSON-6516 + static String possiblyTrimStdio(Collection results, KeepStdioConfig config, String stdio) { // HUDSON-6516 if (stdio == null) { return null; } @@ -168,10 +168,10 @@ static String possiblyTrimStdio(Collection results, PluginConfig con } /** - * Flavor of {@link #possiblyTrimStdio(Collection, PluginConfig, String)} that doesn't try to read the whole thing into memory. + * Flavor of {@link #possiblyTrimStdio(Collection, KeepStdioConfig, String)} that doesn't try to read the whole thing into memory. */ @SuppressFBWarnings(value = "DM_DEFAULT_ENCODING", justification = "Expected behavior") - static String possiblyTrimStdio(Collection results, PluginConfig config, File stdio) throws IOException { + static String possiblyTrimStdio(Collection results, KeepStdioConfig config, File stdio) throws IOException { long len = stdio.length(); if (config.isKeepLongStdio() && len < 1024 * 1024) { return FileUtils.readFileToString(stdio); diff --git a/src/main/java/hudson/tasks/junit/JUnitParser.java b/src/main/java/hudson/tasks/junit/JUnitParser.java index 07987a2c8..9c037de42 100644 --- a/src/main/java/hudson/tasks/junit/JUnitParser.java +++ b/src/main/java/hudson/tasks/junit/JUnitParser.java @@ -47,7 +47,7 @@ @Extension public class JUnitParser extends TestResultParser { - private final PluginConfig config; + private final KeepStdioConfig config; private final boolean allowEmptyResults; /** TODO TestResultParser.all does not seem to ever be called so why must this be an Extension? */ @@ -62,7 +62,7 @@ public JUnitParser() { */ @Deprecated public JUnitParser(boolean keepLongStdio) { - this.config = PluginConfig.defaults(keepLongStdio); + this.config = KeepStdioConfig.defaults(keepLongStdio); this.allowEmptyResults = false; } @@ -71,7 +71,7 @@ public JUnitParser(boolean keepLongStdio) { * @param allowEmptyResults if true, empty results are allowed * @since 1.23 */ - public JUnitParser(PluginConfig config, boolean allowEmptyResults) { + public JUnitParser(KeepStdioConfig config, boolean allowEmptyResults) { this.config = config; this.allowEmptyResults = allowEmptyResults; } @@ -82,7 +82,7 @@ public JUnitParser(PluginConfig config, boolean allowEmptyResults) { * @since 1.10 */ public JUnitParser(boolean keepLongStdio, boolean allowEmptyResults) { - this.config = PluginConfig.defaults(keepLongStdio); + this.config = KeepStdioConfig.defaults(keepLongStdio); this.allowEmptyResults = allowEmptyResults; } @@ -121,10 +121,10 @@ private static final class ParseResultCallable extends MasterToSlaveFileCallable private final long buildTime; private final String testResults; private final long nowMaster; - private final PluginConfig config; + private final KeepStdioConfig config; private final boolean allowEmptyResults; - private ParseResultCallable(String testResults, long buildTime, long nowMaster, PluginConfig config, + private ParseResultCallable(String testResults, long buildTime, long nowMaster, KeepStdioConfig config, boolean allowEmptyResults) { this.buildTime = buildTime; this.testResults = testResults; diff --git a/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java b/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java index 5564016b5..9b5e7d6fd 100644 --- a/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java +++ b/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java @@ -128,7 +128,7 @@ public JUnitResultArchiver( private TestResult parse(String expandedTestResults, Run run, @Nonnull FilePath workspace, Launcher launcher, TaskListener listener) throws IOException, InterruptedException { - return new JUnitParser(new PluginConfig(this.isKeepLongStdio(), + return new JUnitParser(new KeepStdioConfig(this.isKeepLongStdio(), this.getMaxSucceededSize(), this.getMaxFailedSize()), this.isAllowEmptyResults()) diff --git a/src/main/java/hudson/tasks/junit/KeepStdioConfig.java b/src/main/java/hudson/tasks/junit/KeepStdioConfig.java new file mode 100644 index 000000000..d48c25582 --- /dev/null +++ b/src/main/java/hudson/tasks/junit/KeepStdioConfig.java @@ -0,0 +1,86 @@ +package hudson.tasks.junit; + +import java.io.Serializable; + +/** + * Object storing all stdio-keeping related configuration. + */ +public final class KeepStdioConfig implements Serializable { + + private final static int DEFAULT_MAX_SUCCEEDED_SIZE = 1000; + + private final static int DEFAULT_MAX_FAILED_SIZE = 100000; + + private final boolean keepLongStdio; + + private final int maxSucceededSize; + + private final int maxFailedSize; + + public KeepStdioConfig(boolean keepLongStdio, int maxSucceededSize, int maxFailedSize) { + this.keepLongStdio = keepLongStdio; + this.maxFailedSize = maxFailedSize; + this.maxSucceededSize = maxSucceededSize; + } + + /** + * If true, retain a suite's complete stdout/stderr even if this is huge and the + * suite passed. + * + * @return true if all stdio should be kept. + */ + public boolean isKeepLongStdio() { + return keepLongStdio; + } + + /** + * @return maximum number of bytes to keep for a succeeded test, or -1 if infinite. + */ + public int getMaxSucceededSize() { + return maxSucceededSize; + } + + /** + * @return maximum number of bytes to keep for a failed test, or -1 if infinite. + */ + public int getMaxFailedSize() { + return maxFailedSize; + } + + /** + * Get a new {@link KeepStdioConfig} initialized with defaults values. + */ + public static KeepStdioConfig defaults() { + return new KeepStdioConfig(false, DEFAULT_MAX_SUCCEEDED_SIZE, DEFAULT_MAX_FAILED_SIZE); + } + + /** + * Get a new {@link KeepStdioConfig} with given keepLongStdio, and + * defaults values for other configuration parameters. + */ + public static KeepStdioConfig defaults(boolean keepLongStdio) { + return new KeepStdioConfig(keepLongStdio, DEFAULT_MAX_SUCCEEDED_SIZE, DEFAULT_MAX_FAILED_SIZE); + } + + /** + * Get the maximum size of data to keep for a test, according to configuration. + * + * @param failed if test has failed. + * @return maximum number of bytes to keep. + */ + public int getMaxSize(boolean failed) { + if (keepLongStdio) { + return -1; + } + + if (failed) { + if (maxFailedSize < 0) + return -1; + return maxFailedSize; + } else { + if (maxSucceededSize < 0) + return -1; + return maxSucceededSize; + } + } +} diff --git a/src/main/java/hudson/tasks/junit/PluginConfig.java b/src/main/java/hudson/tasks/junit/PluginConfig.java deleted file mode 100644 index f5854c2fa..000000000 --- a/src/main/java/hudson/tasks/junit/PluginConfig.java +++ /dev/null @@ -1,85 +0,0 @@ -package hudson.tasks.junit; - -import java.io.Serializable; - -/** - * An object storing the plugin configuration. - */ -public class PluginConfig implements Serializable { - - private final static int DEFAULT_MAX_SUCCEEDED_SIZE = 1000; - - private final static int DEFAULT_MAX_FAILED_SIZE = 100000; - - private final boolean keepLongStdio; - - private final int maxSucceededSize; - - private final int maxFailedSize; - - public PluginConfig(boolean keepLongStdio, int maxSucceededSize, int maxFailedSize) { - this.keepLongStdio = keepLongStdio; - this.maxFailedSize = maxFailedSize; - this.maxSucceededSize = maxSucceededSize; - } - - /** - * If true, retain a suite's complete stdout/stderr even if this is huge and the - * suite passed. - * @return - */ - public boolean isKeepLongStdio() { - return keepLongStdio; - } - - /** - * @return maximum number of bytes to keep for a succeeded test, or -1 if infinite. - */ - public int getMaxSucceededSize() { - return maxSucceededSize; - } - - /** - * @return maximum number of bytes to keep for a failed test, or -1 if infinite. - */ - public int getMaxFailedSize() { - return maxFailedSize; - } - - /** - * Get a new {@link PluginConfig} initialized with defaults values. - */ - public static PluginConfig defaults() { - return new PluginConfig(false, DEFAULT_MAX_SUCCEEDED_SIZE, DEFAULT_MAX_FAILED_SIZE); - } - - /** - * Get a new {@link PluginConfig} with given keepLongStdio, and - * defaults values for other configuration parameters. - */ - public static PluginConfig defaults(boolean keepLongStdio) { - return new PluginConfig(keepLongStdio, DEFAULT_MAX_SUCCEEDED_SIZE, DEFAULT_MAX_FAILED_SIZE); - } - - /** - * Get the maximum size of data to keep for a test, according to configuration. - * @param failed if test has failed. - * @return maximum number of bytes to keep. - */ - public int getMaxSize(boolean failed) { - if (keepLongStdio) { - return -1; - } - - if (failed) { - if (maxFailedSize < 0) - return -1; - return maxFailedSize; - } - else { - if (maxSucceededSize < 0) - return -1; - return maxSucceededSize; - } - } -} diff --git a/src/main/java/hudson/tasks/junit/SuiteResult.java b/src/main/java/hudson/tasks/junit/SuiteResult.java index 70fbc4ff3..17b1db5e5 100644 --- a/src/main/java/hudson/tasks/junit/SuiteResult.java +++ b/src/main/java/hudson/tasks/junit/SuiteResult.java @@ -115,10 +115,10 @@ public static class SuiteResultParserConfigurationContext { * Parses the JUnit XML file into {@link SuiteResult}s. * This method returns a collection, as a single XML may have multiple <testsuite> * elements wrapped into the top-level <testsuites>. - * @deprecated in favor of {@link #parse(File, PluginConfig)} + * @deprecated in favor of {@link #parse(File, KeepStdioConfig)} */ static List parse(File xmlReport, boolean keepLongStdio) throws DocumentException, IOException, InterruptedException { - return parse(xmlReport, PluginConfig.defaults(keepLongStdio)); + return parse(xmlReport, KeepStdioConfig.defaults(keepLongStdio)); } /** @@ -127,7 +127,7 @@ static List parse(File xmlReport, boolean keepLongStdio) throws Doc * elements wrapped into the top-level <testsuites>. * @since 1.6 */ - static List parse(File xmlReport, PluginConfig config) throws DocumentException, IOException, InterruptedException { + static List parse(File xmlReport, KeepStdioConfig config) throws DocumentException, IOException, InterruptedException { List r = new ArrayList(); // parse into DOM @@ -148,7 +148,7 @@ static List parse(File xmlReport, PluginConfig config) throws Docum return r; } - private static void parseSuite(File xmlReport, PluginConfig config, List r, Element root) throws DocumentException, IOException { + private static void parseSuite(File xmlReport, KeepStdioConfig config, List r, Element root) throws DocumentException, IOException { // nested test suites @SuppressWarnings("unchecked") List testSuites = (List)root.elements("testsuite"); @@ -167,7 +167,7 @@ private static void parseSuite(File xmlReport, PluginConfig config, List failedTests; - private final PluginConfig config; + private final KeepStdioConfig config; /** * Creates an empty result. */ public TestResult() { - this(PluginConfig.defaults()); + this(KeepStdioConfig.defaults()); } /** @@ -107,13 +107,13 @@ public TestResult() { */ @Deprecated public TestResult(boolean keepLongStdio) { - this(PluginConfig.defaults(keepLongStdio)); + this(KeepStdioConfig.defaults(keepLongStdio)); } /** * @since 1.23 */ - public TestResult(PluginConfig config) { + public TestResult(KeepStdioConfig config) { this.config = config; } @@ -127,11 +127,11 @@ public TestResult(long buildTime, DirectoryScanner results) throws IOException { * filtering out all files that were created before the given time. * @param keepLongStdio if true, retain a suite's complete stdout/stderr even if this is huge and the suite passed * @since 1.358 - * @deprecated in favor of {@link #TestResult(long, DirectoryScanner, PluginConfig)}. + * @deprecated in favor of {@link #TestResult(long, DirectoryScanner, KeepStdioConfig)}. */ @Deprecated public TestResult(long buildTime, DirectoryScanner results, boolean keepLongStdio) throws IOException { - this(buildTime, results, PluginConfig.defaults(keepLongStdio)); + this(buildTime, results, KeepStdioConfig.defaults(keepLongStdio)); } /** @@ -140,7 +140,7 @@ public TestResult(long buildTime, DirectoryScanner results, boolean keepLongStdi * @param config plugin configuration. * @since 1.6 */ - public TestResult(long buildTime, DirectoryScanner results, PluginConfig config) throws IOException { + public TestResult(long buildTime, DirectoryScanner results, KeepStdioConfig config) throws IOException { this.config = config; parse(buildTime, results); } diff --git a/src/test/java/hudson/tasks/junit/TrimStdioTest.java b/src/test/java/hudson/tasks/junit/TrimStdioTest.java index e049fb02c..5757aeb7c 100644 --- a/src/test/java/hudson/tasks/junit/TrimStdioTest.java +++ b/src/test/java/hudson/tasks/junit/TrimStdioTest.java @@ -35,15 +35,15 @@ public class TrimStdioTest { public String name; @Parameterized.Parameter(value = 1) - public PluginConfig config; + public KeepStdioConfig config; @Parameterized.Parameters(name = "{0}") public static List parameters() { ArrayList list = new ArrayList(5); - list.add(new Object[] { "defaults", PluginConfig.defaults() }); - list.add(new Object[] { "keep all", PluginConfig.defaults(true) }); - list.add(new Object[] { "maxPassed=10, maxFailed=100", new PluginConfig(false, 10, 100)}); - list.add(new Object[] { "maxPassed=0, maxFailed=all", new PluginConfig(false, 0, -1)}); + list.add(new Object[] { "defaults", KeepStdioConfig.defaults() }); + list.add(new Object[] { "keep all", KeepStdioConfig.defaults(true) }); + list.add(new Object[] { "maxPassed=10, maxFailed=100", new KeepStdioConfig(false, 10, 100)}); + list.add(new Object[] { "maxPassed=0, maxFailed=all", new KeepStdioConfig(false, 0, -1)}); return list; }