Skip to content

Commit c147d5c

Browse files
author
Samuel Nitsche
committed
Merge remote-tracking branch 'origin/feature/version-check' into bugfix/exclude_jdbc_jars
2 parents 5401f35 + b4ef181 commit c147d5c

File tree

12 files changed

+408
-288
lines changed

12 files changed

+408
-288
lines changed

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,35 @@
11
sudo: required
22
language: java
33

4+
services:
5+
- docker
6+
47
jdk:
58
- oraclejdk8
69

710
env:
811
global:
12+
- DOCKER_CFG=$HOME/.docker
913
- CACHE_DIR=$HOME/.cache
1014
- MAVEN_HOME=/usr/local/maven
1115
- MAVEN_CFG=$HOME/.m2
16+
- DB_URL="127.0.0.1:1521:XE"
17+
- DB_USER=app
18+
- DB_PASS=app
19+
matrix:
20+
- ORACLE_VERSION="11g-xe-r2" DOCKER_OPTIONS="--shm-size=1g"
1221

1322
cache:
1423
directories:
24+
- $DOCKER_CFG
1525
- $CACHE_DIR
1626
- $MAVEN_CFG
1727

1828
install:
1929
- bash .travis/maven_cfg.sh
30+
- bash .travis/start_db.sh
31+
- bash .travis/install_utplsql.sh
32+
- bash .travis/install_demo_project.sh
2033

2134
script:
2235
- mvn package -DskipTests

.travis/create_api_user.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
set -ev
3+
4+
sqlplus -S -L sys/oracle@//127.0.0.1:1521/xe AS SYSDBA <<EOF
5+
create user api identified by api
6+
quota unlimited on USERS
7+
default tablespace USERS;
8+
grant create session,
9+
create procedure,
10+
create type,
11+
create table,
12+
create sequence,
13+
create view
14+
to api;
15+
grant select any dictionary to api;
16+
exit;
17+
EOF

.travis/install_demo_project.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
set -ev
3+
cd $(dirname $(readlink -f $0))
4+
5+
PROJECT_FILE="utPLSQL-demo-project"
6+
git clone -b develop --single-branch https://github.com/utPLSQL/utPLSQL-demo-project.git
7+
8+
cat > demo_project.sh.tmp <<EOF
9+
sqlplus -S -L sys/oracle@//127.0.0.1:1521/xe AS SYSDBA <<SQL
10+
create user ${DB_USER} identified by ${DB_PASS} quota unlimited on USERS default tablespace USERS;
11+
grant create session, create procedure, create type, create table, create sequence, create view to ${DB_USER};
12+
grant select any dictionary to ${DB_USER};
13+
exit
14+
SQL
15+
16+
cd ${PROJECT_FILE}
17+
sqlplus -S -L ${DB_USER}/${DB_PASS}@//127.0.0.1:1521/xe <<SQL
18+
whenever sqlerror exit failure rollback
19+
whenever oserror exit failure rollback
20+
21+
@source/award_bonus/employees_test.sql
22+
@source/award_bonus/award_bonus.prc
23+
24+
@source/between_string/betwnstr.fnc
25+
26+
@source/remove_rooms_by_name/rooms.sql
27+
@source/remove_rooms_by_name/remove_rooms_by_name.prc
28+
29+
@test/award_bonus/test_award_bonus.pks
30+
@test/award_bonus/test_award_bonus.pkb
31+
32+
@test/between_string/test_betwnstr.pks
33+
@test/between_string/test_betwnstr.pkb
34+
35+
@test/remove_rooms_by_name/test_remove_rooms_by_name.pks
36+
@test/remove_rooms_by_name/test_remove_rooms_by_name.pkb
37+
38+
exit
39+
SQL
40+
EOF
41+
42+
docker cp ./$PROJECT_FILE $ORACLE_VERSION:/$PROJECT_FILE
43+
docker cp ./demo_project.sh.tmp $ORACLE_VERSION:/demo_project.sh
44+
docker exec $ORACLE_VERSION bash demo_project.sh

