+++ /dev/null
-/*
- * 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.
- */
-package org.sonar.batch.bootstrap;
-
-import org.sonar.api.BatchComponent;
-import org.sonar.core.plugins.DefaultPluginMetadata;
-import org.sonar.core.plugins.PluginInstaller;
-import org.sonar.home.cache.FileCache;
-
-import java.io.File;
-import java.io.IOException;
-
-public class BatchPluginInstaller extends PluginInstaller implements BatchComponent {
-
- private FileCache cache;
-
- public BatchPluginInstaller(FileCache cache) {
- this.cache = cache;
- }
-
- public DefaultPluginMetadata installToCache(File pluginFile, boolean isCore) {
- DefaultPluginMetadata metadata = extractMetadata(pluginFile, isCore);
- install(metadata, null, pluginFile);
- return metadata;
- }
-
- @Override
- protected File extractPluginDependencies(File pluginFile, File pluginBasedir) throws IOException {
- return cache.unzip(pluginFile);
- }
-
-}
--- /dev/null
+/*
+ * 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.
+ */
+package org.sonar.batch.bootstrap;
+
+import org.sonar.api.BatchComponent;
+import org.sonar.core.plugins.DefaultPluginMetadata;
+import org.sonar.core.plugins.PluginJarInstaller;
+import org.sonar.home.cache.FileCache;
+
+import java.io.File;
+import java.io.IOException;
+
+public class BatchPluginJarInstaller extends PluginJarInstaller implements BatchComponent {
+
+ private FileCache cache;
+
+ public BatchPluginJarInstaller(FileCache cache) {
+ this.cache = cache;
+ }
+
+ public DefaultPluginMetadata installToCache(File pluginFile, boolean isCore) {
+ DefaultPluginMetadata metadata = extractMetadata(pluginFile, isCore);
+ install(metadata, null, pluginFile);
+ return metadata;
+ }
+
+ @Override
+ protected File extractPluginDependencies(File pluginFile, File pluginBasedir) throws IOException {
+ return cache.unzip(pluginFile);
+ }
+
+}
private Settings settings;
private PluginClassloaders classLoaders;
private final AnalysisMode analysisMode;
- private final BatchPluginInstaller pluginInstaller;
+ private final BatchPluginJarInstaller pluginInstaller;
public BatchPluginRepository(PluginDownloader pluginDownloader, Settings settings, AnalysisMode analysisMode,
- BatchPluginInstaller pluginInstaller) {
+ BatchPluginJarInstaller pluginInstaller) {
this.pluginDownloader = pluginDownloader;
this.settings = settings;
this.analysisMode = analysisMode;
AnalysisMode.class,
PluginDownloader.class,
BatchPluginRepository.class,
- BatchPluginInstaller.class,
+ BatchPluginJarInstaller.class,
BatchSettings.class,
ServerClient.class,
ExtensionInstaller.class,
+++ /dev/null
-/*
- * 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.
- */
-package org.sonar.batch.bootstrap;
-
-import org.apache.commons.io.FileUtils;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.sonar.core.plugins.DefaultPluginMetadata;
-import org.sonar.home.cache.FileCacheBuilder;
-
-import java.io.File;
-import java.io.IOException;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class BatchPluginInstallerTest {
-
- private BatchPluginInstaller extractor;
-
- @ClassRule
- public static TemporaryFolder temporaryFolder = new TemporaryFolder();
-
- private File userHome;
-
- @Before
- public void setUp() throws IOException {
- userHome = temporaryFolder.newFolder();
- extractor = new BatchPluginInstaller(new FileCacheBuilder().setUserHome(userHome).build());
- }
-
- @Test
- public void should_copy_and_extract_dependencies() throws IOException {
- File fileFromCache = getFileFromCache("sonar-checkstyle-plugin-2.8.jar");
- DefaultPluginMetadata metadata = extractor.installToCache(fileFromCache, true);
-
- assertThat(metadata.getKey()).isEqualTo("checkstyle");
- assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar")).exists();
- assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar_unzip/META-INF/lib/checkstyle-5.1.jar")).exists();
- }
-
- @Test
- public void should_extract_only_dependencies() throws IOException {
- File fileFromCache = getFileFromCache("sonar-checkstyle-plugin-2.8.jar");
- extractor.installToCache(fileFromCache, true);
-
- assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar")).exists();
- assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar_unzip/META-INF/MANIFEST.MF")).doesNotExist();
- assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar_unzip/org/sonar/plugins/checkstyle/CheckstyleVersion.class")).doesNotExist();
- }
-
- File getFileFromCache(String filename) throws IOException {
- File src = FileUtils.toFile(BatchPluginInstallerTest.class.getResource("/org/sonar/batch/bootstrap/BatchPluginInstallerTest/" + filename));
- File destFile = new File(new File(userHome, "" + filename.hashCode()), filename);
- FileUtils.copyFile(src, destFile);
- return destFile;
- }
-
-}
--- /dev/null
+/*
+ * 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.
+ */
+package org.sonar.batch.bootstrap;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.sonar.core.plugins.DefaultPluginMetadata;
+import org.sonar.home.cache.FileCacheBuilder;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class BatchPluginJarInstallerTest {
+
+ private BatchPluginJarInstaller extractor;
+
+ @ClassRule
+ public static TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+ private File userHome;
+
+ @Before
+ public void setUp() throws IOException {
+ userHome = temporaryFolder.newFolder();
+ extractor = new BatchPluginJarInstaller(new FileCacheBuilder().setUserHome(userHome).build());
+ }
+
+ @Test
+ public void should_copy_and_extract_dependencies() throws IOException {
+ File fileFromCache = getFileFromCache("sonar-checkstyle-plugin-2.8.jar");
+ DefaultPluginMetadata metadata = extractor.installToCache(fileFromCache, true);
+
+ assertThat(metadata.getKey()).isEqualTo("checkstyle");
+ assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar")).exists();
+ assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar_unzip/META-INF/lib/checkstyle-5.1.jar")).exists();
+ }
+
+ @Test
+ public void should_extract_only_dependencies() throws IOException {
+ File fileFromCache = getFileFromCache("sonar-checkstyle-plugin-2.8.jar");
+ extractor.installToCache(fileFromCache, true);
+
+ assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar")).exists();
+ assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar_unzip/META-INF/MANIFEST.MF")).doesNotExist();
+ assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar_unzip/org/sonar/plugins/checkstyle/CheckstyleVersion.class")).doesNotExist();
+ }
+
+ File getFileFromCache(String filename) throws IOException {
+ File src = FileUtils.toFile(BatchPluginJarInstallerTest.class.getResource("/org/sonar/batch/bootstrap/BatchPluginJarInstallerTest/" + filename));
+ File destFile = new File(new File(userHome, "" + filename.hashCode()), filename);
+ FileUtils.copyFile(src, destFile);
+ return destFile;
+ }
+
+}
PluginDownloader downloader = mock(PluginDownloader.class);
when(downloader.downloadPlugin(checkstyle)).thenReturn(fileFromCache("sonar-checkstyle-plugin-2.8.jar"));
- repository = new BatchPluginRepository(downloader, new Settings(), mode, new BatchPluginInstaller(cache));
+ repository = new BatchPluginRepository(downloader, new Settings(), mode, new BatchPluginJarInstaller(cache));
repository.doStart(Arrays.asList(checkstyle));
when(downloader.downloadPlugin(checkstyle)).thenReturn(fileFromCache("sonar-checkstyle-plugin-2.8.jar"));
when(downloader.downloadPlugin(checkstyleExt)).thenReturn(fileFromCache("sonar-checkstyle-extensions-plugin-0.1-SNAPSHOT.jar"));
- repository = new BatchPluginRepository(downloader, new Settings(), mode, new BatchPluginInstaller(cache));
+ repository = new BatchPluginRepository(downloader, new Settings(), mode, new BatchPluginJarInstaller(cache));
repository.doStart(Arrays.asList(checkstyle, checkstyleExt));
Settings settings = new Settings();
settings.setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "checkstyle");
- repository = new BatchPluginRepository(downloader, settings, mode, new BatchPluginInstaller(cache));
+ repository = new BatchPluginRepository(downloader, settings, mode, new BatchPluginJarInstaller(cache));
repository.doStart(Arrays.asList(checkstyle, checkstyleExt));
+++ /dev/null
-/*
- * 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.
- */
-package org.sonar.core.plugins;
-
-import org.sonar.api.BatchComponent;
-import org.sonar.api.ServerComponent;
-import org.sonar.api.utils.SonarException;
-import org.sonar.updatecenter.common.PluginManifest;
-
-import javax.annotation.Nullable;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Arrays;
-
-public abstract class PluginInstaller implements BatchComponent, ServerComponent {
-
- protected static final String FAIL_TO_INSTALL_PLUGIN = "Fail to install plugin: ";
-
- protected void install(DefaultPluginMetadata metadata, @Nullable File pluginBasedir, File deployedPlugin) {
- try {
- metadata.addDeployedFile(deployedPlugin);
- copyDependencies(metadata, deployedPlugin, pluginBasedir);
- } catch (IOException e) {
- throw new SonarException(FAIL_TO_INSTALL_PLUGIN + metadata, e);
- }
- }
-
- private void copyDependencies(DefaultPluginMetadata metadata, File pluginFile, @Nullable File pluginBasedir) throws IOException {
- if (!metadata.getPathsToInternalDeps().isEmpty()) {
- // needs to unzip the jar
- File baseDir = extractPluginDependencies(pluginFile, pluginBasedir);
- for (String depPath : metadata.getPathsToInternalDeps()) {
- File dependency = new File(baseDir, depPath);
- if (!dependency.isFile() || !dependency.exists()) {
- throw new IllegalArgumentException("Dependency " + depPath + " can not be found in " + pluginFile.getName());
- }
- metadata.addDeployedFile(dependency);
- }
- }
- }
-
- protected abstract File extractPluginDependencies(File pluginFile, @Nullable File pluginBasedir) throws IOException;
-
- public DefaultPluginMetadata extractMetadata(File file, boolean isCore) {
- try {
- PluginManifest manifest = new PluginManifest(file);
- DefaultPluginMetadata metadata = DefaultPluginMetadata.create(file);
- metadata.setKey(manifest.getKey());
- metadata.setName(manifest.getName());
- metadata.setDescription(manifest.getDescription());
- metadata.setLicense(manifest.getLicense());
- metadata.setOrganization(manifest.getOrganization());
- metadata.setOrganizationUrl(manifest.getOrganizationUrl());
- metadata.setMainClass(manifest.getMainClass());
- metadata.setVersion(manifest.getVersion());
- metadata.setSonarVersion(manifest.getSonarVersion());
- metadata.setHomepage(manifest.getHomepage());
- metadata.setIssueTrackerUrl(manifest.getIssueTrackerUrl());
- metadata.setPathsToInternalDeps(Arrays.asList(manifest.getDependencies()));
- metadata.setUseChildFirstClassLoader(manifest.isUseChildFirstClassLoader());
- metadata.setBasePlugin(manifest.getBasePlugin());
- metadata.setImplementationBuild(manifest.getImplementationBuild());
- metadata.setParent(manifest.getParent());
- metadata.setRequiredPlugins(Arrays.asList(manifest.getRequirePlugins()));
- metadata.setCore(isCore);
- return metadata;
-
- } catch (IOException e) {
- throw new IllegalStateException("Fail to extract plugin metadata from file: " + file, e);
- }
- }
-}
--- /dev/null
+/*
+ * 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.
+ */
+package org.sonar.core.plugins;
+
+import org.sonar.api.BatchComponent;
+import org.sonar.api.ServerComponent;
+import org.sonar.api.utils.SonarException;
+import org.sonar.updatecenter.common.PluginManifest;
+
+import javax.annotation.Nullable;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+
+public abstract class PluginJarInstaller implements BatchComponent, ServerComponent {
+
+ protected static final String FAIL_TO_INSTALL_PLUGIN = "Fail to install plugin: ";
+
+ protected void install(DefaultPluginMetadata metadata, @Nullable File pluginBasedir, File deployedPlugin) {
+ try {
+ metadata.addDeployedFile(deployedPlugin);
+ copyDependencies(metadata, deployedPlugin, pluginBasedir);
+ } catch (IOException e) {
+ throw new SonarException(FAIL_TO_INSTALL_PLUGIN + metadata, e);
+ }
+ }
+
+ private void copyDependencies(DefaultPluginMetadata metadata, File pluginFile, @Nullable File pluginBasedir) throws IOException {
+ if (!metadata.getPathsToInternalDeps().isEmpty()) {
+ // needs to unzip the jar
+ File baseDir = extractPluginDependencies(pluginFile, pluginBasedir);
+ for (String depPath : metadata.getPathsToInternalDeps()) {
+ File dependency = new File(baseDir, depPath);
+ if (!dependency.isFile() || !dependency.exists()) {
+ throw new IllegalArgumentException("Dependency " + depPath + " can not be found in " + pluginFile.getName());
+ }
+ metadata.addDeployedFile(dependency);
+ }
+ }
+ }
+
+ protected abstract File extractPluginDependencies(File pluginFile, @Nullable File pluginBasedir) throws IOException;
+
+ public DefaultPluginMetadata extractMetadata(File file, boolean isCore) {
+ try {
+ PluginManifest manifest = new PluginManifest(file);
+ DefaultPluginMetadata metadata = DefaultPluginMetadata.create(file);
+ metadata.setKey(manifest.getKey());
+ metadata.setName(manifest.getName());
+ metadata.setDescription(manifest.getDescription());
+ metadata.setLicense(manifest.getLicense());
+ metadata.setOrganization(manifest.getOrganization());
+ metadata.setOrganizationUrl(manifest.getOrganizationUrl());
+ metadata.setMainClass(manifest.getMainClass());
+ metadata.setVersion(manifest.getVersion());
+ metadata.setSonarVersion(manifest.getSonarVersion());
+ metadata.setHomepage(manifest.getHomepage());
+ metadata.setIssueTrackerUrl(manifest.getIssueTrackerUrl());
+ metadata.setPathsToInternalDeps(Arrays.asList(manifest.getDependencies()));
+ metadata.setUseChildFirstClassLoader(manifest.isUseChildFirstClassLoader());
+ metadata.setBasePlugin(manifest.getBasePlugin());
+ metadata.setImplementationBuild(manifest.getImplementationBuild());
+ metadata.setParent(manifest.getParent());
+ metadata.setRequiredPlugins(Arrays.asList(manifest.getRequirePlugins()));
+ metadata.setCore(isCore);
+ return metadata;
+
+ } catch (IOException e) {
+ throw new IllegalStateException("Fail to extract plugin metadata from file: " + file, e);
+ }
+ }
+}
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.sonar.api.ServerExtension;
import org.sonar.api.config.Settings;
/**
* @since 4.1
*/
-public final class Profiling implements ServerExtension {
+public class Profiling {
public static final String CONFIG_PROFILING_LEVEL = "sonar.log.profilingLevel";
if (settingsValue != null) {
try {
settingsLevel = Level.valueOf(settingsValue);
- } catch(IllegalArgumentException invalidSettings) {
+ } catch (IllegalArgumentException invalidSettings) {
LOGGER.debug("Bad profiling settings, profiling is disabled", invalidSettings);
}
}
+++ /dev/null
-/*
- * 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.
- */
-package org.sonar.core.plugins;
-
-import org.apache.commons.io.FileUtils;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-
-import java.io.File;
-import java.io.IOException;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class PluginInstallerTest {
-
- private PluginInstaller extractor;
-
- @ClassRule
- public static TemporaryFolder temporaryFolder = new TemporaryFolder();
-
- private File userHome;
-
- @Before
- public void setUp() throws IOException {
- userHome = temporaryFolder.newFolder();
- extractor = new PluginInstaller() {
- @Override
- protected File extractPluginDependencies(File pluginFile, File pluginBasedir) throws IOException {
- return null;
- }
- };
- }
-
- @Test
- public void should_extract_metadata() throws IOException {
- DefaultPluginMetadata metadata = extractor.extractMetadata(getFileFromCache("sonar-cobertura-plugin-3.1.1.jar"), true);
-
- assertThat(metadata.getKey()).isEqualTo("cobertura");
- assertThat(metadata.getBasePlugin()).isNull();
- assertThat(metadata.getName()).isEqualTo("Cobertura");
- assertThat(metadata.isCore()).isEqualTo(true);
- assertThat(metadata.getFile().getName()).isEqualTo("sonar-cobertura-plugin-3.1.1.jar");
- assertThat(metadata.getVersion()).isEqualTo("3.1.1");
- assertThat(metadata.getImplementationBuild()).isEqualTo("b9283404030db9ce1529b1fadfb98331686b116d");
- assertThat(metadata.getHomepage()).isEqualTo("http://www.sonarsource.org/plugins/sonar-cobertura-plugin");
- assertThat(metadata.getIssueTrackerUrl()).isEqualTo("http://jira.codehaus.org/browse/SONAR");
- }
-
- @Test
- public void should_read_sonar_version() throws IOException {
- DefaultPluginMetadata metadata = extractor.extractMetadata(getFileFromCache("sonar-switch-off-violations-plugin-1.1.jar"), false);
-
- assertThat(metadata.getVersion()).isEqualTo("1.1");
- assertThat(metadata.getSonarVersion()).isEqualTo("2.5");
- }
-
- @Test
- public void should_extract_extension_metadata() throws IOException {
- DefaultPluginMetadata metadata = extractor.extractMetadata(getFileFromCache("sonar-checkstyle-extensions-plugin-0.1-SNAPSHOT.jar"), true);
-
- assertThat(metadata.getKey()).isEqualTo("checkstyleextensions");
- assertThat(metadata.getBasePlugin()).isEqualTo("checkstyle");
- }
-
- @Test
- public void should_extract_parent_information() throws IOException {
- DefaultPluginMetadata metadata = extractor.extractMetadata(getFileFromCache("fake1bis-plugin-1.0.jar"), true);
-
- assertThat(metadata.getKey()).isEqualTo("fake1bis");
- assertThat(metadata.getParent()).isEqualTo("fake1");
- }
-
- @Test
- public void should_extract_requires_plugin_information() throws IOException {
- DefaultPluginMetadata metadata = extractor.extractMetadata(getFileFromCache("fake2-plugin-1.1.jar"), true);
-
- assertThat(metadata.getKey()).isEqualTo("fake2");
- assertThat(metadata.getRequiredPlugins().get(0)).isEqualTo("fake1:1.1");
- }
-
- File getFileFromCache(String filename) throws IOException {
- File src = FileUtils.toFile(PluginInstallerTest.class.getResource("/org/sonar/core/plugins/" + filename));
- File destFile = new File(new File(userHome, "" + filename.hashCode()), filename);
- FileUtils.copyFile(src, destFile);
- return destFile;
- }
-
-}
--- /dev/null
+/*
+ * 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.
+ */
+package org.sonar.core.plugins;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class PluginJarInstallerTest {
+
+ private PluginJarInstaller extractor;
+
+ @ClassRule
+ public static TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+ private File userHome;
+
+ @Before
+ public void setUp() throws IOException {
+ userHome = temporaryFolder.newFolder();
+ extractor = new PluginJarInstaller() {
+ @Override
+ protected File extractPluginDependencies(File pluginFile, File pluginBasedir) throws IOException {
+ return null;
+ }
+ };
+ }
+
+ @Test
+ public void should_extract_metadata() throws IOException {
+ DefaultPluginMetadata metadata = extractor.extractMetadata(getFileFromCache("sonar-cobertura-plugin-3.1.1.jar"), true);
+
+ assertThat(metadata.getKey()).isEqualTo("cobertura");
+ assertThat(metadata.getBasePlugin()).isNull();
+ assertThat(metadata.getName()).isEqualTo("Cobertura");
+ assertThat(metadata.isCore()).isEqualTo(true);
+ assertThat(metadata.getFile().getName()).isEqualTo("sonar-cobertura-plugin-3.1.1.jar");
+ assertThat(metadata.getVersion()).isEqualTo("3.1.1");
+ assertThat(metadata.getImplementationBuild()).isEqualTo("b9283404030db9ce1529b1fadfb98331686b116d");
+ assertThat(metadata.getHomepage()).isEqualTo("http://www.sonarsource.org/plugins/sonar-cobertura-plugin");
+ assertThat(metadata.getIssueTrackerUrl()).isEqualTo("http://jira.codehaus.org/browse/SONAR");
+ }
+
+ @Test
+ public void should_read_sonar_version() throws IOException {
+ DefaultPluginMetadata metadata = extractor.extractMetadata(getFileFromCache("sonar-switch-off-violations-plugin-1.1.jar"), false);
+
+ assertThat(metadata.getVersion()).isEqualTo("1.1");
+ assertThat(metadata.getSonarVersion()).isEqualTo("2.5");
+ }
+
+ @Test
+ public void should_extract_extension_metadata() throws IOException {
+ DefaultPluginMetadata metadata = extractor.extractMetadata(getFileFromCache("sonar-checkstyle-extensions-plugin-0.1-SNAPSHOT.jar"), true);
+
+ assertThat(metadata.getKey()).isEqualTo("checkstyleextensions");
+ assertThat(metadata.getBasePlugin()).isEqualTo("checkstyle");
+ }
+
+ @Test
+ public void should_extract_parent_information() throws IOException {
+ DefaultPluginMetadata metadata = extractor.extractMetadata(getFileFromCache("fake1bis-plugin-1.0.jar"), true);
+
+ assertThat(metadata.getKey()).isEqualTo("fake1bis");
+ assertThat(metadata.getParent()).isEqualTo("fake1");
+ }
+
+ @Test
+ public void should_extract_requires_plugin_information() throws IOException {
+ DefaultPluginMetadata metadata = extractor.extractMetadata(getFileFromCache("fake2-plugin-1.1.jar"), true);
+
+ assertThat(metadata.getKey()).isEqualTo("fake2");
+ assertThat(metadata.getRequiredPlugins().get(0)).isEqualTo("fake1:1.1");
+ }
+
+ File getFileFromCache(String filename) throws IOException {
+ File src = FileUtils.toFile(PluginJarInstallerTest.class.getResource("/org/sonar/core/plugins/" + filename));
+ File destFile = new File(new File(userHome, "" + filename.hashCode()), filename);
+ FileUtils.copyFile(src, destFile);
+ return destFile;
+ }
+
+}
import org.sonar.api.Plugin;
import org.sonar.api.ServerComponent;
+import javax.annotation.CheckForNull;
import java.util.Collection;
public interface PluginRepository extends BatchComponent, ServerComponent {
+ @CheckForNull
Plugin getPlugin(String key);
/**
* Search for an installed plugin. Returns null if the plugin is not installed.
* @since 2.9
*/
+ @CheckForNull
PluginMetadata getMetadata(String pluginKey);
}
package org.sonar.server.db;
import com.google.common.annotations.VisibleForTesting;
+import org.picocontainer.Startable;
import org.sonar.api.config.Settings;
import org.sonar.api.database.DatabaseProperties;
-public class EmbeddedDatabaseFactory {
+public class EmbeddedDatabaseFactory implements Startable {
private final Settings settings;
private EmbeddedDatabase embeddedDatabase;
this.settings = settings;
}
+ @Override
public void start() {
if (embeddedDatabase == null) {
String jdbcUrl = settings.getString(DatabaseProperties.PROP_URL);
}
}
+ @Override
public void stop() {
if (embeddedDatabase != null) {
embeddedDatabase.stop();
+ embeddedDatabase = null;
}
}
*/
package org.sonar.server.platform;
+import org.picocontainer.Startable;
import org.slf4j.LoggerFactory;
-import org.sonar.api.ServerComponent;
import org.sonar.api.utils.MessageException;
import org.sonar.core.persistence.DatabaseVersion;
-public class DatabaseServerCompatibility implements ServerComponent {
-
+public class DatabaseServerCompatibility implements Startable {
+
private DatabaseVersion version;
public DatabaseServerCompatibility(DatabaseVersion version) {
this.version = version;
}
+ @Override
public void start() {
DatabaseVersion.Status status = version.getStatus();
- if (status== DatabaseVersion.Status.REQUIRES_DOWNGRADE) {
+ if (status == DatabaseVersion.Status.REQUIRES_DOWNGRADE) {
throw MessageException.of("Database relates to a more recent version of sonar. Please check your settings.");
}
- if (status== DatabaseVersion.Status.REQUIRES_UPGRADE) {
+ if (status == DatabaseVersion.Status.REQUIRES_UPGRADE) {
LoggerFactory.getLogger(DatabaseServerCompatibility.class).info("Database must be upgraded. Please browse /setup");
}
}
+ @Override
+ public void stop() {
+ // do nothing
+ }
}
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.lang.StringUtils;
+import org.picocontainer.Startable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
*
* @since 2.2
*/
-public class DefaultServerFileSystem implements ServerFileSystem {
+public class DefaultServerFileSystem implements ServerFileSystem, Startable {
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultServerFileSystem.class);
this.homeDir = homeDir;
}
+ @Override
public void start() {
LOGGER.info("SonarQube home: " + homeDir.getAbsolutePath());
if (!homeDir.isDirectory() || !homeDir.exists()) {
}
}
+ @Override
+ public void stop() {
+ // do nothing
+ }
+
+ @Override
public File getHomeDir() {
return homeDir;
}
+ @Override
public File getTempDir() {
return new File(homeDir, "temp");
}
/**
* @deprecated since 4.1
*/
+ @Override
@Deprecated
public List<File> getExtensions(String dirName, String... suffixes) {
File dir = new File(getHomeDir(), "extensions/rules/" + dirName);
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
+import org.picocontainer.Startable;
import org.sonar.api.platform.ServerUpgradeStatus;
import org.sonar.core.persistence.DatabaseVersion;
/**
* @since 2.5
*/
-public final class DefaultServerUpgradeStatus implements ServerUpgradeStatus {
+public final class DefaultServerUpgradeStatus implements ServerUpgradeStatus, Startable {
+ private final DatabaseVersion dbVersion;
+
+ // available when connected to db
private int initialDbVersion;
- private DatabaseVersion dbVersion;
public DefaultServerUpgradeStatus(DatabaseVersion dbVersion) {
this.dbVersion = dbVersion;
}
+ @Override
public void start() {
Integer v = dbVersion.getVersion();
this.initialDbVersion = (v != null ? v : -1);
}
+ @Override
+ public void stop() {
+
+ }
+
+ @Override
public boolean isUpgraded() {
return !isFreshInstall() && (initialDbVersion < DatabaseVersion.LAST_VERSION);
}
+ @Override
public boolean isFreshInstall() {
- return initialDbVersion<0;
+ return initialDbVersion < 0;
}
+ @Override
public int getInitialDbVersion() {
return initialDbVersion;
}
package org.sonar.server.platform;
import com.google.common.collect.Maps;
-import org.sonar.api.ServerComponent;
+import org.picocontainer.Startable;
import org.sonar.api.config.Settings;
import org.sonar.core.properties.PropertiesDao;
import org.sonar.core.properties.PropertyDto;
import javax.annotation.Nullable;
-
import java.util.List;
import java.util.Map;
/**
* @since 3.2
*/
-public class PersistentSettings implements ServerComponent {
+public class PersistentSettings implements Startable {
private final PropertiesDao propertiesDao;
private final ServerSettings settings;
this.settings = settings;
}
+ @Override
public void start() {
Map<String, String> databaseProperties = Maps.newHashMap();
for (PropertyDto property : getGlobalProperties()) {
settings.activateDatabaseSettings(databaseProperties);
}
+ @Override
+ public void stop() {
+ // nothing to do
+ }
+
public PersistentSettings saveProperty(String key, @Nullable String value) {
settings.setProperty(key, value);
propertiesDao.setProperty(new PropertyDto().setKey(key).setValue(value));
return settings;
}
- public List<PropertyDto> getGlobalProperties(){
+ public List<PropertyDto> getGlobalProperties() {
return propertiesDao.selectGlobalProperties();
}
}
import org.sonar.server.es.ESNode;
import org.sonar.server.platform.ws.PlatformWs;
import org.sonar.server.platform.ws.RestartHandler;
-import org.sonar.server.plugins.DefaultServerPluginRepository;
+import org.sonar.server.plugins.ServerPluginJarInstaller;
+import org.sonar.server.plugins.ServerPluginJarsInstaller;
+import org.sonar.server.plugins.ServerPluginRepository;
import org.sonar.server.plugins.InstalledPluginReferentialFactory;
-import org.sonar.server.plugins.PluginDeployer;
import org.sonar.server.plugins.ServerExtensionInstaller;
-import org.sonar.server.plugins.ServerPluginInstaller;
import org.sonar.server.startup.ServerMetadataPersister;
import org.sonar.server.ui.JRubyI18n;
import org.sonar.server.ui.JRubyProfiling;
level1Container.addSingleton(daoClass);
}
level1Container.addSingleton(PurgeProfiler.class);
- level1Container.addSingleton(PluginDeployer.class);
- level1Container.addSingleton(ServerPluginInstaller.class);
- level1Container.addSingleton(InstalledPluginReferentialFactory.class);
- level1Container.addSingleton(DefaultServerPluginRepository.class);
level1Container.addSingleton(DefaultServerFileSystem.class);
+ level1Container.addSingleton(PreviewDatabaseFactory.class);
+ level1Container.addSingleton(SemaphoreUpdater.class);
+ level1Container.addSingleton(SemaphoresImpl.class);
+ level1Container.addPicoAdapter(new TempFolderProvider());
+ level1Container.addSingleton(TempFolderCleaner.class);
+
+
+ // plugins
+ level1Container.addSingleton(ServerPluginJarsInstaller.class);
+ level1Container.addSingleton(ServerPluginJarInstaller.class);
+ level1Container.addSingleton(InstalledPluginReferentialFactory.class);
+ level1Container.addSingleton(ServerPluginRepository.class);
+ level1Container.addSingleton(ServerExtensionInstaller.class);
+
+ // depends on plugins
level1Container.addSingleton(RailsAppsDeployer.class);
level1Container.addSingleton(JRubyI18n.class);
level1Container.addSingleton(DefaultI18n.class);
level1Container.addSingleton(RuleI18nManager.class);
level1Container.addSingleton(GwtI18n.class);
level1Container.addSingleton(Durations.class);
- level1Container.addSingleton(PreviewDatabaseFactory.class);
- level1Container.addSingleton(SemaphoreUpdater.class);
- level1Container.addSingleton(SemaphoresImpl.class);
- level1Container.addPicoAdapter(new TempFolderProvider());
- level1Container.addSingleton(TempFolderCleaner.class);
level1Container.startComponents();
}
level2Container = level1Container.createChild();
level2Container.addSingleton(PersistentSettings.class);
level2Container.addSingleton(DefaultDatabaseConnector.class);
- level2Container.addSingleton(ServerExtensionInstaller.class);
level2Container.addSingleton(ThreadLocalDatabaseSessionFactory.class);
level2Container.addPicoAdapter(new DatabaseSessionProvider());
level2Container.addSingleton(ServerMetadataPersister.class);
import com.google.common.base.Function;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
+import org.picocontainer.Startable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.platform.PluginMetadata;
*
* @since 3.0
*/
-public class RailsAppsDeployer {
+public class RailsAppsDeployer implements Startable {
+
private static final Logger LOG = LoggerFactory.getLogger(RailsAppsDeployer.class);
private static final String ROR_PATH = "org/sonar/ror/";
this.pluginRepository = pluginRepository;
}
+ @Override
public void start() {
LOG.info("Deploy Ruby on Rails applications");
File appsDir = prepareRailsDirectory();
}
}
+ @Override
+ public void stop() {
+ // do nothing
+ }
+
@VisibleForTesting
File prepareRailsDirectory() {
File appsDir = new File(fileSystem.getTempDir(), "ror");
pico.addSingleton(StringListTypeValidation.class);
ServerExtensionInstaller extensionRegistrar = pico.getComponentByType(ServerExtensionInstaller.class);
- extensionRegistrar.registerExtensions(pico);
+ extensionRegistrar.installExtensions(pico);
}
private void executeStartupTaks(ComponentContainer pico) {
import com.google.common.base.Joiner;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
+import org.picocontainer.Startable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
import java.util.Date;
import java.util.Properties;
-public final class ServerImpl extends Server {
+public final class ServerImpl extends Server implements Startable {
private static final Logger LOG = LoggerFactory.getLogger(ServerImpl.class);
private final Settings settings;
this.pomProperties = pomProperties;
}
+ @Override
public void start() {
try {
id = new SimpleDateFormat("yyyyMMddHHmmss").format(startedAt);
}
}
+ @Override
+ public void stop() {
+ // do nothing
+ }
+
@Override
public String getPermanentServerId() {
return settings.getString(CoreProperties.PERMANENT_SERVER_ID);
*/
package org.sonar.server.platform;
+import org.picocontainer.Startable;
import org.slf4j.LoggerFactory;
-import org.sonar.api.ServerComponent;
+import org.sonar.api.platform.Server;
import org.sonar.api.platform.ServerStartHandler;
import org.sonar.api.platform.ServerStopHandler;
-import org.sonar.api.platform.Server;
/**
* @since 2.2
*/
-public class ServerLifecycleNotifier implements ServerComponent {
+public class ServerLifecycleNotifier implements Startable {
private ServerStartHandler[] startHandlers;
private ServerStopHandler[] stopHandlers;
this(server, new ServerStartHandler[0], new ServerStopHandler[0]);
}
+ @Override
public void start() {
/* IMPORTANT :
we want to be sure that handlers are notified when all other services are started.
}
}
+ @Override
public void stop() {
LoggerFactory.getLogger(ServerLifecycleNotifier.class).debug("Notify " + ServerStopHandler.class.getSimpleName() + " handlers...");
for (ServerStopHandler handler : stopHandlers) {
package org.sonar.server.platform;
import com.google.common.annotations.VisibleForTesting;
-import org.sonar.api.ServerComponent;
import org.sonar.api.config.GlobalPropertyChangeHandler;
import javax.annotation.Nullable;
-public class SettingsChangeNotifier implements ServerComponent {
+public class SettingsChangeNotifier {
@VisibleForTesting
GlobalPropertyChangeHandler[] changeHandlers;
+++ /dev/null
-/*
- * 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.
- */
-package org.sonar.server.plugins;
-
-import org.picocontainer.Startable;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.Plugin;
-import org.sonar.api.platform.PluginMetadata;
-import org.sonar.api.platform.PluginRepository;
-import org.sonar.core.plugins.PluginClassloaders;
-
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * This class loads JAR files and initializes classloaders of plugins
- */
-public class DefaultServerPluginRepository implements PluginRepository, Startable {
-
- private final PluginDeployer deployer;
- private final PluginClassloaders classloaders;
- private Map<String, Plugin> pluginsByKey;
-
- public DefaultServerPluginRepository(PluginDeployer deployer) {
- this.classloaders = new PluginClassloaders(getClass().getClassLoader());
- this.deployer = deployer;
- }
-
- @Override
- public void start() {
- Collection<PluginMetadata> metadata = deployer.getMetadata();
- pluginsByKey = classloaders.init(metadata);
- }
-
- @Override
- public void stop() {
- classloaders.clean();
- }
-
- @Override
- public Plugin getPlugin(String key) {
- return pluginsByKey.get(key);
- }
-
- public ClassLoader getClassLoader(String pluginKey) {
- return classloaders.get(pluginKey);
- }
-
- public Class getClass(String pluginKey, String classname) {
- Class clazz = null;
- ClassLoader classloader = getClassLoader(pluginKey);
- if (classloader != null) {
- try {
- clazz = classloader.loadClass(classname);
-
- } catch (ClassNotFoundException e) {
- LoggerFactory.getLogger(getClass()).warn("Class not found in plugin " + pluginKey + ": " + classname, e);
- }
- }
- return clazz;
- }
-
- @Override
- public Collection<PluginMetadata> getMetadata() {
- return deployer.getMetadata();
- }
-
- @Override
- public PluginMetadata getMetadata(String pluginKey) {
- return deployer.getMetadata(pluginKey);
- }
-
-}
*/
package org.sonar.server.plugins;
-import org.sonar.api.ServerComponent;
+import org.picocontainer.Startable;
import org.sonar.api.platform.PluginRepository;
import org.sonar.updatecenter.common.PluginReferential;
-public class InstalledPluginReferentialFactory implements ServerComponent {
+public class InstalledPluginReferentialFactory implements Startable {
private final PluginRepository pluginRepository;
private PluginReferential installedPluginReferential;
this.pluginRepository = pluginRepository;
}
+ @Override
public void start() {
try {
init();
}
}
+ @Override
+ public void stop() {
+ // nothing to do
+ }
+
public PluginReferential getInstalledPluginReferential() {
return installedPluginReferential;
}
+++ /dev/null
-/*
- * 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.
- */
-package org.sonar.server.plugins;
-
-import com.google.common.base.Joiner;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.ServerComponent;
-import org.sonar.api.platform.PluginMetadata;
-import org.sonar.api.platform.Server;
-import org.sonar.api.platform.ServerUpgradeStatus;
-import org.sonar.api.utils.TimeProfiler;
-import org.sonar.core.plugins.DefaultPluginMetadata;
-import org.sonar.server.platform.DefaultServerFileSystem;
-import org.sonar.updatecenter.common.PluginReferential;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-public class PluginDeployer implements ServerComponent {
-
- private static final Logger LOG = LoggerFactory.getLogger(PluginDeployer.class);
-
- private final Server server;
- private final DefaultServerFileSystem fileSystem;
- private final ServerPluginInstaller installer;
- private final Map<String, PluginMetadata> pluginByKeys = Maps.newHashMap();
- private final ServerUpgradeStatus serverUpgradeStatus;
-
- public PluginDeployer(Server server, ServerUpgradeStatus serverUpgradeStatus, DefaultServerFileSystem fileSystem, ServerPluginInstaller installer) {
- this.server = server;
- this.serverUpgradeStatus = serverUpgradeStatus;
- this.fileSystem = fileSystem;
- this.installer = installer;
- }
-
- public void start() {
- TimeProfiler profiler = new TimeProfiler().start("Install plugins");
-
- deleteUninstalledPlugins();
-
- loadUserPlugins();
- if (serverUpgradeStatus.isFreshInstall()) {
- copyAndLoadBundledPlugins();
- }
- moveAndLoadDownloadedPlugins();
- loadCorePlugins();
-
- deployPlugins();
-
- profiler.stop();
- }
-
- private void deleteUninstalledPlugins() {
- File trashDir = fileSystem.getRemovedPluginsDir();
- try {
- if (trashDir.exists()) {
- FileUtils.deleteDirectory(trashDir);
- }
- } catch (IOException e) {
- throw new IllegalStateException("Fail to clean the plugin trash directory: " + trashDir, e);
- }
- }
-
- private void loadUserPlugins() {
- for (File file : fileSystem.getUserPlugins()) {
- registerPlugin(file, false, false);
- }
- }
-
- private void registerPlugin(File file, boolean isCore, boolean canDelete) {
- DefaultPluginMetadata metadata = installer.extractMetadata(file, isCore);
- if (StringUtils.isBlank(metadata.getKey())) {
- return;
- }
-
- PluginMetadata existing = pluginByKeys.put(metadata.getKey(), metadata);
-
- if ((existing != null) && !canDelete) {
- throw new IllegalStateException("Found two plugins with the same key '" + metadata.getKey() + "': " + metadata.getFile().getName() + " and "
- + existing.getFile().getName());
- }
-
- if (existing != null) {
- FileUtils.deleteQuietly(existing.getFile());
- LOG.info("Plugin " + metadata.getKey() + " replaced by new version");
- }
- }
-
- private void moveAndLoadDownloadedPlugins() {
- if (fileSystem.getDownloadedPluginsDir().exists()) {
- Collection<File> jars = FileUtils.listFiles(fileSystem.getDownloadedPluginsDir(), new String[] {"jar"}, false);
- for (File jar : jars) {
- installJarPlugin(jar, true);
- }
- }
- }
-
- private void copyAndLoadBundledPlugins() {
- for (File plugin : fileSystem.getBundledPlugins()) {
- installJarPlugin(plugin, false);
- }
- }
-
- private void installJarPlugin(File jar, boolean deleteSource) {
- File destDir = fileSystem.getUserPluginsDir();
- File destFile = new File(destDir, jar.getName());
- if (destFile.exists()) {
- // plugin with same filename already installed
- FileUtils.deleteQuietly(jar);
- }
- try {
- if (deleteSource) {
- FileUtils.moveFileToDirectory(jar, destDir, true);
- } else {
- FileUtils.copyFileToDirectory(jar, destDir, true);
- }
- registerPlugin(destFile, false, true);
-
- } catch (IOException e) {
- LOG.error("Fail to move plugin: " + jar.getAbsolutePath() + " to " + destDir.getAbsolutePath(), e);
- }
- }
-
- private void loadCorePlugins() {
- for (File file : fileSystem.getCorePlugins()) {
- registerPlugin(file, true, false);
- }
- }
-
- public void uninstall(String pluginKey) {
- for (String key : getPluginReferential().findLastReleasesWithDependencies(pluginKey)) {
- uninstallPlugin(key);
- }
- }
-
- private void uninstallPlugin(String pluginKey) {
- PluginMetadata metadata = pluginByKeys.get(pluginKey);
- if ((metadata != null) && !metadata.isCore()) {
- try {
- File masterFile = new File(fileSystem.getUserPluginsDir(), metadata.getFile().getName());
- FileUtils.moveFileToDirectory(masterFile, fileSystem.getRemovedPluginsDir(), true);
- } catch (IOException e) {
- throw new IllegalStateException("Fail to uninstall plugin: " + pluginKey, e);
- }
- }
- }
-
- public List<String> getUninstalls() {
- List<String> names = Lists.newArrayList();
- if (fileSystem.getRemovedPluginsDir().exists()) {
- List<File> files = (List<File>) FileUtils.listFiles(fileSystem.getRemovedPluginsDir(), new String[] {"jar"}, false);
- for (File file : files) {
- names.add(file.getName());
- }
- }
- return names;
- }
-
- public void cancelUninstalls() {
- if (fileSystem.getRemovedPluginsDir().exists()) {
- List<File> files = (List<File>) FileUtils.listFiles(fileSystem.getRemovedPluginsDir(), new String[] {"jar"}, false);
- for (File file : files) {
- try {
- FileUtils.moveFileToDirectory(file, fileSystem.getUserPluginsDir(), false);
- } catch (IOException e) {
- throw new IllegalStateException("Fail to cancel plugin uninstalls", e);
- }
- }
- }
- }
-
- private void deployPlugins() {
- for (PluginMetadata metadata : pluginByKeys.values()) {
- deploy((DefaultPluginMetadata) metadata);
- }
- }
-
- private void deploy(DefaultPluginMetadata plugin) {
- LOG.info("Deploy plugin {}", Joiner.on(" / ").skipNulls().join(plugin.getName(), plugin.getVersion(), plugin.getImplementationBuild()));
-
- Preconditions.checkState(plugin.isCompatibleWith(server.getVersion()),
- "Plugin %s needs a more recent version of SonarQube than %s. At least %s is expected",
- plugin.getKey(), server.getVersion(), plugin.getSonarVersion());
-
- try {
- File pluginDeployDir = new File(fileSystem.getDeployedPluginsDir(), plugin.getKey());
- FileUtils.forceMkdir(pluginDeployDir);
- FileUtils.cleanDirectory(pluginDeployDir);
-
- installer.installToDir(plugin, pluginDeployDir);
- } catch (IOException e) {
- throw new IllegalStateException("Fail to deploy the plugin " + plugin, e);
- }
- }
-
- public Collection<PluginMetadata> getMetadata() {
- return pluginByKeys.values();
- }
-
- public PluginMetadata getMetadata(String pluginKey) {
- return pluginByKeys.get(pluginKey);
- }
-
- private PluginReferential getPluginReferential() {
- return PluginReferentialMetadataConverter.getInstalledPluginReferential(getMetadata());
- }
-}
import org.picocontainer.Startable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.sonar.api.ServerComponent;
import org.sonar.api.utils.HttpDownloader;
import org.sonar.api.utils.SonarException;
import org.sonar.server.platform.DefaultServerFileSystem;
import java.util.Collection;
import java.util.List;
-public class PluginDownloader implements ServerComponent, Startable {
+public class PluginDownloader implements Startable {
private static final Logger LOG = LoggerFactory.getLogger(PluginDownloader.class);
private static final String TMP_SUFFIX = "tmp";
this.pluginRepository = pluginRepository;
}
- public void registerExtensions(ComponentContainer container) {
+ public void installExtensions(ComponentContainer container) {
ListMultimap<PluginMetadata, Object> installedExtensionsByPlugin = ArrayListMultimap.create();
for (PluginMetadata pluginMetadata : pluginRepository.getMetadata()) {
+++ /dev/null
-/*
- * 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.
- */
-package org.sonar.server.plugins;
-
-import org.apache.commons.io.FileUtils;
-import org.sonar.api.ServerComponent;
-import org.sonar.api.utils.SonarException;
-import org.sonar.api.utils.ZipUtils;
-import org.sonar.core.plugins.DefaultPluginMetadata;
-import org.sonar.core.plugins.PluginInstaller;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.zip.ZipEntry;
-
-public class ServerPluginInstaller extends PluginInstaller implements ServerComponent {
-
- public void installToDir(DefaultPluginMetadata metadata, File pluginBasedir) {
- try {
- File pluginFile = metadata.getFile();
- File deployedPlugin = copyPlugin(pluginBasedir, pluginFile);
- install(metadata, pluginBasedir, deployedPlugin);
- } catch (IOException e) {
- throw new SonarException(FAIL_TO_INSTALL_PLUGIN + metadata, e);
- }
- }
-
- private File copyPlugin(File pluginBasedir, File pluginFile) throws IOException {
- FileUtils.forceMkdir(pluginBasedir);
- File targetFile = new File(pluginBasedir, pluginFile.getName());
- FileUtils.copyFile(pluginFile, targetFile);
- return targetFile;
- }
-
- @Override
- protected File extractPluginDependencies(File pluginFile, File pluginBasedir) throws IOException {
- ZipUtils.unzip(pluginFile, pluginBasedir, new LibFilter());
- return pluginBasedir;
- }
-
- private static final class LibFilter implements ZipUtils.ZipEntryFilter {
- public boolean accept(ZipEntry entry) {
- return entry.getName().startsWith("META-INF/lib");
- }
- }
-}
--- /dev/null
+/*
+ * 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.
+ */
+package org.sonar.server.plugins;
+
+import org.apache.commons.io.FileUtils;
+import org.sonar.api.utils.ZipUtils;
+import org.sonar.core.plugins.DefaultPluginMetadata;
+import org.sonar.core.plugins.PluginJarInstaller;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.zip.ZipEntry;
+
+public class ServerPluginJarInstaller extends PluginJarInstaller {
+
+ public void installToDir(DefaultPluginMetadata metadata, File pluginBasedir) {
+ try {
+ File pluginFile = metadata.getFile();
+ File deployedPlugin = copyPlugin(pluginBasedir, pluginFile);
+ install(metadata, pluginBasedir, deployedPlugin);
+ } catch (IOException e) {
+ throw new IllegalStateException(FAIL_TO_INSTALL_PLUGIN + metadata, e);
+ }
+ }
+
+ private File copyPlugin(File pluginBasedir, File pluginFile) throws IOException {
+ FileUtils.forceMkdir(pluginBasedir);
+ File targetFile = new File(pluginBasedir, pluginFile.getName());
+ FileUtils.copyFile(pluginFile, targetFile);
+ return targetFile;
+ }
+
+ @Override
+ protected File extractPluginDependencies(File pluginFile, File pluginBasedir) throws IOException {
+ ZipUtils.unzip(pluginFile, pluginBasedir, new LibFilter());
+ return pluginBasedir;
+ }
+
+ private static final class LibFilter implements ZipUtils.ZipEntryFilter {
+ public boolean accept(ZipEntry entry) {
+ return entry.getName().startsWith("META-INF/lib");
+ }
+ }
+}
--- /dev/null
+/*
+ * 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.
+ */
+package org.sonar.server.plugins;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.platform.PluginMetadata;
+import org.sonar.api.platform.Server;
+import org.sonar.api.platform.ServerUpgradeStatus;
+import org.sonar.api.utils.TimeProfiler;
+import org.sonar.core.plugins.DefaultPluginMetadata;
+import org.sonar.server.platform.DefaultServerFileSystem;
+import org.sonar.updatecenter.common.PluginReferential;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+public class ServerPluginJarsInstaller {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ServerPluginJarsInstaller.class);
+
+ private final Server server;
+ private final DefaultServerFileSystem fileSystem;
+ private final ServerPluginJarInstaller installer;
+ private final Map<String, PluginMetadata> pluginByKeys = Maps.newHashMap();
+ private final ServerUpgradeStatus serverUpgradeStatus;
+
+ public ServerPluginJarsInstaller(Server server, ServerUpgradeStatus serverUpgradeStatus,
+ DefaultServerFileSystem fileSystem, ServerPluginJarInstaller installer) {
+ this.server = server;
+ this.serverUpgradeStatus = serverUpgradeStatus;
+ this.fileSystem = fileSystem;
+ this.installer = installer;
+ }
+
+ public void install() {
+ TimeProfiler profiler = new TimeProfiler().start("Install plugins");
+ deleteUninstalledPlugins();
+ loadUserPlugins();
+ if (serverUpgradeStatus.isFreshInstall()) {
+ copyAndLoadBundledPlugins();
+ }
+ moveAndLoadDownloadedPlugins();
+ loadCorePlugins();
+ deployPlugins();
+ profiler.stop();
+ }
+
+ private void deleteUninstalledPlugins() {
+ File trashDir = fileSystem.getRemovedPluginsDir();
+ try {
+ if (trashDir.exists()) {
+ FileUtils.deleteDirectory(trashDir);
+ }
+ } catch (IOException e) {
+ throw new IllegalStateException("Fail to clean the plugin trash directory: " + trashDir, e);
+ }
+ }
+
+ private void loadUserPlugins() {
+ for (File file : fileSystem.getUserPlugins()) {
+ registerPlugin(file, false, false);
+ }
+ }
+
+ private void registerPlugin(File file, boolean isCore, boolean canDelete) {
+ DefaultPluginMetadata metadata = installer.extractMetadata(file, isCore);
+ if (StringUtils.isBlank(metadata.getKey())) {
+ return;
+ }
+
+ PluginMetadata existing = pluginByKeys.put(metadata.getKey(), metadata);
+
+ if ((existing != null) && !canDelete) {
+ throw new IllegalStateException("Found two plugins with the same key '" + metadata.getKey() + "': " + metadata.getFile().getName() + " and "
+ + existing.getFile().getName());
+ }
+
+ if (existing != null) {
+ FileUtils.deleteQuietly(existing.getFile());
+ LOG.info("Plugin " + metadata.getKey() + " replaced by new version");
+ }
+ }
+
+ private void moveAndLoadDownloadedPlugins() {
+ if (fileSystem.getDownloadedPluginsDir().exists()) {
+ Collection<File> jars = FileUtils.listFiles(fileSystem.getDownloadedPluginsDir(), new String[]{"jar"}, false);
+ for (File jar : jars) {
+ installJarPlugin(jar, true);
+ }
+ }
+ }
+
+ private void copyAndLoadBundledPlugins() {
+ for (File plugin : fileSystem.getBundledPlugins()) {
+ installJarPlugin(plugin, false);
+ }
+ }
+
+ private void installJarPlugin(File jar, boolean deleteSource) {
+ File destDir = fileSystem.getUserPluginsDir();
+ File destFile = new File(destDir, jar.getName());
+ if (destFile.exists()) {
+ // plugin with same filename already installed
+ FileUtils.deleteQuietly(jar);
+ }
+ try {
+ if (deleteSource) {
+ FileUtils.moveFileToDirectory(jar, destDir, true);
+ } else {
+ FileUtils.copyFileToDirectory(jar, destDir, true);
+ }
+ registerPlugin(destFile, false, true);
+
+ } catch (IOException e) {
+ LOG.error("Fail to move plugin: " + jar.getAbsolutePath() + " to " + destDir.getAbsolutePath(), e);
+ }
+ }
+
+ private void loadCorePlugins() {
+ for (File file : fileSystem.getCorePlugins()) {
+ registerPlugin(file, true, false);
+ }
+ }
+
+ public void uninstall(String pluginKey) {
+ for (String key : getPluginReferential().findLastReleasesWithDependencies(pluginKey)) {
+ uninstallPlugin(key);
+ }
+ }
+
+ private void uninstallPlugin(String pluginKey) {
+ PluginMetadata metadata = pluginByKeys.get(pluginKey);
+ if ((metadata != null) && !metadata.isCore()) {
+ try {
+ File masterFile = new File(fileSystem.getUserPluginsDir(), metadata.getFile().getName());
+ FileUtils.moveFileToDirectory(masterFile, fileSystem.getRemovedPluginsDir(), true);
+ } catch (IOException e) {
+ throw new IllegalStateException("Fail to uninstall plugin: " + pluginKey, e);
+ }
+ }
+ }
+
+ public List<String> getUninstalls() {
+ List<String> names = Lists.newArrayList();
+ if (fileSystem.getRemovedPluginsDir().exists()) {
+ List<File> files = (List<File>) FileUtils.listFiles(fileSystem.getRemovedPluginsDir(), new String[]{"jar"}, false);
+ for (File file : files) {
+ names.add(file.getName());
+ }
+ }
+ return names;
+ }
+
+ public void cancelUninstalls() {
+ if (fileSystem.getRemovedPluginsDir().exists()) {
+ List<File> files = (List<File>) FileUtils.listFiles(fileSystem.getRemovedPluginsDir(), new String[]{"jar"}, false);
+ for (File file : files) {
+ try {
+ FileUtils.moveFileToDirectory(file, fileSystem.getUserPluginsDir(), false);
+ } catch (IOException e) {
+ throw new IllegalStateException("Fail to cancel plugin uninstalls", e);
+ }
+ }
+ }
+ }
+
+ private void deployPlugins() {
+ for (PluginMetadata metadata : pluginByKeys.values()) {
+ deploy((DefaultPluginMetadata) metadata);
+ }
+ }
+
+ private void deploy(DefaultPluginMetadata plugin) {
+ LOG.info("Deploy plugin {}", Joiner.on(" / ").skipNulls().join(plugin.getName(), plugin.getVersion(), plugin.getImplementationBuild()));
+
+ Preconditions.checkState(plugin.isCompatibleWith(server.getVersion()),
+ "Plugin %s needs a more recent version of SonarQube than %s. At least %s is expected",
+ plugin.getKey(), server.getVersion(), plugin.getSonarVersion());
+
+ try {
+ File pluginDeployDir = new File(fileSystem.getDeployedPluginsDir(), plugin.getKey());
+ FileUtils.forceMkdir(pluginDeployDir);
+ FileUtils.cleanDirectory(pluginDeployDir);
+
+ installer.installToDir(plugin, pluginDeployDir);
+ } catch (IOException e) {
+ throw new IllegalStateException("Fail to deploy the plugin " + plugin, e);
+ }
+ }
+
+ public Collection<PluginMetadata> getMetadata() {
+ return pluginByKeys.values();
+ }
+
+ public PluginMetadata getMetadata(String pluginKey) {
+ return pluginByKeys.get(pluginKey);
+ }
+
+ private PluginReferential getPluginReferential() {
+ return PluginReferentialMetadataConverter.getInstalledPluginReferential(getMetadata());
+ }
+}
--- /dev/null
+/*
+ * 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.
+ */
+package org.sonar.server.plugins;
+
+import org.picocontainer.Startable;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.Plugin;
+import org.sonar.api.platform.PluginMetadata;
+import org.sonar.api.platform.PluginRepository;
+import org.sonar.core.plugins.PluginClassloaders;
+
+import javax.annotation.CheckForNull;
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * This class loads JAR files and initializes classloaders of plugins
+ */
+public class ServerPluginRepository implements PluginRepository, Startable {
+
+ private final ServerPluginJarsInstaller jarsInstaller;
+ private final PluginClassloaders classloaders;
+ private Map<String, Plugin> pluginsByKey;
+
+ public ServerPluginRepository(ServerPluginJarsInstaller jarsInstaller) {
+ this.classloaders = new PluginClassloaders(getClass().getClassLoader());
+ this.jarsInstaller = jarsInstaller;
+ }
+
+ @Override
+ public void start() {
+ jarsInstaller.install();
+ Collection<PluginMetadata> metadata = jarsInstaller.getMetadata();
+ pluginsByKey = classloaders.init(metadata);
+ }
+
+ @Override
+ public void stop() {
+ classloaders.clean();
+ }
+
+ @Override
+ public Plugin getPlugin(String key) {
+ return pluginsByKey.get(key);
+ }
+
+ @CheckForNull
+ public ClassLoader getClassLoader(String pluginKey) {
+ return classloaders.get(pluginKey);
+ }
+
+ @CheckForNull
+ public Class getClass(String pluginKey, String classname) {
+ Class clazz = null;
+ ClassLoader classloader = getClassLoader(pluginKey);
+ if (classloader != null) {
+ try {
+ clazz = classloader.loadClass(classname);
+
+ } catch (ClassNotFoundException e) {
+ LoggerFactory.getLogger(getClass()).warn("Class not found in plugin " + pluginKey + ": " + classname, e);
+ }
+ }
+ return clazz;
+ }
+
+ @Override
+ public Collection<PluginMetadata> getMetadata() {
+ return jarsInstaller.getMetadata();
+ }
+
+ @Override
+ public PluginMetadata getMetadata(String pluginKey) {
+ return jarsInstaller.getMetadata(pluginKey);
+ }
+
+}
String pluginKey = getPluginKey(request);
String resource = getResourcePath(request);
- DefaultServerPluginRepository pluginRepository = Platform.getInstance().getContainer().getComponentByType(DefaultServerPluginRepository.class);
+ ServerPluginRepository pluginRepository = Platform.getInstance().getContainer().getComponentByType(ServerPluginRepository.class);
ClassLoader classLoader = pluginRepository.getClassLoader(pluginKey);
if (classLoader == null) {
LOG.error("Plugin not found: " + pluginKey);
import org.sonar.api.Properties;
import org.sonar.api.Property;
import org.sonar.api.PropertyType;
-import org.sonar.api.ServerComponent;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.UriReader;
import org.sonar.updatecenter.common.UpdateCenter;
* @since 2.4
*/
@Properties({
- @Property(
- key = "sonar.updatecenter.activate",
- defaultValue = "true",
- name = "Enable Update Center",
- project = false,
- // hidden from UI
- global = false,
- category = "Update Center",
- type = PropertyType.BOOLEAN),
- @Property(
- key = UpdateCenterClient.URL_PROPERTY,
- defaultValue = "http://update.sonarsource.org/update-center.properties",
- name = "Update Center URL",
- project = false,
- // hidden from UI
- global = false,
- category = "Update Center")
+ @Property(
+ key = "sonar.updatecenter.activate",
+ defaultValue = "true",
+ name = "Enable Update Center",
+ project = false,
+ // hidden from UI
+ global = false,
+ category = "Update Center",
+ type = PropertyType.BOOLEAN),
+ @Property(
+ key = UpdateCenterClient.URL_PROPERTY,
+ defaultValue = "http://update.sonarsource.org/update-center.properties",
+ name = "Update Center URL",
+ project = false,
+ // hidden from UI
+ global = false,
+ category = "Update Center")
})
-public class UpdateCenterClient implements ServerComponent {
+public class UpdateCenterClient {
public static final String URL_PROPERTY = "sonar.updatecenter.url";
public static final int PERIOD_IN_MILLISECONDS = 60 * 60 * 1000;
- private URI uri;
+
+ private final URI uri;
+ private final UriReader uriReader;
private UpdateCenter pluginCenter = null;
private long lastRefreshDate = 0;
- private UriReader uriReader;
public UpdateCenterClient(UriReader uriReader, Settings settings) throws URISyntaxException {
this.uriReader = uriReader;
*/
package org.sonar.server.plugins;
-import org.sonar.api.ServerComponent;
import org.sonar.api.platform.Server;
import org.sonar.updatecenter.common.UpdateCenter;
import org.sonar.updatecenter.common.Version;
/**
* @since 2.4
*/
-public class UpdateCenterMatrixFactory implements ServerComponent {
+public class UpdateCenterMatrixFactory {
private final UpdateCenterClient centerClient;
private final Version sonarVersion;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.sql.Connection;
}
public void uninstallPlugin(String pluginKey) {
- get(PluginDeployer.class).uninstall(pluginKey);
+ get(ServerPluginJarsInstaller.class).uninstall(pluginKey);
}
public void cancelPluginUninstalls() {
- get(PluginDeployer.class).cancelUninstalls();
+ get(ServerPluginJarsInstaller.class).cancelUninstalls();
}
public List<String> getPluginUninstalls() {
- return get(PluginDeployer.class).getUninstalls();
+ return get(ServerPluginJarsInstaller.class).getUninstalls();
}
public UpdateCenter getUpdatePluginCenter(boolean forceReload) {
public Object getComponentByClassname(String pluginKey, String className) {
Object component = null;
- Class<?> componentClass = get(DefaultServerPluginRepository.class).getClass(pluginKey, className);
+ Class<?> componentClass = get(ServerPluginRepository.class).getClass(pluginKey, className);
if (componentClass != null) {
component = get(componentClass);
}
+++ /dev/null
-/*
- * 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.
- */
-package org.sonar.server.plugins;
-
-import org.junit.After;
-import org.junit.Test;
-import org.sonar.api.platform.PluginMetadata;
-import org.sonar.core.plugins.DefaultPluginMetadata;
-import org.sonar.test.TestUtils;
-
-import java.io.File;
-import java.util.Arrays;
-
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.core.IsNot.not;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class DefaultServerPluginRepositoryTest {
-
- DefaultServerPluginRepository repository;
-
- @After
- public void stop() {
- if (repository != null) {
- repository.stop();
- }
- }
-
- @Test
- public void testStart() {
- PluginDeployer deployer = mock(PluginDeployer.class);
- File pluginFile = TestUtils.getResource("/org/sonar/server/plugins/DefaultServerPluginRepositoryTest/sonar-artifact-size-plugin-0.2.jar");
- PluginMetadata plugin = DefaultPluginMetadata.create(pluginFile)
- .setKey("artifactsize")
- .setMainClass("org.sonar.plugins.artifactsize.ArtifactSizePlugin")
- .addDeployedFile(pluginFile);
- when(deployer.getMetadata()).thenReturn(Arrays.asList(plugin));
-
- repository = new DefaultServerPluginRepository(deployer);
- repository.start();
-
- assertThat(repository.getPlugin("artifactsize"), not(nullValue()));
- assertThat(repository.getClassLoader("artifactsize"), not(nullValue()));
- assertThat(repository.getClass("artifactsize", "org.sonar.plugins.artifactsize.ArtifactSizeMetrics"), not(nullValue()));
- assertThat(repository.getClass("artifactsize", "org.Unknown"), nullValue());
- assertThat(repository.getClass("other", "org.sonar.plugins.artifactsize.ArtifactSizeMetrics"), nullValue());
- }
-}
+++ /dev/null
-/*
- * 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.
- */
-package org.sonar.server.plugins;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.junit.rules.TestName;
-import org.sonar.api.platform.PluginMetadata;
-import org.sonar.api.platform.Server;
-import org.sonar.api.platform.ServerUpgradeStatus;
-import org.sonar.server.platform.DefaultServerFileSystem;
-import org.sonar.test.TestUtils;
-
-import java.io.File;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class PluginDeployerTest {
-
- @Rule
- public TestName name = new TestName();
- @Rule
- public ExpectedException exception = ExpectedException.none();
- private ServerPluginInstaller extractor;
- private DefaultServerFileSystem fileSystem;
- private File homeDir;
- private File deployDir;
- private PluginDeployer deployer;
- private Server server = mock(Server.class);
- private ServerUpgradeStatus serverUpgradeStatus;
-
- @Before
- public void start() {
- when(server.getVersion()).thenReturn("3.1");
- homeDir = TestUtils.getResource(PluginDeployerTest.class, name.getMethodName());
- deployDir = TestUtils.getTestTempDir(PluginDeployerTest.class, name.getMethodName() + "/deploy");
- fileSystem = new DefaultServerFileSystem(null, homeDir, deployDir);
- extractor = new ServerPluginInstaller();
- serverUpgradeStatus = mock(ServerUpgradeStatus.class);
- deployer = new PluginDeployer(server, serverUpgradeStatus, fileSystem, extractor);
- }
-
- @Test
- public void deployPlugin() {
- when(serverUpgradeStatus.isFreshInstall()).thenReturn(false);
-
- deployer.start();
-
- // check that the plugin is registered
- assertThat(deployer.getMetadata()).hasSize(1);
-
- PluginMetadata plugin = deployer.getMetadata("foo");
- assertThat(plugin.getName()).isEqualTo("Foo");
- assertThat(plugin.getDeployedFiles()).hasSize(1);
- assertThat(plugin.isCore()).isFalse();
- assertThat(plugin.isUseChildFirstClassLoader()).isFalse();
-
- // check that the file is deployed
- File deployedJar = new File(deployDir, "plugins/foo/foo-plugin.jar");
- assertThat(deployedJar).exists();
- assertThat(deployedJar).isFile();
- }
-
- @Test
- public void deployBundledPluginsOnFreshInstall() {
- when(serverUpgradeStatus.isFreshInstall()).thenReturn(true);
-
- deployer.start();
-
- // check that the plugin is registered
- assertThat(deployer.getMetadata()).hasSize(2);
-
- PluginMetadata plugin = deployer.getMetadata("bar");
- assertThat(plugin.getName()).isEqualTo("Bar");
- assertThat(plugin.getDeployedFiles()).hasSize(1);
- assertThat(plugin.isCore()).isFalse();
- assertThat(plugin.isUseChildFirstClassLoader()).isFalse();
-
- // check that the file is deployed
- File deployedJar = new File(deployDir, "plugins/bar/bar-plugin.jar");
- assertThat(deployedJar).exists();
- assertThat(deployedJar).isFile();
- }
-
- @Test
- public void ignoreJarsWhichAreNotPlugins() {
- deployer.start();
-
- assertThat(deployer.getMetadata()).isEmpty();
- }
-
- @Test
- public void should_fail_on_plugin_depending_on_more_recent_sonar() {
- when(server.getVersion()).thenReturn("2.0");
-
- exception.expect(IllegalStateException.class);
- exception.expectMessage("Plugin switchoffviolations needs a more recent version of SonarQube than 2.0. At least 2.5 is expected");
-
- deployer.start();
- }
-
- @Test(expected = IllegalStateException.class)
- public void failIfTwoPluginsWithSameKey() {
- deployer.start();
- }
-}
+++ /dev/null
-/*
- * 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.
- */
-package org.sonar.server.plugins;
-
-import org.junit.Test;
-import org.sonar.api.BatchExtension;
-import org.sonar.api.ExtensionProvider;
-import org.sonar.api.ServerExtension;
-import org.sonar.api.SonarPlugin;
-
-import java.util.Arrays;
-import java.util.List;
-
-public class ServerExtensionInstallerTest {
- @Test
- public void shouldRegisterServerExtensions() {
-// ExtensionRegistrar repository = new ExtensionRegistrar(mock(PluginRepository.class));
-//
-// ComponentContainer container = new ComponentContainer();
-// repository.registerExtensions(container, Arrays.<Plugin>asList(new FakePlugin(Arrays.<Class>asList(FakeBatchExtension.class, FakeServerExtension.class))));
-//
-// assertThat(container.getComponentsByType(Extension.class).size(), is(1));
-// assertThat(container.getComponentsByType(FakeServerExtension.class).size(), is(1));
-// assertThat(container.getComponentsByType(FakeBatchExtension.class).size(), is(0));
- }
-
- @Test
- public void shouldInvokeServerExtensionProviders() {
-// DefaultServerPluginRepository repository = new DefaultServerPluginRepository(mock(PluginDeployer.class));
-//
-// ComponentContainer container = new ComponentContainer();
-// repository.registerExtensions(container, Arrays.<Plugin>asList(new FakePlugin(Arrays.<Class>asList(FakeExtensionProvider.class))));
-//
-// assertThat(container.getComponentsByType(Extension.class).size(), is(2));// provider + FakeServerExtension
-// assertThat(container.getComponentsByType(FakeServerExtension.class).size(), is(1));
-// assertThat(container.getComponentsByType(FakeBatchExtension.class).size(), is(0));
- }
-
- @Test
- public void shouldNotSupportProvidersOfProviders() {
-// DefaultServerPluginRepository repository = new DefaultServerPluginRepository(mock(PluginDeployer.class));
-//
-// ComponentContainer container = new ComponentContainer();
-// repository.registerExtensions(container, Arrays.<Plugin>asList(new FakePlugin(Arrays.<Class>asList(SuperExtensionProvider.class))));
-//
-// assertThat(container.getComponentsByType(FakeBatchExtension.class).size(), is(0));
-// assertThat(container.getComponentsByType(FakeServerExtension.class).size(), is(0));
- }
-
- public static class FakePlugin extends SonarPlugin {
- private List<Class> extensions;
-
- public FakePlugin(List<Class> extensions) {
- this.extensions = extensions;
- }
-
- public List<Class> getExtensions() {
- return extensions;
- }
- }
-
- public static class FakeBatchExtension implements BatchExtension {
-
- }
-
- public static class FakeServerExtension implements ServerExtension {
-
- }
-
- public static class FakeExtensionProvider extends ExtensionProvider implements ServerExtension {
-
- @Override
- public Object provide() {
- return Arrays.<Object> asList(FakeBatchExtension.class, FakeServerExtension.class);
- }
- }
-
- public static class SuperExtensionProvider extends ExtensionProvider implements ServerExtension {
-
- @Override
- public Object provide() {
- return FakeExtensionProvider.class;
- }
- }
-}
--- /dev/null
+/*
+ * 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.
+ */
+package org.sonar.server.plugins;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.rules.TestName;
+import org.sonar.api.platform.PluginMetadata;
+import org.sonar.api.platform.Server;
+import org.sonar.api.platform.ServerUpgradeStatus;
+import org.sonar.server.platform.DefaultServerFileSystem;
+import org.sonar.test.TestUtils;
+
+import java.io.File;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class ServerPluginJarsInstallerTest {
+
+ @Rule
+ public TestName name = new TestName();
+
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
+
+ ServerPluginJarInstaller jarInstaller;
+ DefaultServerFileSystem fileSystem;
+ File homeDir;
+ File deployDir;
+ ServerPluginJarsInstaller jarsInstaller;
+ Server server = mock(Server.class);
+ ServerUpgradeStatus serverUpgradeStatus;
+
+ @Before
+ public void before() {
+ when(server.getVersion()).thenReturn("3.1");
+ homeDir = TestUtils.getResource(ServerPluginJarsInstallerTest.class, name.getMethodName());
+ deployDir = TestUtils.getTestTempDir(ServerPluginJarsInstallerTest.class, name.getMethodName() + "/deploy");
+ fileSystem = new DefaultServerFileSystem(null, homeDir, deployDir);
+ jarInstaller = new ServerPluginJarInstaller();
+ serverUpgradeStatus = mock(ServerUpgradeStatus.class);
+ jarsInstaller = new ServerPluginJarsInstaller(server, serverUpgradeStatus, fileSystem, jarInstaller);
+ }
+
+ @Test
+ public void deployPlugin() {
+ when(serverUpgradeStatus.isFreshInstall()).thenReturn(false);
+
+ jarsInstaller.install();
+
+ // check that the plugin is registered
+ assertThat(jarsInstaller.getMetadata()).hasSize(1);
+
+ PluginMetadata plugin = jarsInstaller.getMetadata("foo");
+ assertThat(plugin.getName()).isEqualTo("Foo");
+ assertThat(plugin.getDeployedFiles()).hasSize(1);
+ assertThat(plugin.isCore()).isFalse();
+ assertThat(plugin.isUseChildFirstClassLoader()).isFalse();
+
+ // check that the file is deployed
+ File deployedJar = new File(deployDir, "plugins/foo/foo-plugin.jar");
+ assertThat(deployedJar).exists();
+ assertThat(deployedJar).isFile();
+ }
+
+ @Test
+ public void deployBundledPluginsOnFreshInstall() {
+ when(serverUpgradeStatus.isFreshInstall()).thenReturn(true);
+
+ jarsInstaller.install();
+
+ // check that the plugin is registered
+ assertThat(jarsInstaller.getMetadata()).hasSize(2);
+
+ PluginMetadata plugin = jarsInstaller.getMetadata("bar");
+ assertThat(plugin.getName()).isEqualTo("Bar");
+ assertThat(plugin.getDeployedFiles()).hasSize(1);
+ assertThat(plugin.isCore()).isFalse();
+ assertThat(plugin.isUseChildFirstClassLoader()).isFalse();
+
+ // check that the file is deployed
+ File deployedJar = new File(deployDir, "plugins/bar/bar-plugin.jar");
+ assertThat(deployedJar).exists();
+ assertThat(deployedJar).isFile();
+ }
+
+ @Test
+ public void ignoreJarsWhichAreNotPlugins() {
+ jarsInstaller.install();
+
+ assertThat(jarsInstaller.getMetadata()).isEmpty();
+ }
+
+ @Test
+ public void should_fail_on_plugin_depending_on_more_recent_sonar() {
+ when(server.getVersion()).thenReturn("2.0");
+
+ exception.expect(IllegalStateException.class);
+ exception.expectMessage("Plugin switchoffviolations needs a more recent version of SonarQube than 2.0. At least 2.5 is expected");
+
+ jarsInstaller.install();
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void failIfTwoPluginsWithSameKey() {
+ jarsInstaller.install();
+ }
+}
--- /dev/null
+/*
+ * 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.
+ */
+package org.sonar.server.plugins;
+
+import org.junit.After;
+import org.junit.Test;
+import org.sonar.api.platform.PluginMetadata;
+import org.sonar.core.plugins.DefaultPluginMetadata;
+import org.sonar.test.TestUtils;
+
+import java.io.File;
+import java.util.Arrays;
+
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.core.IsNot.not;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class ServerPluginRepositoryTest {
+
+ ServerPluginRepository repository;
+
+ @After
+ public void stop() {
+ if (repository != null) {
+ repository.stop();
+ }
+ }
+
+ @Test
+ public void testStart() {
+ ServerPluginJarsInstaller deployer = mock(ServerPluginJarsInstaller.class);
+ File pluginFile = TestUtils.getResource("/org/sonar/server/plugins/ServerPluginRepositoryTest/sonar-artifact-size-plugin-0.2.jar");
+ PluginMetadata plugin = DefaultPluginMetadata.create(pluginFile)
+ .setKey("artifactsize")
+ .setMainClass("org.sonar.plugins.artifactsize.ArtifactSizePlugin")
+ .addDeployedFile(pluginFile);
+ when(deployer.getMetadata()).thenReturn(Arrays.asList(plugin));
+
+ repository = new ServerPluginRepository(deployer);
+ repository.start();
+
+ assertThat(repository.getPlugin("artifactsize"), not(nullValue()));
+ assertThat(repository.getClassLoader("artifactsize"), not(nullValue()));
+ assertThat(repository.getClass("artifactsize", "org.sonar.plugins.artifactsize.ArtifactSizeMetrics"), not(nullValue()));
+ assertThat(repository.getClass("artifactsize", "org.Unknown"), nullValue());
+ assertThat(repository.getClass("other", "org.sonar.plugins.artifactsize.ArtifactSizeMetrics"), nullValue());
+ }
+}
+++ /dev/null
-this is an extension to the plugin foo
\ No newline at end of file
--- /dev/null
+this is an extension to the plugin foo
\ No newline at end of file