Skip to content

Commit 2ec1d50

Browse files
committed
Clean up
1 parent fbb4e58 commit 2ec1d50

28 files changed

Lines changed: 78 additions & 75 deletions

File tree

src/main/java/org/utplsql/maven/plugin/model/ReporterParameter.java renamed to src/main/java/org/utplsql/maven/plugin/ReporterParameter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utplsql.maven.plugin.model;
1+
package org.utplsql.maven.plugin;
22

33
import org.codehaus.plexus.util.StringUtils;
44

‎src/main/java/org/utplsql/maven/plugin/UtPLSQLMojo.java‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
import org.utplsql.api.reporter.ReporterFactory;
2626
import org.utplsql.maven.plugin.helper.PluginDefault;
2727
import org.utplsql.maven.plugin.helper.SqlScannerHelper;
28-
import org.utplsql.maven.plugin.model.ReporterParameter;
29-
import org.utplsql.maven.plugin.reporter.ReporterWriter;
28+
import org.utplsql.maven.plugin.reporter.ReportWriter;
3029

3130
import java.io.File;
3231
import java.sql.Connection;
@@ -35,6 +34,7 @@
3534
import java.util.LinkedHashSet;
3635
import java.util.List;
3736
import java.util.Set;
37+
import java.util.stream.Collectors;
3838

3939
/**
4040
* This class expose the {@link TestRunner} interface to Maven.
@@ -147,7 +147,7 @@ public class UtPLSQLMojo extends AbstractMojo {
147147
*/
148148
private final boolean colorConsole = MessageUtils.isColorEnabled();
149149

150-
private ReporterWriter reporterWriter;
150+
private ReportWriter reportWriter;
151151

152152
private final DatabaseInformation databaseInformation = new DefaultDatabaseInformation();
153153