.travis/install_utplsql.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
set -ev
3+
cd $(dirname $(readlink -f $0))
4+
5+
# Download the specified version of utPLSQL.
6+
UTPLSQL_VERSION="v3.0.4"
7+
UTPLSQL_FILE="utPLSQL"
8+
curl -L -O "https://github.com/utPLSQL/utPLSQL/releases/download/$UTPLSQL_VERSION/$UTPLSQL_FILE.tar.gz"
9+
10+
# Download develop branch of utPLSQL.
11+
#UTPLSQL_VERSION="develop"
12+
#UTPLSQL_FILE="utPLSQL"
13+
#git clone -b develop --single-branch https://github.com/utPLSQL/utPLSQL.git
14+
# tar -czf $UTPLSQL_FILE.tar.gz $UTPLSQL_FILE && rm -rf $UTPLSQL_FILE
15+
16+
# Create a temporary install script.
17+
cat > install.sh.tmp <<EOF
18+
tar -xzf ${UTPLSQL_FILE}.tar.gz && rm ${UTPLSQL_FILE}.tar.gz
19+
cd ${UTPLSQL_FILE}/source
20+
sqlplus -S -L sys/oracle@//127.0.0.1:1521/xe AS SYSDBA @install_headless.sql ut3 ut3 users
21+
EOF
22+
23+
# Copy utPLSQL files to the container and install it.
24+
docker cp ./$UTPLSQL_FILE.tar.gz $ORACLE_VERSION:/$UTPLSQL_FILE.tar.gz
25+
# docker cp ./$UTPLSQL_FILE $ORACLE_VERSION:/$UTPLSQL_FILE
26+
docker cp ./install.sh.tmp $ORACLE_VERSION:/install.sh
27+
docker cp ./create_api_user.sh $ORACLE_VERSION:/create_api_user.sh
28+
29+
# Remove temporary files.
30+
# rm $UTPLSQL_FILE.tar.gz
31+
rm -rf $UTPLSQL_FILE
32+
rm install.sh.tmp
33+
34+
# Execute the utPLSQL installation inside the container.
35+
docker exec $ORACLE_VERSION bash install.sh
36+
docker exec $ORACLE_VERSION bash create_api_user.sh

