From 221ee536cf4e04e1e60b389432aa381d914a270b Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Fri, 24 Apr 2015 16:41:13 +0200 Subject: [PATCH] fix various quality flaws --- .../server/platform/ServerComponents.java | 2 +- .../server/plugins/PluginDownloader.java | 2 +- .../plugins/ServerPluginJarsInstaller.java | 10 ++++---- .../org/sonar/server/ruby/package-info.java | 23 +++++++++++++++++++ .../AbstractStoppableExecutorService.java | 6 +++-- .../core/plugins/PluginJarInstaller.java | 8 +++++-- 6 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 server/sonar-server/src/main/java/org/sonar/server/ruby/package-info.java diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java index 47f16ba9567..16aa1ea53ff 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java @@ -411,7 +411,7 @@ class ServerComponents { /** * All the stuff required to connect to database */ - Collection level1Components() { + Collection level1Components() { List components = Lists.newArrayList(platform, properties); addExtraRootComponents(components); components.addAll(Arrays.asList( diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/PluginDownloader.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/PluginDownloader.java index 860ad0f53af..1e2dd190f49 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/plugins/PluginDownloader.java +++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/PluginDownloader.java @@ -115,7 +115,7 @@ public class PluginDownloader implements Startable { * @return the list of download plugins as {@link DefaultPluginMetadata} instances */ public Collection getDownloadedPlugins() { - return newArrayList(transform(listPlugins(this.downloadDir), installer.fileToPlugin(false))); + return newArrayList(transform(listPlugins(this.downloadDir), installer.fileToPlugin())); } public void download(String pluginKey, Version version) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginJarsInstaller.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginJarsInstaller.java index cbed2cb3602..9b9ce32dc81 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginJarsInstaller.java +++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginJarsInstaller.java @@ -102,7 +102,7 @@ public class ServerPluginJarsInstaller { private void loadInstalledPlugins() { for (File file : fs.getUserPlugins()) { - PluginMetadata metadata = installer.fileToPlugin(false).apply(file); + PluginMetadata metadata = installer.fileToPlugin().apply(file); if (isNotBlank(metadata.getKey())) { loadInstalledPlugin(metadata); } @@ -132,7 +132,7 @@ public class ServerPluginJarsInstaller { private void copyBundledPlugins() { if (serverUpgradeStatus.isFreshInstall()) { for (File sourceFile : fs.getBundledPlugins()) { - PluginMetadata metadata = installer.fileToPlugin(false).apply(sourceFile); + PluginMetadata metadata = installer.fileToPlugin().apply(sourceFile); // lib/bundled-plugins should be copied only if the plugin is not already // available in extensions/plugins if (!pluginByKeys.containsKey(metadata.getKey())) { @@ -161,7 +161,7 @@ public class ServerPluginJarsInstaller { sourceFile.getAbsolutePath(), destFile.getAbsolutePath()), e); } - PluginMetadata metadata = installer.fileToPlugin(false).apply(destFile); + PluginMetadata metadata = installer.fileToPlugin().apply(destFile); if (isNotBlank(metadata.getKey())) { PluginMetadata existing = pluginByKeys.put(metadata.getKey(), metadata); if (existing != null) { @@ -175,7 +175,7 @@ public class ServerPluginJarsInstaller { private void loadCorePlugins() { for (File file : fs.getCorePlugins()) { - PluginMetadata metadata = installer.fileToPlugin(true).apply(file); + PluginMetadata metadata = installer.fileToCorePlugin().apply(file); PluginMetadata existing = pluginByKeys.put(metadata.getKey(), metadata); if (existing != null) { throw new IllegalStateException("Found two plugins with the same key '" + metadata.getKey() + "': " + metadata.getFile().getName() + " and " @@ -218,7 +218,7 @@ public class ServerPluginJarsInstaller { return Collections.emptyList(); } - return newArrayList(transform(listJarFiles(fs.getTrashPluginsDir()), installer.fileToPlugin(false))); + return newArrayList(transform(listJarFiles(fs.getTrashPluginsDir()), installer.fileToPlugin())); } public void cancelUninstalls() { diff --git a/server/sonar-server/src/main/java/org/sonar/server/ruby/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/ruby/package-info.java new file mode 100644 index 00000000000..e6dea1c89ed --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/ruby/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +@ParametersAreNonnullByDefault +package org.sonar.server.ruby; + +import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file diff --git a/server/sonar-server/src/main/java/org/sonar/server/util/AbstractStoppableExecutorService.java b/server/sonar-server/src/main/java/org/sonar/server/util/AbstractStoppableExecutorService.java index 278eb460f7c..daf575eba7d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/util/AbstractStoppableExecutorService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/util/AbstractStoppableExecutorService.java @@ -45,11 +45,13 @@ public abstract class AbstractStoppableExecutorService implements StoppableExecu @Override public void stop() { - delegate.shutdown(); // Disable new tasks from being submitted + // Disable new tasks from being submitted + delegate.shutdown(); try { // Wait a while for existing tasks to terminate if (!delegate.awaitTermination(5, TimeUnit.SECONDS)) { - delegate.shutdownNow(); // Cancel currently executing tasks + // Cancel currently executing tasks + delegate.shutdownNow(); // Wait a while for tasks to respond to being cancelled if (!delegate.awaitTermination(5, TimeUnit.SECONDS)) { Loggers.get(getClass()).error(format("Pool %s did not terminate", getClass().getSimpleName())); diff --git a/sonar-core/src/main/java/org/sonar/core/plugins/PluginJarInstaller.java b/sonar-core/src/main/java/org/sonar/core/plugins/PluginJarInstaller.java index 5af5f9c754f..7c5114a323b 100644 --- a/sonar-core/src/main/java/org/sonar/core/plugins/PluginJarInstaller.java +++ b/sonar-core/src/main/java/org/sonar/core/plugins/PluginJarInstaller.java @@ -88,8 +88,12 @@ public abstract class PluginJarInstaller implements BatchComponent, ServerCompon } } - public Function fileToPlugin(boolean core) { - return core ? jarFileToCorePlugin : jarFileToPlugin; + public Function fileToPlugin() { + return jarFileToPlugin; + } + + public Function fileToCorePlugin() { + return jarFileToCorePlugin; } private final Function jarFileToCorePlugin = new Function() { -- 2.39.5