@@ -91,41 +91,27 @@ public List<String> getTestPaths() {
9191 public int run () throws Exception {
9292 final ConnectionInfo ci = getConnectionInfo ();
9393
94-
94+ final List < Reporter > reporterList ;
9595 final List <ReporterOptions > reporterOptionsList = getReporterOptionsList ();
9696 final List <String > testPaths = getTestPaths ();
97- final List <Reporter > reporterList = new ArrayList <>();
9897
9998 final File baseDir = new File ("" ).getAbsoluteFile ();
10099 final FileMapperOptions [] sourceMappingOptions = {null };
101100 final FileMapperOptions [] testMappingOptions = {null };
102101
103102 final int [] returnCode = {0 };
104103
105- if (!this .sourcePathParams .isEmpty ()) {
106- String sourcePath = this .sourcePathParams .get (0 );
107- List <String > sourceFiles = new FileWalker ().getFileList (baseDir , sourcePath );
108- sourceMappingOptions [0 ] = getMapperOptions (this .sourcePathParams , sourceFiles );
109- }
110-
111- if (!this .testPathParams .isEmpty ()) {
112- String testPath = this .testPathParams .get (0 );
113- List <String > testFiles = new FileWalker ().getFileList (baseDir , testPath );
114- testMappingOptions [0 ] = getMapperOptions (this .testPathParams , testFiles );
115- }
104+ sourceMappingOptions [0 ] = getFileMapperOptionsByParamListItem (this .sourcePathParams , baseDir );
105+ testMappingOptions [0 ] = getFileMapperOptionsByParamListItem (this .testPathParams , baseDir );
116106
117107 // Do the reporters initialization, so we can use the id to run and gather results.
118108 try (Connection conn = ci .getConnection ()) {
119109
120110 // First of all do a compatibility check and fail-fast
121111 checkFrameworkCompatibility (conn );
122112
123- for (ReporterOptions ro : reporterOptionsList ) {
124- Reporter reporter = ReporterFactory .createReporter (ro .getReporterName ());
125- reporter .init (conn );
126- ro .setReporterObj (reporter );
127- reporterList .add (reporter );
128- }
113+ reporterList = initReporters (conn , reporterOptionsList );
114+
129115 } catch (SQLException e ) {
130116 System .out .println (e .getMessage ());
131117 return Cli .DEFAULT_ERROR_CODE ;
@@ -154,6 +140,44 @@ public int run() throws Exception {
154140 }
155141 });
156142
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+ {
157181 // Gather each reporter results on a separate thread.
158182 for (ReporterOptions ro : reporterOptionsList ) {
159183 executorService .submit (() -> {
@@ -181,10 +205,23 @@ public int run() throws Exception {
181205 }
182206 });
183207 }
208+ }
184209
185- executorService .shutdown ();
186- executorService .awaitTermination (60 , TimeUnit .MINUTES );
187- 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 ;
188225 }
189226
190227 public List <ReporterOptions > getReporterOptionsList () {
0 commit comments