@@ -214,7 +214,7 @@ public void execute() throws MojoExecutionException {
214214
} finally {
215215
try {
216216
if (connection != null) {
217-
reporterWriter.writeReporters(connection);
217+
reportWriter.writeReports(connection);
218218

219219
DBHelper.disableDBMSOutput(connection);
220220
connection.close();
@@ -308,11 +308,9 @@ private FileMapperOptions createFileMapperOptions(List<String> scripts, String o
308308
}
309309

310310
if (typeMappings != null && !typeMappings.isEmpty()) {
311-
fileMapperOptions.setTypeMappings(new ArrayList<>());
312-
for (CustomTypeMapping typeMapping : typeMappings) {
313-
fileMapperOptions.getTypeMappings()
314-
.add(new KeyValuePair(typeMapping.getCustomMapping(), typeMapping.getType()));
315-
}
311+
fileMapperOptions.setTypeMappings(typeMappings.stream()
312+
.map(mapping -> new KeyValuePair(mapping.getCustomMapping(), mapping.getType()))
313+
.collect(Collectors.toList()));
316314
}
317315

318316
return fileMapperOptions;
@@ -322,7 +320,7 @@ private List<Reporter> initReporters(Connection connection, Version utlVersion,
322320
throws SQLException {
323321

324322
List<Reporter> reporterList = new ArrayList<>();
325-
reporterWriter = new ReporterWriter(targetDir, utlVersion, getLog());
323+
reportWriter = new ReportWriter(targetDir, utlVersion, getLog());
326324

327325
if (reporters.isEmpty()) {
328326
ReporterParameter reporterParameter = new ReporterParameter();
@@ -343,7 +341,7 @@ private List<Reporter> initReporters(Connection connection, Version utlVersion,
343341

344342
// Only added the reporter if at least one of the output is required
345343
if (StringUtils.isNotBlank(reporterParameter.getFileOutput()) || reporterParameter.isConsoleOutput()) {
346-
reporterWriter.addReporter(reporterParameter, reporter);
344+
reportWriter.addReporter(reporterParameter, reporter);
347345
}
348346
}
349347

src/main/java/org/utplsql/maven/plugin/reporter/ReporterWriter.java renamed to src/main/java/org/utplsql/maven/plugin/reporter/ReportWriter.java

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,27 @@
77
import org.utplsql.api.outputBuffer.OutputBuffer;
88
import org.utplsql.api.outputBuffer.OutputBufferProvider;
99
import org.utplsql.api.reporter.Reporter;
10-
import org.utplsql.maven.plugin.model.ReporterParameter;
10+
import org.utplsql.maven.plugin.ReporterParameter;
1111

1212
import java.io.File;
13+
import java.io.FileNotFoundException;
1314
import java.io.FileOutputStream;
1415
import java.io.IOException;
1516
import java.io.PrintStream;
1617
import java.sql.Connection;
18+
import java.sql.SQLException;
1719
import java.util.ArrayList;
1820
import java.util.List;
1921

2022
import static java.lang.String.format;
2123

22-
public class ReporterWriter {
24+
/**
25+
* Writes the reports
26+
*
27+
* @author Alberto Hernández
28+
* @author Simon Martinelli
29+
*/
30+
public class ReportWriter {
2331

2432
private final List<Pair<Reporter, ReporterParameter>> listReporters;
2533

@@ -32,37 +40,35 @@ public class ReporterWriter {
3240
/**
3341
* Constructor of the reporter writer.
3442
*
35-
* @param outputDirectory the reporter output directory
36-
* @param databaseVersion the utPLSQL framework version
43+
* @param outputDirectory the report output directory
44+
* @param databaseVersion the utPLSQL framework {@link Version}
3745
* @param log the Maven log
3846
*/
39-
public ReporterWriter(String outputDirectory, Version databaseVersion, Log log) {
47+
public ReportWriter(String outputDirectory, Version databaseVersion, Log log) {
4048
this.listReporters = new ArrayList<>();
4149
this.outputDirectory = outputDirectory;
4250
this.databaseVersion = databaseVersion;
4351
this.log = log;
4452
}
4553

4654
/**
47-
* Adds a new reporter to the writter.
55+
* Adds a new reporter to the writer.
4856
*
49-
* @param parameter the reporter parameter
50-
* @param reporter the reporter Object
57+
* @param parameter the {@link ReporterParameter}
58+
* @param reporter the {@link Reporter}
5159
*/
5260
public void addReporter(ReporterParameter parameter, Reporter reporter) {
5361
listReporters.add(Pair.of(reporter, parameter));
5462
}
5563

5664
/**
57-
* Writes the reporters to the output.
65+
* Writes the reports to the output.
5866
*
59-
* @param connection the database connection
67+
* @param connection The database {@link Connection}
6068
* @throws MojoExecutionException if any exception happens
6169
*/
62-
public void writeReporters(Connection connection) throws MojoExecutionException {
63-
log.debug("Write Reporters");
70+
public void writeReports(Connection connection) throws MojoExecutionException {
6471
for (Pair<Reporter, ReporterParameter> pair : listReporters) {
65-
log.debug("Write writeReports " + pair.getRight().getName());
6672
writeReports(connection, pair.getLeft(), pair.getRight());
6773
}
6874
}
@@ -74,37 +80,37 @@ private void writeReports(Connection connection, Reporter reporter, ReporterPara
7480
List<PrintStream> printStreams = new ArrayList<>();
7581

7682
if (reporterParameter.isFileOutput()) {
77-
7883
File file = new File(reporterParameter.getFileOutput());
7984
if (!file.isAbsolute()) {
8085
file = new File(outputDirectory, reporterParameter.getFileOutput());
8186
}
8287

8388
if (!file.getParentFile().exists()) {
84-
log.debug("Creating directory for reporter file " + file.getAbsolutePath());
89+
log.debug("Creating directory for report file " + file.getAbsolutePath());
8590
file.getParentFile().mkdirs();
8691
}
8792

8893
fileOutputStream = new FileOutputStream(file);
8994
log.info(format("Writing report %s to %s", reporter.getTypeName(), file.getAbsolutePath()));
9095

91-
// Added to the Report
9296
printStreams.add(new PrintStream(fileOutputStream));
9397
}
9498

9599
if (reporterParameter.isConsoleOutput()) {
96100
log.info(format("Writing report %s to Console", reporter.getTypeName()));
97101
printStreams.add(System.out);
98102
}
103+
99104
buffer.printAvailable(connection, printStreams);
100-
} catch (Exception e) {
101-
throw new MojoExecutionException("Unexpected error opening file ouput ", e);
105+
106+
} catch (FileNotFoundException | SQLException e) {
107+
throw new MojoExecutionException("Unexpected error opening file output ", e);
102108
} finally {
103109
if (fileOutputStream != null) {
104110
try {
105111
fileOutputStream.close();
106112
} catch (IOException e) {
107-
log.info(format("Failed to closing the reporting %s", reporterParameter.getClass()));
113+
log.info(format("Failed to closing the report %s", reporterParameter.getClass()));
108114
}
109115
}
110116
}

‎src/test/java/org/utplsql/maven/plugin/UtPLSQLMojoIT.java‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void simpleProject() throws IOException, VerificationException {
4949
Verifier verifier = createVerifier(testProject);
5050
verifier.executeGoal("test");
5151

52-
checkReportsGenerated(testFolder, "utplsql/sonar-test-reporter.xml", "utplsql/coverage-sonar-reporter.xml");
52+
checkReports(testFolder, "utplsql/sonar-test-report.xml", "utplsql/coverage-sonar-report.xml");
5353
}
5454

5555
@Test
@@ -60,7 +60,7 @@ public void regexProject() throws IOException, VerificationException {
6060
Verifier verifier = createVerifier(testProject);
6161
verifier.executeGoal("test");
6262

63-
checkReportsGenerated(testFolder, "utplsql/sonar-test-reporter.xml", "utplsql/coverage-sonar-reporter.xml");
63+
checkReports(testFolder, "utplsql/sonar-test-report.xml", "utplsql/coverage-sonar-report.xml");
6464
}
6565

6666
@Test
@@ -71,7 +71,7 @@ public void typeMappingProject() throws IOException, VerificationException {
7171
Verifier verifier = createVerifier(testProject);
7272
verifier.executeGoal("test");
7373

74-
checkReportsGenerated(testFolder, "utplsql/sonar-test-reporter.xml", "utplsql/coverage-sonar-reporter.xml");
74+
checkReports(testFolder, "utplsql/sonar-test-report.xml", "utplsql/coverage-sonar-report.xml");
7575
}
7676

7777
@Test
@@ -82,7 +82,7 @@ public void ownerParameterProject() throws IOException, VerificationException {
8282
Verifier verifier = createVerifier(testProject);
8383
verifier.executeGoal("test");
8484

85-
checkReportsGenerated(testFolder, "utplsql/sonar-test-reporter.xml", "utplsql/coverage-sonar-reporter.xml");
85+
checkReports(testFolder, "utplsql/sonar-test-report.xml", "utplsql/coverage-sonar-report.xml");
8686
}
8787

8888
@Test
@@ -102,7 +102,7 @@ public void tagsProject() throws IOException, VerificationException {
102102
Verifier verifier = createVerifier(testProject);
103103
verifier.executeGoal("test");
104104

105-
checkReportsGenerated(testFolder, "utplsql/sonar-test-reporter.xml");
105+
checkReports(testFolder, "utplsql/sonar-test-report.xml");
106106
}
107107

108108
@Test
@@ -124,12 +124,12 @@ public void skipUtplsqlTests() throws IOException, VerificationException {
124124
* @param testFolder Project name
125125
* @param files Files to compare
126126
*/
127-
private void checkReportsGenerated(String testFolder, String... files) throws IOException {
127+
private void checkReports(String testFolder, String... files) throws IOException {
128128
for (String filename : files) {
129129
File outputFile = new File("target/test-classes/" + testFolder + "/target", filename);
130130
File expectedOutputFile = new File("target/test-classes/" + testFolder + "/expected-output", filename);
131131

132-
assertTrue("The reporter for " + filename + " was not generated", outputFile.exists());
132+
assertTrue("The report for " + filename + " was not generated", outputFile.exists());
133133

134134
try (Stream<String> stream = Files.lines(Paths.get("target", "test-classes", testFolder, "target", filename))) {
135135
String outputContent = stream

‎src/test/java/org/utplsql/maven/plugin/UtPLSQLMojoTest.java‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
import org.utplsql.api.Version;
1717
import org.utplsql.api.reporter.Reporter;
1818
import org.utplsql.api.reporter.ReporterFactory;
19-
import org.utplsql.maven.plugin.model.ReporterParameter;
20-
import org.utplsql.maven.plugin.reporter.ReporterWriter;
19+
import org.utplsql.maven.plugin.reporter.ReportWriter;
2120

2221
import java.io.ByteArrayOutputStream;
2322
import java.io.File;
@@ -277,8 +276,8 @@ public void defaultConsoleBehaviour() throws Exception {
277276
}
278277

279278
// Assert that we added only the necessary reporters to the writer.
280-
ReporterWriter reporterWriter = Whitebox.getInternalState(utplsqlMojo, "reporterWriter");
281-
List<Pair<Reporter, ReporterParameter>> listReporters = Whitebox.getInternalState(reporterWriter, "listReporters");
279+
ReportWriter reportWriter = Whitebox.getInternalState(utplsqlMojo, "reportWriter");
280+
List<Pair<Reporter, ReporterParameter>> listReporters = Whitebox.getInternalState(reportWriter, "listReporters");
282281
assertEquals(3, listReporters.size());
283282

284283
ReporterParameter reporterParameter1 = listReporters.get(0).getRight();

src/test/resources/integration-tests/owner-param-project/expected-output/utplsql/coverage-sonar-reporter.xml renamed to src/test/resources/integration-tests/owner-param-project/expected-output/utplsql/coverage-sonar-report.xml

File renamed without changes.

src/test/resources/integration-tests/owner-param-project/expected-output/utplsql/sonar-test-reporter.xml renamed to src/test/resources/integration-tests/owner-param-project/expected-output/utplsql/sonar-test-report.xml

File renamed without changes.

‎src/test/resources/integration-tests/owner-param-project/pom.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737
<reporters>
3838
<reporter>
3939
<name>UT_COVERAGE_SONAR_REPORTER</name>
40-
<fileOutput>utplsql/coverage-sonar-reporter.xml</fileOutput>
40+
<fileOutput>utplsql/coverage-sonar-report.xml</fileOutput>
4141
<consoleOutput>true</consoleOutput>
4242
</reporter>
4343
<reporter>
4444
<name>UT_SONAR_TEST_REPORTER</name>
45-
<fileOutput>utplsql/sonar-test-reporter.xml</fileOutput>
45+
<fileOutput>utplsql/sonar-test-report.xml</fileOutput>
4646
<consoleOutput>true</consoleOutput>
4747
</reporter>
4848
</reporters>

src/test/resources/integration-tests/regex-project/expected-output/utplsql/coverage-sonar-reporter.xml renamed to src/test/resources/integration-tests/regex-project/expected-output/utplsql/coverage-sonar-report.xml

File renamed without changes.

src/test/resources/integration-tests/regex-project/expected-output/utplsql/sonar-test-reporter.xml renamed to src/test/resources/integration-tests/regex-project/expected-output/utplsql/sonar-test-report.xml

File renamed without changes.

0 commit comments

Comments
 (0)