Skip to content

Commit

Permalink
Fix processing report files with Unicode in pathes.
Browse files Browse the repository at this point in the history
Jenkins replaces some ASCII symbols like colons with Unicode
storing builds data. Parsing reports letter when users open
'SLOCCount Results' window the plugin unable to retrieve
SLOC information - file was stored by path with Unicode.

It relates to JDK 8.
Using unmarshal(File f) indeed proceses not the File but a URL
based on its absolute path. When JDK tries to open connection it
calles ParseUtil.decode(url.getFile()) against our path containing
Unicode. This method converts Unicode back to ASCII. So we get
java.io.FileNotFoundException wrapped in javax.xml.bind.JAXBException,
which is ignored by the plugin. Using unmarshal(java.io.InputStream is)
soleves the issue due to JDK uses passed InputStream and all
described here above do not affect us.
  • Loading branch information
svistun committed Feb 3, 2021
1 parent f7359fa commit 467c57d
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.Serializable;

/**
Expand Down Expand Up @@ -61,10 +63,15 @@ public ClocFiles getFiles() {
* @return the content of the parsed file in form of a report
* @throws javax.xml.bind.JAXBException if a XML related error occurs
*/
public static ClocReport parse(File file) throws JAXBException {
public static ClocReport parse(File file) throws JAXBException, java.io.IOException {
JAXBContext context = JAXBContext.newInstance(ClocReport.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
return (ClocReport) unmarshaller.unmarshal(file);
// Jenkins replaces ASCII symbols like colons found in filenames to Unicode.
// Using File() here causes converting Unicode symbols back to ASCII.
// Such files could not be found of course.
try (InputStream is = new FileInputStream(file)) {
return (ClocReport) unmarshaller.unmarshal(is);
}
}

/**
Expand Down

0 comments on commit 467c57d

Please sign in to comment.