Skip to content

Commit

Permalink
rename PluginConfig to KeepStdioConfig as it is more explicit.
Browse files Browse the repository at this point in the history
  • Loading branch information
avaiss committed Sep 17, 2017
1 parent 06cbe27 commit 89ccfdd
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 115 deletions.
12 changes: 6 additions & 6 deletions src/main/java/hudson/tasks/junit/CaseResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -141,7 +141,7 @@ private static float parseTime(Element testCase) {
stderr = possiblyTrimStdio(_this, config, testCase.elementText("system-err"));
}

static String possiblyTrimStdio(Collection<CaseResult> results, PluginConfig config, String stdio) { // HUDSON-6516
static String possiblyTrimStdio(Collection<CaseResult> results, KeepStdioConfig config, String stdio) { // HUDSON-6516
if (stdio == null) {
return null;
}
Expand All @@ -168,10 +168,10 @@ static String possiblyTrimStdio(Collection<CaseResult> 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<CaseResult> results, PluginConfig config, File stdio) throws IOException {
static String possiblyTrimStdio(Collection<CaseResult> results, KeepStdioConfig config, File stdio) throws IOException {
long len = stdio.length();
if (config.isKeepLongStdio() && len < 1024 * 1024) {
return FileUtils.readFileToString(stdio);
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/hudson/tasks/junit/JUnitParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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? */
Expand All @@ -62,7 +62,7 @@ public JUnitParser() {
*/
@Deprecated
public JUnitParser(boolean keepLongStdio) {
this.config = PluginConfig.defaults(keepLongStdio);
this.config = KeepStdioConfig.defaults(keepLongStdio);
this.allowEmptyResults = false;
}

Expand All @@ -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;
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/tasks/junit/JUnitResultArchiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
86 changes: 86 additions & 0 deletions src/main/java/hudson/tasks/junit/KeepStdioConfig.java
Original file line number Diff line number Diff line change
@@ -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 <code>keepLongStdio</code>, 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;
}
}
}
85 changes: 0 additions & 85 deletions src/main/java/hudson/tasks/junit/PluginConfig.java

This file was deleted.

10 changes: 5 additions & 5 deletions src/main/java/hudson/tasks/junit/SuiteResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 &lt;testsuite>
* elements wrapped into the top-level &lt;testsuites>.
* @deprecated in favor of {@link #parse(File, PluginConfig)}
* @deprecated in favor of {@link #parse(File, KeepStdioConfig)}
*/
static List<SuiteResult> parse(File xmlReport, boolean keepLongStdio) throws DocumentException, IOException, InterruptedException {
return parse(xmlReport, PluginConfig.defaults(keepLongStdio));
return parse(xmlReport, KeepStdioConfig.defaults(keepLongStdio));
}

/**
Expand All @@ -127,7 +127,7 @@ static List<SuiteResult> parse(File xmlReport, boolean keepLongStdio) throws Doc
* elements wrapped into the top-level &lt;testsuites>.
* @since 1.6
*/
static List<SuiteResult> parse(File xmlReport, PluginConfig config) throws DocumentException, IOException, InterruptedException {
static List<SuiteResult> parse(File xmlReport, KeepStdioConfig config) throws DocumentException, IOException, InterruptedException {
List<SuiteResult> r = new ArrayList<SuiteResult>();

// parse into DOM
Expand All @@ -148,7 +148,7 @@ static List<SuiteResult> parse(File xmlReport, PluginConfig config) throws Docum
return r;
}

private static void parseSuite(File xmlReport, PluginConfig config, List<SuiteResult> r, Element root) throws DocumentException, IOException {
private static void parseSuite(File xmlReport, KeepStdioConfig config, List<SuiteResult> r, Element root) throws DocumentException, IOException {
// nested test suites
@SuppressWarnings("unchecked")
List<Element> testSuites = (List<Element>)root.elements("testsuite");
Expand All @@ -167,7 +167,7 @@ private static void parseSuite(File xmlReport, PluginConfig config, List<SuiteRe
* @param suite
* The parsed result of {@code xmlReport}
*/
private SuiteResult(File xmlReport, Element suite, PluginConfig config) throws DocumentException, IOException {
private SuiteResult(File xmlReport, Element suite, KeepStdioConfig config) throws DocumentException, IOException {
this.file = xmlReport.getAbsolutePath();
String name = suite.attributeValue("name");
if(name==null)
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/hudson/tasks/junit/TestResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,27 @@ public final class TestResult extends MetaTabulatedResult {
*/
private transient List<CaseResult> failedTests;

private final PluginConfig config;
private final KeepStdioConfig config;

/**
* Creates an empty result.
*/
public TestResult() {
this(PluginConfig.defaults());
this(KeepStdioConfig.defaults());
}

/**
* @since 1.522
*/
@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;
}

Expand All @@ -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));
}

/**
Expand All @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/hudson/tasks/junit/TrimStdioTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object[]> parameters() {
ArrayList<Object[]> list = new ArrayList<Object[]>(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;
}

Expand Down

0 comments on commit 89ccfdd

Please sign in to comment.