Skip to content

Commit 4641383

Browse files
bsideuprnorth
authored andcommitted
Remove Guava from JDBC module (#401)
* Remove Guava from JDBC module
1 parent 20755cf commit 4641383

File tree

4 files changed

+25
-66
lines changed

4 files changed

+25
-66
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
55
### Fixed
66

77
### Changed
8+
- Removed Guava usage from `jdbc` module (#401)
89

910
## [1.4.1] - 2017-07-10
1011
### Fixed

modules/jdbc/pom.xml

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -18,57 +18,6 @@
1818
<artifactId>testcontainers</artifactId>
1919
<version>${project.version}</version>
2020
</dependency>
21-
<dependency>
22-
<groupId>com.google.guava</groupId>
23-
<artifactId>guava</artifactId>
24-
<version>18.0</version>
25-
</dependency>
2621
</dependencies>
2722

28-
<build>
29-
<plugins>
30-
<plugin>
31-
<artifactId>maven-shade-plugin</artifactId>
32-
<version>3.0.0</version>
33-
<executions>
34-
<execution>
35-
<phase>package</phase>
36-
<goals>
37-
<goal>shade</goal>
38-
</goals>
39-
</execution>
40-
</executions>
41-
<configuration>
42-
<relocations>
43-
<relocation>
44-
<pattern>com.google</pattern>
45-
<shadedPattern>org.testcontainers.shaded.com.google</shadedPattern>
46-
</relocation>
47-
</relocations>
48-
<artifactSet>
49-
<includes>
50-
<include>com.google.guava:*</include>
51-
</includes>
52-
</artifactSet>
53-
<promoteTransitiveDependencies>false</promoteTransitiveDependencies>
54-
<shadedArtifactAttached>false</shadedArtifactAttached>
55-
<filters>
56-
<filter>
57-
<artifact>*:*</artifact>
58-
<excludes>
59-
<exclude>META-INF/NOTICE</exclude>
60-
<exclude>META-INF/LICENSE</exclude>
61-
<exclude>META-INF/DEPENDENCIES</exclude>
62-
<exclude>META-INF/maven/</exclude>
63-
<exclude>META-INF/*.SF</exclude>
64-
<exclude>META-INF/*.DSA</exclude>
65-
<exclude>META-INF/*.RSA</exclude>
66-
</excludes>
67-
</filter>
68-
</filters>
69-
</configuration>
70-
</plugin>
71-
</plugins>
72-
</build>
73-
7423
</project>

modules/jdbc/src/main/java/org/testcontainers/jdbc/ContainerDatabaseDriver.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package org.testcontainers.jdbc;
22

3-
import com.google.common.annotations.VisibleForTesting;
4-
import com.google.common.base.Charsets;
5-
import com.google.common.io.Resources;
3+
import org.apache.commons.io.IOUtils;
64
import org.slf4j.LoggerFactory;
75
import org.testcontainers.containers.JdbcDatabaseContainer;
86
import org.testcontainers.containers.JdbcDatabaseContainerProvider;
@@ -13,6 +11,7 @@
1311
import java.lang.reflect.InvocationTargetException;
1412
import java.lang.reflect.Method;
1513
import java.net.URL;
14+
import java.nio.charset.StandardCharsets;
1615
import java.sql.*;
1716
import java.util.*;
1817
import java.util.logging.Logger;
@@ -223,10 +222,16 @@ private void runInitScriptIfRequired(String url, Connection connection) throws S
223222
if (matcher.matches()) {
224223
String initScriptPath = matcher.group(2);
225224
try {
226-
URL resource = Resources.getResource(initScriptPath);
227-
String sql = Resources.toString(resource, Charsets.UTF_8);
225+
URL resource = Thread.currentThread().getContextClassLoader().getResource(initScriptPath);
226+
227+
if (resource == null) {
228+
LOGGER.warn("Could not load classpath init script: {}", initScriptPath);
229+
throw new SQLException("Could not load classpath init script: " + initScriptPath + ". Resource not found.");
230+
}
231+
232+
String sql = IOUtils.toString(resource, StandardCharsets.UTF_8);
228233
ScriptUtils.executeSqlScript(connection, initScriptPath, sql);
229-
} catch (IOException | IllegalArgumentException e) {
234+
} catch (IOException e) {
230235
LOGGER.warn("Could not load classpath init script: {}", initScriptPath);
231236
throw new SQLException("Could not load classpath init script: " + initScriptPath, e);
232237
} catch (ScriptException e) {
@@ -324,7 +329,6 @@ public static void killContainer(String jdbcUrl) {
324329
* @param jdbcUrl the JDBC URL of the container instance to get
325330
* @return an instance of database container or <code>null</code> if no container associated with JDBC URL
326331
*/
327-
@VisibleForTesting
328332
static JdbcDatabaseContainer getContainer(String jdbcUrl) {
329333
synchronized (jdbcUrlContainerCache) {
330334
return jdbcUrlContainerCache.get(jdbcUrl);

modules/jdbc/src/main/java/org/testcontainers/jdbc/ext/ScriptUtils.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
package org.testcontainers.jdbc.ext;
1818

19-
import com.google.common.base.Preconditions;
20-
import com.google.common.base.Strings;
19+
import org.apache.commons.lang.StringUtils;
2120
import org.slf4j.Logger;
2221
import org.slf4j.LoggerFactory;
2322

@@ -110,11 +109,11 @@ private ScriptUtils() {
110109
public static void splitSqlScript(String resource, String script, String separator, String commentPrefix,
111110
String blockCommentStartDelimiter, String blockCommentEndDelimiter, List<String> statements) {
112111

113-
Preconditions.checkArgument(!Strings.isNullOrEmpty(script), "script must not be null or empty");
114-
Preconditions.checkArgument(separator != null, "separator must not be null");
115-
Preconditions.checkArgument(!Strings.isNullOrEmpty(commentPrefix), "commentPrefix must not be null or empty");
116-
Preconditions.checkArgument(!Strings.isNullOrEmpty(blockCommentStartDelimiter), "blockCommentStartDelimiter must not be null or empty");
117-
Preconditions.checkArgument(!Strings.isNullOrEmpty(blockCommentEndDelimiter), "blockCommentEndDelimiter must not be null or empty");
112+
checkArgument(StringUtils.isNotEmpty(script), "script must not be null or empty");
113+
checkArgument(separator != null, "separator must not be null");
114+
checkArgument(StringUtils.isNotEmpty(commentPrefix), "commentPrefix must not be null or empty");
115+
checkArgument(StringUtils.isNotEmpty(blockCommentStartDelimiter), "blockCommentStartDelimiter must not be null or empty");
116+
checkArgument(StringUtils.isNotEmpty(blockCommentEndDelimiter), "blockCommentEndDelimiter must not be null or empty");
118117

119118
StringBuilder sb = new StringBuilder();
120119
boolean inLiteral = false;
@@ -183,11 +182,17 @@ else if (c == ' ' || c == '\n' || c == '\t') {
183182
}
184183
sb.append(c);
185184
}
186-
if (!Strings.isNullOrEmpty(sb.toString())) {
185+
if (StringUtils.isNotEmpty(sb.toString())) {
187186
statements.add(sb.toString());
188187
}
189188
}
190189

190+
private static void checkArgument(boolean expression, String errorMessage) {
191+
if (!expression) {
192+
throw new IllegalArgumentException(errorMessage);
193+
}
194+
}
195+
191196
/**
192197
* Does the provided SQL script contain the specified delimiter?
193198
* @param script the SQL script

0 commit comments

Comments
 (0)