Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JENKINS-45674 : Automatically archive concordion reports
- Loading branch information
Benoit Guerin
committed
Jul 20, 2017
1 parent
715dc5b
commit eda1cff
Showing
6 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
...c/main/java/org/jenkinsci/plugins/pipeline/maven/publishers/ConcordionTestsPublisher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/* | ||
* 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.pipeline.maven.MavenPublisher; | ||
import org.jenkinsci.plugins.pipeline.maven.util.XmlUtils; | ||
import org.jenkinsci.plugins.workflow.steps.StepContext; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.DataBoundSetter; | ||
import org.w3c.dom.Element; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import javax.annotation.CheckForNull; | ||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
import htmlpublisher.HtmlPublisher; | ||
import htmlpublisher.HtmlPublisherTarget; | ||
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 ConcordionTestsPublisher extends MavenPublisher { | ||
private static final Logger LOGGER = Logger.getLogger(ConcordionTestsPublisher.class.getName()); | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
@CheckForNull | ||
private String pattern = "**/target/*concordion*/**"; | ||
|
||
@DataBoundConstructor | ||
public ConcordionTestsPublisher() { | ||
|
||
} | ||
|
||
@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("htmlpublisher.HtmlPublisher"); | ||
} catch (final ClassNotFoundException e) { | ||
listener.getLogger().print("[withMaven] Jenkins "); | ||
listener.hyperlink("https://wiki.jenkins.io/display/JENKINS/HTML+Publisher+Plugin", | ||
"HTML Publisher Plugin"); | ||
listener.getLogger().print(" not found, do not archive concordion reports."); | ||
return; | ||
} | ||
|
||
executeReporter(context, listener); | ||
} | ||
|
||
private void executeReporter(final StepContext context, final TaskListener listener) | ||
throws IOException, InterruptedException { | ||
final FilePath workspace = context.get(FilePath.class); | ||
final String fileSeparatorOnAgent = XmlUtils.getFileSeparatorOnRemote(workspace); | ||
|
||
final Run run = context.get(Run.class); | ||
final Launcher launcher = context.get(Launcher.class); | ||
|
||
if (pattern == null || pattern.isEmpty()) { | ||
if (LOGGER.isLoggable(Level.FINE)) { | ||
listener.getLogger().println("[withMaven] No pattern given, aborting."); | ||
} | ||
return; | ||
} | ||
|
||
final FilePath[] paths = workspace.list(pattern); | ||
listener.getLogger().println( | ||
"[withMaven] Pattern \"" + pattern + "\" matched " + paths.length + " file(s)."); | ||
|
||
final List<String> files = new ArrayList<String>(); | ||
for (final FilePath path : paths) { | ||
files.add(XmlUtils.getPathInWorkspace(path.getRemote(), workspace)); | ||
} | ||
final HtmlPublisherTarget target = new HtmlPublisherTarget("Concordion reports", ".", | ||
XmlUtils.join(files, ","), true, true, true); | ||
|
||
try { | ||
listener.getLogger().println( | ||
"[withMaven] Publishing HTML named \"Concordion reports\" with the following files: " | ||
+ target.getReportFiles()); | ||
HtmlPublisher.publishReports(run, workspace, launcher, listener, Arrays.asList(target), | ||
HtmlPublisher.class); | ||
} catch (final Exception e) { | ||
listener.error("[withMaven] Silently ignore exception archiving Concordion reports: " + e); | ||
LOGGER.log(Level.WARNING, "Exception processing Concordion reports archiving", e); | ||
} | ||
|
||
} | ||
|
||
@CheckForNull | ||
public String getPattern() { | ||
return pattern; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setPattern(@Nullable final String pattern) { | ||
this.pattern = pattern; | ||
} | ||
|
||
@Symbol("concordionPublisher") | ||
@Extension | ||
public static class DescriptorImpl extends MavenPublisher.DescriptorImpl { | ||
@Nonnull | ||
@Override | ||
public String getDisplayName() { | ||
return "Concordion Publisher"; | ||
} | ||
|
||
@Override | ||
public int ordinal() { | ||
return 20; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getSkipFileName() { | ||
return ".skip-publish-concordion-results"; | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...ces/org/jenkinsci/plugins/pipeline/maven/publishers/ConcordionTestsPublisher/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!-- | ||
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}"/> | ||
|
||
<f:entry title="${%Pattern}" field="pattern"> | ||
<f:textbox/> | ||
</f:entry> | ||
</j:jelly> |
3 changes: 3 additions & 0 deletions
3
...g/jenkinsci/plugins/pipeline/maven/publishers/ConcordionTestsPublisher/help-disabled.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div> | ||
Skip the publishing of tests reports. | ||
</div> |
3 changes: 3 additions & 0 deletions
3
...rg/jenkinsci/plugins/pipeline/maven/publishers/ConcordionTestsPublisher/help-pattern.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div> | ||
Pattern to match Concordion reports to publish. Defaults to <code>**/target/*concordion*/**</code>.<br/> | ||
</div> |
6 changes: 6 additions & 0 deletions
6
...ources/org/jenkinsci/plugins/pipeline/maven/publishers/ConcordionTestsPublisher/help.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div> | ||
Publish <a href="http://concordion.org/">Concordion</a> reports, if found, regarding the given pattern.<br/> | ||
|
||
Test results are by default published if the | ||
<a href="https://wiki.jenkins.io/display/JENKINS/HTML+Publisher+Plugin">Jenkins HTMLPublisher Plugin</a> is installed. | ||
</div> |