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..6d297a4 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; } @@ -52,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)); 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()); } } }