Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
Added another command: reporters <ConnectionUrl>
  • Loading branch information
pesse committed Jun 7, 2018
commit feff4a32b8625d6f4950ba8bfc3cf32c23128d1c
1 change: 1 addition & 0 deletions src/main/java/org/utplsql/cli/CommandProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ private void init() {

addCommand(new RunCommand());
addCommand(new VersionInfoCommand());
addCommand(new ReportersCommand());
}

private void addCommand( ICommand command ) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/utplsql/cli/ReporterFactoryProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import org.utplsql.api.reporter.ReporterFactory;
import org.utplsql.cli.reporters.LocalAssetsCoverageHTMLReporter;

import java.sql.Connection;
import java.sql.SQLException;

/** A simple class to provide a ReporterFactory for the RunCommand
*
* @author pesse
Expand All @@ -17,4 +20,8 @@ public static ReporterFactory createReporterFactory(CompatibilityProxy proxy ) {

return reporterFactory;
}

public static ReporterFactory createReporterFactory(Connection con ) throws SQLException {
return createReporterFactory(new CompatibilityProxy(con));
}
}
59 changes: 59 additions & 0 deletions src/main/java/org/utplsql/cli/ReportersCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.utplsql.cli;

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import org.utplsql.api.compatibility.CompatibilityProxy;
import org.utplsql.api.reporter.ReporterFactory;
import org.utplsql.api.reporter.inspect.ReporterInfo;
import org.utplsql.api.reporter.inspect.ReporterInspector;

import javax.sql.DataSource;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

@Parameters(separators = "=", commandDescription = "prints a list of reporters available in the specified database")
public class ReportersCommand implements ICommand {

@Parameter(
converter = ConnectionInfo.ConnectionStringConverter.class,
arity = 1,
description = ConnectionInfo.COMMANDLINE_PARAM_DESCRIPTION)
private List<ConnectionInfo> connectionInfoList = new ArrayList<>();

public ConnectionInfo getConnectionInfo() {
if ( connectionInfoList != null && connectionInfoList.size() > 0 )
return connectionInfoList.get(0);
else
return null;
}

@Override
public int run() {

DataSource ds = DataSourceProvider.getDataSource(getConnectionInfo(), 1);
try (Connection con = ds.getConnection() ) {

ReporterFactory reporterFactory = ReporterFactoryProvider.createReporterFactory(con);

ReporterInspector.create(reporterFactory, con).getReporterInfos().stream()
.sorted(Comparator.comparing(ReporterInfo::getName))
.forEach(r -> {
System.out.println(r.getName() + " (" + r.getType().name() + "): " + r.getDescription());
System.out.println();
});
}
catch ( Exception e ) {
e.printStackTrace();
return 1;
}

return 0;
}

@Override
public String getCommand() {
return "reporters";
}
}
16 changes: 16 additions & 0 deletions src/test/java/org/utplsql/cli/ReportersCommandIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.utplsql.cli;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class ReportersCommandIT {

@Test
public void callReportersWorks() {

int result = TestHelper.runApp("reporters", TestHelper.getConnectionString());

assertEquals(0, result);
}
}