return server.getDeployDir();
}
- public File getDeployedJdbcDriverIndex() {
- return new File(getDeployDir(), "jdbc-driver.txt");
- }
-
public File getDeployedPluginsDir() {
return new File(getDeployDir(), "plugins");
}
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;
RegisterQualityGates.class,
RegisterRules.class,
RegisterQualityProfiles.class,
- JdbcDriverDeployer.class,
RegisterDebtModel.class,
GeneratePluginIndex.class,
RegisterNewMeasureFilters.class,
+++ /dev/null
-/*
- * 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 "";
- }
-
-}
+++ /dev/null
-/*
- * 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();
- }
-}
+++ /dev/null
-foooo
\ No newline at end of file