Skip to content

Commit

Permalink
Cleaning up liquibase.util tests and code
Browse files Browse the repository at this point in the history
- Upgraded opencsv and moved it to an external but shaded dependency
  • Loading branch information
nvoxland committed Sep 23, 2021
1 parent 4816c8e commit 7437709
Show file tree
Hide file tree
Showing 22 changed files with 168 additions and 2,523 deletions.
45 changes: 44 additions & 1 deletion liquibase-core/pom.xml
Expand Up @@ -116,6 +116,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>5.5.2</version>
</dependency>


</dependencies>

<build>
Expand Down Expand Up @@ -198,6 +205,40 @@
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>com.opencsv:*</include>
<include>org.apache.commons:commons-lang3</include>
<include>org.apache.commons:commons-text</include>
<include>org.apache.commons:commons-collections4</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.apache</pattern>
<shadedPattern>liquibase.repackaged.org.apache</shadedPattern>
</relocation>
<relocation>
<pattern>com.opencsv</pattern>
<shadedPattern>liquibase.repackaged.com.opencsv</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand All @@ -209,7 +250,9 @@
<Main-Class>liquibase.integration.commandline.Main</Main-Class>
</manifest>
<manifestEntries>
<Liquibase-Package>liquibase.change,liquibase.command,liquibase.changelog,liquibase.database,liquibase.parser,liquibase.precondition,liquibase.datatype,liquibase.serializer,liquibase.sqlgenerator,liquibase.executor,liquibase.snapshot,liquibase.logging,liquibase.diff,liquibase.structure,liquibase.structurecompare,liquibase.lockservice,liquibase.sdk.database,liquibase.ext,liquibase.pro,com.datical.liquibase</Liquibase-Package>
<Liquibase-Package>
liquibase.change,liquibase.command,liquibase.changelog,liquibase.database,liquibase.parser,liquibase.precondition,liquibase.datatype,liquibase.serializer,liquibase.sqlgenerator,liquibase.executor,liquibase.snapshot,liquibase.logging,liquibase.diff,liquibase.structure,liquibase.structurecompare,liquibase.lockservice,liquibase.sdk.database,liquibase.ext,liquibase.pro,com.datical.liquibase
</Liquibase-Package>
<Build-Time>${build.timestamp}</Build-Time>
<Build-Number>${build.number}</Build-Number>
<Liquibase-Version>${project.version}</Liquibase-Version>
Expand Down
@@ -1,5 +1,6 @@
package liquibase.change.core;

import com.opencsv.CSVReaderBuilder;
import liquibase.CatalogAndSchema;
import liquibase.Scope;
import liquibase.change.*;
Expand Down Expand Up @@ -571,7 +572,7 @@ database, getCatalogName(), getSchemaName(),
if (null != reader) {
try {
reader.close();
} catch (IOException e) {
} catch (Exception e) {
// Do nothing
}
}
Expand Down
32 changes: 23 additions & 9 deletions liquibase-core/src/main/java/liquibase/util/csv/CSVReader.java
@@ -1,27 +1,41 @@
package liquibase.util.csv;

import com.opencsv.CSVReaderBuilder;
import com.opencsv.RFC4180ParserBuilder;
import com.opencsv.exceptions.CsvValidationException;

import java.io.IOException;
import java.io.Reader;

