3
3
import com .beust .jcommander .Parameter ;
4
4
import com .beust .jcommander .Parameters ;
5
5
import org .utplsql .api .*;
6
+ import org .utplsql .api .exception .DatabaseNotCompatibleException ;
6
7
import org .utplsql .api .exception .SomeTestsFailedException ;
7
8
import org .utplsql .api .reporter .Reporter ;
8
9
import org .utplsql .api .reporter .ReporterFactory ;
21
22
22
23
/**
23
24
* Created by vinicius.moreira on 19/04/2017.
25
+ *
26
+ * @author vinicious moreira
27
+ * @author pesse
24
28
*/
25
29
@ Parameters (separators = "=" , commandDescription = "run tests" )
26
30
public class RunCommand {
@@ -70,6 +74,12 @@ public class RunCommand {
70
74
"-name_subexpression=0] - path to project test files" )
71
75
private List <String > testPathParams = new ArrayList <>();
72
76
77
+ @ Parameter (
78
+ names = {"-scc" , "--skip-compatibility-check" },
79
+ description = "Skips the check for compatibility with database framework. CLI expects the framework to be " +
80
+ "most actual. Use this if you use CLI with a development version of utPLSQL-framework" )
81
+ private boolean skipCompatibilityCheck = false ;
82
+
73
83
public ConnectionInfo getConnectionInfo () {
74
84
return connectionInfoList .get (0 );
75
85
}
@@ -81,36 +91,27 @@ public List<String> getTestPaths() {
81
91
public int run () throws Exception {
82
92
final ConnectionInfo ci = getConnectionInfo ();
83
93
94
+ final List <Reporter > reporterList ;
84
95
final List <ReporterOptions > reporterOptionsList = getReporterOptionsList ();
85
96
final List <String > testPaths = getTestPaths ();
86
- final List <Reporter > reporterList = new ArrayList <>();
87
97
88
98
final File baseDir = new File ("" ).getAbsoluteFile ();
89
99
final FileMapperOptions [] sourceMappingOptions = {null };
90
100
final FileMapperOptions [] testMappingOptions = {null };
91
101
92
102
final int [] returnCode = {0 };
93
103
94
- if (!this .sourcePathParams .isEmpty ()) {
95
- String sourcePath = this .sourcePathParams .get (0 );
96
- List <String > sourceFiles = new FileWalker ().getFileList (baseDir , sourcePath );
97
- sourceMappingOptions [0 ] = getMapperOptions (this .sourcePathParams , sourceFiles );
98
- }
99
-
100
- if (!this .testPathParams .isEmpty ()) {
101
- String testPath = this .testPathParams .get (0 );
102
- List <String > testFiles = new FileWalker ().getFileList (baseDir , testPath );
103
- testMappingOptions [0 ] = getMapperOptions (this .testPathParams , testFiles );
104
- }
104
+ sourceMappingOptions [0 ] = getFileMapperOptionsByParamListItem (this .sourcePathParams , baseDir );
105
+ testMappingOptions [0 ] = getFileMapperOptionsByParamListItem (this .testPathParams , baseDir );
105
106
106
107
// Do the reporters initialization, so we can use the id to run and gather results.
107
108
try (Connection conn = ci .getConnection ()) {
108
- for ( ReporterOptions ro : reporterOptionsList ) {
109
- Reporter reporter = ReporterFactory . createReporter ( ro . getReporterName ());
110
- reporter . init (conn );
111
- ro . setReporterObj ( reporter );
112
- reporterList . add ( reporter );
113
- }
109
+
110
+ // First of all do a compatibility check and fail-fast
111
+ checkFrameworkCompatibility (conn );
112
+
113
+ reporterList = initReporters ( conn , reporterOptionsList );
114
+
114
115
} catch (SQLException e ) {
115
116
System .out .println (e .getMessage ());
116
117
return Cli .DEFAULT_ERROR_CODE ;
@@ -128,6 +129,7 @@ public int run() throws Exception {
128
129
.testMappingOptions (testMappingOptions [0 ])
129
130
.colorConsole (this .colorConsole )
130
131
.failOnErrors (true )
132
+ .skipCompatibilityCheck (skipCompatibilityCheck )
131
133
.run (conn );
132
134
} catch (SomeTestsFailedException e ) {
133
135
returnCode [0 ] = this .failureExitCode ;
@@ -138,6 +140,44 @@ public int run() throws Exception {
138
140
}
139
141
});
140
142
143
+ // Gather each reporter results on a separate thread.
144
+ startReporterGatherers (reporterOptionsList , executorService , ci , returnCode );
145
+
146
+ executorService .shutdown ();
147
+ executorService .awaitTermination (60 , TimeUnit .MINUTES );
148
+ return returnCode [0 ];
149
+ }
150
+
151
+ /** Initializes the reporters so we can use the id to gather results
152
+ *
153
+ * @param conn Active Connection
154
+ * @param reporterOptionsList
155
+ * @return List of Reporters
156
+ * @throws SQLException
157
+ */
158
+ private List <Reporter > initReporters ( Connection conn , List <ReporterOptions > reporterOptionsList ) throws SQLException
159
+ {
160
+ final List <Reporter > reporterList = new ArrayList <>();
161
+
162
+ for (ReporterOptions ro : reporterOptionsList ) {
163
+ Reporter reporter = ReporterFactory .createReporter (ro .getReporterName ());
164
+ reporter .init (conn );
165
+ ro .setReporterObj (reporter );
166
+ reporterList .add (reporter );
167
+ }
168
+
169
+ return reporterList ;
170
+ }
171
+
172
+ /** Starts a separate thread for each Reporter to gather its results
173
+ *
174
+ * @param reporterOptionsList
175
+ * @param executorService
176
+ * @param ci
177
+ * @param returnCode
178
+ */
179
+ private void startReporterGatherers (List <ReporterOptions > reporterOptionsList , ExecutorService executorService , final ConnectionInfo ci , final int [] returnCode )
180
+ {
141
181
// Gather each reporter results on a separate thread.
142
182
for (ReporterOptions ro : reporterOptionsList ) {
143
183
executorService .submit (() -> {
@@ -165,10 +205,23 @@ public int run() throws Exception {
165
205
}
166
206
});
167
207
}
208
+ }
168
209
169
- executorService .shutdown ();
170
- executorService .awaitTermination (60 , TimeUnit .MINUTES );
171
- return returnCode [0 ];
210
+ /** Returns FileMapperOptions for the first item of a given param list in a baseDir
211
+ *
212
+ * @param pathParams
213
+ * @param baseDir
214
+ * @return FileMapperOptions or null
215
+ */
216
+ private FileMapperOptions getFileMapperOptionsByParamListItem (List <String > pathParams , File baseDir )
217
+ {
218
+ if (!pathParams .isEmpty ()) {
219
+ String sourcePath = pathParams .get (0 );
220
+ List <String > files = new FileWalker ().getFileList (baseDir , sourcePath );
221
+ return getMapperOptions (pathParams , files );
222
+ }
223
+
224
+ return null ;
172
225
}
173
226
174
227
public List <ReporterOptions > getReporterOptionsList () {
@@ -198,6 +251,28 @@ public List<ReporterOptions> getReporterOptionsList() {
198
251
return reporterOptionsList ;
199
252
}
200
253
254
+ /** Checks whether cli is compatible with the database framework
255
+ *
256
+ * @param conn Active Connection
257
+ * @throws SQLException
258
+ */
259
+ private void checkFrameworkCompatibility (Connection conn ) throws SQLException {
260
+
261
+ if ( !skipCompatibilityCheck ) {
262
+ try {
263
+ DBHelper .failOnVersionCompatibilityCheckFailed (conn );
264
+ } catch (DatabaseNotCompatibleException e ) {
265
+ System .out .println (e .getMessage ());
266
+
267
+ throw e ;
268
+ }
269
+ }
270
+ else {
271
+ System .out .println ("Skipping Compatibility check with framework version, expecting the latest version " +
272
+ "to be installed in database" );
273
+ }
274
+ }
275
+
201
276
public FileMapperOptions getMapperOptions (List <String > mappingParams , List <String > filePaths ) {
202
277
FileMapperOptions mapperOptions = new FileMapperOptions (filePaths );
203
278
0 commit comments