Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
simasch committed Jul 11, 2023
2 parents 5a59b72 + 2240fee commit c29a3f7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ This is a collection of classes, that makes it easy to access the [utPLSQL v3](h

This is a Maven Library project, you can add on your Java project as a dependency.

*Notice: You no longer need to configure an additional repository. The library is available in Maven Central since version 3.1.15.*

```xml
<dependency>
<groupId>org.utplsql</groupId>
<artifactId>utplsql-java-api</artifactId>
<version>3.1.10</version>
<version>3.1.16</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.utplsql</groupId>
<artifactId>utplsql-java-api</artifactId>
<version>3.1.15</version>
<version>3.1.16</version>

<name>utPLSQL Java API</name>
<description>Java API for running Unit Tests with utPLSQL v3+.</description>
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/org/utplsql/api/EnvironmentVariableUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.utplsql.api;

import javax.annotation.Nullable;

/**
* This class provides an easy way to get environmental variables.
* This is mainly to improve testability but also to standardize the way how utPLSQL API and CLI read from
* environment.
* <p>
* Variables are obtained from the following scopes in that order (chain breaks as soon as a value is obtained):
* <ul>
* <li>Properties (System.getProperty())</li>
* <li>Environment (System.getEnv())</li>
* <li>Default value</li>
* </ul>
* <p>
* An empty string is treated the same as null.
*
* @author pesse
*/
public class EnvironmentVariableUtil {

private EnvironmentVariableUtil() {
}

/**
* Returns the value for a given key from environment (see class description)
*
* @param key Key of environment or property value
* @return Environment value or null
*/
public static String getEnvValue(String key) {
return getEnvValue(key, null);
}

/**
* Returns the value for a given key from environment or a default value (see class description)
*
* @param key Key of environment or property value
* @param defaultValue Default value if nothing found
* @return Environment value or defaultValue
*/
public static String getEnvValue(String key, @Nullable String defaultValue) {

String val = System.getProperty(key);
if (val == null || val.isEmpty()) val = System.getenv(key);
if (val == null || val.isEmpty()) val = defaultValue;

return val;
}


}

0 comments on commit c29a3f7

Please sign in to comment.