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;
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;
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;
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;
}
private void moveDownloadedPlugins() {
if (fs.getDownloadedPluginsDir().exists()) {
for (File sourceFile : listJarFiles(fs.getDownloadedPluginsDir())) {
- overrideAndRegisterPlugin(sourceFile, true);
+ overrideAndRegisterPlugin(sourceFile);
}
}
}
private void moveDownloadedEditionPlugins() {
if (fs.getEditionDownloadedPluginsDir().exists()) {
for (File sourceFile : listJarFiles(fs.getEditionDownloadedPluginsDir())) {
- overrideAndRegisterPlugin(sourceFile, true);
+ overrideAndRegisterPlugin(sourceFile);
}
}
}
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()));
}
}
* 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()) {
}
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);
}
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;
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 {
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");
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();
}
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();
}
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();
}