]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7428 Server fail to start if Views, SQALE or Report is installed
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 22 Mar 2016 16:35:24 +0000 (17:35 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 23 Mar 2016 12:23:00 +0000 (13:23 +0100)
22 files changed:
server/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java
server/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java
server/sonar-server/src/test/projects/fake-report-plugin/pom.xml [new file with mode: 0644]
server/sonar-server/src/test/projects/fake-report-plugin/src/BasePlugin.java [new file with mode: 0644]
server/sonar-server/src/test/projects/fake-report-plugin/src/org/sonar/plugins/testbase/api/BaseApi.java [new file with mode: 0644]
server/sonar-server/src/test/projects/fake-report-plugin/target/fake-report-plugin-0.1-SNAPSHOT.jar [new file with mode: 0644]
server/sonar-server/src/test/projects/fake-sqale-plugin/pom.xml [new file with mode: 0644]
server/sonar-server/src/test/projects/fake-sqale-plugin/src/BasePlugin.java [new file with mode: 0644]
server/sonar-server/src/test/projects/fake-sqale-plugin/src/org/sonar/plugins/testbase/api/BaseApi.java [new file with mode: 0644]
server/sonar-server/src/test/projects/fake-sqale-plugin/target/fake-sqale-plugin-0.1-SNAPSHOT.jar [new file with mode: 0644]
server/sonar-server/src/test/projects/fake-views-plugin/pom.xml [new file with mode: 0644]
server/sonar-server/src/test/projects/fake-views-plugin/src/BasePlugin.java [new file with mode: 0644]
server/sonar-server/src/test/projects/fake-views-plugin/src/org/sonar/plugins/testbase/api/BaseApi.java [new file with mode: 0644]
server/sonar-server/src/test/projects/fake-views-plugin/target/fake-views-plugin-0.1-SNAPSHOT.jar [new file with mode: 0644]
server/sonar-server/src/test/projects/pom.xml
server/sonar-server/src/test/projects/test-base-plugin-v2/target/test-base-plugin-0.2-SNAPSHOT.jar
server/sonar-server/src/test/projects/test-base-plugin/target/test-base-plugin-0.1-SNAPSHOT.jar
server/sonar-server/src/test/projects/test-core-plugin/target/test-core-plugin-0.1-SNAPSHOT.jar
server/sonar-server/src/test/projects/test-extend-plugin/target/test-extend-plugin-0.1-SNAPSHOT.jar
server/sonar-server/src/test/projects/test-libs-plugin/target/test-libs-plugin-0.1-SNAPSHOT.jar
server/sonar-server/src/test/projects/test-require-plugin/target/test-require-plugin-0.1-SNAPSHOT.jar
server/sonar-server/src/test/projects/test-requirenew-plugin/target/test-requirenew-plugin-0.1-SNAPSHOT.jar

index 66729394485a4b87f04eccc1ae339c629f4ddcb3..b11a78543878ab9574036bab7deb178b5dc55d29 100644 (file)
@@ -72,7 +72,10 @@ public class ServerPluginRepository implements PluginRepository, Startable {
 
   private static final Logger LOG = Loggers.get(ServerPluginRepository.class);
   private static final String[] JAR_FILE_EXTENSIONS = new String[] {"jar"};
+  // List of plugins that are silently removed if installed
   private static final Set<String> DEFAULT_BLACKLISTED_PLUGINS = ImmutableSet.of("scmactivity", "issuesreport");
+  // List of plugins that should prevent the server to finish its startup
+  private static final Set<String> FORBIDDEN_COMPATIBLE_PLUGINS = ImmutableSet.of("sqale", "report", "views");
   private static final Joiner SLASH_JOINER = Joiner.on(" / ").skipNulls();
 
   private final Server server;
@@ -157,15 +160,19 @@ public class ServerPluginRepository implements PluginRepository, Startable {
   }
 
   private void registerPluginInfo(PluginInfo info) {
-    if (blacklistedPluginKeys.contains(info.getKey())) {
-      LOG.warn("Plugin {} [{}] is blacklisted and is being uninstalled.", info.getName(), info.getKey());
+    String pluginKey = info.getKey();
+    if (blacklistedPluginKeys.contains(pluginKey)) {
+      LOG.warn("Plugin {} [{}] is blacklisted and is being uninstalled.", info.getName(), pluginKey);
       org.sonar.core.util.FileUtils.deleteQuietly(info.getNonNullJarFile());
       return;
     }
-    PluginInfo existing = pluginInfosByKeys.put(info.getKey(), info);
+    if (FORBIDDEN_COMPATIBLE_PLUGINS.contains(pluginKey)) {
+      throw MessageException.of(String.format("Plugin '%s' is no more compatible with this version of SonarQube", pluginKey));
+    }
+    PluginInfo existing = pluginInfosByKeys.put(pluginKey, info);
     if (existing != null) {
       throw MessageException.of(format("Found two files for the same plugin [%s]: %s and %s",
-        info.getKey(), info.getNonNullJarFile().getName(), existing.getNonNullJarFile().getName()));
+        pluginKey, info.getNonNullJarFile().getName(), existing.getNonNullJarFile().getName()));
     }
 
   }
index 31ba885dd95fe621aa51b5807ac340f6c6bdc5cb..a6173acd3177da9034381cc02bd01e38b2fd16df 100644 (file)
@@ -30,6 +30,7 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 import org.mockito.Mockito;
 import org.sonar.api.platform.Server;
@@ -48,6 +49,9 @@ import static org.mockito.Mockito.when;
 
 public class ServerPluginRepositoryTest {
 
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
 
@@ -309,6 +313,33 @@ public class ServerPluginRepositoryTest {
     assertThat(logs.logs()).contains("Plugin Foo [foo] is ignored because entry point class is not defined");
   }
 
+  @Test
+  public void fail_when_views_is_installed() throws Exception {
+    copyTestPluginTo("fake-views-plugin", fs.getInstalledPluginsDir());
+
+    thrown.expect(MessageException.class);
+    thrown.expectMessage("Plugin 'views' is no more compatible with this version of SonarQube");
+    underTest.start();
+  }
+
+  @Test
+  public void fail_when_sqale_plugin_is_installed() throws Exception {
+    copyTestPluginTo("fake-sqale-plugin", fs.getInstalledPluginsDir());
+
+    thrown.expect(MessageException.class);
+    thrown.expectMessage("Plugin 'sqale' is no more compatible with this version of SonarQube");
+    underTest.start();
+  }
+
+  @Test
+  public void fail_when_report_is_installed() throws Exception {
+    copyTestPluginTo("fake-report-plugin", fs.getInstalledPluginsDir());
+
+    thrown.expect(MessageException.class);
+    thrown.expectMessage("Plugin 'report' is no more compatible with this version of SonarQube");
+    underTest.start();
+  }
+
   /**
    * Some plugins can only extend the classloader of base plugin, without declaring new extensions.
    */
diff --git a/server/sonar-server/src/test/projects/fake-report-plugin/pom.xml b/server/sonar-server/src/test/projects/fake-report-plugin/pom.xml
new file mode 100644 (file)
index 0000000..72a04db
--- /dev/null
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.sonarsource.sonarqube.tests</groupId>
+  <artifactId>fake-report-plugin</artifactId>
+  <version>0.1-SNAPSHOT</version>
+  <packaging>sonar-plugin</packaging>
+  <name>Fake Report Plugin</name>
+  <description>Fake Report Plugin</description>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.codehaus.sonar</groupId>
+      <artifactId>sonar-plugin-api</artifactId>
+      <version>4.5.4</version>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+  <build>
+    <sourceDirectory>src</sourceDirectory>
+    <plugins>
+      <plugin>
+        <groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
+        <artifactId>sonar-packaging-maven-plugin</artifactId>
+        <version>1.15</version>
+        <extensions>true</extensions>
+        <configuration>
+          <pluginKey>report</pluginKey>
+          <pluginClass>BasePlugin</pluginClass>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/server/sonar-server/src/test/projects/fake-report-plugin/src/BasePlugin.java b/server/sonar-server/src/test/projects/fake-report-plugin/src/BasePlugin.java
new file mode 100644 (file)
index 0000000..57b4a5d
--- /dev/null
@@ -0,0 +1,11 @@
+import org.sonar.api.SonarPlugin;
+
+import java.util.Collections;
+import java.util.List;
+
+public class BasePlugin extends SonarPlugin {
+
+  public List getExtensions() {
+    return Collections.emptyList();
+  }
+}
diff --git a/server/sonar-server/src/test/projects/fake-report-plugin/src/org/sonar/plugins/testbase/api/BaseApi.java b/server/sonar-server/src/test/projects/fake-report-plugin/src/org/sonar/plugins/testbase/api/BaseApi.java
new file mode 100644 (file)
index 0000000..356a9c8
--- /dev/null
@@ -0,0 +1,6 @@
+package org.sonar.plugins.testbase.api;
+
+public class BaseApi {
+  public void doNothing() {
+  }
+}
diff --git a/server/sonar-server/src/test/projects/fake-report-plugin/target/fake-report-plugin-0.1-SNAPSHOT.jar b/server/sonar-server/src/test/projects/fake-report-plugin/target/fake-report-plugin-0.1-SNAPSHOT.jar
new file mode 100644 (file)
index 0000000..6085e44
Binary files /dev/null and b/server/sonar-server/src/test/projects/fake-report-plugin/target/fake-report-plugin-0.1-SNAPSHOT.jar differ
diff --git a/server/sonar-server/src/test/projects/fake-sqale-plugin/pom.xml b/server/sonar-server/src/test/projects/fake-sqale-plugin/pom.xml
new file mode 100644 (file)
index 0000000..e417dd9
--- /dev/null
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.sonarsource.sonarqube.tests</groupId>
+  <artifactId>fake-sqale-plugin</artifactId>
+  <version>0.1-SNAPSHOT</version>
+  <packaging>sonar-plugin</packaging>
+  <name>Fake SQALE Plugin</name>
+  <description>Fake SQALE Plugin</description>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.codehaus.sonar</groupId>
+      <artifactId>sonar-plugin-api</artifactId>
+      <version>4.5.4</version>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+  <build>
+    <sourceDirectory>src</sourceDirectory>
+    <plugins>
+      <plugin>
+        <groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
+        <artifactId>sonar-packaging-maven-plugin</artifactId>
+        <version>1.15</version>
+        <extensions>true</extensions>
+        <configuration>
+          <pluginKey>sqale</pluginKey>
+          <pluginClass>BasePlugin</pluginClass>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/server/sonar-server/src/test/projects/fake-sqale-plugin/src/BasePlugin.java b/server/sonar-server/src/test/projects/fake-sqale-plugin/src/BasePlugin.java
new file mode 100644 (file)
index 0000000..57b4a5d
--- /dev/null
@@ -0,0 +1,11 @@
+import org.sonar.api.SonarPlugin;
+
+import java.util.Collections;
+import java.util.List;
+
+public class BasePlugin extends SonarPlugin {
+
+  public List getExtensions() {
+    return Collections.emptyList();
+  }
+}
diff --git a/server/sonar-server/src/test/projects/fake-sqale-plugin/src/org/sonar/plugins/testbase/api/BaseApi.java b/server/sonar-server/src/test/projects/fake-sqale-plugin/src/org/sonar/plugins/testbase/api/BaseApi.java
new file mode 100644 (file)
index 0000000..356a9c8
--- /dev/null
@@ -0,0 +1,6 @@
+package org.sonar.plugins.testbase.api;
+
+public class BaseApi {
+  public void doNothing() {
+  }
+}
diff --git a/server/sonar-server/src/test/projects/fake-sqale-plugin/target/fake-sqale-plugin-0.1-SNAPSHOT.jar b/server/sonar-server/src/test/projects/fake-sqale-plugin/target/fake-sqale-plugin-0.1-SNAPSHOT.jar
new file mode 100644 (file)
index 0000000..b5c99f7
Binary files /dev/null and b/server/sonar-server/src/test/projects/fake-sqale-plugin/target/fake-sqale-plugin-0.1-SNAPSHOT.jar differ
diff --git a/server/sonar-server/src/test/projects/fake-views-plugin/pom.xml b/server/sonar-server/src/test/projects/fake-views-plugin/pom.xml
new file mode 100644 (file)
index 0000000..1ef73d2
--- /dev/null
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.sonarsource.sonarqube.tests</groupId>
+  <artifactId>fake-views-plugin</artifactId>
+  <version>0.1-SNAPSHOT</version>
+  <packaging>sonar-plugin</packaging>
+  <name>Fake Views Plugin</name>
+  <description>Fake Views Plugin</description>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.codehaus.sonar</groupId>
+      <artifactId>sonar-plugin-api</artifactId>
+      <version>4.5.4</version>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+  <build>
+    <sourceDirectory>src</sourceDirectory>
+    <plugins>
+      <plugin>
+        <groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
+        <artifactId>sonar-packaging-maven-plugin</artifactId>
+        <version>1.15</version>
+        <extensions>true</extensions>
+        <configuration>
+          <pluginKey>views</pluginKey>
+          <pluginClass>BasePlugin</pluginClass>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/server/sonar-server/src/test/projects/fake-views-plugin/src/BasePlugin.java b/server/sonar-server/src/test/projects/fake-views-plugin/src/BasePlugin.java
new file mode 100644 (file)
index 0000000..1fc5b54
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+import org.sonar.api.SonarPlugin;
+
+import java.util.Collections;
+import java.util.List;
+
+public class BasePlugin extends SonarPlugin {
+
+  public List getExtensions() {
+    return Collections.emptyList();
+  }
+}
diff --git a/server/sonar-server/src/test/projects/fake-views-plugin/src/org/sonar/plugins/testbase/api/BaseApi.java b/server/sonar-server/src/test/projects/fake-views-plugin/src/org/sonar/plugins/testbase/api/BaseApi.java
new file mode 100644 (file)
index 0000000..356a9c8
--- /dev/null
@@ -0,0 +1,6 @@
+package org.sonar.plugins.testbase.api;
+
+public class BaseApi {
+  public void doNothing() {
+  }
+}
diff --git a/server/sonar-server/src/test/projects/fake-views-plugin/target/fake-views-plugin-0.1-SNAPSHOT.jar b/server/sonar-server/src/test/projects/fake-views-plugin/target/fake-views-plugin-0.1-SNAPSHOT.jar
new file mode 100644 (file)
index 0000000..a47d93d
Binary files /dev/null and b/server/sonar-server/src/test/projects/fake-views-plugin/target/fake-views-plugin-0.1-SNAPSHOT.jar differ
index 2ae2bb8b9ecff7dc4eb5c05e9534ea9cd862e630..37338313ac0ffe805475288929fd98bf201789a4 100644 (file)
@@ -14,6 +14,9 @@
     <module>test-libs-plugin</module>
     <module>test-require-plugin</module>
     <module>test-requirenew-plugin</module>
+    <module>fake-report-plugin</module>
+    <module>fake-sqale-plugin</module>
+    <module>fake-views-plugin</module>
   </modules>
 
 </project>
index 32ac594aad1241af223daa968c1db05290d2e897..1d4ef5430c7d772d2c34e18e8a57190c2d68a2b3 100644 (file)
Binary files a/server/sonar-server/src/test/projects/test-base-plugin-v2/target/test-base-plugin-0.2-SNAPSHOT.jar and b/server/sonar-server/src/test/projects/test-base-plugin-v2/target/test-base-plugin-0.2-SNAPSHOT.jar differ
index f943a16b28f4088d0771e3384f22de4aa7c9cbc5..739a22fcdaecab7da14f7eb0bfd4e5badb94e1fa 100644 (file)
Binary files a/server/sonar-server/src/test/projects/test-base-plugin/target/test-base-plugin-0.1-SNAPSHOT.jar and b/server/sonar-server/src/test/projects/test-base-plugin/target/test-base-plugin-0.1-SNAPSHOT.jar differ
index 278b459622726916c011acf9243734b3b861c2ca..831cc364b5cd7f44c195751bd6e940981e047b09 100644 (file)
Binary files a/server/sonar-server/src/test/projects/test-core-plugin/target/test-core-plugin-0.1-SNAPSHOT.jar and b/server/sonar-server/src/test/projects/test-core-plugin/target/test-core-plugin-0.1-SNAPSHOT.jar differ
index 71dcee704960487f94ff491bd944451e6c7aebb8..2f63c2e652c20c80294aadedd5aaee197f727247 100644 (file)
Binary files a/server/sonar-server/src/test/projects/test-extend-plugin/target/test-extend-plugin-0.1-SNAPSHOT.jar and b/server/sonar-server/src/test/projects/test-extend-plugin/target/test-extend-plugin-0.1-SNAPSHOT.jar differ
index 590d91b74f200e45ecb2a2389f2b2cf899aa8410..6ebe8652d8b71f423235cfc60a9ed6c4161a5462 100644 (file)
Binary files a/server/sonar-server/src/test/projects/test-libs-plugin/target/test-libs-plugin-0.1-SNAPSHOT.jar and b/server/sonar-server/src/test/projects/test-libs-plugin/target/test-libs-plugin-0.1-SNAPSHOT.jar differ
index abf9bbed5eb994e6ec5d6195e8d3cd465f764570..f5fc95f9d0d6248995aa40b5451f9b0507452f9b 100644 (file)
Binary files a/server/sonar-server/src/test/projects/test-require-plugin/target/test-require-plugin-0.1-SNAPSHOT.jar and b/server/sonar-server/src/test/projects/test-require-plugin/target/test-require-plugin-0.1-SNAPSHOT.jar differ
index 671f69f10f84a83d0c0f63e0b7e9c550d8bffb2c..0dd577fc3607a4fee5916c09204835691a929bbd 100644 (file)
Binary files a/server/sonar-server/src/test/projects/test-requirenew-plugin/target/test-requirenew-plugin-0.1-SNAPSHOT.jar and b/server/sonar-server/src/test/projects/test-requirenew-plugin/target/test-requirenew-plugin-0.1-SNAPSHOT.jar differ