private static final Logger LOGGER = Loggers.get(DefaultServerFileSystem.class);
private final Server server;
- private File homeDir;
+ private final File homeDir, tempDir;
public DefaultServerFileSystem(Settings settings, Server server) {
this.server = server;
this.homeDir = new File(settings.getString(ProcessProperties.PATH_HOME));
+ this.tempDir = new File(settings.getString(ProcessProperties.PATH_TEMP));
}
/**
* for unit tests
*/
- public DefaultServerFileSystem(File homeDir, Server server) {
+ public DefaultServerFileSystem(File homeDir, File tempDir, Server server) {
this.homeDir = homeDir;
+ this.tempDir = tempDir;
this.server = server;
}
@Override
public File getTempDir() {
- // Tomcat is started by app process with correct java.io.tmpdir
- return FileUtils.getTempDirectory();
+ return tempDir;
}
public File getDeployDir() {
package org.sonar.server.platform;
import com.google.common.io.Resources;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.sonar.api.platform.ServerFileSystem;
import java.io.File;
private static final String PATH = "org/sonar/server/platform/DefaultServerFileSystemTest/";
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
@Test
public void find_plugins() throws Exception {
- List<File> plugins = new DefaultServerFileSystem(new File(Resources.getResource(PATH + "shouldFindPlugins").toURI()), null).getUserPlugins();
+ List<File> plugins = new DefaultServerFileSystem(
+ new File(Resources.getResource(PATH + "shouldFindPlugins").toURI()), temp.newFolder(), null).getUserPlugins();
assertThat(plugins).hasSize(2);
}
@Test
public void not_fail_if_no_plugins() throws Exception {
- List<File> plugins = new DefaultServerFileSystem(new File(Resources.getResource(PATH + "shouldNotFailIfNoPlugins").toURI()), null).getUserPlugins();
+ List<File> plugins = new DefaultServerFileSystem(
+ new File(Resources.getResource(PATH + "shouldNotFailIfNoPlugins").toURI()), temp.newFolder(), null).getUserPlugins();
assertThat(plugins).isEmpty();
}
@Test
public void find_checkstyle_extensions() throws Exception {
- ServerFileSystem fs = new DefaultServerFileSystem(new File(Resources.getResource(PATH + "shouldFindCheckstyleExtensions").toURI()), null);
+ ServerFileSystem fs = new DefaultServerFileSystem(
+ new File(Resources.getResource(PATH + "shouldFindCheckstyleExtensions").toURI()), temp.newFolder(), null);
List<File> xmls = fs.getExtensions("checkstyle", "xml");
assertThat(xmls).hasSize(1);
@Test
public void not_fail_if_no_checkstyle_extensions() throws Exception {
- ServerFileSystem fs = new DefaultServerFileSystem(new File(Resources.getResource(PATH + "shouldNotFailIfNoCheckstyleExtensions").toURI()), null);
+ ServerFileSystem fs = new DefaultServerFileSystem(
+ new File(Resources.getResource(PATH + "shouldNotFailIfNoCheckstyleExtensions").toURI()), temp.newFolder(), null);
List<File> xmls = fs.getExtensions("checkstyle", "xml");
assertThat(xmls).isEmpty();
coreDir = new File(homeDir, "lib/core-plugins");
FileUtils.forceMkdir(bundledDir);
- fileSystem = new DefaultServerFileSystem(homeDir, server);
+ fileSystem = new DefaultServerFileSystem(homeDir, temp.newFolder(), server);
jarInstaller = new ServerPluginJarInstaller();
jarsInstaller = new ServerPluginJarsInstaller(server, upgradeStatus, fileSystem, jarInstaller);
}
import javax.annotation.Nullable;
import java.io.File;
+import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
properties.setProperty(ProcessProperties.SEARCH_HOST, String.valueOf(esServerHolder.getHostName()));
properties.setProperty(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath());
properties.setProperty(ProcessProperties.PATH_DATA, new File(homeDir, "data").getAbsolutePath());
+ properties.setProperty(ProcessProperties.PATH_TEMP, createTemporaryFolderIn().getAbsolutePath());
properties.setProperty(DatabaseProperties.PROP_URL, "jdbc:h2:" + homeDir.getAbsolutePath() + "/h2");
for (Map.Entry<Object, Object> entry : System.getProperties().entrySet()) {
String key = entry.getKey().toString();
}
}
+ private File createTemporaryFolderIn() throws IOException {
+ File createdFolder = File.createTempFile("ServerTester", "");
+ createdFolder.delete();
+ createdFolder.mkdir();
+ return createdFolder;
+ }
+
/**
* Called only when JUnit @Rule or @ClassRule is used.
*/