Skip to content
Permalink
Browse files
[FIXED JENKINS-10236]Emma plugin causes maven release job to fail
  • Loading branch information
ssogabe committed May 6, 2012
1 parent d3a87fb commit bcad7397b2f907fc611844cb26c8cc1a120dbf52
Showing with 38 additions and 3 deletions.
  1. +38 −3 src/main/java/hudson/plugins/emma/EmmaPublisher.java
@@ -4,6 +4,9 @@
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.maven.ExecutedMojo;
import hudson.maven.MavenBuild;
import hudson.maven.MavenModuleSetBuild;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Action;
@@ -94,13 +97,27 @@ protected static void saveCoverageReports(FilePath folder, FilePath[] files) thr

@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
final PrintStream logger = listener.getLogger();

// Make sure Emma actually ran
if (build instanceof MavenBuild) {
MavenBuild mavenBuild = (MavenBuild) build;
if (!didEmmaRun(mavenBuild)) {
listener.getLogger().println("Skipping Emma coverage report as mojo did not run.");
return true;
}
} else if (build instanceof MavenModuleSetBuild) {
MavenModuleSetBuild moduleSetBuild = (MavenModuleSetBuild) build;
if (!didEmmaRun(moduleSetBuild.getModuleLastBuilds().values())) {
listener.getLogger().println("Skipping Emma coverage report as mojo did not run.");
return true;
}
}

EnvVars env = build.getEnvironment(listener);
env.overrideAll(build.getBuildVariables());

includes = env.expand(includes);

final PrintStream logger = listener.getLogger();

FilePath[] reports;
if (includes == null || includes.trim().length() == 0) {
logger.println("Emma: looking for coverage reports in the entire workspace: " + build.getWorkspace().getRemote());
@@ -170,6 +187,24 @@ public BuildStepDescriptor<Publisher> getDescriptor() {
return DESCRIPTOR;
}

private boolean didEmmaRun(Iterable<MavenBuild> mavenBuilds) {
for (MavenBuild build : mavenBuilds) {
if (didEmmaRun(build)) {
return true;
}
}
return false;
}

private boolean didEmmaRun(MavenBuild mavenBuild) {
for (ExecutedMojo mojo : mavenBuild.getExecutedMojos()) {
if ("org.codehaus.mojo".equals(mojo.groupId) && "emma-maven-plugin".equals(mojo.artifactId)) {
return true;
}
}
return false;
}

@Extension
public static final BuildStepDescriptor<Publisher> DESCRIPTOR = new DescriptorImpl();

2 comments on commit bcad739

@hostirosti
Copy link

@hostirosti hostirosti commented on bcad739 Jul 3, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

this change restricts the usage of the plugin with the org.codehaus.mojo.emma-maven-plugin only.
By searching through the web one can see that there are at least 3(org.sonatype.maven.plugin:emma-maven-plugin:1.2, org.codehaus.mojo:emma-maven-plugin:1.0-alpha-3,org.apache.maven.plugins:maven-emma-plugin:0.5) possibly more plugins out there that produce the emma reports.

Would it be possible to choose a different mechanism to prevent build failure if no reports are available to process rather than restricting the plugin that is producing it?

Cheers,
Robert

@manolo
Copy link
Member

@manolo manolo commented on bcad739 Jul 4, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could do either: add the list of mojos to check or count the report files after the execution.

Please sign in to comment.