From a58f9440d5d1adcadfcc7ccd6941b403e5b08843 Mon Sep 17 00:00:00 2001 From: Kengo TODA Date: Fri, 17 Apr 2015 07:34:11 +0800 Subject: [PATCH] pass compilation, but still have four test failures --- pom.xml | 12 +++++++++++- .../regression/RegressionPredicate.java | 11 ++++++++--- .../regression/RegressionReportNotifier.java | 18 ++++++++++++++---- .../regression/TestResultToCaseResult.java | 13 +++++++++++++ 4 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 src/main/java/jp/skypencil/jenkins/regression/TestResultToCaseResult.java diff --git a/pom.xml b/pom.xml index 78979fb..2d961bf 100755 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.jenkins-ci.plugins plugin - 1.436 + 1.596 regression-report-plugin Regression Report Plugin @@ -73,6 +73,16 @@ + + org.jenkins-ci.plugins + junit + 1.3 + + + org.jenkins-ci.plugins + mailer + 1.10 + junit junit diff --git a/src/main/java/jp/skypencil/jenkins/regression/RegressionPredicate.java b/src/main/java/jp/skypencil/jenkins/regression/RegressionPredicate.java index fce2716..4d09efa 100755 --- a/src/main/java/jp/skypencil/jenkins/regression/RegressionPredicate.java +++ b/src/main/java/jp/skypencil/jenkins/regression/RegressionPredicate.java @@ -1,12 +1,17 @@ package jp.skypencil.jenkins.regression; import hudson.tasks.junit.CaseResult; +import hudson.tasks.test.TestResult; import com.google.common.base.Predicate; -class RegressionPredicate implements Predicate { +class RegressionPredicate implements Predicate { @Override - public boolean apply(CaseResult input) { - return input.getStatus().isRegression(); + public boolean apply(TestResult input) { + if (input instanceof CaseResult) { + CaseResult caseResult = (CaseResult) input; + return caseResult.getStatus().isRegression(); + } + return false; } } diff --git a/src/main/java/jp/skypencil/jenkins/regression/RegressionReportNotifier.java b/src/main/java/jp/skypencil/jenkins/regression/RegressionReportNotifier.java index 2347f8f..a816744 100644 --- a/src/main/java/jp/skypencil/jenkins/regression/RegressionReportNotifier.java +++ b/src/main/java/jp/skypencil/jenkins/regression/RegressionReportNotifier.java @@ -16,6 +16,7 @@ import hudson.tasks.Mailer; import hudson.tasks.junit.CaseResult; import hudson.tasks.test.AbstractTestResultAction; +import hudson.tasks.test.TestResult; import java.io.PrintStream; import java.util.Date; @@ -33,6 +34,7 @@ import javax.mail.internet.MimeMessage; import jenkins.model.Jenkins; +import jenkins.model.JenkinsLocationConfiguration; import org.kohsuke.stapler.DataBoundConstructor; @@ -103,8 +105,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, } logger.println("regression reporter starts now..."); - List failedTest = testResultAction.getFailedTests(); - List regressionedTests = Lists.newArrayList(Iterables.filter(failedTest, new RegressionPredicate())); + List regressionedTests = listRegressions(testResultAction); writeToConsole(regressionedTests, listener); try { @@ -117,6 +118,15 @@ public boolean perform(AbstractBuild build, Launcher launcher, return true; } + private List listRegressions( + AbstractTestResultAction testResultAction) { + List failedTest = testResultAction.getFailedTests(); + Iterable filtered = Iterables.filter(failedTest, new RegressionPredicate()); + List regressionedTests = + Lists.newArrayList(Iterables.transform(filtered, new TestResultToCaseResult())); + return regressionedTests; + } + private void writeToConsole(List regressions, BuildListener listener) { if (regressions.isEmpty()) { @@ -147,8 +157,8 @@ private void mailReport(List regressions, String recipients, if (Jenkins.getInstance() != null) { rootUrl = Jenkins.getInstance().getRootUrl(); session = Mailer.descriptor().createSession(); - adminAddress = new InternetAddress(Mailer.descriptor() - .getAdminAddress()); + adminAddress = new InternetAddress( + JenkinsLocationConfiguration.get().getAdminAddress()); } builder.append(Util.encode(rootUrl)); builder.append(Util.encode(build.getUrl())); diff --git a/src/main/java/jp/skypencil/jenkins/regression/TestResultToCaseResult.java b/src/main/java/jp/skypencil/jenkins/regression/TestResultToCaseResult.java new file mode 100644 index 0000000..1d50688 --- /dev/null +++ b/src/main/java/jp/skypencil/jenkins/regression/TestResultToCaseResult.java @@ -0,0 +1,13 @@ +package jp.skypencil.jenkins.regression; + +import hudson.tasks.junit.CaseResult; +import hudson.tasks.test.TestResult; + +import com.google.common.base.Function; + +class TestResultToCaseResult implements Function { + @Override + public CaseResult apply(TestResult input) { + return (CaseResult) input; + } +}