Skip to content
Permalink
Browse files

JENKINS-45887 : Automatically archive JGiven reports

  • Loading branch information
bguerin committed Sep 12, 2017
1 parent 270f0c7 commit 734849a6db74397db96e73ff4c9329f710901b53
@@ -59,6 +59,7 @@ Maven build executions inside the `withMaven(){...}` wil be detected and Jenkins
| Generated Findbugs reports | Publishing of the Findbugs reports generated by the Maven build | [FindBugs Plugin](https://wiki.jenkins-ci.org/display/JENKINS/FindBugs+Plugin) | `.skip-publish-findbugs-results` |
| Generated Invoker reports | Publishing of the Invoker reports generated by the Maven build | [Maven Invoker Plugin](https://wiki.jenkins.io/display/JENKINS/Maven+Invoker+Plugin) | `.skip-publish-invoker-results` |
| Generated Concordion reports | Publishing of the Concordion reports generated by the Maven build | [HTML Publisher Plugin](https://wiki.jenkins.io/display/JENKINS/HTML+Publisher+Plugin) | `.skip-publish-concordion-results` |
| Generated JGiven reports | Publishing of the JGiven reports generated by the Maven build | [JGiven Plugin](https://wiki.jenkins.io/display/JENKINS/JGiven+Plugin) | `.skip-publish-jgiven-results` |
(1) Jenkins Plugin to publish the reports on the Jenkins build page
@@ -168,6 +168,13 @@
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>jgiven</artifactId>
<version>0.15.1</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
@@ -0,0 +1,111 @@
/*
* The MIT License Copyright (c) 2016, CloudBees, Inc. Permission is hereby
* granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions: The above copyright notice and this
* permission notice shall be included in all copies or substantial portions of
* the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
* EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/

package org.jenkinsci.plugins.pipeline.maven.publishers;

import org.jenkinsci.Symbol;
import org.jenkinsci.plugins.jgiven.JgivenReportGenerator;
import org.jenkinsci.plugins.jgiven.JgivenReportGenerator.ReportConfig;
import org.jenkinsci.plugins.pipeline.maven.MavenPublisher;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.kohsuke.stapler.DataBoundConstructor;
import org.w3c.dom.Element;

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.annotation.Nonnull;

import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.Run;
import hudson.model.StreamBuildListener;
import hudson.model.TaskListener;

/**
* @author <a href="mailto:cleclerc@cloudbees.com">Cyrille Le Clerc</a>
*/
public class JGivenTestsPublisher extends MavenPublisher {
private static final Logger LOGGER = Logger.getLogger(JGivenTestsPublisher.class.getName());

private static final long serialVersionUID = 1L;

@DataBoundConstructor
public JGivenTestsPublisher() {

}

@Override
public void process(@Nonnull final StepContext context, @Nonnull final Element mavenSpyLogsElt)
throws IOException, InterruptedException {

TaskListener listener = context.get(TaskListener.class);
if (listener == null) {
LOGGER.warning("TaskListener is NULL, default to stderr");
listener = new StreamBuildListener((OutputStream) System.err);
}

try {
Class.forName("org.jenkinsci.plugins.jgiven.JgivenReportGenerator");
} catch (final ClassNotFoundException e) {
listener.getLogger().print("[withMaven] Jenkins ");
listener.hyperlink("https://wiki.jenkins.io/display/JENKINS/JGiven+Plugin", "JGiven Plugin");
listener.getLogger().println(" not found, do not archive jgiven reports.");
return;
}

final FilePath workspace = context.get(FilePath.class);
final Run run = context.get(Run.class);
final Launcher launcher = context.get(Launcher.class);

final JgivenReportGenerator generator = new JgivenReportGenerator(new ArrayList<ReportConfig>());

try {
listener.getLogger().println("[withMaven] Running JGiven report generator");
generator.perform(run, workspace, launcher, listener);
} catch (final Exception e) {
listener.error("[withMaven] Silently ignore exception archiving JGiven reports: " + e);
LOGGER.log(Level.WARNING, "Exception processing JGiven reports archiving", e);
}
}

@Symbol("jgivenPublisher")
@Extension
public static class DescriptorImpl extends MavenPublisher.DescriptorImpl {
@Nonnull
@Override
public String getDisplayName() {
return "JGiven Publisher";
}

@Override
public int ordinal() {
return 20;
}

@Nonnull
@Override
public String getSkipFileName() {
return ".skip-publish-jgiven-results";
}
}
}
@@ -0,0 +1,31 @@
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Seiji Sogabe, Tom Huybrechts
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout"
xmlns:t="/lib/hudson" xmlns:f="/lib/form">

<st:include page="maven-publisher" class="${descriptor.clazz}"/>

</j:jelly>
@@ -0,0 +1,3 @@
<div>
Skip the publishing of tests reports.
</div>
@@ -0,0 +1,5 @@
<div>
Publish <a href="http://jgiven.org/">JGiven</a> reports, if found.<br/>

Test results are by default published if the <a href="https://wiki.jenkins.io/display/JENKINS/JGiven+Plugin">Jenkins JGiven Plugin</a> is installed.
</div>

0 comments on commit 734849a

Please sign in to comment.
You can’t perform that action at this time.