diff --git a/config/pom.xml b/config/pom.xml index 5efcc6f098..80776b2612 100644 --- a/config/pom.xml +++ b/config/pom.xml @@ -68,7 +68,7 @@ org.apache.commons commons-lang3 - + diff --git a/config/src/main/java/com/quorum/tessera/config/ServerConfig.java b/config/src/main/java/com/quorum/tessera/config/ServerConfig.java index 687ed78a4d..2030f6eac7 100644 --- a/config/src/main/java/com/quorum/tessera/config/ServerConfig.java +++ b/config/src/main/java/com/quorum/tessera/config/ServerConfig.java @@ -159,6 +159,4 @@ public void setCrossDomainConfig(CrossDomainConfig crossDomainConfig) { this.crossDomainConfig = crossDomainConfig; } - - } diff --git a/data-migration/src/main/java/com/quorum/tessera/data/migration/CmdLineExecutor.java b/data-migration/src/main/java/com/quorum/tessera/data/migration/CmdLineExecutor.java index 837f25c978..9f3d8d5739 100644 --- a/data-migration/src/main/java/com/quorum/tessera/data/migration/CmdLineExecutor.java +++ b/data-migration/src/main/java/com/quorum/tessera/data/migration/CmdLineExecutor.java @@ -99,7 +99,6 @@ private Options createOptions() { .required() .build()); - options.addOption( Option.builder() .longOpt("exporttype") diff --git a/data-migration/src/main/java/com/quorum/tessera/data/migration/H2DataExporter.java b/data-migration/src/main/java/com/quorum/tessera/data/migration/H2DataExporter.java index de2409e0e9..43a26ea92f 100644 --- a/data-migration/src/main/java/com/quorum/tessera/data/migration/H2DataExporter.java +++ b/data-migration/src/main/java/com/quorum/tessera/data/migration/H2DataExporter.java @@ -1,15 +1,13 @@ package com.quorum.tessera.data.migration; -import com.quorum.tessera.io.IOCallback; -import com.quorum.tessera.io.UriCallback; - +import java.io.BufferedReader; import java.io.IOException; -import java.net.URL; -import java.nio.file.Files; +import java.io.InputStreamReader; import java.nio.file.Path; -import java.nio.file.Paths; import java.sql.SQLException; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class H2DataExporter implements DataExporter { @@ -25,9 +23,11 @@ public void export(final StoreLoader loader, final String connectionString = "jdbc:h2:" + output.toString(); - final URL sqlFile = getClass().getResource(CREATE_TABLE_RESOURCE); - final Path uri = UriCallback.execute(() -> Paths.get(sqlFile.toURI())); - final List createTableStatements = IOCallback.execute(() -> Files.readAllLines(uri)); + final List createTableStatements = Stream.of(getClass().getResourceAsStream(CREATE_TABLE_RESOURCE)) + .map(InputStreamReader::new) + .map(BufferedReader::new) + .flatMap(BufferedReader::lines) + .collect(Collectors.toList()); final JdbcDataExporter jdbcDataExporter = new JdbcDataExporter(connectionString, INSERT_ROW, createTableStatements); diff --git a/data-migration/src/main/java/com/quorum/tessera/data/migration/Main.java b/data-migration/src/main/java/com/quorum/tessera/data/migration/Main.java index d3c57798ad..a0f592df77 100644 --- a/data-migration/src/main/java/com/quorum/tessera/data/migration/Main.java +++ b/data-migration/src/main/java/com/quorum/tessera/data/migration/Main.java @@ -1,5 +1,7 @@ package com.quorum.tessera.data.migration; +import java.util.Arrays; + public class Main { private Main() { @@ -12,7 +14,14 @@ public static void main(final String... args) { final int result = new CmdLineExecutor().execute(args); System.exit(result); } catch (final Exception ex) { - System.err.println(ex.getMessage()); + System.err.println("An error has occurred: " + ex.getMessage()); + + if (Arrays.asList(args).contains("debug")) { + System.err.println(); + System.err.println("Exception message: " + ex.getMessage()); + System.err.println("Exception class: " + ex.getClass()); + } + System.exit(1); } diff --git a/data-migration/src/main/java/com/quorum/tessera/data/migration/SqliteDataExporter.java b/data-migration/src/main/java/com/quorum/tessera/data/migration/SqliteDataExporter.java index b26229096d..931236c9e3 100644 --- a/data-migration/src/main/java/com/quorum/tessera/data/migration/SqliteDataExporter.java +++ b/data-migration/src/main/java/com/quorum/tessera/data/migration/SqliteDataExporter.java @@ -1,22 +1,23 @@ package com.quorum.tessera.data.migration; -import com.quorum.tessera.io.IOCallback; -import com.quorum.tessera.io.UriCallback; import org.apache.commons.io.IOUtils; +import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; -import java.net.URI; -import java.nio.file.Files; +import java.io.InputStreamReader; import java.nio.file.Path; -import java.nio.file.Paths; import java.sql.*; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class SqliteDataExporter implements DataExporter { private static final String INSERT_ROW = "INSERT INTO ENCRYPTED_TRANSACTION (HASH, ENCODED_PAYLOAD) VALUES (?, ?)"; + private static final String CREATE_TABLE_RESOURCE = "/ddls/sqlite-ddl.sql"; + @Override public void export(final StoreLoader loader, final Path output, @@ -25,14 +26,16 @@ public void export(final StoreLoader loader, final String connectionString = "jdbc:sqlite:" + output.toString(); - final URI sqlFile = UriCallback.execute(() -> getClass().getResource("/ddls/sqlite-ddl.sql").toURI()); - - final List createTables = IOCallback.execute(() -> Files.readAllLines(Paths.get(sqlFile))); + final List createTableStatements = Stream.of(getClass().getResourceAsStream(CREATE_TABLE_RESOURCE)) + .map(InputStreamReader::new) + .map(BufferedReader::new) + .flatMap(BufferedReader::lines) + .collect(Collectors.toList()); try (Connection conn = DriverManager.getConnection(connectionString, username, password)) { try (Statement stmt = conn.createStatement()) { - for (final String createTable : createTables) { + for (final String createTable : createTableStatements) { stmt.executeUpdate(createTable); } } diff --git a/data-migration/src/test/java/com/quorum/tessera/data/migration/MainTest.java b/data-migration/src/test/java/com/quorum/tessera/data/migration/MainTest.java index e3970e523f..5c7bb607cb 100644 --- a/data-migration/src/test/java/com/quorum/tessera/data/migration/MainTest.java +++ b/data-migration/src/test/java/com/quorum/tessera/data/migration/MainTest.java @@ -21,4 +21,10 @@ public void doStuffAndBreak() { Main.main(); } + @Test + public void outputDebugInformationWithNullCause() { + expectedSystemExit.expectSystemExitWithStatus(1); + Main.main("debug"); + } + } diff --git a/pom.xml b/pom.xml index a0b843f3c0..30d4be2ad1 100644 --- a/pom.xml +++ b/pom.xml @@ -979,7 +979,6 @@ runtime - org.slf4j slf4j-api