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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6717057
Failing test to catch and reproduce #143
pesse Jun 4, 2019
038981f
Merge branch 'develop' into feature/new_cli_library
pesse Jun 7, 2019
b21f651
Unit-Test to simulate passing all parameters that should be known
pesse Jun 7, 2019
ce849fc
Initial implementation of Picocli usage
pesse Jun 11, 2019
5520562
Some more tests around FileMapping
pesse Jun 12, 2019
f9c4cf7
New RunAction which does the logic based on RunCommandConfig
pesse Jun 12, 2019
d8cbce2
RunAction tested and functional so far
pesse Jun 12, 2019
3b5e168
Include RunAction into RunCommand
pesse Jun 12, 2019
60997d7
New entry point for Picocli
pesse Jun 12, 2019
d13ae5b
Extract functionality to interface
pesse Jun 12, 2019
5e86b01
Adapt tests to IRunCommand and implement necessary functionality
pesse Jun 12, 2019
00f3f5f
Change VersionCommand to Picocli
pesse Jun 12, 2019
2ce4e91
Change ReportersCommand to Picocli
pesse Jun 13, 2019
b88d5c5
Fix arity for mapping options and prevent NPE
pesse Jun 13, 2019
c80dc8c
Refactor RunCommandTest to cover new approach
pesse Jun 13, 2019
8eec2cb
Implement rules for printToScreen Reporters: Only one can go to screen
pesse Jun 13, 2019
ded39d3
Implemented new Picocli help
pesse Jun 13, 2019
6922e52
Removed some now unnecessary stuff
pesse Jun 13, 2019
5aa4c1d
We don't need the old RunCommand anymore, time to get rid of it
pesse Jun 13, 2019
60fcfaf
Improve help and help-tests
pesse Jun 13, 2019
a3608b5
Refactor: Remove unnecessary logic
pesse Jun 13, 2019
09bf357
Refactor: extract ReporterConfig -> ReporterOption conversion
pesse Jun 13, 2019
1b65b51
Refactor: getCommand() no longer needed
pesse Jun 13, 2019
77fd752
Refactor: Include only left check-functionality
pesse Jun 13, 2019
e443e3c
Refactor: Cleanup ReporterManager a bit
pesse Jun 13, 2019
0bdca7d
Get rid of JCommander dependency
pesse Jun 13, 2019
ae0e9c4
Move ConnectionString description to main Utplsql-Command
pesse Jun 18, 2019
f47c0de
Fix Typo
pesse Jun 18, 2019
bb18ea1
Some Refactorings and make things final
pesse Jun 18, 2019
1a984ff
Merge branch 'develop' into feature/new_cli_library
pesse Jun 18, 2019
81e0953
Reformatting
pesse Jun 18, 2019
a8acbb9
Add `-h` option to all commands and cover it with tests
pesse Jun 18, 2019
10bef7b
Adjust documentation to reflect parameter changes
pesse Jun 18, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Initial implementation of Picocli usage
Introduced new Config-Objects to abstract away cli-arguments to config
transformation.
Will also be needed for YAML/JSON configuration in the future
  • Loading branch information
pesse committed Jun 11, 2019
commit ce849fcabf34dd39bd47fdca0691ec724335a200
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>4.0.0-beta-1b</version>
</dependency>
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/utplsql/cli/LoggerConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.zaxxer.hikari.HikariDataSource;
import org.slf4j.LoggerFactory;

