From b0ca714605b3f12385ac40050e776f8c3ebd0f02 Mon Sep 17 00:00:00 2001 From: pesse Date: Fri, 5 Oct 2018 15:11:07 +0200 Subject: [PATCH 1/2] Reporter and Version-Command: Better error-handling --- pom.xml | 2 +- .../java/org/utplsql/cli/ReportersCommand.java | 17 +++++++++++++---- .../org/utplsql/cli/VersionInfoCommand.java | 6 ++++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 703f470..3be939e 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ org.utplsql java-api - 3.1.1 + 3.1.1.1-SNAPSHOT compile diff --git a/src/main/java/org/utplsql/cli/ReportersCommand.java b/src/main/java/org/utplsql/cli/ReportersCommand.java index 32624eb..b4fed8c 100644 --- a/src/main/java/org/utplsql/cli/ReportersCommand.java +++ b/src/main/java/org/utplsql/cli/ReportersCommand.java @@ -2,9 +2,12 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; +import org.utplsql.api.exception.DatabaseNotCompatibleException; +import org.utplsql.api.exception.UtPLSQLNotInstalledException; import org.utplsql.api.reporter.ReporterFactory; import org.utplsql.api.reporter.inspect.ReporterInfo; import org.utplsql.api.reporter.inspect.ReporterInspector; +import org.utplsql.cli.exception.DatabaseConnectionFailed; import javax.sql.DataSource; import java.io.PrintStream; @@ -21,9 +24,11 @@ public class ReportersCommand implements ICommand { private List connectionInfoList = new ArrayList<>(); private ConnectionInfo getConnectionInfo() { - assert connectionInfoList != null; - assert connectionInfoList.size() > 0; - assert connectionInfoList.get(0) != null; + Objects.requireNonNull(connectionInfoList); + + if ( connectionInfoList.size() <= 0 + || connectionInfoList.get(0) == null) + throw new IllegalArgumentException("No Connection-Info given"); return connectionInfoList.get(0); } @@ -39,7 +44,11 @@ public int run() { writeReporters(ReporterInspector.create(reporterFactory, con).getReporterInfos(), System.out); } - } catch (Exception e) { + } + catch ( DatabaseNotCompatibleException | UtPLSQLNotInstalledException | DatabaseConnectionFailed | IllegalArgumentException e ) { + System.out.println(e.getMessage()); + } + catch (Exception e) { e.printStackTrace(); return 1; } diff --git a/src/main/java/org/utplsql/cli/VersionInfoCommand.java b/src/main/java/org/utplsql/cli/VersionInfoCommand.java index 0fec979..b391df8 100644 --- a/src/main/java/org/utplsql/cli/VersionInfoCommand.java +++ b/src/main/java/org/utplsql/cli/VersionInfoCommand.java @@ -6,6 +6,8 @@ import org.utplsql.api.DBHelper; import org.utplsql.api.JavaApiVersionInfo; import org.utplsql.api.Version; +import org.utplsql.api.db.DatabaseInformation; +import org.utplsql.api.db.DefaultDatabaseInformation; import org.utplsql.api.exception.UtPLSQLNotInstalledException; import javax.sql.DataSource; @@ -52,11 +54,11 @@ private void writeUtPlsqlVersion( ConnectionInfo ci ) throws SQLException { DataSource dataSource = DataSourceProvider.getDataSource(ci, 1); try (Connection con = dataSource.getConnection()) { - Version v = DBHelper.getDatabaseFrameworkVersion( con ); + Version v = new DefaultDatabaseInformation().getUtPlsqlFrameworkVersion(con); System.out.println("utPLSQL " + v.getNormalizedString()); } catch ( UtPLSQLNotInstalledException e ) { - System.out.println("utPLSQL framework is not installed in database."); + System.out.println(e.getMessage()); } } } From 96fec2cac8a7a18b3b96fcfd42ef7e5689d99bc6 Mon Sep 17 00:00:00 2001 From: pesse Date: Fri, 5 Oct 2018 15:11:28 +0200 Subject: [PATCH 2/2] Remove unnecessary functions --- src/main/java/org/utplsql/cli/ReportersCommand.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/main/java/org/utplsql/cli/ReportersCommand.java b/src/main/java/org/utplsql/cli/ReportersCommand.java index b4fed8c..6d297a4 100644 --- a/src/main/java/org/utplsql/cli/ReportersCommand.java +++ b/src/main/java/org/utplsql/cli/ReportersCommand.java @@ -61,15 +61,7 @@ public String getCommand() { return "reporters"; } - private int getMaxNameLength(List reporterInfos) { - return reporterInfos.stream() - .mapToInt(info -> info.getName().length()) - .max() - .orElse(0); - } - private void writeReporters(List reporterInfos, PrintStream out) { - //int padding = getMaxNameLength(reporterInfos)+1; reporterInfos.stream() .sorted(Comparator.comparing(ReporterInfo::getName)) .forEach(info -> writeReporter(info, 4, out));