Skip to content

Commit 80ee1f0

Browse files
committed
Custom file mapping support
1 parent 1b93beb commit 80ee1f0

File tree

2 files changed

+119
-44
lines changed

2 files changed

+119
-44
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,25 @@ db - Database to connect to.
5555
Generates a JSON report providing detailed information on test execution.
5656
Designed for [SonarQube](https://about.sonarqube.com/) to report test execution.
5757
58-
-o=output - Defines file name to save the output from the specified reporter.
58+
-o=output - Defines file name to save the output from the specified reporter.
5959
If defined, the output is not displayed on screen by default. This can be changed with the -s parameter.
6060
If not defined, then output will be displayed on screen, even if the parameter -s is not specified.
6161
If more than one -o parameter is specified for one -f parameter, the last one is taken into consideration.
62-
-s - Forces putting output to to screen for a given -f parameter.
62+
-s - Forces putting output to to screen for a given -f parameter.
63+
-source_path=source - path to project source files, use the following options to enable custom type mappings:
64+
-owner="app"
65+
-regex_expression="pattern"
66+
-type_mapping="matched_string=TYPE[/matched_string=TYPE]*"
67+
-owner_subexpression=subexpression_number
68+
-type_subexpression=subexpression_number
69+
-name_subexpression=subexpression_number
70+
-test_path=test - path to project test files, use the following options to enable custom type mappings:
71+
-owner="app"
72+
-regex_expression="pattern"
73+
-type_mapping="matched_string=TYPE[/matched_string=TYPE]*"
74+
-owner_subexpression=subexpression_number
75+
-type_subexpression=subexpression_number
76+
-name_subexpression=subexpression_number
6377
-c - If specified, enables printing of test results in colors as defined by ANSICONSOLE standards.
6478
Works only on reporeters that support colors (ut_documentation_reporter).
6579
--failure-exit-code - Override the exit code on failure, defaults to 1. You can set it to 0 to always exit with a success status.

src/main/java/io/github/utplsql/cli/RunCommand.java

Lines changed: 103 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import com.beust.jcommander.Parameter;
44
import 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.*;
86
import io.github.utplsql.api.exception.SomeTestsFailedException;
97
import io.github.utplsql.api.reporter.Reporter;
108
import 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

@@ -108,15 +87,25 @@ public int run() throws Exception {
10887
final File baseDir = new File("").getAbsoluteFile();
10988
List<String> sourceFilesTmp = null;
11089
List<String> testFilesTmp = null;
90+
FileMapperOptions sourceMappingOptionsTmp= null;
91+
FileMapperOptions testMappingOptionsTmp = null;
11192

112-
if (this.sourcePath != null)
113-
sourceFilesTmp = new FileWalker().getFileList(baseDir, this.sourcePath);
93+
if (!this.sourcePathParams.isEmpty()) {
94+
String sourcePath = this.sourcePathParams.get(0);
95+
sourceFilesTmp = new FileWalker().getFileList(baseDir, sourcePath);
96+
sourceMappingOptionsTmp = getMapperOptions(this.sourcePathParams);
97+
}
11498

115-
if (this.testPath != null)
116-
testFilesTmp = new FileWalker().getFileList(baseDir, this.testPath);
99+
if (!this.testPathParams.isEmpty()) {
100+
String testPath = this.testPathParams.get(0);
101+
testFilesTmp = new FileWalker().getFileList(baseDir, testPath);
102+
testMappingOptionsTmp = getMapperOptions(this.testPathParams);
103+
}
117104

118105
final List<String> sourceFiles = sourceFilesTmp;
119106
final List<String> testFiles = testFilesTmp;
107+
final FileMapperOptions sourceMappingOptions = sourceMappingOptionsTmp;
108+
final FileMapperOptions testMappingOptions = testMappingOptionsTmp;
120109
final int[] returnCode = {0};
121110

122111
if (testPaths.isEmpty()) testPaths.add(ci.getUser());
@@ -143,7 +132,9 @@ public int run() throws Exception {
143132
.addPathList(testPaths)
144133
.addReporterList(reporterList)
145134
.withSourceFiles(sourceFiles)
135+
.sourceMappingOptions(sourceMappingOptions)
146136
.withTestFiles(testFiles)
137+
.testMappingOptions(testMappingOptions)
147138
.colorConsole(this.colorConsole)
148139
.failOnErrors(true)
149140
.run(conn);
@@ -187,4 +178,74 @@ public int run() throws Exception {
187178
return returnCode[0];
188179
}
189180

181+
public List<ReporterOptions> getReporterOptionsList() {
182+
List<ReporterOptions> reporterOptionsList = new ArrayList<>();
183+
ReporterOptions reporterOptions = null;
184+
185+
for (String p : reporterParams) {
186+
if (reporterOptions == null || !p.startsWith("-")) {
187+
reporterOptions = new ReporterOptions(p);
188+
reporterOptionsList.add(reporterOptions);
189+
}
190+
else
191+
if (p.startsWith("-o=")) {
192+
reporterOptions.setOutputFileName(p.substring(3));
193+
}
194+
else
195+
if (p.equals("-s")) {
196+
reporterOptions.forceOutputToScreen(true);
197+
}
198+
}
199+
200+
// If no reporter parameters were passed, use default reporter.
201+
if (reporterOptionsList.isEmpty()) {
202+
reporterOptionsList.add(new ReporterOptions(CustomTypes.UT_DOCUMENTATION_REPORTER));
203+
}
204+
205+
return reporterOptionsList;
206+
}
207+
208+
public FileMapperOptions getMapperOptions(List<String> mappingParams) {
209+
FileMapperOptions mapperOptions = new FileMapperOptions();
210+
211+
for (String p : mappingParams) {
212+
if (p.startsWith("-object_owner=")) {
213+
mapperOptions.setObjectOwner(p.substring("-object_owner=".length()));
214+
}
215+
else
216+
if (p.startsWith("-regex_pattern=")) {
217+
mapperOptions.setRegexPattern(p.substring("-regex_pattern=".length()));
218+
}
219+
else
220+
if (p.startsWith("-type_mapping=")) {
221+
String typeMappingsParam = p.substring("-type_mapping=".length());
222+
223+
List<KeyValuePair> typeMappings = new ArrayList<>();
224+
for (String mapping : typeMappingsParam.split("/")) {
225+
String[] values = mapping.split("=");
226+
typeMappings.add(new KeyValuePair(values[0], values[1]));
227+
}
228+
229+
mapperOptions.setTypeMappings(typeMappings);
230+
}
231+
else
232+
if (p.startsWith("-owner_subexpression=")) {
233+
mapperOptions.setOwnerSubExpression(Integer.parseInt(p.substring("-owner_subexpression=".length())));
234+
}
235+
else
236+
if (p.startsWith("-name_subexpression=")) {
237+
mapperOptions.setNameSubExpression(Integer.parseInt(p.substring("-name_subexpression=".length())));
238+
}
239+
else
240+
if (p.startsWith("-type_subexpression=")) {
241+
mapperOptions.setTypeSubExpression(Integer.parseInt(p.substring("-type_subexpression=".length())));
242+
}
243+
}
244+
245+
if (mapperOptions.getRegexPattern() == null || mapperOptions.getRegexPattern().isEmpty())
246+
return null;
247+
else
248+
return mapperOptions;
249+
}
250+
190251
}

0 commit comments

Comments
 (0)