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

Skip to content

Bugfix/Locale-Info and Nullpointer #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ ALTER SESSION SET NLS_LANGUAGE='AMERICAN';
ALTER SESSION SET NLS_TERRITORY='AMERICA';
```

## Charset

Java will use the default charset of your system for any string output.
You can change this by passing the `-Dfile.encoding` property to the JVM when running a java-application.
To avoid changing the utPLSQL-cli shell- or batchscript, you can define `-Dfile.encoding` in the environment variable `JAVA_TOOL_OPTIONS`.
This environment variable will be picked up and interpreted by the JVM:

```
export JAVA_TOOL_OPTIONS='-Dfile.encoding=utf8'
utplsql run user/pw@connecstring

> Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=utf8
```

Make sure that the defined charset matches with the codepage your console is using.

## Usage
Currently, utPLSQL-cli supports the following sub-commands:
- run
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>com.oracle.jdbc</groupId>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>ucp</artifactId>
</exclusion>
<exclusion>
<groupId>com.oracle.jdbc</groupId>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>ojdbc8</artifactId>
</exclusion>
<exclusion>
<groupId>com.oracle.jdbc</groupId>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>orai18n</artifactId>
</exclusion>
</exclusions>
Expand Down Expand Up @@ -67,7 +67,7 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<dependency>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>orai18n</artifactId>
<version>${oracle.jdbc.version}</version>
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/org/utplsql/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ public static void main(String[] args) {

static int runPicocliWithExitCode(String[] args) {

LoggerConfiguration.configure(LoggerConfiguration.ConfigLevel.NONE);
LocaleInitializer.initLocale();

CommandLine commandLine = new CommandLine(UtplsqlPicocliCommand.class);
commandLine.setTrimQuotes(true);

Expand Down
10 changes: 9 additions & 1 deletion src/main/java/org/utplsql/cli/LocaleInitializer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.utplsql.cli;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.utplsql.api.EnvironmentVariableUtil;

import java.util.Locale;
Expand All @@ -18,6 +20,8 @@
*/
class LocaleInitializer {

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

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

/**
Expand All @@ -27,7 +31,10 @@ static void initLocale() {

boolean localeChanged = setDefaultLocale(EnvironmentVariableUtil.getEnvValue("LC_ALL"));
if (!localeChanged) {
setDefaultLocale(EnvironmentVariableUtil.getEnvValue("LANG"));
localeChanged = setDefaultLocale(EnvironmentVariableUtil.getEnvValue("LANG"));
}
if ( !localeChanged ) {
logger.debug("Java Locale not changed from LC_ALL or LANG environment variable");
}
}

Expand All @@ -54,6 +61,7 @@ private static boolean setDefaultLocale(String localeString) {
Locale l = new Locale.Builder().setLanguageTag(sb.toString()).build();
if (l != null) {
Locale.setDefault(l);
logger.debug("Java Locale changed to {}", l);
return true;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/utplsql/cli/ReportersCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class ReportersCommand implements ICommand {

@Override
public int run() {
LoggerConfiguration.configure(LoggerConfiguration.ConfigLevel.NONE);

try {
DataSource ds = DataSourceProvider.getDataSource(connectionString, 1);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/utplsql/cli/RunAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public RunAction(RunCommandConfig config) {

void init() {
LoggerConfiguration.configure(config.getLogConfigLevel());
LocaleInitializer.initLocale();
}

public RunCommandConfig getConfig() {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/utplsql/cli/VersionInfoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class VersionInfoCommand implements ICommand {
boolean help;

public int run() {
LoggerConfiguration.configure(LoggerConfiguration.ConfigLevel.NONE);

System.out.println(CliVersionInfo.getInfo());
System.out.println(JavaApiVersionInfo.getInfo());
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/org/utplsql/cli/config/ReporterConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.utplsql.cli.config;

import org.utplsql.api.reporter.CoreReporters;

import java.beans.ConstructorProperties;

public class ReporterConfig {
Expand All @@ -10,7 +12,11 @@ public class ReporterConfig {

@ConstructorProperties({"name", "output", "forceToScreen"})
public ReporterConfig(String name, String output, Boolean forceToScreen) {
this.name = name;
if ( name != null ) {
this.name = name;
} else {
this.name = CoreReporters.UT_DOCUMENTATION_REPORTER.name();
}
this.output = output;
if (forceToScreen != null) this.forceToScreen = forceToScreen;
}
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/org/utplsql/cli/PicocliRunCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ void multipleReporters() throws Exception {
assertTrue(reporterConfig.isForceToScreen());
}

@Test
void outputWithDefaultReporter() throws Exception {
RunCommandConfig config = parseForConfig("run",
TestHelper.getConnectionString(),
"-o=output1.txt");

assertNotNull( config.getReporters() );

ReporterConfig reporterConfig = config.getReporters()[0];
assertEquals("ut_documentation_reporter", reporterConfig.getName().toLowerCase());
assertEquals("output1.txt", reporterConfig.getOutput());
assertFalse(reporterConfig.isForceToScreen());
}

@Test
void sourceFileMapping() throws Exception {
RunCommandConfig config = parseForConfig("run",
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/org/utplsql/cli/RunCommandIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,18 @@ void run_withDbmsOutputEnabled() throws Exception {

assertValidReturnCode(result);
}

@Test
void run_withOutputButNoReporterDefined() throws Exception {

String outputFileName = "output_" + System.currentTimeMillis() + ".xml";
addTempPath(Paths.get(outputFileName));

int result = TestHelper.runApp("run",
TestHelper.getConnectionString(),
"-o=" + outputFileName,
"--failure-exit-code=2");

assertValidReturnCode(result);
}
}