Skip to content
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

Remove Guava from JDBC module #401

Merged
merged 2 commits into from
Jul 18, 2017
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
### Fixed

### Changed
- Removed Guava usage from `jdbc` module (#401)

## [1.4.1] - 2017-07-10
### Fixed
Expand Down
51 changes: 0 additions & 51 deletions modules/jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,57 +18,6 @@
<artifactId>testcontainers</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<relocations>
<relocation>
<pattern>com.google</pattern>
<shadedPattern>org.testcontainers.shaded.com.google</shadedPattern>
</relocation>
</relocations>
<artifactSet>
<includes>
<include>com.google.guava:*</include>
</includes>
</artifactSet>
<promoteTransitiveDependencies>false</promoteTransitiveDependencies>
<shadedArtifactAttached>false</shadedArtifactAttached>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/NOTICE</exclude>
<exclude>META-INF/LICENSE</exclude>
<exclude>META-INF/DEPENDENCIES</exclude>
<exclude>META-INF/maven/</exclude>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.testcontainers.jdbc;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Charsets;
import com.google.common.io.Resources;
import org.apache.commons.io.IOUtils;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.JdbcDatabaseContainerProvider;
Expand All @@ -13,6 +11,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.sql.*;
import java.util.*;
import java.util.logging.Logger;
Expand Down Expand Up @@ -223,10 +222,16 @@ private void runInitScriptIfRequired(String url, Connection connection) throws S
if (matcher.matches()) {
String initScriptPath = matcher.group(2);
try {
URL resource = Resources.getResource(initScriptPath);
String sql = Resources.toString(resource, Charsets.UTF_8);
URL resource = Thread.currentThread().getContextClassLoader().getResource(initScriptPath);

if (resource == null) {
LOGGER.warn("Could not load classpath init script: {}", initScriptPath);
throw new SQLException("Could not load classpath init script: " + initScriptPath + ". Resource not found.");
}

String sql = IOUtils.toString(resource, StandardCharsets.UTF_8);
ScriptUtils.executeSqlScript(connection, initScriptPath, sql);
} catch (IOException | IllegalArgumentException e) {
} catch (IOException e) {
LOGGER.warn("Could not load classpath init script: {}", initScriptPath);
throw new SQLException("Could not load classpath init script: " + initScriptPath, e);
} catch (ScriptException e) {
Expand Down Expand Up @@ -324,7 +329,6 @@ public static void killContainer(String jdbcUrl) {
* @param jdbcUrl the JDBC URL of the container instance to get
* @return an instance of database container or <code>null</code> if no container associated with JDBC URL
*/
@VisibleForTesting
static JdbcDatabaseContainer getContainer(String jdbcUrl) {
synchronized (jdbcUrlContainerCache) {
return jdbcUrlContainerCache.get(jdbcUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

package org.testcontainers.jdbc.ext;

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

Preconditions.checkArgument(!Strings.isNullOrEmpty(script), "script must not be null or empty");
Preconditions.checkArgument(separator != null, "separator must not be null");
Preconditions.checkArgument(!Strings.isNullOrEmpty(commentPrefix), "commentPrefix must not be null or empty");
Preconditions.checkArgument(!Strings.isNullOrEmpty(blockCommentStartDelimiter), "blockCommentStartDelimiter must not be null or empty");
Preconditions.checkArgument(!Strings.isNullOrEmpty(blockCommentEndDelimiter), "blockCommentEndDelimiter must not be null or empty");
checkArgument(StringUtils.isNotEmpty(script), "script must not be null or empty");
checkArgument(separator != null, "separator must not be null");
checkArgument(StringUtils.isNotEmpty(commentPrefix), "commentPrefix must not be null or empty");
checkArgument(StringUtils.isNotEmpty(blockCommentStartDelimiter), "blockCommentStartDelimiter must not be null or empty");
checkArgument(StringUtils.isNotEmpty(blockCommentEndDelimiter), "blockCommentEndDelimiter must not be null or empty");

StringBuilder sb = new StringBuilder();
boolean inLiteral = false;
Expand Down Expand Up @@ -183,11 +182,17 @@ else if (c == ' ' || c == '\n' || c == '\t') {
}
sb.append(c);
}
if (!Strings.isNullOrEmpty(sb.toString())) {
if (StringUtils.isNotEmpty(sb.toString())) {
statements.add(sb.toString());
}
}

private static void checkArgument(boolean expression, String errorMessage) {
if (!expression) {
throw new IllegalArgumentException(errorMessage);
}
}

/**
* Does the provided SQL script contain the specified delimiter?
* @param script the SQL script
Expand Down