Skip to content

Commit

Permalink
Merge pull request #10 from rbaradari/fix-15518
Browse files Browse the repository at this point in the history
[JENKINS-15518] changed anonymous inner FileCallable to nested class because the outer class is not serializable
  • Loading branch information
ndeloof committed Oct 16, 2012
2 parents 9e6a61b + 2e2f3b0 commit e2777e8
Showing 1 changed file with 42 additions and 31 deletions.
73 changes: 42 additions & 31 deletions src/main/java/hudson/plugins/cobertura/CoberturaPublisher.java
Expand Up @@ -332,37 +332,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen

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

XMLInputFactory factory = XMLInputFactory.newInstance();
factory.setProperty("javax.xml.stream.supportDTD", "false");

for (FilePath filePath : r) {
try {
XMLEventReader reader = factory.createXMLEventReader(filePath.read());
while (reader.hasNext()) {
XMLEvent event = reader.nextEvent();
if (event.isStartElement()) {
StartElement start = (StartElement) event;
if (start.getName().getLocalPart().equals("coverage")) {
// This is a cobertura coverage report file
break;
} else {
throw new IOException(filePath + " is not a cobertura coverage report, please check your report pattern");
}
}
}
reader.close();
} catch (XMLStreamException e) {
throw new IOException(filePath + " is not an XML file, please check your report pattern");
}

}
return r;
}
});
reports = moduleRoot.act(new ParseReportCallable(coberturaReportFile));

// if the build has failed, then there's not
// much point in reporting an error
Expand Down Expand Up @@ -556,6 +526,47 @@ public SourceEncoding getSourceEncoding() {
@Extension
public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();

public static class ParseReportCallable implements FilePath.FileCallable<FilePath[]> {
private static final long serialVersionUID = 1L;

private final String reportFilePath;

public ParseReportCallable(String reportFilePath) {
this.reportFilePath = reportFilePath;
}

public FilePath[] invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
FilePath[] r = new FilePath(f).list(reportFilePath);

XMLInputFactory factory = XMLInputFactory.newInstance();
factory.setProperty("javax.xml.stream.supportDTD", "false");

for (FilePath filePath : r) {
try {
XMLEventReader reader = factory.createXMLEventReader(filePath.read());
while (reader.hasNext()) {
XMLEvent event = reader.nextEvent();
if (event.isStartElement()) {
StartElement start = (StartElement) event;
if (start.getName().getLocalPart().equals("coverage")) {
// This is a cobertura coverage report file
break;
} else {
throw new IOException(filePath + " is not a cobertura coverage report, please check your report pattern");
}
}
}
reader.close();
} catch (XMLStreamException e) {
throw new IOException(filePath + " is not an XML file, please check your report pattern");
}

}
return r;
}
}


/**
* Descriptor for {@link CoberturaPublisher}. Used as a singleton. The class is marked as public so that it can be
* accessed from views.
Expand Down

0 comments on commit e2777e8

Please sign in to comment.