diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-04-03 15:19:04 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-04-03 15:27:30 +0200 |
commit | 09c5d20c6c86d544c5a5a2448fe553b95f3cba2d (patch) | |
tree | 05706d85a0f06bdb98475fcb5e1409f46eaa5a3d /server | |
parent | bfb40f4bb93ccd4dfd878873bf9bb33dd24981f7 (diff) | |
download | sonarqube-09c5d20c6c86d544c5a5a2448fe553b95f3cba2d.tar.gz sonarqube-09c5d20c6c86d544c5a5a2448fe553b95f3cba2d.zip |
SONAR-6348 Property sonar.path.temp is ignored by Ruby on Rails application
Diffstat (limited to 'server')
3 files changed, 29 insertions, 11 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 eecf1e5386e..624ad9854b6 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 @@ -99,7 +99,8 @@ public class DefaultServerFileSystem implements ServerFileSystem, Startable { @Override public File getTempDir() { - return new File(homeDir, "temp"); + // Tomcat is started by app process with correct java.io.tmpdir + return FileUtils.getTempDirectory(); } public File getDeployDir() { diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/TempFolderProvider.java b/server/sonar-server/src/main/java/org/sonar/server/platform/TempFolderProvider.java index 21aabdb9729..2d2f598db80 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/TempFolderProvider.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/TempFolderProvider.java @@ -38,7 +38,7 @@ public class TempFolderProvider extends ProviderAdapter { try { FileUtils.forceMkdir(tempDir); } catch (IOException e) { - throw new IllegalStateException("Unable to create root temp directory " + tempDir, e); + throw new IllegalStateException("Unable to create temp directory " + tempDir, e); } tempFolder = new DefaultTempFolder(tempDir); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/TempFolderProviderTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/TempFolderProviderTest.java index 0f66f406e1d..6452f4477d8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/TempFolderProviderTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/TempFolderProviderTest.java @@ -19,6 +19,7 @@ */ package org.sonar.server.platform; +import org.apache.commons.io.FileUtils; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -40,16 +41,32 @@ public class TempFolderProviderTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); + TempFolderProvider sut = new TempFolderProvider(); + @Test - public void createTempFolder() throws Exception { + public void existing_temp_dir() throws Exception { ServerFileSystem fs = mock(ServerFileSystem.class); - File serverTempFolder = temp.newFolder(); - when(fs.getTempDir()).thenReturn(serverTempFolder); - TempFolderProvider tempFolderProvider = new TempFolderProvider(); - TempFolder tempUtils = tempFolderProvider.provide(fs); - tempUtils.newDir(); - tempUtils.newFile(); - assertThat(new File(serverTempFolder, "tmp")).exists(); - assertThat(new File(serverTempFolder, "tmp").list()).hasSize(2); + File tmpDir = temp.newFolder(); + when(fs.getTempDir()).thenReturn(tmpDir); + + TempFolder folder = sut.provide(fs); + assertThat(folder).isNotNull(); + File newDir = folder.newDir(); + assertThat(newDir).exists().isDirectory(); + assertThat(newDir.getParentFile().getCanonicalPath()).startsWith(tmpDir.getCanonicalPath()); + } + + @Test + public void create_temp_dir_if_missing() throws Exception { + ServerFileSystem fs = mock(ServerFileSystem.class); + File tmpDir = temp.newFolder(); + when(fs.getTempDir()).thenReturn(tmpDir); + FileUtils.forceDelete(tmpDir); + + TempFolder folder = sut.provide(fs); + assertThat(folder).isNotNull(); + File newDir = folder.newDir(); + assertThat(newDir).exists().isDirectory(); + assertThat(newDir.getParentFile().getCanonicalPath()).startsWith(tmpDir.getCanonicalPath()); } } |