22
33import com .beust .jcommander .Parameter ;
44import 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 .*;
98import org .utplsql .api .compatibility .CompatibilityProxy ;
9+ import org .utplsql .api .db .DefaultDatabaseInformation ;
1010import org .utplsql .api .exception .DatabaseNotCompatibleException ;
1111import org .utplsql .api .exception .SomeTestsFailedException ;
1212import org .utplsql .api .exception .UtPLSQLNotInstalledException ;
1313import org .utplsql .api .reporter .Reporter ;
1414import org .utplsql .api .reporter .ReporterFactory ;
1515import org .utplsql .cli .exception .DatabaseConnectionFailed ;
16+ import org .utplsql .cli .log .StringBlockFormatter ;
1617
1718import javax .sql .DataSource ;
1819import java .io .File ;
3435@ Parameters (separators = "=" , commandDescription = "run tests" )
3536public class RunCommand implements ICommand {
3637
38+ private static final Logger logger = LoggerFactory .getLogger (RunCommand .class );
39+
3740 @ Parameter (
3841 required = true ,
3942 converter = ConnectionInfo .ConnectionStringConverter .class ,
@@ -99,6 +102,15 @@ public class RunCommand implements ICommand {
99102 )
100103 private String excludeObjects = null ;
101104
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 ;
102114
103115 private CompatibilityProxy compatibilityProxy ;
104116 private ReporterFactory reporterFactory ;
@@ -112,7 +124,22 @@ public List<String> getTestPaths() {
112124 return testPaths ;
113125 }
114126
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+
115140 public int run () {
141+ init ();
142+ outputMainInformation ();
116143
117144 try {
118145
@@ -148,25 +175,8 @@ public int run() {
148175
149176 final DataSource dataSource = DataSourceProvider .getDataSource (getConnectionInfo (), getReporterManager ().getNumberOfReporters () + 1 );
150177
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 );
170180
171181 // Output a message if --failureExitCode is set but database framework is not capable of
172182 String msg = RunCommandChecker .getCheckFailOnErrorMessage (failureExitCode , compatibilityProxy .getDatabaseVersion ());
@@ -190,6 +200,8 @@ public int run() {
190200 .includeObjects (finalIncludeObjectsList )
191201 .excludeObjects (finalExcludeObjectsList );
192202
203+ logger .info ("Running tests now." );
204+ logger .info ("--------------------------------------" );
193205 testRunner .run (conn );
194206 } catch (SomeTestsFailedException e ) {
195207 returnCode [0 ] = this .failureExitCode ;
@@ -205,6 +217,10 @@ public int run() {
205217
206218 executorService .shutdown ();
207219 executorService .awaitTermination (60 , TimeUnit .MINUTES );
220+
221+ logger .info ("--------------------------------------" );
222+ logger .info ("All tests done." );
223+
208224 return returnCode [0 ];
209225 }
210226 catch ( DatabaseNotCompatibleException | UtPLSQLNotInstalledException | DatabaseConnectionFailed e ) {
@@ -221,6 +237,49 @@ public String getCommand() {
221237 }
222238
223239
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+
224283 /** Returns FileMapperOptions for the first item of a given param list in a baseDir
225284 *
226285 * @param pathParams
0 commit comments