Skip to content

Commit f87c61e

Browse files
authored
Merge pull request #105 from utPLSQL/feature/improve_reporters_command_stability
Feature/improve reporters command
2 parents 7d9c239 + 96fec2c commit f87c61e

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<dependency>
2424
<groupId>org.utplsql</groupId>
2525
<artifactId>java-api</artifactId>
26-
<version>3.1.1</version>
26+
<version>3.1.1.1-SNAPSHOT</version>
2727
<scope>compile</scope>
2828
<exclusions>
2929
<exclusion>

src/main/java/org/utplsql/cli/ReportersCommand.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
import com.beust.jcommander.Parameter;
44
import com.beust.jcommander.Parameters;
5+
import org.utplsql.api.exception.DatabaseNotCompatibleException;
6+
import org.utplsql.api.exception.UtPLSQLNotInstalledException;
57
import org.utplsql.api.reporter.ReporterFactory;
68
import org.utplsql.api.reporter.inspect.ReporterInfo;
79
import org.utplsql.api.reporter.inspect.ReporterInspector;
10+
import org.utplsql.cli.exception.DatabaseConnectionFailed;
811

912
import javax.sql.DataSource;
1013
import java.io.PrintStream;
@@ -21,9 +24,11 @@ public class ReportersCommand implements ICommand {
2124
private List<ConnectionInfo> connectionInfoList = new ArrayList<>();
2225

2326
private ConnectionInfo getConnectionInfo() {
24-
assert connectionInfoList != null;
25-
assert connectionInfoList.size() > 0;
26-
assert connectionInfoList.get(0) != null;
27+
Objects.requireNonNull(connectionInfoList);
28+
29+
if ( connectionInfoList.size() <= 0
30+
|| connectionInfoList.get(0) == null)
31+
throw new IllegalArgumentException("No Connection-Info given");
2732

2833
return connectionInfoList.get(0);
2934
}
@@ -39,7 +44,11 @@ public int run() {
3944

4045
writeReporters(ReporterInspector.create(reporterFactory, con).getReporterInfos(), System.out);
4146
}
42-
} catch (Exception e) {
47+
}
48+
catch ( DatabaseNotCompatibleException | UtPLSQLNotInstalledException | DatabaseConnectionFailed | IllegalArgumentException e ) {
49+
System.out.println(e.getMessage());
50+
}
51+
catch (Exception e) {
4352
e.printStackTrace();
4453
return 1;
4554
}
@@ -52,15 +61,7 @@ public String getCommand() {
5261
return "reporters";
5362
}
5463

55-
private int getMaxNameLength(List<ReporterInfo> reporterInfos) {
56-
return reporterInfos.stream()
57-
.mapToInt(info -> info.getName().length())
58-
.max()
59-
.orElse(0);
60-
}
61-
6264
private void writeReporters(List<ReporterInfo> reporterInfos, PrintStream out) {
63-
//int padding = getMaxNameLength(reporterInfos)+1;
6465
reporterInfos.stream()
6566
.sorted(Comparator.comparing(ReporterInfo::getName))
6667
.forEach(info -> writeReporter(info, 4, out));

src/main/java/org/utplsql/cli/VersionInfoCommand.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import org.utplsql.api.DBHelper;
77
import org.utplsql.api.JavaApiVersionInfo;
88
import org.utplsql.api.Version;
9+
import org.utplsql.api.db.DatabaseInformation;
10+
import org.utplsql.api.db.DefaultDatabaseInformation;
911
import org.utplsql.api.exception.UtPLSQLNotInstalledException;
1012

1113
import javax.sql.DataSource;
@@ -52,11 +54,11 @@ private void writeUtPlsqlVersion( ConnectionInfo ci ) throws SQLException {
5254
DataSource dataSource = DataSourceProvider.getDataSource(ci, 1);
5355

5456
try (Connection con = dataSource.getConnection()) {
55-
Version v = DBHelper.getDatabaseFrameworkVersion( con );
57+
Version v = new DefaultDatabaseInformation().getUtPlsqlFrameworkVersion(con);
5658
System.out.println("utPLSQL " + v.getNormalizedString());
5759
}
5860
catch ( UtPLSQLNotInstalledException e ) {
59-
System.out.println("utPLSQL framework is not installed in database.");
61+
System.out.println(e.getMessage());
6062
}
6163
}
6264
}

0 commit comments

Comments
 (0)