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 Jan 28, 2021
1 parent e3edcd2 commit 1b61020
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javax.xml.bind.annotation.XmlRootElement;
import java.io.File;
import java.io.Serializable;
import java.net.URL;

/**
* Cloc report parser and the parsed file.
Expand Down Expand Up @@ -61,10 +62,13 @@ 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 : to Unicode in filenames.
// Using File() here couse converting Unicode symbols back to ASCII.
// Such files could not be found of course.
return (ClocReport) unmarshaller.unmarshal(new java.io.FileInputStream(file));
}

/**
Expand Down

0 comments on commit 1b61020

Please sign in to comment.