diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-02-03 23:10:34 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-02-04 16:48:43 +0100 |
commit | 0053dab746f5e1234e234185958b6970e69e7da6 (patch) | |
tree | e1f3ce19d0fbe7496b7d033bb2304e845e667ffc | |
parent | 1f4b2123afcb0fb70c8e105a5d9820f7761da875 (diff) | |
download | sonarqube-0053dab746f5e1234e234185958b6970e69e7da6.tar.gz sonarqube-0053dab746f5e1234e234185958b6970e69e7da6.zip |
SONAR-6858 remove useless deployment of JDBC driver
5 files changed, 0 insertions, 162 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/DefaultServerFileSystem.java b/server/sonar-server/src/main/java/org/sonar/server/platform/DefaultServerFileSystem.java index 1ef4a639110..2740d708306 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/DefaultServerFileSystem.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/DefaultServerFileSystem.java @@ -116,10 +116,6 @@ public class DefaultServerFileSystem implements ServerFileSystem, Startable { return server.getDeployDir(); } - public File getDeployedJdbcDriverIndex() { - return new File(getDeployDir(), "jdbc-driver.txt"); - } - public File getDeployedPluginsDir() { return new File(getDeployDir(), "plugins"); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java index 56e898325d6..e4d92734ee5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java @@ -29,7 +29,6 @@ import org.sonar.server.search.IndexSynchronizer; import org.sonar.server.startup.ClearRulesOverloadedDebt; import org.sonar.server.startup.DisplayLogOnDeprecatedProjects; import org.sonar.server.startup.GeneratePluginIndex; -import org.sonar.server.startup.JdbcDriverDeployer; import org.sonar.server.startup.LogServerId; import org.sonar.server.startup.RegisterDashboards; import org.sonar.server.startup.RegisterDebtModel; @@ -55,7 +54,6 @@ public class PlatformLevelStartup extends PlatformLevel { RegisterQualityGates.class, RegisterRules.class, RegisterQualityProfiles.class, - JdbcDriverDeployer.class, RegisterDebtModel.class, GeneratePluginIndex.class, RegisterNewMeasureFilters.class, diff --git a/server/sonar-server/src/main/java/org/sonar/server/startup/JdbcDriverDeployer.java b/server/sonar-server/src/main/java/org/sonar/server/startup/JdbcDriverDeployer.java deleted file mode 100644 index af48fb77df5..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/startup/JdbcDriverDeployer.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.startup; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import javax.annotation.Nullable; -import org.apache.commons.codec.digest.DigestUtils; -import org.apache.commons.io.FileUtils; -import org.sonar.api.config.Settings; -import org.sonar.process.ProcessProperties; -import org.sonar.server.platform.DefaultServerFileSystem; - -public class JdbcDriverDeployer { - - private final DefaultServerFileSystem fileSystem; - private final Settings settings; - - public JdbcDriverDeployer(DefaultServerFileSystem fileSystem, Settings settings) { - this.fileSystem = fileSystem; - this.settings = settings; - } - - public void start() { - // see initialization of this property in sonar-application - String driverPath = settings.getString(ProcessProperties.JDBC_DRIVER_PATH); - if (driverPath == null) { - // Medium tests - return; - } - File driver = new File(driverPath); - File deployedDriver = new File(fileSystem.getDeployDir(), driver.getName()); - if (!deployedDriver.exists() || FileUtils.sizeOf(deployedDriver) != FileUtils.sizeOf(driver)) { - try { - FileUtils.copyFile(driver, deployedDriver); - } catch (IOException e) { - throw new IllegalStateException( - String.format("Can not copy the JDBC driver from %s to %s", driver, deployedDriver), e); - } - } - - File deployedDriverIndex = fileSystem.getDeployedJdbcDriverIndex(); - try { - FileUtils.writeStringToFile(deployedDriverIndex, driverIndexContent(deployedDriver)); - } catch (IOException e) { - throw new IllegalStateException("Can not generate index of JDBC driver", e); - } - } - - private static String driverIndexContent(@Nullable File deployedDriver) { - if (deployedDriver != null) { - try (FileInputStream fis = new FileInputStream(deployedDriver)) { - String hash = DigestUtils.md5Hex(fis); - return deployedDriver.getName() + "|" + hash; - } catch (IOException e) { - throw new IllegalStateException("Fail to compute hash", e); - } - } - return ""; - } - -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/startup/JdbcDriverDeployerTest.java b/server/sonar-server/src/test/java/org/sonar/server/startup/JdbcDriverDeployerTest.java deleted file mode 100644 index 10f2863ed1c..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/startup/JdbcDriverDeployerTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.startup; - -import com.google.common.io.Files; -import com.google.common.io.Resources; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.sonar.api.config.Settings; -import org.sonar.server.platform.DefaultServerFileSystem; - -import java.io.File; -import java.nio.charset.StandardCharsets; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class JdbcDriverDeployerTest { - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - @Test - public void test_deploy() throws Exception { - DefaultServerFileSystem fs = mock(DefaultServerFileSystem.class); - File driver = new File(Resources.getResource(getClass(), "JdbcDriverDeployerTest/deploy/my-driver.jar").toURI()); - Settings settings = new Settings(); - settings.setProperty("sonar.jdbc.driverPath", driver.getAbsolutePath()); - - File deployDir = temp.newFolder("deploy"); - when(fs.getDeployDir()).thenReturn(deployDir); - File deployedIndex = new File(deployDir, "jdbc-driver.txt"); - File deployedFile = new File(deployDir, "my-driver.jar"); - assertThat(deployedIndex).doesNotExist(); - assertThat(deployedFile).doesNotExist(); - when(fs.getDeployedJdbcDriverIndex()).thenReturn(deployedIndex); - - new JdbcDriverDeployer(fs, settings).start(); - - assertThat(deployedIndex).exists(); - assertThat(deployedFile).exists(); - assertThat(deployedFile).hasContentEqualTo(driver); - - assertThat(Files.toString(deployedIndex, StandardCharsets.UTF_8)).isEqualTo("my-driver.jar|02b97f7bc37b2b68fc847fcc3fc1c156"); - } - - @Test - public void dont_fail_when_medium_test() { - Settings settings = new Settings(); - DefaultServerFileSystem fs = mock(DefaultServerFileSystem.class); - - // No sonar.jdbc.driverPath property - - new JdbcDriverDeployer(fs, settings).start(); - } -} diff --git a/server/sonar-server/src/test/resources/org/sonar/server/startup/JdbcDriverDeployerTest/deploy/my-driver.jar b/server/sonar-server/src/test/resources/org/sonar/server/startup/JdbcDriverDeployerTest/deploy/my-driver.jar deleted file mode 100644 index b84613e99b1..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/startup/JdbcDriverDeployerTest/deploy/my-driver.jar +++ /dev/null @@ -1 +0,0 @@ -foooo
\ No newline at end of file |