Quantcast
Channel: Liquibase Forums
Viewing all articles
Browse latest Browse all 2993

Incorrect default charset for formatted sql files via maven plugin

$
0
0
Hi,

I have been trying to solve a problem I have with UTF-8 encoded sql scripts via the maven plugin.  Data is being inserted into the database with encoding "windows-1252", even though the file.encoding System property is set to "UTF-8".

I tried various ways to workaround this, maven settings, plugins etc, but to no avail.  Working with the code I see that, even though the system property for file.encoding is UTF-8, the Charset.defaultCharset() still returns "windows-1252".

Further testing (via groovy scripts) seems to verify the file.encoding has no effect on the default charset, contrary to the information I found online:

  1. $ groovy -Dfile.encoding=test -e "println System.getProperty(\"file.encoding\")"
  2. test
  3. $ groovy -Dfile.encoding=UTF-8 -e "println java.nio.charset.Charset.defaultCharset().name()"
  4. windows-1252


My "solution" at this point appears to be to fork the code and change the default charset in UtfBomAwareReader to use the file.encoding property (diff is below), but I also wanted to ask is this is a problem for others, and whether this change would make sense going into the main codebase?

Best regards,
Gary


  1. diff --git a/liquibase-core/src/main/java/liquibase/resource/UtfBomAwareReader.java b/liquibase-core/src/main/java/liquibase/resource/UtfBomAwareReader.java
  2. index af65682..7297f71 100644
  3. --- a/liquibase-core/src/main/java/liquibase/resource/UtfBomAwareReader.java
  4. +++ b/liquibase-core/src/main/java/liquibase/resource/UtfBomAwareReader.java
  5. @@ -28,7 +28,7 @@ public class UtfBomAwareReader extends Reader {

  6.        public UtfBomAwareReader(InputStream in) {
  7.                pis = new PushbackInputStream(in, 4);
  8. -               this.defaultCharsetName = Charset.defaultCharset().name();
  9. +               this.defaultCharsetName = System.getProperty("file.encoding");
  10.        }

  11.        public UtfBomAwareReader(InputStream in, String defaultCharsetName) {

Viewing all articles
Browse latest Browse all 2993

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>