Permalink
Browse files

CORE-2874 Ensure consistent charset encoding usage

  • Loading branch information...
nvoxland committed Sep 1, 2016
1 parent e9e5afe commit 936b617d7b5f854b00176ea7368c834f2766f771
Showing with 161 additions and 110 deletions.
  1. +1 −0 findbugs-exclude.xml
  2. +8 −2 liquibase-core/src/main/java/liquibase/change/AbstractSQLChange.java
  3. +5 −2 liquibase-core/src/main/java/liquibase/change/core/CreateProcedureChange.java
  4. +4 −2 liquibase-core/src/main/java/liquibase/change/core/ExecuteShellCommandChange.java
  5. +17 −18 liquibase-core/src/main/java/liquibase/changelog/OfflineChangeLogHistoryService.java
  6. +2 −2 liquibase-core/src/main/java/liquibase/dbdoc/AuthorWriter.java
  7. +3 −1 liquibase-core/src/main/java/liquibase/dbdoc/ChangeLogWriter.java
  8. +2 −2 liquibase-core/src/main/java/liquibase/dbdoc/ColumnWriter.java
  9. +4 −4 liquibase-core/src/main/java/liquibase/dbdoc/HTMLListWriter.java
  10. +13 −13 liquibase-core/src/main/java/liquibase/dbdoc/HTMLWriter.java
  11. +3 −3 liquibase-core/src/main/java/liquibase/dbdoc/PendingChangesWriter.java
  12. +3 −4 liquibase-core/src/main/java/liquibase/dbdoc/PendingSQLWriter.java
  13. +3 −3 liquibase-core/src/main/java/liquibase/dbdoc/RecentChangesWriter.java
  14. +7 −11 liquibase-core/src/main/java/liquibase/dbdoc/TableWriter.java
  15. +5 −5 liquibase-core/src/main/java/liquibase/diff/output/changelog/DiffToChangeLog.java
  16. +3 −1 liquibase-core/src/main/java/liquibase/diff/output/changelog/core/MissingDataChangeGenerator.java
  17. +5 −5 ...re/src/main/java/liquibase/diff/output/changelog/core/MissingDataExternalFileChangeGenerator.java
  18. +3 −6 liquibase-core/src/main/java/liquibase/integration/spring/SpringLiquibase.java
  19. +2 −1 liquibase-core/src/main/java/liquibase/logging/core/DefaultLogger.java
  20. +3 −1 liquibase-core/src/main/java/liquibase/parser/core/yaml/YamlSnapshotParser.java
  21. +3 −1 liquibase-core/src/main/java/liquibase/resource/ClassLoaderResourceAccessor.java
  22. +4 −1 liquibase-core/src/main/java/liquibase/resource/UtfBomAwareReader.java
  23. +3 −1 liquibase-core/src/main/java/liquibase/sdk/resource/MockResourceAccessor.java
  24. +6 −3 liquibase-core/src/main/java/liquibase/sdk/supplier/resource/ResourceSupplier.java
  25. +3 −1 liquibase-core/src/main/java/liquibase/serializer/core/json/JsonChangeLogSerializer.java
  26. +3 −1 liquibase-core/src/main/java/liquibase/serializer/core/string/StringSnapshotSerializer.java
  27. +3 −1 liquibase-core/src/main/java/liquibase/serializer/core/string/StringSnapshotSerializerReadable.java
  28. +3 −1 liquibase-core/src/main/java/liquibase/serializer/core/xml/XMLChangeLogSerializer.java
  29. +3 −1 liquibase-core/src/main/java/liquibase/serializer/core/yaml/YamlChangeLogSerializer.java
  30. +3 −1 liquibase-core/src/main/java/liquibase/servicelocator/DefaultPackageScanClassResolver.java
  31. +3 −1 liquibase-core/src/main/java/liquibase/snapshot/DatabaseSnapshot.java
  32. +6 −3 liquibase-core/src/main/java/liquibase/util/FileUtil.java
  33. +3 −1 liquibase-core/src/main/java/liquibase/util/MD5Util.java
  34. +4 −2 liquibase-core/src/main/java/liquibase/util/xml/DefaultXmlWriter.java
  35. +5 −2 liquibase-core/src/test/java/liquibase/integration/ant/AbstractAntTaskTest.java
  36. +1 −1 liquibase-maven-plugin/src/main/java/org/liquibase/maven/plugins/AbstractLiquibaseMojo.java
  37. +9 −2 liquibase-maven-plugin/src/main/java/org/liquibase/maven/plugins/LiquibaseReportStatusMojo.java
