Skip to content
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

Feature/java17 #24

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 20 additions & 51 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>eu.lmc.tools</groupId>
<artifactId>applyalter</artifactId>
<version>4.9</version>
<version>5.0</version>
<name>applyalter</name>

<properties>
Expand All @@ -23,70 +23,39 @@
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.2</version>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.0</version>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>net.sf.opencsv</groupId>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>1.8</version>
<version>5.6</version>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.3</version>
</dependency>

<!-- log4j is included, but without some silly dependencies -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
<version>1.4.19</version>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.14.9</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.0</version>
<artifactId>mockito-core</artifactId>
<version>4.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -114,7 +83,7 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.5</version>
<version>42.4.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
Expand All @@ -141,7 +110,7 @@
<plugin>
<artifactId>jdeb</artifactId>
<groupId>org.vafer</groupId>
<version>1.4</version>
<version>1.10</version>
<executions>
<execution>
<phase>package</phase>
Expand Down Expand Up @@ -182,16 +151,16 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<version>3.10.1</version>
<configuration>
<source>8</source>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to be able to run on java 8, but also on java 17. Target must stay at 8

<target>8</target>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4</version>
<version>3.3.0</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<filters>
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/ch/ips/g2/applyalter/ApplyAlter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import ch.ips.g2.applyalter.logreport.ReportedResult;
import ch.ips.g2.applyalter.logreport.StructuredLog;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.XStreamException;
import org.apache.commons.cli.BasicParser;
Expand Down Expand Up @@ -38,6 +36,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -155,7 +154,7 @@ public class ApplyAlter {

protected XStream xstream = new XStream();
protected String username;
protected Multimap<String, String> unapplied = ArrayListMultimap.create();
protected Map<String, List<String>> unapplied = new LinkedHashMap<>();
private boolean logTableUsed;
private String environment;
private boolean unknownInstancesIgnored = false;
Expand Down Expand Up @@ -535,7 +534,9 @@ private void applySingleAlter(final Alter a, ApplyAlterExceptions aae) {

if (RunMode.LOOK.equals(getRunMode())) {
runContext.report(MAIN, "Alter %s seems unapplied", a.getId());
unapplied.put(d.getId(), a.getId());
final List<String> data = unapplied.getOrDefault(d.getId(), new ArrayList<>());
data.add(a.getId());
unapplied.putIfAbsent(d.getId(), data);
continue;
}
d.markConnectionUsed(runContext);
Expand Down Expand Up @@ -784,7 +785,7 @@ public Set<String> getApplyAlterLog(DbInstance d) {
* @return concatenated list ready to print
*/
public String getUnappliedAlters() {
Multimap<String, String> un = ArrayListMultimap.create(unapplied);
final Map<String, List<String>> un = new LinkedHashMap<>(unapplied);
StringBuilder s = new StringBuilder();
for (DbInstance d : db.getEntries()) {
Collection<String> c = un.get(d.getId());
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/ch/ips/g2/applyalter/CSV.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package ch.ips.g2.applyalter;

import au.com.bytecode.opencsv.CSVReader;
import com.opencsv.CSVReader;
import com.opencsv.exceptions.CsvValidationException;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.ParameterMetaData;
Expand Down Expand Up @@ -58,8 +58,8 @@ public CSV() {
* Prepared statement parameters meta info.
*/
private static class ParamMeta {
private int typeId;
private String name;
private final int typeId;
private final String name;
;;

ParamMeta(int typeId, String name) {
Expand Down Expand Up @@ -93,7 +93,7 @@ public void execute(DbInstance dbConn, RunContext ctx, Map<String, byte[]> dataf
throw new ApplyAlterException(String.format("missing top-level element: <datafile>%s</datafile>", getFile()));
}

CSVReader rdr = new CSVReader(new InputStreamReader(new ByteArrayInputStream(rawFile), Charset.forName("UTF-8")));
CSVReader rdr = new CSVReader(new InputStreamReader(new ByteArrayInputStream(rawFile), StandardCharsets.UTF_8));

PreparedStatement st = null;
try {
Expand Down Expand Up @@ -144,7 +144,7 @@ public void execute(DbInstance dbConn, RunContext ctx, Map<String, byte[]> dataf

ctx.report(ReportLevel.STATEMENT_STEP, "statement executed %d times, changed rows: %d%n", execCnt, rows);
rdr.close();
} catch (IOException e) {
} catch (IOException | CsvValidationException e) {
throw new ApplyAlterException("error reading CSV file " + getFile(), e);
} finally {
DbUtils.close(st);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/ch/ips/g2/applyalter/PgInstance.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ch.ips.g2.applyalter;

import com.google.common.annotations.VisibleForTesting;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import org.apache.commons.io.IOUtils;

Expand Down Expand Up @@ -124,7 +123,7 @@ public String getPkgLogTable() {
* matching line and if found, set password via {@link #setPass(String)}
* @param runContext context (used by logging)
*/
@VisibleForTesting void loadPgpass(RunContext runContext, InputStream pgpassInputStream) {
void loadPgpass(RunContext runContext, InputStream pgpassInputStream) {
if (pgpassInputStream == null)
return;
//load whole file at once
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/ch/ips/g2/applyalter/PkgLogTableHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.thoughtworks.xstream.annotations.XStreamImplicit;
import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateFormatUtils;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -14,6 +14,7 @@
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand Down Expand Up @@ -136,7 +137,7 @@ public void queryAndWrite(@Nonnull String outputFile, @Nullable String hash) {
Writer wr = null;
try {
final OutputStream os = stdout ? System.out : new FileOutputStream(outputFile);
wr = new OutputStreamWriter(os, "UTF-8");
wr = new OutputStreamWriter(os, StandardCharsets.UTF_8);
XStream xstream = new XStream();
xstream.processAnnotations(QueryResult.class);
xstream.marshal(new QueryResult(result), new PrettyPrintWriter(wr));
Expand Down Expand Up @@ -179,7 +180,7 @@ public static class Record {
public Record(String hash, String username, Timestamp at) {
this.hash = hash;
this.username = username;
this.at = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(at);
this.at = DateFormatUtils.ISO_8601_EXTENDED_DATETIME_TIME_ZONE_FORMAT.format(at);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import ch.ips.g2.applyalter.ReportLevel;
import ch.ips.g2.applyalter.RunContext;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

Expand All @@ -19,10 +19,7 @@
import javax.xml.transform.stream.StreamResult;
import java.io.IOException;
import java.io.OutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

/**
* Collect logs into json.
Expand All @@ -42,7 +39,7 @@ public class XmlLoggingRunContext extends RunContext.WrapperRunContext {
* Format date and time.
*/
protected String formatTime(Date time) {
return DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(time);
return DateFormatUtils.ISO_8601_EXTENDED_DATETIME_TIME_ZONE_FORMAT.format(time);
}


Expand Down Expand Up @@ -138,7 +135,7 @@ public void report(ReportLevel level, Exception e, String format, Object... args
final Element msg = createMessageElement(format, args);
if (e != null) {
Element stacktrace = document.createElement("stacktrace");
stacktrace.setTextContent(ExceptionUtils.getFullStackTrace(e));
stacktrace.setTextContent(ExceptionUtils.getStackTrace(e));
msg.appendChild(stacktrace);
}
}
Expand Down
50 changes: 24 additions & 26 deletions src/test/java/ch/ips/g2/applyalter/BytesToHexTest.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
package ch.ips.g2.applyalter;

import org.testng.Assert;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import static ch.ips.g2.applyalter.AlterLoader.bytes2hex;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
*
*/
@Test
public class BytesToHexTest
{

public void testEmpty()
{
Assert.assertEquals( bytes2hex( new byte[0] ), "" );
}

public void testSingleByte()
{
for ( int i = 0; i < 256; i++ )
Assert.assertEquals( bytes2hex( new byte[]{(byte) i} ), String.format( "%02X", i ) );
}

public void testBytes()
{
byte[] b1 = new byte[]{
15, 0x12, 0x34, 0x56, 0x78, (byte) 0x9a, (byte) 0xbc, 0xd, (byte) 0xef
};
Assert.assertEquals( bytes2hex( b1 ), "0F123456789ABC0DEF" );
}


public class BytesToHexTest {

@Test
public void testEmpty() {
assertEquals("", bytes2hex(new byte[0]));
}

@Test
public void testSingleByte() {
for (int i = 0; i < 256; i++) {
assertEquals(String.format("%02X", i), bytes2hex(new byte[]{(byte) i}));
}
}

@Test
public void testBytes() {
byte[] b1 = new byte[]{
15, 0x12, 0x34, 0x56, 0x78, (byte) 0x9a, (byte) 0xbc, 0xd, (byte) 0xef
};
assertEquals("0F123456789ABC0DEF", bytes2hex(b1));
}
}
7 changes: 4 additions & 3 deletions src/test/java/ch/ips/g2/applyalter/DbConfigFileTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package ch.ips.g2.applyalter;

import com.thoughtworks.xstream.XStream;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;

import static org.junit.jupiter.api.Assertions.assertTrue;

public class DbConfigFileTest {

@Test
Expand All @@ -29,6 +30,6 @@ public void generateConfigXmlTest() {

System.out.println(xml);

Assert.assertTrue(xml.contains("<param name=\"roleRW\" value=\"pgs_brand0_rw\"/>"), "Final xml must contain element param with attribute name= roleRW");
assertTrue(xml.contains("<param name=\"roleRW\" value=\"pgs_brand0_rw\"/>"), "Final xml must contain element param with attribute name= roleRW");
}
}
Loading