-
Notifications
You must be signed in to change notification settings - Fork 45
Add an option to execute the plugin with a custom encoding setting #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an option to execute the plugin with a custom encoding setting #70
Conversation
@@ -146,10 +150,23 @@ class ScoverageExtension { | |||
if (extension.highlighting) { | |||
parameters.add('-Yrangepos') | |||
} | |||
if (extension.encoding) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part was not actually necessary in my build, but I suspect that this is only because I was using the Gradle daemon, where as in the case of not using it, it may be that the other settings (in the fork options) will be irrelevant and this one will actually matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks very much for this - it's great to find fellow-minded folks.
It seems that there is already a property on ScalaCompileOptions, which can be set globally with:
tasks.withType(ScalaCompile) {
scalaCompileOptions.encoding = 'UTF-8'
}
I think I prefer that this plugin respect the compiler configuration rather than introducing a new place to configure things. The report task reports on something that has to be compiled in.
I think this makes the PR much simpler, I'll see if I can get a fix out later today unless you're keen to take a closer look?
Cheers,
Stu.
That was one of the things I tried at first actually, as I already mentioned in the issue (#68):
The only thing that actually worked was adding the JVM encoding argument to the fork options. I'm guessing this has something to do with how the Gradle daemon executes the tasks. I added the JVM argument to the non-fork options as well only to try cover cases when executing gradle without the daemon (but haven't actually tested this). Other than this, I added the JVM argument to both of the applications' (report and aggregate) execution since those make use of "third party" code that doesn't support custom encoding other than this method. |
Sorry for the confusion. I've created #71 - the intention was to actually respect the values that are being configured on the ScalaCompile tasks, rather than to add additional configuration options for this plugin. I've added this to the check task as it too uses the default encoding when parsing XML. Would it be possible to see if the PR works for you? I still need to figure out how to test this automatically. |
Again, the problem is not just with the gradle plugin code, but with the scalac plugin as well. The scalac plugin is generating a coverage XML with corrupted data. I've managed to find the problematic source code that causes this problem. The source code has a literal string with the character \u201c, which is To reproduce / automatically test this, you could create a project with the following source code: object Foo {
def foo = "this is unicode - “ - this is unicode"
} And I don't know exactly why this is happening. I tried to reproduce this with my own code writing this character to a file and it wrote it just fine. Perhaps there's something going on when the plugin / compiler reads the source code. Again, this could only be solved if the fork JVM arguments are set to the right encoding. I don't mind relying on the encoding configured for the |
Ah, ok. It looks as thought the current version of scalac plugin should produce UTF-8 regardless of any specified encoding. It may be that SBT adds the fork option to set encoding as well as passing the command-line argument to the compiler (as you have done above). I'll see if I can take a closer look tomorrow; this may also involve an upstream PR or two :-/. Stu. |
For me a test with this code: object Foo {
def foo = "this is unicode - “ - this is unicode"
} works. The files |
Well, I'm running on Windows 10 and my default Scala codec is scala> def foo()(implicit codec: scala.io.Codec) = codec
scala> foo()
res0: scala.io.Codec = windows-1252 Perhaps that has something to do with that... |
@eyalroth can you confirm that with encoding set to |
Well, yes, this is what this is about - forcing |
Don't force |
Yep, obviously we don't want to force It would have been better if there was a way to invoke the compiler / scalac plugin with custom encoding, but this method should work for the Gradle plugin as well. |
I've changed my system encoding to
Conclusions:
|
Sorry, I'm struggling to test this on my local machine. I've set the fork option as you suggest, please could you see if #71 helps? Thanks, |
Hi, I've managed to source a build environment with Windows 10, and I can't seem to reproduce the issue with a simple Gradle project. I did have to explicitly state the encoding. If I don't, I see
If I do specify the encoding
Then
This is with gradle-scoverage-2.1.0, scalac-scoverage-1.3.1, and scalac 2.12.5 Sorry to be a pain, but please could you share an example repository that fails so that I can take a closer look? Thanks, |
I've uploaded my test repository to https://github.com/maiflai/gradle-scoverage-encoding - please could you let me know if it builds? Thanks, |
@maiflai Your system's encoding has to be changed to |
Sorry, I'm not sure I follow. My Windows machine is configured for the United States and reports that it is using How do I make my system encoding match yours? maiflai/gradle-scoverage-encoding@91658cc
|
I believe Can you please check the encoding with a scala REPL using the code I used in one of my previous comments (the one with the implicit codec variable)? |
|
does my test repository build? |
@maiflai well, not exactly. If you remove this part from the
Then the compilation fails with:
Which is strange and shouldn't normally happen. I realized that the problem is with the Creating a file with proper UTF-8 encoding makes the compilation work. Re-adding the
Anyhow, after encoding the file properly and removing that gradle part, |
See #117. |
The data scoverage is covering is often encoded with custom charsets, which may lead to problems with reading / writing the coverage data, since scalac plugin relies on the default encoding configured on the JVM and doesn't fully support configuring custom encoding with other means.
This could be seen in multiple locations such as:
serialize
without a custom encoding.This means that to overcome such problems one must be able to set the default JVM encoding when using the scalac plugin. This PR adds the ability to do so with the gradle plugin.
It makes sure to execute all the launched processes / JVMs -- including both the report and aggregate apps and the scalac compilation with the compiler plugin -- with the custom encoding as the default JVM encoding (using the
-Dfile.encoding=encoding
argument).This PR fixes #68.