aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-squid
diff options
context:
space:
mode:
authorFreddy Mallet <freddy.mallet@gmail.com>2011-10-24 17:25:08 +0200
committerFreddy Mallet <freddy.mallet@gmail.com>2011-10-24 17:25:08 +0200
commit7b85ebdefdd22560fcfeb22e5c60116690149314 (patch)
tree03fd47312299a8ffce18d42179d5872afe8fac81 /sonar-squid
parent31e06917a220453a328a6edfaea6fa686dbcb1de (diff)
downloadsonarqube-7b85ebdefdd22560fcfeb22e5c60116690149314.tar.gz
sonarqube-7b85ebdefdd22560fcfeb22e5c60116690149314.zip
SONAR-2741 The method JavaAstScanner.scanDirectory(..) can't be called several times
Diffstat (limited to 'sonar-squid')
-rw-r--r--sonar-squid/src/main/java/org/sonar/squid/Squid.java23
-rw-r--r--sonar-squid/src/test/java/org/sonar/squid/MyCodeScanner.java35
-rw-r--r--sonar-squid/src/test/java/org/sonar/squid/SquidTest.java33
3 files changed, 85 insertions, 6 deletions
diff --git a/sonar-squid/src/main/java/org/sonar/squid/Squid.java b/sonar-squid/src/main/java/org/sonar/squid/Squid.java
index b2153e25ef0..760a457d770 100644
--- a/sonar-squid/src/main/java/org/sonar/squid/Squid.java
+++ b/sonar-squid/src/main/java/org/sonar/squid/Squid.java
@@ -20,20 +20,28 @@
package org.sonar.squid;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
import org.picocontainer.MutablePicoContainer;
import org.picocontainer.containers.TransientPicoContainer;
import org.sonar.graph.DirectedGraph;
import org.sonar.graph.DirectedGraphAccessor;
-import org.sonar.squid.api.*;
+import org.sonar.squid.api.CodeScanner;
+import org.sonar.squid.api.CodeVisitor;
+import org.sonar.squid.api.Query;
+import org.sonar.squid.api.SourceCode;
+import org.sonar.squid.api.SourceCodeEdge;
+import org.sonar.squid.api.SourceCodeSearchEngine;
+import org.sonar.squid.api.SourceCodeTreeDecorator;
+import org.sonar.squid.api.SourceProject;
+import org.sonar.squid.api.SquidConfiguration;
import org.sonar.squid.indexer.SquidIndex;
import org.sonar.squid.measures.Metric;
import org.sonar.squid.measures.MetricDef;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
public class Squid implements DirectedGraphAccessor<SourceCode, SourceCodeEdge>, SourceCodeSearchEngine {
private MutablePicoContainer pico;
@@ -67,6 +75,9 @@ public class Squid implements DirectedGraphAccessor<SourceCode, SourceCodeEdge>,
}
public <SCANNER extends CodeScanner> SCANNER register(Class<SCANNER> scannerClass) {
+ if(pico.getComponent(scannerClass) != null){
+ throw new IllegalStateException("The Squid SCANNER '" + scannerClass.getName() + "' can't be registered multiple times.");
+ }
addToPicocontainer(scannerClass);
SCANNER scanner = pico.getComponent(scannerClass);
for (Object clazz : scanner.getVisitorClasses()) {
diff --git a/sonar-squid/src/test/java/org/sonar/squid/MyCodeScanner.java b/sonar-squid/src/test/java/org/sonar/squid/MyCodeScanner.java
new file mode 100644
index 00000000000..409bef945c4
--- /dev/null
+++ b/sonar-squid/src/test/java/org/sonar/squid/MyCodeScanner.java
@@ -0,0 +1,35 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+
+package org.sonar.squid;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.sonar.squid.api.CodeScanner;
+import org.sonar.squid.api.CodeVisitor;
+
+public class MyCodeScanner extends CodeScanner<CodeVisitor> {
+
+ @Override
+ public Collection<Class<? extends CodeVisitor>> getVisitorClasses() {
+ return new ArrayList<Class<? extends CodeVisitor>>();
+ }
+}
diff --git a/sonar-squid/src/test/java/org/sonar/squid/SquidTest.java b/sonar-squid/src/test/java/org/sonar/squid/SquidTest.java
new file mode 100644
index 00000000000..576b7fed6a2
--- /dev/null
+++ b/sonar-squid/src/test/java/org/sonar/squid/SquidTest.java
@@ -0,0 +1,33 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+
+package org.sonar.squid;
+
+import org.junit.Test;
+
+public class SquidTest {
+
+ @Test(expected = IllegalStateException.class)
+ public void shouldNotAcceptToRegisterTwiceTheSameScanner() {
+ Squid squid = new Squid();
+ squid.register(MyCodeScanner.class);
+ squid.register(MyCodeScanner.class);
+ }
+}