package org.sonar.server.platform.platformlevel;
import org.sonar.api.utils.Durations;
+import org.sonar.core.extension.CoreExtensionRepositoryImpl;
+import org.sonar.core.extension.CoreExtensionsLoader;
import org.sonar.core.i18n.RuleI18nManager;
import org.sonar.core.platform.PluginClassloaderFactory;
import org.sonar.core.platform.PluginLoader;
-import org.sonar.core.extension.CoreExtensionRepositoryImpl;
-import org.sonar.core.extension.CoreExtensionsLoader;
-import org.sonar.server.l18n.ServerI18n;
import org.sonar.server.es.MigrationEsClientImpl;
+import org.sonar.server.l18n.ServerI18n;
import org.sonar.server.platform.DatabaseServerCompatibility;
import org.sonar.server.platform.DefaultServerUpgradeStatus;
import org.sonar.server.platform.StartupMetadataProvider;
import com.google.common.collect.Ordering;
import java.io.File;
import java.io.IOException;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
info.setImplementationBuild(manifest.getImplementationBuild());
String[] requiredPlugins = manifest.getRequirePlugins();
if (requiredPlugins != null) {
- for (String s : requiredPlugins) {
- info.addRequiredPlugin(RequiredPlugin.parse(s));
- }
+ Arrays.stream(requiredPlugins)
+ .map(RequiredPlugin::parse)
+ .filter(t -> !"license".equals(t.key))
+ .forEach(info::addRequiredPlugin);
}
return info;
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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 com.sonarsource.plugins.license.api;
+
+public interface FooBar {
+}
*/
package org.sonar.core.platform;
+import com.sonarsource.plugins.license.api.FooBar;
import java.io.File;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
assertThat(canLoadClass(baseClassloader, BASE_PLUGIN_CLASSNAME)).isTrue();
}
+ @Test
+ public void classloader_exposes_license_api_from_main_classloader() {
+ PluginClassLoaderDef def = basePluginDef();
+ Map<PluginClassLoaderDef, ClassLoader> map = factory.create(asList(def));
+
+ assertThat(map).containsOnlyKeys(def);
+ ClassLoader classLoader = map.get(def);
+
+ assertThat(canLoadClass(classLoader, FooBar.class.getCanonicalName())).isTrue();
+ }
+
private static PluginClassLoaderDef basePluginDef() {
PluginClassLoaderDef def = new PluginClassLoaderDef(BASE_PLUGIN_KEY);
def.addMainClass(BASE_PLUGIN_KEY, BASE_PLUGIN_CLASSNAME);
*/
package org.sonar.core.platform;
+import com.tngtech.java.junit.dataprovider.DataProvider;
+import com.tngtech.java.junit.dataprovider.DataProviderRunner;
+import com.tngtech.java.junit.dataprovider.UseDataProvider;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.ZipUtils;
import org.sonar.updatecenter.common.PluginManifest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
+@RunWith(DataProviderRunner.class)
public class PluginInfoTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
- public void test_RequiredPlugin() throws Exception {
+ public void test_RequiredPlugin() {
PluginInfo.RequiredPlugin plugin = PluginInfo.RequiredPlugin.parse("java:1.1");
assertThat(plugin.getKey()).isEqualTo("java");
assertThat(plugin.getMinimalVersion().getName()).isEqualTo("1.1");
* All other build environments have unique release versions (6.3.0.12345).
*/
@Test
- public void test_compatibility_with_snapshot_version_of_sonarqube() throws IOException {
+ public void test_compatibility_with_snapshot_version_of_sonarqube() {
// plugins compatible with 5.6 LTS
assertThat(withMinSqVersion("5.6").isCompatibleWith("6.3-SNAPSHOT")).isTrue();
assertThat(withMinSqVersion("5.6.1").isCompatibleWith("6.3-SNAPSHOT")).isTrue();
* @see #test_compatibility_with_snapshot_version_of_sonarqube
*/
@Test
- public void test_compatibility_with_release_version_of_sonarqube() throws IOException {
+ public void test_compatibility_with_release_version_of_sonarqube() {
// plugins compatible with 5.6 LTS
assertThat(withMinSqVersion("5.6").isCompatibleWith("6.3.0.5000")).isTrue();
assertThat(withMinSqVersion("5.6.1").isCompatibleWith("6.3.0.5000")).isTrue();
assertThat(pluginInfo.isSonarLintSupported()).isTrue();
}
+ @Test
+ @UseDataProvider("licenseVersions")
+ public void requiredPlugin_license_is_ignored_when_reading_manifest(String version) throws IOException {
+ PluginManifest manifest = new PluginManifest();
+ manifest.setKey("java");
+ manifest.setVersion("1.0");
+ manifest.setName("Java");
+ manifest.setMainClass("org.foo.FooPlugin");
+ manifest.setRequirePlugins(new String[] {"license:" + version});
+
+ File jarFile = temp.newFile();
+ PluginInfo pluginInfo = PluginInfo.create(jarFile, manifest);
+ assertThat(pluginInfo.getRequiredPlugins()).isEmpty();
+ }
+
+ @Test
+ @UseDataProvider("licenseVersions")
+ public void requiredPlugin_license_among_others_is_ignored_when_reading_manifest(String version) throws IOException {
+ PluginManifest manifest = new PluginManifest();
+ manifest.setKey("java");
+ manifest.setVersion("1.0");
+ manifest.setName("Java");
+ manifest.setMainClass("org.foo.FooPlugin");
+ manifest.setRequirePlugins(new String[] {"java:2.0", "license:" + version, "pmd:1.3"});
+
+ File jarFile = temp.newFile();
+ PluginInfo pluginInfo = PluginInfo.create(jarFile, manifest);
+ assertThat(pluginInfo.getRequiredPlugins()).extracting("key").containsOnly("java", "pmd");
+ }
+
+ @DataProvider
+ public static Object[][] licenseVersions() {
+ return new Object[][] {
+ {"0.3"},
+ {"7.2.0.1253"}
+ };
+ }
+
@Test
public void create_from_file() {
File checkstyleJar = FileUtils.toFile(getClass().getResource("/org/sonar/core/platform/sonar-checkstyle-plugin-2.8.jar"));