diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2020-03-03 15:15:40 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2020-03-21 20:04:01 +0000 |
commit | 3351fb7e24c0c1e420cc7524029a735198f30ccf (patch) | |
tree | 59f3f2c8334b64bc73ad3f997c06399d1dff0555 /server | |
parent | 1324596989bf50752ef6bb44c3127fc2b8d9fae5 (diff) | |
download | sonarqube-3351fb7e24c0c1e420cc7524029a735198f30ccf.tar.gz sonarqube-3351fb7e24c0c1e420cc7524029a735198f30ccf.zip |
SONAR-13155 Drop usage of commons-dbutils
except for unit tests
Diffstat (limited to 'server')
10 files changed, 21 insertions, 20 deletions
diff --git a/server/sonar-db-core/build.gradle b/server/sonar-db-core/build.gradle index f8bb54ca373..2ab4e3e0148 100644 --- a/server/sonar-db-core/build.gradle +++ b/server/sonar-db-core/build.gradle @@ -10,7 +10,6 @@ dependencies { compile 'ch.qos.logback:logback-classic' compile 'ch.qos.logback:logback-core' compile 'com.google.guava:guava' - compile 'commons-dbutils:commons-dbutils' compile 'commons-io:commons-io' compile 'commons-lang:commons-lang' compile 'org.apache.commons:commons-dbcp2' @@ -37,6 +36,7 @@ dependencies { testRuntime 'com.oracle.jdbc:ojdbc8' testRuntime 'org.postgresql:postgresql' + testFixturesApi 'commons-dbutils:commons-dbutils' testFixturesApi 'junit:junit' testFixturesApi 'org.assertj:assertj-core' diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/DefaultDatabase.java b/server/sonar-db-core/src/main/java/org/sonar/db/DefaultDatabase.java index 02c4ad51fc7..40991c11ca9 100644 --- a/server/sonar-db-core/src/main/java/org/sonar/db/DefaultDatabase.java +++ b/server/sonar-db-core/src/main/java/org/sonar/db/DefaultDatabase.java @@ -30,7 +30,6 @@ import java.util.Properties; import javax.sql.DataSource; import org.apache.commons.dbcp2.BasicDataSource; import org.apache.commons.dbcp2.BasicDataSourceFactory; -import org.apache.commons.dbutils.DbUtils; import org.apache.commons.lang.StringUtils; import org.sonar.api.config.Settings; import org.sonar.api.utils.log.Logger; @@ -118,7 +117,7 @@ public class DefaultDatabase implements Database { } catch (SQLException e) { throw new IllegalStateException("Can not connect to database. Please check connectivity and settings (see the properties prefixed by 'sonar.jdbc.').", e); } finally { - DbUtils.closeQuietly(connection); + DatabaseUtils.closeQuietly(connection); } } diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/ResultSetIterator.java b/server/sonar-db-core/src/main/java/org/sonar/db/ResultSetIterator.java index 0264b9d655a..bc6ab1f167b 100644 --- a/server/sonar-db-core/src/main/java/org/sonar/db/ResultSetIterator.java +++ b/server/sonar-db-core/src/main/java/org/sonar/db/ResultSetIterator.java @@ -25,7 +25,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.Iterator; import java.util.NoSuchElementException; -import org.apache.commons.dbutils.DbUtils; /** * Forward-only {@link java.util.Iterator} over a {@link java.sql.ResultSet}. Rows are @@ -98,8 +97,8 @@ public abstract class ResultSetIterator<E> implements Iterator<E>, Closeable { @Override public void close() { closed = true; - DbUtils.closeQuietly(rs); - DbUtils.closeQuietly(stmt); + DatabaseUtils.closeQuietly(rs); + DatabaseUtils.closeQuietly(stmt); } protected abstract E read(ResultSet rs) throws SQLException; diff --git a/server/sonar-db-dao/build.gradle b/server/sonar-db-dao/build.gradle index 2b0f2d86f6e..b443df09fd4 100644 --- a/server/sonar-db-dao/build.gradle +++ b/server/sonar-db-dao/build.gradle @@ -9,7 +9,6 @@ dependencies { compile 'com.google.guava:guava' compile 'com.google.protobuf:protobuf-java' - compile 'commons-dbutils:commons-dbutils' compile 'commons-io:commons-io' compile 'commons-lang:commons-lang' compile 'net.jpountz.lz4:lz4' @@ -23,6 +22,7 @@ dependencies { compileOnly 'com.google.code.findbugs:jsr305' testCompile 'com.tngtech.java:junit-dataprovider' + testCompile 'commons-dbutils:commons-dbutils' testCompile 'junit:junit' testCompile 'org.assertj:assertj-core' testCompile 'org.assertj:assertj-guava' diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/source/FileSourceDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/source/FileSourceDao.java index ff006368b28..b2e3a0daf1d 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/source/FileSourceDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/source/FileSourceDao.java @@ -30,10 +30,10 @@ import java.util.Collections; import java.util.List; import java.util.function.Consumer; import javax.annotation.CheckForNull; -import org.apache.commons.dbutils.DbUtils; import org.apache.commons.io.IOUtils; import org.apache.ibatis.session.ResultHandler; import org.sonar.db.Dao; +import org.sonar.db.DatabaseUtils; import org.sonar.db.DbSession; import static org.sonar.db.DatabaseUtils.toUniqueAndSortedPartitions; @@ -73,7 +73,9 @@ public class FileSourceDao implements Dao { } catch (SQLException e) { throw new IllegalStateException("Fail to read FILE_SOURCES.LINE_HASHES of file " + fileUuid, e); } finally { - DbUtils.closeQuietly(connection, pstmt, rs); + DatabaseUtils.closeQuietly(rs); + DatabaseUtils.closeQuietly(pstmt); + DatabaseUtils.closeQuietly(connection); } } @@ -106,7 +108,9 @@ public class FileSourceDao implements Dao { throw new IllegalStateException("Fail to read FILE_SOURCES.LINE_HASHES of file " + fileUuid, e); } finally { IOUtils.closeQuietly(reader); - DbUtils.closeQuietly(connection, pstmt, rs); + DatabaseUtils.closeQuietly(rs); + DatabaseUtils.closeQuietly(pstmt); + DatabaseUtils.closeQuietly(connection); } } diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/SQDatabase.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/SQDatabase.java index 1c4ab5125a4..b04f133ee51 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/SQDatabase.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/SQDatabase.java @@ -24,7 +24,6 @@ import java.sql.Connection; import java.sql.SQLException; import java.util.List; import javax.sql.DataSource; -import org.apache.commons.dbutils.DbUtils; import org.apache.commons.io.output.NullWriter; import org.apache.ibatis.io.Resources; import org.apache.ibatis.jdbc.ScriptRunner; @@ -97,7 +96,7 @@ public class SQDatabase extends DefaultDatabase { } catch (SQLException e) { throw new IllegalStateException("Fail to create schema", e); } finally { - DbUtils.closeQuietly(connection); + DatabaseUtils.closeQuietly(connection); } } diff --git a/server/sonar-db-migration/build.gradle b/server/sonar-db-migration/build.gradle index 4dd9a0d0b58..b6d51d37714 100644 --- a/server/sonar-db-migration/build.gradle +++ b/server/sonar-db-migration/build.gradle @@ -11,7 +11,6 @@ dependencies { compile 'commons-lang:commons-lang' compile 'commons-codec:commons-codec' compile 'org.picocontainer:picocontainer' - compile 'commons-dbutils:commons-dbutils' compile project(':server:sonar-db-core') compile project(':server:sonar-process') @@ -21,6 +20,7 @@ dependencies { testCompile 'com.google.code.findbugs:jsr305' testCompile 'com.tngtech.java:junit-dataprovider' + testCompile 'commons-dbutils:commons-dbutils' testCompile 'junit:junit' testCompile 'org.assertj:assertj-core' testCompile 'org.mindrot:jbcrypt' diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/BaseSqlStatement.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/BaseSqlStatement.java index 2d7af722ab9..e02bc9de48b 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/BaseSqlStatement.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/BaseSqlStatement.java @@ -25,7 +25,7 @@ import java.sql.Timestamp; import java.sql.Types; import java.util.Date; import javax.annotation.Nullable; -import org.apache.commons.dbutils.DbUtils; +import org.sonar.db.DatabaseUtils; class BaseSqlStatement<CHILD extends SqlStatement> implements SqlStatement<CHILD> { protected PreparedStatement pstmt; @@ -36,7 +36,7 @@ class BaseSqlStatement<CHILD extends SqlStatement> implements SqlStatement<CHILD @Override public void close() { - DbUtils.closeQuietly(pstmt); + DatabaseUtils.closeQuietly(pstmt); pstmt = null; } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/SelectImpl.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/SelectImpl.java index 923f6836b78..2cfb5df9c77 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/SelectImpl.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/SelectImpl.java @@ -25,8 +25,8 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import org.apache.commons.dbutils.DbUtils; import org.sonar.db.Database; +import org.sonar.db.DatabaseUtils; public class SelectImpl extends BaseSqlStatement<Select> implements Select { @@ -47,7 +47,7 @@ public class SelectImpl extends BaseSqlStatement<Select> implements Select { } catch (Exception e) { throw newExceptionWithRowDetails(row, e); } finally { - DbUtils.closeQuietly(rs); + DatabaseUtils.closeQuietly(rs); close(); } } @@ -64,7 +64,7 @@ public class SelectImpl extends BaseSqlStatement<Select> implements Select { } catch (Exception e) { throw newExceptionWithRowDetails(row, e); } finally { - DbUtils.closeQuietly(rs); + DatabaseUtils.closeQuietly(rs); close(); } } @@ -80,7 +80,7 @@ public class SelectImpl extends BaseSqlStatement<Select> implements Select { } catch (Exception e) { throw newExceptionWithRowDetails(row, e); } finally { - DbUtils.closeQuietly(rs); + DatabaseUtils.closeQuietly(rs); close(); } } diff --git a/server/sonar-webserver-core/build.gradle b/server/sonar-webserver-core/build.gradle index 221d8981d55..519e02a0f9a 100644 --- a/server/sonar-webserver-core/build.gradle +++ b/server/sonar-webserver-core/build.gradle @@ -23,7 +23,6 @@ dependencies { compile 'ch.qos.logback:logback-core' compile 'com.google.code.gson:gson' compile 'com.google.protobuf:protobuf-java' - compile 'commons-dbutils:commons-dbutils' compile 'io.jsonwebtoken:jjwt-api' compile 'io.jsonwebtoken:jjwt-impl' compile 'org.apache.httpcomponents:httpclient' @@ -61,6 +60,7 @@ dependencies { testCompile 'com.h2database:h2' testCompile 'com.squareup.okhttp3:mockwebserver' testCompile 'com.tngtech.java:junit-dataprovider' + testCompile 'commons-dbutils:commons-dbutils' testCompile 'org.apache.logging.log4j:log4j-api' testCompile 'org.apache.logging.log4j:log4j-core' testCompile 'org.assertj:assertj-core' |