]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6858 remove useless deployment of JDBC driver
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 3 Feb 2016 22:10:34 +0000 (23:10 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 4 Feb 2016 15:48:43 +0000 (16:48 +0100)
server/sonar-server/src/main/java/org/sonar/server/platform/DefaultServerFileSystem.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java
server/sonar-server/src/main/java/org/sonar/server/startup/JdbcDriverDeployer.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/startup/JdbcDriverDeployerTest.java [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/startup/JdbcDriverDeployerTest/deploy/my-driver.jar [deleted file]

index 1ef4a63911077f7aafd58380375ef1fcccae6f67..2740d708306047ab4b1493bf33f595e130229233 100644 (file)
@@ -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");
   }
index 56e898325d6964e3a2f495b7ed46f4911470c895..e4d92734ee5c8587c52cc42cf95b1a6d3fc198b5 100644 (file)
@@ -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 (file)
index af48fb7..0000000
+++ /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 (file)
index 10f2863..0000000
+++ /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 (file)
index b84613e..0000000
+++ /dev/null
@@ -1 +0,0 @@
-foooo
\ No newline at end of file