.travis/start_db.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
set -ev
3+
4+
# If docker credentials are not cached, do the login.
5+
if [ ! -f $DOCKER_CFG/config.json ]; then
6+
docker login -u "$DOCKER_USER" -p "$DOCKER_PASSWORD"
7+
else
8+
echo "Using docker login from cache..."
9+
fi
10+
11+
# Pull the specified db version from docker hub.
12+
docker pull $DOCKER_REPO:$ORACLE_VERSION
13+
docker run -d --name $ORACLE_VERSION $DOCKER_OPTIONS -p 1521:1521 $DOCKER_REPO:$ORACLE_VERSION
14+
docker logs -f $ORACLE_VERSION | grep -m 1 "DATABASE IS READY TO USE!" --line-buffered

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ You can download development versions on [Bintray](https://bintray.com/viniciusa
1616
* [Java SE Runtime Environment 8](http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html)
1717
* When using reporters for Sonar or Coveralls client needs to be invoked from project's root directory.
1818

19+
## Compatibility
20+
The latest CLI is always compatible with all database frameworks of the same major version.
21+
For example CLI-3.0.4 is compatible with database framework 3.0.0-3.0.4 but not with database framework 2.x.
22+
1923
## Usage
20-
utplsql run user/pass@[[host][:port]/]db [-p=(ut_path|ut_paths)] [-f=format [-o=output_file] [-s] ...]
24+
utplsql run \<ConnectionURL\> [-p=(ut_path|ut_paths)] [-f=format [-o=output_file] [-s] ...]
2125

2226
```
23-
user - Username to connect as.
24-
password - Password of the user.
25-
host - Server address, defaults to 127.0.0.1.
26-
port - Server port, defaults to 1521.
27-
db - Database to connect to.
27+
<ConnectionURL> - <user>/<password>@//<host>[:<port>]/<service> OR <user>/<password>@<TNSName> OR <user>/<password>@<host>:<port>:<SID>
28+
To connect using TNS, you need to have the ORACLE_HOME environment variable set.
2829
-p=suite_path(s) - A suite path or a comma separated list of suite paths for unit test to be executed.
2930
The path(s) can be in one of the following formats:
3031
schema[.package[.procedure]]
@@ -77,6 +78,8 @@ db - Database to connect to.
7778
-c - If specified, enables printing of test results in colors as defined by ANSICONSOLE standards.
7879
Works only on reporeters that support colors (ut_documentation_reporter).
7980
--failure-exit-code - Override the exit code on failure, defaults to 1. You can set it to 0 to always exit with a success status.
81+
-scc - If specified, skips the compatibility-check with the version of the database framework.
82+
If you skip compatibility-check, CLI will expect the most actual framework version
8083
```
8184

8285
Parameters -f, -o, -s are correlated. That is parameters -o and -s are controlling outputs for reporter specified by the preceding -f parameter.

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>org.utplsql</groupId>
66
<artifactId>cli</artifactId>
7-
<version>1.0-SNAPSHOT</version>
7+
<version>3.0.4-SNAPSHOT</version>
88
<packaging>jar</packaging>
99

1010
<name>cli</name>
@@ -20,7 +20,7 @@
2020
<dependency>
2121
<groupId>org.utplsql</groupId>
2222
<artifactId>java-api</artifactId>
23-
<version>1.0-SNAPSHOT</version>
23+
<version>3.0.4-SNAPSHOT</version>
2424
<scope>compile</scope>
2525
</dependency>
2626
<dependency>
Lines changed: 25 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,138 +1,45 @@
11
package org.utplsql.cli;
22

3-
import com.beust.jcommander.ParameterException;
3+
import com.beust.jcommander.IStringConverter;
4+
import oracle.ucp.jdbc.PoolDataSource;
5+
import oracle.ucp.jdbc.PoolDataSourceFactory;
46

7+
import java.io.File;
58
import java.sql.Connection;
6-
import java.sql.DriverManager;
79
import java.sql.SQLException;
810

9-
/**
10-
* Created by Vinicius on 21/04/2017.
11-
*/
1211
public class ConnectionInfo {
1312

14-
private static final String DEFAULT_HOST = "127.0.0.1";
15-
private static final int DEFAULT_PORT = 1521;
16-
17-
private String user;
18-
private String password;
19-
private String host;
20-
private int port;
21-
private String database;
22-
23-
public ConnectionInfo() {}
24-
25-
public Connection getConnection() throws SQLException {
26-
return DriverManager.getConnection(getConnectionUrl(), getUser(), getPassword());
27-
}
28-
29-
public ConnectionInfo parseConnectionString(String connectionString)
30-
throws ParameterException, IllegalArgumentException {
31-
32-
if (connectionString == null || connectionString.isEmpty())
33-
throw invalidConnectionString();
34-
35-
int i = connectionString.lastIndexOf("@");
36-
if (i == -1)
37-
throw invalidConnectionString();
38-
39-
String credentials = connectionString.substring(0, i);
40-
String host = connectionString.substring(i+1);
41-
parseCredentials(credentials);
42-
parseHost(host);
43-
44-
return this;
45-
}
46-
47-
private void parseCredentials(String str) throws ParameterException, IllegalArgumentException {
48-
int barIdx = str.indexOf("/");
49-
50-
if (barIdx == -1 || barIdx == 0 || barIdx == str.length() - 1)
51-
throw invalidConnectionString();
52-
53-
this.setUser(str.substring(0, barIdx));
54-
this.setPassword(str.substring(barIdx+1));
55-
}
56-
57-
private void parseHost(String str) throws ParameterException, IllegalArgumentException {
58-
if (str == null || str.isEmpty())
59-
throw invalidConnectionString();
60-
61-
int colonIdx = str.indexOf(":");
62-
int barIdx = str.indexOf("/");
63-
64-
if ((colonIdx != -1 && barIdx == -1) || barIdx == 0) // @host:port or // @/db
65-
throw invalidConnectionString();
66-
67-
if (colonIdx != -1) { // @host:port/db
68-
setHost(str.substring(0, colonIdx));
69-
setPort(Integer.parseInt(str.substring(colonIdx + 1, barIdx)));
70-
setDatabase(str.substring(barIdx + 1));
71-
}
72-
else
73-
if (barIdx != -1) { // @host/db
74-
setHost(str.substring(0, barIdx));
75-
setPort(DEFAULT_PORT);
76-
setDatabase(str.substring(barIdx + 1));
77-
}
78-
else { // @db
79-
setHost(DEFAULT_HOST);
80-
setPort(DEFAULT_PORT);
81-
setDatabase(str);
13+
static {
14+
String oracleHome = System.getenv("ORACLE_HOME");
15+
if (oracleHome != null) {
16+
System.setProperty("oracle.net.tns_admin",
17+
String.join(File.separator, oracleHome, "NETWORK", "ADMIN"));
8218
}
8319
}
8420

85-
private ParameterException invalidConnectionString() {
86-
return new ParameterException("Invalid connection string.");
87-
}
88-
89-
public String getUser() {
90-
return user;
91-
}
92-
93-
private void setUser(String user) {
94-
this.user = user;
95-
}
96-
97-
public String getPassword() {
98-
return password;
99-
}
100-
101-
private void setPassword(String password) {
102-
this.password = password;
103-
}
104-
105-
public String getHost() {
106-
return host;
107-
}
21+
private PoolDataSource pds = PoolDataSourceFactory.getPoolDataSource();
10822

109-
private void setHost(String host) {
110-
this.host = host;
111-
}
112-
113-
public int getPort() {
114-
return port;
115-
}
116-
117-
private void setPort(int port) {
118-
this.port = port;
119-
}
120-
121-
public String getDatabase() {
122-
return database;
23+
public ConnectionInfo(String connectionInfo) {
24+
try {
25+
this.pds.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource");
26+
this.pds.setURL("jdbc:oracle:thin:" + connectionInfo);
27+
this.pds.setInitialPoolSize(2);
28+
} catch (SQLException e) {
29+
e.printStackTrace();
30+
}
12331
}
12432

125-
private void setDatabase(String database) {
126-
this.database = database;
33+
public Connection getConnection() throws SQLException {
34+
return pds.getConnection();
12735
}
12836

129-
public String getConnectionUrl() {
130-
return String.format("jdbc:oracle:thin:@//%s:%d/%s", getHost(), getPort(), getDatabase());
131-
}
37+
public static class ConnectionStringConverter implements IStringConverter<ConnectionInfo> {
13238

133-
@Override
134-
public String toString() {
135-
return String.format("%s@%s:%d/%s", getUser(), getHost(), getPort(), getDatabase());
39+
@Override
40+
public ConnectionInfo convert(String s) {
41+
return new ConnectionInfo(s);
42+
}
13643
}
13744

13845
}

src/main/java/org/utplsql/cli/ConnectionStringConverter.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)