You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ServerFileSystemImpl.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2018 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.server.platform;
  21. import java.io.File;
  22. import java.io.IOException;
  23. import org.apache.commons.io.FileUtils;
  24. import org.picocontainer.Startable;
  25. import org.sonar.api.config.Configuration;
  26. import org.sonar.api.utils.log.Logger;
  27. import org.sonar.api.utils.log.Loggers;
  28. import static org.sonar.process.ProcessProperties.Property.PATH_DATA;
  29. import static org.sonar.process.ProcessProperties.Property.PATH_HOME;
  30. import static org.sonar.process.ProcessProperties.Property.PATH_TEMP;
  31. public class ServerFileSystemImpl implements ServerFileSystem, org.sonar.api.platform.ServerFileSystem, Startable {
  32. private static final Logger LOGGER = Loggers.get(ServerFileSystemImpl.class);
  33. private final File homeDir;
  34. private final File tempDir;
  35. private final File deployDir;
  36. private final File uninstallDir;
  37. public ServerFileSystemImpl(Configuration config) {
  38. this.homeDir = createDir(new File(config.get(PATH_HOME.getKey()).get()));
  39. this.tempDir = createDir(new File(config.get(PATH_TEMP.getKey()).get()));
  40. File dataDir = createDir(new File(config.get(PATH_DATA.getKey()).get()));
  41. this.deployDir = new File(dataDir, "web/deploy");
  42. this.uninstallDir = new File(getTempDir(), "uninstalled-plugins");
  43. }
  44. @Override
  45. public void start() {
  46. LOGGER.info("SonarQube home: " + homeDir.getAbsolutePath());
  47. }
  48. @Override
  49. public void stop() {
  50. // do nothing
  51. }
  52. @Override
  53. public File getHomeDir() {
  54. return homeDir;
  55. }
  56. @Override
  57. public File getTempDir() {
  58. return tempDir;
  59. }
  60. @Override
  61. public File getDeployedPluginsDir() {
  62. return new File(deployDir, "plugins");
  63. }
  64. @Override
  65. public File getDownloadedPluginsDir() {
  66. return new File(getHomeDir(), "extensions/downloads");
  67. }
  68. @Override
  69. public File getInstalledPluginsDir() {
  70. return new File(getHomeDir(), "extensions/plugins");
  71. }
  72. @Override
  73. public File getPluginIndex() {
  74. return new File(deployDir, "plugins/index.txt");
  75. }
  76. @Override
  77. public File getUninstalledPluginsDir() {
  78. return uninstallDir;
  79. }
  80. private static File createDir(File dir) {
  81. try {
  82. FileUtils.forceMkdir(dir);
  83. return dir;
  84. } catch (IOException e) {
  85. throw new IllegalStateException("Fail to create directory " + dir, e);
  86. }
  87. }
  88. }