2
2
3
3
import com .beust .jcommander .Parameter ;
4
4
import com .beust .jcommander .Parameters ;
5
- import org .utplsql .api .FileMapperOptions ;
6
- import org .utplsql .api .KeyValuePair ;
7
- import org .utplsql .api .TestRunner ;
8
- import org .utplsql .api .Version ;
5
+ import org .slf4j .Logger ;
6
+ import org .slf4j .LoggerFactory ;
7
+ import org .utplsql .api .*;
9
8
import org .utplsql .api .compatibility .CompatibilityProxy ;
9
+ import org .utplsql .api .db .DefaultDatabaseInformation ;
10
10
import org .utplsql .api .exception .DatabaseNotCompatibleException ;
11
11
import org .utplsql .api .exception .SomeTestsFailedException ;
12
12
import org .utplsql .api .exception .UtPLSQLNotInstalledException ;
13
13
import org .utplsql .api .reporter .Reporter ;
14
14
import org .utplsql .api .reporter .ReporterFactory ;
15
15
import org .utplsql .cli .exception .DatabaseConnectionFailed ;
16
+ import org .utplsql .cli .log .StringBlockFormatter ;
16
17
17
18
import javax .sql .DataSource ;
18
19
import java .io .File ;
34
35
@ Parameters (separators = "=" , commandDescription = "run tests" )
35
36
public class RunCommand implements ICommand {
36
37
38
+ private static final Logger logger = LoggerFactory .getLogger (RunCommand .class );
39
+
37
40
@ Parameter (
38
41
required = true ,
39
42
converter = ConnectionInfo .ConnectionStringConverter .class ,
@@ -99,6 +102,15 @@ public class RunCommand implements ICommand {
99
102
)
100
103
private String excludeObjects = null ;
101
104
105
+ @ Parameter (
106
+ names = {"-q" , "--quiet" },
107
+ description = "Does not output the informational messages normally printed to console" )
108
+ private boolean logSilent = false ;
109
+
110
+ @ Parameter (
111
+ names = {"-d" , "--debug" },
112
+ description = "Outputs a load of debug information to console" )
113
+ private boolean logDebug = false ;
102
114
103
115
private CompatibilityProxy compatibilityProxy ;
104
116
private ReporterFactory reporterFactory ;
@@ -112,7 +124,22 @@ public List<String> getTestPaths() {
112
124
return testPaths ;
113
125
}
114
126
127
+ void init () {
128
+
129
+ LoggerConfiguration .ConfigLevel level = LoggerConfiguration .ConfigLevel .BASIC ;
130
+ if ( logSilent ) {
131
+ level = LoggerConfiguration .ConfigLevel .NONE ;
132
+ }
133
+ else if ( logDebug ) {
134
+ level = LoggerConfiguration .ConfigLevel .DEBUG ;
135
+ }
136
+
137
+ LoggerConfiguration .configure (level );
138
+ }
139
+
115
140
public int run () {
141
+ init ();
142
+ outputMainInformation ();
116
143
117
144
try {
118
145
@@ -148,25 +175,8 @@ public int run() {
148
175
149
176
final DataSource dataSource = DataSourceProvider .getDataSource (getConnectionInfo (), getReporterManager ().getNumberOfReporters () + 1 );
150
177
151
- // Do the reporters initialization, so we can use the id to run and gather results.
152
- try (Connection conn = dataSource .getConnection ()) {
153
-
154
- // Check if orai18n exists if database version is 11g
155
- RunCommandChecker .checkOracleI18nExists (conn );
156
-
157
- // First of all do a compatibility check and fail-fast
158
- compatibilityProxy = checkFrameworkCompatibility (conn );
159
- reporterFactory = ReporterFactoryProvider .createReporterFactory (compatibilityProxy );
160
-
161
- reporterList = getReporterManager ().initReporters (conn , reporterFactory , compatibilityProxy );
162
-
163
- } catch (SQLException e ) {
164
- if (e .getErrorCode () == 1017 || e .getErrorCode () == 12514 ) {
165
- throw new DatabaseConnectionFailed (e );
166
- } else {
167
- throw e ;
168
- }
169
- }
178
+ initDatabase (dataSource );
179
+ reporterList = initReporters (dataSource );
170
180
171
181
// Output a message if --failureExitCode is set but database framework is not capable of
172
182
String msg = RunCommandChecker .getCheckFailOnErrorMessage (failureExitCode , compatibilityProxy .getDatabaseVersion ());
@@ -190,6 +200,8 @@ public int run() {
190
200
.includeObjects (finalIncludeObjectsList )
191
201
.excludeObjects (finalExcludeObjectsList );
192
202
203
+ logger .info ("Running tests now." );
204
+ logger .info ("--------------------------------------" );
193
205
testRunner .run (conn );
194
206
} catch (SomeTestsFailedException e ) {
195
207
returnCode [0 ] = this .failureExitCode ;
@@ -205,6 +217,10 @@ public int run() {
205
217
206
218
executorService .shutdown ();
207
219
executorService .awaitTermination (60 , TimeUnit .MINUTES );
220
+
221
+ logger .info ("--------------------------------------" );
222
+ logger .info ("All tests done." );
223
+
208
224
return returnCode [0 ];
209
225
}
210
226
catch ( DatabaseNotCompatibleException | UtPLSQLNotInstalledException | DatabaseConnectionFailed e ) {
@@ -221,6 +237,49 @@ public String getCommand() {
221
237
}
222
238
223
239
240
+ private void outputMainInformation () {
241
+
242
+ StringBlockFormatter formatter = new StringBlockFormatter ("utPLCSL cli" );
243
+ formatter .appendLine (CliVersionInfo .getInfo ());
244
+ formatter .appendLine (JavaApiVersionInfo .getInfo ());
245
+ formatter .appendLine ("Java-Version: " + System .getProperty ("java.version" ));
246
+ formatter .appendLine ("ORACLE_HOME: " + EnvironmentVariableUtil .getEnvValue ("ORACLE_HOME" ));
247
+ formatter .appendLine ("NLS_LANG: " + EnvironmentVariableUtil .getEnvValue ("NLS_LANG" ));
248
+ formatter .appendLine ("" );
249
+ formatter .appendLine ("Thanks for testing!" );
250
+
251
+ logger .info (formatter .toString ());
252
+ logger .info ("" );
253
+ }
254
+
255
+ private void initDatabase (DataSource dataSource ) throws SQLException {
256
+ try (Connection conn = dataSource .getConnection ()) {
257
+
258
+ // Check if orai18n exists if database version is 11g
259
+ RunCommandChecker .checkOracleI18nExists (conn );
260
+
261
+ // First of all do a compatibility check and fail-fast
262
+ compatibilityProxy = checkFrameworkCompatibility (conn );
263
+
264
+ logger .info ("Successfully connected to database. UtPLSQL core: {}" , compatibilityProxy .getDatabaseVersion ());
265
+ logger .info ("Oracle-Version: {}" , new DefaultDatabaseInformation ().getOracleVersion (conn ));
266
+ }
267
+ catch (SQLException e ) {
268
+ if (e .getErrorCode () == 1017 || e .getErrorCode () == 12514 ) {
269
+ throw new DatabaseConnectionFailed (e );
270
+ } else {
271
+ throw e ;
272
+ }
273
+ }
274
+ }
275
+
276
+ private List <Reporter > initReporters (DataSource dataSource ) throws SQLException {
277
+ try (Connection conn = dataSource .getConnection ()) {
278
+ reporterFactory = ReporterFactoryProvider .createReporterFactory (compatibilityProxy );
279
+ return getReporterManager ().initReporters (conn , reporterFactory , compatibilityProxy );
280
+ }
281
+ }
282
+
224
283
/** Returns FileMapperOptions for the first item of a given param list in a baseDir
225
284
*
226
285
* @param pathParams
0 commit comments