22
33import com .beust .jcommander .Parameter ;
44import com .beust .jcommander .Parameters ;
5- import io .github .utplsql .api .CustomTypes ;
6- import io .github .utplsql .api .OutputBuffer ;
7- import io .github .utplsql .api .TestRunner ;
5+ import io .github .utplsql .api .*;
86import io .github .utplsql .api .exception .SomeTestsFailedException ;
97import io .github .utplsql .api .reporter .Reporter ;
108import io .github .utplsql .api .reporter .ReporterFactory ;
@@ -35,16 +33,15 @@ public class RunCommand {
3533
3634 @ Parameter (
3735 names = {"-p" , "--path" },
38- description = "run suites/tests by path, format: \n " +
36+ description = "run suites/tests by path, format: " +
3937 "-p=[schema|schema:[suite ...][.test]|schema[.suite ...][.test]" )
4038 private List <String > testPaths = new ArrayList <>();
4139
4240 @ Parameter (
4341 names = {"-f" , "--format" },
4442 variableArity = true ,
45- description = "output reporter format: \n " +
46- "enables specified format reporting to specified output file (-o) and to screen (-s)\n " +
47- "-f=reporter_name [-o=output_file [-s]]" )
43+ description = "-f=reporter_name [-o=output_file [-s]] - enables specified format reporting to specified " +
44+ "output file (-o) and to screen (-s)" )
4845 private List <String > reporterParams = new ArrayList <>();
4946
5047 @ Parameter (
@@ -57,11 +54,20 @@ public class RunCommand {
5754 description = "override the exit code on failure, default = 1" )
5855 private int failureExitCode = 1 ;
5956
60- @ Parameter (names = {"-source_path" }, description = "path to project source files" )
61- private String sourcePath ;
57+ @ Parameter (
58+ names = {"-source_path" },
59+ variableArity = true ,
60+ description = "-source_path [-owner=\" owner\" -regex_expression=\" pattern\" " +
61+ "-type_mapping=\" matched_string=TYPE/matched_string=TYPE\" " +
62+ "-owner_subexpression=0 -type_subexpression=0 -name_subexpression=0] - path to project source files" )
63+ private List <String > sourcePathParams = new ArrayList <>();
6264
63- @ Parameter (names = {"-test_path" }, description = "path to project test files" )
64- private String testPath ;
65+ @ Parameter (
66+ names = {"-test_path" },
67+ variableArity = true ,
68+ description = "-test_path [-regex_expression=\" pattern\" -owner_subexpression=0 -type_subexpression=0 " +
69+ "-name_subexpression=0] - path to project test files" )
70+ private List <String > testPathParams = new ArrayList <>();
6571
6672 public ConnectionInfo getConnectionInfo () {
6773 return connectionInfoList .get (0 );
@@ -71,33 +77,6 @@ public List<String> getTestPaths() {
7177 return testPaths ;
7278 }
7379
74- public List <ReporterOptions > getReporterOptionsList () {
75- List <ReporterOptions > reporterOptionsList = new ArrayList <>();
76- ReporterOptions reporterOptions = null ;
77-
78- for (String p : reporterParams ) {
79- if (reporterOptions == null || !p .startsWith ("-" )) {
80- reporterOptions = new ReporterOptions (p );
81- reporterOptionsList .add (reporterOptions );
82- }
83- else
84- if (p .startsWith ("-o=" )) {
85- reporterOptions .setOutputFileName (p .substring (3 ));
86- }
87- else
88- if (p .equals ("-s" )) {
89- reporterOptions .forceOutputToScreen (true );
90- }
91- }
92-
93- // If no reporter parameters were passed, use default reporter.
94- if (reporterOptionsList .isEmpty ()) {
95- reporterOptionsList .add (new ReporterOptions (CustomTypes .UT_DOCUMENTATION_REPORTER ));
96- }
97-
98- return reporterOptionsList ;
99- }
100-
10180 public int run () throws Exception {
10281 final ConnectionInfo ci = getConnectionInfo ();
10382
@@ -106,18 +85,22 @@ public int run() throws Exception {
10685 final List <Reporter > reporterList = new ArrayList <>();
10786
10887 final File baseDir = new File ("" ).getAbsoluteFile ();
109- List < String > sourceFilesTmp = null ;
110- List < String > testFilesTmp = null ;
88+ final FileMapperOptions [] sourceMappingOptions = { null } ;
89+ final FileMapperOptions [] testMappingOptions = { null } ;
11190
112- if (this .sourcePath != null )
113- sourceFilesTmp = new FileWalker ().getFileList (baseDir , this .sourcePath );
91+ final int [] returnCode = {0 };
11492
115- if (this .testPath != null )
116- testFilesTmp = new FileWalker ().getFileList (baseDir , this .testPath );
93+ if (!this .sourcePathParams .isEmpty ()) {
94+ String sourcePath = this .sourcePathParams .get (0 );
95+ List <String > sourceFiles = new FileWalker ().getFileList (baseDir , sourcePath );
96+ sourceMappingOptions [0 ] = getMapperOptions (this .sourcePathParams , sourceFiles );
97+ }
11798
118- final List <String > sourceFiles = sourceFilesTmp ;
119- final List <String > testFiles = testFilesTmp ;
120- final int [] returnCode = {0 };
99+ if (!this .testPathParams .isEmpty ()) {
100+ String testPath = this .testPathParams .get (0 );
101+ List <String > testFiles = new FileWalker ().getFileList (baseDir , testPath );
102+ testMappingOptions [0 ] = getMapperOptions (this .testPathParams , testFiles );
103+ }
121104
122105 if (testPaths .isEmpty ()) testPaths .add (ci .getUser ());
123106
@@ -142,8 +125,8 @@ public int run() throws Exception {
142125 new TestRunner ()
143126 .addPathList (testPaths )
144127 .addReporterList (reporterList )
145- .withSourceFiles ( sourceFiles )
146- .withTestFiles ( testFiles )
128+ .sourceMappingOptions ( sourceMappingOptions [ 0 ] )
129+ .testMappingOptions ( testMappingOptions [ 0 ] )
147130 .colorConsole (this .colorConsole )
148131 .failOnErrors (true )
149132 .run (conn );
@@ -187,4 +170,74 @@ public int run() throws Exception {
187170 return returnCode [0 ];
188171 }
189172
173+ public List <ReporterOptions > getReporterOptionsList () {
174+ List <ReporterOptions > reporterOptionsList = new ArrayList <>();
175+ ReporterOptions reporterOptions = null ;
176+
177+ for (String p : reporterParams ) {
178+ if (reporterOptions == null || !p .startsWith ("-" )) {
179+ reporterOptions = new ReporterOptions (p );
180+ reporterOptionsList .add (reporterOptions );
181+ }
182+ else
183+ if (p .startsWith ("-o=" )) {
184+ reporterOptions .setOutputFileName (p .substring (3 ));
185+ }
186+ else
187+ if (p .equals ("-s" )) {
188+ reporterOptions .forceOutputToScreen (true );
189+ }
190+ }
191+
192+ // If no reporter parameters were passed, use default reporter.
193+ if (reporterOptionsList .isEmpty ()) {
194+ reporterOptionsList .add (new ReporterOptions (CustomTypes .UT_DOCUMENTATION_REPORTER ));
195+ }
196+
197+ return reporterOptionsList ;
198+ }
199+
200+ public FileMapperOptions getMapperOptions (List <String > mappingParams , List <String > filePaths ) {
201+ FileMapperOptions mapperOptions = new FileMapperOptions (filePaths );
202+
203+ for (String p : mappingParams ) {
204+ if (p .startsWith ("-object_owner=" )) {
205+ mapperOptions .setObjectOwner (p .substring ("-object_owner=" .length ()));
206+ }
207+ else
208+ if (p .startsWith ("-regex_pattern=" )) {
209+ mapperOptions .setRegexPattern (p .substring ("-regex_pattern=" .length ()));
210+ }
211+ else
212+ if (p .startsWith ("-type_mapping=" )) {
213+ String typeMappingsParam = p .substring ("-type_mapping=" .length ());
214+
215+ List <KeyValuePair > typeMappings = new ArrayList <>();
216+ for (String mapping : typeMappingsParam .split ("/" )) {
217+ String [] values = mapping .split ("=" );
218+ typeMappings .add (new KeyValuePair (values [0 ], values [1 ]));
219+ }
220+
221+ mapperOptions .setTypeMappings (typeMappings );
222+ }
223+ else
224+ if (p .startsWith ("-owner_subexpression=" )) {
225+ mapperOptions .setOwnerSubExpression (Integer .parseInt (p .substring ("-owner_subexpression=" .length ())));
226+ }
227+ else
228+ if (p .startsWith ("-name_subexpression=" )) {
229+ mapperOptions .setNameSubExpression (Integer .parseInt (p .substring ("-name_subexpression=" .length ())));
230+ }
231+ else
232+ if (p .startsWith ("-type_subexpression=" )) {
233+ mapperOptions .setTypeSubExpression (Integer .parseInt (p .substring ("-type_subexpression=" .length ())));
234+ }
235+ }
236+
237+ if (mapperOptions .getRegexPattern () == null || mapperOptions .getRegexPattern ().isEmpty ())
238+ return null ;
239+ else
240+ return mapperOptions ;
241+ }
242+
190243}
0 commit comments