]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10689 fix Quality flaws
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 29 May 2018 13:16:45 +0000 (15:16 +0200)
committerSonarTech <sonartech@sonarsource.com>
Tue, 12 Jun 2018 18:20:59 +0000 (20:20 +0200)
server/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java
server/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java

index ef7faf3c594dd20b4b8d3c48c48a359b4fc13f9e..b3d5b242b3631184259aece913a36f2a2a029699 100644 (file)
@@ -40,7 +40,6 @@ import org.apache.commons.io.FileUtils;
 import org.picocontainer.Startable;
 import org.sonar.api.Plugin;
 import org.sonar.api.SonarRuntime;
-import org.sonar.api.platform.ServerUpgradeStatus;
 import org.sonar.api.utils.MessageException;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
@@ -53,7 +52,6 @@ import org.sonar.updatecenter.common.Version;
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkState;
 import static java.lang.String.format;
-import static org.apache.commons.io.FileUtils.copyFile;
 import static org.apache.commons.io.FileUtils.moveFile;
 import static org.apache.commons.io.FileUtils.moveFileToDirectory;
 import static org.sonar.core.util.FileUtils.deleteQuietly;
@@ -80,7 +78,6 @@ public class ServerPluginRepository implements PluginRepository, Startable {
 
   private final SonarRuntime runtime;
   private final ServerFileSystem fs;
-  private final ServerUpgradeStatus upgradeStatus;
   private final PluginLoader loader;
   private final AtomicBoolean started = new AtomicBoolean(false);
   private Set<String> blacklistedPluginKeys = DEFAULT_BLACKLISTED_PLUGINS;
@@ -90,9 +87,8 @@ public class ServerPluginRepository implements PluginRepository, Startable {
   private final Map<String, Plugin> pluginInstancesByKeys = new HashMap<>();
   private final Map<ClassLoader, String> keysByClassLoader = new HashMap<>();
 
-  public ServerPluginRepository(SonarRuntime runtime, ServerUpgradeStatus upgradeStatus, ServerFileSystem fs, PluginLoader loader) {
+  public ServerPluginRepository(SonarRuntime runtime, ServerFileSystem fs, PluginLoader loader) {
     this.runtime = runtime;
-    this.upgradeStatus = upgradeStatus;
     this.fs = fs;
     this.loader = loader;
   }
@@ -148,7 +144,7 @@ public class ServerPluginRepository implements PluginRepository, Startable {
   private void moveDownloadedPlugins() {
     if (fs.getDownloadedPluginsDir().exists()) {
       for (File sourceFile : listJarFiles(fs.getDownloadedPluginsDir())) {
-        overrideAndRegisterPlugin(sourceFile, true);
+        overrideAndRegisterPlugin(sourceFile);
       }
     }
   }
@@ -156,7 +152,7 @@ public class ServerPluginRepository implements PluginRepository, Startable {
   private void moveDownloadedEditionPlugins() {
     if (fs.getEditionDownloadedPluginsDir().exists()) {
       for (File sourceFile : listJarFiles(fs.getEditionDownloadedPluginsDir())) {
-        overrideAndRegisterPlugin(sourceFile, true);
+        overrideAndRegisterPlugin(sourceFile);
       }
     }
   }
@@ -164,17 +160,17 @@ public class ServerPluginRepository implements PluginRepository, Startable {
   private void registerPluginInfo(PluginInfo info) {
     String pluginKey = info.getKey();
     if (blacklistedPluginKeys.contains(pluginKey)) {
-      LOG.warn("Plugin {} [{}] is blacklisted and is being uninstalled.", info.getName(), pluginKey);
+      LOG.warn("Plugin {} [{}] is blacklisted and is being uninstalled", info.getName(), pluginKey);
       deleteQuietly(info.getNonNullJarFile());
       return;
     }
     if (FORBIDDEN_COMPATIBLE_PLUGINS.contains(pluginKey)) {
-      throw MessageException.of(String.format("Plugin '%s' is no more compatible with this version of SonarQube", pluginKey));
+      throw MessageException.of(String.format("Plugin '%s' is no longer compatible with this version of SonarQube", pluginKey));
     }
     PluginInfo existing = pluginInfosByKeys.put(pluginKey, info);
     if (existing != null) {
-      throw MessageException.of(format("Found two files for the same plugin [%s]: %s and %s",
-        pluginKey, info.getNonNullJarFile().getName(), existing.getNonNullJarFile().getName()));
+      throw MessageException.of(format("Found two versions of the plugin %s [%s] in the directory extensions/plugins. Please remove one of %s or %s.",
+        info.getName(), pluginKey, info.getNonNullJarFile().getName(), existing.getNonNullJarFile().getName()));
     }
 
   }
@@ -183,7 +179,7 @@ public class ServerPluginRepository implements PluginRepository, Startable {
    * Move or copy plugin to directory extensions/plugins. If a version of this plugin
    * already exists then it's deleted.
    */
-  private void overrideAndRegisterPlugin(File sourceFile, boolean deleteSource) {
+  private void overrideAndRegisterPlugin(File sourceFile) {
     File destDir = fs.getInstalledPluginsDir();
     File destFile = new File(destDir, sourceFile.getName());
     if (destFile.exists()) {
@@ -192,13 +188,10 @@ public class ServerPluginRepository implements PluginRepository, Startable {
     }
 
     try {
-      if (deleteSource) {
-        moveFile(sourceFile, destFile);
-      } else {
-        copyFile(sourceFile, destFile, true);
-      }
+      moveFile(sourceFile, destFile);
+
     } catch (IOException e) {
-      throw new IllegalStateException(format("Fail to move or copy plugin: %s to %s",
+      throw new IllegalStateException(format("Fail to move plugin: %s to %s",
         sourceFile.getAbsolutePath(), destFile.getAbsolutePath()), e);
     }
 
index 69dd7856b9cebd6462b8aac2237c9545ea5188e4..04a44eea1d5e230f7964bcdcb8d45cb2a14988ab 100644 (file)
@@ -34,7 +34,6 @@ import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 import org.mockito.Mockito;
 import org.sonar.api.SonarRuntime;
-import org.sonar.api.platform.ServerUpgradeStatus;
 import org.sonar.api.utils.MessageException;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.core.platform.PluginInfo;
@@ -59,10 +58,9 @@ public class ServerPluginRepositoryTest {
   public LogTester logs = new LogTester();
 
   private SonarRuntime runtime = mock(SonarRuntime.class);
-  ServerUpgradeStatus upgradeStatus = mock(ServerUpgradeStatus.class);
-  ServerFileSystem fs = mock(ServerFileSystem.class, Mockito.RETURNS_DEEP_STUBS);
-  PluginLoader pluginLoader = mock(PluginLoader.class);
-  ServerPluginRepository underTest = new ServerPluginRepository(runtime, upgradeStatus, fs, pluginLoader);
+  private ServerFileSystem fs = mock(ServerFileSystem.class, Mockito.RETURNS_DEEP_STUBS);
+  private PluginLoader pluginLoader = mock(PluginLoader.class);
+  private ServerPluginRepository underTest = new ServerPluginRepository(runtime, fs, pluginLoader);
 
   @Before
   public void setUp() throws IOException {
@@ -107,7 +105,7 @@ public class ServerPluginRepositoryTest {
       fail();
     } catch (MessageException e) {
       assertThat(e)
-        .hasMessageStartingWith("Found two files for the same plugin [testbase]: ")
+        .hasMessageStartingWith("Found two versions of the plugin Base Plugin [testbase] in the directory extensions/plugins. Please remove one of ")
         // order is not guaranteed, so assertion is split
         .hasMessageContaining("test-base-plugin-0.1-SNAPSHOT.jar")
         .hasMessageContaining("test-base-plugin-0.2-SNAPSHOT.jar");
@@ -312,7 +310,7 @@ public class ServerPluginRepositoryTest {
     copyTestPluginTo("fake-views-plugin", fs.getInstalledPluginsDir());
 
     expectedException.expect(MessageException.class);
-    expectedException.expectMessage("Plugin 'views' is no more compatible with this version of SonarQube");
+    expectedException.expectMessage("Plugin 'views' is no longer compatible with this version of SonarQube");
     underTest.start();
   }
 
@@ -321,7 +319,7 @@ public class ServerPluginRepositoryTest {
     copyTestPluginTo("fake-sqale-plugin", fs.getInstalledPluginsDir());
 
     expectedException.expect(MessageException.class);
-    expectedException.expectMessage("Plugin 'sqale' is no more compatible with this version of SonarQube");
+    expectedException.expectMessage("Plugin 'sqale' is no longer compatible with this version of SonarQube");
     underTest.start();
   }
 
@@ -330,7 +328,7 @@ public class ServerPluginRepositoryTest {
     copyTestPluginTo("fake-report-plugin", fs.getInstalledPluginsDir());
 
     expectedException.expect(MessageException.class);
-    expectedException.expectMessage("Plugin 'report' is no more compatible with this version of SonarQube");
+    expectedException.expectMessage("Plugin 'report' is no longer compatible with this version of SonarQube");
     underTest.start();
   }