Honor XML encoding declaration over sonar.sourceEncoding property

Running the Gradle Sonar Scanner for an 8.9 LTS SonarQube server, I noticed the following output in the console:

Invalid character encountered in file /path/to/my/project/filename.xsl at line 136 for encoding UTF-8. Please fix file content or configure the encoding to be used using property ‘sonar.sourceEncoding’.

Our source code is encoded in UTF-8, which is why we set sonar.sourceEncoding to that. But resource files may have different encoding.

In the example above, the file contains an umlaut in the specified line that is encoded in ISO-8859-1. But that should be fine for parsing because the file declares its encoding in the first line:

<?xml version="1.0" encoding="ISO-8859-1"?>

Since XML and related files (XSL, XSD, BPMN, DMN) usually declare the encoding of their content, it would be nice if Sonar could use the declared encoding when analyzing these files and only fall back to the sonar.sourceEncoding if no explicit declaration was found.