Skip to content

Commit

Permalink
Merge pull request #7 from sschuberth/master
Browse files Browse the repository at this point in the history
[FIXED JENKINS-22047] Add option to reduce noise in logs
  • Loading branch information
kinow committed Jul 25, 2014
2 parents 65b57b2 + 82167d2 commit 239c532
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
15 changes: 10 additions & 5 deletions src/main/java/org/tap4j/plugin/TapParser.java
Expand Up @@ -49,8 +49,7 @@
public class TapParser {

/** Prints the logs to the web server's console / log files */
private static final Logger log = Logger.getLogger(TapParser.class
.getName());
private static final Logger log = Logger.getLogger(TapParser.class.getName());
private final Boolean outputTapToConsole;
private final Boolean enableSubtests;
private final Boolean todoIsFailure;
Expand All @@ -60,21 +59,23 @@ public class TapParser {
private final Boolean includeCommentDiagnostics;
private final Boolean validateNumberOfTests;
private final Boolean planRequired;
private final Boolean verbose;

private boolean hasFailedTests;
private boolean parserErrors;

public TapParser(Boolean outputTapToConsole, Boolean enableSubtests, Boolean todoIsFailure,
Boolean includeCommentDiagnostics, Boolean validateNumberOfTests, Boolean planRequired,
PrintStream logger) {
Boolean verbose, PrintStream logger) {
this.outputTapToConsole = outputTapToConsole;
this.enableSubtests = enableSubtests;
this.todoIsFailure = todoIsFailure;
this.logger = logger;
this.parserErrors = false;
this.includeCommentDiagnostics = includeCommentDiagnostics;
this.validateNumberOfTests = validateNumberOfTests;
this.planRequired = planRequired;
this.verbose = verbose;
this.logger = logger;
}

public Boolean hasParserErrors() {
Expand Down Expand Up @@ -112,6 +113,10 @@ public Boolean getEnableSubtests() {
public boolean hasFailedTests() {
return this.hasFailedTests;
}

public Boolean getVerbose() {
return verbose;
}

public TapResult parse(FilePath[] results, AbstractBuild<?, ?> build) {
this.parserErrors = Boolean.FALSE;
Expand Down Expand Up @@ -163,7 +168,7 @@ public TapResult parse(FilePath[] results, AbstractBuild<?, ?> build) {
}

private void log(String str) {
if (logger != null) {
if (verbose && logger != null) {
logger.println(str);
} else {
log.fine(str);
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/org/tap4j/plugin/TapPublisher.java
Expand Up @@ -74,6 +74,7 @@ public class TapPublisher extends Recorder implements MatrixAggregatable {
private final Boolean includeCommentDiagnostics;
private final Boolean validateNumberOfTests;
private final Boolean planRequired;
private final Boolean verbose;

@DataBoundConstructor
public TapPublisher(String testResults,
Expand All @@ -85,7 +86,8 @@ public TapPublisher(String testResults,
Boolean todoIsFailure,
Boolean includeCommentDiagnostics,
Boolean validateNumberOfTests,
Boolean planRequired) {
Boolean planRequired,
Boolean verbose) {
this.testResults = testResults;
this.failIfNoResults = BooleanUtils.toBooleanDefaultIfNull(failIfNoResults, false);
this.failedTestsMarkBuildAsFailure = BooleanUtils.toBooleanDefaultIfNull(failedTestsMarkBuildAsFailure, false);
Expand All @@ -95,7 +97,8 @@ public TapPublisher(String testResults,
this.todoIsFailure = BooleanUtils.toBooleanDefaultIfNull(todoIsFailure, true);
this.includeCommentDiagnostics = BooleanUtils.toBooleanDefaultIfNull(includeCommentDiagnostics, true);
this.validateNumberOfTests = BooleanUtils.toBooleanDefaultIfNull(validateNumberOfTests, false);
this.planRequired = BooleanUtils.toBooleanDefaultIfNull(planRequired, Boolean.TRUE); // true is the old behaviour
this.planRequired = BooleanUtils.toBooleanDefaultIfNull(planRequired, true); // true is the old behaviour
this.verbose = BooleanUtils.toBooleanDefaultIfNull(verbose, true);
}

public Object readResolve() {
Expand All @@ -109,7 +112,8 @@ public Object readResolve() {
Boolean includeCommentDiagnostics = BooleanUtils.toBooleanDefaultIfNull(this.getIncludeCommentDiagnostics(), true);
Boolean validateNumberOfTests = BooleanUtils.toBooleanDefaultIfNull(this.getValidateNumberOfTests(), false);
Boolean planRequired = BooleanUtils.toBooleanDefaultIfNull(this.getPlanRequired(), true);
return new TapPublisher(testResults, failIfNoResults, failedTestsMarkBuildAsFailure, outputTapToConsole, enableSubtests, discardOldReports, todoIsFailure, includeCommentDiagnostics, validateNumberOfTests, planRequired);
Boolean verbose = BooleanUtils.toBooleanDefaultIfNull(this.getVerbose(), true);
return new TapPublisher(testResults, failIfNoResults, failedTestsMarkBuildAsFailure, outputTapToConsole, enableSubtests, discardOldReports, todoIsFailure, includeCommentDiagnostics, validateNumberOfTests, planRequired, verbose);
}

/**
Expand Down Expand Up @@ -172,6 +176,10 @@ public Boolean getValidateNumberOfTests() {
public Boolean getPlanRequired() {
return planRequired;
}

public Boolean getVerbose() {
return verbose;
}

/**
* Gets the directory where the plug-in saves its TAP streams before processing them and
Expand Down Expand Up @@ -319,7 +327,7 @@ private TapResult loadResults(AbstractBuild<?, ?> owner, PrintStream logger) {
try {
results = tapDir.list("**/*.*");

final TapParser parser = new TapParser(getOutputTapToConsole(), getEnableSubtests(), getTodoIsFailure(), getIncludeCommentDiagnostics(), getValidateNumberOfTests(), getPlanRequired(), logger);
final TapParser parser = new TapParser(getOutputTapToConsole(), getEnableSubtests(), getTodoIsFailure(), getIncludeCommentDiagnostics(), getValidateNumberOfTests(), getPlanRequired(), getVerbose(), logger);
final TapResult result = parser.parse(results, owner);
result.setOwner(owner);
return result;
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/org/tap4j/plugin/TapPublisher/config.jelly
Expand Up @@ -3,6 +3,9 @@
<f:entry title="Test results" field="testResults">
<f:textbox />
</f:entry>
<f:entry title="Verbose (if checked will print a message for each TAP stream file)">
<f:checkbox name="TapPublisher.verbose" value="${instance.verbose}" checked="${instance.verbose}" default="true" />
</f:entry>
<f:advanced>
<f:entry title="Fail the build if no test results are present">
<f:checkbox name="TapPublisher.failIfNoResults" value="${instance.failIfNoResults}" checked="${instance.failIfNoResults}" />
Expand Down
Expand Up @@ -47,7 +47,8 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher arg1,
true,
true,
true,
false);
false,
true);
project.getPublishersList().add(publisher);
project.save();
FreeStyleBuild build = (FreeStyleBuild) project.scheduleBuild2(0).get();
Expand Down
Expand Up @@ -54,7 +54,8 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher arg1,
true,
true,
true,
false);
false,
true);
project.getPublishersList().add(publisher);
project.save();
FreeStyleBuild build = (FreeStyleBuild) project.scheduleBuild2(0).get();
Expand Down

0 comments on commit 239c532

Please sign in to comment.