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
Reformatting
  • Loading branch information
pesse committed Jun 18, 2019
commit 81e0953149f01e557f790b48ace2d85188e1282e
13 changes: 6 additions & 7 deletions src/main/java/org/utplsql/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void main(String[] args) {
System.exit(exitCode);
}

static int runPicocliWithExitCode( String[] args ) {
static int runPicocliWithExitCode(String[] args) {

LoggerConfiguration.configure(LoggerConfiguration.ConfigLevel.NONE);
LocaleInitializer.initLocale();
Expand All @@ -30,25 +30,24 @@ static int runPicocliWithExitCode( String[] args ) {
List<CommandLine> parsedLines = commandLine.parse(args);

boolean commandWasRun = false;
for ( CommandLine parsedLine : parsedLines ) {
for (CommandLine parsedLine : parsedLines) {
if (parsedLine.isUsageHelpRequested()) {
parsedLine.usage(System.out);
return 0;
}
else if (parsedLine.isVersionHelpRequested()) {
} else if (parsedLine.isVersionHelpRequested()) {
parsedLine.printVersionHelp(System.out);
return 0;
}

Object command = parsedLine.getCommand();
if ( command instanceof ICommand ) {
exitCode = ((ICommand)command).run();
if (command instanceof ICommand) {
exitCode = ((ICommand) command).run();
commandWasRun = true;
break;
}
}

if ( !commandWasRun ) {
if (!commandWasRun) {
commandLine.usage(System.out);
}
} catch (CommandLine.ParameterException e) {
Expand Down
19 changes: 12 additions & 7 deletions src/main/java/org/utplsql/cli/CliVersionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import java.io.InputStream;
import java.io.InputStreamReader;

/** This class is getting updated automatically by the build process.
/**
* This class is getting updated automatically by the build process.
* Please do not update its constants manually cause they will be overwritten.
*
* @author pesse
Expand All @@ -19,18 +20,22 @@ public class CliVersionInfo {

static {
try {
try ( InputStream in = JavaApiVersionInfo.class.getClassLoader().getResourceAsStream("utplsql-cli.version");
BufferedReader reader = new BufferedReader(new InputStreamReader(in)) ) {
try (InputStream in = JavaApiVersionInfo.class.getClassLoader().getResourceAsStream("utplsql-cli.version");
BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
MAVEN_PROJECT_VERSION = reader.readLine();
}
}
catch ( IOException e ) {
} catch (IOException e) {
System.out.println("WARNING: Could not get Version information!");
}
}

public static String getVersion() { return MAVEN_PROJECT_VERSION; }
public static String getInfo() { return MAVEN_PROJECT_NAME + " " + getVersion(); }
public static String getVersion() {
return MAVEN_PROJECT_VERSION;
}

public static String getInfo() {
return MAVEN_PROJECT_NAME + " " + getVersion();
}


}
16 changes: 8 additions & 8 deletions src/main/java/org/utplsql/cli/ConnectionConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ public class ConnectionConfig {
private final String password;
private final String connect;

public ConnectionConfig( String connectString ) {
public ConnectionConfig(String connectString) {
Matcher m = Pattern.compile("^(\".+\"|[^/]+)/(\".+\"|[^@]+)@(.*)$").matcher(connectString);
if ( m.find() ) {
if (m.find()) {
user = stripEnclosingQuotes(m.group(1));
password = stripEnclosingQuotes(m.group(2));
connect = m.group(3);
}
else
} else {
throw new IllegalArgumentException("Not a valid connectString: '" + connectString + "'");
}
}

private String stripEnclosingQuotes( String value ) {
if ( value.length() > 1
private String stripEnclosingQuotes(String value) {
if (value.length() > 1
&& value.startsWith("\"")
&& value.endsWith("\"")) {
return value.substring(1, value.length()-1);
return value.substring(1, value.length() - 1);
} else {
return value;
}
Expand All @@ -49,6 +49,6 @@ public String getConnectString() {
public boolean isSysDba() {
return user != null &&
(user.toLowerCase().endsWith(" as sysdba")
|| user.toLowerCase().endsWith(" as sysoper"));
|| user.toLowerCase().endsWith(" as sysoper"));
}
}
10 changes: 5 additions & 5 deletions src/main/java/org/utplsql/cli/DataSourceProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import java.io.File;
import java.sql.SQLException;

/** Helper class to give you a ready-to-use datasource
/**
* Helper class to give you a ready-to-use datasource
*
* @author pesse
*/
Expand All @@ -20,7 +21,7 @@ public class DataSourceProvider {
}
}

public static DataSource getDataSource(String connectString, int maxConnections ) throws SQLException {
public static DataSource getDataSource(String connectString, int maxConnections) throws SQLException {

requireOjdbc();

Expand All @@ -31,8 +32,7 @@ public static DataSource getDataSource(String connectString, int maxConnections
}

private static void requireOjdbc() {
if ( !OracleLibraryChecker.checkOjdbcExists() )
{
if (!OracleLibraryChecker.checkOjdbcExists()) {
System.out.println("Could not find Oracle JDBC driver in classpath. Please download the jar from Oracle website" +
" and copy it to the 'lib' folder of your utPLSQL-cli installation.");
System.out.println("Download from http://www.oracle.com/technetwork/database/features/jdbc/jdbc-ucp-122-3110062.html");
Expand All @@ -42,7 +42,7 @@ private static void requireOjdbc() {
}

private static void warnIfSysDba(ConnectionConfig config) {
if ( config.isSysDba() ) {
if (config.isSysDba()) {
System.out.println("WARNING: You are connecting to the database as SYSDBA or SYSOPER, which is NOT RECOMMENDED and can put your database at risk!");
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/org/utplsql/cli/FileWalker.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ public List<String> getFileList(File baseDir, String inspectPath) {
public List<String> getFileList(File baseDir, String inspectPath, boolean relative) {
File inspectDir = new File(baseDir, inspectPath);

if (!inspectDir.isDirectory())
if (!inspectDir.isDirectory()) {
throw new IllegalArgumentException(inspectPath + " is not a directory.");
}

List<String> fileList = new ArrayList<>();
listDirFiles(baseDir, inspectDir, fileList, relative);
Expand All @@ -28,15 +29,17 @@ public List<String> getFileList(File baseDir, String inspectPath, boolean relati
private void listDirFiles(File baseDir, File directory, List<String> fileList, boolean relative) {
File[] directoryFiles = directory.listFiles();

if (directoryFiles == null)
if (directoryFiles == null) {
return;
}

for (File file : directoryFiles) {
if (file.isFile()) {
String absolutePath = file.getAbsolutePath();

if (relative)
if (relative) {
absolutePath = absolutePath.substring(baseDir.getAbsolutePath().length() + 1);
}

fileList.add(absolutePath);
} else {
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/utplsql/cli/ICommand.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.utplsql.cli;

/** This is the very basic interface that should be implemented by all utPLSQL cli commands
/**
* This is the very basic interface that should be implemented by all utPLSQL cli commands
*
* @author pesse
*/
public interface ICommand {

/** We expect the command to handle all eventually occurring exceptions
/**
* We expect the command to handle all eventually occurring exceptions
* and return an exit code
*
* @return exit code integer
Expand Down
34 changes: 19 additions & 15 deletions src/main/java/org/utplsql/cli/LocaleInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,58 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/** This class makes sure the java locale is set according to the environment variables LC_ALL and LANG
/**
* This class makes sure the java locale is set according to the environment variables LC_ALL and LANG
* We experienced that, in some cases, the locale was not set as expected, therefore this class implements some clear
* rules:
* 1. If environment variable LC_ALL is set, we try to parse its content and set locale according to its value if valid
* 2. If environment variable LANG is set, we try to parse its content and set locale according to its value if valid
* 3. Otherwise we use default locale
* 1. If environment variable LC_ALL is set, we try to parse its content and set locale according to its value if valid
* 2. If environment variable LANG is set, we try to parse its content and set locale according to its value if valid
* 3. Otherwise we use default locale
*
* @author pesse
* @author pesse
*/
class LocaleInitializer {

private static final Pattern REGEX_LOCALE = Pattern.compile("^([a-zA-Z]+)[_-]([a-zA-Z]+)"); // We only need the very first part and are pretty forgiving in parsing

/** Sets the default locale according to the rules described above
*
/**
* Sets the default locale according to the rules described above
*/
static void initLocale() {

boolean localeChanged = setDefaultLocale(EnvironmentVariableUtil.getEnvValue("LC_ALL"));
if ( !localeChanged )
if (!localeChanged) {
setDefaultLocale(EnvironmentVariableUtil.getEnvValue("LANG"));
}
}

/** Set the default locale from a given string like LC_ALL or LANG environment variable
/**
* Set the default locale from a given string like LC_ALL or LANG environment variable
*
* @param localeString Locale-string from LC_ALL or LANG, e.g "en_US.utf-8"
* @return true if successful, false if not
*/
private static boolean setDefaultLocale( String localeString ) {
if ( localeString == null || localeString.isEmpty() )
private static boolean setDefaultLocale(String localeString) {
if (localeString == null || localeString.isEmpty()) {
return false;
}

try {
Matcher m = REGEX_LOCALE.matcher(localeString);
if (m.find()) {
StringBuilder sb = new StringBuilder();
sb.append(m.group(1));
if (m.group(2) != null)
if (m.group(2) != null) {
sb.append("-").append(m.group(2));
}

Locale l = new Locale.Builder().setLanguageTag(sb.toString()).build();
if ( l != null ) {
if (l != null) {
Locale.setDefault(l);
return true;
}
}
}
catch ( Exception e ) {
} catch (Exception e) {
System.out.println("Could not get locale from " + localeString);
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/utplsql/cli/LoggerConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public enum ConfigLevel {
}

private LoggerConfiguration() {
throw new UnsupportedOperationException();
throw new UnsupportedOperationException();
}

static void configure(ConfigLevel level) {
switch ( level ) {
switch (level) {
case BASIC:
configureInfo();
break;
Expand Down Expand Up @@ -48,17 +48,17 @@ private static void configureDebug() {
setSingleConsoleAppenderWithLayout("%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n");
}

private static void setRootLoggerLevel( Level level ) {
Logger root = (Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
private static void setRootLoggerLevel(Level level) {
Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
root.setLevel(level);
}

private static void muteHikariLogger() {
((Logger) LoggerFactory.getLogger(HikariDataSource.class)).setLevel(Level.OFF);
}

private static void setSingleConsoleAppenderWithLayout( String patternLayout ) {
Logger logger = (Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
private static void setSingleConsoleAppenderWithLayout(String patternLayout) {
Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();

PatternLayoutEncoder ple = new PatternLayoutEncoder();
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/org/utplsql/cli/OracleLibraryChecker.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
package org.utplsql.cli;

/** Simple class to check whether needed Oracle libraries are on classpath or not
/**
* Simple class to check whether needed Oracle libraries are on classpath or not
*
* @author pesse
*/
class OracleLibraryChecker {

private static boolean classExists( String classFullName ){
try
{
private static boolean classExists(String classFullName) {
try {
Class.forName(classFullName);

return true;
}
catch ( ClassNotFoundException e )
{
} catch (ClassNotFoundException e) {
return false;
}
}

/** Checks if OJDBC library is on the classpath by searching for oracle.jdbc.OracleDriver class
/**
* Checks if OJDBC library is on the classpath by searching for oracle.jdbc.OracleDriver class
*
* @return true or false
*/
public static boolean checkOjdbcExists() {
return classExists("oracle.jdbc.OracleDriver");
}

/** Checks if Orai18n library is on the classpath by searching for oracle.i18n.text.OraCharset
/**
* Checks if Orai18n library is on the classpath by searching for oracle.i18n.text.OraCharset
*
* @return true or false
*/
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/utplsql/cli/ReporterFactoryProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@
import java.sql.Connection;
import java.sql.SQLException;

/** A simple class to provide a ReporterFactory for the RunCommand
/**
* A simple class to provide a ReporterFactory for the RunCommand
*
* @author pesse
*/
class ReporterFactoryProvider {

public static ReporterFactory createReporterFactory(CompatibilityProxy proxy ) {
public static ReporterFactory createReporterFactory(CompatibilityProxy proxy) {
ReporterFactory reporterFactory = ReporterFactory.createDefault(proxy);
reporterFactory.registerReporterFactoryMethod(CoreReporters.UT_COVERAGE_HTML_REPORTER.name(), LocalAssetsCoverageHTMLReporter::new, "Will copy all necessary assets to a folder named after the Output-File");

return reporterFactory;
}

public static ReporterFactory createReporterFactory(Connection con ) throws SQLException {
public static ReporterFactory createReporterFactory(Connection con) throws SQLException {
return createReporterFactory(new CompatibilityProxy(con));
}
}
Loading