2
2
3
3
import com .beust .jcommander .Parameter ;
4
4
import com .beust .jcommander .Parameters ;
5
+ import org .utplsql .api .exception .DatabaseNotCompatibleException ;
6
+ import org .utplsql .api .exception .UtPLSQLNotInstalledException ;
5
7
import org .utplsql .api .reporter .ReporterFactory ;
6
8
import org .utplsql .api .reporter .inspect .ReporterInfo ;
7
9
import org .utplsql .api .reporter .inspect .ReporterInspector ;
10
+ import org .utplsql .cli .exception .DatabaseConnectionFailed ;
8
11
9
12
import javax .sql .DataSource ;
10
13
import java .io .PrintStream ;
@@ -21,9 +24,11 @@ public class ReportersCommand implements ICommand {
21
24
private List <ConnectionInfo > connectionInfoList = new ArrayList <>();
22
25
23
26
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" );
27
32
28
33
return connectionInfoList .get (0 );
29
34
}
@@ -39,7 +44,11 @@ public int run() {
39
44
40
45
writeReporters (ReporterInspector .create (reporterFactory , con ).getReporterInfos (), System .out );
41
46
}
42
- } catch (Exception e ) {
47
+ }
48
+ catch ( DatabaseNotCompatibleException | UtPLSQLNotInstalledException | DatabaseConnectionFailed | IllegalArgumentException e ) {
49
+ System .out .println (e .getMessage ());
50
+ }
51
+ catch (Exception e ) {
43
52
e .printStackTrace ();
44
53
return 1 ;
45
54
}
@@ -52,15 +61,7 @@ public String getCommand() {
52
61
return "reporters" ;
53
62
}
54
63
55
- private int getMaxNameLength (List <ReporterInfo > reporterInfos ) {
56
- return reporterInfos .stream ()
57
- .mapToInt (info -> info .getName ().length ())
58
- .max ()
59
- .orElse (0 );
60
- }
61
-
62
64
private void writeReporters (List <ReporterInfo > reporterInfos , PrintStream out ) {
63
- //int padding = getMaxNameLength(reporterInfos)+1;
64
65
reporterInfos .stream ()
65
66
.sorted (Comparator .comparing (ReporterInfo ::getName ))
66
67
.forEach (info -> writeReporter (info , 4 , out ));
0 commit comments