Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-6684] Cobertura plugin should autoconfigure for Maven projects #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/main/java/hudson/plugins/cobertura/CoberturaPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
* @author Stephen Connolly
*/
public class CoberturaPublisher extends Recorder {
private static final String DEFAULT_COBERTURA_REPORT_FILE = "**/target/site/cobertura/coverage.xml";

private final String coberturaReportFile;

Expand Down Expand Up @@ -338,9 +339,19 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
final File buildCoberturaDir = build.getRootDir();
FilePath buildTarget = new FilePath(buildCoberturaDir);

// JENKINS-6684 Cobertura plugin should autoconfigure for Maven projects
String reportFile;
if (coberturaReportFile == null || "".equals(coberturaReportFile)) {
listener.getLogger().println("No file name pattern specified for Cobertura xml report files. Using default value '" + DEFAULT_COBERTURA_REPORT_FILE + "'.");
reportFile = DEFAULT_COBERTURA_REPORT_FILE;
}
else {
reportFile = coberturaReportFile;
}

FilePath[] reports = new FilePath[0];
try {
reports = moduleRoot.act(new ParseReportCallable(coberturaReportFile));
reports = moduleRoot.act(new ParseReportCallable(reportFile));

// if the build has failed, then there's not
// much point in reporting an error
Expand All @@ -356,7 +367,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen

if (reports.length == 0) {
String msg = "[Cobertura] No coverage results were found using the pattern '"
+ coberturaReportFile + "' relative to '"
+ reportFile + "' relative to '"
+ moduleRoot.getRemote() + "'."
+ " Did you enter a pattern relative to the correct directory?"
+ " Did you generate the XML report(s) for Cobertura?";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
xml.report.pattern.description=\
This is a file name pattern that can be used to locate the cobertura xml report files \
This is a file name pattern that is used to locate the Cobertura xml report files \
(for example with Maven2 use <b>**/target/site/cobertura/coverage.xml</b>). \
The path is relative to the module root unless you have configured \
your SCM with multiple modules, in which case it is relative to the \
workspace root. Note that the module root is SCM-specific, and may \
not be the same as the workspace root. \
not be the same as the workspace root. If no value is set, then the default \
**/target/site/cobertura/coverage.xml is used. \
<br/> \
Cobertura must be configured to generate XML reports for this plugin to function.
only.stable.builds.description=Include only stable builds, i.e. exclude unstable and failed ones.
Expand Down