both on server side (web server & CE & scanner) and in SonarLinttags/7.5
@@ -20,13 +20,13 @@ | |||
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; |
@@ -178,6 +178,7 @@ public class PluginClassloaderFactory { | |||
.addInclusion("org/sonar/core/persistence/") | |||
.addInclusion("org/sonar/core/properties/") | |||
.addInclusion("org/sonar/server/views/") | |||
.addInclusion("com/sonarsource/plugins/license/api/") | |||
// API exclusions | |||
.addExclusion("org/sonar/api/internal/"); |
@@ -25,6 +25,7 @@ import com.google.common.collect.ComparisonChain; | |||
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; | |||
@@ -429,9 +430,10 @@ public class PluginInfo implements Comparable<PluginInfo> { | |||
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; | |||
} |
@@ -0,0 +1,23 @@ | |||
/* | |||
* 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 { | |||
} |
@@ -19,6 +19,7 @@ | |||
*/ | |||
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; | |||
@@ -92,6 +93,17 @@ public class PluginClassloaderFactoryTest { | |||
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); |
@@ -19,6 +19,9 @@ | |||
*/ | |||
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; | |||
@@ -30,6 +33,7 @@ import org.junit.Rule; | |||
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; | |||
@@ -39,6 +43,7 @@ import static com.google.common.collect.Ordering.natural; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.junit.Assert.fail; | |||
@RunWith(DataProviderRunner.class) | |||
public class PluginInfoTest { | |||
@Rule | |||
@@ -48,7 +53,7 @@ public class PluginInfoTest { | |||
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"); | |||
@@ -105,7 +110,7 @@ public class PluginInfoTest { | |||
* 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(); | |||
@@ -134,7 +139,7 @@ public class PluginInfoTest { | |||
* @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(); | |||
@@ -224,6 +229,44 @@ public class PluginInfoTest { | |||
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")); |