class LoggerConfiguration {
public class LoggerConfiguration {

public enum ConfigLevel {
BASIC, NONE, DEBUG
Expand Down
230 changes: 230 additions & 0 deletions src/main/java/org/utplsql/cli/RunPicocliCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
package org.utplsql.cli;

import org.utplsql.cli.config.FileMapperConfig;
import org.utplsql.cli.config.ReporterConfig;
import org.utplsql.cli.config.RunCommandConfig;
import picocli.CommandLine.*;

import java.util.*;
import java.util.concurrent.Callable;

@Command( name = "run", description = "run tests")
public class RunPicocliCommand implements Callable<RunCommandConfig> {

@Parameters(description = ConnectionInfo.COMMANDLINE_PARAM_DESCRIPTION)
private String connectionString;

@Option(names = {"-p", "--path"},
description = "run suites/tests by path, format: " +
"-p=[schema|schema:[suite ...][.test]|schema[.suite ...][.test]")
private List<String> paths = new ArrayList<>();


@Option(
names = {"-c", "--color"},
description = "enables printing of test results in colors as defined by ANSICONSOLE standards")
private boolean colorConsole = false;

@Option(
names = {"-d", "--debug"},
description = "Outputs a load of debug information to console")
private boolean logDebug = false;

@Option(
names = {"-q", "--quiet"},
description = "Does not output the informational messages normally printed to console")
private boolean logSilent = false;

@Option(
names = {"--failure-exit-code"},
description = "override the exit code on failure, default = 1")
private int failureExitCode = 1;


@Option(
names = {"-scc", "--skip-compatibility-check"},
description = "Skips the check for compatibility with database framework. CLI expects the framework to be " +
"most actual. Use this if you use CLI with a development version of utPLSQL-framework")
private boolean skipCompatibilityCheck = false;

@Option(
names = {"-t", "--timeout"},
description = "Sets the timeout in minutes after which the cli will abort. Default 60")
private int timeoutInMinutes = 60;

@Option(
names = {"-include"},
description = "Comma-separated object list to include in the coverage report. " +
"Format: [schema.]package[,[schema.]package ...]. See coverage reporting options in framework documentation"
)
private String includeObjects = null;

@Option(
names = {"-exclude"},
description = "Comma-separated object list to exclude from the coverage report. " +
"Format: [schema.]package[,[schema.]package ...]. See coverage reporting options in framework documentation"
)
private String excludeObjects = null;


@Option(
names = {"-D", "--dbms_output"},
description = "Enables DBMS_OUTPUT for the TestRunner (default: DISABLED)"
)
private boolean enableDbmsOutput = false;

// RandomTestOrder
@Option(
names = {"-r", "--random-test-order"},
description = "Enables random order of test executions (default: DISABLED)"
)
private boolean randomTestOrder = false;

@Option(
names = {"-seed", "--random-test-order-seed"},
description = "Sets the seed to use for random test execution order. If set, it sets --random-test-order to true"
)
private Integer randomTestOrderSeed;

@ArgGroup(exclusive = false, multiplicity = "0..*")
private List<Format> reporters = new ArrayList<>();

static class Format {
@Option(names={"-f", "--format"}, required = true, description = "Enables specified format reporting")
String format;
@Option(names={"-o"}, description = "Outputs format to file")
String outputFile;
@Option(names={"-s"}, description = "Outputs to screen even when an output file is specified")
boolean outputToScreen = false;
}

// FileMappings
@ArgGroup(exclusive = false, multiplicity = "0..2")
private List<FileMappingComposite> fileMappings;

static class FileMappingComposite {

static class TestOrSourcePath {
@Option(names="-source_path", required = true)
String sourcePath;
@Option(names="-test_path", required = true)
String testPath;

String getPath() {
return ( isSourcePath() ) ? sourcePath : testPath;
}

boolean isSourcePath() {
return sourcePath != null;
}
}

static class FileMapping {
@Option(names="-owner")
String owner;
@Option(names="-regex_expression")
String regexExpression;
@Option(names="-type_mapping")
String typeMapping;
@Option(names="-owner_subexpression")
Integer ownerSubExpression;
@Option(names="-type_subexpression")
Integer typeSubExpression;
@Option(names="-name_subexpression")
Integer nameSubExpression;
}

@ArgGroup(exclusive = true, multiplicity = "1")
TestOrSourcePath testOrSourcePath;

@ArgGroup(exclusive = false, multiplicity = "1")
FileMapping mapping;


FileMapperConfig toFileMapperConfig() {
Map<String, String> typeMap = new HashMap<>();

if ( mapping.typeMapping != null && !mapping.typeMapping.isEmpty()) {
for ( String keyVal : mapping.typeMapping.split("/")) {
String[] values = keyVal.split("=");
typeMap.put(values[0], values[1]);
}
}

return new FileMapperConfig(
testOrSourcePath.getPath(),
mapping.owner,
mapping.regexExpression,
typeMap,
mapping.ownerSubExpression,
mapping.typeSubExpression,
mapping.nameSubExpression
);
}
}

private String[] splitOrEmpty(String value) {
if ( value == null || value.isEmpty() ) {
return new String[0];
}
else {
return value.split(",");
}
}

@Override
public RunCommandConfig call() throws Exception {

// Prepare path elements
ArrayList<String> suitePaths = new ArrayList<>();
for ( String pathElem : paths ) {
suitePaths.addAll(Arrays.asList(pathElem.split(",")));
}

// Prepare LogLevelConfig
LoggerConfiguration.ConfigLevel loggerConfigLevel = LoggerConfiguration.ConfigLevel.BASIC;
if ( logSilent ) {
loggerConfigLevel = LoggerConfiguration.ConfigLevel.NONE;
}
else if ( logDebug ) {
loggerConfigLevel = LoggerConfiguration.ConfigLevel.DEBUG;
}

// Prepare Reporter configs
List<ReporterConfig> reporterConfigs = new ArrayList<>();
for ( Format format : reporters ) {
reporterConfigs.add(new ReporterConfig(format.format, format.outputFile, format.outputToScreen));
}

// Prepare TypeMappings
FileMapperConfig sourceFileMapping = null;
FileMapperConfig testFileMapping = null;
if ( fileMappings != null ) {
for ( FileMappingComposite fmc : fileMappings ) {
if ( fmc.testOrSourcePath.isSourcePath() ) {
sourceFileMapping = fmc.toFileMapperConfig();
}
else {
testFileMapping = fmc.toFileMapperConfig();
}
}
}

return new RunCommandConfig(
connectionString,
suitePaths.toArray(new String[0]),
reporterConfigs.toArray(new ReporterConfig[0]),
colorConsole,
failureExitCode,
skipCompatibilityCheck,
splitOrEmpty(includeObjects),
splitOrEmpty(excludeObjects),
sourceFileMapping,
testFileMapping,
loggerConfigLevel,
timeoutInMinutes,
enableDbmsOutput,
randomTestOrder,
randomTestOrderSeed);
}
}
11 changes: 11 additions & 0 deletions src/main/java/org/utplsql/cli/UtplsqlPicocliCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.utplsql.cli;

import picocli.CommandLine;

@CommandLine.Command(
name = "utplsql",
description = "utPLSQL cli",
subcommands = { RunPicocliCommand.class })
public class UtplsqlPicocliCommand {

}
18 changes: 18 additions & 0 deletions src/main/java/org/utplsql/cli/config/ConnectionConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.utplsql.cli.config;

import java.beans.ConstructorProperties;

public class ConnectionConfig {

private final String connectString;

@ConstructorProperties({"connectString"})
public ConnectionConfig(String connectString) {
this.connectString = connectString;
}

public String getConnectString() {
return connectString;
}

}
54 changes: 54 additions & 0 deletions src/main/java/org/utplsql/cli/config/FileMapperConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.utplsql.cli.config;

import java.beans.ConstructorProperties;
import java.util.Map;

public class FileMapperConfig {

private final String path;
private final String owner;
private final String regexExpression;
private final Map<String, String> typeMapping;
private final Integer ownerSubexpression;
private final Integer nameSubexpression;
private final Integer typeSubexpression;

@ConstructorProperties({"path", "owner", "regexExpression", "typeMapping", "ownerSubexpression", "nameSubexpression", "typeSubexpression"})
public FileMapperConfig(String path, String owner, String regexExpression, Map<String, String> typeMapping, Integer ownerSubexpression, Integer nameSubexpression, Integer typeSubexpression) {
this.path = path;
this.owner = owner;
this.regexExpression = regexExpression;
this.typeMapping = typeMapping;
this.ownerSubexpression = ownerSubexpression;
this.nameSubexpression = nameSubexpression;
this.typeSubexpression = typeSubexpression;
}

public String getPath() {
return path;
}

public String getOwner() {
return owner;
}

public String getRegexExpression() {
return regexExpression;
}

public Map<String, String> getTypeMapping() {
return typeMapping;
}

public Integer getOwnerSubexpression() {
return ownerSubexpression;
}

public Integer getNameSubexpression() {
return nameSubexpression;
}

public Integer getTypeSubexpression() {
return typeSubexpression;
}
}
29 changes: 29 additions & 0 deletions src/main/java/org/utplsql/cli/config/ReporterConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.utplsql.cli.config;

import java.beans.ConstructorProperties;

public class ReporterConfig {

private final String name;
private final String output;
private boolean screen = false;

@ConstructorProperties({"name", "output", "screen"})
public ReporterConfig( String name, String output, Boolean screen ) {
this.name = name;
this.output = output;
if ( screen != null ) this.screen = screen;
}

public String getName() {
return name;
}

public String getOutput() {
return output;
}

public boolean isScreen() {
return screen;
}
}
Loading