Skip to content

Commit feff4a3

Browse files
committed
Added another command: reporters <ConnectionUrl>
1 parent 6326514 commit feff4a3

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

src/main/java/org/utplsql/cli/CommandProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ private void init() {
1717

1818
addCommand(new RunCommand());
1919
addCommand(new VersionInfoCommand());
20+
addCommand(new ReportersCommand());
2021
}
2122

2223
private void addCommand( ICommand command ) {

src/main/java/org/utplsql/cli/ReporterFactoryProvider.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import org.utplsql.api.reporter.ReporterFactory;
66
import org.utplsql.cli.reporters.LocalAssetsCoverageHTMLReporter;
77

8+
import java.sql.Connection;
9+
import java.sql.SQLException;
10+
811
/** A simple class to provide a ReporterFactory for the RunCommand
912
*
1013
* @author pesse
@@ -17,4 +20,8 @@ public static ReporterFactory createReporterFactory(CompatibilityProxy proxy ) {
1720

1821
return reporterFactory;
1922
}
23+
24+
public static ReporterFactory createReporterFactory(Connection con ) throws SQLException {
25+
return createReporterFactory(new CompatibilityProxy(con));
26+
}
2027
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package org.utplsql.cli;
2+
3+
import com.beust.jcommander.Parameter;
4+
import com.beust.jcommander.Parameters;
5+
import org.utplsql.api.compatibility.CompatibilityProxy;
6+
import org.utplsql.api.reporter.ReporterFactory;
7+
import org.utplsql.api.reporter.inspect.ReporterInfo;
8+
import org.utplsql.api.reporter.inspect.ReporterInspector;
9+
10+
import javax.sql.DataSource;
11+
import java.sql.Connection;
12+
import java.util.ArrayList;
13+
import java.util.Comparator;
14+
import java.util.List;
15+
16+
@Parameters(separators = "=", commandDescription = "prints a list of reporters available in the specified database")
17+
public class ReportersCommand implements ICommand {
18+
19+
@Parameter(
20+
converter = ConnectionInfo.ConnectionStringConverter.class,
21+
arity = 1,
22+
description = ConnectionInfo.COMMANDLINE_PARAM_DESCRIPTION)
23+
private List<ConnectionInfo> connectionInfoList = new ArrayList<>();
24+
25+
public ConnectionInfo getConnectionInfo() {
26+
if ( connectionInfoList != null && connectionInfoList.size() > 0 )
27+
return connectionInfoList.get(0);
28+
else
29+
return null;
30+
}
31+
32+
@Override
33+
public int run() {
34+
35+
DataSource ds = DataSourceProvider.getDataSource(getConnectionInfo(), 1);
36+
try (Connection con = ds.getConnection() ) {
37+
38+
ReporterFactory reporterFactory = ReporterFactoryProvider.createReporterFactory(con);
39+
40+
ReporterInspector.create(reporterFactory, con).getReporterInfos().stream()
41+
.sorted(Comparator.comparing(ReporterInfo::getName))
42+
.forEach(r -> {
43+
System.out.println(r.getName() + " (" + r.getType().name() + "): " + r.getDescription());
44+
System.out.println();
45+
});
46+
}
47+
catch ( Exception e ) {
48+
e.printStackTrace();
49+
return 1;
50+
}
51+
52+
return 0;
53+
}
54+
55+
@Override
56+
public String getCommand() {
57+
return "reporters";
58+
}
59+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.utplsql.cli;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
7+
public class ReportersCommandIT {
8+
9+
@Test
10+
public void callReportersWorks() {
11+
12+
int result = TestHelper.runApp("reporters", TestHelper.getConnectionString());
13+
14+
assertEquals(0, result);
15+
}
16+
}

0 commit comments

Comments
 (0)