Skip to content

Commit

Permalink
[JENKINS-15035] quick check report files identified by pattern to be …
Browse files Browse the repository at this point in the history
…xml ones
  • Loading branch information
ndeloof committed Sep 4, 2012
1 parent 7d0c5db commit 2ad1ea3
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/main/java/hudson/plugins/cobertura/CoberturaPublisher.java
Expand Up @@ -18,14 +18,19 @@
import hudson.plugins.cobertura.targets.CoverageMetric;
import hudson.plugins.cobertura.targets.CoverageResult;
import hudson.plugins.cobertura.targets.CoverageTarget;
import hudson.remoting.VirtualChannel;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Publisher;
import hudson.tasks.Recorder;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
Expand Down Expand Up @@ -320,7 +325,22 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen

FilePath[] reports = new FilePath[0];
try {
reports = moduleRoot.list(coberturaReportFile);
reports = moduleRoot.act(new FilePath.FileCallable<FilePath[]>() {
public FilePath[] invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
FilePath[] r = new FilePath(f).list(coberturaReportFile);

byte[] c = new byte[5];
for (FilePath filePath : r) {
InputStream is = filePath.read();
int i = is.read(c, 0, 5);
if (i < 0 || ! (new String(c).equals("<?xml")) ) {
throw new IOException(filePath + " is not an XML file, please check your report pattern");
}
is.close();
}
return r;
}
});

// if the build has failed, then there's not
// much point in reporting an error
Expand Down

0 comments on commit 2ad1ea3

Please sign in to comment.