Skip to content
Permalink
Browse files

JENKINS-33610: extracted anonymous class to lop-level to get rid of

NoClassDefFoundError: hudson/plugins/clover/CloverPublisher$1'; added more logging
  • Loading branch information...
marek-parfianowicz committed Feb 13, 2018
1 parent 2d9d81d commit c356a20e9f14da32db36194a2e80e1827ead0c44
@@ -10,14 +10,13 @@
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.plugins.clover.results.ProjectCoverage;
import hudson.plugins.clover.slave.GetPathFileCallable;
import hudson.plugins.clover.targets.CoverageMetric;
import hudson.plugins.clover.targets.CoverageTarget;
import hudson.remoting.VirtualChannel;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Publisher;
import hudson.tasks.Recorder;
import jenkins.SlaveToMasterFileCallable;
import jenkins.tasks.SimpleBuildStep;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.DataBoundConstructor;
@@ -190,12 +189,12 @@ private void performImpl(Run<?, ?> run, FilePath workspace, TaskListener listene
*/
private void processCloverXml(Run<?, ?> build, FilePath workspace, TaskListener listener,
FilePath coverageReport, FilePath buildTarget) throws InterruptedException {
listener.getLogger().print("Processing Clover XML report ...");

final String workspacePath = withTrailingSeparator(getWorkspacePath(listener, workspace));

final File cloverXmlReport = getCloverXmlReport(build);
if (cloverXmlReport.exists()) {
listener.getLogger().println("Publishing Clover coverage results...");
ProjectCoverage result = null;
try {
result = CloverCoverageParser.parse(cloverXmlReport, workspacePath);
@@ -204,6 +203,8 @@ private void processCloverXml(Run<?, ?> build, FilePath workspace, TaskListener
e.printStackTrace(listener.fatalError("Unable to copy coverage from " + coverageReport + " to " + buildTarget));
build.setResult(Result.FAILURE);
}

listener.getLogger().println("Publishing Clover coverage results...");
build.addAction(CloverBuildAction.load(workspacePath, result, healthyTarget, unhealthyTarget));

final Set<CoverageMetric> failingMetrics = getFailingMetrics(result);
@@ -220,15 +221,7 @@ private void processCloverXml(Run<?, ?> build, FilePath workspace, TaskListener
@Nonnull
private String getWorkspacePath(TaskListener listener, FilePath workspace) throws InterruptedException {
try {
return workspace.act(new SlaveToMasterFileCallable<String>() {
public String invoke(File file, VirtualChannel virtualChannel) throws IOException {
try {
return file.getCanonicalPath();
} catch (IOException e) {
return file.getAbsolutePath();
}
}
});
return workspace.act(new GetPathFileCallable());
} catch (IOException e) {
listener.getLogger().println("IOException when checking workspace path:" + e.getMessage());
return "";
@@ -260,15 +253,14 @@ private boolean copyXmlReport(FilePath coverageReport, FilePath buildTarget, Tas
// check one directory deep for a clover.xml, if there is not one in the coverageReport dir already
// the clover auto-integration saves clover reports in: clover/${ant.project.name}/clover.xml
final FilePath cloverXmlPath = findOneDirDeep(coverageReport, fileName);
final FilePath toFile = buildTarget.child("clover.xml");
if (cloverXmlPath.exists()) {
listener.getLogger().println("Publishing Clover XML report...");
final FilePath toFile = buildTarget.child("clover.xml");
cloverXmlPath.copyTo(toFile);
return true;
} else {
listener.getLogger().println("Clover xml file does not exist in: " + coverageReport +
" called: " + fileName +
" and will not be copied to: " + toFile);
listener.getLogger().println(String.format(
"Clover XML file '%s' does not exist in '%s' and was not be copied!", fileName, coverageReport));
return false;
}
}
@@ -283,6 +275,8 @@ private boolean copyHtmlReport(FilePath coverageReport, FilePath buildTarget, Ta
htmlDirPath.copyRecursiveTo("**/*", buildTarget);
return true;
} else {
listener.getLogger().println(String.format(
"Clover HTML report '%s' does not exist and was not copied!", coverageReport));
return false;
}
}
@@ -0,0 +1,17 @@
package hudson.plugins.clover.slave;

import hudson.remoting.VirtualChannel;
import jenkins.SlaveToMasterFileCallable;

import java.io.File;
import java.io.IOException;

public class GetPathFileCallable extends SlaveToMasterFileCallable<String> {
public String invoke(File file, VirtualChannel virtualChannel) throws IOException {
try {
return file.getCanonicalPath();
} catch (IOException e) {
return file.getAbsolutePath();
}
}
}

0 comments on commit c356a20

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