diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2013-01-28 15:10:44 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2013-01-28 15:11:10 +0100 |
commit | d676c2eaed04480c5516e692f2ac3c8ce7908686 (patch) | |
tree | 08462ed9038475d1dc1f915c347a2358cfe5ee74 /sonar-core | |
parent | ee10ce224ea3f6eaf389ad0c4572270de80b1cd9 (diff) | |
download | sonarqube-d676c2eaed04480c5516e692f2ac3c8ce7908686.tar.gz sonarqube-d676c2eaed04480c5516e692f2ac3c8ce7908686.zip |
SONAR-2501 fix loading of perspectives on server-side
Diffstat (limited to 'sonar-core')
6 files changed, 35 insertions, 23 deletions
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 9155e05bdc1..4c110c1be96 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 @@ -35,6 +35,8 @@ public abstract class PerspectiveBuilder<T extends Perspective> implements Batch return perspectiveClass; } - public abstract T build(ComponentWrapper<?> componentWrapper); + public abstract T load(ComponentWrapper<?> componentWrapper); + + public abstract T create(ComponentWrapper<?> componentWrapper); } diff --git a/sonar-core/src/main/java/org/sonar/core/component/PerspectiveBuilders.java b/sonar-core/src/main/java/org/sonar/core/component/PerspectiveBuilders.java index ea7fa5c8370..aff9e1852d9 100644 --- a/sonar-core/src/main/java/org/sonar/core/component/PerspectiveBuilders.java +++ b/sonar-core/src/main/java/org/sonar/core/component/PerspectiveBuilders.java @@ -62,7 +62,11 @@ public class PerspectiveBuilders implements ResourcePerspectives, BatchComponent P perspective = (P) perspectives.get(toClass); if (perspective == null) { ComponentWrapper componentWrapper = graph.wrap(component, ComponentWrapper.class); - perspective = builderFor(toClass).build(componentWrapper); + PerspectiveBuilder<P> perspectiveBuilder = builderFor(toClass); + perspective = perspectiveBuilder.load(componentWrapper); + if (perspective == null) { + perspective = perspectiveBuilder.create(componentWrapper); + } perspectives.put((Class) toClass, perspective); } return perspective; diff --git a/sonar-core/src/main/java/org/sonar/core/component/PerspectiveLoaders.java b/sonar-core/src/main/java/org/sonar/core/component/PerspectiveLoaders.java index bf8025f6456..203b25f9aee 100644 --- a/sonar-core/src/main/java/org/sonar/core/component/PerspectiveLoaders.java +++ b/sonar-core/src/main/java/org/sonar/core/component/PerspectiveLoaders.java @@ -37,13 +37,13 @@ public class PerspectiveLoaders implements ServerComponent { } @CheckForNull - Perspective as(String componentKey, String perspectiveKey) { + public Perspective as(String componentKey, String perspectiveKey) { GraphDto graphDto = dao.selectByComponent(perspectiveKey, componentKey); return doAs(perspectiveKey, graphDto); } @CheckForNull - Perspective as(long snapshotId, String perspectiveKey) { + public Perspective as(long snapshotId, String perspectiveKey) { GraphDto graphDto = dao.selectBySnapshot(perspectiveKey, snapshotId); return doAs(perspectiveKey, graphDto); } 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 f91428dc59d..9318c2d4cb4 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 @@ -22,11 +22,9 @@ package org.sonar.core.test; import com.tinkerpop.blueprints.Direction; import com.tinkerpop.blueprints.Vertex; import org.sonar.api.test.MutableTestPlan; -import org.sonar.api.test.TestPlan; -import org.sonar.core.component.PerspectiveBuilder; import org.sonar.core.component.ComponentWrapper; - -import java.util.Iterator; +import org.sonar.core.component.PerspectiveBuilder; +import org.sonar.core.graph.GraphUtil; public class TestPlanBuilder extends PerspectiveBuilder<MutableTestPlan> { @@ -35,11 +33,16 @@ public class TestPlanBuilder extends PerspectiveBuilder<MutableTestPlan> { } @Override - public MutableTestPlan build(ComponentWrapper<?> componentWrapper) { - Iterator<Vertex> plan = componentWrapper.element().getVertices(Direction.OUT, "testplan").iterator(); - if (plan.hasNext()) { - return componentWrapper.graph().wrap(plan.next(), DefaultTestPlan.class); + public MutableTestPlan load(ComponentWrapper<?> componentWrapper) { + Vertex planVertex = GraphUtil.singleAdjacent(componentWrapper.element(), Direction.OUT, "testplan"); + if (planVertex != null) { + return componentWrapper.graph().wrap(planVertex, DefaultTestPlan.class); } + return null; + } + + @Override + public MutableTestPlan create(ComponentWrapper<?> componentWrapper) { return componentWrapper.graph().createVertex(componentWrapper, DefaultTestPlan.class, "testplan"); } } 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 ab629e29d73..bf4785d543d 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 @@ -22,11 +22,9 @@ package org.sonar.core.test; import com.tinkerpop.blueprints.Direction; import com.tinkerpop.blueprints.Vertex; import org.sonar.api.test.MutableTestable; -import org.sonar.api.test.Testable; -import org.sonar.core.component.PerspectiveBuilder; import org.sonar.core.component.ComponentWrapper; - -import java.util.Iterator; +import org.sonar.core.component.PerspectiveBuilder; +import org.sonar.core.graph.GraphUtil; public class TestableBuilder extends PerspectiveBuilder<MutableTestable> { @@ -35,11 +33,16 @@ public class TestableBuilder extends PerspectiveBuilder<MutableTestable> { } @Override - public MutableTestable build(ComponentWrapper<?> componentWrapper) { - Iterator<Vertex> testables = componentWrapper.element().getVertices(Direction.OUT, "testable").iterator(); - if (testables.hasNext()) { - return componentWrapper.graph().wrap(testables.next(), DefaultTestable.class); + public MutableTestable load(ComponentWrapper<?> componentWrapper) { + Vertex perspectiveVertex = GraphUtil.singleAdjacent(componentWrapper.element(), Direction.OUT, "testable"); + if (perspectiveVertex != null) { + return componentWrapper.graph().wrap(perspectiveVertex, DefaultTestable.class); } + return null; + } + + @Override + public MutableTestable create(ComponentWrapper<?> componentWrapper) { return componentWrapper.graph().createVertex(componentWrapper, DefaultTestable.class, "testable"); } } 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 1457695a3f6..d9dbcd3af17 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 @@ -39,7 +39,7 @@ public class TestPlanBuilderTest { SourceFile file = MockSourceFile.createMain("org/codehaus/sonar/Main.java"); ComponentWrapper fileWrapper = graph.createComponent(file); - MutableTestPlan plan = new TestPlanBuilder().build(fileWrapper); + MutableTestPlan plan = new TestPlanBuilder().create(fileWrapper); assertThat(plan).isNotNull(); assertThat(plan.component().getKey()).isEqualTo(file.getKey()); assertThat(plan.component().getQualifier()).isEqualTo(file.getQualifier()); @@ -53,7 +53,7 @@ public class TestPlanBuilderTest { SourceFile file = MockSourceFile.createMain("org/codehaus/sonar/Main.java"); ComponentWrapper fileWrapper = graph.createComponent(file); - MutableTestPlan plan = new TestPlanBuilder().build(fileWrapper); + MutableTestPlan plan = new TestPlanBuilder().create(fileWrapper); MutableTestCase testCase = plan.addTestCase("should_pass"); assertThat(testCase.key()).isEqualTo("should_pass"); assertThat(testCase.name()).isNull(); @@ -69,7 +69,7 @@ public class TestPlanBuilderTest { Vertex componentVertex = graph.getVertex("33"); ComponentGraph componentGraph = new ComponentGraph(graph, componentVertex); - MutableTestPlan testPlan = new TestPlanBuilder().build(componentGraph.wrap(componentVertex, ComponentWrapper.class)); + MutableTestPlan testPlan = new TestPlanBuilder().load(componentGraph.wrap(componentVertex, ComponentWrapper.class)); assertThat(testPlan.testCases()).hasSize(4); } |