public class CSVReader extends liquibase.util.csv.opencsv.CSVReader {
public class CSVReader implements AutoCloseable {

private final com.opencsv.CSVReader delegate;

public static final char DEFAULT_SEPARATOR = ',';

public static final char DEFAULT_QUOTE_CHARACTER = '"';


public CSVReader(Reader reader) {
super(reader);
this(reader, DEFAULT_SEPARATOR, DEFAULT_QUOTE_CHARACTER);
}

public CSVReader(Reader reader, char c) {
super(reader, c);

public CSVReader(Reader reader, char separator, char quotchar) {
delegate = new CSVReaderBuilder(reader).withCSVParser(
new RFC4180ParserBuilder().withSeparator(separator).withQuoteChar(quotchar).build()
).build();
}

public CSVReader(Reader reader, char c, char c1) {
super(reader, c, c1);
@Override
public void close() throws Exception {
delegate.close();
}

public CSVReader(Reader reader, char c, char c1, int i) {
super(reader, c, c1, i);
public String[] readNext() throws IOException {
try {
return delegate.readNext();
} catch (CsvValidationException e) {
throw new IOException(e.getMessage(), e);
}
}
}
153 changes: 13 additions & 140 deletions liquibase-core/src/main/java/liquibase/util/csv/CSVWriter.java
@@ -1,159 +1,32 @@
package liquibase.util.csv;

import com.opencsv.CSVWriterBuilder;
import com.opencsv.ICSVWriter;
import liquibase.util.ISODateFormat;

import java.io.Flushable;
import java.io.IOException;
import java.io.Writer;
import java.sql.ResultSet;
import java.sql.SQLException;

public class CSVWriter extends liquibase.util.csv.opencsv.CSVWriter {
private static final ISODateFormat ISO_DATE_FORMAT = new ISODateFormat();
public class CSVWriter implements AutoCloseable, Flushable {
private final ICSVWriter delegate;

public CSVWriter(Writer writer) {
super(writer);
delegate = new CSVWriterBuilder(writer).build();
}

public CSVWriter(Writer writer, char c) {
super(writer, c);
@Override
public void close() throws Exception {
delegate.close();
}

public CSVWriter(Writer writer, char c, char c1) {
super(writer, c, c1);
public void writeNext(String[] nextLine) {
delegate.writeNext(nextLine);
}

public CSVWriter(Writer writer, char c, char c1, char c2) {
super(writer, c, c1, c2);
public void flush() throws IOException {
delegate.flush();
}

public CSVWriter(Writer writer, char c, char c1, String s) {
super(writer, c, c1, s);
}

public CSVWriter(Writer writer, char c, char c1, char c2, String s) {
super(writer, c, c1, c2, s);
}


private String getColumnValue(ResultSet rs, int colType, int colIndex) throws SQLException, IOException {

Object value = rs.getObject(colIndex);
if (rs.wasNull()) {
return "NULL";
}

if (value instanceof java.sql.Date) {
return ISO_DATE_FORMAT.format((java.sql.Date) value);
} else if (value instanceof java.sql.Time) {
return ISO_DATE_FORMAT.format((java.sql.Time) value);
} else if (value instanceof java.sql.Timestamp) {
return ISO_DATE_FORMAT.format((java.sql.Timestamp) value);
// } else if (value instanceof oracle.sql.TIMESTAMP) {
// return ISO_DATE_FORMAT.format((oracle.sql.TIMESTAMP) value);
} else {
return value.toString();
}

// if (colType == Types.BIT) {
// Object bit = rs.getObject(colIndex);
// if (rs.wasNull()) {
// return null;
// } else {
// return String.valueOf(bit);
// }
// } else if (colType == Types.BOOLEAN) {
// boolean b = rs.getBoolean(colIndex);
// if (rs.wasNull()) {
// return null;
// } else {
// return Boolean.valueOf(b).toString();
// }
// } else if (colType == Types.CLOB) {
// Clob c = rs.getClob(colIndex);
// if (rs.wasNull()) {
// return null;
// } else {
// return read(c);
// }
// } else if (colType == Types.BIGINT
// || colType == Types.DECIMAL
// || colType == Types.DOUBLE
// || colType == Types.FLOAT
// || colType == Types.REAL
// || colType == Types.NUMERIC) {
// BigDecimal bd = rs.getBigDecimal(colIndex);
// if (rs.wasNull()) {
// return null;
// } else {
// return String.valueOf(bd.doubleValue());
// }
//
// } else if (colType == Types.INTEGER
// || colType == Types.TINYINT
// || colType == Types.SMALLINT) {
// int intValue = rs.getInt(colIndex);
// if (rs.wasNull()) {
// return null;
// } else {
// return String.valueOf(intValue);
// }
// }
//
// case Types.JAVA_OBJECT:
// Object obj = rs.getObject(colIndex);
// if (obj != null) {
// value = String.valueOf(obj);
// }
// break;
// case Types.DATE:
// java.sql.Date date = rs.getDate(colIndex);
// if (date != null) {
// value = ISO_DATE_FORMAT.format(date);
// ;
// }
// break;
// case Types.TIME:
// Time t = rs.getTime(colIndex);
// if (t != null) {
// value = t.toString();
// }
// break;
// case Types.TIMESTAMP:
// Timestamp tstamp = rs.getTimestamp(colIndex);
// if (tstamp != null) {
// value = ISO_DATE_FORMAT.format(tstamp);
// }
// break;
// case Types.LONGVARCHAR:
// case Types.VARCHAR:
// case Types.CHAR:
// value = rs.getString(colIndex);
// break;
// default:
// value = "";
// }

// if (value == null)
//
// {
// value = "";
// }
//
// return value;

}

// private static String read(Clob c) throws SQLException, IOException {
// StringBuffer sb = new StringBuffer((int) c.length());
// Reader r = c.getCharacterStream();
// char[] cbuf = new char[2048];
// int n = 0;
// while ((n = r.read(cbuf, 0, cbuf.length)) != -1) {
// if (n > 0) {
// sb.append(cbuf, 0, n);
// }
// }
// return sb.toString();
// }

}

This file was deleted.

0 comments on commit 7437709

Please sign in to comment.