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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ The file tnsnames.ora must contain valid TNS entries.
-exclude=pckg_list - Comma-separated object list to exclude from the coverage report.
Format: [schema.]package[,[schema.]package ...].
See coverage reporting options in framework documentation.

-q - Does not output the informational messages normally printed to console.
Default: false

-d - Outputs a load of debug information to console
Default: false
```

Parameters -f, -o, -s are correlated. That is parameters -o and -s are controlling outputs for reporter specified by the preceding -f parameter.
Expand Down
66 changes: 34 additions & 32 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,42 @@
</properties>

<dependencies>
<dependency>
<groupId>org.utplsql</groupId>
<artifactId>java-api</artifactId>
<version>3.1.2</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ucp</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.72</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.7.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.7.25</version>
<groupId>org.utplsql</groupId>
<artifactId>java-api</artifactId>
<version>3.1.3-SNAPSHOT</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ucp</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.72</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.7.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
Comment thread
pesse marked this conversation as resolved.
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>

<!-- Test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand All @@ -62,11 +68,7 @@
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>

</dependencies>

<build>
Expand Down
64 changes: 64 additions & 0 deletions src/main/java/org/utplsql/cli/LoggerConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.utplsql.cli;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.ConsoleAppender;
import com.zaxxer.hikari.HikariDataSource;
import org.slf4j.LoggerFactory;
import org.utplsql.api.TestRunner;

class LoggerConfiguration {

Comment thread
pesse marked this conversation as resolved.
static void configure(boolean silent, boolean debug) {
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.

Why do we use two parameters here? Are all 4 combination of their values valid? Maybe we should accept 3-valued enum?

SILENT, DEFAULT, DEBUG

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.

Reason is to make it easy to just pass the parameters of the RunCommand to the LoggerConfigurator.
Enum would increase clarity of the LoggerConfigurator class taken alone but not its usage. This way it's clear that logging is depenent on two flags.
If we can increase clarity on the fact that silent is superior to debug, I'd appreciate it.

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.

I think we should. If non flags are passed then default logging is enabled, if silent - non, if debug - debug. And then we end up with 3 levels, set on application level and non of other classes should think about it. Classes just log using appropriate log level (logger.info, logger.debug).

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.

I'm not sure if I get you completely right.
You'd like to introduce a 3-leveled ENUM and shift the logic which configuration to take to the RunCommand?
The classes themselves already use appropriate log level, the purpose of the configuration is to either hide or show the log information.

if ( silent )
configureSilent();
else if ( debug )
configureDebug();
else
configureDefault();
}

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

private static void configureDefault() {
Comment thread
pesse marked this conversation as resolved.
Outdated
Logger root = (Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
root.setLevel(Level.INFO);

((Logger) LoggerFactory.getLogger(HikariDataSource.class)).setLevel(Level.OFF);
((Logger) LoggerFactory.getLogger(TestRunner.class)).setLevel(Level.ERROR);

setSingleConsoleAppenderWithLayout(root, "%msg%n");
}

private static void configureDebug() {
Logger root = (Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
root.setLevel(Level.DEBUG);

setSingleConsoleAppenderWithLayout(root, "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n");
}

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

PatternLayoutEncoder ple = new PatternLayoutEncoder();
ple.setPattern(patternLayout);

ple.setContext(lc);
ple.start();

ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>();
consoleAppender.setEncoder(ple);
consoleAppender.setContext(lc);
consoleAppender.start();

logger.detachAndStopAllAppenders();
logger.setAdditive(false);
logger.addAppender(consoleAppender);
}
}
2 changes: 2 additions & 0 deletions src/main/java/org/utplsql/cli/ReportersCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ private ConnectionInfo getConnectionInfo() {
@Override
public int run() {

LoggerConfiguration.configure(true, false );

try {
DataSource ds = DataSourceProvider.getDataSource(getConnectionInfo(), 1);
try (Connection con = ds.getConnection()) {
Expand Down
95 changes: 72 additions & 23 deletions src/main/java/org/utplsql/cli/RunCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import org.utplsql.api.FileMapperOptions;
import org.utplsql.api.KeyValuePair;
import org.utplsql.api.TestRunner;
import org.utplsql.api.Version;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.utplsql.api.*;
import org.utplsql.api.compatibility.CompatibilityProxy;
import org.utplsql.api.db.DefaultDatabaseInformation;
import org.utplsql.api.exception.DatabaseNotCompatibleException;
import org.utplsql.api.exception.SomeTestsFailedException;
import org.utplsql.api.exception.UtPLSQLNotInstalledException;
import org.utplsql.api.reporter.Reporter;
import org.utplsql.api.reporter.ReporterFactory;
import org.utplsql.cli.exception.DatabaseConnectionFailed;
import org.utplsql.cli.log.StringBlockFormatter;

import javax.sql.DataSource;
import java.io.File;
Expand All @@ -34,6 +35,8 @@
@Parameters(separators = "=", commandDescription = "run tests")
public class RunCommand implements ICommand {

private static final Logger logger = LoggerFactory.getLogger(RunCommand.class);

@Parameter(
required = true,
converter = ConnectionInfo.ConnectionStringConverter.class,
Expand Down Expand Up @@ -99,6 +102,15 @@ public class RunCommand implements ICommand {
)
private String excludeObjects = null;

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

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

private CompatibilityProxy compatibilityProxy;
private ReporterFactory reporterFactory;
Expand All @@ -112,7 +124,13 @@ public List<String> getTestPaths() {
return testPaths;
}

void init() {
LoggerConfiguration.configure(logSilent, logDebug);
}

public int run() {
init();
outputMainInformation();

try {

Expand Down Expand Up @@ -148,25 +166,8 @@ public int run() {

final DataSource dataSource = DataSourceProvider.getDataSource(getConnectionInfo(), getReporterManager().getNumberOfReporters() + 1);

// Do the reporters initialization, so we can use the id to run and gather results.
try (Connection conn = dataSource.getConnection()) {

// Check if orai18n exists if database version is 11g
RunCommandChecker.checkOracleI18nExists(conn);

// First of all do a compatibility check and fail-fast
compatibilityProxy = checkFrameworkCompatibility(conn);
reporterFactory = ReporterFactoryProvider.createReporterFactory(compatibilityProxy);

reporterList = getReporterManager().initReporters(conn, reporterFactory, compatibilityProxy);

} catch (SQLException e) {
if (e.getErrorCode() == 1017 || e.getErrorCode() == 12514) {
throw new DatabaseConnectionFailed(e);
} else {
throw e;
}
}
initDatabase(dataSource);
reporterList = initReporters(dataSource);

// Output a message if --failureExitCode is set but database framework is not capable of
String msg = RunCommandChecker.getCheckFailOnErrorMessage(failureExitCode, compatibilityProxy.getDatabaseVersion());
Expand All @@ -190,6 +191,8 @@ public int run() {
.includeObjects(finalIncludeObjectsList)
.excludeObjects(finalExcludeObjectsList);

logger.info("Running tests now.");
logger.info("--------------------------------------");
testRunner.run(conn);
} catch (SomeTestsFailedException e) {
returnCode[0] = this.failureExitCode;
Expand All @@ -205,6 +208,10 @@ public int run() {

executorService.shutdown();
executorService.awaitTermination(60, TimeUnit.MINUTES);

logger.info("--------------------------------------");
logger.info("All tests done.");

return returnCode[0];
}
catch ( DatabaseNotCompatibleException | UtPLSQLNotInstalledException | DatabaseConnectionFailed e ) {
Expand All @@ -221,6 +228,48 @@ public String getCommand() {
}


private void outputMainInformation() {

StringBlockFormatter formatter = new StringBlockFormatter("utPLCSL cli");
formatter.appendLine(CliVersionInfo.getInfo());
formatter.appendLine(JavaApiVersionInfo.getInfo());
formatter.appendLine("Java-Version: " + System.getProperty("java.version"));
formatter.appendLine("ORACLE_HOME: " + EnvironmentVariableUtil.getEnvValue("ORACLE_HOME"));
formatter.appendLine("");
formatter.appendLine("Thanks for testing!");

logger.info(formatter.toString());
logger.info("");
}

private void initDatabase(DataSource dataSource) throws SQLException {
try (Connection conn = dataSource.getConnection()) {

// Check if orai18n exists if database version is 11g
RunCommandChecker.checkOracleI18nExists(conn);

// First of all do a compatibility check and fail-fast
compatibilityProxy = checkFrameworkCompatibility(conn);

logger.info("Successfully connected to database. UtPLSQL core: " + compatibilityProxy.getDatabaseVersion());
logger.info("Oracle-Version: {}", new DefaultDatabaseInformation().getOracleVersion(conn));
Comment thread
pesse marked this conversation as resolved.
}
catch (SQLException e) {
if (e.getErrorCode() == 1017 || e.getErrorCode() == 12514) {
throw new DatabaseConnectionFailed(e);
} else {
throw e;
}
}
}

private List<Reporter> initReporters(DataSource dataSource) throws SQLException {
try (Connection conn = dataSource.getConnection()) {
reporterFactory = ReporterFactoryProvider.createReporterFactory(compatibilityProxy);
return getReporterManager().initReporters(conn, reporterFactory, compatibilityProxy);
}
}

/** Returns FileMapperOptions for the first item of a given param list in a baseDir
*
* @param pathParams
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/utplsql/cli/VersionInfoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public ConnectionInfo getConnectionInfo() {

public int run() {

LoggerConfiguration.configure(true, false );

System.out.println(CliVersionInfo.getInfo());
System.out.println(JavaApiVersionInfo.getInfo());

Expand Down
Loading