aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>2013-04-04 15:50:09 +0200
committerJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>2013-04-04 15:50:09 +0200
commita3521edd7c7cc726e5aa2161e8cc0f76ecd571dc (patch)
treecb5805817d86d89e1098e3d42059cf85f76a7601 /sonar-core
parent5a38f5a540005d0703a3ef870c95f46469027f1a (diff)
downloadsonarqube-a3521edd7c7cc726e5aa2161e8cc0f76ecd571dc.tar.gz
sonarqube-a3521edd7c7cc726e5aa2161e8cc0f76ecd571dc.zip
(SONAR-3893) Improve the highlighter API to not depend on sonar-channel and allow to work on multi-line tokens
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/component/GraphPerspectiveBuilder.java84
-rw-r--r--sonar-core/src/main/java/org/sonar/core/component/PerspectiveBuilder.java19
-rw-r--r--sonar-core/src/main/java/org/sonar/core/component/ScanGraphStore.java50
-rw-r--r--sonar-core/src/main/java/org/sonar/core/component/ScanPerspectives.java24
-rw-r--r--sonar-core/src/main/java/org/sonar/core/component/SnapshotPerspectives.java6
-rw-r--r--sonar-core/src/main/java/org/sonar/core/source/DefaultHighlightable.java49
-rw-r--r--sonar-core/src/main/java/org/sonar/core/source/HighlightableBuilder.java36
-rw-r--r--sonar-core/src/main/java/org/sonar/core/test/TestPlanBuilder.java31
-rw-r--r--sonar-core/src/main/java/org/sonar/core/test/TestableBuilder.java31
-rw-r--r--sonar-core/src/test/java/org/sonar/core/source/DefaultHighlightableTest.java57
-rw-r--r--sonar-core/src/test/java/org/sonar/core/source/HighlightableBuilderTest.java41
-rw-r--r--sonar-core/src/test/java/org/sonar/core/test/TestPlanBuilderTest.java8
-rw-r--r--sonar-core/src/test/java/org/sonar/core/test/TestableBuilderTest.java7
13 files changed, 333 insertions, 110 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/component/GraphPerspectiveBuilder.java b/sonar-core/src/main/java/org/sonar/core/component/GraphPerspectiveBuilder.java
new file mode 100644
index 00000000000..30f9fe07197
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/component/GraphPerspectiveBuilder.java
@@ -0,0 +1,84 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 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.core.component;
+
+import com.tinkerpop.blueprints.Direction;
+import com.tinkerpop.blueprints.Vertex;
+import org.sonar.api.component.Component;
+import org.sonar.api.component.Perspective;
+import org.sonar.core.graph.BeanVertex;
+import org.sonar.core.graph.EdgePath;
+import org.sonar.core.graph.GraphUtil;
+
+public abstract class GraphPerspectiveBuilder<T extends Perspective> extends PerspectiveBuilder<T> {
+
+ protected final ScanGraph graph;
+ protected final EdgePath path;
+ protected final String perspectiveKey;
+
+ protected GraphPerspectiveBuilder(ScanGraph graph, String perspectiveKey, Class<T> perspectiveClass, EdgePath path) {
+ super(perspectiveClass);
+ this.graph = graph;
+ this.path = path;
+ this.perspectiveKey = perspectiveKey;
+ }
+
+ public T load(ComponentVertex component) {
+ Vertex perspectiveVertex = GraphUtil.singleAdjacent(component.element(), Direction.OUT, getPerspectiveKey());
+ if (perspectiveVertex != null) {
+ return (T) component.beanGraph().wrap(perspectiveVertex, getBeanClass());
+ }
+ return null;
+ }
+
+ public T create(ComponentVertex component) {
+ return (T) component.beanGraph().createAdjacentVertex(component, getBeanClass(), getPerspectiveKey());
+ }
+
+ public EdgePath path() {
+ return path;
+ }
+
+ @Override
+ protected T loadPerspective(Class<T> perspectiveClass, Component component) {
+ ComponentVertex vertex;
+ if (component instanceof ComponentVertex) {
+ vertex = (ComponentVertex) component;
+ } else {
+ vertex = graph.getComponent(component.key());
+ }
+
+ if (vertex != null) {
+ T perspective = load(vertex);
+ if (perspective == null) {
+ perspective = create(vertex);
+ }
+ return perspective;
+ }
+ return null;
+ }
+
+
+ protected String getPerspectiveKey() {
+ return perspectiveKey;
+ }
+
+ protected abstract Class<? extends BeanVertex> getBeanClass();
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/component/PerspectiveBuilder.java b/sonar-core/src/main/java/org/sonar/core/component/PerspectiveBuilder.java
index 0a66905e077..a605ed40170 100644
--- a/sonar-core/src/main/java/org/sonar/core/component/PerspectiveBuilder.java
+++ b/sonar-core/src/main/java/org/sonar/core/component/PerspectiveBuilder.java
@@ -21,34 +21,21 @@ package org.sonar.core.component;
import org.sonar.api.BatchComponent;
import org.sonar.api.ServerComponent;
+import org.sonar.api.component.Component;
import org.sonar.api.component.Perspective;
-import org.sonar.core.graph.EdgePath;
-
-import javax.annotation.CheckForNull;
public abstract class PerspectiveBuilder<T extends Perspective> implements BatchComponent, ServerComponent {
- private final String perspectiveKey;
private final Class<T> perspectiveClass;
- protected PerspectiveBuilder(String perspectiveKey, Class<T> perspectiveClass) {
- this.perspectiveKey = perspectiveKey;
+ protected PerspectiveBuilder(Class<T> perspectiveClass) {
this.perspectiveClass = perspectiveClass;
}
- protected String getPerspectiveKey() {
- return perspectiveKey;
- }
-
protected Class<T> getPerspectiveClass() {
return perspectiveClass;
}
- @CheckForNull
- public abstract T load(ComponentVertex component);
-
- public abstract T create(ComponentVertex component);
-
- public abstract EdgePath path();
+ protected abstract T loadPerspective(Class<T> perspectiveClass, Component component);
}
diff --git a/sonar-core/src/main/java/org/sonar/core/component/ScanGraphStore.java b/sonar-core/src/main/java/org/sonar/core/component/ScanGraphStore.java
index 44590d76ef6..f527cf00e22 100644
--- a/sonar-core/src/main/java/org/sonar/core/component/ScanGraphStore.java
+++ b/sonar-core/src/main/java/org/sonar/core/component/ScanGraphStore.java
@@ -50,25 +50,7 @@ public class ScanGraphStore {
GraphDtoMapper mapper = session.getMapper(GraphDtoMapper.class);
try {
for (ComponentVertex component : projectGraph.getComponents()) {
- Long snapshotId = (Long) component.element().getProperty("sid");
- if (snapshotId != null) {
- for (PerspectiveBuilder builder : builders) {
- Perspective perspective = builder.load(component);
- if (perspective != null) {
- Graph subGraph = SubGraph.extract(component.element(), builder.path());
- String data = write(subGraph);
- mapper.insert(new GraphDto()
- .setData(data)
- .setFormat("graphson")
- .setPerspective(builder.getPerspectiveKey())
- .setVersion(1)
- .setResourceId((Long) component.element().getProperty("rid"))
- .setSnapshotId(snapshotId)
- .setRootVertexId(component.element().getId().toString())
- );
- }
- }
- }
+ persistComponentGraph(mapper, component);
}
session.commit();
} finally {
@@ -76,6 +58,36 @@ public class ScanGraphStore {
}
}
+ private void persistComponentGraph(GraphDtoMapper mapper, ComponentVertex component) {
+ Long snapshotId = (Long) component.element().getProperty("sid");
+ if (snapshotId != null) {
+ for (PerspectiveBuilder builder : builders) {
+ if(builder instanceof GraphPerspectiveBuilder) {
+ GraphPerspectiveBuilder graphPerspectiveBuilder = (GraphPerspectiveBuilder)builder;
+ Perspective perspective = graphPerspectiveBuilder.load(component);
+ if (perspective != null) {
+ serializePerspectiveData(mapper, component, snapshotId, graphPerspectiveBuilder);
+ }
+ }
+ }
+ }
+ }
+
+ private void serializePerspectiveData(GraphDtoMapper mapper, ComponentVertex component, Long snapshotId,
+ GraphPerspectiveBuilder builder) {
+ Graph subGraph = SubGraph.extract(component.element(), builder.path());
+ String data = write(subGraph);
+ mapper.insert(new GraphDto()
+ .setData(data)
+ .setFormat("graphson")
+ .setPerspective(builder.getPerspectiveKey())
+ .setVersion(1)
+ .setResourceId((Long) component.element().getProperty("rid"))
+ .setSnapshotId(snapshotId)
+ .setRootVertexId(component.element().getId().toString())
+ );
+ }
+
private String write(Graph graph) {
StringWriter output = new StringWriter();
try {
diff --git a/sonar-core/src/main/java/org/sonar/core/component/ScanPerspectives.java b/sonar-core/src/main/java/org/sonar/core/component/ScanPerspectives.java
index c9dc3368c52..6cd29abf004 100644
--- a/sonar-core/src/main/java/org/sonar/core/component/ScanPerspectives.java
+++ b/sonar-core/src/main/java/org/sonar/core/component/ScanPerspectives.java
@@ -32,12 +32,11 @@ import javax.annotation.CheckForNull;
import java.util.Map;
public class ScanPerspectives implements ResourcePerspectives, BatchComponent {
- private final ScanGraph graph;
+
private final Map<Class<?>, PerspectiveBuilder<?>> builders = Maps.newHashMap();
private final SonarIndex resourceIndex;
- public ScanPerspectives(ScanGraph graph, PerspectiveBuilder[] builders, SonarIndex resourceIndex) {
- this.graph = graph;
+ public ScanPerspectives(PerspectiveBuilder[] builders, SonarIndex resourceIndex) {
this.resourceIndex = resourceIndex;
for (PerspectiveBuilder builder : builders) {
// TODO check duplications
@@ -50,23 +49,8 @@ public class ScanPerspectives implements ResourcePerspectives, BatchComponent {
if (component.key() == null) {
return null;
}
-
- ComponentVertex vertex;
- if (component instanceof ComponentVertex) {
- vertex = (ComponentVertex) component;
- } else {
- vertex = graph.getComponent(component.key());
- }
-
- if (vertex != null) {
- PerspectiveBuilder<P> builder = builderFor(perspectiveClass);
- P perspective = builder.load(vertex);
- if (perspective == null) {
- perspective = builder.create(vertex);
- }
- return perspective;
- }
- return null;
+ PerspectiveBuilder<P> builder = builderFor(perspectiveClass);
+ return builder.loadPerspective(perspectiveClass, component);
}
public <P extends Perspective> P as(Class<P> perspectiveClass, Resource resource) {
diff --git a/sonar-core/src/main/java/org/sonar/core/component/SnapshotPerspectives.java b/sonar-core/src/main/java/org/sonar/core/component/SnapshotPerspectives.java
index fb615caaaf8..d64ee818d93 100644
--- a/sonar-core/src/main/java/org/sonar/core/component/SnapshotPerspectives.java
+++ b/sonar-core/src/main/java/org/sonar/core/component/SnapshotPerspectives.java
@@ -47,7 +47,7 @@ public class SnapshotPerspectives implements ServerComponent {
@CheckForNull
public <T extends Perspective> T as(Class<T> perspectiveClass, String componentKey) {
- PerspectiveBuilder<T> builder = (PerspectiveBuilder<T>) builders.get(perspectiveClass);
+ GraphPerspectiveBuilder<T> builder = (GraphPerspectiveBuilder<T>) builders.get(perspectiveClass);
if (builder == null) {
throw new IllegalStateException();
}
@@ -57,7 +57,7 @@ public class SnapshotPerspectives implements ServerComponent {
@CheckForNull
public <T extends Perspective> T as(Class<T> perspectiveClass, long snapshotId) {
- PerspectiveBuilder<T> builder = (PerspectiveBuilder<T>) builders.get(perspectiveClass);
+ GraphPerspectiveBuilder<T> builder = (GraphPerspectiveBuilder<T>) builders.get(perspectiveClass);
if (builder == null) {
throw new IllegalStateException();
}
@@ -69,7 +69,7 @@ public class SnapshotPerspectives implements ServerComponent {
T result = null;
if (graphDto != null) {
SnapshotGraph graph = read(graphDto.getData(), graphDto.getRootVertexId());
- result = builder.load(graph.wrap(graph.getComponentRoot(), ComponentVertex.class));
+ result = ((GraphPerspectiveBuilder<T>)builder).load(graph.wrap(graph.getComponentRoot(), ComponentVertex.class));
}
return result;
}
diff --git a/sonar-core/src/main/java/org/sonar/core/source/DefaultHighlightable.java b/sonar-core/src/main/java/org/sonar/core/source/DefaultHighlightable.java
new file mode 100644
index 00000000000..006fa22be3a
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/source/DefaultHighlightable.java
@@ -0,0 +1,49 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 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.core.source;
+
+import org.sonar.api.component.Component;
+import org.sonar.api.scan.source.Highlightable;
+import org.sonar.api.scan.source.SyntaxHighlightingRuleSet;
+
+public class DefaultHighlightable implements Highlightable {
+
+ private final Component component;
+ private final SyntaxHighlightingRuleSet.Builder highlightingRulesBuilder;
+
+ public DefaultHighlightable(Component component) {
+ highlightingRulesBuilder = new SyntaxHighlightingRuleSet.Builder();
+ this.component = component;
+ }
+
+ @Override
+ public SyntaxHighlightingRuleSet.Builder highlightText(int startOffset, int endOffset, String typeOfText) {
+ return highlightingRulesBuilder.registerHighlightingRule(startOffset, endOffset, typeOfText);
+ }
+
+ @Override
+ public Component component() {
+ throw new UnsupportedOperationException("Unexpected call to component API");
+ }
+
+ public SyntaxHighlightingRuleSet getHighlightingRules() {
+ return highlightingRulesBuilder.build();
+ }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/source/HighlightableBuilder.java b/sonar-core/src/main/java/org/sonar/core/source/HighlightableBuilder.java
new file mode 100644
index 00000000000..ba823be360e
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/source/HighlightableBuilder.java
@@ -0,0 +1,36 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 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.core.source;
+
+import org.sonar.api.component.Component;
+import org.sonar.api.scan.source.Highlightable;
+import org.sonar.core.component.PerspectiveBuilder;
+
+public class HighlightableBuilder extends PerspectiveBuilder<Highlightable> {
+
+ public HighlightableBuilder() {
+ super(Highlightable.class);
+ }
+
+ @Override
+ protected Highlightable loadPerspective(Class<Highlightable> perspectiveClass, Component component) {
+ return new DefaultHighlightable(component);
+ }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/test/TestPlanBuilder.java b/sonar-core/src/main/java/org/sonar/core/test/TestPlanBuilder.java
index 3084d6e3891..8d4df5eb4a1 100644
--- a/sonar-core/src/main/java/org/sonar/core/test/TestPlanBuilder.java
+++ b/sonar-core/src/main/java/org/sonar/core/test/TestPlanBuilder.java
@@ -20,14 +20,13 @@
package org.sonar.core.test;
import com.tinkerpop.blueprints.Direction;
-import com.tinkerpop.blueprints.Vertex;
import org.sonar.api.test.MutableTestPlan;
-import org.sonar.core.component.ComponentVertex;
-import org.sonar.core.component.PerspectiveBuilder;
+import org.sonar.core.component.GraphPerspectiveBuilder;
+import org.sonar.core.component.ScanGraph;
+import org.sonar.core.graph.BeanVertex;
import org.sonar.core.graph.EdgePath;
-import org.sonar.core.graph.GraphUtil;
-public class TestPlanBuilder extends PerspectiveBuilder<MutableTestPlan> {
+public class TestPlanBuilder extends GraphPerspectiveBuilder<MutableTestPlan> {
static final String PERSPECTIVE_KEY = "testplan";
@@ -38,26 +37,12 @@ public class TestPlanBuilder extends PerspectiveBuilder<MutableTestPlan> {
Direction.IN, "testable"
);
- public TestPlanBuilder() {
- super(PERSPECTIVE_KEY, MutableTestPlan.class);
+ public TestPlanBuilder(ScanGraph graph) {
+ super(graph, PERSPECTIVE_KEY, MutableTestPlan.class, PATH);
}
@Override
- public MutableTestPlan load(ComponentVertex component) {
- Vertex planVertex = GraphUtil.singleAdjacent(component.element(), Direction.OUT, PERSPECTIVE_KEY);
- if (planVertex != null) {
- return component.beanGraph().wrap(planVertex, DefaultTestPlan.class);
- }
- return null;
- }
-
- @Override
- public MutableTestPlan create(ComponentVertex component) {
- return component.beanGraph().createAdjacentVertex(component, DefaultTestPlan.class, PERSPECTIVE_KEY);
- }
-
- @Override
- public EdgePath path() {
- return PATH;
+ protected Class<? extends BeanVertex> getBeanClass() {
+ return DefaultTestPlan.class;
}
}
diff --git a/sonar-core/src/main/java/org/sonar/core/test/TestableBuilder.java b/sonar-core/src/main/java/org/sonar/core/test/TestableBuilder.java
index a7a86813213..5b1b5aec4c4 100644
--- a/sonar-core/src/main/java/org/sonar/core/test/TestableBuilder.java
+++ b/sonar-core/src/main/java/org/sonar/core/test/TestableBuilder.java
@@ -20,14 +20,13 @@
package org.sonar.core.test;
import com.tinkerpop.blueprints.Direction;
-import com.tinkerpop.blueprints.Vertex;
import org.sonar.api.test.MutableTestable;
-import org.sonar.core.component.ComponentVertex;
+import org.sonar.core.component.GraphPerspectiveBuilder;
+import org.sonar.core.component.ScanGraph;
+import org.sonar.core.graph.BeanVertex;
import org.sonar.core.graph.EdgePath;
-import org.sonar.core.component.PerspectiveBuilder;
-import org.sonar.core.graph.GraphUtil;
-public class TestableBuilder extends PerspectiveBuilder<MutableTestable> {
+public class TestableBuilder extends GraphPerspectiveBuilder<MutableTestable> {
static final String PERSPECTIVE_KEY = "testable";
@@ -38,26 +37,12 @@ public class TestableBuilder extends PerspectiveBuilder<MutableTestable> {
Direction.IN,"testplan"
);
- public TestableBuilder() {
- super(PERSPECTIVE_KEY, MutableTestable.class);
+ public TestableBuilder(ScanGraph graph) {
+ super(graph, PERSPECTIVE_KEY, MutableTestable.class, PATH);
}
@Override
- public MutableTestable load(ComponentVertex component) {
- Vertex perspectiveVertex = GraphUtil.singleAdjacent(component.element(), Direction.OUT, PERSPECTIVE_KEY);
- if (perspectiveVertex != null) {
- return component.beanGraph().wrap(perspectiveVertex, DefaultTestable.class);
- }
- return null;
- }
-
- @Override
- public MutableTestable create(ComponentVertex component) {
- return component.beanGraph().createAdjacentVertex(component, DefaultTestable.class, PERSPECTIVE_KEY);
- }
-
- @Override
- public EdgePath path() {
- return PATH;
+ protected Class<? extends BeanVertex> getBeanClass() {
+ return DefaultTestable.class;
}
}
diff --git a/sonar-core/src/test/java/org/sonar/core/source/DefaultHighlightableTest.java b/sonar-core/src/test/java/org/sonar/core/source/DefaultHighlightableTest.java
new file mode 100644
index 00000000000..9990218d2ee
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/source/DefaultHighlightableTest.java
@@ -0,0 +1,57 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 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.core.source;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.component.Component;
+import org.sonar.api.scan.source.HighlightableTextType;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+public class DefaultHighlightableTest {
+
+ @Rule
+ public ExpectedException throwable = ExpectedException.none();
+
+ @Test
+ public void should_register_highlighting_rule() throws Exception {
+
+ Component mockComponent = mock(Component.class);
+
+ DefaultHighlightable highlightable = new DefaultHighlightable(mockComponent);
+ highlightable.highlightText(1, 10, HighlightableTextType.KEYWORD);
+
+ assertThat(highlightable.getHighlightingRules().getSyntaxHighlightingRuleSet()).hasSize(1);
+ }
+
+ @Test
+ public void should_reject_any_call_to_component() throws Exception {
+
+ Component mockComponent = mock(Component.class);
+
+ throwable.expect(UnsupportedOperationException.class);
+
+ DefaultHighlightable highlightable = new DefaultHighlightable(mockComponent);
+ highlightable.component();
+ }
+}
diff --git a/sonar-core/src/test/java/org/sonar/core/source/HighlightableBuilderTest.java b/sonar-core/src/test/java/org/sonar/core/source/HighlightableBuilderTest.java
new file mode 100644
index 00000000000..427feb7ce9e
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/source/HighlightableBuilderTest.java
@@ -0,0 +1,41 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 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.core.source;
+
+import org.junit.Test;
+import org.sonar.api.component.Component;
+import org.sonar.api.scan.source.Highlightable;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+public class HighlightableBuilderTest {
+
+ @Test
+ public void should_load_default_perspective() throws Exception {
+
+ Component mockComponent = mock(Component.class);
+
+ HighlightableBuilder builder = new HighlightableBuilder();
+ Highlightable perspective = builder.loadPerspective(Highlightable.class, mockComponent);
+
+ assertThat(perspective).isInstanceOf(DefaultHighlightable.class);
+ }
+}
diff --git a/sonar-core/src/test/java/org/sonar/core/test/TestPlanBuilderTest.java b/sonar-core/src/test/java/org/sonar/core/test/TestPlanBuilderTest.java
index fa493c879f0..4c03a6f457e 100644
--- a/sonar-core/src/test/java/org/sonar/core/test/TestPlanBuilderTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/test/TestPlanBuilderTest.java
@@ -30,15 +30,17 @@ import static org.fest.assertions.Assertions.assertThat;
public class TestPlanBuilderTest {
@Test
public void test_path() {
- TestPlanBuilder builder = new TestPlanBuilder();
+
+ ScanGraph graph = ScanGraph.create();
+ TestPlanBuilder builder = new TestPlanBuilder(graph);
assertThat(builder.path().getElements()).isNotEmpty();
}
@Test
public void should_not_load_missing_perspective() {
- TestPlanBuilder builder = new TestPlanBuilder();
ScanGraph graph = ScanGraph.create();
+ TestPlanBuilder builder = new TestPlanBuilder(graph);
ComponentVertex file = graph.addComponent(MockSourceFile.createMain("org.foo.Bar"));
assertThat(builder.load(file)).isNull();
@@ -46,8 +48,8 @@ public class TestPlanBuilderTest {
@Test
public void should_create_perspective() {
- TestPlanBuilder builder = new TestPlanBuilder();
ScanGraph graph = ScanGraph.create();
+ TestPlanBuilder builder = new TestPlanBuilder(graph);
ComponentVertex file = graph.addComponent(MockSourceFile.createMain("org.foo.Bar"));
MutableTestPlan plan = builder.create(file);
diff --git a/sonar-core/src/test/java/org/sonar/core/test/TestableBuilderTest.java b/sonar-core/src/test/java/org/sonar/core/test/TestableBuilderTest.java
index fa8eed08924..a21be60aad7 100644
--- a/sonar-core/src/test/java/org/sonar/core/test/TestableBuilderTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/test/TestableBuilderTest.java
@@ -30,15 +30,16 @@ import static org.fest.assertions.Assertions.assertThat;
public class TestableBuilderTest {
@Test
public void test_path() {
- TestableBuilder builder = new TestableBuilder();
+ ScanGraph graph = ScanGraph.create();
+ TestableBuilder builder = new TestableBuilder(graph);
assertThat(builder.path().getElements()).isNotEmpty();
}
@Test
public void should_not_load_missing_perspective() {
- TestableBuilder builder = new TestableBuilder();
ScanGraph graph = ScanGraph.create();
+ TestableBuilder builder = new TestableBuilder(graph);
ComponentVertex file = graph.addComponent(MockSourceFile.createMain("org.foo.Bar"));
assertThat(builder.load(file)).isNull();
@@ -46,8 +47,8 @@ public class TestableBuilderTest {
@Test
public void should_create_perspective() {
- TestableBuilder builder = new TestableBuilder();
ScanGraph graph = ScanGraph.create();
+ TestableBuilder builder = new TestableBuilder(graph);
ComponentVertex file = graph.addComponent(MockSourceFile.createMain("org.foo.Bar"));
MutableTestable testable = builder.create(file);