|
| 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 | +} |
0 commit comments