]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6968 Bad error message when analyzer detects that no language plugins are installed
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Thu, 19 Nov 2015 14:44:12 +0000 (15:44 +0100)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Fri, 20 Nov 2015 13:27:53 +0000 (14:27 +0100)
sonar-batch/src/main/java/org/sonar/batch/repository/language/DefaultLanguagesRepository.java
sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/NoLanguagesPluginsMediumTest.java [new file with mode: 0644]

index dd3b43b422fb613d36deeb2c3f7c72deb7bba704..e1f0c915cfb1f7b39990127352b2d460fb6b3a4e 100644 (file)
@@ -38,6 +38,12 @@ public class DefaultLanguagesRepository implements LanguagesRepository {
     this.languages = languages;
   }
 
+  public void start() {
+    if (languages.all().length == 0) {
+      throw new IllegalStateException("No language plugins are installed.");
+    }
+  }
+
   /**
    * Get language.
    */
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/NoLanguagesPluginsMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/NoLanguagesPluginsMediumTest.java
new file mode 100644 (file)
index 0000000..5383725
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * 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.mediumtest.fs;
+
+import org.junit.rules.ExpectedException;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.filefilter.FileFilterUtils;
+import org.sonar.batch.mediumtest.issuesmode.IssueModeAndReportsMediumTest;
+
+import java.io.File;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.Rule;
+import org.junit.rules.TemporaryFolder;
+import org.sonar.batch.mediumtest.BatchMediumTester;
+
+public class NoLanguagesPluginsMediumTest {
+  @Rule
+  public TemporaryFolder temp = new TemporaryFolder();
+
+  @Rule
+  public ExpectedException exception = ExpectedException.none();
+
+  public BatchMediumTester tester = BatchMediumTester.builder()
+    .setPreviousAnalysisDate(null)
+    .build();
+
+  @Before
+  public void prepare() {
+    tester.start();
+  }
+
+  @After
+  public void stop() {
+    tester.stop();
+  }
+
+  @Test
+  public void testNoLanguagePluginsInstalled() throws Exception {
+    File projectDir = copyProject("/mediumtest/xoo/sample");
+
+    exception.expect(IllegalStateException.class);
+    exception.expectMessage("No language plugins are installed");
+
+    tester
+      .newScanTask(new File(projectDir, "sonar-project.properties"))
+      .start();
+  }
+
+  private File copyProject(String path) throws Exception {
+    File projectDir = temp.newFolder();
+    File originalProjectDir = new File(IssueModeAndReportsMediumTest.class.getResource(path).toURI());
+    FileUtils.copyDirectory(originalProjectDir, projectDir, FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter(".sonar")));
+    return projectDir;
+  }
+}