View
@@ -2,6 +2,7 @@
<FindBugsFilter>
<LastVersion value="-1" relOp="NEQ"/>
<Class name="liquibase.util.grammar.SimpleCharStream"/>
<And>
<Rank value="10"/>
<Bug category="SECURITY"/>
@@ -1,5 +1,7 @@
package liquibase.change;
import liquibase.configuration.GlobalConfiguration;
import liquibase.configuration.LiquibaseConfiguration;
import liquibase.database.Database;
import liquibase.database.core.MSSQLDatabase;
import liquibase.exception.*;
@@ -169,7 +171,7 @@ public CheckSum generateCheckSum() {
}
if (sql != null) {
stream = new ByteArrayInputStream(sql.getBytes("UTF-8"));
stream = new ByteArrayInputStream(sql.getBytes(LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding()));
}
return CheckSum.compute(new NormalizingStream(this.getEndDelimiter(), this.isSplitStatements(), this.isStripComments(), stream), false);
@@ -272,7 +274,11 @@ protected String normalizeLineEndings(String string) {
public NormalizingStream(String endDelimiter, Boolean splitStatements, Boolean stripComments, InputStream stream) {
this.stream = new PushbackInputStream(stream, 2048);
this.headerStream = new ByteArrayInputStream((endDelimiter+":"+splitStatements+":"+stripComments+":").getBytes());
try {
this.headerStream = new ByteArrayInputStream((endDelimiter+":"+splitStatements+":"+stripComments+":").getBytes(LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding()));
} catch (UnsupportedEncodingException e) {
throw new UnexpectedLiquibaseException(e);
}
}
@Override
@@ -1,6 +1,8 @@
package liquibase.change.core;
import liquibase.change.*;
import liquibase.configuration.GlobalConfiguration;
import liquibase.configuration.LiquibaseConfiguration;
import liquibase.database.Database;
import liquibase.database.DatabaseList;
import liquibase.database.core.HsqlDatabase;
@@ -219,11 +221,12 @@ public CheckSum generateCheckSum() {
procedureText = "";
}
String encoding = LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding();
if (procedureText != null) {
try {
stream = new ByteArrayInputStream(procedureText.getBytes("UTF-8"));
stream = new ByteArrayInputStream(procedureText.getBytes(encoding));
} catch (UnsupportedEncodingException e) {
throw new AssertionError("UTF-8 is not supported by the JVM, this should not happen according to the JavaDoc of the Charset class");
throw new AssertionError(encoding+" is not supported by the JVM, this should not happen according to the JavaDoc of the Charset class");
}
}
@@ -4,6 +4,8 @@
import liquibase.change.DatabaseChange;
import liquibase.change.ChangeMetaData;
import liquibase.change.DatabaseChangeProperty;
import liquibase.configuration.GlobalConfiguration;
import liquibase.configuration.LiquibaseConfiguration;
import liquibase.database.Database;
import liquibase.exception.UnexpectedLiquibaseException;
import liquibase.exception.ValidationErrors;
@@ -174,8 +176,8 @@ protected void executeCommand(Database database) throws Exception {
;
}
LogFactory.getLogger().severe(errorStream.toString());
LogFactory.getLogger().info(inputStream.toString());
LogFactory.getLogger().severe(errorStream.toString(LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding()));
LogFactory.getLogger().info(inputStream.toString(LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding()));
if (returnCode != 0) {
throw new RuntimeException(getCommandString() + " returned an code of " + returnCode);
@@ -4,6 +4,8 @@
import liquibase.Labels;
import liquibase.change.CheckSum;
import liquibase.changelog.ChangeSet.ExecType;
import liquibase.configuration.GlobalConfiguration;
import liquibase.configuration.LiquibaseConfiguration;
import liquibase.database.Database;
import liquibase.database.OfflineConnection;
import liquibase.exception.DatabaseException;
@@ -21,10 +23,7 @@
import liquibase.util.csv.CSVReader;
import liquibase.util.csv.CSVWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.*;
import java.util.*;
@LiquibaseService(skip = true)
@@ -114,9 +113,9 @@ public void init() throws DatabaseException {
}
protected void writeHeader(File file) throws IOException {
FileWriter writer = null;
Writer writer = null;
try {
writer = new FileWriter(file);
writer = new OutputStreamWriter(new FileOutputStream(file), LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding());
CSVWriter csvWriter = new CSVWriter(writer);
csvWriter.writeNext(new String[]{
"ID",
@@ -157,9 +156,9 @@ protected void replaceChecksum(final ChangeSet changeSet) throws DatabaseExcepti
@Override
public List<RanChangeSet> getRanChangeSets() throws DatabaseException {
FileReader reader = null;
Reader reader = null;
try {
reader = new FileReader(this.changeLogFile);
reader = new InputStreamReader(new FileInputStream(this.changeLogFile), LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding());
CSVReader csvReader = new CSVReader(reader);
String[] line = csvReader.readNext();
@@ -218,12 +217,12 @@ protected void replaceChangeSet(ChangeSet changeSet, ReplaceChangeSetLogic repla
File oldFile = this.changeLogFile;
File newFile = new File(oldFile.getParentFile(), oldFile.getName()+".new");
FileReader reader = null;
FileWriter writer = null;
Reader reader = null;
Writer writer = null;
try {
reader = new FileReader(oldFile);
writer = new FileWriter(newFile);
reader = new InputStreamReader(new FileInputStream(oldFile), LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding());
writer = new OutputStreamWriter(new FileOutputStream(newFile), LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding());
CSVReader csvReader = new CSVReader(reader);
CSVWriter csvWriter = new CSVWriter(writer);
String[] line;
@@ -267,12 +266,12 @@ protected void appendChangeSet(ChangeSet changeSet, ChangeSet.ExecType execType)
File oldFile = this.changeLogFile;
File newFile = new File(oldFile.getParentFile(), oldFile.getName()+".new");
FileReader reader = null;
FileWriter writer = null;
Reader reader = null;
Writer writer = null;
try {
reader = new FileReader(oldFile);
writer = new FileWriter(newFile);
reader = new InputStreamReader(new FileInputStream(oldFile), LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding());
writer = new OutputStreamWriter(new FileOutputStream(newFile), LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding());
CSVReader csvReader = new CSVReader(reader);
CSVWriter csvWriter = new CSVWriter(writer);
String[] line;
@@ -373,9 +372,9 @@ public int getNextSequenceValue() throws LiquibaseException {
if (lastChangeSetSequenceValue == null) {
lastChangeSetSequenceValue = 0;
FileReader reader = null;
Reader reader = null;
try {
reader = new FileReader(this.changeLogFile);
reader = new InputStreamReader(new FileInputStream(this.changeLogFile), LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding());
CSVReader csvReader = new CSVReader(reader);
String[] line = csvReader.readNext(); //skip header line
@@ -4,8 +4,8 @@
import liquibase.database.Database;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.List;
public class AuthorWriter extends HTMLWriter {
@@ -20,6 +20,6 @@ protected String createTitle(Object object) {
}
@Override
protected void writeCustomHTML(FileWriter fileWriter, Object object, List<Change> changes, Database database) throws IOException {
protected void writeCustomHTML(Writer fileWriter, Object object, List<Change> changes, Database database) throws IOException {
}
}
@@ -1,5 +1,7 @@
package liquibase.dbdoc;
import liquibase.configuration.GlobalConfiguration;
import liquibase.configuration.LiquibaseConfiguration;
import liquibase.resource.ResourceAccessor;
import liquibase.util.StreamUtil;
@@ -35,7 +37,7 @@ public void writeChangeLog(String changeLog, String physicalFilePath) throws IOE
File xmlFile = new File(outputDir, changeLogOutFile + ".html");
xmlFile.getParentFile().mkdirs();
BufferedWriter changeLogStream = new BufferedWriter(new FileWriter(xmlFile, false));
BufferedWriter changeLogStream = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(xmlFile, false), LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding()));
try {
changeLogStream.write("<html><body><pre>\n");
changeLogStream.write(StreamUtil.getStreamContents(stylesheet).replace("<", "&lt;").replace(">", "&gt;"));
@@ -4,8 +4,8 @@
import liquibase.database.Database;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.List;
public class ColumnWriter extends HTMLWriter {
@@ -21,6 +21,6 @@ protected String createTitle(Object object) {
}
@Override
protected void writeCustomHTML(FileWriter fileWriter, Object object, List<Change> changes, Database database) throws IOException {
protected void writeCustomHTML(Writer fileWriter, Object object, List<Change> changes, Database database) throws IOException {
}
}
@@ -1,11 +1,11 @@
package liquibase.dbdoc;
import liquibase.configuration.GlobalConfiguration;
import liquibase.configuration.LiquibaseConfiguration;
import liquibase.structure.DatabaseObject;
import liquibase.util.StringUtils;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.*;
import java.util.SortedSet;
public class HTMLListWriter {
@@ -25,7 +25,7 @@ public HTMLListWriter(String title, String filename, String subdir, File outputD
}
public void writeHTML(SortedSet objects) throws IOException {
FileWriter fileWriter = new FileWriter(new File(outputDir, filename));
Writer fileWriter = new OutputStreamWriter(new FileOutputStream(new File(outputDir, filename)), LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding());
try {
fileWriter.append("<HTML>\n" + "<HEAD>\n" + "<TITLE>\n");
@@ -2,15 +2,15 @@
import liquibase.change.Change;
import liquibase.changelog.ChangeSet;
import liquibase.configuration.GlobalConfiguration;
import liquibase.configuration.LiquibaseConfiguration;
import liquibase.database.Database;
import liquibase.exception.DatabaseException;
import liquibase.exception.DatabaseHistoryException;
import liquibase.util.LiquibaseUtil;
import liquibase.util.StringUtils;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.*;
import java.net.URLEncoder;
import java.text.DateFormat;
import java.util.Date;
@@ -28,14 +28,14 @@ public HTMLWriter(File outputDir, Database database) {
}
}
protected abstract void writeCustomHTML(FileWriter fileWriter, Object object, List<Change> changes, Database database) throws IOException;
protected abstract void writeCustomHTML(Writer fileWriter, Object object, List<Change> changes, Database database) throws IOException;
private FileWriter createFileWriter(Object object) throws IOException {
return new FileWriter(new File(outputDir, DBDocUtil.toFileName(object.toString().toLowerCase()) + ".html"));
private Writer createFileWriter(Object object) throws IOException {
return new OutputStreamWriter(new FileOutputStream(new File(outputDir, DBDocUtil.toFileName(object.toString().toLowerCase()) + ".html")), LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding());
}
public void writeHTML(Object object, List<Change> ranChanges, List<Change> changesToRun, String changeLog) throws IOException, DatabaseHistoryException, DatabaseException {
FileWriter fileWriter = createFileWriter(object);
Writer fileWriter = createFileWriter(object);
try {
@@ -57,7 +57,7 @@ public void writeHTML(Object object, List<Change> ranChanges, List<Change> chang
}
private void writeFooter(FileWriter fileWriter, String changeLog) throws IOException {
private void writeFooter(Writer fileWriter, String changeLog) throws IOException {
fileWriter.append("<hr>Generated: ");
fileWriter.append(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date()));
fileWriter.append("<BR>Against: ");
@@ -68,13 +68,13 @@ private void writeFooter(FileWriter fileWriter, String changeLog) throws IOExcep
fileWriter.append("<a href='http://www.liquibase.org' target='_TOP'>Liquibase ").append(LiquibaseUtil.getBuildVersion()).append("</a>");
}
protected void writeBody(FileWriter fileWriter, Object object, List<Change> ranChanges, List<Change> changesToRun) throws IOException, DatabaseHistoryException, DatabaseException {
protected void writeBody(Writer fileWriter, Object object, List<Change> ranChanges, List<Change> changesToRun) throws IOException, DatabaseHistoryException, DatabaseException {
writeCustomHTML(fileWriter, object, ranChanges, database);
writeChanges("Pending Changes", fileWriter, changesToRun);
writeChanges("Past Changes", fileWriter, ranChanges);
}
protected void writeTable(String title, List<List<String>> cells, FileWriter fileWriter) throws IOException {
protected void writeTable(String title, List<List<String>> cells, Writer fileWriter) throws IOException {
fileWriter.append("<P>");
int colspan = 0;
if (cells.size() == 0) {
@@ -96,13 +96,13 @@ protected void writeTable(String title, List<List<String>> cells, FileWriter fil
fileWriter.append("</TABLE>\n");
}
private void writeTD(FileWriter fileWriter, String filePath) throws IOException {
private void writeTD(Writer fileWriter, String filePath) throws IOException {
fileWriter.append("<TD VALIGN=\"top\">\n");
fileWriter.append(filePath);
fileWriter.append("</TD>\n");
}
private void writeHeader(Object object, FileWriter fileWriter) throws IOException {
private void writeHeader(Object object, Writer fileWriter) throws IOException {
String title = createTitle(object);
fileWriter.append("<head>")
.append("<title>").append(title).append("</title>")
@@ -117,7 +117,7 @@ private void writeHeader(Object object, FileWriter fileWriter) throws IOExceptio
protected abstract String createTitle(Object object);
protected void writeChanges(String title, FileWriter fileWriter, List<Change> changes) throws IOException, DatabaseHistoryException, DatabaseException {
protected void writeChanges(String title, Writer fileWriter, List<Change> changes) throws IOException, DatabaseHistoryException, DatabaseException {
fileWriter.append("<p><TABLE BORDER=\"1\" WIDTH=\"100%\" CELLPADDING=\"3\" CELLSPACING=\"0\" SUMMARY=\"\">\n");
fileWriter.append("<TR BGCOLOR=\"#CCCCFF\" CLASS=\"TableHeadingColor\">\n");
fileWriter.append("<TD COLSPAN='4'><FONT SIZE=\"+2\">\n");
@@ -6,8 +6,8 @@
import liquibase.exception.DatabaseHistoryException;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.List;
public class PendingChangesWriter extends HTMLWriter {
@@ -22,12 +22,12 @@ protected String createTitle(Object object) {
}
@Override
protected void writeBody(FileWriter fileWriter, Object object, List<Change> ranChanges, List<Change> changesToRun) throws IOException, DatabaseHistoryException, DatabaseException {
protected void writeBody(Writer fileWriter, Object object, List<Change> ranChanges, List<Change> changesToRun) throws IOException, DatabaseHistoryException, DatabaseException {
writeCustomHTML(fileWriter, object, ranChanges, database);
writeChanges("Pending Changes", fileWriter, changesToRun);
}
@Override
protected void writeCustomHTML(FileWriter fileWriter, Object object, List<Change> changes, Database database) throws IOException {
protected void writeCustomHTML(Writer fileWriter, Object object, List<Change> changes, Database database) throws IOException {
}
}
@@ -1,6 +1,5 @@
package liquibase.dbdoc;
import liquibase.Liquibase;
import liquibase.change.Change;
import liquibase.change.ChangeFactory;
import liquibase.changelog.ChangeSet;
@@ -14,8 +13,8 @@
import liquibase.executor.LoggingExecutor;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.List;
public class PendingSQLWriter extends HTMLWriter {
@@ -33,7 +32,7 @@ protected String createTitle(Object object) {
}
@Override
protected void writeBody(FileWriter fileWriter, Object object, List<Change> ranChanges, List<Change> changesToRun) throws IOException, DatabaseHistoryException, DatabaseException {
protected void writeBody(Writer fileWriter, Object object, List<Change> ranChanges, List<Change> changesToRun) throws IOException, DatabaseHistoryException, DatabaseException {
Executor oldTemplate = ExecutorService.getInstance().getExecutor(database);
LoggingExecutor loggingExecutor = new LoggingExecutor(ExecutorService.getInstance().getExecutor(database), fileWriter, database);
@@ -69,6 +68,6 @@ protected void writeBody(FileWriter fileWriter, Object object, List<Change> ranC
}
@Override
protected void writeCustomHTML(FileWriter fileWriter, Object object, List<Change> changes, Database database) throws IOException {
protected void writeCustomHTML(Writer fileWriter, Object object, List<Change> changes, Database database) throws IOException {
}
}
Oops, something went wrong.

0 comments on commit 936b617

Please sign in to comment.