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
Refactor: extract ReporterConfig -> ReporterOption conversion
  • Loading branch information
pesse committed Jun 13, 2019
commit 09bf357d76f6c3105d35735d42af4e8bf5647fc2
31 changes: 22 additions & 9 deletions src/main/java/org/utplsql/cli/ReporterManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.utplsql.api.reporter.CoreReporters;
import org.utplsql.api.reporter.Reporter;
import org.utplsql.api.reporter.ReporterFactory;
import org.utplsql.cli.config.ReporterConfig;
import org.utplsql.cli.reporters.ReporterOptionsAware;

import javax.sql.DataSource;
Expand All @@ -13,7 +14,6 @@
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutorService;

Expand All @@ -23,17 +23,30 @@ class ReporterManager {
private List<Throwable> reporterGatherErrors;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we gather Errors? if not, lets make it List<Exception>

private ExecutorService executorService;

ReporterManager( ReporterOptions[] reporterOptions ) {
this.reporterOptionsList = Arrays.asList(reporterOptions);
initReporterOptionsList();
ReporterManager(ReporterConfig[] reporterConfigs ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me share with you my point. I prefere to use simple constructors and use factory methods for all necessary operation neede to call the constructor. I don't like calling functions from a constructor as it doesn't allow making fields final and I personnaly like final fields. Do you mind making a small refactoring of this place?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean like

public static ReporterManager create( ReporterConfig[] reporterConfigs ) { ...

?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes with all necessary stuff populating arrays done there and then call a simple private constructor.

reporterOptionsList = new ArrayList<>();
if ( reporterConfigs != null && reporterConfigs.length > 0 ) {
loadOptionsFromConfigs( reporterConfigs );
}
else {
reporterOptionsList.add(getDefaultReporterOption());
}
}

private void initReporterOptionsList( ) {
private void loadOptionsFromConfigs( ReporterConfig[] reporterConfigs ) {
boolean printToScreen = false;
for (ReporterConfig reporterConfig : reporterConfigs) {
ReporterOptions option = new ReporterOptions(
reporterConfig.getName(),
reporterConfig.getOutput());

// If no reporter parameters were passed, use default reporter.
if (reporterOptionsList.isEmpty()) {
reporterOptionsList = new ArrayList<>();
reporterOptionsList.add(getDefaultReporterOption());
option.forceOutputToScreen(reporterConfig.isForceToScreen());
reporterOptionsList.add(option);

// Check printToScreen validity
if (option.outputToScreen() && printToScreen)
throw new IllegalArgumentException("You cannot configure more than one reporter to output to screen");
printToScreen = option.outputToScreen();
}
}

Expand Down
21 changes: 1 addition & 20 deletions src/main/java/org/utplsql/cli/RunAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.utplsql.api.reporter.Reporter;
import org.utplsql.api.reporter.ReporterFactory;
import org.utplsql.cli.config.FileMapperConfig;
import org.utplsql.cli.config.ReporterConfig;
import org.utplsql.cli.config.RunCommandConfig;
import org.utplsql.cli.exception.DatabaseConnectionFailed;
import org.utplsql.cli.exception.ReporterTimeoutException;
Expand Down Expand Up @@ -273,25 +272,7 @@ private CompatibilityProxy checkFrameworkCompatibility(Connection conn) throws S

private ReporterManager getReporterManager() {
if ( reporterManager == null ) {

ReporterConfig[] reporterConfigs = config.getReporters();
if ( reporterConfigs != null ) {
ReporterOptions[] options = new ReporterOptions[reporterConfigs.length];
boolean printToScreen = false;
for (int i = 0; i<reporterConfigs.length; i++ ) {
options[i] = new ReporterOptions(
reporterConfigs[i].getName(),
reporterConfigs[i].getOutput());

options[i].forceOutputToScreen(reporterConfigs[i].isForceToScreen());

// Check printToScreen validity
if ( options[i].outputToScreen() && printToScreen )
throw new IllegalArgumentException("You cannot configure more than one reporter to output to screen");
printToScreen = options[i].outputToScreen();
}
reporterManager = new ReporterManager(options);
}
reporterManager = new ReporterManager(config.getReporters());
}

return reporterManager;
Expand Down