summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2018-05-29 15:16:45 +0200
committerSonarTech <sonartech@sonarsource.com>2018-06-12 20:20:59 +0200
commit10f7f22611704b51dc9ebef153311fbd01aa7455 (patch)
tree499df806a8a0413cc2a412939ad35fe883575290
parentd089f05aca497ec89fa1e4ebee25728294ccba1e (diff)
downloadsonarqube-10f7f22611704b51dc9ebef153311fbd01aa7455.tar.gz
sonarqube-10f7f22611704b51dc9ebef153311fbd01aa7455.zip
SONAR-10689 fix Quality flaws
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java29
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java16
2 files changed, 18 insertions, 27 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java
index ef7faf3c594..b3d5b242b36 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java
@@ -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);
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java b/server/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java
index 69dd7856b9c..04a44eea1d5 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java
@@ -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();
}