diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2013-02-05 12:43:45 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2013-02-05 12:43:45 +0100 |
commit | 7bf52372a4f63be30ae6513bae70d2f8b775e29b (patch) | |
tree | 459e8af8de426d1b4c320270b367962176390fc4 /sonar-server | |
parent | 5c6c22c2820f420428cb308a22c1a5262d0295e9 (diff) | |
download | sonarqube-7bf52372a4f63be30ae6513bae70d2f8b775e29b.tar.gz sonarqube-7bf52372a4f63be30ae6513bae70d2f8b775e29b.zip |
SONAR-2291 move management of file cache to the new module sonar-home
Diffstat (limited to 'sonar-server')
4 files changed, 16 insertions, 38 deletions
diff --git a/sonar-server/pom.xml b/sonar-server/pom.xml index 4417542fa20..da24a99a4ea 100644 --- a/sonar-server/pom.xml +++ b/sonar-server/pom.xml @@ -1,5 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.codehaus.sonar</groupId> @@ -39,6 +40,10 @@ </dependency> <dependency> <groupId>org.codehaus.sonar</groupId> + <artifactId>sonar-home</artifactId> + </dependency> + <dependency> + <groupId>org.codehaus.sonar</groupId> <artifactId>sonar-java-api</artifactId> </dependency> <dependency> diff --git a/sonar-server/src/main/java/org/sonar/server/startup/GenerateBootstrapIndex.java b/sonar-server/src/main/java/org/sonar/server/startup/GenerateBootstrapIndex.java index e449ad76500..1c04c970baf 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/GenerateBootstrapIndex.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/GenerateBootstrapIndex.java @@ -20,14 +20,11 @@ package org.sonar.server.startup; import com.google.common.collect.Lists; -import com.google.common.io.Closeables; -import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.CharUtils; import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.sonar.home.cache.FileHashes; import org.sonar.server.platform.DefaultServerFileSystem; import javax.servlet.ServletContext; @@ -44,8 +41,6 @@ import java.util.Set; */ public final class GenerateBootstrapIndex { - private static final Logger LOG = LoggerFactory.getLogger(GenerateBootstrapIndex.class); - private final ServletContext servletContext; private final DefaultServerFileSystem fileSystem; @@ -64,16 +59,8 @@ public final class GenerateBootstrapIndex { try { for (String path : getLibs(servletContext)) { writer.append(path); - // Compute MD5 InputStream is = servletContext.getResourceAsStream("/WEB-INF/lib/" + path); - try { - String md5 = DigestUtils.md5Hex(is); - writer.append("|").append(md5); - } catch (IOException e) { - LOG.warn("Unable to compute checksum of {}", path, e); - } finally { - Closeables.closeQuietly(is); - } + writer.append("|").append(new FileHashes().of(is)); writer.append(CharUtils.LF); } writer.flush(); diff --git a/sonar-server/src/main/java/org/sonar/server/startup/JdbcDriverDeployer.java b/sonar-server/src/main/java/org/sonar/server/startup/JdbcDriverDeployer.java index 1e1a8a8b52b..4bf99bcff4e 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/JdbcDriverDeployer.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/JdbcDriverDeployer.java @@ -19,21 +19,15 @@ */ package org.sonar.server.startup; -import com.google.common.io.Closeables; -import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.FileUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.sonar.home.cache.FileHashes; import org.sonar.server.platform.DefaultServerFileSystem; import java.io.File; import java.io.IOException; -import java.io.InputStream; public class JdbcDriverDeployer { - private static final Logger LOG = LoggerFactory.getLogger(JdbcDriverDeployer.class); - private final DefaultServerFileSystem fileSystem; public JdbcDriverDeployer(DefaultServerFileSystem fileSystem) { @@ -43,7 +37,7 @@ public class JdbcDriverDeployer { public void start() { File driver = fileSystem.getJdbcDriver(); File deployedDriver = new File(fileSystem.getDeployDir(), driver.getName()); - if (deployedDriver == null || !deployedDriver.exists() || deployedDriver.length() != driver.length()) { + if (!deployedDriver.exists() || deployedDriver.length() != driver.length()) { try { FileUtils.copyFile(driver, deployedDriver); @@ -52,16 +46,11 @@ public class JdbcDriverDeployer { } } File deployedDriverIndex = fileSystem.getDeployedJdbcDriverIndex(); - // Compute MD5 - InputStream is = null; try { - is = FileUtils.openInputStream(deployedDriver); - String md5 = DigestUtils.md5Hex(is); - FileUtils.writeStringToFile(deployedDriverIndex, deployedDriver.getName() + "|" + md5); + String hash = new FileHashes().of(deployedDriver); + FileUtils.writeStringToFile(deployedDriverIndex, deployedDriver.getName() + "|" + hash); } catch (IOException e) { - throw new RuntimeException("Can not generate index of JDBC driver", e); - } finally { - Closeables.closeQuietly(is); + throw new IllegalStateException("Can not generate index of JDBC driver", e); } } } diff --git a/sonar-server/src/test/java/org/sonar/server/startup/JdbcDriverDeployerTest.java b/sonar-server/src/test/java/org/sonar/server/startup/JdbcDriverDeployerTest.java index 4cac7112870..eeb5a76ef2e 100644 --- a/sonar-server/src/test/java/org/sonar/server/startup/JdbcDriverDeployerTest.java +++ b/sonar-server/src/test/java/org/sonar/server/startup/JdbcDriverDeployerTest.java @@ -25,18 +25,15 @@ import org.sonar.server.platform.DefaultServerFileSystem; import org.sonar.test.TestUtils; import java.io.File; -import java.io.IOException; import static org.fest.assertions.Assertions.assertThat; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; public class JdbcDriverDeployerTest { @Test - public void testDeploy() throws IOException { + public void test_deploy() throws Exception { DefaultServerFileSystem fs = mock(DefaultServerFileSystem.class); File initialDriver = TestUtils.getResource(getClass(), "deploy/my-driver.jar"); when(fs.getJdbcDriver()).thenReturn(initialDriver); @@ -54,7 +51,7 @@ public class JdbcDriverDeployerTest { assertThat(deployedIndex).exists(); assertThat(deployedFile).exists(); - assertThat(deployedFile.length(), is(initialDriver.length())); - assertThat(FileUtils.readFileToString(deployedIndex)).isEqualTo("my-driver.jar|02b97f7bc37b2b68fc847fcc3fc1c156"); + assertThat(deployedFile).hasSize(initialDriver.length()); + assertThat(FileUtils.readFileToString(deployedIndex)).isEqualTo("my-driver.jar|02B97F7BC37B2B68FC847FCC3FC1C156"); } } |