From 921963613e862a3749cda659f5a9f8d4813ca13c Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Wed, 20 May 2015 10:10:34 +0200 Subject: [PATCH] SONAR-6278 Stop relying on graph to store tests --- .../AbstractNewCoverageFileAnalyzer.java | 8 +- .../timemachine/NewCoverageFileAnalyzer.java | 6 +- .../NewItCoverageFileAnalyzer.java | 4 +- .../NewOverallCoverageFileAnalyzer.java | 4 +- .../TimeMachineConfigurationPersister.java | 6 +- .../NewCoverageFileAnalyzerTest.java | 4 +- ...TimeMachineConfigurationPersisterTest.java | 4 +- pom.xml | 5 - .../platformlevel/PlatformLevel4.java | 6 - .../batch/cpd/index/DbDuplicationsIndex.java | 6 +- .../sonar/batch/cpd/index/IndexFactory.java | 8 +- .../perspectives/BatchPerspectives.java | 32 +- .../perspectives}/PerspectiveBuilder.java | 11 +- .../PerspectiveNotFoundException.java | 2 +- ...BatchResource.java => BatchComponent.java} | 16 +- ...rceCache.java => BatchComponentCache.java} | 66 +- .../org/sonar/batch/index/DefaultIndex.java | 4 +- .../sonar/batch/index/ResourcePersister.java | 25 +- .../sonar/batch/issue/DefaultIssuable.java | 19 +- .../sonar/batch/issue/IssuableFactory.java | 17 +- .../issue/tracking/LocalIssueTracking.java | 16 +- .../issue/tracking/ServerIssueRepository.java | 12 +- .../sonar/batch/mediumtest/TaskResult.java | 4 +- .../batch/postjob/DefaultPostJobContext.java | 10 +- .../qualitygate/QualityGateVerifier.java | 6 +- .../batch/report/ComponentsPublisher.java | 18 +- .../sonar/batch/report/CoveragePublisher.java | 10 +- .../batch/report/DuplicationsPublisher.java | 12 +- .../org/sonar/batch/report/EventCache.java | 6 +- .../sonar/batch/report/IssuesPublisher.java | 12 +- .../sonar/batch/report/MeasuresPublisher.java | 10 +- .../sonar/batch/report/SourcePublisher.java | 10 +- .../TestExecutionAndCoveragePublisher.java | 35 +- .../batch/scan/ProjectScanContainer.java | 14 +- .../scan/filesystem/ComponentIndexer.java | 8 +- .../batch/scan/filesystem/InputPathCache.java | 4 +- .../sonar/batch/scan/report/IssuesReport.java | 14 +- .../scan/report/IssuesReportBuilder.java | 12 +- .../batch/scan/report/ResourceReport.java | 8 +- .../batch/scan/report/SourceProvider.java | 4 +- .../sonar/batch/scm/DefaultBlameOutput.java | 10 +- .../java/org/sonar/batch/scm/ScmSensor.java | 6 +- .../batch/sensor/DefaultSensorStorage.java | 10 +- .../batch/source/CodeColorizerSensor.java | 6 +- .../batch/source/DefaultHighlightable.java | 7 - .../batch/source/DefaultSymbolizable.java | 7 - .../batch/source/HighlightableBuilder.java | 33 +- .../batch/source/SymbolizableBuilder.java | 33 +- .../batch}/test/DefaultCoverageBlock.java | 24 +- .../sonar/batch}/test/DefaultTestCase.java | 107 +- .../sonar/batch}/test/DefaultTestPlan.java | 30 +- .../org/sonar/batch/test/DefaultTestable.java | 86 ++ .../org/sonar/batch/test/TestPlanBuilder.java | 54 + .../org/sonar/batch/test/TestableBuilder.java | 29 +- .../org/sonar/batch}/test/package-info.java | 2 +- .../batch/cpd/index/IndexFactoryTest.java | 4 +- .../perspectives}/PerspectiveBuilderTest.java | 6 +- ...Test.java => BatchComponentCacheTest.java} | 6 +- .../sonar/batch/index/DefaultIndexTest.java | 2 +- .../batch/index/ResourcePersisterTest.java | 17 +- .../batch/issue/DefaultIssuableTest.java | 9 +- .../batch/issue/IssuableFactoryTest.java | 9 +- .../postjob/DefaultPostJobContextTest.java | 6 +- .../qualitygate/QualityGateVerifierTest.java | 6 +- .../batch/report/ComponentsPublisherTest.java | 6 +- .../batch/report/CoveragePublisherTest.java | 4 +- .../report/DuplicationsPublisherTest.java | 4 +- .../batch/report/IssuesPublisherTest.java | 4 +- .../batch/report/MeasuresPublisherTest.java | 4 +- .../batch/report/ReportPublisherTest.java | 4 +- .../batch/report/SourcePublisherTest.java | 4 +- .../scan/filesystem/ComponentIndexerTest.java | 8 +- .../sensor/DefaultSensorStorageTest.java | 6 +- .../source/HighlightableBuilderTest.java | 18 +- .../batch/source/SymbolizableBuilderTest.java | 19 +- sonar-core/pom.xml | 22 - .../sonar/core/component/ComponentQuery.java | 63 - .../sonar/core/component/ComponentVertex.java | 64 - .../component/GraphPerspectiveBuilder.java | 82 -- .../component/GraphPerspectiveLoader.java | 55 - .../core/component/ResourceComponent.java | 79 -- .../org/sonar/core/component/ScanGraph.java | 82 -- .../sonar/core/component/SnapshotGraph.java | 37 - .../java/org/sonar/core/graph/BeanEdge.java | 31 - .../org/sonar/core/graph/BeanElement.java | 68 - .../org/sonar/core/graph/BeanElements.java | 88 -- .../java/org/sonar/core/graph/BeanGraph.java | 63 - .../org/sonar/core/graph/BeanIterable.java | 59 - .../java/org/sonar/core/graph/BeanVertex.java | 34 - .../java/org/sonar/core/graph/EdgePath.java | 55 - .../java/org/sonar/core/graph/GraphUtil.java | 65 - .../core/graph/MultipleElementsException.java | 26 - .../core/graph/graphson/ElementFactory.java | 47 - .../graph/graphson/ElementPropertyConfig.java | 87 -- .../graph/graphson/GraphsonException.java | 26 - .../core/graph/graphson/GraphsonMode.java | 45 - .../core/graph/graphson/GraphsonReader.java | 75 -- .../core/graph/graphson/GraphsonTokens.java | 52 - .../core/graph/graphson/GraphsonUtil.java | 673 ---------- .../core/graph/graphson/GraphsonWriter.java | 73 -- .../org/sonar/core/graph/package-info.java | 23 - .../org/sonar/core/persistence/MyBatis.java | 8 +- .../org/sonar/core/test/DefaultTestable.java | 137 -- .../org/sonar/core/test/TestPlanBuilder.java | 40 - .../core/test/TestPlanPerspectiveLoader.java | 38 - .../org/sonar/core/test/TestableBuilder.java | 40 - .../core/component/ComponentVertexTest.java | 46 - .../GraphPerspectiveBuilderTest.java | 113 -- .../core/component/ResourceComponentTest.java | 56 - .../org/sonar/core/graph/BeanElementTest.java | 105 -- .../sonar/core/graph/BeanElementsTest.java | 144 --- .../org/sonar/core/graph/BeanGraphTest.java | 91 -- .../org/sonar/core/graph/EdgePathTest.java | 68 - .../org/sonar/core/graph/GraphUtilTest.java | 94 -- .../graph/graphson/GraphsonReaderTest.java | 328 ----- .../core/graph/graphson/GraphsonUtilTest.java | 1151 ----------------- .../graph/graphson/GraphsonWriterTest.java | 133 -- .../sonar/core/test/DefaultTestCaseTest.java | 153 --- .../sonar/core/test/DefaultTestPlanTest.java | 84 -- .../sonar/core/test/DefaultTestableTest.java | 130 -- .../sonar/core/test/TestPlanBuilderTest.java | 63 - .../sonar/core/test/TestableBuilderTest.java | 62 - .../org/sonar/api/component/Component.java | 4 + .../api/component/MutablePerspective.java | 23 - .../org/sonar/api/component/Perspective.java | 5 +- .../org/sonar/api/component/Perspectives.java | 35 - .../api/component/ResourcePerspectives.java | 8 +- .../org/sonar/api/test/MutableTestCase.java | 10 +- .../org/sonar/api/test/MutableTestPlan.java | 6 +- .../org/sonar/api/test/MutableTestable.java | 4 +- .../java/org/sonar/api/test/TestCase.java | 4 +- .../java/org/sonar/api/test/TestPlan.java | 3 +- .../java/org/sonar/api/test/Testable.java | 7 +- 133 files changed, 569 insertions(+), 5766 deletions(-) rename {sonar-core/src/main/java/org/sonar/core/component => sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives}/PerspectiveBuilder.java (86%) rename {sonar-core/src/main/java/org/sonar/core/component => sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives}/PerspectiveNotFoundException.java (95%) rename sonar-batch/src/main/java/org/sonar/batch/index/{BatchResource.java => BatchComponent.java} (84%) rename sonar-batch/src/main/java/org/sonar/batch/index/{ResourceCache.java => BatchComponentCache.java} (54%) rename {sonar-core/src/main/java/org/sonar/core => sonar-batch/src/main/java/org/sonar/batch}/test/DefaultCoverageBlock.java (68%) rename {sonar-core/src/main/java/org/sonar/core => sonar-batch/src/main/java/org/sonar/batch}/test/DefaultTestCase.java (52%) rename {sonar-core/src/main/java/org/sonar/core => sonar-batch/src/main/java/org/sonar/batch}/test/DefaultTestPlan.java (66%) create mode 100644 sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestable.java create mode 100644 sonar-batch/src/main/java/org/sonar/batch/test/TestPlanBuilder.java rename sonar-core/src/main/java/org/sonar/core/test/TestablePerspectiveLoader.java => sonar-batch/src/main/java/org/sonar/batch/test/TestableBuilder.java (53%) rename {sonar-core/src/main/java/org/sonar/core => sonar-batch/src/main/java/org/sonar/batch}/test/package-info.java (97%) rename {sonar-core/src/test/java/org/sonar/core/component => sonar-batch/src/test/java/org/sonar/batch/deprecated/perspectives}/PerspectiveBuilderTest.java (91%) rename sonar-batch/src/test/java/org/sonar/batch/index/{ResourceCacheTest.java => BatchComponentCacheTest.java} (92%) delete mode 100644 sonar-core/src/main/java/org/sonar/core/component/ComponentQuery.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/component/ComponentVertex.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/component/GraphPerspectiveBuilder.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/component/GraphPerspectiveLoader.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/component/ResourceComponent.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/component/ScanGraph.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/component/SnapshotGraph.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/graph/BeanEdge.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/graph/BeanElement.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/graph/BeanElements.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/graph/BeanGraph.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/graph/BeanIterable.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/graph/BeanVertex.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/graph/EdgePath.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/graph/GraphUtil.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/graph/MultipleElementsException.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/graph/graphson/ElementFactory.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/graph/graphson/ElementPropertyConfig.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonException.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonMode.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonReader.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonTokens.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonUtil.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonWriter.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/graph/package-info.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/test/DefaultTestable.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/test/TestPlanBuilder.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/test/TestPlanPerspectiveLoader.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/test/TestableBuilder.java delete mode 100644 sonar-core/src/test/java/org/sonar/core/component/ComponentVertexTest.java delete mode 100644 sonar-core/src/test/java/org/sonar/core/component/GraphPerspectiveBuilderTest.java delete mode 100644 sonar-core/src/test/java/org/sonar/core/component/ResourceComponentTest.java delete mode 100644 sonar-core/src/test/java/org/sonar/core/graph/BeanElementTest.java delete mode 100644 sonar-core/src/test/java/org/sonar/core/graph/BeanElementsTest.java delete mode 100644 sonar-core/src/test/java/org/sonar/core/graph/BeanGraphTest.java delete mode 100644 sonar-core/src/test/java/org/sonar/core/graph/EdgePathTest.java delete mode 100644 sonar-core/src/test/java/org/sonar/core/graph/GraphUtilTest.java delete mode 100644 sonar-core/src/test/java/org/sonar/core/graph/graphson/GraphsonReaderTest.java delete mode 100644 sonar-core/src/test/java/org/sonar/core/graph/graphson/GraphsonUtilTest.java delete mode 100644 sonar-core/src/test/java/org/sonar/core/graph/graphson/GraphsonWriterTest.java delete mode 100644 sonar-core/src/test/java/org/sonar/core/test/DefaultTestCaseTest.java delete mode 100644 sonar-core/src/test/java/org/sonar/core/test/DefaultTestPlanTest.java delete mode 100644 sonar-core/src/test/java/org/sonar/core/test/DefaultTestableTest.java delete mode 100644 sonar-core/src/test/java/org/sonar/core/test/TestPlanBuilderTest.java delete mode 100644 sonar-core/src/test/java/org/sonar/core/test/TestableBuilderTest.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/component/MutablePerspective.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/component/Perspectives.java diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/AbstractNewCoverageFileAnalyzer.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/AbstractNewCoverageFileAnalyzer.java index e215fc18fe5..35d8a3506e4 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/AbstractNewCoverageFileAnalyzer.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/AbstractNewCoverageFileAnalyzer.java @@ -37,7 +37,7 @@ import org.sonar.api.resources.Scopes; import org.sonar.api.utils.KeyValueFormat; import org.sonar.batch.components.Period; import org.sonar.batch.components.TimeMachineConfiguration; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.output.BatchReport; import org.sonar.batch.protocol.output.BatchReport.Changesets.Changeset; import org.sonar.batch.protocol.output.BatchReportReader; @@ -59,16 +59,16 @@ public abstract class AbstractNewCoverageFileAnalyzer implements Decorator { private final List structs; private final ReportPublisher publishReportJob; - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; - public AbstractNewCoverageFileAnalyzer(TimeMachineConfiguration timeMachineConfiguration, ReportPublisher publishReportJob, ResourceCache resourceCache) { + public AbstractNewCoverageFileAnalyzer(TimeMachineConfiguration timeMachineConfiguration, ReportPublisher publishReportJob, BatchComponentCache resourceCache) { this(Lists.newArrayList(), publishReportJob, resourceCache); for (Period period : timeMachineConfiguration.periods()) { structs.add(new PeriodStruct(period.getIndex(), period.getDate())); } } - AbstractNewCoverageFileAnalyzer(List structs, ReportPublisher publishReportJob, ResourceCache resourceCache) { + AbstractNewCoverageFileAnalyzer(List structs, ReportPublisher publishReportJob, BatchComponentCache resourceCache) { this.resourceCache = resourceCache; this.publishReportJob = publishReportJob; this.structs = structs; diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewCoverageFileAnalyzer.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewCoverageFileAnalyzer.java index d13df7224ef..79f028966cd 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewCoverageFileAnalyzer.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewCoverageFileAnalyzer.java @@ -22,18 +22,18 @@ package org.sonar.plugins.core.timemachine; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Metric; import org.sonar.batch.components.TimeMachineConfiguration; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.report.ReportPublisher; import java.util.List; public class NewCoverageFileAnalyzer extends AbstractNewCoverageFileAnalyzer { - public NewCoverageFileAnalyzer(TimeMachineConfiguration timeMachineConfiguration, ReportPublisher publishReportJob, ResourceCache resourceCache) { + public NewCoverageFileAnalyzer(TimeMachineConfiguration timeMachineConfiguration, ReportPublisher publishReportJob, BatchComponentCache resourceCache) { super(timeMachineConfiguration, publishReportJob, resourceCache); } - NewCoverageFileAnalyzer(List structs, ReportPublisher publishReportJob, ResourceCache resourceCache) { + NewCoverageFileAnalyzer(List structs, ReportPublisher publishReportJob, BatchComponentCache resourceCache) { super(structs, publishReportJob, resourceCache); } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewItCoverageFileAnalyzer.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewItCoverageFileAnalyzer.java index f069a633b4e..2aacf34a9bd 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewItCoverageFileAnalyzer.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewItCoverageFileAnalyzer.java @@ -22,12 +22,12 @@ package org.sonar.plugins.core.timemachine; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Metric; import org.sonar.batch.components.TimeMachineConfiguration; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.report.ReportPublisher; public class NewItCoverageFileAnalyzer extends AbstractNewCoverageFileAnalyzer { - public NewItCoverageFileAnalyzer(TimeMachineConfiguration timeMachineConfiguration, ReportPublisher publishReportJob, ResourceCache resourceCache) { + public NewItCoverageFileAnalyzer(TimeMachineConfiguration timeMachineConfiguration, ReportPublisher publishReportJob, BatchComponentCache resourceCache) { super(timeMachineConfiguration, publishReportJob, resourceCache); } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewOverallCoverageFileAnalyzer.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewOverallCoverageFileAnalyzer.java index fc61e4eafe3..f80da9470bb 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewOverallCoverageFileAnalyzer.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewOverallCoverageFileAnalyzer.java @@ -22,12 +22,12 @@ package org.sonar.plugins.core.timemachine; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Metric; import org.sonar.batch.components.TimeMachineConfiguration; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.report.ReportPublisher; public class NewOverallCoverageFileAnalyzer extends AbstractNewCoverageFileAnalyzer { - public NewOverallCoverageFileAnalyzer(TimeMachineConfiguration timeMachineConfiguration, ReportPublisher publishReportJob, ResourceCache resourceCache) { + public NewOverallCoverageFileAnalyzer(TimeMachineConfiguration timeMachineConfiguration, ReportPublisher publishReportJob, BatchComponentCache resourceCache) { super(timeMachineConfiguration, publishReportJob, resourceCache); } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java index 49473602e35..7427654f1bc 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java @@ -27,7 +27,7 @@ import org.sonar.api.resources.Resource; import org.sonar.api.resources.ResourceUtils; import org.sonar.batch.components.PastSnapshot; import org.sonar.batch.components.TimeMachineConfiguration; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import java.util.List; @@ -38,10 +38,10 @@ import static org.sonar.api.utils.DateUtils.dateToLong; public final class TimeMachineConfigurationPersister implements Decorator { private final TimeMachineConfiguration timeMachineConfiguration; - private ResourceCache resourceCache; + private BatchComponentCache resourceCache; private DatabaseSession session; - public TimeMachineConfigurationPersister(TimeMachineConfiguration timeMachineConfiguration, ResourceCache resourceCache, DatabaseSession session) { + public TimeMachineConfigurationPersister(TimeMachineConfiguration timeMachineConfiguration, BatchComponentCache resourceCache, DatabaseSession session) { this.timeMachineConfiguration = timeMachineConfiguration; this.resourceCache = resourceCache; this.session = session; diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewCoverageFileAnalyzerTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewCoverageFileAnalyzerTest.java index 75297f6578f..adc6f087b44 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewCoverageFileAnalyzerTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewCoverageFileAnalyzerTest.java @@ -31,7 +31,7 @@ import org.sonar.api.measures.Metric; import org.sonar.api.resources.File; import org.sonar.api.resources.Resource; import org.sonar.api.utils.DateUtils; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.output.BatchReport; import org.sonar.batch.protocol.output.BatchReport.Changesets.Changeset; import org.sonar.batch.protocol.output.BatchReportWriter; @@ -64,7 +64,7 @@ public class NewCoverageFileAnalyzerTest { context = mock(DecoratorContext.class); Resource f = File.create("src/Foo.java").setEffectiveKey("foo:src/Foo.java"); when(context.getResource()).thenReturn(f); - ResourceCache cache = new ResourceCache(); + BatchComponentCache cache = new BatchComponentCache(); cache.add(f, null); List structs = Arrays.asList( new AbstractNewCoverageFileAnalyzer.PeriodStruct(1, newDate("2009-12-25")), diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java index ae79e7a47d3..ca8c36a51cd 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java @@ -26,7 +26,7 @@ import org.junit.Test; import org.sonar.api.database.model.Snapshot; import org.sonar.api.resources.Project; import org.sonar.api.utils.DateUtils; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.jpa.test.AbstractDbUnitTestCase; import java.util.Arrays; @@ -48,7 +48,7 @@ public class TimeMachineConfigurationPersisterTest extends AbstractDbUnitTestCas when(timeMachineConfiguration.getProjectPastSnapshots()).thenReturn(Arrays.asList(vs1, vs3)); Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1000); - ResourceCache resourceCache = new ResourceCache(); + BatchComponentCache resourceCache = new BatchComponentCache(); Project project = new Project("foo"); resourceCache.add(project, null).setSnapshot(projectSnapshot); diff --git a/pom.xml b/pom.xml index 9c79b6fd369..298885efd80 100644 --- a/pom.xml +++ b/pom.xml @@ -694,11 +694,6 @@ - - com.tinkerpop.blueprints - blueprints-core - 2.2.0 - commons-collections commons-collections diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java index 987e8901d21..f829d7ea3ba 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java @@ -44,8 +44,6 @@ import org.sonar.core.qualitygate.db.ProjectQgateAssociationDao; import org.sonar.core.qualitygate.db.QualityGateConditionDao; import org.sonar.core.qualitygate.db.QualityGateDao; import org.sonar.core.resource.DefaultResourcePermissions; -import org.sonar.core.test.TestPlanPerspectiveLoader; -import org.sonar.core.test.TestablePerspectiveLoader; import org.sonar.core.timemachine.Periods; import org.sonar.core.user.DefaultUserFinder; import org.sonar.core.user.HibernateUserFinder; @@ -631,10 +629,6 @@ public class PlatformLevel4 extends PlatformLevel { // Properties PropertiesWs.class, - // graphs and perspective related classes - TestablePerspectiveLoader.class, - TestPlanPerspectiveLoader.class, - // Type validation TypeValidations.class, IntegerTypeValidation.class, diff --git a/sonar-batch/src/main/java/org/sonar/batch/cpd/index/DbDuplicationsIndex.java b/sonar-batch/src/main/java/org/sonar/batch/cpd/index/DbDuplicationsIndex.java index 4318e0fa8ad..70fb4d77b2a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/cpd/index/DbDuplicationsIndex.java +++ b/sonar-batch/src/main/java/org/sonar/batch/cpd/index/DbDuplicationsIndex.java @@ -26,7 +26,7 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.Snapshot; import org.sonar.api.resources.Project; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.core.duplication.DuplicationDao; import org.sonar.core.duplication.DuplicationUnitDto; import org.sonar.duplications.block.Block; @@ -51,10 +51,10 @@ public class DbDuplicationsIndex { private final String languageKey; private final DuplicationDao dao; private final DatabaseSession session; - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; public DbDuplicationsIndex(Project currentProject, DuplicationDao dao, - String language, DatabaseSession session, ResourceCache resourceCache) { + String language, DatabaseSession session, BatchComponentCache resourceCache) { this.dao = dao; this.session = session; this.resourceCache = resourceCache; diff --git a/sonar-batch/src/main/java/org/sonar/batch/cpd/index/IndexFactory.java b/sonar-batch/src/main/java/org/sonar/batch/cpd/index/IndexFactory.java index 9f8fe75c46b..6ee5c5edc7d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/cpd/index/IndexFactory.java +++ b/sonar-batch/src/main/java/org/sonar/batch/cpd/index/IndexFactory.java @@ -29,7 +29,7 @@ import org.sonar.api.config.Settings; import org.sonar.api.database.DatabaseSession; import org.sonar.api.resources.Project; import org.sonar.batch.bootstrap.DefaultAnalysisMode; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.core.duplication.DuplicationDao; import javax.annotation.Nullable; @@ -43,9 +43,9 @@ public class IndexFactory { private final DuplicationDao dao; private final DefaultAnalysisMode mode; private final DatabaseSession session; - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; - public IndexFactory(DefaultAnalysisMode mode, Settings settings, @Nullable DuplicationDao dao, @Nullable DatabaseSession session, ResourceCache resourceCache) { + public IndexFactory(DefaultAnalysisMode mode, Settings settings, @Nullable DuplicationDao dao, @Nullable DatabaseSession session, BatchComponentCache resourceCache) { this.mode = mode; this.settings = settings; this.dao = dao; @@ -56,7 +56,7 @@ public class IndexFactory { /** * Used by new sensor mode */ - public IndexFactory(DefaultAnalysisMode mode, Settings settings, ResourceCache resourceCache) { + public IndexFactory(DefaultAnalysisMode mode, Settings settings, BatchComponentCache resourceCache) { this(mode, settings, null, null, resourceCache); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/BatchPerspectives.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/BatchPerspectives.java index 445508ab0f5..47124c44c29 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/BatchPerspectives.java +++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/BatchPerspectives.java @@ -20,47 +20,33 @@ package org.sonar.batch.deprecated.perspectives; import com.google.common.collect.Maps; +import java.util.Map; +import javax.annotation.CheckForNull; import org.sonar.api.batch.SonarIndex; import org.sonar.api.batch.fs.InputDir; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.InputPath; -import org.sonar.api.component.Component; import org.sonar.api.component.Perspective; import org.sonar.api.component.ResourcePerspectives; import org.sonar.api.resources.Directory; import org.sonar.api.resources.File; import org.sonar.api.resources.Resource; -import org.sonar.core.component.PerspectiveBuilder; -import org.sonar.core.component.PerspectiveNotFoundException; -import org.sonar.core.component.ResourceComponent; - -import javax.annotation.CheckForNull; - -import java.util.Map; +import org.sonar.batch.index.BatchComponentCache; public class BatchPerspectives implements ResourcePerspectives { private final Map, PerspectiveBuilder> builders = Maps.newHashMap(); private final SonarIndex resourceIndex; + private final BatchComponentCache componentCache; - public BatchPerspectives(PerspectiveBuilder[] builders, SonarIndex resourceIndex) { + public BatchPerspectives(PerspectiveBuilder[] builders, SonarIndex resourceIndex, BatchComponentCache componentCache) { this.resourceIndex = resourceIndex; + this.componentCache = componentCache; for (PerspectiveBuilder builder : builders) { - // TODO check duplications this.builders.put(builder.getPerspectiveClass(), builder); } } - @Override - @CheckForNull - public

P as(Class

perspectiveClass, Component component) { - if (component.key() == null) { - return null; - } - PerspectiveBuilder

builder = builderFor(perspectiveClass); - return builder.loadPerspective(perspectiveClass, component); - } - @Override @CheckForNull public

P as(Class

perspectiveClass, Resource resource) { @@ -69,7 +55,8 @@ public class BatchPerspectives implements ResourcePerspectives { indexedResource = resourceIndex.getResource(resource); } if (indexedResource != null) { - return as(perspectiveClass, new ResourceComponent(indexedResource)); + PerspectiveBuilder

builder = builderFor(perspectiveClass); + return builder.loadPerspective(perspectiveClass, componentCache.get(indexedResource)); } return null; } @@ -84,7 +71,8 @@ public class BatchPerspectives implements ResourcePerspectives { } else { throw new IllegalArgumentException("Unknow input path type: " + inputPath); } - return as(perspectiveClass, r); + PerspectiveBuilder

builder = builderFor(perspectiveClass); + return builder.loadPerspective(perspectiveClass, componentCache.get(inputPath)); } private PerspectiveBuilder builderFor(Class clazz) { diff --git a/sonar-core/src/main/java/org/sonar/core/component/PerspectiveBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/PerspectiveBuilder.java similarity index 86% rename from sonar-core/src/main/java/org/sonar/core/component/PerspectiveBuilder.java rename to sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/PerspectiveBuilder.java index e31bcf2a59a..6a18b67210e 100644 --- a/sonar-core/src/main/java/org/sonar/core/component/PerspectiveBuilder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/PerspectiveBuilder.java @@ -17,17 +17,14 @@ * 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.core.component; +package org.sonar.batch.deprecated.perspectives; +import javax.annotation.CheckForNull; import org.sonar.api.batch.BatchSide; -import org.sonar.api.server.ServerSide; -import org.sonar.api.component.Component; import org.sonar.api.component.Perspective; - -import javax.annotation.CheckForNull; +import org.sonar.batch.index.BatchComponent; @BatchSide -@ServerSide public abstract class PerspectiveBuilder { private final Class perspectiveClass; @@ -41,5 +38,5 @@ public abstract class PerspectiveBuilder { } @CheckForNull - public abstract T loadPerspective(Class perspectiveClass, Component component); + public abstract T loadPerspective(Class perspectiveClass, BatchComponent component); } diff --git a/sonar-core/src/main/java/org/sonar/core/component/PerspectiveNotFoundException.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/PerspectiveNotFoundException.java similarity index 95% rename from sonar-core/src/main/java/org/sonar/core/component/PerspectiveNotFoundException.java rename to sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/PerspectiveNotFoundException.java index 70a0a4cb230..d75067a4358 100644 --- a/sonar-core/src/main/java/org/sonar/core/component/PerspectiveNotFoundException.java +++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/PerspectiveNotFoundException.java @@ -17,7 +17,7 @@ * 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.core.component; +package org.sonar.batch.deprecated.perspectives; public class PerspectiveNotFoundException extends RuntimeException { public PerspectiveNotFoundException(String message) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/BatchResource.java b/sonar-batch/src/main/java/org/sonar/batch/index/BatchComponent.java similarity index 84% rename from sonar-batch/src/main/java/org/sonar/batch/index/BatchResource.java rename to sonar-batch/src/main/java/org/sonar/batch/index/BatchComponent.java index af4eedd4bd9..38655cc298b 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/BatchResource.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/BatchComponent.java @@ -31,16 +31,16 @@ import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Collection; -public class BatchResource { +public class BatchComponent { private final int batchId; private final Resource r; private Snapshot s; - private final BatchResource parent; - private final Collection children = new ArrayList<>(); + private final BatchComponent parent; + private final Collection children = new ArrayList<>(); private InputPath inputPath; - public BatchResource(int batchId, Resource r, @Nullable BatchResource parent) { + public BatchComponent(int batchId, Resource r, @Nullable BatchComponent parent) { this.batchId = batchId; this.r = r; this.parent = parent; @@ -61,7 +61,7 @@ public class BatchResource { return r; } - public BatchResource setSnapshot(Snapshot snapshot) { + public BatchComponent setSnapshot(Snapshot snapshot) { this.s = snapshot; return this; } @@ -79,11 +79,11 @@ public class BatchResource { } @CheckForNull - public BatchResource parent() { + public BatchComponent parent() { return parent; } - public Collection children() { + public Collection children() { return children; } @@ -95,7 +95,7 @@ public class BatchResource { return Qualifiers.isDirectory(r); } - public BatchResource setInputPath(InputPath inputPath) { + public BatchComponent setInputPath(InputPath inputPath) { this.inputPath = inputPath; return this; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ResourceCache.java b/sonar-batch/src/main/java/org/sonar/batch/index/BatchComponentCache.java similarity index 54% rename from sonar-batch/src/main/java/org/sonar/batch/index/ResourceCache.java rename to sonar-batch/src/main/java/org/sonar/batch/index/BatchComponentCache.java index 156ff96305f..f030027e24f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/ResourceCache.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/BatchComponentCache.java @@ -19,74 +19,60 @@ */ package org.sonar.batch.index; -import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.collect.Maps; +import java.util.Collection; +import java.util.Map; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.fs.InputPath; +import org.sonar.api.batch.fs.internal.DefaultInputDir; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.resources.Resource; -import org.sonar.api.resources.ResourceUtils; -import org.sonar.core.component.ScanGraph; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -import java.util.Collection; -import java.util.Map; @BatchSide -public class ResourceCache { - // resource by component key - private final Map resources = Maps.newLinkedHashMap(); - - private BatchResource root; - private final ScanGraph scanGraph; - - public ResourceCache(ScanGraph scanGraph) { - this.scanGraph = scanGraph; - } +public class BatchComponentCache { + // components by key + private final Map components = Maps.newLinkedHashMap(); - @VisibleForTesting - public ResourceCache() { - this.scanGraph = null; - } + private BatchComponent root; @CheckForNull - public BatchResource get(String componentKey) { - return resources.get(componentKey); + public BatchComponent get(String componentKey) { + return components.get(componentKey); } - public BatchResource get(Resource resource) { - return resources.get(resource.getEffectiveKey()); + public BatchComponent get(Resource resource) { + return components.get(resource.getEffectiveKey()); } - public BatchResource get(InputFile inputFile) { - return resources.get(((DefaultInputFile) inputFile).key()); + public BatchComponent get(InputPath inputPath) { + if (inputPath instanceof DefaultInputFile) { + return components.get(((DefaultInputFile) inputPath).key()); + } + return components.get(((DefaultInputDir) inputPath).key()); } - public BatchResource add(Resource resource, @Nullable Resource parentResource) { + public BatchComponent add(Resource resource, @Nullable Resource parentResource) { String componentKey = resource.getEffectiveKey(); Preconditions.checkState(!Strings.isNullOrEmpty(componentKey), "Missing resource effective key"); - BatchResource parent = parentResource != null ? get(parentResource.getEffectiveKey()) : null; - BatchResource batchResource = new BatchResource(resources.size() + 1, resource, parent); + BatchComponent parent = parentResource != null ? get(parentResource.getEffectiveKey()) : null; + BatchComponent batchResource = new BatchComponent(components.size() + 1, resource, parent); // Libraries can have the same effective key than a project so we can't cache by effectiveKey - resources.put(componentKey, batchResource); + components.put(componentKey, batchResource); if (parent == null) { root = batchResource; } - if (scanGraph != null && ResourceUtils.isPersistable(batchResource.resource())) { - scanGraph.addComponent(batchResource.resource()); - } return batchResource; } - public Collection all() { - return resources.values(); + public Collection all() { + return components.values(); } - public BatchResource getRoot() { + public BatchComponent getRoot() { return root; } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java index bed28c439a5..63dac585a2c 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java @@ -91,7 +91,7 @@ public class DefaultIndex extends SonarIndex { CoreMetrics.DUPLICATIONS_DATA_KEY ); - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; private final MetricFinder metricFinder; private final MeasureCache measureCache; // caches @@ -100,7 +100,7 @@ public class DefaultIndex extends SonarIndex { private DefaultProjectTree projectTree; private ModuleIssues moduleIssues; - public DefaultIndex(ResourceCache resourceCache, DefaultProjectTree projectTree, MetricFinder metricFinder, MeasureCache measureCache) { + public DefaultIndex(BatchComponentCache resourceCache, DefaultProjectTree projectTree, MetricFinder metricFinder, MeasureCache measureCache) { this.resourceCache = resourceCache; this.projectTree = projectTree; this.metricFinder = metricFinder; diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java index cf31dfdcaf5..504286a67af 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java @@ -20,6 +20,8 @@ package org.sonar.batch.index; import com.google.common.annotations.VisibleForTesting; +import javax.annotation.Nullable; +import javax.persistence.NonUniqueResultException; import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.StringUtils; import org.sonar.api.database.DatabaseSession; @@ -34,10 +36,6 @@ import org.sonar.api.resources.Scopes; import org.sonar.api.security.ResourcePermissions; import org.sonar.api.utils.SonarException; import org.sonar.api.utils.internal.Uuids; -import org.sonar.core.component.ScanGraph; - -import javax.annotation.Nullable; -import javax.persistence.NonUniqueResultException; import static org.sonar.api.utils.DateUtils.dateToLong; @@ -48,29 +46,27 @@ public class ResourcePersister implements ScanPersister { private final DatabaseSession session; private final ResourcePermissions permissions; - private final ResourceCache resourceCache; - private final ScanGraph scanGraph; + private final BatchComponentCache resourceCache; - public ResourcePersister(DatabaseSession session, ResourcePermissions permissions, ResourceCache resourceCache, ScanGraph scanGraph) { + public ResourcePersister(DatabaseSession session, ResourcePermissions permissions, BatchComponentCache resourceCache) { this.session = session; this.permissions = permissions; this.resourceCache = resourceCache; - this.scanGraph = scanGraph; } @Override public void persist() { - for (BatchResource resource : resourceCache.all()) { + for (BatchComponent resource : resourceCache.all()) { persist(resource); } } - private void persist(BatchResource batchResource) { + private void persist(BatchComponent batchResource) { if (batchResource.snapshot() != null) { // already persisted return; } - BatchResource parentBatchResource = batchResource.parent(); + BatchComponent parentBatchResource = batchResource.parent(); Snapshot s; if (parentBatchResource != null) { persist(parentBatchResource); @@ -80,12 +76,9 @@ public class ResourcePersister implements ScanPersister { s = persistProject((Project) batchResource.resource(), null); } batchResource.setSnapshot(s); - if (ResourceUtils.isPersistable(batchResource.resource())) { - scanGraph.completeComponent(batchResource.key(), batchResource.resource().getId(), s.getId()); - } } - private Project findModule(BatchResource batchResource) { + private Project findModule(BatchComponent batchResource) { if (batchResource.resource() instanceof Project) { return (Project) batchResource.resource(); } else { @@ -147,7 +140,7 @@ public class ResourcePersister implements ScanPersister { * Everything except project and library */ private Snapshot persistFileOrDirectory(Project project, Resource resource, @Nullable Resource parentReference) { - BatchResource moduleResource = resourceCache.get(project); + BatchComponent moduleResource = resourceCache.get(project); Integer moduleId = moduleResource.resource().getId(); ResourceModel model = findOrCreateModel(resource, parentReference != null ? parentReference : project); model.setRootId(moduleId); diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java b/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java index 578bb2bb49e..89561865d63 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java @@ -20,15 +20,14 @@ package org.sonar.batch.issue; import com.google.common.collect.Lists; -import org.sonar.api.component.Component; +import java.util.List; import org.sonar.api.issue.Issuable; import org.sonar.api.issue.Issue; import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.resources.Project; +import org.sonar.batch.index.BatchComponent; import org.sonar.core.issue.DefaultIssueBuilder; -import java.util.List; - /** * @since 3.6 */ @@ -36,10 +35,10 @@ public class DefaultIssuable implements Issuable { private final ModuleIssues moduleIssues; private final IssueCache cache; - private final Component component; + private final BatchComponent component; private final Project project; - DefaultIssuable(Component component, Project project, ModuleIssues moduleIssues, IssueCache cache) { + DefaultIssuable(BatchComponent component, Project project, ModuleIssues moduleIssues, IssueCache cache) { this.component = component; this.project = project; this.moduleIssues = moduleIssues; @@ -56,32 +55,26 @@ public class DefaultIssuable implements Issuable { return moduleIssues.initAndAddIssue((DefaultIssue) issue); } - @SuppressWarnings("unchecked") @Override public List resolvedIssues() { List result = Lists.newArrayList(); for (DefaultIssue issue : cache.byComponent(component.key())) { - if (issue.resolution()!=null) { + if (issue.resolution() != null) { result.add(issue); } } return result; } - @SuppressWarnings("unchecked") @Override public List issues() { List result = Lists.newArrayList(); for (DefaultIssue issue : cache.byComponent(component.key())) { - if (issue.resolution()==null) { + if (issue.resolution() == null) { result.add(issue); } } return result; } - @Override - public Component component() { - return component; - } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/IssuableFactory.java b/sonar-batch/src/main/java/org/sonar/batch/issue/IssuableFactory.java index 51ec2b9fe7e..1fda7c27513 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/IssuableFactory.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/IssuableFactory.java @@ -19,14 +19,10 @@ */ package org.sonar.batch.issue; -import org.sonar.api.component.Component; import org.sonar.api.issue.Issuable; -import org.sonar.api.resources.Scopes; import org.sonar.batch.DefaultProjectTree; -import org.sonar.core.component.PerspectiveBuilder; -import org.sonar.core.component.ResourceComponent; - -import javax.annotation.CheckForNull; +import org.sonar.batch.deprecated.perspectives.PerspectiveBuilder; +import org.sonar.batch.index.BatchComponent; /** * Create the perspective {@link Issuable} on components. @@ -45,13 +41,8 @@ public class IssuableFactory extends PerspectiveBuilder { this.projectTree = projectTree; } - @CheckForNull @Override - public Issuable loadPerspective(Class perspectiveClass, Component component) { - boolean supported = true; - if (component instanceof ResourceComponent) { - supported = Scopes.isHigherThanOrEquals(((ResourceComponent) component).scope(), Scopes.FILE); - } - return supported ? new DefaultIssuable(component, projectTree.getRootProject(), moduleIssues, cache) : null; + public Issuable loadPerspective(Class perspectiveClass, BatchComponent component) { + return new DefaultIssuable(component, projectTree.getRootProject(), moduleIssues, cache); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java index dfba07392e6..a946c9f7dea 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java @@ -34,8 +34,8 @@ import org.sonar.api.issue.internal.IssueChangeContext; import org.sonar.api.resources.Project; import org.sonar.api.resources.ResourceUtils; import org.sonar.api.rule.RuleKey; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.issue.IssueCache; import org.sonar.batch.protocol.input.ProjectRepositories; import org.sonar.batch.scan.filesystem.InputPathCache; @@ -62,12 +62,12 @@ public class LocalIssueTracking { private final IssueChangeContext changeContext; private final ActiveRules activeRules; private final InputPathCache inputPathCache; - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; private final ServerIssueRepository serverIssueRepository; private final ProjectRepositories projectRepositories; private final AnalysisMode analysisMode; - public LocalIssueTracking(ResourceCache resourceCache, IssueCache issueCache, IssueTracking tracking, + public LocalIssueTracking(BatchComponentCache resourceCache, IssueCache issueCache, IssueTracking tracking, ServerLineHashesLoader lastLineHashes, IssueWorkflow workflow, IssueUpdater updater, ActiveRules activeRules, InputPathCache inputPathCache, ServerIssueRepository serverIssueRepository, ProjectRepositories projectRepositories, AnalysisMode analysisMode) { @@ -93,12 +93,12 @@ public class LocalIssueTracking { serverIssueRepository.load(); - for (BatchResource component : resourceCache.all()) { + for (BatchComponent component : resourceCache.all()) { trackIssues(component); } } - public void trackIssues(BatchResource component) { + public void trackIssues(BatchComponent component) { Collection issues = Lists.newArrayList(); for (Issue issue : issueCache.byComponent(component.resource().getEffectiveKey())) { @@ -136,7 +136,7 @@ public class LocalIssueTracking { } @CheckForNull - private SourceHashHolder loadSourceHashes(BatchResource component) { + private SourceHashHolder loadSourceHashes(BatchComponent component) { SourceHashHolder sourceHashHolder = null; if (component.isFile()) { DefaultInputFile file = (DefaultInputFile) inputPathCache.getInputPath(component); @@ -148,7 +148,7 @@ public class LocalIssueTracking { return sourceHashHolder; } - private Collection loadServerIssues(BatchResource component) { + private Collection loadServerIssues(BatchComponent component) { Collection serverIssues = new ArrayList<>(); for (org.sonar.batch.protocol.input.BatchInput.ServerIssue previousIssue : serverIssueRepository.byComponent(component)) { serverIssues.add(new ServerIssueFromWs(previousIssue)); diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java index 81de6745192..79bedb1c112 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java @@ -29,10 +29,10 @@ import org.sonar.api.batch.fs.InputFile.Status; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.api.utils.log.Profiler; -import org.sonar.batch.index.BatchResource; +import org.sonar.batch.index.BatchComponent; import org.sonar.batch.index.Cache; import org.sonar.batch.index.Caches; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.input.BatchInput.ServerIssue; import org.sonar.batch.repository.ServerIssuesLoader; import org.sonar.batch.scan.filesystem.InputPathCache; @@ -54,11 +54,11 @@ public class ServerIssueRepository { private Cache issuesCache; private final ServerIssuesLoader previousIssuesLoader; private final ProjectReactor reactor; - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; private final AnalysisMode analysisMode; private final InputPathCache inputPathCache; - public ServerIssueRepository(Caches caches, ServerIssuesLoader previousIssuesLoader, ProjectReactor reactor, ResourceCache resourceCache, + public ServerIssueRepository(Caches caches, ServerIssuesLoader previousIssuesLoader, ProjectReactor reactor, BatchComponentCache resourceCache, AnalysisMode analysisMode, InputPathCache inputPathCache) { this.caches = caches; this.previousIssuesLoader = previousIssuesLoader; @@ -83,7 +83,7 @@ public class ServerIssueRepository { return null; } String componentKey = ComponentKeys.createEffectiveKey(issue.getModuleKey(), issue.hasPath() ? issue.getPath() : null); - BatchResource r = resourceCache.get(componentKey); + BatchComponent r = resourceCache.get(componentKey); if (r == null) { // Deleted resource issuesCache.put(0, issue.getKey(), issue); @@ -96,7 +96,7 @@ public class ServerIssueRepository { profiler.stopDebug(); } - public Iterable byComponent(BatchResource component) { + public Iterable byComponent(BatchComponent component) { if (analysisMode.isIncremental()) { if (!component.isFile()) { throw new UnsupportedOperationException("Incremental mode should only get issues on files"); diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java index 321d495f929..55502e9ba78 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java +++ b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java @@ -41,7 +41,7 @@ import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.measures.Measure; import org.sonar.batch.duplication.DuplicationCache; import org.sonar.batch.index.Cache.Entry; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.issue.IssueCache; import org.sonar.batch.protocol.output.BatchReport; import org.sonar.batch.protocol.output.BatchReport.Component; @@ -120,7 +120,7 @@ public class TaskResult implements org.sonar.batch.mediumtest.ScanTaskObserver { } private void storeMeasures(ProjectScanContainer container) { - ResourceCache resourceCache = container.getComponentByType(ResourceCache.class); + BatchComponentCache resourceCache = container.getComponentByType(BatchComponentCache.class); for (Entry measureEntry : container.getComponentByType(MeasureCache.class).entries()) { String componentKey = measureEntry.key()[0].toString(); InputPath path = resourceCache.get(componentKey).inputPath(); diff --git a/sonar-batch/src/main/java/org/sonar/batch/postjob/DefaultPostJobContext.java b/sonar-batch/src/main/java/org/sonar/batch/postjob/DefaultPostJobContext.java index 56840eb88b4..6f46c012ce9 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/postjob/DefaultPostJobContext.java +++ b/sonar-batch/src/main/java/org/sonar/batch/postjob/DefaultPostJobContext.java @@ -30,8 +30,8 @@ import org.sonar.api.batch.rule.Severity; import org.sonar.api.config.Settings; import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.rule.RuleKey; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.issue.IssueCache; import javax.annotation.Nullable; @@ -41,9 +41,9 @@ public class DefaultPostJobContext implements PostJobContext { private final Settings settings; private final AnalysisMode analysisMode; private final IssueCache cache; - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; - public DefaultPostJobContext(Settings settings, AnalysisMode analysisMode, IssueCache cache, ResourceCache resourceCache) { + public DefaultPostJobContext(Settings settings, AnalysisMode analysisMode, IssueCache cache, BatchComponentCache resourceCache) { this.settings = settings; this.analysisMode = analysisMode; this.cache = cache; @@ -105,7 +105,7 @@ public class DefaultPostJobContext implements PostJobContext { @Override public InputPath inputPath() { - BatchResource component = resourceCache.get(wrapped.componentKey()); + BatchComponent component = resourceCache.get(wrapped.componentKey()); return component != null ? component.inputPath() : null; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/qualitygate/QualityGateVerifier.java b/sonar-batch/src/main/java/org/sonar/batch/qualitygate/QualityGateVerifier.java index 657dbaba303..54427072235 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/qualitygate/QualityGateVerifier.java +++ b/sonar-batch/src/main/java/org/sonar/batch/qualitygate/QualityGateVerifier.java @@ -34,7 +34,7 @@ import org.sonar.api.resources.Resource; import org.sonar.api.resources.ResourceUtils; import org.sonar.api.utils.Duration; import org.sonar.api.utils.Durations; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.core.qualitygate.db.QualityGateConditionDto; import org.sonar.core.timemachine.Periods; @@ -55,9 +55,9 @@ public class QualityGateVerifier implements Decorator { private Periods periods; private I18n i18n; private Durations durations; - private ResourceCache resourceCache; + private BatchComponentCache resourceCache; - public QualityGateVerifier(QualityGate qualityGate, ResourceCache resourceCache, Periods periods, I18n i18n, Durations durations) { + public QualityGateVerifier(QualityGate qualityGate, BatchComponentCache resourceCache, Periods periods, I18n i18n, Durations durations) { this.qualityGate = qualityGate; this.resourceCache = resourceCache; this.periods = periods; diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java index 217458bcdea..2398ec25434 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java @@ -27,8 +27,8 @@ import org.sonar.api.batch.fs.InputFile; import org.sonar.api.resources.Language; import org.sonar.api.resources.Resource; import org.sonar.api.resources.ResourceUtils; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.Constants; import org.sonar.batch.protocol.Constants.ComponentLinkType; import org.sonar.batch.protocol.output.*; @@ -43,11 +43,11 @@ import javax.annotation.CheckForNull; */ public class ComponentsPublisher implements ReportPublisherStep { - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; private final ProjectReactor reactor; private final EventCache eventCache; - public ComponentsPublisher(ProjectReactor reactor, ResourceCache resourceCache, EventCache eventCache) { + public ComponentsPublisher(ProjectReactor reactor, BatchComponentCache resourceCache, EventCache eventCache) { this.reactor = reactor; this.resourceCache = resourceCache; this.eventCache = eventCache; @@ -55,11 +55,11 @@ public class ComponentsPublisher implements ReportPublisherStep { @Override public void publish(BatchReportWriter writer) { - BatchResource rootProject = resourceCache.get(reactor.getRoot().getKeyWithBranch()); + BatchComponent rootProject = resourceCache.get(reactor.getRoot().getKeyWithBranch()); recursiveWriteComponent(rootProject, writer); } - private void recursiveWriteComponent(BatchResource batchResource, BatchReportWriter writer) { + private void recursiveWriteComponent(BatchComponent batchResource, BatchReportWriter writer) { Resource r = batchResource.resource(); BatchReport.Component.Builder builder = BatchReport.Component.newBuilder(); @@ -98,7 +98,7 @@ public class ComponentsPublisher implements ReportPublisherStep { if (lang != null) { builder.setLanguage(lang); } - for (BatchResource child : batchResource.children()) { + for (BatchComponent child : batchResource.children()) { builder.addChildRef(child.batchId()); } writeLinks(r, builder); @@ -106,12 +106,12 @@ public class ComponentsPublisher implements ReportPublisherStep { writeEvents(batchResource, builder); writer.writeComponent(builder.build()); - for (BatchResource child : batchResource.children()) { + for (BatchComponent child : batchResource.children()) { recursiveWriteComponent(child, writer); } } - private void writeEvents(BatchResource batchResource, Builder builder) { + private void writeEvents(BatchComponent batchResource, Builder builder) { if (ResourceUtils.isProject(batchResource.resource())) { for (Event event : eventCache.getEvents(batchResource.batchId())) { builder.addEvent(event); diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/CoveragePublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/CoveragePublisher.java index 617e4d1b943..27a64a9e21f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/CoveragePublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/CoveragePublisher.java @@ -26,8 +26,8 @@ import org.sonar.api.batch.fs.InputFile; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Measure; import org.sonar.api.utils.KeyValueFormat; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.output.BatchReport.Coverage; import org.sonar.batch.protocol.output.BatchReport.Coverage.Builder; import org.sonar.batch.protocol.output.BatchReportWriter; @@ -38,17 +38,17 @@ import java.util.Map; public class CoveragePublisher implements ReportPublisherStep { - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; private final MeasureCache measureCache; - public CoveragePublisher(ResourceCache resourceCache, MeasureCache measureCache) { + public CoveragePublisher(BatchComponentCache resourceCache, MeasureCache measureCache) { this.resourceCache = resourceCache; this.measureCache = measureCache; } @Override public void publish(BatchReportWriter writer) { - for (final BatchResource resource : resourceCache.all()) { + for (final BatchComponent resource : resourceCache.all()) { if (!resource.isFile()) { continue; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/DuplicationsPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/DuplicationsPublisher.java index 9b0dde87911..b40521f355f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/DuplicationsPublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/DuplicationsPublisher.java @@ -24,8 +24,8 @@ import com.google.common.collect.Iterables; import org.sonar.api.batch.sensor.duplication.Duplication.Block; import org.sonar.api.batch.sensor.duplication.internal.DefaultDuplication; import org.sonar.batch.duplication.DuplicationCache; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.output.*; import org.sonar.batch.protocol.output.BatchReport.Duplicate; import org.sonar.batch.protocol.output.BatchReport.Duplication; @@ -33,17 +33,17 @@ import org.sonar.batch.protocol.output.BatchReport.Range; public class DuplicationsPublisher implements ReportPublisherStep { - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; private final DuplicationCache duplicationCache; - public DuplicationsPublisher(ResourceCache resourceCache, DuplicationCache duplicationCache) { + public DuplicationsPublisher(BatchComponentCache resourceCache, DuplicationCache duplicationCache) { this.resourceCache = resourceCache; this.duplicationCache = duplicationCache; } @Override public void publish(BatchReportWriter writer) { - for (final BatchResource resource : resourceCache.all()) { + for (final BatchComponent resource : resourceCache.all()) { if (!resource.isFile()) { continue; } @@ -77,7 +77,7 @@ public class DuplicationsPublisher implements ReportPublisherStep { blockBuilder.clear(); String componentKey = duplicate.resourceKey(); if (!currentComponentKey.equals(componentKey)) { - BatchResource sameProjectComponent = resourceCache.get(componentKey); + BatchComponent sameProjectComponent = resourceCache.get(componentKey); if (sameProjectComponent != null) { blockBuilder.setOtherFileRef(sameProjectComponent.batchId()); } else { diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/EventCache.java b/sonar-batch/src/main/java/org/sonar/batch/report/EventCache.java index c7fdc589677..7ffc48bfd7d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/EventCache.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/EventCache.java @@ -21,7 +21,7 @@ package org.sonar.batch.report; import org.sonar.api.batch.BatchSide; import org.sonar.api.resources.Resource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.Constants.EventCategory; import org.sonar.batch.protocol.output.BatchReport.Event; @@ -37,9 +37,9 @@ import java.util.Map; public class EventCache { private final Map> eventsByComponentBatchId = new HashMap<>(); - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; - public EventCache(ResourceCache resourceCache) { + public EventCache(BatchComponentCache resourceCache) { this.resourceCache = resourceCache; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/IssuesPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/IssuesPublisher.java index f2268cd20a9..e2c70d590db 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/IssuesPublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/IssuesPublisher.java @@ -26,8 +26,8 @@ import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.issue.internal.FieldDiffs; import org.sonar.api.resources.Project; import org.sonar.api.utils.KeyValueFormat; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.issue.IssueCache; import org.sonar.batch.protocol.Constants; import org.sonar.batch.protocol.output.BatchReport; @@ -41,11 +41,11 @@ import java.util.Iterator; public class IssuesPublisher implements ReportPublisherStep { - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; private final IssueCache issueCache; private final ProjectReactor reactor; - public IssuesPublisher(ProjectReactor reactor, ResourceCache resourceCache, IssueCache issueCache) { + public IssuesPublisher(ProjectReactor reactor, BatchComponentCache resourceCache, IssueCache issueCache) { this.reactor = reactor; this.resourceCache = resourceCache; this.issueCache = issueCache; @@ -54,7 +54,7 @@ public class IssuesPublisher implements ReportPublisherStep { @Override public void publish(BatchReportWriter writer) { Collection deletedComponentKeys = issueCache.componentKeys(); - for (BatchResource resource : resourceCache.all()) { + for (BatchComponent resource : resourceCache.all()) { String componentKey = resource.resource().getEffectiveKey(); Iterable issues = issueCache.byComponent(componentKey); writer.writeComponentIssues(resource.batchId(), Iterables.transform(issues, new Function() { @@ -74,7 +74,7 @@ public class IssuesPublisher implements ReportPublisherStep { } private void exportMetadata(BatchReportWriter writer, int count) { - BatchResource rootProject = resourceCache.get(reactor.getRoot().getKeyWithBranch()); + BatchComponent rootProject = resourceCache.get(reactor.getRoot().getKeyWithBranch()); BatchReport.Metadata.Builder builder = BatchReport.Metadata.newBuilder() .setAnalysisDate(((Project) rootProject.resource()).getAnalysisDate().getTime()) .setProjectKey(((Project) rootProject.resource()).key()) diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/MeasuresPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/MeasuresPublisher.java index 8c68e6b787f..07c53cad1f1 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/MeasuresPublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/MeasuresPublisher.java @@ -31,8 +31,8 @@ import org.sonar.api.resources.ResourceUtils; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.RulePriority; import org.sonar.api.technicaldebt.batch.Characteristic; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.Constants; import org.sonar.batch.protocol.Constants.MeasureValueType; import org.sonar.batch.protocol.output.BatchReport; @@ -45,11 +45,11 @@ import java.io.Serializable; public class MeasuresPublisher implements ReportPublisherStep { - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; private final MeasureCache measureCache; private final MetricFinder metricFinder; - public MeasuresPublisher(ResourceCache resourceCache, MeasureCache measureCache, MetricFinder metricFinder) { + public MeasuresPublisher(BatchComponentCache resourceCache, MeasureCache measureCache, MetricFinder metricFinder) { this.resourceCache = resourceCache; this.measureCache = measureCache; this.metricFinder = metricFinder; @@ -57,7 +57,7 @@ public class MeasuresPublisher implements ReportPublisherStep { @Override public void publish(BatchReportWriter writer) { - for (final BatchResource resource : resourceCache.all()) { + for (final BatchComponent resource : resourceCache.all()) { Iterable batchMeasures = measureCache.byResource(resource.resource()); batchMeasures = Iterables.filter(batchMeasures, new Predicate() { @Override diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/SourcePublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/SourcePublisher.java index bd89b7dfe2f..c4395e755e9 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/SourcePublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/SourcePublisher.java @@ -23,8 +23,8 @@ import org.apache.commons.io.ByteOrderMark; import org.apache.commons.io.IOUtils; import org.apache.commons.io.input.BOMInputStream; import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.output.BatchReportWriter; import java.io.BufferedReader; @@ -37,15 +37,15 @@ import java.nio.charset.StandardCharsets; public class SourcePublisher implements ReportPublisherStep { - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; - public SourcePublisher(ResourceCache resourceCache) { + public SourcePublisher(BatchComponentCache resourceCache) { this.resourceCache = resourceCache; } @Override public void publish(BatchReportWriter writer) { - for (final BatchResource resource : resourceCache.all()) { + for (final BatchComponent resource : resourceCache.all()) { if (!resource.isFile()) { continue; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/TestExecutionAndCoveragePublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/TestExecutionAndCoveragePublisher.java index 344ba437ce9..fd430aebc58 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/TestExecutionAndCoveragePublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/TestExecutionAndCoveragePublisher.java @@ -21,25 +21,24 @@ package org.sonar.batch.report; import com.google.common.base.Function; import com.google.common.collect.Iterables; +import java.util.HashSet; +import java.util.Set; +import javax.annotation.Nonnull; import org.sonar.api.batch.fs.InputFile.Type; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.test.CoverageBlock; import org.sonar.api.test.MutableTestCase; import org.sonar.api.test.MutableTestPlan; import org.sonar.api.test.TestCase; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.Constants.TestStatus; import org.sonar.batch.protocol.output.BatchReport; import org.sonar.batch.protocol.output.BatchReport.CoverageDetail; import org.sonar.batch.protocol.output.BatchReport.Test; import org.sonar.batch.protocol.output.BatchReportWriter; -import org.sonar.core.test.TestPlanBuilder; - -import javax.annotation.Nonnull; - -import java.util.HashSet; -import java.util.Set; +import org.sonar.batch.test.DefaultTestable; +import org.sonar.batch.test.TestPlanBuilder; public class TestExecutionAndCoveragePublisher implements ReportPublisherStep { @@ -95,7 +94,7 @@ public class TestExecutionAndCoveragePublisher implements ReportPublisherStep { builder.setTestName(testName); for (CoverageBlock block : testCase.coverageBlocks()) { coveredBuilder.clear(); - coveredBuilder.setFileRef(resourceCache.get(block.testable().component().key()).batchId()); + coveredBuilder.setFileRef(componentCache.get(((DefaultTestable) block.testable()).inputFile().key()).batchId()); for (int line : block.lines()) { coveredBuilder.addCoveredLine(line); } @@ -105,36 +104,36 @@ public class TestExecutionAndCoveragePublisher implements ReportPublisherStep { } } - private final ResourceCache resourceCache; + private final BatchComponentCache componentCache; private final TestPlanBuilder testPlanBuilder; - public TestExecutionAndCoveragePublisher(ResourceCache resourceCache, TestPlanBuilder testPlanBuilder) { - this.resourceCache = resourceCache; + public TestExecutionAndCoveragePublisher(BatchComponentCache resourceCache, TestPlanBuilder testPlanBuilder) { + this.componentCache = resourceCache; this.testPlanBuilder = testPlanBuilder; } @Override public void publish(BatchReportWriter writer) { - for (final BatchResource resource : resourceCache.all()) { - if (!resource.isFile()) { + for (final BatchComponent component : componentCache.all()) { + if (!component.isFile()) { continue; } - DefaultInputFile inputFile = (DefaultInputFile) resource.inputPath(); + DefaultInputFile inputFile = (DefaultInputFile) component.inputPath(); if (inputFile.type() != Type.TEST) { continue; } - final MutableTestPlan testPlan = testPlanBuilder.get(MutableTestPlan.class, inputFile.key()); + final MutableTestPlan testPlan = testPlanBuilder.loadPerspective(MutableTestPlan.class, component); if (testPlan == null || Iterables.isEmpty(testPlan.testCases())) { continue; } final Set testNamesWithCoverage = new HashSet<>(); - writer.writeTests(resource.batchId(), Iterables.transform(testPlan.testCases(), new TestConverter(testNamesWithCoverage))); + writer.writeTests(component.batchId(), Iterables.transform(testPlan.testCases(), new TestConverter(testNamesWithCoverage))); - writer.writeCoverageDetails(resource.batchId(), Iterables.transform(testNamesWithCoverage, new TestCoverageConverter(testPlan))); + writer.writeCoverageDetails(component.batchId(), Iterables.transform(testNamesWithCoverage, new TestCoverageConverter(testPlan))); } } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java index a1c3bbb8202..85e2a54f232 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java @@ -46,7 +46,7 @@ import org.sonar.batch.duplication.DuplicationCache; import org.sonar.batch.events.EventBus; import org.sonar.batch.index.Caches; import org.sonar.batch.index.DefaultIndex; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.index.ResourcePersister; import org.sonar.batch.issue.DefaultProjectIssues; import org.sonar.batch.issue.IssueCache; @@ -75,7 +75,8 @@ import org.sonar.batch.scan.measure.DefaultMetricFinder; import org.sonar.batch.scan.measure.DeprecatedMetricFinder; import org.sonar.batch.scan.measure.MeasureCache; import org.sonar.batch.source.CodeColorizers; -import org.sonar.core.component.ScanGraph; +import org.sonar.batch.test.TestPlanBuilder; +import org.sonar.batch.test.TestableBuilder; import org.sonar.core.issue.IssueUpdater; import org.sonar.core.issue.workflow.FunctionExecutor; import org.sonar.core.issue.workflow.IssueWorkflow; @@ -83,10 +84,6 @@ import org.sonar.core.permission.PermissionFacade; import org.sonar.core.platform.ComponentContainer; import org.sonar.core.resource.DefaultResourcePermissions; import org.sonar.core.technicaldebt.DefaultTechnicalDebtModel; -import org.sonar.core.test.TestPlanBuilder; -import org.sonar.core.test.TestPlanPerspectiveLoader; -import org.sonar.core.test.TestableBuilder; -import org.sonar.core.test.TestablePerspectiveLoader; import org.sonar.core.user.DefaultUserFinder; public class ProjectScanContainer extends ComponentContainer { @@ -154,7 +151,7 @@ public class ProjectScanContainer extends ComponentContainer { DefaultIndex.class, DefaultFileLinesContextFactory.class, Caches.class, - ResourceCache.class, + BatchComponentCache.class, // file system InputPathCache.class, @@ -177,11 +174,8 @@ public class ProjectScanContainer extends ComponentContainer { DeprecatedMetricFinder.class, // tests - TestPlanPerspectiveLoader.class, - TestablePerspectiveLoader.class, TestPlanBuilder.class, TestableBuilder.class, - ScanGraph.create(), // lang Languages.class, diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java index eb0976b7776..f9ff2fb6511 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java @@ -26,7 +26,7 @@ import org.sonar.api.resources.File; import org.sonar.api.resources.Languages; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.index.ResourcePersister; import javax.annotation.Nullable; @@ -43,9 +43,9 @@ public class ComponentIndexer { private final SonarIndex sonarIndex; private final Project module; private final ResourcePersister resourcePersister; - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; - public ComponentIndexer(Project module, Languages languages, SonarIndex sonarIndex, ResourceCache resourceCache, @Nullable ResourcePersister resourcePersister) { + public ComponentIndexer(Project module, Languages languages, SonarIndex sonarIndex, BatchComponentCache resourceCache, @Nullable ResourcePersister resourcePersister) { this.module = module; this.languages = languages; this.sonarIndex = sonarIndex; @@ -53,7 +53,7 @@ public class ComponentIndexer { this.resourcePersister = resourcePersister; } - public ComponentIndexer(Project module, Languages languages, SonarIndex sonarIndex, ResourceCache resourceCache) { + public ComponentIndexer(Project module, Languages languages, SonarIndex sonarIndex, BatchComponentCache resourceCache) { this(module, languages, sonarIndex, resourceCache, null); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputPathCache.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputPathCache.java index 2eacbf5aac4..cbfd8d0c5df 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputPathCache.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputPathCache.java @@ -25,7 +25,7 @@ import org.sonar.api.batch.BatchSide; import org.sonar.api.batch.fs.InputDir; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.InputPath; -import org.sonar.batch.index.BatchResource; +import org.sonar.batch.index.BatchComponent; import javax.annotation.CheckForNull; @@ -131,7 +131,7 @@ public class InputPathCache { } @CheckForNull - public InputPath getInputPath(BatchResource component) { + public InputPath getInputPath(BatchComponent component) { if (component.isFile()) { return getFile(component.parent().parent().resource().getEffectiveKey(), component.resource().getPath()); } else if (component.isDir()) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReport.java index 5604537b15f..c087219e1f2 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReport.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReport.java @@ -23,7 +23,7 @@ import com.google.common.collect.Maps; import org.sonar.api.issue.Issue; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RulePriority; -import org.sonar.batch.index.BatchResource; +import org.sonar.batch.index.BatchComponent; import java.util.ArrayList; import java.util.Date; @@ -37,7 +37,7 @@ public class IssuesReport { private Date date; private boolean noFile; private final ReportSummary summary = new ReportSummary(); - private final Map resourceReportsByResource = Maps.newLinkedHashMap(); + private final Map resourceReportsByResource = Maps.newLinkedHashMap(); public IssuesReport() { } @@ -70,7 +70,7 @@ public class IssuesReport { this.noFile = noFile; } - public Map getResourceReportsByResource() { + public Map getResourceReportsByResource() { return resourceReportsByResource; } @@ -78,23 +78,23 @@ public class IssuesReport { return new ArrayList<>(resourceReportsByResource.values()); } - public List getResourcesWithReport() { + public List getResourcesWithReport() { return new ArrayList<>(resourceReportsByResource.keySet()); } - public void addIssueOnResource(BatchResource resource, Issue issue, Rule rule, RulePriority severity) { + public void addIssueOnResource(BatchComponent resource, Issue issue, Rule rule, RulePriority severity) { addResource(resource); getSummary().addIssue(issue, rule, severity); resourceReportsByResource.get(resource).addIssue(issue, rule, RulePriority.valueOf(issue.severity())); } - public void addResolvedIssueOnResource(BatchResource resource, Issue issue, Rule rule, RulePriority severity) { + public void addResolvedIssueOnResource(BatchComponent resource, Issue issue, Rule rule, RulePriority severity) { addResource(resource); getSummary().addResolvedIssue(issue, rule, severity); resourceReportsByResource.get(resource).addResolvedIssue(issue, rule, RulePriority.valueOf(issue.severity())); } - private void addResource(BatchResource resource) { + private void addResource(BatchComponent resource) { if (!resourceReportsByResource.containsKey(resource)) { resourceReportsByResource.put(resource, new ResourceReport(resource)); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReportBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReportBuilder.java index 4dfcf17d249..72c48f9bb7a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReportBuilder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReportBuilder.java @@ -30,8 +30,8 @@ import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; import org.sonar.api.rules.RulePriority; import org.sonar.batch.DefaultProjectTree; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.issue.IssueCache; import org.sonar.batch.scan.filesystem.InputPathCache; @@ -44,11 +44,11 @@ public class IssuesReportBuilder { private final IssueCache issueCache; private final RuleFinder ruleFinder; - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; private final DefaultProjectTree projectTree; private final InputPathCache inputPathCache; - public IssuesReportBuilder(IssueCache issueCache, RuleFinder ruleFinder, ResourceCache resourceCache, DefaultProjectTree projectTree, InputPathCache inputPathCache) { + public IssuesReportBuilder(IssueCache issueCache, RuleFinder ruleFinder, BatchComponentCache resourceCache, DefaultProjectTree projectTree, InputPathCache inputPathCache) { this.issueCache = issueCache; this.ruleFinder = ruleFinder; this.resourceCache = resourceCache; @@ -72,7 +72,7 @@ public class IssuesReportBuilder { for (Issue issue : issues) { Rule rule = findRule(issue); RulePriority severity = RulePriority.valueOf(issue.severity()); - BatchResource resource = resourceCache.get(issue.componentKey()); + BatchComponent resource = resourceCache.get(issue.componentKey()); if (!validate(issue, rule, resource)) { continue; } @@ -84,7 +84,7 @@ public class IssuesReportBuilder { } } - private boolean validate(Issue issue, Rule rule, BatchResource resource) { + private boolean validate(Issue issue, Rule rule, BatchComponent resource) { if (rule == null) { LOG.warn("Unknow rule for issue {}", issue); return false; diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ResourceReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ResourceReport.java index e48ffc3e40a..4a4329f908d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ResourceReport.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ResourceReport.java @@ -23,7 +23,7 @@ import com.google.common.collect.Maps; import org.sonar.api.issue.Issue; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RulePriority; -import org.sonar.batch.index.BatchResource; +import org.sonar.batch.index.BatchComponent; import java.util.ArrayList; import java.util.Collections; @@ -32,7 +32,7 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; public final class ResourceReport { - private final BatchResource resource; + private final BatchComponent resource; private final IssueVariation total = new IssueVariation(); private final Map ruleReportByRuleKey = Maps.newHashMap(); @@ -42,11 +42,11 @@ public final class ResourceReport { private Map issuesByRule = Maps.newHashMap(); private Map issuesBySeverity = Maps.newHashMap(); - public ResourceReport(BatchResource resource) { + public ResourceReport(BatchComponent resource) { this.resource = resource; } - public BatchResource getResourceNode() { + public BatchComponent getResourceNode() { return resource; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/SourceProvider.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/SourceProvider.java index 049f581fa2b..9ae89557e95 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/SourceProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/SourceProvider.java @@ -26,7 +26,7 @@ import org.slf4j.LoggerFactory; import org.sonar.api.batch.BatchSide; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.InputFile; -import org.sonar.batch.index.BatchResource; +import org.sonar.batch.index.BatchComponent; import org.sonar.batch.scan.filesystem.InputPathCache; import java.io.IOException; @@ -46,7 +46,7 @@ public class SourceProvider { this.fs = fs; } - public List getEscapedSource(BatchResource component) { + public List getEscapedSource(BatchComponent component) { if (!component.isFile()) { // Folder return Collections.emptyList(); diff --git a/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java b/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java index 399d2d3779f..33ec11e25f5 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java @@ -26,8 +26,8 @@ import org.slf4j.LoggerFactory; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.scm.BlameCommand.BlameOutput; import org.sonar.api.batch.scm.BlameLine; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.output.BatchReport; import org.sonar.batch.protocol.output.BatchReport.Changesets.Builder; import org.sonar.batch.protocol.output.BatchReportWriter; @@ -48,13 +48,13 @@ class DefaultBlameOutput implements BlameOutput { private static final Pattern ACCENT_CODES = Pattern.compile("\\p{InCombiningDiacriticalMarks}+"); private final BatchReportWriter writer; - private final ResourceCache componentCache; + private final BatchComponentCache componentCache; private final Set allFilesToBlame = new HashSet<>(); private ProgressReport progressReport; private int count; private int total; - DefaultBlameOutput(BatchReportWriter writer, ResourceCache componentCache, List filesToBlame) { + DefaultBlameOutput(BatchReportWriter writer, BatchComponentCache componentCache, List filesToBlame) { this.writer = writer; this.componentCache = componentCache; this.allFilesToBlame.addAll(filesToBlame); @@ -75,7 +75,7 @@ class DefaultBlameOutput implements BlameOutput { return; } - BatchResource batchComponent = componentCache.get(file); + BatchComponent batchComponent = componentCache.get(file); Builder scmBuilder = BatchReport.Changesets.newBuilder(); scmBuilder.setComponentRef(batchComponent.batchId()); Map changesetsIdByRevision = new HashMap<>(); diff --git a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java b/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java index 24492bbdc78..a74ad87c3e1 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java @@ -29,7 +29,7 @@ import org.sonar.api.batch.fs.InputFile.Status; import org.sonar.api.batch.sensor.Sensor; import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.SensorDescriptor; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.input.FileData; import org.sonar.batch.protocol.input.ProjectRepositories; import org.sonar.batch.report.ReportPublisher; @@ -46,11 +46,11 @@ public final class ScmSensor implements Sensor { private final ScmConfiguration configuration; private final FileSystem fs; private final ProjectRepositories projectReferentials; - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; private final ReportPublisher publishReportJob; public ScmSensor(ProjectDefinition projectDefinition, ScmConfiguration configuration, - ProjectRepositories projectReferentials, FileSystem fs, InputPathCache inputPathCache, ResourceCache resourceCache, + ProjectRepositories projectReferentials, FileSystem fs, InputPathCache inputPathCache, BatchComponentCache resourceCache, ReportPublisher publishReportJob) { this.projectDefinition = projectDefinition; this.configuration = configuration; diff --git a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java b/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java index cf4b285971a..208dc809210 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java +++ b/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java @@ -52,9 +52,9 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.source.Symbol; import org.sonar.api.utils.KeyValueFormat; import org.sonar.batch.duplication.DuplicationCache; -import org.sonar.batch.index.BatchResource; +import org.sonar.batch.index.BatchComponent; import org.sonar.batch.index.DefaultIndex; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.issue.ModuleIssues; import org.sonar.batch.protocol.output.BatchReport; import org.sonar.batch.protocol.output.BatchReport.Range; @@ -76,12 +76,12 @@ public class DefaultSensorStorage implements SensorStorage { private final DefaultIndex sonarIndex; private final CoverageExclusions coverageExclusions; private final DuplicationCache duplicationCache; - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; private final ReportPublisher reportPublisher; public DefaultSensorStorage(MetricFinder metricFinder, Project project, ModuleIssues moduleIssues, Settings settings, FileSystem fs, ActiveRules activeRules, DuplicationCache duplicationCache, DefaultIndex sonarIndex, - CoverageExclusions coverageExclusions, ResourceCache resourceCache, ReportPublisher reportPublisher) { + CoverageExclusions coverageExclusions, BatchComponentCache resourceCache, ReportPublisher reportPublisher) { this.metricFinder = metricFinder; this.project = project; this.moduleIssues = moduleIssues; @@ -178,7 +178,7 @@ public class DefaultSensorStorage implements SensorStorage { } private File getFile(InputFile file) { - BatchResource r = resourceCache.get(file); + BatchComponent r = resourceCache.get(file); if (r == null) { throw new IllegalStateException("Provided input file is not indexed"); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/CodeColorizerSensor.java b/sonar-batch/src/main/java/org/sonar/batch/source/CodeColorizerSensor.java index 7581b44b14d..0d19be3cdea 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/source/CodeColorizerSensor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/source/CodeColorizerSensor.java @@ -25,7 +25,7 @@ import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.sensor.Sensor; import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.SensorDescriptor; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.output.BatchReportReader; import org.sonar.batch.report.ReportPublisher; import org.sonar.colorizer.CodeColorizer; @@ -37,10 +37,10 @@ import org.sonar.colorizer.CodeColorizer; public final class CodeColorizerSensor implements Sensor { private final ReportPublisher reportPublisher; - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; private final CodeColorizers codeColorizers; - public CodeColorizerSensor(ReportPublisher reportPublisher, ResourceCache resourceCache, CodeColorizers codeColorizers) { + public CodeColorizerSensor(ReportPublisher reportPublisher, BatchComponentCache resourceCache, CodeColorizers codeColorizers) { this.reportPublisher = reportPublisher; this.resourceCache = resourceCache; this.codeColorizers = codeColorizers; diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultHighlightable.java b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultHighlightable.java index 741346dd99b..e03531d243e 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultHighlightable.java +++ b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultHighlightable.java @@ -23,9 +23,7 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.sensor.highlighting.TypeOfText; import org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting; import org.sonar.api.batch.sensor.internal.SensorStorage; -import org.sonar.api.component.Component; import org.sonar.api.source.Highlightable; -import org.sonar.batch.deprecated.InputFileComponent; /** * @since 3.6 @@ -47,11 +45,6 @@ public class DefaultHighlightable implements Highlightable { return new DefaultHighlightingBuilder(defaultHighlighting); } - @Override - public Component component() { - return new InputFileComponent(inputFile); - } - private static class DefaultHighlightingBuilder implements HighlightingBuilder { private final DefaultHighlighting defaultHighlighting; diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolizable.java b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolizable.java index 037913f06cd..f65cb609c21 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolizable.java +++ b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolizable.java @@ -21,9 +21,7 @@ package org.sonar.batch.source; import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.component.Component; import org.sonar.api.source.Symbolizable; -import org.sonar.batch.deprecated.InputFileComponent; import org.sonar.batch.sensor.DefaultSensorStorage; public class DefaultSymbolizable implements Symbolizable { @@ -36,11 +34,6 @@ public class DefaultSymbolizable implements Symbolizable { this.sensorStorage = sensorStorage; } - @Override - public Component component() { - return new InputFileComponent(inputFile); - } - @Override public SymbolTableBuilder newSymbolTableBuilder() { return new DefaultSymbolTable.Builder(inputFile); diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/HighlightableBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/source/HighlightableBuilder.java index fa9326a1604..2a1a7d3ac5e 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/source/HighlightableBuilder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/source/HighlightableBuilder.java @@ -19,46 +19,29 @@ */ package org.sonar.batch.source; -import com.google.common.collect.ImmutableSet; +import javax.annotation.CheckForNull; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.sensor.internal.SensorStorage; -import org.sonar.api.component.Component; -import org.sonar.api.resources.Qualifiers; import org.sonar.api.source.Highlightable; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; -import org.sonar.core.component.PerspectiveBuilder; -import org.sonar.core.component.ResourceComponent; - -import javax.annotation.CheckForNull; - -import java.util.Set; +import org.sonar.batch.deprecated.perspectives.PerspectiveBuilder; +import org.sonar.batch.index.BatchComponent; public class HighlightableBuilder extends PerspectiveBuilder { - private static final Set SUPPORTED_QUALIFIERS = ImmutableSet.of(Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE); - private final ResourceCache cache; private final SensorStorage sensorStorage; - public HighlightableBuilder(ResourceCache cache, SensorStorage sensorStorage) { + public HighlightableBuilder(SensorStorage sensorStorage) { super(Highlightable.class); - this.cache = cache; this.sensorStorage = sensorStorage; } @CheckForNull @Override - public Highlightable loadPerspective(Class perspectiveClass, Component component) { - boolean supported = SUPPORTED_QUALIFIERS.contains(component.qualifier()); - if (supported && component instanceof ResourceComponent) { - BatchResource batchComponent = cache.get(component.key()); - if (batchComponent != null) { - InputFile path = (InputFile) batchComponent.inputPath(); - if (path != null) { - return new DefaultHighlightable((DefaultInputFile) path, sensorStorage); - } - } + public Highlightable loadPerspective(Class perspectiveClass, BatchComponent component) { + if (component.isFile()) { + InputFile path = (InputFile) component.inputPath(); + return new DefaultHighlightable((DefaultInputFile) path, sensorStorage); } return null; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/SymbolizableBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/source/SymbolizableBuilder.java index 212c31d87b4..05ab9db0a45 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/source/SymbolizableBuilder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/source/SymbolizableBuilder.java @@ -20,46 +20,29 @@ package org.sonar.batch.source; -import com.google.common.collect.ImmutableSet; +import javax.annotation.CheckForNull; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.component.Component; -import org.sonar.api.resources.Qualifiers; import org.sonar.api.source.Symbolizable; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.deprecated.perspectives.PerspectiveBuilder; +import org.sonar.batch.index.BatchComponent; import org.sonar.batch.sensor.DefaultSensorStorage; -import org.sonar.core.component.PerspectiveBuilder; -import org.sonar.core.component.ResourceComponent; - -import javax.annotation.CheckForNull; - -import java.util.Set; public class SymbolizableBuilder extends PerspectiveBuilder { - private static final Set SUPPORTED_QUALIFIERS = ImmutableSet.of(Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE); - private final ResourceCache cache; private final DefaultSensorStorage sensorStorage; - public SymbolizableBuilder(ResourceCache cache, DefaultSensorStorage sensorStorage) { + public SymbolizableBuilder(DefaultSensorStorage sensorStorage) { super(Symbolizable.class); - this.cache = cache; this.sensorStorage = sensorStorage; } @CheckForNull @Override - public Symbolizable loadPerspective(Class perspectiveClass, Component component) { - boolean supported = SUPPORTED_QUALIFIERS.contains(component.qualifier()); - if (supported && component instanceof ResourceComponent) { - BatchResource batchComponent = cache.get(component.key()); - if (batchComponent != null) { - InputFile path = (InputFile) batchComponent.inputPath(); - if (path != null) { - return new DefaultSymbolizable((DefaultInputFile) path, sensorStorage); - } - } + public Symbolizable loadPerspective(Class perspectiveClass, BatchComponent component) { + if (component.isFile()) { + InputFile path = (InputFile) component.inputPath(); + return new DefaultSymbolizable((DefaultInputFile) path, sensorStorage); } return null; } diff --git a/sonar-core/src/main/java/org/sonar/core/test/DefaultCoverageBlock.java b/sonar-batch/src/main/java/org/sonar/batch/test/DefaultCoverageBlock.java similarity index 68% rename from sonar-core/src/main/java/org/sonar/core/test/DefaultCoverageBlock.java rename to sonar-batch/src/main/java/org/sonar/batch/test/DefaultCoverageBlock.java index d2d10cca958..b65526824f9 100644 --- a/sonar-core/src/main/java/org/sonar/core/test/DefaultCoverageBlock.java +++ b/sonar-batch/src/main/java/org/sonar/batch/test/DefaultCoverageBlock.java @@ -17,30 +17,38 @@ * 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.core.test; +package org.sonar.batch.test; -import com.tinkerpop.blueprints.Direction; +import java.util.List; +import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.test.CoverageBlock; import org.sonar.api.test.TestCase; import org.sonar.api.test.Testable; -import org.sonar.core.graph.BeanEdge; -import java.util.List; +public class DefaultCoverageBlock implements CoverageBlock { -public class DefaultCoverageBlock extends BeanEdge implements CoverageBlock { + private final TestCase testCase; + private final DefaultInputFile testable; + private final List lines; + + public DefaultCoverageBlock(TestCase testCase, DefaultInputFile testable, List lines) { + this.testCase = testCase; + this.testable = testable; + this.lines = lines; + } @Override public TestCase testCase() { - return getVertex(DefaultTestCase.class, Direction.OUT); + return testCase; } @Override public Testable testable() { - return getVertex(DefaultTestable.class, Direction.IN); + return new DefaultTestable(testable); } @Override public List lines() { - return (List) getProperty("lines"); + return lines; } } diff --git a/sonar-core/src/main/java/org/sonar/core/test/DefaultTestCase.java b/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestCase.java similarity index 52% rename from sonar-core/src/main/java/org/sonar/core/test/DefaultTestCase.java rename to sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestCase.java index 3f8c8e86646..6cf1af728da 100644 --- a/sonar-core/src/main/java/org/sonar/core/test/DefaultTestCase.java +++ b/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestCase.java @@ -17,52 +17,52 @@ * 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.core.test; +package org.sonar.batch.test; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import com.tinkerpop.blueprints.Direction; -import com.tinkerpop.blueprints.Edge; -import com.tinkerpop.blueprints.Vertex; +import com.google.common.base.Preconditions; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.Nullable; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.fs.InputFile.Type; +import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.test.CoverageBlock; import org.sonar.api.test.MutableTestCase; import org.sonar.api.test.TestPlan; import org.sonar.api.test.Testable; import org.sonar.api.test.exception.CoverageAlreadyExistsException; import org.sonar.api.test.exception.IllegalDurationException; -import org.sonar.core.graph.BeanVertex; -import org.sonar.core.graph.GraphUtil; - -import javax.annotation.Nullable; -import java.util.List; +public class DefaultTestCase implements MutableTestCase { -public class DefaultTestCase extends BeanVertex implements MutableTestCase { + private final DefaultTestPlan testPlan; + private String type; + private Long durationInMs; + private Status status; + private String name; + private String message; + private String stackTrace; + private Map coverageBlocksByTestedFile = new LinkedHashMap<>(); - private static final String DURATION = "duration"; - private static final String TYPE = "type"; - private static final String STATUS = "status"; - private static final String NAME = "name"; - private static final String MESSAGE = "message"; - private static final String STACK_TRACE = "stackTrace"; - private static final String COVERS = "covers"; - private static final String LINES = "lines"; - private static final String TESTCASE = "testcase"; + public DefaultTestCase(DefaultTestPlan testPlan) { + this.testPlan = testPlan; + } @Override public String type() { - return (String) getProperty(TYPE); + return type; } @Override public MutableTestCase setType(@Nullable String s) { - setProperty(TYPE, s); + this.type = s; return this; } @Override public Long durationInMs() { - return (Long) getProperty(DURATION); + return durationInMs; } @Override @@ -70,100 +70,95 @@ public class DefaultTestCase extends BeanVertex implements MutableTestCase { if (l != null && l < 0) { throw new IllegalDurationException("Test duration must be positive (got: " + l + ")"); } - setProperty(DURATION, l); + this.durationInMs = l; return this; } @Override public Status status() { - return Status.of((String) getProperty(STATUS)); + return status; } @Override public MutableTestCase setStatus(@Nullable Status s) { - setProperty(STATUS, s == null ? null : s.name()); + this.status = s; + ; return this; } @Override public String name() { - return (String) getProperty(NAME); + return name; } public MutableTestCase setName(String s) { - setProperty(NAME, s); + this.name = s; return this; } @Override public String message() { - return (String) getProperty(MESSAGE); + return message; } @Override public MutableTestCase setMessage(String s) { - setProperty(MESSAGE, s); + this.message = s; return this; } @Override public String stackTrace() { - return (String) getProperty(STACK_TRACE); + return stackTrace; } @Override public MutableTestCase setStackTrace(String s) { - setProperty(STACK_TRACE, s); + this.stackTrace = s; return this; } @Override public MutableTestCase setCoverageBlock(Testable testable, List lines) { - if (coverageBlock(testable) != null) { - throw new CoverageAlreadyExistsException("The link between " + name() + " and " + testable.component().key() + " already exists"); + DefaultInputFile coveredFile = ((DefaultTestable) testable).inputFile(); + return setCoverageBlock(coveredFile, lines); + } + + @Override + public MutableTestCase setCoverageBlock(InputFile mainFile, List lines) { + Preconditions.checkArgument(mainFile.type() == Type.MAIN, "Test file can only cover a main file"); + DefaultInputFile coveredFile = (DefaultInputFile) mainFile; + if (coverageBlocksByTestedFile.containsKey(coveredFile)) { + throw new CoverageAlreadyExistsException("The link between " + name() + " and " + coveredFile.key() + " already exists"); } - beanGraph().getUnderlyingGraph().addEdge(null, element(), ((BeanVertex) testable).element(), COVERS).setProperty(LINES, lines); + coverageBlocksByTestedFile.put(coveredFile, new DefaultCoverageBlock(this, coveredFile, lines)); return this; } @Override public TestPlan testPlan() { - Vertex plan = GraphUtil.singleAdjacent(element(), Direction.IN, TESTCASE); - return beanGraph().wrap(plan, DefaultTestPlan.class); + return testPlan; } @Override public boolean doesCover() { - return edgeCovers().iterator().hasNext(); + return !coverageBlocksByTestedFile.isEmpty(); } @Override public int countCoveredLines() { - int result = 0; - for (Edge edge : edgeCovers()) { - List lines = (List) edge.getProperty(LINES); - result = result + lines.size(); - } - return result; + throw new UnsupportedOperationException("Not supported since SQ 5.2"); } @Override public Iterable coverageBlocks() { - return (Iterable) getEdges(DefaultCoverageBlock.class, Direction.OUT, COVERS); + return coverageBlocksByTestedFile.values(); } @Override public CoverageBlock coverageBlock(final Testable testable) { - return Iterables.find(getEdges(DefaultCoverageBlock.class, Direction.OUT, COVERS), new Predicate() { - @Override - public boolean apply(CoverageBlock input) { - return input.testable().component().key().equals(testable.component().key()); - } - }, null); - } - - private Iterable edgeCovers() { - return element().query().labels(COVERS).direction(Direction.OUT).edges(); + DefaultInputFile coveredFile = ((DefaultTestable) testable).inputFile(); + return coverageBlocksByTestedFile.get(coveredFile); } } diff --git a/sonar-core/src/main/java/org/sonar/core/test/DefaultTestPlan.java b/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestPlan.java similarity index 66% rename from sonar-core/src/main/java/org/sonar/core/test/DefaultTestPlan.java rename to sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestPlan.java index b701dc29d8e..79adc923c24 100644 --- a/sonar-core/src/main/java/org/sonar/core/test/DefaultTestPlan.java +++ b/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestPlan.java @@ -17,30 +17,17 @@ * 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.core.test; +package org.sonar.batch.test; import com.google.common.collect.Lists; -import com.tinkerpop.blueprints.Direction; -import com.tinkerpop.blueprints.Vertex; -import org.sonar.api.component.Component; +import java.util.ArrayList; +import java.util.List; +import javax.annotation.CheckForNull; import org.sonar.api.test.MutableTestCase; import org.sonar.api.test.MutableTestPlan; -import org.sonar.core.component.ComponentVertex; -import org.sonar.core.graph.BeanVertex; -import org.sonar.core.graph.GraphUtil; -import javax.annotation.CheckForNull; - -import java.util.List; - -public class DefaultTestPlan extends BeanVertex implements MutableTestPlan { - private static final String TESTCASE = "testcase"; - - @Override - public Component component() { - Vertex component = GraphUtil.singleAdjacent(element(), Direction.IN, "testplan"); - return beanGraph().wrap(component, ComponentVertex.class); - } +public class DefaultTestPlan implements MutableTestPlan { + private List testCases = new ArrayList<>(); @Override @CheckForNull @@ -56,14 +43,15 @@ public class DefaultTestPlan extends BeanVertex implements MutableTestPlan { @Override public MutableTestCase addTestCase(String name) { - DefaultTestCase testCase = beanGraph().createAdjacentVertex(this, DefaultTestCase.class, TESTCASE); + DefaultTestCase testCase = new DefaultTestCase(this); testCase.setName(name); + testCases.add(testCase); return testCase; } @Override public Iterable testCases() { - return (Iterable) getVertices(DefaultTestCase.class, Direction.OUT, TESTCASE); + return testCases; } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestable.java b/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestable.java new file mode 100644 index 00000000000..6bfe739b196 --- /dev/null +++ b/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestable.java @@ -0,0 +1,86 @@ +/* + * 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.test; + +import java.util.List; +import java.util.Map; +import java.util.SortedSet; +import org.sonar.api.batch.fs.internal.DefaultInputFile; +import org.sonar.api.test.CoverageBlock; +import org.sonar.api.test.MutableTestable; +import org.sonar.api.test.TestCase; + +public class DefaultTestable implements MutableTestable { + + private final DefaultInputFile inputFile; + + public DefaultTestable(DefaultInputFile inputFile) { + this.inputFile = inputFile; + } + + public DefaultInputFile inputFile() { + return inputFile; + } + + @Override + public List testCases() { + throw unsupported(); + } + + @Override + public TestCase testCaseByName(final String name) { + throw unsupported(); + } + + @Override + public int countTestCasesOfLine(Integer line) { + throw unsupported(); + } + + @Override + public Map testCasesByLines() { + throw unsupported(); + } + + @Override + public List testCasesOfLine(int line) { + throw unsupported(); + } + + @Override + public SortedSet testedLines() { + throw unsupported(); + } + + @Override + public CoverageBlock coverageBlock(final TestCase testCase) { + throw unsupported(); + } + + @Override + public Iterable coverageBlocks() { + throw unsupported(); + } + + private UnsupportedOperationException unsupported() { + return new UnsupportedOperationException("No more available since SQ 5.2"); + } + +} diff --git a/sonar-batch/src/main/java/org/sonar/batch/test/TestPlanBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/test/TestPlanBuilder.java new file mode 100644 index 00000000000..296bc8713bb --- /dev/null +++ b/sonar-batch/src/main/java/org/sonar/batch/test/TestPlanBuilder.java @@ -0,0 +1,54 @@ +/* + * 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.test; + +import java.util.HashMap; +import java.util.Map; +import javax.annotation.CheckForNull; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.fs.InputFile.Type; +import org.sonar.api.test.MutableTestPlan; +import org.sonar.batch.deprecated.perspectives.PerspectiveBuilder; +import org.sonar.batch.index.BatchComponent; + +public class TestPlanBuilder extends PerspectiveBuilder { + + private Map testPlanByFile = new HashMap<>(); + + public TestPlanBuilder() { + super(MutableTestPlan.class); + } + + @CheckForNull + @Override + public MutableTestPlan loadPerspective(Class perspectiveClass, BatchComponent component) { + if (component.isFile()) { + InputFile inputFile = (InputFile) component.inputPath(); + if (inputFile.type() == Type.TEST) { + if (!testPlanByFile.containsKey(inputFile)) { + testPlanByFile.put(inputFile, new DefaultTestPlan()); + } + return testPlanByFile.get(inputFile); + } + } + return null; + } + +} diff --git a/sonar-core/src/main/java/org/sonar/core/test/TestablePerspectiveLoader.java b/sonar-batch/src/main/java/org/sonar/batch/test/TestableBuilder.java similarity index 53% rename from sonar-core/src/main/java/org/sonar/core/test/TestablePerspectiveLoader.java rename to sonar-batch/src/main/java/org/sonar/batch/test/TestableBuilder.java index ced3aa5b0de..e1927ecdba6 100644 --- a/sonar-core/src/main/java/org/sonar/core/test/TestablePerspectiveLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/test/TestableBuilder.java @@ -17,22 +17,31 @@ * 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.core.test; +package org.sonar.batch.test; +import javax.annotation.CheckForNull; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.fs.InputFile.Type; +import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.test.MutableTestable; -import org.sonar.core.component.GraphPerspectiveLoader; -import org.sonar.core.graph.BeanVertex; +import org.sonar.batch.deprecated.perspectives.PerspectiveBuilder; +import org.sonar.batch.index.BatchComponent; -public class TestablePerspectiveLoader extends GraphPerspectiveLoader { +public class TestableBuilder extends PerspectiveBuilder { - static final String PERSPECTIVE_KEY = "testable"; - - public TestablePerspectiveLoader() { - super(PERSPECTIVE_KEY, MutableTestable.class); + public TestableBuilder() { + super(MutableTestable.class); } + @CheckForNull @Override - protected Class getBeanClass() { - return DefaultTestable.class; + public MutableTestable loadPerspective(Class perspectiveClass, BatchComponent component) { + if (component.isFile()) { + InputFile inputFile = (InputFile) component.inputPath(); + if (inputFile.type() == Type.MAIN) { + return new DefaultTestable((DefaultInputFile) inputFile); + } + } + return null; } } diff --git a/sonar-core/src/main/java/org/sonar/core/test/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/test/package-info.java similarity index 97% rename from sonar-core/src/main/java/org/sonar/core/test/package-info.java rename to sonar-batch/src/main/java/org/sonar/batch/test/package-info.java index aff214ebbd9..0c5f5e473ee 100644 --- a/sonar-core/src/main/java/org/sonar/core/test/package-info.java +++ b/sonar-batch/src/main/java/org/sonar/batch/test/package-info.java @@ -19,6 +19,6 @@ */ @ParametersAreNonnullByDefault -package org.sonar.core.test; +package org.sonar.batch.test; import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/test/java/org/sonar/batch/cpd/index/IndexFactoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/cpd/index/IndexFactoryTest.java index f4aef8284d4..7028bfcceba 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/cpd/index/IndexFactoryTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/cpd/index/IndexFactoryTest.java @@ -27,7 +27,7 @@ import org.sonar.api.config.Settings; import org.sonar.api.database.DatabaseSession; import org.sonar.api.resources.Project; import org.sonar.batch.bootstrap.DefaultAnalysisMode; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.core.duplication.DuplicationDao; import static org.assertj.core.api.Assertions.assertThat; @@ -48,7 +48,7 @@ public class IndexFactoryTest { project = new Project("foo"); settings = new Settings(); analysisMode = mock(DefaultAnalysisMode.class); - factory = new IndexFactory(analysisMode, settings, mock(DuplicationDao.class), mock(DatabaseSession.class), new ResourceCache()); + factory = new IndexFactory(analysisMode, settings, mock(DuplicationDao.class), mock(DatabaseSession.class), new BatchComponentCache()); logger = mock(Logger.class); } diff --git a/sonar-core/src/test/java/org/sonar/core/component/PerspectiveBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/perspectives/PerspectiveBuilderTest.java similarity index 91% rename from sonar-core/src/test/java/org/sonar/core/component/PerspectiveBuilderTest.java rename to sonar-batch/src/test/java/org/sonar/batch/deprecated/perspectives/PerspectiveBuilderTest.java index d3bb10520d5..917a7339ba7 100644 --- a/sonar-core/src/test/java/org/sonar/core/component/PerspectiveBuilderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/deprecated/perspectives/PerspectiveBuilderTest.java @@ -17,11 +17,11 @@ * 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.core.component; +package org.sonar.batch.deprecated.perspectives; import org.junit.Test; -import org.sonar.api.component.Component; import org.sonar.api.component.Perspective; +import org.sonar.batch.index.BatchComponent; import static org.assertj.core.api.Assertions.assertThat; @@ -30,7 +30,7 @@ public class PerspectiveBuilderTest { public void testGetPerspectiveClass() throws Exception { PerspectiveBuilder builder = new PerspectiveBuilder(FakePerspective.class) { @Override - public FakePerspective loadPerspective(Class perspectiveClass, Component component) { + public FakePerspective loadPerspective(Class perspectiveClass, BatchComponent component) { return null; } }; diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/ResourceCacheTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/BatchComponentCacheTest.java similarity index 92% rename from sonar-batch/src/test/java/org/sonar/batch/index/ResourceCacheTest.java rename to sonar-batch/src/test/java/org/sonar/batch/index/BatchComponentCacheTest.java index 461a9a4d7f1..4262d004d8b 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/ResourceCacheTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/BatchComponentCacheTest.java @@ -26,10 +26,10 @@ import org.sonar.api.resources.Resource; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; -public class ResourceCacheTest { +public class BatchComponentCacheTest { @Test public void should_cache_resource() { - ResourceCache cache = new ResourceCache(); + BatchComponentCache cache = new BatchComponentCache(); String componentKey = "struts:src/org/struts/Action.java"; Resource resource = File.create("org/struts/Action.java").setEffectiveKey(componentKey); cache.add(resource, null); @@ -40,7 +40,7 @@ public class ResourceCacheTest { @Test public void should_fail_if_missing_component_key() { - ResourceCache cache = new ResourceCache(); + BatchComponentCache cache = new BatchComponentCache(); Resource resource = File.create("org/struts/Action.java").setEffectiveKey(null); try { cache.add(resource, null); diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java index bab64fa049b..29cdc0e6f24 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java @@ -68,7 +68,7 @@ public class DefaultIndexTest { ruleFinder = mock(RuleFinder.class); DefaultProjectTree projectTree = mock(DefaultProjectTree.class); - ResourceCache resourceCache = new ResourceCache(); + BatchComponentCache resourceCache = new BatchComponentCache(); index = new DefaultIndex(resourceCache, projectTree, metricFinder, mock(MeasureCache.class)); baseDir = temp.newFolder(); diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java index 4ef7d6173e6..4c83e9da457 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java @@ -19,6 +19,10 @@ */ package org.sonar.batch.index; +import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import javax.persistence.Query; import org.apache.ibatis.session.SqlSession; import org.junit.Before; import org.junit.Rule; @@ -38,16 +42,9 @@ import org.sonar.api.security.ResourcePermissions; import org.sonar.batch.DefaultProjectTree; import org.sonar.batch.scan.measure.MeasureCache; import org.sonar.core.component.ComponentDto; -import org.sonar.core.component.ScanGraph; import org.sonar.core.component.db.ComponentMapper; import org.sonar.jpa.test.AbstractDbUnitTestCase; -import javax.persistence.Query; - -import java.io.IOException; -import java.text.ParseException; -import java.text.SimpleDateFormat; - import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -64,7 +61,7 @@ public class ResourcePersisterTest extends AbstractDbUnitTestCase { public TemporaryFolder temp = new TemporaryFolder(); private Project singleProject, singleCopyProject, multiModuleProject, moduleA, moduleB, moduleB1, existingProject; - private ResourceCache resourceCache; + private BatchComponentCache resourceCache; private ResourcePersister persister; @@ -74,7 +71,7 @@ public class ResourcePersisterTest extends AbstractDbUnitTestCase { @Before public void before() throws ParseException { - resourceCache = new ResourceCache(); + resourceCache = new BatchComponentCache(); SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); singleProject = newProject("foo", "java"); @@ -106,7 +103,7 @@ public class ResourcePersisterTest extends AbstractDbUnitTestCase { projectTree = mock(DefaultProjectTree.class); permissions = mock(ResourcePermissions.class); - persister = new ResourcePersister(getSession(), permissions, resourceCache, mock(ScanGraph.class)); + persister = new ResourcePersister(getSession(), permissions, resourceCache); } @Test diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java index 26d1fccd060..42843ddd8ec 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java @@ -19,14 +19,13 @@ */ package org.sonar.batch.issue; +import java.util.Arrays; +import java.util.List; import org.junit.Test; -import org.sonar.api.component.Component; import org.sonar.api.issue.Issue; import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.resources.Project; - -import java.util.Arrays; -import java.util.List; +import org.sonar.batch.index.BatchComponent; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -37,7 +36,7 @@ public class DefaultIssuableTest { ModuleIssues moduleIssues = mock(ModuleIssues.class); IssueCache cache = mock(IssueCache.class); Project project = mock(Project.class); - Component component = mock(Component.class); + BatchComponent component = mock(BatchComponent.class); @Test public void test_unresolved_issues() throws Exception { diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java index ac390520311..c124a40fc49 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java @@ -21,12 +21,11 @@ package org.sonar.batch.issue; import org.junit.Test; import org.mockito.Mockito; -import org.sonar.api.component.Component; import org.sonar.api.issue.Issuable; import org.sonar.api.resources.File; import org.sonar.api.resources.Project; import org.sonar.batch.DefaultProjectTree; -import org.sonar.core.component.ResourceComponent; +import org.sonar.batch.index.BatchComponent; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -40,22 +39,20 @@ public class IssuableFactoryTest { @Test public void file_should_be_issuable() { IssuableFactory factory = new IssuableFactory(moduleIssues, cache, projectTree); - Component component = new ResourceComponent(File.create("foo/bar.c").setEffectiveKey("foo/bar.c")); + BatchComponent component = new BatchComponent(1, File.create("foo/bar.c").setEffectiveKey("foo/bar.c"), null); Issuable issuable = factory.loadPerspective(Issuable.class, component); assertThat(issuable).isNotNull(); - assertThat(issuable.component()).isSameAs(component); assertThat(issuable.issues()).isEmpty(); } @Test public void project_should_be_issuable() { IssuableFactory factory = new IssuableFactory(moduleIssues, cache, projectTree); - Component component = new ResourceComponent(new Project("Foo").setEffectiveKey("foo")); + BatchComponent component = new BatchComponent(1, new Project("Foo").setEffectiveKey("foo"), null); Issuable issuable = factory.loadPerspective(Issuable.class, component); assertThat(issuable).isNotNull(); - assertThat(issuable.component()).isSameAs(component); assertThat(issuable.issues()).isEmpty(); } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/postjob/DefaultPostJobContextTest.java b/sonar-batch/src/test/java/org/sonar/batch/postjob/DefaultPostJobContextTest.java index 9ca6dd40771..5db240ddeb5 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/postjob/DefaultPostJobContextTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/postjob/DefaultPostJobContextTest.java @@ -28,7 +28,7 @@ import org.sonar.api.batch.rule.Severity; import org.sonar.api.config.Settings; import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.resources.File; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.issue.IssueCache; import java.util.Arrays; @@ -40,7 +40,7 @@ import static org.mockito.Mockito.when; public class DefaultPostJobContextTest { private IssueCache issueCache; - private ResourceCache resourceCache; + private BatchComponentCache resourceCache; private AnalysisMode analysisMode; private DefaultPostJobContext context; private Settings settings; @@ -48,7 +48,7 @@ public class DefaultPostJobContextTest { @Before public void prepare() { issueCache = mock(IssueCache.class); - resourceCache = new ResourceCache(); + resourceCache = new BatchComponentCache(); analysisMode = mock(AnalysisMode.class); settings = new Settings(); context = new DefaultPostJobContext(settings, analysisMode, issueCache, resourceCache); diff --git a/sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateVerifierTest.java b/sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateVerifierTest.java index 759471b4677..12194f753ca 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateVerifierTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateVerifierTest.java @@ -39,7 +39,7 @@ import org.sonar.api.resources.Resource; import org.sonar.api.test.IsMeasure; import org.sonar.api.utils.Duration; import org.sonar.api.utils.Durations; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.core.qualitygate.db.QualityGateConditionDto; import org.sonar.core.timemachine.Periods; @@ -70,7 +70,7 @@ public class QualityGateVerifierTest { Periods periods; I18n i18n; Durations durations; - private ResourceCache resourceCache; + private BatchComponentCache resourceCache; @Before public void before() { @@ -94,7 +94,7 @@ public class QualityGateVerifierTest { project = new Project("foo"); - resourceCache = new ResourceCache(); + resourceCache = new BatchComponentCache(); resourceCache.add(project, null).setSnapshot(snapshot); verifier = new QualityGateVerifier(qualityGate, resourceCache, periods, i18n, durations); diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java index 2d2a97e234d..ead29534e98 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java @@ -32,7 +32,7 @@ import org.sonar.api.resources.Directory; import org.sonar.api.resources.Java; import org.sonar.api.resources.Project; import org.sonar.api.utils.DateUtils; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.Constants.ComponentLinkType; import org.sonar.batch.protocol.Constants.EventCategory; import org.sonar.batch.protocol.output.BatchReport.Component; @@ -54,7 +54,7 @@ public class ComponentsPublisherTest { public TemporaryFolder temp = new TemporaryFolder(); private ProjectReactor reactor; - private ResourceCache resourceCache; + private BatchComponentCache resourceCache; private ComponentsPublisher publisher; private EventCache eventCache; @@ -62,7 +62,7 @@ public class ComponentsPublisherTest { public void prepare() { reactor = new ProjectReactor(ProjectDefinition.create().setKey("foo")); reactor.getRoot().properties().put(CoreProperties.PROJECT_VERSION_PROPERTY, "1.0"); - resourceCache = new ResourceCache(); + resourceCache = new BatchComponentCache(); eventCache = mock(EventCache.class); publisher = new ComponentsPublisher(reactor, resourceCache, eventCache); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java index f799843baba..b8e4b7acfb3 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java @@ -29,7 +29,7 @@ import org.sonar.api.database.model.Snapshot; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Measure; import org.sonar.api.resources.Project; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.output.BatchReport; import org.sonar.batch.protocol.output.BatchReport.Coverage; import org.sonar.batch.protocol.output.BatchReportReader; @@ -60,7 +60,7 @@ public class CoveragePublisherTest { @Before public void prepare() { Project p = new Project("foo").setAnalysisDate(new Date(1234567L)); - ResourceCache resourceCache = new ResourceCache(); + BatchComponentCache resourceCache = new BatchComponentCache(); sampleFile = org.sonar.api.resources.File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php"); resourceCache.add(p, null).setSnapshot(new Snapshot().setId(2)); resourceCache.add(sampleFile, null).setInputPath(new DefaultInputFile("foo", "src/Foo.php").setLines(5)); diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/DuplicationsPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/DuplicationsPublisherTest.java index a3536f2ada1..4c64bd4b2c9 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/DuplicationsPublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/DuplicationsPublisherTest.java @@ -27,7 +27,7 @@ import org.sonar.api.batch.sensor.duplication.Duplication; import org.sonar.api.batch.sensor.duplication.internal.DefaultDuplication; import org.sonar.api.resources.Project; import org.sonar.batch.duplication.DuplicationCache; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.output.BatchReportReader; import org.sonar.batch.protocol.output.BatchReportWriter; @@ -51,7 +51,7 @@ public class DuplicationsPublisherTest { @Before public void prepare() { - ResourceCache resourceCache = new ResourceCache(); + BatchComponentCache resourceCache = new BatchComponentCache(); Project p = new Project("foo"); resourceCache.add(p, null); org.sonar.api.resources.Resource sampleFile = org.sonar.api.resources.File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php"); diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java index ecfd2377b17..f4299ae0df6 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java @@ -31,7 +31,7 @@ import org.sonar.api.issue.internal.FieldDiffs; import org.sonar.api.resources.Project; import org.sonar.api.rule.RuleKey; import org.sonar.api.utils.Duration; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.issue.IssueCache; import org.sonar.batch.protocol.output.BatchReport.Metadata; import org.sonar.batch.protocol.output.BatchReportReader; @@ -59,7 +59,7 @@ public class IssuesPublisherTest { public void prepare() { ProjectDefinition root = ProjectDefinition.create().setKey("foo"); Project p = new Project("foo").setAnalysisDate(new Date(1234567L)); - ResourceCache resourceCache = new ResourceCache(); + BatchComponentCache resourceCache = new BatchComponentCache(); org.sonar.api.resources.Resource sampleFile = org.sonar.api.resources.File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php"); resourceCache.add(p, null).setSnapshot(new Snapshot().setId(2)); resourceCache.add(sampleFile, null); diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/MeasuresPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/MeasuresPublisherTest.java index bc22f032a19..658cafcc62d 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/MeasuresPublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/MeasuresPublisherTest.java @@ -36,7 +36,7 @@ import org.sonar.api.resources.Resource; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.RulePriority; import org.sonar.api.technicaldebt.batch.Characteristic; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.output.BatchReportReader; import org.sonar.batch.protocol.output.BatchReportWriter; import org.sonar.batch.scan.measure.MeasureCache; @@ -66,7 +66,7 @@ public class MeasuresPublisherTest { @Before public void prepare() { Project p = new Project("foo").setAnalysisDate(new Date(1234567L)); - ResourceCache resourceCache = new ResourceCache(); + BatchComponentCache resourceCache = new BatchComponentCache(); sampleFile = org.sonar.api.resources.File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php"); resourceCache.add(p, null).setSnapshot(new Snapshot().setId(2)); resourceCache.add(sampleFile, null); diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/ReportPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/ReportPublisherTest.java index 4a6e27960d2..dcb0438619f 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/ReportPublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/ReportPublisherTest.java @@ -30,7 +30,7 @@ import org.sonar.api.platform.Server; import org.sonar.api.utils.TempFolder; import org.sonar.batch.bootstrap.DefaultAnalysisMode; import org.sonar.batch.bootstrap.ServerClient; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.jpa.test.AbstractDbUnitTestCase; import static org.mockito.Mockito.mock; @@ -41,7 +41,7 @@ public class ReportPublisherTest extends AbstractDbUnitTestCase { private DefaultAnalysisMode mode; - ResourceCache resourceCache = mock(ResourceCache.class); + BatchComponentCache resourceCache = mock(BatchComponentCache.class); private ProjectReactor reactor; diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java index bfe6067b692..0125a4bb5ba 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java @@ -28,7 +28,7 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.database.model.Snapshot; import org.sonar.api.resources.Project; import org.sonar.api.resources.Qualifiers; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.output.BatchReportWriter; import java.io.File; @@ -54,7 +54,7 @@ public class SourcePublisherTest { @Before public void prepare() throws IOException { Project p = new Project("foo").setAnalysisDate(new Date(1234567L)); - ResourceCache resourceCache = new ResourceCache(); + BatchComponentCache resourceCache = new BatchComponentCache(); sampleFile = org.sonar.api.resources.File.create("src/Foo.php"); sampleFile.setEffectiveKey("foo:src/Foo.php"); resourceCache.add(p, null).setSnapshot(new Snapshot().setId(2)); diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java index b5b8732d5f9..df55eddc1f7 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java @@ -35,8 +35,8 @@ import org.sonar.api.resources.Languages; import org.sonar.api.resources.Project; import org.sonar.api.resources.Qualifiers; import org.sonar.api.resources.Resource; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; +import org.sonar.batch.index.BatchComponentCache; import java.io.File; import java.io.IOException; @@ -100,8 +100,8 @@ public class ComponentIndexerTest { } private ComponentIndexer createIndexer(Languages languages) { - ResourceCache resourceCache = mock(ResourceCache.class); - when(resourceCache.get(any(Resource.class))).thenReturn(new BatchResource(1, org.sonar.api.resources.File.create("foo.php"), null)); + BatchComponentCache resourceCache = mock(BatchComponentCache.class); + when(resourceCache.get(any(Resource.class))).thenReturn(new BatchComponent(1, org.sonar.api.resources.File.create("foo.php"), null)); return new ComponentIndexer(project, languages, sonarIndex, resourceCache); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java b/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java index e3135e79a34..b03d9baf3bd 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java @@ -46,7 +46,7 @@ import org.sonar.api.resources.Resource; import org.sonar.api.rule.RuleKey; import org.sonar.batch.duplication.DuplicationCache; import org.sonar.batch.index.DefaultIndex; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.issue.ModuleIssues; import org.sonar.batch.report.ReportPublisher; import org.sonar.batch.sensor.coverage.CoverageExclusions; @@ -74,7 +74,7 @@ public class DefaultSensorStorageTest { private Project project; private DefaultIndex sonarIndex; - private ResourceCache resourceCache; + private BatchComponentCache resourceCache; @Before public void prepare() throws Exception { @@ -89,7 +89,7 @@ public class DefaultSensorStorageTest { sonarIndex = mock(DefaultIndex.class); CoverageExclusions coverageExclusions = mock(CoverageExclusions.class); when(coverageExclusions.accept(any(Resource.class), any(Measure.class))).thenReturn(true); - resourceCache = new ResourceCache(); + resourceCache = new BatchComponentCache(); sensorStorage = new DefaultSensorStorage(metricFinder, project, moduleIssues, settings, fs, activeRules, mock(DuplicationCache.class), sonarIndex, coverageExclusions, resourceCache, mock(ReportPublisher.class)); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java index e98f3bad906..3d05b7eb3ed 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java @@ -20,42 +20,34 @@ package org.sonar.batch.source; import org.junit.Test; -import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.sensor.internal.SensorStorage; -import org.sonar.api.component.Component; import org.sonar.api.resources.File; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; import org.sonar.api.source.Highlightable; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; -import org.sonar.core.component.ResourceComponent; +import org.sonar.batch.index.BatchComponent; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; public class HighlightableBuilderTest { @Test public void should_load_default_perspective() { Resource file = File.create("foo.c").setEffectiveKey("myproject:path/to/foo.c"); - Component component = new ResourceComponent(file); + BatchComponent component = new BatchComponent(1, file, null); - ResourceCache resourceCache = mock(ResourceCache.class); - when(resourceCache.get(file.getEffectiveKey())).thenReturn(new BatchResource(1, file, null).setInputPath(new DefaultInputFile("myproject", "path/to/foo.c"))); - HighlightableBuilder builder = new HighlightableBuilder(resourceCache, mock(SensorStorage.class)); + HighlightableBuilder builder = new HighlightableBuilder(mock(SensorStorage.class)); Highlightable perspective = builder.loadPerspective(Highlightable.class, component); assertThat(perspective).isNotNull().isInstanceOf(DefaultHighlightable.class); - assertThat(perspective.component().key()).isEqualTo(component.key()); } @Test public void project_should_not_be_highlightable() { - Component component = new ResourceComponent(new Project("struts").setEffectiveKey("org.struts")); + BatchComponent component = new BatchComponent(1, new Project("struts").setEffectiveKey("org.struts"), null); - HighlightableBuilder builder = new HighlightableBuilder(mock(ResourceCache.class), mock(SensorStorage.class)); + HighlightableBuilder builder = new HighlightableBuilder(mock(SensorStorage.class)); Highlightable perspective = builder.loadPerspective(Highlightable.class, component); assertThat(perspective).isNull(); diff --git a/sonar-batch/src/test/java/org/sonar/batch/source/SymbolizableBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/source/SymbolizableBuilderTest.java index 8a1d3cbe580..9b29c6ff3c3 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/source/SymbolizableBuilderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/source/SymbolizableBuilderTest.java @@ -21,44 +21,35 @@ package org.sonar.batch.source; import org.junit.Test; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.component.Component; import org.sonar.api.component.Perspective; import org.sonar.api.resources.File; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; import org.sonar.api.source.Symbolizable; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; import org.sonar.batch.sensor.DefaultSensorStorage; -import org.sonar.core.component.ResourceComponent; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; public class SymbolizableBuilderTest { @Test public void should_load_perspective() { Resource file = File.create("foo.c").setEffectiveKey("myproject:path/to/foo.c"); - Component component = new ResourceComponent(file); + BatchComponent component = new BatchComponent(1, file, null); - ResourceCache resourceCache = mock(ResourceCache.class); - when(resourceCache.get(file.getEffectiveKey())).thenReturn(new BatchResource(1, file, null).setInputPath(new DefaultInputFile("myproject", "path/to/foo.c"))); - - SymbolizableBuilder perspectiveBuilder = new SymbolizableBuilder(resourceCache, mock(DefaultSensorStorage.class)); + SymbolizableBuilder perspectiveBuilder = new SymbolizableBuilder(mock(DefaultSensorStorage.class)); Perspective perspective = perspectiveBuilder.loadPerspective(Symbolizable.class, component); assertThat(perspective).isInstanceOf(Symbolizable.class); - assertThat(perspective.component().key()).isEqualTo(component.key()); } @Test public void project_should_not_be_highlightable() { - Component component = new ResourceComponent(new Project("struts").setEffectiveKey("org.struts")); + BatchComponent component = new BatchComponent(1, new Project("struts").setEffectiveKey("org.struts"), null); - SymbolizableBuilder builder = new SymbolizableBuilder(mock(ResourceCache.class), mock(DefaultSensorStorage.class)); + SymbolizableBuilder builder = new SymbolizableBuilder(mock(DefaultSensorStorage.class)); Perspective perspective = builder.loadPerspective(Symbolizable.class, component); assertThat(perspective).isNull(); diff --git a/sonar-core/pom.xml b/sonar-core/pom.xml index cb59be1290b..4a2b1b40f90 100644 --- a/sonar-core/pom.xml +++ b/sonar-core/pom.xml @@ -86,28 +86,6 @@ com.googlecode.json-simple json-simple - - com.tinkerpop.blueprints - blueprints-core - - - org.codehaus.jackson - jackson-core-asl - - - org.codehaus.jackson - jackson-mapper-asl - - - org.codehaus.jettison - jettison - - - colt - colt - - - org.codehaus.sonar sonar-graph diff --git a/sonar-core/src/main/java/org/sonar/core/component/ComponentQuery.java b/sonar-core/src/main/java/org/sonar/core/component/ComponentQuery.java deleted file mode 100644 index 53ffd32bbd8..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/component/ComponentQuery.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.core.component; - -import com.google.common.collect.Sets; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; - -/** - * @since 4.3 - */ -public class ComponentQuery { - - private Collection ids; - - private Collection qualifiers; - - private ComponentQuery() { - this.ids = Sets.newHashSet(); - this.qualifiers = Sets.newHashSet(); - } - - public static ComponentQuery create() { - return new ComponentQuery(); - } - - public Collection ids() { - return Collections.unmodifiableCollection(ids); - } - - public ComponentQuery addIds(Long... ids) { - this.ids.addAll(Arrays.asList(ids)); - return this; - } - - public Collection qualifiers() { - return Collections.unmodifiableCollection(qualifiers); - } - - public ComponentQuery addQualifiers(String... qualifiers) { - this.qualifiers.addAll(Arrays.asList(qualifiers)); - return this; - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/component/ComponentVertex.java b/sonar-core/src/main/java/org/sonar/core/component/ComponentVertex.java deleted file mode 100644 index 6be36ff6e65..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/component/ComponentVertex.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.core.component; - -import org.sonar.api.component.Component; -import org.sonar.core.graph.BeanVertex; - -public class ComponentVertex extends BeanVertex implements Component { - - @Override - public String key() { - return (String) getProperty("key"); - } - - @Override - public String path() { - return (String) getProperty("path"); - } - - @Override - public String name() { - return (String) getProperty("name"); - } - - @Override - public String longName() { - return (String) getProperty("longName"); - } - - @Override - public String qualifier() { - return (String) getProperty("qualifier"); - } - - void copyFrom(Component component) { - setProperty("key", component.key()); - setProperty("path", component.path()); - setProperty("name", component.name()); - setProperty("longName", component.longName()); - setProperty("qualifier", component.qualifier()); - } - - @Override - public String toString() { - return key(); - } -} 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 deleted file mode 100644 index 8e0f64e3c57..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/component/GraphPerspectiveBuilder.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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.core.component; - -import org.sonar.api.component.Component; -import org.sonar.api.component.Perspective; -import org.sonar.core.graph.EdgePath; - -public abstract class GraphPerspectiveBuilder extends PerspectiveBuilder { - - protected final ScanGraph graph; - protected final EdgePath path; - protected final GraphPerspectiveLoader perspectiveLoader; - - protected GraphPerspectiveBuilder(ScanGraph graph, Class perspectiveClass, EdgePath path, - GraphPerspectiveLoader perspectiveLoader) { - super(perspectiveClass); - this.graph = graph; - this.path = path; - this.perspectiveLoader = perspectiveLoader; - } - - public T create(ComponentVertex component) { - return (T) component.beanGraph().createAdjacentVertex(component, perspectiveLoader.getBeanClass(), - perspectiveLoader.getPerspectiveKey()); - } - - public EdgePath path() { - return path; - } - - public GraphPerspectiveLoader getPerspectiveLoader() { - return perspectiveLoader; - } - - @Override - public T loadPerspective(Class perspectiveClass, Component component) { - ComponentVertex vertex; - if (component instanceof ComponentVertex) { - vertex = (ComponentVertex) component; - } else { - vertex = graph.getComponent(component.key()); - } - - if (vertex != null) { - T perspective = perspectiveLoader.load(vertex); - if (perspective == null) { - perspective = create(vertex); - } - return perspective; - } - return null; - } - - public T get(Class perspectiveClass, String componentKey) { - ComponentVertex vertex = graph.getComponent(componentKey); - if (vertex != null) { - T perspective = perspectiveLoader.load(vertex); - if (perspective != null) { - return perspective; - } - } - return null; - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/component/GraphPerspectiveLoader.java b/sonar-core/src/main/java/org/sonar/core/component/GraphPerspectiveLoader.java deleted file mode 100644 index 968ba28530a..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/component/GraphPerspectiveLoader.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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.core.component; - -import com.tinkerpop.blueprints.Direction; -import com.tinkerpop.blueprints.Vertex; -import org.sonar.api.component.Perspective; -import org.sonar.core.graph.BeanVertex; -import org.sonar.core.graph.GraphUtil; - -public abstract class GraphPerspectiveLoader { - - protected final String perspectiveKey; - protected final Class perspectiveClass; - - protected GraphPerspectiveLoader(String perspectiveKey, Class perspectiveClass) { - this.perspectiveKey = perspectiveKey; - this.perspectiveClass = perspectiveClass; - } - - 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 String getPerspectiveKey() { - return perspectiveKey; - } - - protected Class getPerspectiveClass() { - return perspectiveClass; - } - - protected abstract Class getBeanClass(); -} diff --git a/sonar-core/src/main/java/org/sonar/core/component/ResourceComponent.java b/sonar-core/src/main/java/org/sonar/core/component/ResourceComponent.java deleted file mode 100644 index 9680a0fc301..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/component/ResourceComponent.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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.core.component; - -import com.google.common.base.Strings; -import org.sonar.api.component.Component; -import org.sonar.api.resources.Resource; - -public class ResourceComponent implements Component { - private String key; - private String path; - private String name; - private String longName; - private String qualifier; - private String scope; - - public ResourceComponent(Resource resource) { - this.key = resource.getEffectiveKey(); - this.path = resource.getPath(); - if (Strings.isNullOrEmpty(key)) { - throw new IllegalArgumentException("Missing component key"); - } - this.name = resource.getName(); - this.longName = resource.getLongName(); - this.qualifier = resource.getQualifier(); - this.scope = resource.getScope(); - } - - @Override - public String key() { - return key; - } - - @Override - public String path() { - return path; - } - - @Override - public String name() { - return name; - } - - @Override - public String longName() { - return longName; - } - - @Override - public String qualifier() { - return qualifier; - } - - public String scope() { - return scope; - } - - @Override - public String toString() { - return key; - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/component/ScanGraph.java b/sonar-core/src/main/java/org/sonar/core/component/ScanGraph.java deleted file mode 100644 index d7c62c58389..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/component/ScanGraph.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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.core.component; - -import com.tinkerpop.blueprints.Direction; -import com.tinkerpop.blueprints.Graph; -import com.tinkerpop.blueprints.Vertex; -import com.tinkerpop.blueprints.impls.tg.TinkerGraph; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.component.Component; -import org.sonar.api.resources.Resource; -import org.sonar.core.graph.BeanGraph; -import org.sonar.core.graph.BeanIterable; -import org.sonar.core.graph.GraphUtil; - -@BatchSide -public class ScanGraph extends BeanGraph { - - private static final String COMPONENT = "component"; - private final Vertex componentsRoot; - - private ScanGraph(Graph graph) { - super(graph); - componentsRoot = graph.addVertex(null); - componentsRoot.setProperty("root", "components"); - } - - public static ScanGraph create() { - TinkerGraph graph = new TinkerGraph(); - graph.createKeyIndex("key", Vertex.class); - return new ScanGraph(graph); - } - - public ComponentVertex wrapComponent(Vertex vertex) { - return wrap(vertex, ComponentVertex.class); - } - - public ComponentVertex getComponent(String key) { - Vertex vertex = GraphUtil.single(getUnderlyingGraph().getVertices("key", key)); - return vertex != null ? wrapComponent(vertex) : null; - } - - public ComponentVertex addComponent(Resource resource) { - return addComponent(new ResourceComponent(resource)); - } - - public void completeComponent(String key, long resourceId, long snapshotId) { - ComponentVertex component = getComponent(key); - component.setProperty("sid", snapshotId); - component.setProperty("rid", resourceId); - } - - public Iterable getComponents() { - Iterable componentVertices = componentsRoot.getVertices(Direction.OUT, COMPONENT); - return new BeanIterable<>(this, ComponentVertex.class, componentVertices); - } - - public ComponentVertex addComponent(Component component) { - Vertex vertex = getUnderlyingGraph().addVertex(null); - getUnderlyingGraph().addEdge(null, componentsRoot, vertex, COMPONENT); - ComponentVertex wrapper = wrap(vertex, ComponentVertex.class); - wrapper.copyFrom(component); - return wrapper; - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/component/SnapshotGraph.java b/sonar-core/src/main/java/org/sonar/core/component/SnapshotGraph.java deleted file mode 100644 index 9d9fcc7bcc1..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/component/SnapshotGraph.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.core.component; - -import com.tinkerpop.blueprints.Graph; -import com.tinkerpop.blueprints.Vertex; -import org.sonar.core.graph.BeanGraph; - -class SnapshotGraph extends BeanGraph { - private final Vertex componentRoot; - - SnapshotGraph(Graph graph, String rootVertexId) { - super(graph); - componentRoot = graph.getVertex(rootVertexId); - } - - Vertex getComponentRoot() { - return componentRoot; - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/graph/BeanEdge.java b/sonar-core/src/main/java/org/sonar/core/graph/BeanEdge.java deleted file mode 100644 index daa1be339e1..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/graph/BeanEdge.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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.core.graph; - -import com.tinkerpop.blueprints.Direction; -import com.tinkerpop.blueprints.Edge; - -public abstract class BeanEdge extends BeanElement { - - protected final T getVertex(Class vertexClass, Direction direction) { - return beanGraph().wrap(element().getVertex(direction), vertexClass); - } - -} diff --git a/sonar-core/src/main/java/org/sonar/core/graph/BeanElement.java b/sonar-core/src/main/java/org/sonar/core/graph/BeanElement.java deleted file mode 100644 index 6a5ecbaec9d..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/graph/BeanElement.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.core.graph; - -import com.tinkerpop.blueprints.Element; - -import javax.annotation.Nullable; - -import java.util.Set; - -public abstract class BeanElement> { - private T element; - private BeanGraph graph; - - public T element() { - return element; - } - - void setElement(T element) { - this.element = element; - } - - public BeanGraph beanGraph() { - return graph; - } - - void setBeanGraph(BeanGraph graph) { - this.graph = graph; - } - - protected final Object getProperty(String key) { - return element.getProperty(key); - } - - protected final Set getPropertyKeys() { - return element.getPropertyKeys(); - } - - public final C setProperty(String key, @Nullable Object value) { - if (value != null) { - element.setProperty(key, value); - } else { - element.removeProperty(key); - } - return (C) this; - } - - protected final Object removeProperty(String key) { - return element.removeProperty(key); - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/graph/BeanElements.java b/sonar-core/src/main/java/org/sonar/core/graph/BeanElements.java deleted file mode 100644 index c1e6420c794..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/graph/BeanElements.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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.core.graph; - -import com.google.common.collect.MapMaker; -import com.tinkerpop.blueprints.Element; - -import java.util.Map; - -class BeanElements { - - private final Map cache; - - BeanElements() { - cache = new MapMaker().weakValues().makeMap(); - } - - T wrap(Element element, Class beanClass, BeanGraph graph) { - ElementKey key = new ElementKey(element, beanClass); - T bean = (T) cache.get(key); - if (bean == null) { - try { - bean = (T) key.beanClass.newInstance(); - bean.setElement(key.element); - bean.setBeanGraph(graph); - cache.put(key, bean); - } catch (InstantiationException e) { - throw new IllegalStateException("Class has no default constructor: " + beanClass.getName(), e); - } catch (IllegalAccessException e) { - throw new IllegalStateException("Can not access to default constructor: " + beanClass.getName(), e); - } - } - return bean; - } - - void clear() { - cache.clear(); - } - - private static class ElementKey { - Element element; - Class beanClass; - - ElementKey(Element element, Class beanClass) { - this.element = element; - this.beanClass = beanClass; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null) { - return false; - } - ElementKey that = (ElementKey) o; - if (!element.equals(that.element)) { - return false; - } - return beanClass.equals(that.beanClass); - } - - @Override - public int hashCode() { - int result = element.hashCode(); - result = 31 * result + beanClass.hashCode(); - return result; - } - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/graph/BeanGraph.java b/sonar-core/src/main/java/org/sonar/core/graph/BeanGraph.java deleted file mode 100644 index f543b01f432..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/graph/BeanGraph.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.core.graph; - -import com.tinkerpop.blueprints.Edge; -import com.tinkerpop.blueprints.Element; -import com.tinkerpop.blueprints.Graph; -import com.tinkerpop.blueprints.Vertex; -import com.tinkerpop.blueprints.impls.tg.TinkerGraph; -import com.tinkerpop.blueprints.util.ElementHelper; - -import javax.annotation.Nullable; - -public class BeanGraph { - private final Graph graph; - private final BeanElements beans; - - public BeanGraph(Graph graph) { - this.graph = graph; - this.beans = new BeanElements(); - } - - public static BeanGraph createInMemory() { - return new BeanGraph(new TinkerGraph()); - } - - public final T wrap(@Nullable Element element, Class beanClass) { - return element != null ? beans.wrap(element, beanClass, this) : null; - } - - public final T createAdjacentVertex(BeanVertex from, Class beanClass, String edgeLabel, String... edgeProperties) { - T to = createVertex(beanClass); - Edge edge = graph.addEdge(null, from.element(), to.element(), edgeLabel); - ElementHelper.setProperties(edge, edgeProperties); - return to; - } - - public final T createVertex(Class beanClass) { - Vertex vertex = graph.addVertex(null); - return beans.wrap(vertex, beanClass, this); - } - - public final Graph getUnderlyingGraph() { - return graph; - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/graph/BeanIterable.java b/sonar-core/src/main/java/org/sonar/core/graph/BeanIterable.java deleted file mode 100644 index c7c1d99f473..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/graph/BeanIterable.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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.core.graph; - -import com.tinkerpop.blueprints.Element; - -import java.util.Iterator; - -public class BeanIterable implements Iterable { - - private final Iterable iterable; - private final BeanGraph graph; - private final Class beanClass; - - public BeanIterable(BeanGraph graph, Class beanClass, Iterable iterable) { - this.iterable = iterable; - this.graph = graph; - this.beanClass = beanClass; - } - - @Override - public Iterator iterator() { - return new Iterator() { - private final Iterator iterator = iterable.iterator(); - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean hasNext() { - return this.iterator.hasNext(); - } - - @Override - public T next() { - return graph.wrap(this.iterator.next(), beanClass); - } - }; - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/graph/BeanVertex.java b/sonar-core/src/main/java/org/sonar/core/graph/BeanVertex.java deleted file mode 100644 index d1f544b144b..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/graph/BeanVertex.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.core.graph; - -import com.tinkerpop.blueprints.Direction; -import com.tinkerpop.blueprints.Vertex; - -public abstract class BeanVertex extends BeanElement { - - protected final Iterable getEdges(Class edgeClass, Direction direction, String... labels) { - return new BeanIterable<>(beanGraph(), edgeClass, element().getEdges(direction, labels)); - } - - protected final Iterable getVertices(Class vertexClass, Direction direction, String... labels) { - return new BeanIterable<>(beanGraph(), vertexClass, element().getVertices(direction, labels)); - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/graph/EdgePath.java b/sonar-core/src/main/java/org/sonar/core/graph/EdgePath.java deleted file mode 100644 index f99c3b0fbe0..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/graph/EdgePath.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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.core.graph; - -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; -import com.tinkerpop.blueprints.Direction; - -import java.util.List; - -public class EdgePath { - private List elements; - - private EdgePath(Object[] elements) { - Preconditions.checkArgument(elements != null && elements.length > 0, "Elements can't be null or empty"); - Preconditions.checkArgument(elements.length % 2 == 0, "Odd number of elements (" + elements.length + ")"); - - for (int i = 0; i < elements.length; i++) { - if (i % 2 == 0) { - Preconditions.checkArgument(elements[i] instanceof Direction, - "Element " + i + " must be a " + Direction.class.getName() + " (got " + elements[i].getClass().getName() + ")"); - } else { - Preconditions.checkArgument(elements[i] instanceof String, - "Element " + i + " must be a String" + " (got " + elements[i].getClass().getName() + ")"); - } - } - - this.elements = ImmutableList.copyOf(elements); - } - - public List getElements() { - return elements; - } - - public static EdgePath create(Object... elements) { - return new EdgePath(elements); - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/graph/GraphUtil.java b/sonar-core/src/main/java/org/sonar/core/graph/GraphUtil.java deleted file mode 100644 index b868a8578ee..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/graph/GraphUtil.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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.core.graph; - -import com.google.common.base.Joiner; -import com.tinkerpop.blueprints.Direction; -import com.tinkerpop.blueprints.Element; -import com.tinkerpop.blueprints.Vertex; - -import javax.annotation.CheckForNull; - -import java.util.Iterator; - -public class GraphUtil { - - private GraphUtil() { - } - - /** - * Get adjacent vertex. It assumes that there are only 0 or 1 results. - * - * @throws MultipleElementsException if there are more than 1 adjacent vertices with the given criteria. - */ - @CheckForNull - public static Vertex singleAdjacent(Vertex from, Direction direction, String... labels) { - Iterator vertices = from.getVertices(direction, labels).iterator(); - Vertex result = null; - if (vertices.hasNext()) { - result = vertices.next(); - if (vertices.hasNext()) { - throw new MultipleElementsException(String.format("More than one vertex is adjacent to: %s, direction: %s, labels: %s", from, direction, Joiner.on(",").join(labels))); - } - } - return result; - } - - public static T single(Iterable iterable) { - Iterator iterator = iterable.iterator(); - T result = null; - if (iterator.hasNext()) { - result = iterator.next(); - if (iterator.hasNext()) { - throw new MultipleElementsException("More than one element"); - } - } - return result; - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/graph/MultipleElementsException.java b/sonar-core/src/main/java/org/sonar/core/graph/MultipleElementsException.java deleted file mode 100644 index 44bfb4ec32e..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/graph/MultipleElementsException.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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.core.graph; - -public class MultipleElementsException extends RuntimeException { - public MultipleElementsException(String message) { - super(message); - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/graph/graphson/ElementFactory.java b/sonar-core/src/main/java/org/sonar/core/graph/graphson/ElementFactory.java deleted file mode 100644 index 0eee36ea399..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/graph/graphson/ElementFactory.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.core.graph.graphson; - -import com.tinkerpop.blueprints.Edge; -import com.tinkerpop.blueprints.Graph; -import com.tinkerpop.blueprints.Vertex; - -/** - * The standard factory used for most graph element creation. It uses an actual - * Graph implementation to construct vertices and edges - * - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -class ElementFactory { - - private final Graph graph; - - ElementFactory(Graph g) { - this.graph = g; - } - - Edge createEdge(Object id, Vertex out, Vertex in, String label) { - return this.graph.addEdge(id, out, in, label); - } - - Vertex createVertex(Object id) { - return this.graph.addVertex(id); - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/graph/graphson/ElementPropertyConfig.java b/sonar-core/src/main/java/org/sonar/core/graph/graphson/ElementPropertyConfig.java deleted file mode 100644 index 7dfc3ea0049..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/graph/graphson/ElementPropertyConfig.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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.core.graph.graphson; - -import java.util.Set; - -/** - * Configure how the GraphSON utility treats edge and vertex properties. - * - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -class ElementPropertyConfig { - - enum ElementPropertiesRule { - INCLUDE, EXCLUDE - } - - private final Set vertexPropertyKeys; - private final Set edgePropertyKeys; - private final ElementPropertiesRule vertexPropertiesRule; - private final ElementPropertiesRule edgePropertiesRule; - - /** - * A configuration that includes all properties of vertices and edges. - */ - static ElementPropertyConfig AllProperties = new ElementPropertyConfig(null, null, - ElementPropertiesRule.INCLUDE, ElementPropertiesRule.INCLUDE); - - ElementPropertyConfig(Set vertexPropertyKeys, Set edgePropertyKeys, - ElementPropertiesRule vertexPropertiesRule, ElementPropertiesRule edgePropertiesRule) { - this.vertexPropertiesRule = vertexPropertiesRule; - this.vertexPropertyKeys = vertexPropertyKeys; - this.edgePropertiesRule = edgePropertiesRule; - this.edgePropertyKeys = edgePropertyKeys; - } - - /** - * Construct a configuration that includes the specified properties from both vertices and edges. - */ - static ElementPropertyConfig includeProperties(Set vertexPropertyKeys, - Set edgePropertyKeys) { - return new ElementPropertyConfig(vertexPropertyKeys, edgePropertyKeys, ElementPropertiesRule.INCLUDE, - ElementPropertiesRule.INCLUDE); - } - - /** - * Construct a configuration that excludes the specified properties from both vertices and edges. - */ - static ElementPropertyConfig excludeProperties(Set vertexPropertyKeys, - Set edgePropertyKeys) { - return new ElementPropertyConfig(vertexPropertyKeys, edgePropertyKeys, ElementPropertiesRule.EXCLUDE, - ElementPropertiesRule.EXCLUDE); - } - - Set getVertexPropertyKeys() { - return vertexPropertyKeys; - } - - Set getEdgePropertyKeys() { - return edgePropertyKeys; - } - - ElementPropertiesRule getVertexPropertiesRule() { - return vertexPropertiesRule; - } - - ElementPropertiesRule getEdgePropertiesRule() { - return edgePropertiesRule; - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonException.java b/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonException.java deleted file mode 100644 index cfc80c1c7d6..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonException.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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.core.graph.graphson; - -public class GraphsonException extends RuntimeException { - public GraphsonException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonMode.java b/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonMode.java deleted file mode 100644 index 0e93351a6d8..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonMode.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.core.graph.graphson; - -/** - * Modes of operation of the GraphSONUtility. - * - * @author Stephen Mallette - */ -public enum GraphsonMode { - /** - * COMPACT constructs GraphSON on the assumption that all property keys - * are fair game for exclusion including _type, _inV, _outV, _label and _id. - * It is possible to write GraphSON that cannot be read back into Graph, - * if some or all of these keys are excluded. - */ - COMPACT, - - /** - * NORMAL includes the _type field and JSON data typing. - */ - NORMAL, - - /** - * EXTENDED includes the _type field and explicit data typing. - */ - EXTENDED -} diff --git a/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonReader.java b/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonReader.java deleted file mode 100644 index c681aaaf7a0..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonReader.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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.core.graph.graphson; - -import com.tinkerpop.blueprints.Graph; -import com.tinkerpop.blueprints.Vertex; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; - -import java.io.Reader; -import java.util.Set; - -/** - * Greatly inspired by the Blueprints implementation based on Jettison/Jackson - */ -public class GraphsonReader { - - public Graph read(Reader jsonInput, Graph toGraph) { - return read(jsonInput, toGraph, null, null); - } - - /** - * Input the JSON stream data into the graph. - * More control over how data is streamed is provided by this method. - * - * @param toGraph the graph to populate with the JSON data - * @param input an InputStream of JSON data - * @param bufferSize the amount of elements to hold in memory before committing a transactions (only valid for TransactionalGraphs) - */ - public Graph read(Reader input, Graph toGraph, Set edgePropertyKeys, Set vertexPropertyKeys) { - try { - JSONParser parser = new JSONParser(); - JSONObject json = (JSONObject) parser.parse(input); - - ElementFactory elementFactory = new ElementFactory(toGraph); - GraphsonMode mode = GraphsonMode.valueOf(json.get(GraphsonTokens.MODE).toString()); - GraphsonUtil graphson = new GraphsonUtil(mode, elementFactory, vertexPropertyKeys, edgePropertyKeys); - - JSONArray vertices = (JSONArray) json.get(GraphsonTokens.VERTICES); - for (Object vertice : vertices) { - graphson.vertexFromJson((JSONObject) vertice); - } - - JSONArray edges = (JSONArray) json.get(GraphsonTokens.EDGES); - for (Object edgeObject : edges) { - JSONObject edge = (JSONObject) edgeObject; - Vertex inV = toGraph.getVertex(edge.get(GraphsonTokens._IN_V)); - Vertex outV = toGraph.getVertex(edge.get(GraphsonTokens._OUT_V)); - graphson.edgeFromJson(edge, outV, inV); - } - toGraph.shutdown(); - return toGraph; - } catch (Exception e) { - throw new GraphsonException("Unable to parse GraphSON", e); - } - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonTokens.java b/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonTokens.java deleted file mode 100644 index 052da0c23d8..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonTokens.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.core.graph.graphson; - -/** - * @author Marko A. Rodriguez (http://markorodriguez.com) - * @author Stephen Mallette - */ -class GraphsonTokens { - private GraphsonTokens() { - } - - static final String VERTEX = "vertex"; - static final String EDGE = "edge"; - static final String _ID = "_id"; - static final String _LABEL = "_label"; - static final String _TYPE = "_type"; - static final String _OUT_V = "_outV"; - static final String _IN_V = "_inV"; - static final String VALUE = "value"; - static final String TYPE = "type"; - static final String TYPE_LIST = "list"; - static final String TYPE_STRING = "string"; - static final String TYPE_DOUBLE = "double"; - static final String TYPE_INTEGER = "integer"; - static final String TYPE_FLOAT = "float"; - static final String TYPE_MAP = "map"; - static final String TYPE_BOOLEAN = "boolean"; - static final String TYPE_LONG = "long"; - static final String TYPE_UNKNOWN = "unknown"; - - static final String VERTICES = "vertices"; - static final String EDGES = "edges"; - static final String MODE = "mode"; -} diff --git a/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonUtil.java b/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonUtil.java deleted file mode 100644 index a837bbf9ac0..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonUtil.java +++ /dev/null @@ -1,673 +0,0 @@ -/* - * 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.core.graph.graphson; - -import com.tinkerpop.blueprints.Direction; -import com.tinkerpop.blueprints.Edge; -import com.tinkerpop.blueprints.Element; -import com.tinkerpop.blueprints.Vertex; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; -import org.json.simple.parser.ParseException; - -import javax.annotation.Nullable; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import static org.sonar.core.graph.graphson.ElementPropertyConfig.ElementPropertiesRule; - -/** - * Helps write individual graph elements to TinkerPop JSON format known as GraphSON. - * - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -class GraphsonUtil { - - private final GraphsonMode mode; - private final Set vertexPropertyKeys; - private final Set edgePropertyKeys; - private final ElementFactory factory; - private final boolean hasEmbeddedTypes; - private final ElementPropertiesRule vertexPropertiesRule; - private final ElementPropertiesRule edgePropertiesRule; - private final boolean includeReservedVertexId; - private final boolean includeReservedEdgeId; - private final boolean includeReservedVertexType; - private final boolean includeReservedEdgeType; - private final boolean includeReservedEdgeLabel; - private final boolean includeReservedEdgeOutV; - private final boolean includeReservedEdgeInV; - private JSONParser parser = new JSONParser(); - - /** - * A GraphSONUtiltiy that includes all properties of vertices and edges. - */ - GraphsonUtil(GraphsonMode mode, ElementFactory factory) { - this(mode, factory, ElementPropertyConfig.AllProperties); - } - - /** - * A GraphSONUtility that includes the specified properties. - */ - GraphsonUtil(GraphsonMode mode, ElementFactory factory, - Set vertexPropertyKeys, Set edgePropertyKeys) { - this(mode, factory, ElementPropertyConfig.includeProperties(vertexPropertyKeys, edgePropertyKeys)); - } - - GraphsonUtil(GraphsonMode mode, ElementFactory factory, - ElementPropertyConfig config) { - this.vertexPropertyKeys = config.getVertexPropertyKeys(); - this.edgePropertyKeys = config.getEdgePropertyKeys(); - this.vertexPropertiesRule = config.getVertexPropertiesRule(); - this.edgePropertiesRule = config.getEdgePropertiesRule(); - - this.mode = mode; - this.factory = factory; - this.hasEmbeddedTypes = mode == GraphsonMode.EXTENDED; - - this.includeReservedVertexId = includeReservedKey(mode, GraphsonTokens._ID, vertexPropertyKeys, this.vertexPropertiesRule); - this.includeReservedEdgeId = includeReservedKey(mode, GraphsonTokens._ID, edgePropertyKeys, this.edgePropertiesRule); - this.includeReservedVertexType = includeReservedKey(mode, GraphsonTokens._TYPE, vertexPropertyKeys, this.vertexPropertiesRule); - this.includeReservedEdgeType = includeReservedKey(mode, GraphsonTokens._TYPE, edgePropertyKeys, this.edgePropertiesRule); - this.includeReservedEdgeLabel = includeReservedKey(mode, GraphsonTokens._LABEL, edgePropertyKeys, this.edgePropertiesRule); - this.includeReservedEdgeOutV = includeReservedKey(mode, GraphsonTokens._OUT_V, edgePropertyKeys, this.edgePropertiesRule); - this.includeReservedEdgeInV = includeReservedKey(mode, GraphsonTokens._IN_V, edgePropertyKeys, this.edgePropertiesRule); - } - - /** - * Creates a JSONObject from a graph element. - * - * @param element the graph element to convert to JSON. - * @param propertyKeys The property keys at the root of the element to serialize. If null, then all keys are serialized. - * @param mode the type of GraphSON to be generated. - */ - static JSONObject jsonFromElement(Element element, @Nullable Set propertyKeys, GraphsonMode mode) { - GraphsonUtil graphson = element instanceof Edge ? new GraphsonUtil(mode, null, null, propertyKeys) - : new GraphsonUtil(mode, null, propertyKeys, null); - return graphson.jsonFromElement(element); - } - - /** - * Reads an individual Vertex from JSON. The vertex must match the accepted GraphSON format. - * - * @param json a single vertex in GraphSON format as JSONObject - * @param factory the factory responsible for constructing graph elements - * @param mode the mode of the GraphSON - * @param propertyKeys a list of keys to include on reading of element properties - */ - static Vertex vertexFromJson(JSONObject json, ElementFactory factory, GraphsonMode mode, - Set propertyKeys) throws IOException { - GraphsonUtil graphson = new GraphsonUtil(mode, factory, propertyKeys, null); - return graphson.vertexFromJson(json); - } - - /** - * Reads an individual Vertex from JSON. The vertex must match the accepted GraphSON format. - * - * @param json a single vertex in GraphSON format as a String. - * @param factory the factory responsible for constructing graph elements - * @param mode the mode of the GraphSON - * @param propertyKeys a list of keys to include on reading of element properties - */ - static Vertex vertexFromJson(String json, ElementFactory factory, GraphsonMode mode, - Set propertyKeys) throws ParseException { - GraphsonUtil graphson = new GraphsonUtil(mode, factory, propertyKeys, null); - return graphson.vertexFromJson(json); - } - - /** - * Reads an individual Vertex from JSON. The vertex must match the accepted GraphSON format. - * - * @param json a single vertex in GraphSON format as an InputStream. - * @param factory the factory responsible for constructing graph elements - * @param mode the mode of the GraphSON - * @param propertyKeys a list of keys to include on reading of element properties - */ - static Vertex vertexFromJson(InputStream json, ElementFactory factory, GraphsonMode mode, - Set propertyKeys) throws IOException, ParseException { - GraphsonUtil graphson = new GraphsonUtil(mode, factory, propertyKeys, null); - return graphson.vertexFromJson(json); - } - - private static boolean includeReservedKey(GraphsonMode mode, String key, - Set propertyKeys, - ElementPropertiesRule rule) { - // the key is always included in modes other than compact. if it is compact, then validate that the - // key is in the property key list - return mode != GraphsonMode.COMPACT || includeKey(key, propertyKeys, rule); - } - - private static boolean includeKey(String key, Set propertyKeys, - ElementPropertiesRule rule) { - if (propertyKeys == null) { - // when null always include the key and shortcut this piece - return true; - } - - // default the key situation. if it's included then it should be explicitly defined in the - // property keys list to be included or the reverse otherwise - boolean keySituation = rule == ElementPropertiesRule.INCLUDE; - - if (rule == ElementPropertiesRule.INCLUDE) { - keySituation = propertyKeys.contains(key); - } else if (rule == ElementPropertiesRule.EXCLUDE) { - keySituation = !propertyKeys.contains(key); - } - return keySituation; - } - - /** - * Reads an individual Edge from JSON. The edge must match the accepted GraphSON format. - * - * @param json a single edge in GraphSON format as a String - * @param factory the factory responsible for constructing graph elements - * @param mode the mode of the GraphSON - * @param propertyKeys a list of keys to include when reading of element properties - */ - static Edge edgeFromJson(String json, Vertex out, Vertex in, - ElementFactory factory, GraphsonMode mode, - Set propertyKeys) throws IOException, ParseException { - GraphsonUtil graphson = new GraphsonUtil(mode, factory, null, propertyKeys); - return graphson.edgeFromJson(json, out, in); - } - - /** - * Reads an individual Edge from JSON. The edge must match the accepted GraphSON format. - * - * @param json a single edge in GraphSON format as an InputStream - * @param factory the factory responsible for constructing graph elements - * @param mode the mode of the GraphSON - * @param propertyKeys a list of keys to include when reading of element properties - */ - static Edge edgeFromJson(InputStream json, Vertex out, Vertex in, - ElementFactory factory, GraphsonMode mode, - Set propertyKeys) throws IOException, ParseException { - GraphsonUtil graphson = new GraphsonUtil(mode, factory, null, propertyKeys); - return graphson.edgeFromJson(json, out, in); - } - - /** - * Reads an individual Edge from JSON. The edge must match the accepted GraphSON format. - * - * @param json a single edge in GraphSON format as a JSONObject - * @param factory the factory responsible for constructing graph elements - * @param mode the mode of the GraphSON - * @param propertyKeys a list of keys to include when reading of element properties - */ - static Edge edgeFromJson(JSONObject json, Vertex out, Vertex in, - ElementFactory factory, GraphsonMode mode, - Set propertyKeys) throws IOException { - GraphsonUtil graphson = new GraphsonUtil(mode, factory, null, propertyKeys); - return graphson.edgeFromJson(json, out, in); - } - - static Map readProperties(JSONObject node, boolean ignoreReservedKeys, boolean hasEmbeddedTypes) { - Map map = new HashMap<>(); - - for (Object objKey : node.keySet()) { - String key = (String) objKey; - Object value = node.get(key); - - if (!ignoreReservedKeys || !isReservedKey(key)) { - map.put(key, readProperty(value, hasEmbeddedTypes)); - } - } - - return map; - } - - private static boolean isReservedKey(String key) { - return key.equals(GraphsonTokens._ID) || key.equals(GraphsonTokens._TYPE) || key.equals(GraphsonTokens._LABEL) - || key.equals(GraphsonTokens._OUT_V) || key.equals(GraphsonTokens._IN_V); - } - - private static JSONArray createJSONList(List list, Set propertyKeys, boolean showTypes) { - JSONArray jsonList = new JSONArray(); - for (Object item : list) { - if (item instanceof Element) { - jsonList.add(jsonFromElement((Element) item, propertyKeys, - showTypes ? GraphsonMode.EXTENDED : GraphsonMode.NORMAL)); - } else if (item instanceof List) { - jsonList.add(createJSONList((List) item, propertyKeys, showTypes)); - } else if (item instanceof Map) { - jsonList.add(createJSONMap((Map) item, propertyKeys, showTypes)); - } else if (item != null && item.getClass().isArray()) { - jsonList.add(createJSONList(convertArrayToList(item), propertyKeys, showTypes)); - } else if (item instanceof Set) { - throw new UnsupportedOperationException("Set property is not supported"); - } else { - addObject(jsonList, item); - } - } - return jsonList; - } - - // - private static JSONObject createJSONMap(Map map, Set propertyKeys, boolean showTypes) { - JSONObject jsonMap = new JSONObject(); - for (Map.Entry entry : map.entrySet()) { - Object value = entry.getValue(); - if (value != null) { - if (value instanceof List) { - value = createJSONList((List) value, propertyKeys, showTypes); - } else if (value instanceof Map) { - value = createJSONMap((Map) value, propertyKeys, showTypes); - } else if (value instanceof Element) { - value = jsonFromElement((Element) value, propertyKeys, - showTypes ? GraphsonMode.EXTENDED : GraphsonMode.NORMAL); - } else if (value.getClass().isArray()) { - value = createJSONList(convertArrayToList(value), propertyKeys, showTypes); - } - } - - putObject(jsonMap, entry.getKey().toString(), getValue(value, showTypes)); - } - return jsonMap; - - } - - private static Object readProperty(Object node, boolean hasEmbeddedTypes) { - Object propertyValue; - - if (hasEmbeddedTypes) { - JSONObject json = (JSONObject) node; - if (json.get(GraphsonTokens.TYPE).equals(GraphsonTokens.TYPE_UNKNOWN)) { - propertyValue = null; - } else if (json.get(GraphsonTokens.TYPE).equals(GraphsonTokens.TYPE_BOOLEAN)) { - propertyValue = json.get(GraphsonTokens.VALUE); - } else if (json.get(GraphsonTokens.TYPE).equals(GraphsonTokens.TYPE_FLOAT)) { - propertyValue = ((Double) json.get(GraphsonTokens.VALUE)).floatValue(); - } else if (json.get(GraphsonTokens.TYPE).equals(GraphsonTokens.TYPE_DOUBLE)) { - propertyValue = json.get(GraphsonTokens.VALUE); - } else if (json.get(GraphsonTokens.TYPE).equals(GraphsonTokens.TYPE_INTEGER)) { - propertyValue = ((Long) json.get(GraphsonTokens.VALUE)).intValue(); - } else if (json.get(GraphsonTokens.TYPE).equals(GraphsonTokens.TYPE_LONG)) { - propertyValue = json.get(GraphsonTokens.VALUE); - } else if (json.get(GraphsonTokens.TYPE).equals(GraphsonTokens.TYPE_STRING)) { - propertyValue = json.get(GraphsonTokens.VALUE); - } else if (json.get(GraphsonTokens.TYPE).equals(GraphsonTokens.TYPE_LIST)) { - propertyValue = readProperties(((JSONArray) json.get(GraphsonTokens.VALUE)).iterator(), hasEmbeddedTypes); - } else if (json.get(GraphsonTokens.TYPE).equals(GraphsonTokens.TYPE_MAP)) { - propertyValue = readProperties((JSONObject) json.get(GraphsonTokens.VALUE), false, hasEmbeddedTypes); - } else { - propertyValue = node.toString(); - } - } else { - if (node == null) { - propertyValue = null; - } else if (node instanceof Boolean) { - propertyValue = node; - } else if (node instanceof Double) { - propertyValue = node; - } else if (node instanceof Integer) { - propertyValue = node; - } else if (node instanceof Long) { - propertyValue = node; - } else if (node instanceof String) { - propertyValue = node; - } else if (node instanceof JSONArray) { - propertyValue = readProperties(((JSONArray) node).iterator(), hasEmbeddedTypes); - } else if (node instanceof JSONObject) { - propertyValue = readProperties((JSONObject) node, false, hasEmbeddedTypes); - } else { - propertyValue = node; - } - } - - return propertyValue; - } - - private static void putObject(JSONObject jsonMap, String key, Object value) { - if (value == null) { - jsonMap.put(key, null); - } else if (value instanceof Boolean) { - jsonMap.put(key, value); - } else if (value instanceof Long) { - jsonMap.put(key, value); - } else if (value instanceof Integer) { - jsonMap.put(key, value); - } else if (value instanceof Float) { - jsonMap.put(key, value); - } else if (value instanceof Double) { - jsonMap.put(key, value); - } else if (value instanceof String) { - jsonMap.put(key, value); - } else if (value instanceof JSONObject) { - jsonMap.put(key, value); - } else if (value instanceof JSONArray) { - jsonMap.put(key, value); - } else { - jsonMap.put(key, value.toString()); - } - } - - private static List readProperties(Iterator listOfNodes, boolean hasEmbeddedTypes) { - List array = new ArrayList(); - - while (listOfNodes.hasNext()) { - array.add(readProperty(listOfNodes.next(), hasEmbeddedTypes)); - } - - return array; - } - - private static void addObject(JSONArray jsonList, Object value) { - if (value == null) { - jsonList.add(null); - } else if (value instanceof Boolean) { - jsonList.add(value); - } else if (value instanceof Long) { - jsonList.add(value); - } else if (value instanceof Integer) { - jsonList.add(value); - } else if (value instanceof Float) { - jsonList.add(value); - } else if (value instanceof Double) { - jsonList.add(value); - } else if (value instanceof String) { - jsonList.add(value); - } else if (value instanceof JSONObject) { - jsonList.add(value); - } else if (value instanceof JSONArray) { - jsonList.add(value); - } else { - jsonList.add(value.toString()); - } - } - - private static Map createPropertyMap(Element element, Set propertyKeys, ElementPropertiesRule rule) { - Map map = new HashMap<>(); - - if (propertyKeys == null) { - for (String key : element.getPropertyKeys()) { - map.put(key, element.getProperty(key)); - } - } else { - if (rule == ElementPropertiesRule.INCLUDE) { - for (String key : propertyKeys) { - Object valToPutInMap = element.getProperty(key); - if (valToPutInMap != null) { - map.put(key, valToPutInMap); - } - } - } else { - for (String key : element.getPropertyKeys()) { - if (!propertyKeys.contains(key)) { - map.put(key, element.getProperty(key)); - } - } - } - } - - return map; - } - - private static Object getValue(Object value, boolean includeType) { - - Object returnValue = value; - - // if the includeType is set to true then show the data types of the properties - if (includeType) { - - // type will be one of: map, list, string, long, int, double, float. - // in the event of a complex object it will call a toString and store as a - // string - String type = determineType(value); - - JSONObject valueAndType = new JSONObject(); - valueAndType.put(GraphsonTokens.TYPE, type); - - if (type.equals(GraphsonTokens.TYPE_LIST)) { - - // values of lists must be accumulated as ObjectNode objects under the value key. - // will return as a ArrayNode. called recursively to traverse the entire - // object graph of each item in the array. - JSONArray list = (JSONArray) value; - - // there is a set of values that must be accumulated as an array under a key - JSONArray valueArray = new JSONArray(); - valueAndType.put(GraphsonTokens.VALUE, valueArray); - for (int ix = 0; ix < list.size(); ix++) { - // the value of each item in the array is a node object from an ArrayNode...must - // get the value of it. - addObject(valueArray, getValue(list.get(ix), includeType)); - } - - } else if (type.equals(GraphsonTokens.TYPE_MAP)) { - - // maps are converted to a ObjectNode. called recursively to traverse - // the entire object graph within the map. - JSONObject convertedMap = new JSONObject(); - JSONObject jsonObject = (JSONObject) value; - - Map jsonObjectMap = jsonObject; - for (Map.Entry entry : jsonObjectMap.entrySet()) { - - // no need to getValue() here as this is already a ObjectNode and should have type info - convertedMap.put(entry.getKey(), entry.getValue()); - } - - valueAndType.put(GraphsonTokens.VALUE, convertedMap); - - } else { - - // this must be a primitive value or a complex object. if a complex - // object it will be handled by a call to toString and stored as a - // string value - putObject(valueAndType, GraphsonTokens.VALUE, value); - } - - // this goes back as a JSONObject with data type and value - returnValue = valueAndType; - } - - return returnValue; - } - - private static List convertArrayToList(Object value) { - - // is there seriously no better way to do this...bah! - List list = new ArrayList(); - if (value instanceof int[]) { - int[] arr = (int[]) value; - for (int ix = 0; ix < arr.length; ix++) { - list.add(arr[ix]); - } - } else if (value instanceof double[]) { - double[] arr = (double[]) value; - for (int ix = 0; ix < arr.length; ix++) { - list.add(arr[ix]); - } - } else if (value instanceof float[]) { - float[] arr = (float[]) value; - for (int ix = 0; ix < arr.length; ix++) { - list.add(arr[ix]); - } - } else if (value instanceof long[]) { - long[] arr = (long[]) value; - for (int ix = 0; ix < arr.length; ix++) { - list.add(arr[ix]); - } - } else if (value instanceof boolean[]) { - boolean[] arr = (boolean[]) value; - for (int ix = 0; ix < arr.length; ix++) { - list.add(arr[ix]); - } - } else { - list = Arrays.asList((Object[]) value); - } - - return list; - } - - private static String determineType(Object value) { - String type = GraphsonTokens.TYPE_STRING; - if (value == null) { - type = "unknown"; - } else if (value instanceof Double) { - type = GraphsonTokens.TYPE_DOUBLE; - } else if (value instanceof Float) { - type = GraphsonTokens.TYPE_FLOAT; - } else if (value instanceof Integer) { - type = GraphsonTokens.TYPE_INTEGER; - } else if (value instanceof Long) { - type = GraphsonTokens.TYPE_LONG; - } else if (value instanceof Boolean) { - type = GraphsonTokens.TYPE_BOOLEAN; - } else if (value instanceof JSONArray) { - type = GraphsonTokens.TYPE_LIST; - } else if (value instanceof JSONObject) { - type = GraphsonTokens.TYPE_MAP; - } - - return type; - } - - /** - * Creates a vertex from GraphSON using settings supplied in the constructor. - */ - Vertex vertexFromJson(InputStream json) throws ParseException, IOException { - return this.vertexFromJson((JSONObject) parser.parse(new InputStreamReader(json, StandardCharsets.UTF_8))); - } - - /** - * Creates an edge from GraphSON using settings supplied in the constructor. - */ - Edge edgeFromJson(String json, Vertex out, Vertex in) throws IOException, ParseException { - return this.edgeFromJson((JSONObject) parser.parse(json), out, in); - } - - /** - * Creates an edge from GraphSON using settings supplied in the constructor. - */ - Edge edgeFromJson(InputStream json, Vertex out, Vertex in) throws IOException, ParseException { - return this.edgeFromJson((JSONObject) parser.parse(new InputStreamReader(json, StandardCharsets.UTF_8)), out, in); - } - - /** - * Creates an edge from GraphSON using settings supplied in the constructor. - */ - Edge edgeFromJson(JSONObject json, Vertex out, Vertex in) throws IOException { - Map props = GraphsonUtil.readProperties(json, true, this.hasEmbeddedTypes); - - Object edgeId = json.get(GraphsonTokens._ID); - - Object nodeLabel = json.get(GraphsonTokens._LABEL); - String label = nodeLabel == null ? null : nodeLabel.toString(); - - Edge e = factory.createEdge(edgeId, out, in, label); - - for (Map.Entry entry : props.entrySet()) { - if (includeKey(entry.getKey(), edgePropertyKeys, this.edgePropertiesRule)) { - e.setProperty(entry.getKey(), entry.getValue()); - } - } - - return e; - } - - /** - * Creates a vertex from GraphSON using settings supplied in the constructor. - */ - Vertex vertexFromJson(String json) throws ParseException { - return this.vertexFromJson((JSONObject) parser.parse(json)); - } - - /** - * Creates a vertex from GraphSON using settings supplied in the constructor. - */ - Vertex vertexFromJson(JSONObject json) { - Map props = readProperties(json, true, this.hasEmbeddedTypes); - - Object vertexId = json.get(GraphsonTokens._ID); - Vertex v = factory.createVertex(vertexId); - - for (Map.Entry entry : props.entrySet()) { - if (includeKey(entry.getKey(), vertexPropertyKeys, this.vertexPropertiesRule)) { - v.setProperty(entry.getKey(), entry.getValue()); - } - } - - return v; - } - - /** - * Creates GraphSON for a single graph element. - */ - JSONObject jsonFromElement(Element element) { - boolean isEdge = element instanceof Edge; - boolean showTypes = mode == GraphsonMode.EXTENDED; - Set propertyKeys = isEdge ? this.edgePropertyKeys : this.vertexPropertyKeys; - ElementPropertiesRule elementPropertyConfig = isEdge ? this.edgePropertiesRule : this.vertexPropertiesRule; - - JSONObject jsonElement = createJSONMap(createPropertyMap(element, propertyKeys, elementPropertyConfig), propertyKeys, showTypes); - - if ((isEdge && this.includeReservedEdgeId) || (!isEdge && this.includeReservedVertexId)) { - putObject(jsonElement, GraphsonTokens._ID, element.getId()); - } - - // it's important to keep the order of these straight. check Edge first and then Vertex because there - // are graph implementations that have Edge extend from Vertex - if (element instanceof Edge) { - Edge edge = (Edge) element; - - if (this.includeReservedEdgeId) { - putObject(jsonElement, GraphsonTokens._ID, element.getId()); - } - - if (this.includeReservedEdgeType) { - jsonElement.put(GraphsonTokens._TYPE, GraphsonTokens.EDGE); - } - - if (this.includeReservedEdgeOutV) { - putObject(jsonElement, GraphsonTokens._OUT_V, edge.getVertex(Direction.OUT).getId()); - } - - if (this.includeReservedEdgeInV) { - putObject(jsonElement, GraphsonTokens._IN_V, edge.getVertex(Direction.IN).getId()); - } - - if (this.includeReservedEdgeLabel) { - jsonElement.put(GraphsonTokens._LABEL, edge.getLabel()); - } - } else if (element instanceof Vertex) { - if (this.includeReservedVertexId) { - putObject(jsonElement, GraphsonTokens._ID, element.getId()); - } - - if (this.includeReservedVertexType) { - jsonElement.put(GraphsonTokens._TYPE, GraphsonTokens.VERTEX); - } - } - - return jsonElement; - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonWriter.java b/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonWriter.java deleted file mode 100644 index 90d7b2c84a4..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonWriter.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.core.graph.graphson; - -import com.tinkerpop.blueprints.Edge; -import com.tinkerpop.blueprints.Graph; -import com.tinkerpop.blueprints.Vertex; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; - -import javax.annotation.Nullable; - -import java.io.Writer; -import java.util.Set; - -public class GraphsonWriter { - - public void write(Graph graph, Writer output, GraphsonMode mode) { - write(graph, output, mode, null, null); - } - - /** - * Write the data in a Graph to a JSON OutputStream. - * - * @param output the JSON Writer to write the Graph data to - * @param vertexPropertyKeys the keys of the vertex elements to write to JSON - * @param edgePropertyKeys the keys of the edge elements to write to JSON - * @param mode determines the format of the GraphSON - * @throws java.io.IOException thrown if there is an error generating the JSON data - */ - public void write(Graph graph, Writer output, GraphsonMode mode, @Nullable Set vertexPropertyKeys, @Nullable Set edgePropertyKeys) { - try { - JSONObject root = new JSONObject(); - GraphsonUtil graphson = new GraphsonUtil(mode, null, vertexPropertyKeys, edgePropertyKeys); - - root.put(GraphsonTokens.MODE, mode.toString()); - - JSONArray verticesArray = new JSONArray(); - for (Vertex v : graph.getVertices()) { - verticesArray.add(graphson.jsonFromElement(v)); - } - root.put(GraphsonTokens.VERTICES, verticesArray); - - JSONArray edgesArray = new JSONArray(); - for (Edge e : graph.getEdges()) { - edgesArray.add(graphson.jsonFromElement(e)); - } - root.put(GraphsonTokens.EDGES, edgesArray); - - output.write(root.toString()); - } catch (Exception e) { - throw new GraphsonException("Fail to generate GraphSON", e); - } - } - -} diff --git a/sonar-core/src/main/java/org/sonar/core/graph/package-info.java b/sonar-core/src/main/java/org/sonar/core/graph/package-info.java deleted file mode 100644 index aa8af89a5cf..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/graph/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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. - */ -@ParametersAreNonnullByDefault -package org.sonar.core.graph; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java index d9475203622..c933f606dcb 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java @@ -20,10 +20,10 @@ package org.sonar.core.persistence; +import ch.qos.logback.classic.Level; +import com.google.common.io.Closeables; import java.io.InputStream; - import javax.annotation.Nullable; - import org.apache.ibatis.builder.xml.XMLMapperBuilder; import org.apache.ibatis.logging.LogFactory; import org.apache.ibatis.mapping.Environment; @@ -139,10 +139,6 @@ import org.sonar.core.user.UserGroupMapper; import org.sonar.core.user.UserMapper; import org.sonar.core.user.UserRoleDto; -import ch.qos.logback.classic.Level; - -import com.google.common.io.Closeables; - @BatchSide @ServerSide public class MyBatis { diff --git a/sonar-core/src/main/java/org/sonar/core/test/DefaultTestable.java b/sonar-core/src/main/java/org/sonar/core/test/DefaultTestable.java deleted file mode 100644 index 33e118a6923..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/test/DefaultTestable.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * 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.core.test; - -import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSortedSet; -import com.google.common.collect.Iterables; -import com.tinkerpop.blueprints.Direction; -import com.tinkerpop.blueprints.Edge; -import com.tinkerpop.blueprints.Vertex; -import org.sonar.api.component.Component; -import org.sonar.api.test.CoverageBlock; -import org.sonar.api.test.MutableTestable; -import org.sonar.api.test.TestCase; -import org.sonar.core.component.ComponentVertex; -import org.sonar.core.graph.BeanVertex; -import org.sonar.core.graph.GraphUtil; - -import java.util.List; -import java.util.Map; -import java.util.SortedSet; - -import static com.google.common.collect.Maps.newHashMap; - -public class DefaultTestable extends BeanVertex implements MutableTestable { - - private static final String COVERS = "covers"; - - @Override - public Component component() { - Vertex component = GraphUtil.singleAdjacent(element(), Direction.IN, "testable"); - return beanGraph().wrap(component, ComponentVertex.class); - } - - @Override - public List testCases() { - ImmutableList.Builder cases = ImmutableList.builder(); - for (Edge coversEdge : coverEdges()) { - Vertex testable = coversEdge.getVertex(Direction.OUT); - cases.add(beanGraph().wrap(testable, DefaultTestCase.class)); - } - return cases.build(); - } - - @Override - public TestCase testCaseByName(final String name) { - return Iterables.find(testCases(), new Predicate() { - @Override - public boolean apply(TestCase input) { - return input.name().equals(name); - } - }, null); - } - - @Override - public int countTestCasesOfLine(Integer line) { - int number = 0; - for (Edge edge : coverEdges()) { - if (Iterables.contains(lines(edge), line)) { - number++; - } - } - return number; - } - - @Override - public Map testCasesByLines() { - Map testCasesByLines = newHashMap(); - for (Integer line : testedLines()) { - testCasesByLines.put(line, countTestCasesOfLine(line)); - } - return testCasesByLines; - } - - @Override - public List testCasesOfLine(int line) { - ImmutableList.Builder cases = ImmutableList.builder(); - for (Edge edge : coverEdges()) { - if (lines(edge).contains(line)) { - Vertex vertexTestable = edge.getVertex(Direction.OUT); - DefaultTestCase testCase = beanGraph().wrap(vertexTestable, DefaultTestCase.class); - cases.add(testCase); - } - } - return cases.build(); - } - - @Override - public SortedSet testedLines() { - ImmutableSortedSet.Builder coveredLines = ImmutableSortedSet.naturalOrder(); - for (Edge edge : coverEdges()) { - coveredLines.addAll(lines(edge)); - } - return coveredLines.build(); - } - - @Override - public CoverageBlock coverageBlock(final TestCase testCase) { - return Iterables.find(getEdges(DefaultCoverageBlock.class, Direction.IN, COVERS), new Predicate() { - @Override - public boolean apply(CoverageBlock input) { - return input.testCase().name().equals(testCase.name()); - } - }, null); - } - - @Override - public Iterable coverageBlocks() { - return (Iterable) getEdges(DefaultCoverageBlock.class, Direction.IN, COVERS); - } - - private Iterable coverEdges() { - return element().query().labels(COVERS).direction(Direction.IN).edges(); - } - - private List lines(Edge edge) { - return (List) edge.getProperty("lines"); - } -} 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 deleted file mode 100644 index 2bdbe71ee62..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/test/TestPlanBuilder.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.core.test; - -import com.tinkerpop.blueprints.Direction; -import org.sonar.api.test.MutableTestPlan; -import org.sonar.core.component.GraphPerspectiveBuilder; -import org.sonar.core.component.ScanGraph; -import org.sonar.core.graph.EdgePath; - -public class TestPlanBuilder extends GraphPerspectiveBuilder { - - private static final EdgePath PATH = EdgePath.create( - Direction.OUT, "testplan", - Direction.OUT, "testcase", - Direction.OUT, "covers", - Direction.IN, "testable" - ); - - public TestPlanBuilder(ScanGraph graph, TestPlanPerspectiveLoader perspectiveLoader) { - super(graph, MutableTestPlan.class, PATH, perspectiveLoader); - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/test/TestPlanPerspectiveLoader.java b/sonar-core/src/main/java/org/sonar/core/test/TestPlanPerspectiveLoader.java deleted file mode 100644 index 059946a365a..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/test/TestPlanPerspectiveLoader.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.core.test; - -import org.sonar.api.test.MutableTestPlan; -import org.sonar.core.component.GraphPerspectiveLoader; -import org.sonar.core.graph.BeanVertex; - -public class TestPlanPerspectiveLoader extends GraphPerspectiveLoader { - - static final String PERSPECTIVE_KEY = "testplan"; - - public TestPlanPerspectiveLoader() { - super(PERSPECTIVE_KEY, MutableTestPlan.class); - } - - @Override - protected Class 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 deleted file mode 100644 index 07df06f084a..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/test/TestableBuilder.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.core.test; - -import com.tinkerpop.blueprints.Direction; -import org.sonar.api.test.MutableTestable; -import org.sonar.core.component.GraphPerspectiveBuilder; -import org.sonar.core.component.ScanGraph; -import org.sonar.core.graph.EdgePath; - -public class TestableBuilder extends GraphPerspectiveBuilder { - - private static final EdgePath PATH = EdgePath.create( - Direction.OUT, "testable", - Direction.IN,"covers", - Direction.IN,"testcase", - Direction.IN,"testplan" - ); - - public TestableBuilder(ScanGraph graph, TestablePerspectiveLoader perspectiveLoader) { - super(graph, MutableTestable.class, PATH, perspectiveLoader); - } -} diff --git a/sonar-core/src/test/java/org/sonar/core/component/ComponentVertexTest.java b/sonar-core/src/test/java/org/sonar/core/component/ComponentVertexTest.java deleted file mode 100644 index ac0c157d6a0..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/component/ComponentVertexTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.core.component; - -import com.tinkerpop.blueprints.impls.tg.TinkerGraph; -import org.junit.Test; -import org.sonar.api.component.Component; -import org.sonar.api.component.mock.MockSourceFile; -import org.sonar.api.resources.Qualifiers; -import org.sonar.core.graph.BeanGraph; - -import static org.assertj.core.api.Assertions.assertThat; - -public class ComponentVertexTest { - @Test - public void should_copy() { - BeanGraph beanGraph = new BeanGraph(new TinkerGraph()); - ComponentVertex vertex = beanGraph.createVertex(ComponentVertex.class); - Component file = MockSourceFile.createMain("myproject:org/Foo.java").setName("Foo.java").setQualifier(Qualifiers.FILE) - .setPath("src/org/Foo.java"); - - vertex.copyFrom(file); - - assertThat(vertex.key()).isEqualTo("myproject:org/Foo.java"); - assertThat(vertex.name()).isEqualTo("Foo.java"); - assertThat(vertex.qualifier()).isEqualTo(Qualifiers.FILE); - assertThat(vertex.path()).isEqualTo("src/org/Foo.java"); - } -} diff --git a/sonar-core/src/test/java/org/sonar/core/component/GraphPerspectiveBuilderTest.java b/sonar-core/src/test/java/org/sonar/core/component/GraphPerspectiveBuilderTest.java deleted file mode 100644 index d699dc6a30e..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/component/GraphPerspectiveBuilderTest.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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.core.component; - -import org.junit.Test; -import org.sonar.api.component.Component; -import org.sonar.api.component.MutablePerspective; -import org.sonar.api.component.Perspective; -import org.sonar.api.component.mock.MockSourceFile; -import org.sonar.core.graph.BeanVertex; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class GraphPerspectiveBuilderTest { - - @Test - public void should_return_null_on_null_component() { - - String componentKey = "org.foo.Bar"; - - Component component = mock(Component.class); - when(component.key()).thenReturn(componentKey); - - ScanGraph graph = mock(ScanGraph.class); - when(graph.getComponent(componentKey)).thenReturn(null); - - GraphPerspectiveLoader perspectiveLoader = mock(GraphPerspectiveLoader.class); - - GraphPerspectiveBuilder perspectiveBuilder = - new GraphPerspectiveBuilder(graph, MutablePerspective.class, null, perspectiveLoader) {}; - - Perspective loadedPerspective = perspectiveBuilder.loadPerspective(MutablePerspective.class, component); - - assertThat(loadedPerspective).isNull(); - } - - @Test - public void should_load_perspective() { - - ScanGraph graph = ScanGraph.create(); - MutablePerspective expectedPerspective = mock(MutablePerspective.class); - - ComponentVertex fileComponent = graph.addComponent(MockSourceFile.createMain("org.foo.Bar")); - GraphPerspectiveLoader perspectiveLoader = mock(GraphPerspectiveLoader.class); - when(perspectiveLoader.load(fileComponent)).thenReturn(expectedPerspective); - - GraphPerspectiveBuilder perspectiveBuilder = - new GraphPerspectiveBuilder(graph, MutablePerspective.class, null, perspectiveLoader) {}; - - Perspective loadedPerspective = perspectiveBuilder.loadPerspective(MutablePerspective.class, fileComponent); - - assertThat(loadedPerspective).isEqualTo(expectedPerspective); - } - - @Test - public void should_create_perspective_when_loaded_one_is_null() { - - String perspectiveKey = "perspectiveKey"; - - ScanGraph graph = ScanGraph.create(); - ComponentVertex fileComponent = graph.addComponent(MockSourceFile.createMain("org.foo.Bar")); - - GraphPerspectiveLoader perspectiveLoader = - new GraphPerspectiveLoader(perspectiveKey, DefaultMutablePerspective.class) { - - @Override - public DefaultMutablePerspective load(ComponentVertex component) { - return null; - } - - @Override - protected Class getBeanClass() { - return DefaultMutablePerspective.class; - } - }; - - GraphPerspectiveBuilder perspectiveBuilder = - new GraphPerspectiveBuilder(graph, MutablePerspective.class, null, perspectiveLoader) {}; - - Perspective loadedPerspective = perspectiveBuilder.loadPerspective(MutablePerspective.class, fileComponent); - - assertThat(loadedPerspective).isNotNull(); - assertThat(loadedPerspective).isInstanceOf(DefaultMutablePerspective.class); - } - - public static class DefaultMutablePerspective extends BeanVertex implements MutablePerspective { - - @Override - public Component component() { - return null; - } - } -} diff --git a/sonar-core/src/test/java/org/sonar/core/component/ResourceComponentTest.java b/sonar-core/src/test/java/org/sonar/core/component/ResourceComponentTest.java deleted file mode 100644 index f8723d8730f..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/component/ResourceComponentTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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.core.component; - -import org.junit.Before; -import org.junit.Test; -import org.sonar.api.resources.File; -import org.sonar.api.resources.Resource; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.fail; - -public class ResourceComponentTest { - - private Resource file; - - @Before - public void prepare() { - file = File.create("foo.c").setEffectiveKey("myproject:path/to/foo.c"); - file.setKey("path/to/foo.c"); - } - - @Test - public void should_use_effective_key() { - ResourceComponent component = new ResourceComponent(file); - assertThat(component.key()).isEqualTo("myproject:path/to/foo.c"); - } - - @Test - public void effective_key_should_be_set() { - try { - File file = File.create("foo.c"); - new ResourceComponent(file); - fail(); - } catch (IllegalArgumentException e) { - assertThat(e).hasMessage("Missing component key"); - } - } -} diff --git a/sonar-core/src/test/java/org/sonar/core/graph/BeanElementTest.java b/sonar-core/src/test/java/org/sonar/core/graph/BeanElementTest.java deleted file mode 100644 index 69fd68da899..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/graph/BeanElementTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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.core.graph; - -import com.tinkerpop.blueprints.Vertex; -import com.tinkerpop.blueprints.impls.tg.TinkerGraph; -import org.junit.Before; -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class BeanElementTest { - - BeanGraph beanGraph; - BeanVertex beanVertex; - - @Before - public void before() { - TinkerGraph graph = new TinkerGraph(); - beanGraph = new BeanGraph(graph); - - Vertex vertex = graph.addVertex(null); - beanVertex = new BeanVertex() { - }; - beanVertex.setElement(vertex); - beanVertex.setBeanGraph(beanGraph); - } - - @Test - public void should_set_required_fields() { - assertThat(beanVertex.beanGraph()).isSameAs(beanGraph); - assertThat(beanVertex.element()).isInstanceOf(Vertex.class); - } - - @Test - public void no_properties_by_default() { - assertThat(beanVertex.getProperty("color")).isNull(); - assertThat(beanVertex.getProperty("code")).isNull(); - assertThat(beanVertex.getProperty("alive")).isNull(); - assertThat(beanVertex.getPropertyKeys()).isEmpty(); - } - - @Test - public void should_set_properties() { - beanVertex.setProperty("color", "red"); - beanVertex.setProperty("code", 123); - beanVertex.setProperty("alive", true); - - assertThat(beanVertex.getProperty("color")).isEqualTo("red"); - assertThat(beanVertex.getProperty("code")).isEqualTo(123); - assertThat(beanVertex.getProperty("alive")).isEqualTo(true); - assertThat(beanVertex.getPropertyKeys()).containsOnly("color", "code", "alive"); - } - - @Test - public void should_unset_properties_with_null_values() { - beanVertex.setProperty("color", "red"); - beanVertex.setProperty("code", 123); - beanVertex.setProperty("alive", true); - - beanVertex.setProperty("color", null); - beanVertex.setProperty("code", null); - beanVertex.setProperty("alive", null); - beanVertex.setProperty("other", null); - - assertThat(beanVertex.getProperty("color")).isNull(); - assertThat(beanVertex.getProperty("code")).isNull(); - assertThat(beanVertex.getProperty("alive")).isNull(); - assertThat(beanVertex.getPropertyKeys()).isEmpty(); - } - - @Test - public void should_remove_property() { - beanVertex.setProperty("color", "red"); - beanVertex.setProperty("code", 123); - beanVertex.setProperty("alive", true); - - beanVertex.removeProperty("color"); - beanVertex.removeProperty("code"); - beanVertex.removeProperty("alive"); - beanVertex.removeProperty("other"); - - assertThat(beanVertex.getProperty("color")).isNull(); - assertThat(beanVertex.getProperty("code")).isNull(); - assertThat(beanVertex.getProperty("alive")).isNull(); - assertThat(beanVertex.getPropertyKeys()).isEmpty(); - } -} diff --git a/sonar-core/src/test/java/org/sonar/core/graph/BeanElementsTest.java b/sonar-core/src/test/java/org/sonar/core/graph/BeanElementsTest.java deleted file mode 100644 index eb5f4d09c6f..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/graph/BeanElementsTest.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * 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.core.graph; - -import com.tinkerpop.blueprints.Vertex; -import com.tinkerpop.blueprints.impls.tg.TinkerGraph; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import static org.assertj.core.api.Assertions.assertThat; - -public class BeanElementsTest { - TinkerGraph graph; - Vertex vertex; - BeanGraph beanGraph; - BeanVertex beanVertex; - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Before - public void before() { - graph = new TinkerGraph(); - beanGraph = new BeanGraph(graph); - - vertex = graph.addVertex(null); - beanVertex = new BeanVertex() { - }; - beanVertex.setElement(vertex); - beanVertex.setBeanGraph(beanGraph); - } - - @Test - public void should_wrap_vertex_into_bean() { - BeanElements elements = new BeanElements(); - Person bean = elements.wrap(vertex, Person.class, beanGraph); - - assertThat(bean).isNotNull(); - assertThat(bean.element()).isSameAs(vertex); - assertThat(bean.beanGraph()).isSameAs(beanGraph); - } - - @Test - public void should_keep_cache_of_beans() { - BeanElements elements = new BeanElements(); - Person bean = elements.wrap(vertex, Person.class, beanGraph); - Person bean2 = elements.wrap(vertex, Person.class, beanGraph); - - assertThat(bean).isSameAs(bean2); - } - - @Test - public void should_wrap_different_elements() { - BeanElements elements = new BeanElements(); - Vertex vertex2 = graph.addVertex(null); - - Person bean = elements.wrap(vertex, Person.class, beanGraph); - Person bean2 = elements.wrap(vertex2, Person.class, beanGraph); - - assertThat(bean).isNotNull(); - assertThat(bean).isNotSameAs(bean2); - } - - @Test - public void should_clear_cache() { - BeanElements elements = new BeanElements(); - - Person bean = elements.wrap(vertex, Person.class, beanGraph); - assertThat(bean).isNotNull(); - elements.clear(); - - Person bean2 = elements.wrap(vertex, Person.class, beanGraph); - assertThat(bean2).isNotNull(); - assertThat(bean2).isNotSameAs(bean); - } - - @Test - public void element_could_be_wrapped_by_several_beans() { - BeanElements elements = new BeanElements(); - Person person = elements.wrap(vertex, Person.class, beanGraph); - Job job = elements.wrap(vertex, Job.class, beanGraph); - - assertThat(person).isNotSameAs(job); - } - - @Test - public void bean_class_should_have_an_empty_constructor() { - thrown.expect(IllegalStateException.class); - thrown.expectMessage("Class has no default constructor: org.sonar.core.graph.BeanElementsTest$NoEmptyConstructor"); - - BeanElements elements = new BeanElements(); - elements.wrap(vertex, NoEmptyConstructor.class, beanGraph); - } - - @Test - public void bean_constructor_should_be_accessible() { - thrown.expect(IllegalStateException.class); - thrown.expectMessage("Can not access to default constructor: org.sonar.core.graph.BeanElementsTest$PrivateConstructor"); - - BeanElements elements = new BeanElements(); - elements.wrap(vertex, PrivateConstructor.class, beanGraph); - } - - static class Person extends BeanVertex { - - } - - static class Job extends BeanVertex { - - } - - static class NoEmptyConstructor extends BeanVertex { - private int i; - - NoEmptyConstructor(int i) { - this.i = i; - } - } - - static class PrivateConstructor extends BeanVertex { - private PrivateConstructor() { - - } - } -} diff --git a/sonar-core/src/test/java/org/sonar/core/graph/BeanGraphTest.java b/sonar-core/src/test/java/org/sonar/core/graph/BeanGraphTest.java deleted file mode 100644 index 8054f745878..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/graph/BeanGraphTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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.core.graph; - -import com.tinkerpop.blueprints.Direction; -import com.tinkerpop.blueprints.Vertex; -import com.tinkerpop.blueprints.impls.tg.TinkerGraph; -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class BeanGraphTest { - - @Test - public void should_get_underlying_graph() { - TinkerGraph graph = new TinkerGraph(); - BeanGraph beanGraph = new BeanGraph(graph); - - assertThat(beanGraph.getUnderlyingGraph()).isSameAs(graph); - } - - @Test - public void should_create_bean_vertex() { - BeanGraph beanGraph = BeanGraph.createInMemory(); - Person person = beanGraph.createVertex(Person.class); - - assertThat(person).isNotNull(); - assertThat(person.element()).isNotNull(); - assertThat(person.element().getId()).isNotNull(); - assertThat(person.beanGraph()).isSameAs(beanGraph); - assertThat(person.age()).isNull(); - } - - @Test - public void should_wrap_existing_element() { - TinkerGraph graph = new TinkerGraph(); - BeanGraph beanGraph = new BeanGraph(graph); - Vertex vertex = graph.addVertex(null); - vertex.setProperty("age", 42); - - Person person = beanGraph.wrap(vertex, Person.class); - assertThat(person).isNotNull(); - assertThat(person.element()).isSameAs(vertex); - assertThat(person.age()).isEqualTo(42); - } - - @Test - public void should_create_adjacent_bean_vertex() { - BeanGraph beanGraph = BeanGraph.createInMemory(); - Person person = beanGraph.createVertex(Person.class); - - Person adjacent = beanGraph.createAdjacentVertex(person, Person.class, "knows", "type", "family"); - assertThat(adjacent).isNotNull(); - assertThat(person.knows()).hasSize(1); - assertThat(person.knows().iterator().next()).isSameAs(adjacent); - assertThat(adjacent.knows()).isEmpty(); - } - - @Test - public void should_not_wrap_null_element() { - BeanGraph beanGraph = BeanGraph.createInMemory(); - assertThat(beanGraph.wrap(null, Person.class)).isNull(); - } - - static class Person extends BeanVertex { - Integer age() { - return (Integer) getProperty("age"); - } - - Iterable knows() { - return getVertices(Person.class, Direction.OUT, "knows"); - } - } -} diff --git a/sonar-core/src/test/java/org/sonar/core/graph/EdgePathTest.java b/sonar-core/src/test/java/org/sonar/core/graph/EdgePathTest.java deleted file mode 100644 index a254e777634..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/graph/EdgePathTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.core.graph; - -import com.tinkerpop.blueprints.Direction; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import static org.assertj.core.api.Assertions.assertThat; - -public class EdgePathTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void create_valid_edge_path() { - EdgePath path = EdgePath.create(Direction.OUT, "knows", Direction.OUT, "has"); - - assertThat(path).isNotNull(); - assertThat(path.getElements()).hasSize(4); - assertThat(path.getElements().get(0)).isEqualTo(Direction.OUT); - assertThat(path.getElements().get(1)).isEqualTo("knows"); - assertThat(path.getElements().get(2)).isEqualTo(Direction.OUT); - assertThat(path.getElements().get(3)).isEqualTo("has"); - } - - @Test - public void should_have_even_number_of_elements() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Odd number of elements (3)"); - EdgePath.create(Direction.OUT, "knows", Direction.OUT); - } - - @Test - public void should_have_sequence_of_directions_and_strings_1() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Element 0 must be a com.tinkerpop.blueprints.Direction (got java.lang.String)"); - - EdgePath.create("knows", Direction.OUT); - } - - @Test - public void should_have_sequence_of_directions_and_strings_2() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Element 1 must be a String (got com.tinkerpop.blueprints.Direction)"); - - EdgePath.create(Direction.OUT, Direction.OUT); - } -} diff --git a/sonar-core/src/test/java/org/sonar/core/graph/GraphUtilTest.java b/sonar-core/src/test/java/org/sonar/core/graph/GraphUtilTest.java deleted file mode 100644 index 748f09a0203..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/graph/GraphUtilTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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.core.graph; - -import com.tinkerpop.blueprints.Direction; -import com.tinkerpop.blueprints.Vertex; -import com.tinkerpop.blueprints.impls.tg.TinkerGraph; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import static org.assertj.core.api.Assertions.assertThat; - -public class GraphUtilTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void uniqueAdjacent() { - TinkerGraph graph = new TinkerGraph(); - Vertex a = graph.addVertex(null); - Vertex b = graph.addVertex(null); - Vertex c = graph.addVertex(null); - graph.addEdge(null, a, b, "likes"); - graph.addEdge(null, a, c, "hates"); - - assertThat(GraphUtil.singleAdjacent(a, Direction.OUT, "likes")).isEqualTo(b); - assertThat(GraphUtil.singleAdjacent(a, Direction.OUT, "likes", "other")).isEqualTo(b); - assertThat(GraphUtil.singleAdjacent(a, Direction.OUT, "other")).isNull(); - assertThat(GraphUtil.singleAdjacent(a, Direction.IN, "likes")).isNull(); - } - - @Test - public void uniqueAdjacent_fail_if_multiple_adjacents() { - thrown.expect(MultipleElementsException.class); - thrown.expectMessage("More than one vertex is adjacent to: v[0], direction: OUT, labels: likes,hates"); - - TinkerGraph graph = new TinkerGraph(); - Vertex a = graph.addVertex(null); - Vertex b = graph.addVertex(null); - Vertex c = graph.addVertex(null); - graph.addEdge(null, a, b, "likes"); - graph.addEdge(null, a, c, "likes"); - - GraphUtil.singleAdjacent(a, Direction.OUT, "likes", "hates"); - } - - @Test - public void should_extract_single_element() { - TinkerGraph graph = new TinkerGraph(); - Vertex a = graph.addVertex(null); - - Vertex single = GraphUtil.single(graph.getVertices()); - assertThat(single).isSameAs(a); - } - - @Test - public void should_extract_null() { - TinkerGraph graph = new TinkerGraph(); - Vertex single = GraphUtil.single(graph.getVertices()); - assertThat(single).isNull(); - } - - @Test - public void should_fail_to_extract_single_element() { - thrown.expect(MultipleElementsException.class); - thrown.expectMessage("More than one element"); - - TinkerGraph graph = new TinkerGraph(); - graph.addVertex(null); - graph.addVertex(null); - graph.addVertex(null); - - GraphUtil.single(graph.getVertices()); - } -} diff --git a/sonar-core/src/test/java/org/sonar/core/graph/graphson/GraphsonReaderTest.java b/sonar-core/src/test/java/org/sonar/core/graph/graphson/GraphsonReaderTest.java deleted file mode 100644 index b63cd4de940..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/graph/graphson/GraphsonReaderTest.java +++ /dev/null @@ -1,328 +0,0 @@ -/* - * 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.core.graph.graphson; - -import com.google.common.collect.Sets; -import com.tinkerpop.blueprints.Direction; -import com.tinkerpop.blueprints.Edge; -import com.tinkerpop.blueprints.Vertex; -import com.tinkerpop.blueprints.impls.tg.TinkerGraph; -import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; -import org.junit.Assert; -import org.junit.Test; - -import java.io.StringReader; -import java.io.StringWriter; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -public class GraphsonReaderTest { - - @Test - public void inputGraphModeExtended() { - TinkerGraph graph = new TinkerGraph(); - - String json = "{ \"mode\":\"EXTENDED\", \"vertices\": [ {\"_id\":1, \"_type\":\"vertex\", \"test\": { \"type\":\"string\", \"value\":\"please work\"}, \"testlist\":{\"type\":\"list\", \"value\":[{\"type\":\"int\", \"value\":1}, {\"type\":\"int\",\"value\":2}, {\"type\":\"int\",\"value\":3}, {\"type\":\"unknown\",\"value\":null}]}, \"testmap\":{\"type\":\"map\", \"value\":{\"big\":{\"type\":\"long\", \"value\":10000000000}, \"small\":{\"type\":\"double\", \"value\":0.4954959595959}, \"nullKey\":{\"type\":\"unknown\", \"value\":null}}}}, {\"_id\":2, \"_type\":\"vertex\", \"testagain\":{\"type\":\"string\", \"value\":\"please work again\"}}], \"edges\":[{\"_id\":100, \"_type\":\"edge\", \"_outV\":1, \"_inV\":2, \"_label\":\"works\", \"teste\": {\"type\":\"string\", \"value\":\"please worke\"}, \"keyNull\":{\"type\":\"unknown\", \"value\":null}}]}"; - - StringReader input = new StringReader(json); - new GraphsonReader().read(input, graph); - - Assert.assertEquals(2, getIterableCount(graph.getVertices())); - Assert.assertEquals(1, getIterableCount(graph.getEdges())); - - Vertex v1 = graph.getVertex(1); - Assert.assertNotNull(v1); - Assert.assertEquals("please work", v1.getProperty("test")); - - Map map = (Map) v1.getProperty("testmap"); - Assert.assertNotNull(map); - Assert.assertEquals(10000000000l, Long.parseLong(map.get("big").toString())); - Assert.assertEquals(0.4954959595959, Double.parseDouble(map.get("small").toString()), 0); - Assert.assertNull(map.get("nullKey")); - - List list = (List) v1.getProperty("testlist"); - Assert.assertEquals(4, list.size()); - - boolean foundNull = false; - for (int ix = 0; ix < list.size(); ix++) { - if (list.get(ix) == null) { - foundNull = true; - break; - } - } - - Assert.assertTrue(foundNull); - - Vertex v2 = graph.getVertex(2); - Assert.assertNotNull(v2); - Assert.assertEquals("please work again", v2.getProperty("testagain")); - - Edge e = graph.getEdge(100); - Assert.assertNotNull(e); - Assert.assertEquals("works", e.getLabel()); - Assert.assertEquals(v1, e.getVertex(Direction.OUT)); - Assert.assertEquals(v2, e.getVertex(Direction.IN)); - Assert.assertEquals("please worke", e.getProperty("teste")); - Assert.assertNull(e.getProperty("keyNull")); - - } - - @Test - public void inputGraphModeNormal() { - TinkerGraph graph = new TinkerGraph(); - - String json = "{ \"mode\":\"NORMAL\",\"vertices\": [ {\"_id\":1, \"_type\":\"vertex\", \"test\": \"please work\", \"testlist\":[1, 2, 3, null], \"testmap\":{\"big\":10000000000, \"small\":0.4954959595959, \"nullKey\":null}}, {\"_id\":2, \"_type\":\"vertex\", \"testagain\":\"please work again\"}], \"edges\":[{\"_id\":100, \"_type\":\"edge\", \"_outV\":1, \"_inV\":2, \"_label\":\"works\", \"teste\": \"please worke\", \"keyNull\":null}]}"; - - StringReader input = new StringReader(json); - new GraphsonReader().read(input, graph); - - Assert.assertEquals(2, getIterableCount(graph.getVertices())); - Assert.assertEquals(1, getIterableCount(graph.getEdges())); - - Vertex v1 = graph.getVertex(1); - Assert.assertNotNull(v1); - Assert.assertEquals("please work", v1.getProperty("test")); - - Map map = (Map) v1.getProperty("testmap"); - Assert.assertNotNull(map); - Assert.assertEquals(10000000000l, Long.parseLong(map.get("big").toString())); - Assert.assertEquals(0.4954959595959, Double.parseDouble(map.get("small").toString()), 0); - Assert.assertNull(map.get("nullKey")); - - List list = (List) v1.getProperty("testlist"); - Assert.assertEquals(4, list.size()); - - boolean foundNull = false; - for (int ix = 0; ix < list.size(); ix++) { - if (list.get(ix) == null) { - foundNull = true; - break; - } - } - - Assert.assertTrue(foundNull); - - Vertex v2 = graph.getVertex(2); - Assert.assertNotNull(v2); - Assert.assertEquals("please work again", v2.getProperty("testagain")); - - Edge e = graph.getEdge(100); - Assert.assertNotNull(e); - Assert.assertEquals("works", e.getLabel()); - Assert.assertEquals(v1, e.getVertex(Direction.OUT)); - Assert.assertEquals(v2, e.getVertex(Direction.IN)); - Assert.assertEquals("please worke", e.getProperty("teste")); - Assert.assertNull(e.getProperty("keyNull")); - - } - - @Test - public void inputGraphModeCompact() { - TinkerGraph graph = new TinkerGraph(); - - String json = "{ \"mode\":\"COMPACT\",\"vertices\": [ {\"_id\":1, \"test\": \"please work\", \"testlist\":[1, 2, 3, null], \"testmap\":{\"big\":10000000000, \"small\":0.4954959595959, \"nullKey\":null}}, {\"_id\":2, \"testagain\":\"please work again\"}], \"edges\":[{\"_id\":100, \"_outV\":1, \"_inV\":2, \"_label\":\"works\", \"teste\": \"please worke\", \"keyNull\":null}]}"; - - StringReader input = new StringReader(json); - new GraphsonReader().read(input, graph); - - Assert.assertEquals(2, getIterableCount(graph.getVertices())); - Assert.assertEquals(1, getIterableCount(graph.getEdges())); - - Vertex v1 = graph.getVertex(1); - Assert.assertNotNull(v1); - Assert.assertEquals("please work", v1.getProperty("test")); - - Map map = (Map) v1.getProperty("testmap"); - Assert.assertNotNull(map); - Assert.assertEquals(10000000000l, Long.parseLong(map.get("big").toString())); - Assert.assertEquals(0.4954959595959, Double.parseDouble(map.get("small").toString()), 0); - Assert.assertNull(map.get("nullKey")); - - List list = (List) v1.getProperty("testlist"); - Assert.assertEquals(4, list.size()); - - boolean foundNull = false; - for (Object aList : list) { - if (aList == null) { - foundNull = true; - break; - } - } - - Assert.assertTrue(foundNull); - - Vertex v2 = graph.getVertex(2); - Assert.assertNotNull(v2); - Assert.assertEquals("please work again", v2.getProperty("testagain")); - - Edge e = graph.getEdge(100); - Assert.assertNotNull(e); - Assert.assertEquals("works", e.getLabel()); - Assert.assertEquals(v1, e.getVertex(Direction.OUT)); - Assert.assertEquals(v2, e.getVertex(Direction.IN)); - Assert.assertEquals("please worke", e.getProperty("teste")); - Assert.assertNull(e.getProperty("keyNull")); - - } - - @Test - public void inputGraphExtendedFullCycle() throws Exception { - TinkerGraph graph = TinkerGraphFactory.createTinkerGraph(); - - StringWriter stream = new StringWriter(); - - GraphsonWriter writer = new GraphsonWriter(); - writer.write(graph, stream, GraphsonMode.EXTENDED); - - stream.flush(); - stream.close(); - - String jsonString = stream.toString(); - - StringReader input = new StringReader(jsonString); - - TinkerGraph emptyGraph = new TinkerGraph(); - new GraphsonReader().read(input, emptyGraph); - - Assert.assertEquals(6, getIterableCount(emptyGraph.getVertices())); - Assert.assertEquals(6, getIterableCount(emptyGraph.getEdges())); - - for (Vertex v : graph.getVertices()) { - Vertex found = emptyGraph.getVertex(v.getId()); - - Assert.assertNotNull(v); - - for (String key : found.getPropertyKeys()) { - Assert.assertEquals(v.getProperty(key), found.getProperty(key)); - } - } - - for (Edge e : graph.getEdges()) { - Edge found = emptyGraph.getEdge(e.getId()); - - Assert.assertNotNull(e); - - for (String key : found.getPropertyKeys()) { - Assert.assertEquals(e.getProperty(key), found.getProperty(key)); - } - } - - } - - @Test - public void inputGraphCompactFullCycle() throws Exception { - TinkerGraph graph = TinkerGraphFactory.createTinkerGraph(); - - StringWriter stream = new StringWriter(); - - Set edgeKeys = new HashSet<>(); - edgeKeys.add(GraphsonTokens._ID); - edgeKeys.add(GraphsonTokens._IN_V); - edgeKeys.add(GraphsonTokens._OUT_V); - edgeKeys.add(GraphsonTokens._LABEL); - - Set vertexKeys = Sets.newHashSet(); - vertexKeys.add(GraphsonTokens._ID); - - GraphsonWriter writer = new GraphsonWriter(); - writer.write(graph, stream, GraphsonMode.EXTENDED, vertexKeys, edgeKeys); - - stream.flush(); - stream.close(); - - String jsonString = stream.toString(); - StringReader input = new StringReader(jsonString); - - TinkerGraph emptyGraph = new TinkerGraph(); - new GraphsonReader().read(input, emptyGraph); - - Assert.assertEquals(6, getIterableCount(emptyGraph.getVertices())); - Assert.assertEquals(6, getIterableCount(emptyGraph.getEdges())); - - for (Vertex v : graph.getVertices()) { - Vertex found = emptyGraph.getVertex(v.getId()); - - Assert.assertNotNull(v); - - for (String key : found.getPropertyKeys()) { - Assert.assertEquals(v.getProperty(key), found.getProperty(key)); - } - - // no properties should be here - Assert.assertEquals(null, found.getProperty("name")); - } - - for (Edge e : graph.getEdges()) { - Edge found = emptyGraph.getEdge(e.getId()); - - Assert.assertNotNull(e); - - for (String key : found.getPropertyKeys()) { - Assert.assertEquals(e.getProperty(key), found.getProperty(key)); - } - - // no properties should be here - Assert.assertEquals(null, found.getProperty("weight")); - } - - } - - @Test(expected = GraphsonException.class) - public void inputGraphCompactFullCycleBroken() throws Exception { - TinkerGraph graph = TinkerGraphFactory.createTinkerGraph(); - - StringWriter stream = new StringWriter(); - - Set edgeKeys = new HashSet<>(); - edgeKeys.add(GraphsonTokens._IN_V); - edgeKeys.add(GraphsonTokens._OUT_V); - edgeKeys.add(GraphsonTokens._LABEL); - - Set vertexKeys = Sets.newHashSet(); - - GraphsonWriter writer = new GraphsonWriter(); - writer.write(graph, stream, GraphsonMode.COMPACT, vertexKeys, edgeKeys); - - stream.flush(); - stream.close(); - - String jsonString = writer.toString(); - StringReader input = new StringReader(jsonString); - - TinkerGraph emptyGraph = new TinkerGraph(); - new GraphsonReader().read(input, emptyGraph); - - } - - private int getIterableCount(Iterable elements) { - int counter = 0; - - Iterator iterator = elements.iterator(); - while (iterator.hasNext()) { - iterator.next(); - counter++; - } - - return counter; - } -} diff --git a/sonar-core/src/test/java/org/sonar/core/graph/graphson/GraphsonUtilTest.java b/sonar-core/src/test/java/org/sonar/core/graph/graphson/GraphsonUtilTest.java deleted file mode 100644 index e021175f810..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/graph/graphson/GraphsonUtilTest.java +++ /dev/null @@ -1,1151 +0,0 @@ -/* - * 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.core.graph.graphson; - -import com.tinkerpop.blueprints.Direction; -import com.tinkerpop.blueprints.Edge; -import com.tinkerpop.blueprints.Graph; -import com.tinkerpop.blueprints.Vertex; -import com.tinkerpop.blueprints.impls.tg.TinkerGraph; -import com.tinkerpop.blueprints.util.io.graphson.GraphSONTokens; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.JSONValue; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import static org.assertj.core.api.Assertions.assertThat; - -public class GraphsonUtilTest { - private final String vertexJson1 = "{\"name\":\"marko\",\"age\":29,\"_id\":1,\"_type\":\"vertex\"}"; - private final String vertexJson2 = "{\"name\":\"vadas\",\"age\":27,\"_id\":2,\"_type\":\"vertex\"}"; - private final String edgeJsonLight = "{\"weight\":0.5,\"_outV\":1,\"_inV\":2}"; - private final String edgeJson = "{\"weight\":0.5,\"_id\":7,\"_type\":\"edge\",\"_outV\":1,\"_inV\":2,\"_label\":\"knows\"}"; - private TinkerGraph graph = new TinkerGraph(); - private InputStream inputStreamVertexJson1; - private InputStream inputStreamEdgeJsonLight; - - @Before - public void setUp() { - this.graph.clear(); - - this.inputStreamVertexJson1 = new ByteArrayInputStream(vertexJson1.getBytes()); - this.inputStreamEdgeJsonLight = new ByteArrayInputStream(edgeJsonLight.getBytes()); - } - - @Test - public void jsonFromElementEdgeNoPropertiesNoKeysNoTypes() { - Vertex v1 = this.graph.addVertex(1); - Vertex v2 = this.graph.addVertex(2); - - Edge e = this.graph.addEdge(3, v1, v2, "test"); - e.setProperty("weight", 0.5f); - - JSONObject json = GraphsonUtil.jsonFromElement(e, null, GraphsonMode.NORMAL); - - assertThat(json).isNotNull(); - assertThat(json.containsKey(GraphSONTokens._ID)).isTrue(); - assertThat(json.get(GraphSONTokens._ID)).isEqualTo("3"); - assertThat(json.containsKey(GraphSONTokens._LABEL)).isTrue(); - assertThat(json.get(GraphSONTokens._LABEL)).isEqualTo("test"); - assertThat(json.containsKey(GraphSONTokens._TYPE)).isTrue(); - assertThat(json.get(GraphSONTokens._TYPE)).isEqualTo("edge"); - assertThat(json.containsKey(GraphSONTokens._IN_V)).isTrue(); - assertThat(json.get(GraphSONTokens._IN_V)).isEqualTo("2"); - assertThat(json.containsKey(GraphSONTokens._OUT_V)).isTrue(); - assertThat(json.get(GraphSONTokens._OUT_V)).isEqualTo("1"); - assertThat(json.containsKey("weight")).isTrue(); - assertThat(json.get("weight")).isEqualTo(0.5f); - } - - @Test - public void jsonFromElementEdgeCompactIdOnlyAsInclude() { - Vertex v1 = this.graph.addVertex(1); - Vertex v2 = this.graph.addVertex(2); - - Edge e = this.graph.addEdge(3, v1, v2, "test"); - e.setProperty("weight", 0.5f); - - Set propertiesToInclude = new HashSet() {{ - add(GraphSONTokens._ID); - }}; - - JSONObject json = GraphsonUtil.jsonFromElement(e, propertiesToInclude, GraphsonMode.COMPACT); - - assertThat(json).isNotNull(); - assertThat(json.containsKey(GraphSONTokens._TYPE)).isFalse(); - assertThat(json.containsKey(GraphSONTokens._LABEL)).isFalse(); - assertThat(json.containsKey(GraphSONTokens._IN_V)).isFalse(); - assertThat(json.containsKey(GraphSONTokens._OUT_V)).isFalse(); - assertThat(json.containsKey(GraphSONTokens._ID)).isTrue(); - assertThat(json.containsKey("weight")).isFalse(); - } - - @Test - public void jsonFromElementEdgeCompactIdOnlyAsExclude() { - ElementFactory factory = new ElementFactory(this.graph); - Vertex v1 = this.graph.addVertex(1); - Vertex v2 = this.graph.addVertex(2); - - Edge e = this.graph.addEdge(3, v1, v2, "test"); - e.setProperty("weight", 0.5f); - e.setProperty("x", "y"); - - Set propertiesToExclude = new HashSet() {{ - add(GraphSONTokens._TYPE); - add(GraphSONTokens._LABEL); - add(GraphSONTokens._IN_V); - add(GraphSONTokens._OUT_V); - add("weight"); - }}; - - ElementPropertyConfig config = new ElementPropertyConfig(null, propertiesToExclude, - ElementPropertyConfig.ElementPropertiesRule.INCLUDE, - ElementPropertyConfig.ElementPropertiesRule.EXCLUDE); - GraphsonUtil utility = new GraphsonUtil(GraphsonMode.COMPACT, factory, config); - JSONObject json = utility.jsonFromElement(e); - - assertThat(json).isNotNull(); - assertThat(json.containsKey(GraphSONTokens._TYPE)).isFalse(); - assertThat(json.containsKey(GraphSONTokens._LABEL)).isFalse(); - assertThat(json.containsKey(GraphSONTokens._IN_V)).isFalse(); - assertThat(json.containsKey(GraphSONTokens._OUT_V)).isFalse(); - assertThat(json.containsKey(GraphSONTokens._ID)).isTrue(); - assertThat(json.containsKey("weight")).isFalse(); - assertThat(json.containsKey("x")).isTrue(); - assertThat(json.get("x")).isEqualTo("y"); - } - - @Test - public void jsonFromElementEdgeCompactAllKeys() { - Vertex v1 = this.graph.addVertex(1); - Vertex v2 = this.graph.addVertex(2); - - Edge e = this.graph.addEdge(3, v1, v2, "test"); - e.setProperty("weight", 0.5f); - - JSONObject json = GraphsonUtil.jsonFromElement(e, null, GraphsonMode.COMPACT); - - assertThat(json).isNotNull(); - assertThat(json.containsKey(GraphSONTokens._ID)).isTrue(); - assertThat(json.containsKey(GraphSONTokens._TYPE)).isTrue(); - assertThat(json.containsKey(GraphSONTokens._LABEL)).isTrue(); - assertThat(json.containsKey(GraphSONTokens._IN_V)).isTrue(); - assertThat(json.containsKey(GraphSONTokens._OUT_V)).isTrue(); - assertThat(json.get("weight")).isEqualTo(0.5f); - } - - @Test - public void jsonFromElementVertexNoPropertiesNoKeysNoTypes() { - Vertex v = this.graph.addVertex(1); - v.setProperty("name", "marko"); - - JSONObject json = GraphsonUtil.jsonFromElement(v, null, GraphsonMode.NORMAL); - - assertThat(json).isNotNull(); - assertThat(json.containsKey(GraphSONTokens._ID)).isTrue(); - assertThat(json.get(GraphSONTokens._ID)).isEqualTo("1"); - assertThat(json.containsKey(GraphSONTokens._TYPE)).isTrue(); - assertThat(json.get(GraphSONTokens._TYPE)).isEqualTo("vertex"); - assertThat(json.get("name")).isEqualTo("marko"); - } - - @Test - public void jsonFromElementVertexCompactIdOnlyAsInclude() { - Vertex v = this.graph.addVertex(1); - v.setProperty("name", "marko"); - - Set propertiesToInclude = new HashSet() {{ - add(GraphSONTokens._ID); - }}; - - JSONObject json = GraphsonUtil.jsonFromElement(v, propertiesToInclude, GraphsonMode.COMPACT); - - assertThat(json).isNotNull(); - assertThat(json.containsKey(GraphSONTokens._TYPE)).isFalse(); - assertThat(json.containsKey(GraphSONTokens._ID)).isTrue(); - assertThat(json.containsKey("name")).isFalse(); - } - - @Test - public void jsonFromElementVertexCompactIdNameOnlyAsExclude() { - ElementFactory factory = new ElementFactory(this.graph); - Vertex v = this.graph.addVertex(1); - v.setProperty("name", "marko"); - - Set propertiesToExclude = new HashSet() {{ - add(GraphSONTokens._TYPE); - }}; - - ElementPropertyConfig config = new ElementPropertyConfig(propertiesToExclude, null, - ElementPropertyConfig.ElementPropertiesRule.EXCLUDE, - ElementPropertyConfig.ElementPropertiesRule.EXCLUDE); - - GraphsonUtil utility = new GraphsonUtil(GraphsonMode.COMPACT, factory, config); - JSONObject json = utility.jsonFromElement(v); - - assertThat(json).isNotNull(); - assertThat(json.containsKey(GraphSONTokens._TYPE)).isFalse(); - assertThat(json.containsKey(GraphSONTokens._ID)).isTrue(); - assertThat(json.containsKey("name")).isTrue(); - } - - @Test - public void jsonFromElementVertexCompactAllOnly() { - Vertex v = this.graph.addVertex(1); - v.setProperty("name", "marko"); - - JSONObject json = GraphsonUtil.jsonFromElement(v, null, GraphsonMode.COMPACT); - - assertThat(json).isNotNull(); - assertThat(json.containsKey(GraphSONTokens._TYPE)).isTrue(); - assertThat(json.containsKey(GraphSONTokens._ID)).isTrue(); - assertThat(json.containsKey("name")).isTrue(); - } - - @Test - public void jsonFromElementVertexPrimitivePropertiesNoKeysNoTypes() { - Vertex v = this.graph.addVertex(1); - v.setProperty("keyString", "string"); - v.setProperty("keyLong", 1L); - v.setProperty("keyInt", 2); - v.setProperty("keyFloat", 3.3f); - v.setProperty("keyExponentialDouble", 1312928167.626012); - v.setProperty("keyDouble", 4.4); - v.setProperty("keyBoolean", true); - - JSONObject json = GraphsonUtil.jsonFromElement(v, null, GraphsonMode.NORMAL); - - assertThat(json).isNotNull(); - assertThat(json.containsKey(GraphSONTokens._ID)).isTrue(); - assertThat(json.get(GraphSONTokens._ID)).isEqualTo("1"); - assertThat(json.containsKey("keyString")).isTrue(); - assertThat(json.get("keyString")).isEqualTo("string"); - assertThat(json.containsKey("keyLong")).isTrue(); - assertThat(json.get("keyLong")).isEqualTo(1L); - assertThat(json.containsKey("keyInt")).isTrue(); - assertThat(json.get("keyInt")).isEqualTo(2); - assertThat(json.containsKey("keyFloat")).isTrue(); - assertThat(json.get("keyFloat")).isEqualTo(3.3f); - assertThat(json.containsKey("keyExponentialDouble")).isTrue(); - assertThat(json.get("keyExponentialDouble")).isEqualTo(1312928167.626012); - assertThat(json.containsKey("keyDouble")).isTrue(); - assertThat(json.get("keyDouble")).isEqualTo(4.4); - assertThat(json.containsKey("keyBoolean")).isTrue(); - assertThat(json.get("keyBoolean")).isEqualTo(true); - } - - @Test - public void jsonFromElementVertexMapPropertyNoKeysNoTypes() { - Vertex v = this.graph.addVertex(1); - Map map = new HashMap(); - map.put("this", "some"); - map.put("that", 1); - - v.setProperty("keyMap", map); - - JSONObject json = GraphsonUtil.jsonFromElement(v, null, GraphsonMode.NORMAL); - - assertThat(json).isNotNull(); - assertThat(json.get(GraphSONTokens._ID)).isEqualTo("1"); - assertThat(json.containsKey("keyMap")).isTrue(); - - JSONObject mapAsJSON = (JSONObject) json.get("keyMap"); - assertThat(mapAsJSON).isNotNull(); - assertThat(mapAsJSON.containsKey("this")).isTrue(); - assertThat(mapAsJSON.get("this")).isEqualTo("some"); - assertThat(mapAsJSON.containsKey("that")).isTrue(); - assertThat(mapAsJSON.get("that")).isEqualTo(1); - } - - @Test - public void jsonFromElementVertexListPropertyNoKeysNoTypes() { - Vertex v = this.graph.addVertex(1); - List list = new ArrayList<>(); - list.add("this"); - list.add("that"); - list.add("other"); - list.add(true); - - v.setProperty("keyList", list); - - JSONObject json = GraphsonUtil.jsonFromElement(v, null, GraphsonMode.NORMAL); - - assertThat(json).isNotNull(); - assertThat(json.get(GraphSONTokens._ID)).isEqualTo("1"); - assertThat(json.containsKey("keyList")).isTrue(); - - JSONArray listAsJSON = (JSONArray) json.get("keyList"); - assertThat(listAsJSON).isNotNull(); - assertThat(listAsJSON).hasSize(4); - } - - @Test - public void jsonFromElementVertexStringArrayPropertyNoKeysNoTypes() { - Vertex v = this.graph.addVertex(1); - String[] stringArray = new String[]{"this", "that", "other"}; - - v.setProperty("keyStringArray", stringArray); - - JSONObject json = GraphsonUtil.jsonFromElement(v, null, GraphsonMode.NORMAL); - - assertThat(json).isNotNull(); - assertThat(json.get(GraphSONTokens._ID)).isEqualTo("1"); - assertThat(json.containsKey("keyStringArray")).isTrue(); - - JSONArray stringArrayAsJSON = (JSONArray) json.get("keyStringArray"); - assertThat(stringArrayAsJSON).isNotNull(); - assertThat(stringArrayAsJSON).hasSize(3); - } - - @Test - public void jsonFromElementVertexDoubleArrayPropertyNoKeysNoTypes() { - Vertex v = this.graph.addVertex(1); - double[] doubleArray = new double[]{1.0, 2.0, 3.0}; - - v.setProperty("keyDoubleArray", doubleArray); - - JSONObject json = GraphsonUtil.jsonFromElement(v, null, GraphsonMode.NORMAL); - - assertThat(json).isNotNull(); - assertThat(json.get(GraphSONTokens._ID)).isEqualTo("1"); - assertThat(json.containsKey("keyDoubleArray")).isTrue(); - - JSONArray doubleArrayAsJSON = (JSONArray) json.get("keyDoubleArray"); - assertThat(doubleArrayAsJSON).isNotNull(); - assertThat(doubleArrayAsJSON).hasSize(3); - } - - @Test - public void jsonFromElementVertexIntArrayPropertyNoKeysNoTypes() { - Vertex v = this.graph.addVertex(1); - int[] intArray = new int[]{1, 2, 3}; - - v.setProperty("keyIntArray", intArray); - - JSONObject json = GraphsonUtil.jsonFromElement(v, null, GraphsonMode.NORMAL); - - assertThat(json).isNotNull(); - assertThat(json.get(GraphSONTokens._ID)).isEqualTo("1"); - assertThat(json.containsKey("keyIntArray")).isTrue(); - - JSONArray intArrayAsJSON = (JSONArray) json.get("keyIntArray"); - assertThat(intArrayAsJSON).isNotNull(); - assertThat(intArrayAsJSON).hasSize(3); - } - - @Test - public void jsonFromElementVertexLongArrayPropertyNoKeysNoTypes() { - Vertex v = this.graph.addVertex(1); - long[] longArray = new long[]{1l, 2l, 3l}; - - v.setProperty("keyLongArray", longArray); - - JSONObject json = GraphsonUtil.jsonFromElement(v, null, GraphsonMode.NORMAL); - - assertThat(json).isNotNull(); - assertThat(json.get(GraphSONTokens._ID)).isEqualTo("1"); - assertThat(json.containsKey("keyLongArray")).isTrue(); - - JSONArray longArrayAsJSON = (JSONArray) json.get("keyLongArray"); - assertThat(longArrayAsJSON).isNotNull(); - assertThat(longArrayAsJSON).hasSize(3); - } - - @Test - public void jsonFromElementFloatArrayPropertyNoKeysNoTypes() { - Vertex v = this.graph.addVertex(1); - float[] floatArray = new float[]{1.0f, 2.0f, 3.0f}; - - v.setProperty("keyFloatArray", floatArray); - - JSONObject json = GraphsonUtil.jsonFromElement(v, null, GraphsonMode.NORMAL); - - assertThat(json).isNotNull(); - assertThat(json.get(GraphSONTokens._ID)).isEqualTo("1"); - assertThat(json.containsKey("keyFloatArray")).isTrue(); - - JSONArray floatArrayAsJSON = (JSONArray) json.get("keyFloatArray"); - assertThat(floatArrayAsJSON).isNotNull(); - assertThat(floatArrayAsJSON).hasSize(3); - } - - @Test - public void jsonFromElementBooleanArrayPropertyNoKeysNoTypes() { - Vertex v = this.graph.addVertex(1); - boolean[] booleanArray = new boolean[]{true, false, true}; - - v.setProperty("keyBooleanArray", booleanArray); - - JSONObject json = GraphsonUtil.jsonFromElement(v, null, GraphsonMode.NORMAL); - - assertThat(json).isNotNull(); - assertThat(json.get(GraphSONTokens._ID)).isEqualTo("1"); - assertThat(json.containsKey("keyBooleanArray")).isTrue(); - - JSONArray booleanArrayAsJSON = (JSONArray) json.get("keyBooleanArray"); - assertThat(booleanArrayAsJSON).isNotNull(); - assertThat(booleanArrayAsJSON).hasSize(3); - } - - @Test - public void jsonFromElementVertexCatPropertyNoKeysNoTypes() { - Vertex v = this.graph.addVertex(1); - v.setProperty("mycat", new Cat("smithers")); - - JSONObject json = GraphsonUtil.jsonFromElement(v, null, GraphsonMode.NORMAL); - - assertThat(json).isNotNull(); - assertThat(json.get(GraphSONTokens._ID)).isEqualTo("1"); - assertThat(json.containsKey("mycat")).isTrue(); - assertThat(json.get("mycat")).isEqualTo("smithers"); - } - - @Test - public void jsonFromElementVertexCatPropertyNoKeysWithTypes() { - Vertex v = this.graph.addVertex(1); - v.setProperty("mycat", new Cat("smithers")); - - JSONObject json = GraphsonUtil.jsonFromElement(v, null, GraphsonMode.EXTENDED); - - assertThat(json).isNotNull(); - assertThat(json.get(GraphSONTokens._ID)).isEqualTo("1"); - assertThat(json.containsKey("mycat")).isTrue(); - - JSONObject jsonObjectCat = (JSONObject) json.get("mycat"); - assertThat(jsonObjectCat.containsKey("value")).isTrue(); - assertThat(jsonObjectCat.get("value")).isEqualTo("smithers"); - } - - @Test - public void jsonFromElementVertexCatArrayPropertyNoKeysNoTypes() { - Vertex v = this.graph.addVertex(1); - List cats = new ArrayList<>(); - cats.add(new Cat("smithers")); - cats.add(new Cat("mcallister")); - - v.setProperty("cats", cats); - - JSONObject json = GraphsonUtil.jsonFromElement(v, null, GraphsonMode.NORMAL); - - assertThat(json).isNotNull(); - assertThat(json.get(GraphSONTokens._ID)).isEqualTo("1"); - assertThat(json.containsKey("cats")).isTrue(); - - JSONArray catListAsJson = (JSONArray) json.get("cats"); - assertThat(catListAsJson).hasSize(2); - } - - @Test - public void jsonFromElementCrazyPropertyNoKeysNoTypes() { - Vertex v = this.graph.addVertex(1); - List mix = new ArrayList(); - mix.add(new Cat("smithers")); - mix.add(true); - - List deepCats = new ArrayList(); - deepCats.add(new Cat("mcallister")); - mix.add(deepCats); - - Map map = new HashMap(); - map.put("crazy", mix); - - int[] someInts = new int[]{1, 2, 3}; - map.put("ints", someInts); - - map.put("regular", "stuff"); - - Map innerMap = new HashMap(); - innerMap.put("me", "you"); - - map.put("inner", innerMap); - - v.setProperty("crazy-map", map); - - JSONObject json = GraphsonUtil.jsonFromElement(v, null, GraphsonMode.NORMAL); - - assertThat(json).isNotNull(); - assertThat(json.get(GraphSONTokens._ID)).isEqualTo("1"); - assertThat(json.containsKey("crazy-map")).isTrue(); - - JSONObject mapAsJson = (JSONObject) json.get("crazy-map"); - assertThat(mapAsJson.containsKey("regular")).isTrue(); - assertThat(mapAsJson.get("regular")).isEqualTo("stuff"); - - assertThat(mapAsJson.containsKey("ints")).isTrue(); - JSONArray intArrayAsJson = (JSONArray) mapAsJson.get("ints"); - assertThat(intArrayAsJson).hasSize(3); - - assertThat(mapAsJson.containsKey("crazy")).isTrue(); - JSONArray deepListAsJSON = (JSONArray) mapAsJson.get("crazy"); - assertThat(deepListAsJSON).hasSize(3); - - assertThat(mapAsJson.containsKey("inner")).isTrue(); - JSONObject mapInMapAsJSON = (JSONObject) mapAsJson.get("inner"); - assertThat(mapInMapAsJSON.containsKey("me")).isTrue(); - assertThat(mapInMapAsJSON.get("me")).isEqualTo("you"); - - } - - @Test - public void jsonFromElementVertexNoPropertiesWithKeysNoTypes() { - Vertex v = this.graph.addVertex(1); - v.setProperty("x", "X"); - v.setProperty("y", "Y"); - v.setProperty("z", "Z"); - - Set propertiesToInclude = new HashSet<>(); - propertiesToInclude.add("y"); - JSONObject json = GraphsonUtil.jsonFromElement(v, propertiesToInclude, GraphsonMode.NORMAL); - - assertThat(json).isNotNull(); - assertThat(json.get(GraphSONTokens._ID)).isEqualTo("1"); - assertThat(json.get(GraphSONTokens._TYPE)).isEqualTo("vertex"); - assertThat(json.containsKey("x")).isFalse(); - assertThat(json.containsKey("z")).isFalse(); - assertThat(json.containsKey("y")).isTrue(); - } - - @Test - public void jsonFromElementVertexVertexPropertiesWithKeysNoTypes() { - Vertex v = this.graph.addVertex(1); - v.setProperty("x", "X"); - v.setProperty("y", "Y"); - v.setProperty("z", "Z"); - - Vertex innerV = this.graph.addVertex(2); - innerV.setProperty("x", "X"); - innerV.setProperty("y", "Y"); - innerV.setProperty("z", "Z"); - - v.setProperty("v", innerV); - - Set propertiesToInclude = new HashSet<>(); - propertiesToInclude.add("y"); - propertiesToInclude.add("v"); - - JSONObject json = GraphsonUtil.jsonFromElement(v, propertiesToInclude, GraphsonMode.NORMAL); - - assertThat(json).isNotNull(); - assertThat(json.get(GraphSONTokens._ID)).isEqualTo("1"); - assertThat(json.get(GraphSONTokens._TYPE)).isEqualTo("vertex"); - assertThat(json.containsKey("x")).isFalse(); - assertThat(json.containsKey("z")).isFalse(); - assertThat(json.containsKey("y")).isTrue(); - assertThat(json.containsKey("v")).isTrue(); - - JSONObject innerJson = (JSONObject) json.get("v"); - assertThat(innerJson.containsKey("x")).isFalse(); - assertThat(innerJson.containsKey("z")).isFalse(); - assertThat(innerJson.containsKey("y")).isTrue(); - assertThat(innerJson.containsKey("v")).isFalse(); - } - - @Test - public void jsonFromElementVertexPrimitivePropertiesNoKeysWithTypes() { - Vertex v = this.graph.addVertex(1); - v.setProperty("keyString", "string"); - v.setProperty("keyLong", 1L); - v.setProperty("keyInt", 2); - v.setProperty("keyFloat", 3.3f); - v.setProperty("keyDouble", 4.4); - v.setProperty("keyBoolean", true); - - JSONObject json = GraphsonUtil.jsonFromElement(v, null, GraphsonMode.EXTENDED); - - assertThat(json).isNotNull(); - assertThat(json.get(GraphSONTokens._ID)).isEqualTo("1"); - assertThat(json.containsKey("keyString")).isTrue(); - - JSONObject valueAsJson = (JSONObject) json.get("keyString"); - assertThat(valueAsJson.containsKey(GraphSONTokens.TYPE)).isTrue(); - assertThat(valueAsJson.get(GraphSONTokens.TYPE)).isEqualTo(GraphSONTokens.TYPE_STRING); - assertThat(valueAsJson.containsKey(GraphSONTokens.VALUE)).isTrue(); - assertThat(valueAsJson.get(GraphSONTokens.VALUE)).isEqualTo("string"); - - valueAsJson = (JSONObject) json.get("keyLong"); - assertThat(valueAsJson.containsKey(GraphSONTokens.TYPE)).isTrue(); - assertThat(valueAsJson.get(GraphSONTokens.TYPE)).isEqualTo(GraphSONTokens.TYPE_LONG); - assertThat(valueAsJson.containsKey(GraphSONTokens.VALUE)).isTrue(); - assertThat(valueAsJson.get(GraphSONTokens.VALUE)).isEqualTo(1L); - - valueAsJson = (JSONObject) json.get("keyInt"); - assertThat(valueAsJson.containsKey(GraphSONTokens.TYPE)).isTrue(); - assertThat(valueAsJson.get(GraphSONTokens.TYPE)).isEqualTo(GraphSONTokens.TYPE_INTEGER); - assertThat(valueAsJson.containsKey(GraphSONTokens.VALUE)).isTrue(); - assertThat(valueAsJson.get(GraphSONTokens.VALUE)).isEqualTo(2); - - valueAsJson = (JSONObject) json.get("keyFloat"); - assertThat(valueAsJson.containsKey(GraphSONTokens.TYPE)).isTrue(); - assertThat(valueAsJson.get(GraphSONTokens.TYPE)).isEqualTo(GraphSONTokens.TYPE_FLOAT); - assertThat(valueAsJson.containsKey(GraphSONTokens.VALUE)).isTrue(); - assertThat(valueAsJson.get(GraphSONTokens.VALUE)).isEqualTo(3.3f); - - valueAsJson = (JSONObject) json.get("keyDouble"); - assertThat(valueAsJson.containsKey(GraphSONTokens.TYPE)).isTrue(); - assertThat(valueAsJson.get(GraphSONTokens.TYPE)).isEqualTo(GraphSONTokens.TYPE_DOUBLE); - assertThat(valueAsJson.containsKey(GraphSONTokens.VALUE)).isTrue(); - assertThat(valueAsJson.get(GraphSONTokens.VALUE)).isEqualTo(4.4); - - valueAsJson = (JSONObject) json.get("keyBoolean"); - assertThat(valueAsJson.containsKey(GraphSONTokens.TYPE)).isTrue(); - assertThat(valueAsJson.get(GraphSONTokens.TYPE)).isEqualTo(GraphSONTokens.TYPE_BOOLEAN); - assertThat(valueAsJson.containsKey(GraphSONTokens.VALUE)).isTrue(); - assertThat(valueAsJson.get(GraphSONTokens.VALUE)).isEqualTo(true); - } - - @Test - public void jsonFromElementVertexListPropertiesNoKeysWithTypes() { - Vertex v = this.graph.addVertex(1); - List list = new ArrayList<>(); - list.add("this"); - list.add("this"); - list.add("this"); - - v.setProperty("keyList", list); - - JSONObject json = GraphsonUtil.jsonFromElement(v, null, GraphsonMode.EXTENDED); - - assertThat(json).isNotNull(); - assertThat(json.get(GraphSONTokens._ID)).isEqualTo("1"); - assertThat(json.containsKey("keyList")).isTrue(); - - JSONObject listWithTypeAsJson = (JSONObject) json.get("keyList"); - assertThat(listWithTypeAsJson.containsKey(GraphSONTokens.TYPE)).isTrue(); - assertThat(listWithTypeAsJson.get(GraphSONTokens.TYPE)).isEqualTo(GraphSONTokens.TYPE_LIST); - assertThat(listWithTypeAsJson.containsKey(GraphSONTokens.VALUE)).isTrue(); - - JSONArray listAsJSON = (JSONArray) listWithTypeAsJson.get(GraphSONTokens.VALUE); - assertThat(listAsJSON).isNotNull(); - assertThat(listAsJSON).hasSize(3); - - for (int ix = 0; ix < listAsJSON.size(); ix++) { - JSONObject valueAsJson = (JSONObject) listAsJSON.get(ix); - assertThat(valueAsJson).isNotNull(); - assertThat(valueAsJson.containsKey(GraphSONTokens.TYPE)).isTrue(); - assertThat(valueAsJson.get(GraphSONTokens.TYPE)).isEqualTo(GraphSONTokens.TYPE_STRING); - assertThat(valueAsJson.containsKey(GraphSONTokens.VALUE)).isTrue(); - assertThat(valueAsJson.get(GraphSONTokens.VALUE)).isEqualTo("this"); - } - } - - @Test - public void jsonFromElementVertexBooleanListPropertiesNoKeysWithTypes() { - Vertex v = this.graph.addVertex(1); - List list = new ArrayList<>(); - list.add(true); - list.add(true); - list.add(true); - - v.setProperty("keyList", list); - - JSONObject json = GraphsonUtil.jsonFromElement(v, null, GraphsonMode.EXTENDED); - - assertThat(json).isNotNull(); - assertThat(json.get(GraphSONTokens._ID)).isEqualTo("1"); - assertThat(json.containsKey("keyList")).isTrue(); - - JSONObject listWithTypeAsJson = (JSONObject) json.get("keyList"); - assertThat(listWithTypeAsJson.containsKey(GraphSONTokens.TYPE)).isTrue(); - assertThat(listWithTypeAsJson.get(GraphSONTokens.TYPE)).isEqualTo(GraphSONTokens.TYPE_LIST); - assertThat(listWithTypeAsJson.containsKey(GraphSONTokens.VALUE)).isTrue(); - - JSONArray listAsJSON = (JSONArray) listWithTypeAsJson.get(GraphSONTokens.VALUE); - assertThat(listAsJSON).isNotNull(); - assertThat(listAsJSON).hasSize(3); - - for (int ix = 0; ix < listAsJSON.size(); ix++) { - JSONObject valueAsJson = (JSONObject) listAsJSON.get(ix); - assertThat(valueAsJson).isNotNull(); - assertThat(valueAsJson.containsKey(GraphSONTokens.TYPE)).isTrue(); - assertThat(valueAsJson.get(GraphSONTokens.TYPE)).isEqualTo(GraphSONTokens.TYPE_BOOLEAN); - assertThat(valueAsJson.containsKey(GraphSONTokens.VALUE)).isTrue(); - assertThat(valueAsJson.get(GraphSONTokens.VALUE)).isEqualTo(true); - } - } - - @Test - public void jsonFromElementVertexLongListPropertiesNoKeysWithTypes() { - Vertex v = this.graph.addVertex(1); - List list = new ArrayList<>(); - list.add(1000L); - list.add(1000L); - list.add(1000L); - - v.setProperty("keyList", list); - - JSONObject json = GraphsonUtil.jsonFromElement(v, null, GraphsonMode.EXTENDED); - - assertThat(json).isNotNull(); - assertThat(json.get(GraphSONTokens._ID)).isEqualTo("1"); - assertThat(json.containsKey("keyList")).isTrue(); - - JSONObject listWithTypeAsJson = (JSONObject) json.get("keyList"); - assertThat(listWithTypeAsJson.containsKey(GraphSONTokens.TYPE)).isTrue(); - assertThat(listWithTypeAsJson.get(GraphSONTokens.TYPE)).isEqualTo(GraphSONTokens.TYPE_LIST); - assertThat(listWithTypeAsJson.containsKey(GraphSONTokens.VALUE)).isTrue(); - - JSONArray listAsJSON = (JSONArray) listWithTypeAsJson.get(GraphSONTokens.VALUE); - assertThat(listAsJSON).isNotNull(); - assertThat(listAsJSON).hasSize(3); - - for (int ix = 0; ix < listAsJSON.size(); ix++) { - JSONObject valueAsJson = (JSONObject) listAsJSON.get(ix); - assertThat(valueAsJson).isNotNull(); - assertThat(valueAsJson.containsKey(GraphSONTokens.TYPE)).isTrue(); - assertThat(valueAsJson.get(GraphSONTokens.TYPE)).isEqualTo(GraphSONTokens.TYPE_LONG); - assertThat(valueAsJson.containsKey(GraphSONTokens.VALUE)).isTrue(); - assertThat(valueAsJson.get(GraphSONTokens.VALUE)).isEqualTo(1000L); - } - } - - @Test - public void jsonFromElementVertexIntListPropertiesNoKeysWithTypes() { - Vertex v = this.graph.addVertex(1); - List list = new ArrayList<>(); - list.add(1); - list.add(1); - list.add(1); - - v.setProperty("keyList", list); - - JSONObject json = GraphsonUtil.jsonFromElement(v, null, GraphsonMode.EXTENDED); - - assertThat(json).isNotNull(); - assertThat(json.get(GraphSONTokens._ID)).isEqualTo("1"); - assertThat(json.containsKey("keyList")).isTrue(); - - JSONObject listWithTypeAsJson = (JSONObject) json.get("keyList"); - assertThat(listWithTypeAsJson.containsKey(GraphSONTokens.TYPE)).isTrue(); - assertThat(listWithTypeAsJson.get(GraphSONTokens.TYPE)).isEqualTo(GraphSONTokens.TYPE_LIST); - assertThat(listWithTypeAsJson.containsKey(GraphSONTokens.VALUE)).isTrue(); - - JSONArray listAsJSON = (JSONArray) listWithTypeAsJson.get(GraphSONTokens.VALUE); - assertThat(listAsJSON).isNotNull(); - assertThat(listAsJSON).hasSize(3); - - for (int ix = 0; ix < listAsJSON.size(); ix++) { - JSONObject valueAsJson = (JSONObject) listAsJSON.get(ix); - assertThat(valueAsJson).isNotNull(); - assertThat(valueAsJson.containsKey(GraphSONTokens.TYPE)).isTrue(); - assertThat(valueAsJson.get(GraphSONTokens.TYPE)).isEqualTo(GraphSONTokens.TYPE_INTEGER); - assertThat(valueAsJson.containsKey(GraphSONTokens.VALUE)).isTrue(); - assertThat(valueAsJson.get(GraphSONTokens.VALUE)).isEqualTo(1); - } - } - - @Test - public void jsonFromElementVertexListOfListPropertiesNoKeysWithTypes() { - Vertex v = this.graph.addVertex(1); - List list = new ArrayList<>(); - list.add(1); - list.add(1); - list.add(1); - - List> listList = new ArrayList<>(); - listList.add(list); - - v.setProperty("keyList", listList); - - JSONObject json = GraphsonUtil.jsonFromElement(v, null, GraphsonMode.EXTENDED); - - assertThat(json).isNotNull(); - assertThat(json.get(GraphSONTokens._ID)).isEqualTo("1"); - assertThat(json.containsKey("keyList")).isTrue(); - - JSONObject listWithTypeAsJson = (JSONObject) json.get("keyList"); - assertThat(listWithTypeAsJson.containsKey(GraphSONTokens.TYPE)).isTrue(); - assertThat(listWithTypeAsJson.get(GraphSONTokens.TYPE)).isEqualTo(GraphSONTokens.TYPE_LIST); - assertThat(listWithTypeAsJson.containsKey(GraphSONTokens.VALUE)).isTrue(); - - JSONArray array = (JSONArray) listWithTypeAsJson.get(GraphSONTokens.VALUE); - JSONObject obj = (JSONObject) array.get(0); - JSONArray listAsJSON = (JSONArray) obj.get(GraphSONTokens.VALUE); - assertThat(listAsJSON).isNotNull(); - assertThat(listAsJSON).hasSize(3); - - for (int ix = 0; ix < listAsJSON.size(); ix++) { - JSONObject valueAsJson = (JSONObject) listAsJSON.get(ix); - assertThat(valueAsJson).isNotNull(); - assertThat(valueAsJson.containsKey(GraphSONTokens.TYPE)).isTrue(); - assertThat(valueAsJson.get(GraphSONTokens.TYPE)).isEqualTo(GraphSONTokens.TYPE_INTEGER); - assertThat(valueAsJson.containsKey(GraphSONTokens.VALUE)).isTrue(); - assertThat(valueAsJson.get(GraphSONTokens.VALUE)).isEqualTo(1); - } - } - - @Test - public void jsonFromElementVertexMapPropertiesNoKeysWithTypes() { - Vertex v = this.graph.addVertex(1); - - Map map = new HashMap(); - map.put("this", "some"); - map.put("that", 1); - - v.setProperty("keyMap", map); - - JSONObject json = GraphsonUtil.jsonFromElement(v, null, GraphsonMode.EXTENDED); - - assertThat(json).isNotNull(); - assertThat(json.get(GraphSONTokens._ID)).isEqualTo("1"); - assertThat(json.containsKey("keyMap")).isTrue(); - - JSONObject mapWithTypeAsJSON = (JSONObject) json.get("keyMap"); - assertThat(mapWithTypeAsJSON).isNotNull(); - assertThat(mapWithTypeAsJSON.containsKey(GraphSONTokens.TYPE)).isTrue(); - assertThat(mapWithTypeAsJSON.get(GraphSONTokens.TYPE)).isEqualTo(GraphSONTokens.TYPE_MAP); - - assertThat(mapWithTypeAsJSON.containsKey(GraphSONTokens.VALUE)).isTrue(); - JSONObject mapAsJSON = (JSONObject) mapWithTypeAsJSON.get(GraphSONTokens.VALUE); - - assertThat(mapAsJSON.containsKey("this")).isTrue(); - JSONObject thisAsJson = (JSONObject) mapAsJSON.get("this"); - assertThat(thisAsJson.containsKey(GraphSONTokens.TYPE)).isTrue(); - assertThat(thisAsJson.get(GraphSONTokens.TYPE)).isEqualTo(GraphSONTokens.TYPE_STRING); - assertThat(thisAsJson.containsKey(GraphSONTokens.VALUE)).isTrue(); - assertThat(thisAsJson.get(GraphSONTokens.VALUE)).isEqualTo("some"); - - assertThat(mapAsJSON.containsKey("that")).isTrue(); - JSONObject thatAsJson = (JSONObject) mapAsJSON.get("that"); - assertThat(thatAsJson.containsKey(GraphSONTokens.TYPE)).isTrue(); - assertThat(thatAsJson.get(GraphSONTokens.TYPE)).isEqualTo(GraphSONTokens.TYPE_INTEGER); - assertThat(thatAsJson.containsKey(GraphSONTokens.VALUE)).isTrue(); - assertThat(thatAsJson.get(GraphSONTokens.VALUE)).isEqualTo(1); - } - - @Test - public void jsonFromElementNullsNoKeysNoTypes() { - Graph g = new TinkerGraph(); - Vertex v = g.addVertex(1); - v.setProperty("key", null); - - Map map = new HashMap<>(); - map.put("innerkey", null); - - List innerList = new ArrayList<>(); - innerList.add(null); - innerList.add("innerstring"); - map.put("list", innerList); - - v.setProperty("keyMap", map); - - List list = new ArrayList<>(); - list.add(null); - list.add("string"); - v.setProperty("keyList", list); - - JSONObject json = GraphsonUtil.jsonFromElement(v, null, GraphsonMode.NORMAL); - - assertThat(json).isNotNull(); - assertThat(json.get("key")).isNull(); - ; - - JSONObject jsonMap = (JSONObject) json.get("keyMap"); - assertThat(jsonMap).isNotNull(); - assertThat(jsonMap.get("innerkey")).isNull(); - - JSONArray jsonInnerArray = (JSONArray) jsonMap.get("list"); - assertThat(jsonInnerArray).isNotNull(); - assertThat(jsonInnerArray.get(0)).isNull(); - assertThat(jsonInnerArray.get(1)).isEqualTo("innerstring"); - - JSONArray jsonArray = (JSONArray) json.get("keyList"); - assertThat(jsonArray).isNotNull(); - assertThat(jsonArray.get(0)).isNull(); - assertThat(jsonArray.get(1)).isEqualTo("string"); - } - - @Test - public void jsonFromElementNullsNoKeysWithTypes() { - Graph g = new TinkerGraph(); - Vertex v = g.addVertex(1); - v.setProperty("key", null); - - Map map = new HashMap<>(); - map.put("innerkey", null); - - List innerList = new ArrayList<>(); - innerList.add(null); - innerList.add("innerstring"); - map.put("list", innerList); - - v.setProperty("keyMap", map); - - List list = new ArrayList<>(); - list.add(null); - list.add("string"); - v.setProperty("keyList", list); - - JSONObject json = GraphsonUtil.jsonFromElement(v, null, GraphsonMode.EXTENDED); - - - assertThat(json).isNotNull(); - JSONObject jsonObjectKey = (JSONObject) json.get("key"); - assertThat(jsonObjectKey.get(GraphSONTokens.VALUE)).isNull(); - assertThat(jsonObjectKey.get(GraphSONTokens.TYPE)).isEqualTo(GraphSONTokens.TYPE_UNKNOWN); - - JSONObject keyMap = (JSONObject) json.get("keyMap"); - JSONObject jsonMap = (JSONObject) keyMap.get(GraphSONTokens.VALUE); - assertThat(jsonMap).isNotNull(); - JSONObject jsonObjectMap = (JSONObject) jsonMap.get("innerkey"); - assertThat(jsonObjectMap.get(GraphSONTokens.VALUE)).isNull(); - assertThat(jsonObjectMap.get(GraphSONTokens.TYPE)).isEqualTo(GraphSONTokens.TYPE_UNKNOWN); - - JSONObject listJson = (JSONObject) jsonMap.get("list"); - JSONArray jsonInnerArray = (JSONArray) listJson.get(GraphSONTokens.VALUE); - assertThat(jsonInnerArray).isNotNull(); - JSONObject jsonObjectInnerListFirst = (JSONObject) jsonInnerArray.get(0); - assertThat(jsonObjectInnerListFirst.get(GraphSONTokens.VALUE)).isNull(); - assertThat(jsonObjectInnerListFirst.get(GraphSONTokens.TYPE)).isEqualTo(GraphSONTokens.TYPE_UNKNOWN); - - JSONObject keyList = (JSONObject) json.get("keyList"); - JSONArray jsonArray = (JSONArray) keyList.get(GraphSONTokens.VALUE); - assertThat(jsonArray).isNotNull(); - JSONObject jsonObjectListFirst = (JSONObject) jsonArray.get(0); - assertThat(jsonObjectListFirst.get(GraphSONTokens.VALUE)).isNull(); - assertThat(jsonObjectListFirst.get(GraphSONTokens.TYPE)).isEqualTo(GraphSONTokens.TYPE_UNKNOWN); - } - - @Test - public void vertexFromJsonValid() throws Exception { - Graph g = new TinkerGraph(); - ElementFactory factory = new ElementFactory(g); - - Vertex v = GraphsonUtil.vertexFromJson((JSONObject) JSONValue.parse(vertexJson1), factory, GraphsonMode.NORMAL, null); - - assertThat(v).isSameAs(g.getVertex(1)); - - // tinkergraph converts id to string - assertThat(v.getId()).isEqualTo("1"); - assertThat(v.getProperty("name")).isEqualTo("marko"); - assertThat(v.getProperty("age")).isEqualTo(29L); - } - - @Test - public void vertexFromJsonStringValid() throws Exception { - Graph g = new TinkerGraph(); - ElementFactory factory = new ElementFactory(g); - - Vertex v = GraphsonUtil.vertexFromJson(vertexJson1, factory, GraphsonMode.NORMAL, null); - - assertThat(v).isSameAs(g.getVertex(1)); - - // tinkergraph converts id to string - assertThat(v.getId()).isEqualTo("1"); - assertThat(v.getProperty("name")).isEqualTo("marko"); - assertThat(v.getProperty("age")).isEqualTo(29L); - } - - @Test - public void vertexFromJsonStringValidExtended() throws Exception { - Graph g = new TinkerGraph(); - ElementFactory factory = new ElementFactory(g); - - String vertexJson = "{\"person\":{\"value\":\"marko\",\"type\":\"string\"},\"_id\":1,\"_type\":\"vertex\"}"; - Vertex v = GraphsonUtil.vertexFromJson(vertexJson, factory, GraphsonMode.EXTENDED, null); - - Assert.assertSame(v, g.getVertex(1)); - - // tinkergraph converts id to string - Assert.assertEquals("1", v.getId()); - Assert.assertEquals("marko", v.getProperty("person")); - } - - @Test - public void vertexFromJsonInputStreamValid() throws Exception { - Graph g = new TinkerGraph(); - ElementFactory factory = new ElementFactory(g); - - Vertex v = GraphsonUtil.vertexFromJson(inputStreamVertexJson1, factory, GraphsonMode.NORMAL, null); - - Assert.assertSame(v, g.getVertex(1)); - - // tinkergraph converts id to string - Assert.assertEquals("1", v.getId()); - Assert.assertEquals("marko", v.getProperty("name")); - Assert.assertEquals(29L, v.getProperty("age")); - } - - @Test - public void vertexFromJsonIgnoreKeyValid() { - Graph g = new TinkerGraph(); - ElementFactory factory = new ElementFactory(g); - - Set ignoreAge = new HashSet<>(); - ignoreAge.add("age"); - ElementPropertyConfig config = ElementPropertyConfig.excludeProperties(ignoreAge, null); - GraphsonUtil utility = new GraphsonUtil(GraphsonMode.NORMAL, factory, config); - Vertex v = utility.vertexFromJson((JSONObject) JSONValue.parse(vertexJson1)); - - Assert.assertSame(v, g.getVertex(1)); - - // tinkergraph converts id to string - Assert.assertEquals("1", v.getId()); - Assert.assertEquals("marko", v.getProperty("name")); - Assert.assertNull(v.getProperty("age")); - } - - @Test - public void edgeFromJsonValid() throws Exception { - Graph g = new TinkerGraph(); - ElementFactory factory = new ElementFactory(g); - - Vertex v1 = GraphsonUtil.vertexFromJson((JSONObject) JSONValue.parse(vertexJson1), factory, GraphsonMode.NORMAL, null); - Vertex v2 = GraphsonUtil.vertexFromJson((JSONObject) JSONValue.parse(vertexJson2), factory, GraphsonMode.NORMAL, null); - Edge e = GraphsonUtil.edgeFromJson((JSONObject) JSONValue.parse(edgeJson), v1, v2, factory, GraphsonMode.NORMAL, null); - - Assert.assertSame(v1, g.getVertex(1)); - Assert.assertSame(v2, g.getVertex(2)); - Assert.assertSame(e, g.getEdge(7)); - - // tinkergraph converts id to string - Assert.assertEquals("7", e.getId()); - Assert.assertEquals(0.5d, e.getProperty("weight")); - Assert.assertEquals("knows", e.getLabel()); - Assert.assertEquals(v1, e.getVertex(Direction.OUT)); - Assert.assertEquals(v2, e.getVertex(Direction.IN)); - } - - @Test - public void edgeFromJsonStringValid() throws Exception { - Graph g = new TinkerGraph(); - ElementFactory factory = new ElementFactory(g); - - Vertex v1 = GraphsonUtil.vertexFromJson(vertexJson1, factory, GraphsonMode.NORMAL, null); - Vertex v2 = GraphsonUtil.vertexFromJson(vertexJson2, factory, GraphsonMode.NORMAL, null); - Edge e = GraphsonUtil.edgeFromJson(edgeJson, v1, v2, factory, GraphsonMode.NORMAL, null); - - Assert.assertSame(v1, g.getVertex(1)); - Assert.assertSame(v2, g.getVertex(2)); - Assert.assertSame(e, g.getEdge(7)); - - // tinkergraph converts id to string - Assert.assertEquals("7", e.getId()); - Assert.assertEquals(0.5d, e.getProperty("weight")); - Assert.assertEquals("knows", e.getLabel()); - Assert.assertEquals(v1, e.getVertex(Direction.OUT)); - Assert.assertEquals(v2, e.getVertex(Direction.IN)); - } - - @Test - public void edgeFromJsonIgnoreWeightValid() throws Exception { - Graph g = new TinkerGraph(); - ElementFactory factory = new ElementFactory(g); - - Vertex v1 = GraphsonUtil.vertexFromJson((JSONObject) JSONValue.parse(vertexJson1), factory, GraphsonMode.NORMAL, null); - Vertex v2 = GraphsonUtil.vertexFromJson((JSONObject) JSONValue.parse(vertexJson2), factory, GraphsonMode.NORMAL, null); - - Set ignoreWeight = new HashSet<>(); - ignoreWeight.add("weight"); - ElementPropertyConfig config = ElementPropertyConfig.excludeProperties(null, ignoreWeight); - GraphsonUtil utility = new GraphsonUtil(GraphsonMode.NORMAL, factory, config); - Edge e = utility.edgeFromJson((JSONObject) JSONValue.parse(edgeJson), v1, v2); - - Assert.assertSame(v1, g.getVertex(1)); - Assert.assertSame(v2, g.getVertex(2)); - Assert.assertSame(e, g.getEdge(7)); - - // tinkergraph converts id to string - Assert.assertEquals("7", e.getId()); - Assert.assertNull(e.getProperty("weight")); - Assert.assertEquals("knows", e.getLabel()); - Assert.assertEquals(v1, e.getVertex(Direction.OUT)); - Assert.assertEquals(v2, e.getVertex(Direction.IN)); - } - - @Test - public void edgeFromJsonNormalLabelOrIdOnEdge() throws Exception { - Graph g = new TinkerGraph(); - ElementFactory factory = new ElementFactory(g); - - Vertex v1 = GraphsonUtil.vertexFromJson((JSONObject) JSONValue.parse(vertexJson1), factory, GraphsonMode.NORMAL, null); - Vertex v2 = GraphsonUtil.vertexFromJson((JSONObject) JSONValue.parse(vertexJson2), factory, GraphsonMode.NORMAL, null); - Edge e = GraphsonUtil.edgeFromJson((JSONObject) JSONValue.parse(edgeJsonLight), v1, v2, factory, GraphsonMode.NORMAL, null); - - Assert.assertSame(v1, g.getVertex(1)); - Assert.assertSame(v2, g.getVertex(2)); - Assert.assertSame(e, g.getEdge(0)); - } - - @Test - public void edgeFromJsonInputStreamCompactLabelOrIdOnEdge() throws Exception { - Graph g = new TinkerGraph(); - ElementFactory factory = new ElementFactory(g); - - Vertex v1 = GraphsonUtil.vertexFromJson((JSONObject) JSONValue.parse(vertexJson1), factory, GraphsonMode.COMPACT, null); - Vertex v2 = GraphsonUtil.vertexFromJson((JSONObject) JSONValue.parse(vertexJson2), factory, GraphsonMode.COMPACT, null); - Edge e = GraphsonUtil.edgeFromJson(inputStreamEdgeJsonLight, v1, v2, factory, GraphsonMode.COMPACT, null); - - Assert.assertSame(v1, g.getVertex(1)); - Assert.assertSame(v2, g.getVertex(2)); - Assert.assertSame(e, g.getEdge(0)); - } - - @Test - public void edgeFromJsonInputStreamCompactNoIdOnEdge() throws Exception { - Graph g = new TinkerGraph(); - ElementFactory factory = new ElementFactory(g); - - Set vertexKeys = new HashSet() {{ - add(GraphSONTokens._ID); - }}; - - Set edgeKeys = new HashSet() {{ - add(GraphSONTokens._IN_V); - }}; - - GraphsonUtil graphson = new GraphsonUtil(GraphsonMode.COMPACT, factory, vertexKeys, edgeKeys); - - Vertex v1 = graphson.vertexFromJson((JSONObject) JSONValue.parse(vertexJson1)); - Vertex v2 = graphson.vertexFromJson((JSONObject) JSONValue.parse(vertexJson2)); - Edge e = graphson.edgeFromJson(inputStreamEdgeJsonLight, v1, v2); - - Assert.assertSame(v1, g.getVertex(1)); - Assert.assertSame(v2, g.getVertex(2)); - Assert.assertSame(e, g.getEdge(0)); - } - - private class Cat { - private String name; - - public Cat(String name) { - this.name = name; - } - - public String getName() { - return this.name; - } - - @Override - public String toString() { - return this.name; - } - } -} diff --git a/sonar-core/src/test/java/org/sonar/core/graph/graphson/GraphsonWriterTest.java b/sonar-core/src/test/java/org/sonar/core/graph/graphson/GraphsonWriterTest.java deleted file mode 100644 index 8a08894e871..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/graph/graphson/GraphsonWriterTest.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * 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.core.graph.graphson; - -import com.tinkerpop.blueprints.Graph; -import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.JSONValue; -import org.junit.Test; - -import java.io.StringWriter; - -import static org.assertj.core.api.Assertions.assertThat; - -public class GraphsonWriterTest { - - @Test - public void outputGraphNoEmbeddedTypes() throws Exception { - Graph g = TinkerGraphFactory.createTinkerGraph(); - - StringWriter stream = new StringWriter(); - - GraphsonWriter writer = new GraphsonWriter(); - writer.write(g, stream, GraphsonMode.NORMAL); - - stream.flush(); - stream.close(); - - String jsonString = stream.toString(); - - JSONObject rootNode = (JSONObject) JSONValue.parse(jsonString); - - // ensure that the JSON conforms to basic structure and that the right - // number of graph elements are present. other tests already cover element formatting - assertThat(rootNode).isNotNull(); - assertThat(rootNode.containsKey(GraphsonTokens.MODE)).isTrue(); - assertThat(rootNode.get(GraphsonTokens.MODE)).isEqualTo("NORMAL"); - - assertThat(rootNode.containsKey(GraphsonTokens.VERTICES)).isTrue(); - - JSONArray vertices = (JSONArray) rootNode.get(GraphsonTokens.VERTICES); - assertThat(vertices).hasSize(6); - - assertThat(rootNode.containsKey(GraphsonTokens.EDGES)).isTrue(); - - JSONArray edges = (JSONArray) rootNode.get(GraphsonTokens.EDGES); - assertThat(edges).hasSize(6); - } - - @Test - public void outputGraphWithEmbeddedTypes() throws Exception { - Graph g = TinkerGraphFactory.createTinkerGraph(); - - StringWriter stream = new StringWriter(); - - GraphsonWriter writer = new GraphsonWriter(); - writer.write(g, stream, GraphsonMode.EXTENDED); - - stream.flush(); - stream.close(); - - String jsonString = stream.toString(); - - JSONObject rootNode = (JSONObject) JSONValue.parse(jsonString); - - // ensure that the JSON conforms to basic structure and that the right - // number of graph elements are present. other tests already cover element formatting - assertThat(rootNode).isNotNull(); - assertThat(rootNode.containsKey(GraphsonTokens.MODE)).isTrue(); - assertThat(rootNode.get(GraphsonTokens.MODE)).isEqualTo("EXTENDED"); - - assertThat(rootNode.containsKey(GraphsonTokens.VERTICES)).isTrue(); - - JSONArray vertices = (JSONArray) rootNode.get(GraphsonTokens.VERTICES); - assertThat(vertices).hasSize(6); - - assertThat(rootNode.containsKey(GraphsonTokens.EDGES)).isTrue(); - - JSONArray edges = (JSONArray) rootNode.get(GraphsonTokens.EDGES); - assertThat(edges).hasSize(6); - } - - @Test - public void outputGraphWithCompact() throws Exception { - Graph g = TinkerGraphFactory.createTinkerGraph(); - - StringWriter stream = new StringWriter(); - - GraphsonWriter writer = new GraphsonWriter(); - writer.write(g, stream, GraphsonMode.COMPACT); - - stream.flush(); - stream.close(); - - String jsonString = stream.toString(); - - JSONObject rootNode = (JSONObject) JSONValue.parse(jsonString); - - // ensure that the JSON conforms to basic structure and that the right - // number of graph elements are present. other tests already cover element formatting - assertThat(rootNode).isNotNull(); - assertThat(rootNode.containsKey(GraphsonTokens.MODE)).isTrue(); - assertThat(rootNode.get(GraphsonTokens.MODE)).isEqualTo("COMPACT"); - - assertThat(rootNode.containsKey(GraphsonTokens.VERTICES)).isTrue(); - - JSONArray vertices = (JSONArray) rootNode.get(GraphsonTokens.VERTICES); - assertThat(vertices).hasSize(6); - - assertThat(rootNode.containsKey(GraphsonTokens.EDGES)).isTrue(); - - JSONArray edges = (JSONArray) rootNode.get(GraphsonTokens.EDGES); - assertThat(edges).hasSize(6); - } -} diff --git a/sonar-core/src/test/java/org/sonar/core/test/DefaultTestCaseTest.java b/sonar-core/src/test/java/org/sonar/core/test/DefaultTestCaseTest.java deleted file mode 100644 index 683460628a8..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/test/DefaultTestCaseTest.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * 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.core.test; - -import com.google.common.collect.Iterables; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.component.mock.MockSourceFile; -import org.sonar.api.test.CoverageBlock; -import org.sonar.api.test.TestCase; -import org.sonar.api.test.exception.CoverageAlreadyExistsException; -import org.sonar.api.test.exception.IllegalDurationException; -import org.sonar.core.component.ComponentVertex; -import org.sonar.core.component.ScanGraph; -import org.sonar.core.graph.BeanGraph; - -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; - -public class DefaultTestCaseTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void no_coverage_blocks() { - BeanGraph beanGraph = BeanGraph.createInMemory(); - DefaultTestCase testCase = beanGraph.createVertex(DefaultTestCase.class); - - assertThat(testCase.doesCover()).isFalse(); - assertThat(testCase.countCoveredLines()).isEqualTo(0); - assertThat(testCase.coverageBlocks()).isEmpty(); - } - - @Test - public void should_cover_testable() { - BeanGraph beanGraph = BeanGraph.createInMemory(); - DefaultTestable testable = beanGraph.createVertex(DefaultTestable.class); - DefaultTestCase testCase = beanGraph.createVertex(DefaultTestCase.class); - testCase.setCoverageBlock(testable, Arrays.asList(10, 11, 12)); - - assertThat(testCase.doesCover()).isTrue(); - assertThat(testCase.countCoveredLines()).isEqualTo(3); - assertThat(testCase.coverageBlocks()).hasSize(1); - - CoverageBlock cover = Iterables.getFirst(testCase.coverageBlocks(), null); - assertThat(cover.testCase()).isEqualTo(testCase); - assertThat(cover.testable()).isSameAs(testable); - assertThat(cover.lines()).containsExactly(10, 11, 12); - } - - @Test - public void should_cover_multiple_testables() { - ScanGraph graph = ScanGraph.create(); - ComponentVertex file1 = graph.addComponent(MockSourceFile.createMain("org.foo.Bar")); - DefaultTestable testable1 = graph.createAdjacentVertex(file1, DefaultTestable.class, "testable"); - ComponentVertex file2 = graph.addComponent(MockSourceFile.createMain("org.foo.File")); - DefaultTestable testable2 = graph.createAdjacentVertex(file2, DefaultTestable.class, "testable"); - DefaultTestCase testCase = graph.createVertex(DefaultTestCase.class); - - testCase.setCoverageBlock(testable1, Arrays.asList(10, 11, 12)); - testCase.setCoverageBlock(testable2, Arrays.asList(12, 13, 14)); - - assertThat(testCase.doesCover()).isTrue(); - assertThat(testCase.countCoveredLines()).isEqualTo(6); - assertThat(testCase.coverageBlocks()).hasSize(2); - } - - @Test - public void should_return_cover_of_testable() { - BeanGraph beanGraph = BeanGraph.createInMemory(); - - ScanGraph graph = ScanGraph.create(); - ComponentVertex file1 = graph.addComponent(MockSourceFile.createMain("org.foo.Bar")); - DefaultTestable testable1 = beanGraph.createAdjacentVertex(file1, DefaultTestable.class, "testable"); - - ComponentVertex file2 = graph.addComponent(MockSourceFile.createMain("org.foo.File")); - DefaultTestable testable2 = beanGraph.createAdjacentVertex(file2, DefaultTestable.class, "testable"); - - DefaultTestCase testCase = beanGraph.createVertex(DefaultTestCase.class); - testCase.setCoverageBlock(testable1, Arrays.asList(10, 11, 12)); - - assertThat(testCase.coverageBlock(testable1).testable()).isEqualTo(testable1); - assertThat(testCase.coverageBlock(testable1).testCase()).isEqualTo(testCase); - assertThat(testCase.coverageBlock(testable2)).isNull(); - } - - @Test - public void should_set_metadata() { - BeanGraph beanGraph = BeanGraph.createInMemory(); - DefaultTestCase testCase = beanGraph.createVertex(DefaultTestCase.class); - - testCase.setName("T1") - .setDurationInMs(1234L) - .setMessage("Error msg") - .setStackTrace("xxx") - .setType(TestCase.TYPE_UNIT) - .setStatus(TestCase.Status.ERROR); - - assertThat(testCase.name()).isEqualTo("T1"); - assertThat(testCase.message()).isEqualTo("Error msg"); - assertThat(testCase.stackTrace()).isEqualTo("xxx"); - assertThat(testCase.durationInMs()).isEqualTo(1234L); - assertThat(testCase.status()).isEqualTo(TestCase.Status.ERROR); - assertThat(testCase.type()).isEqualTo(TestCase.TYPE_UNIT); - } - - @Test - public void duration_should_be_positive() { - thrown.expect(IllegalDurationException.class); - thrown.expectMessage("Test duration must be positive (got: -1234)"); - - BeanGraph beanGraph = BeanGraph.createInMemory(); - DefaultTestCase testCase = beanGraph.createVertex(DefaultTestCase.class); - - testCase.setDurationInMs(-1234L); - } - - @Test - public void should_fail_if_coverage_block_already_exits() { - thrown.expect(CoverageAlreadyExistsException.class); - - ScanGraph graph = ScanGraph.create(); - - ComponentVertex file = graph.addComponent(MockSourceFile.createMain("org.foo.Bar")); - DefaultTestable testable = graph.createAdjacentVertex(file, DefaultTestable.class, "testable"); - - DefaultTestCase testCase = graph.createVertex(DefaultTestCase.class); - testCase.setCoverageBlock(testable, Arrays.asList(10, 11, 12)); - - // error - testCase.setCoverageBlock(testable, Arrays.asList(20)); - } -} diff --git a/sonar-core/src/test/java/org/sonar/core/test/DefaultTestPlanTest.java b/sonar-core/src/test/java/org/sonar/core/test/DefaultTestPlanTest.java deleted file mode 100644 index 27d39465ed4..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/test/DefaultTestPlanTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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.core.test; - -import com.google.common.collect.Iterables; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.test.MutableTestCase; -import org.sonar.core.graph.BeanGraph; - -import static org.assertj.core.api.Assertions.assertThat; - -public class DefaultTestPlanTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void should_not_have_test_cases() { - BeanGraph beanGraph = BeanGraph.createInMemory(); - - DefaultTestPlan plan = beanGraph.createVertex(DefaultTestPlan.class); - assertThat(plan.testCases()).isEmpty(); - } - - @Test - public void should_add_test_cases() { - BeanGraph beanGraph = BeanGraph.createInMemory(); - - DefaultTestPlan plan = beanGraph.createVertex(DefaultTestPlan.class); - plan.addTestCase("T1"); - plan.addTestCase("T2"); - - assertThat(plan.testCases()).hasSize(2); - MutableTestCase firstTestCase = Iterables.get(plan.testCases(), 0); - assertThat(firstTestCase.name()).isEqualTo("T1"); - assertThat(firstTestCase.testPlan()).isSameAs(plan); - - MutableTestCase secondTestCase = Iterables.get(plan.testCases(), 1); - assertThat(secondTestCase.name()).isEqualTo("T2"); - assertThat(secondTestCase.testPlan()).isSameAs(plan); - } - - @Test - public void should_find_test_case_by_name() { - BeanGraph beanGraph = BeanGraph.createInMemory(); - - DefaultTestPlan plan = beanGraph.createVertex(DefaultTestPlan.class); - plan.addTestCase("T1"); - plan.addTestCase("T2"); - - assertThat(plan.testCasesByName("T1")).hasSize(1); - assertThat(Iterables.get(plan.testCasesByName("T1"), 0).name()).isEqualTo("T1"); - assertThat(plan.testCasesByName("T3")).isEmpty(); - } - - @Test - public void should_find_multiple_test_cases_by_name() { - BeanGraph beanGraph = BeanGraph.createInMemory(); - - DefaultTestPlan plan = beanGraph.createVertex(DefaultTestPlan.class); - plan.addTestCase("T1"); - plan.addTestCase("T1"); - - assertThat(plan.testCasesByName("T1")).hasSize(2); - } -} diff --git a/sonar-core/src/test/java/org/sonar/core/test/DefaultTestableTest.java b/sonar-core/src/test/java/org/sonar/core/test/DefaultTestableTest.java deleted file mode 100644 index 23e92bb71d8..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/test/DefaultTestableTest.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * 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.core.test; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Iterables; -import org.junit.Test; -import org.sonar.api.component.mock.MockSourceFile; -import org.sonar.api.test.MutableTestCase; -import org.sonar.core.component.ComponentVertex; -import org.sonar.core.component.ScanGraph; -import org.sonar.core.graph.BeanGraph; - -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; - -public class DefaultTestableTest { - - @Test - public void not_have_tested_lines() { - BeanGraph beanGraph = BeanGraph.createInMemory(); - - DefaultTestable testable = beanGraph.createVertex(DefaultTestable.class); - assertThat(testable.testedLines()).isEmpty(); - } - - @Test - public void tested_lines() { - BeanGraph beanGraph = BeanGraph.createInMemory(); - - DefaultTestable testable = beanGraph.createVertex(DefaultTestable.class); - DefaultTestCase testCase1 = beanGraph.createVertex(DefaultTestCase.class); - testCase1.setCoverageBlock(testable, Arrays.asList(10, 11, 12)); - DefaultTestCase testCase2 = beanGraph.createVertex(DefaultTestCase.class); - testCase2.setCoverageBlock(testable, Arrays.asList(12, 48, 49)); - - assertThat(testable.testedLines()).containsOnly(10, 11, 12, 48, 49); - assertThat(testable.countTestCasesOfLine(2)).isEqualTo(0); - assertThat(testable.countTestCasesOfLine(10)).isEqualTo(1); - assertThat(testable.countTestCasesOfLine(12)).isEqualTo(2); - } - - @Test - public void get_test_cases() { - BeanGraph beanGraph = BeanGraph.createInMemory(); - - DefaultTestable testable = beanGraph.createVertex(DefaultTestable.class); - DefaultTestCase testCase1 = beanGraph.createVertex(DefaultTestCase.class); - testCase1.setCoverageBlock(testable, Arrays.asList(10, 11, 12)); - DefaultTestCase testCase2 = beanGraph.createVertex(DefaultTestCase.class); - testCase2.setCoverageBlock(testable, Arrays.asList(12, 48, 49)); - - assertThat(testable.testCases()).containsOnly(testCase1, testCase2); - assertThat(testable.testCasesOfLine(5)).isEmpty(); - assertThat(testable.testCasesOfLine(10)).containsExactly(testCase1); - assertThat(testable.testCasesOfLine(12)).contains(testCase1, testCase2); - } - - @Test - public void get_test_case_by_key() { - BeanGraph beanGraph = BeanGraph.createInMemory(); - - DefaultTestPlan plan = beanGraph.createVertex(DefaultTestPlan.class); - plan.addTestCase("T1"); - plan.addTestCase("T2"); - - DefaultTestable testable = beanGraph.createVertex(DefaultTestable.class); - MutableTestCase testCase1 = Iterables.get(plan.testCases(), 0); - testCase1.setCoverageBlock(testable, Arrays.asList(10, 11, 12)); - MutableTestCase testCase2 = Iterables.get(plan.testCases(), 1); - testCase2.setCoverageBlock(testable, Arrays.asList(12, 48, 49)); - - assertThat(testable.testCaseByName("T1")).isEqualTo(testCase1); - assertThat(testable.testCaseByName("T2")).isEqualTo(testCase2); - assertThat(testable.testCaseByName("Unknown")).isNull(); - } - - @Test - public void return_cover_of_testCase(){ - BeanGraph beanGraph = BeanGraph.createInMemory(); - - ScanGraph graph = ScanGraph.create(); - ComponentVertex file1 = graph.addComponent(MockSourceFile.createMain("org.foo.Bar")); - DefaultTestable testable1 = beanGraph.createAdjacentVertex(file1, DefaultTestable.class, "testable"); - - ComponentVertex file2 = graph.addComponent(MockSourceFile.createMain("org.foo.File")); - DefaultTestable testable2 = beanGraph.createAdjacentVertex(file2, DefaultTestable.class, "testable"); - - DefaultTestPlan plan = beanGraph.createVertex(DefaultTestPlan.class); - plan.addTestCase("T1"); - - MutableTestCase testCase = Iterables.get(plan.testCases(), 0); - testCase.setCoverageBlock(testable1, Arrays.asList(10, 11, 12)); - - assertThat(testable1.coverageBlock(testCase).testCase()).isEqualTo(testCase); - assertThat(testable1.coverageBlock(testCase).testable()).isEqualTo(testable1); - assertThat(testable2.coverageBlock(testCase)).isNull(); - } - - @Test - public void test_cases_by_lines() { - BeanGraph beanGraph = BeanGraph.createInMemory(); - - DefaultTestable testable = beanGraph.createVertex(DefaultTestable.class); - DefaultTestCase testCase1 = beanGraph.createVertex(DefaultTestCase.class); - testCase1.setCoverageBlock(testable, Arrays.asList(10, 11, 12)); - DefaultTestCase testCase2 = beanGraph.createVertex(DefaultTestCase.class); - testCase2.setCoverageBlock(testable, Arrays.asList(12, 48, 49)); - - assertThat(testable.testCasesByLines()).isEqualTo(ImmutableMap.of(49, 1, 48, 1, 10, 1, 11, 1, 12, 2)); - } -} 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 deleted file mode 100644 index 0b455e57cf8..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/test/TestPlanBuilderTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.core.test; - -import org.junit.Test; -import org.sonar.api.component.mock.MockSourceFile; -import org.sonar.api.test.MutableTestPlan; -import org.sonar.core.component.ComponentVertex; -import org.sonar.core.component.ScanGraph; - -import static org.assertj.core.api.Assertions.assertThat; - -public class TestPlanBuilderTest { - @Test - public void test_path() { - - ScanGraph graph = ScanGraph.create(); - TestPlanPerspectiveLoader loader = new TestPlanPerspectiveLoader(); - TestPlanBuilder builder = new TestPlanBuilder(graph, loader); - - assertThat(builder.path().getElements()).isNotEmpty(); - } - - @Test - public void should_not_load_missing_perspective() { - ScanGraph graph = ScanGraph.create(); - TestPlanPerspectiveLoader loader = new TestPlanPerspectiveLoader(); - TestPlanBuilder builder = new TestPlanBuilder(graph, loader); - ComponentVertex file = graph.addComponent(MockSourceFile.createMain("org.foo.Bar")); - - assertThat(builder.getPerspectiveLoader().load(file)).isNull(); - } - - @Test - public void should_create_perspective() { - ScanGraph graph = ScanGraph.create(); - TestPlanPerspectiveLoader loader = new TestPlanPerspectiveLoader(); - TestPlanBuilder builder = new TestPlanBuilder(graph, loader); - ComponentVertex file = graph.addComponent(MockSourceFile.createMain("org.foo.Bar")); - - MutableTestPlan plan = builder.create(file); - assertThat(plan).isNotNull(); - assertThat(plan.component()).isSameAs(file); - assertThat(builder.getPerspectiveLoader().load(file)).isSameAs(plan); - } -} 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 deleted file mode 100644 index e9a962fb237..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/test/TestableBuilderTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.core.test; - -import org.junit.Test; -import org.sonar.api.component.mock.MockSourceFile; -import org.sonar.api.test.MutableTestable; -import org.sonar.core.component.ComponentVertex; -import org.sonar.core.component.ScanGraph; - -import static org.assertj.core.api.Assertions.assertThat; - -public class TestableBuilderTest { - @Test - public void test_path() { - ScanGraph graph = ScanGraph.create(); - TestablePerspectiveLoader loader = new TestablePerspectiveLoader(); - TestableBuilder builder = new TestableBuilder(graph, loader); - - assertThat(builder.path().getElements()).isNotEmpty(); - } - - @Test - public void should_not_load_missing_perspective() { - ScanGraph graph = ScanGraph.create(); - TestablePerspectiveLoader loader = new TestablePerspectiveLoader(); - TestableBuilder builder = new TestableBuilder(graph, loader); - ComponentVertex file = graph.addComponent(MockSourceFile.createMain("org.foo.Bar")); - - assertThat(builder.getPerspectiveLoader().load(file)).isNull(); - } - - @Test - public void should_create_perspective() { - ScanGraph graph = ScanGraph.create(); - TestablePerspectiveLoader loader = new TestablePerspectiveLoader(); - TestableBuilder builder = new TestableBuilder(graph, loader); - ComponentVertex file = graph.addComponent(MockSourceFile.createMain("org.foo.Bar")); - - MutableTestable testable = builder.create(file); - assertThat(testable).isNotNull(); - assertThat(testable.component()).isSameAs(file); - assertThat(builder.getPerspectiveLoader().load(file)).isSameAs(testable); - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/component/Component.java b/sonar-plugin-api/src/main/java/org/sonar/api/component/Component.java index 098b469a172..9ae9872d603 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/component/Component.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/component/Component.java @@ -21,6 +21,10 @@ package org.sonar.api.component; import javax.annotation.CheckForNull; +/** + * @deprecated since 5.2 + */ +@Deprecated public interface Component { String key(); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/component/MutablePerspective.java b/sonar-plugin-api/src/main/java/org/sonar/api/component/MutablePerspective.java deleted file mode 100644 index 8395148c9cf..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/component/MutablePerspective.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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.api.component; - -public interface MutablePerspective extends Perspective { -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/component/Perspective.java b/sonar-plugin-api/src/main/java/org/sonar/api/component/Perspective.java index 9f5395c0a02..10bbed9a754 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/component/Perspective.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/component/Perspective.java @@ -19,6 +19,9 @@ */ package org.sonar.api.component; +/** + * @deprecated since 5.2 + */ +@Deprecated public interface Perspective { - C component(); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/component/Perspectives.java b/sonar-plugin-api/src/main/java/org/sonar/api/component/Perspectives.java deleted file mode 100644 index 58eff623a4e..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/component/Perspectives.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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.api.component; - -import org.sonar.api.batch.BatchSide; -import org.sonar.api.server.ServerSide; - -/** - * @deprecated since 5.2 unused - */ -@Deprecated -@BatchSide -@ServerSide -public interface Perspectives { - -

P as(Class

perspectiveClass, Component component); - -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/component/ResourcePerspectives.java b/sonar-plugin-api/src/main/java/org/sonar/api/component/ResourcePerspectives.java index 18bce8f9e36..c14cf64d622 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/component/ResourcePerspectives.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/component/ResourcePerspectives.java @@ -19,8 +19,10 @@ */ package org.sonar.api.component; +import javax.annotation.CheckForNull; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.InputPath; +import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.issue.Issuable; import org.sonar.api.resources.Resource; import org.sonar.api.source.Highlightable; @@ -28,8 +30,6 @@ import org.sonar.api.source.Symbolizable; import org.sonar.api.test.TestPlan; import org.sonar.api.test.Testable; -import javax.annotation.CheckForNull; - /** * Use this component to create perspective from resources or {@link InputPath} * Only on batch-side. @@ -57,8 +57,10 @@ import javax.annotation.CheckForNull; * @see Testable * @see TestPlan * @since 3.5 + * @deprecated since 5.2. Use appropriate methods on {@link SensorContext}. */ -public interface ResourcePerspectives extends Perspectives { +@Deprecated +public interface ResourcePerspectives { @CheckForNull

P as(Class

perspectiveClass, Resource resource); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestCase.java b/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestCase.java index 50a5e0c21ff..05e528885ba 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestCase.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestCase.java @@ -19,9 +19,9 @@ */ package org.sonar.api.test; -import javax.annotation.Nullable; - import java.util.List; +import javax.annotation.Nullable; +import org.sonar.api.batch.fs.InputFile; public interface MutableTestCase extends TestCase { MutableTestCase setStatus(@Nullable Status s); @@ -38,5 +38,11 @@ public interface MutableTestCase extends TestCase { @Deprecated MutableTestCase setType(@Nullable String s); + /** + * @deprecated since 5.2. Use {@link #setCoverageBlock(InputFile, List)} + */ + @Deprecated MutableTestCase setCoverageBlock(Testable testable, List lines); + + MutableTestCase setCoverageBlock(InputFile mainFile, List lines); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestPlan.java b/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestPlan.java index 4659917f0ee..020606d412b 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestPlan.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestPlan.java @@ -19,15 +19,13 @@ */ package org.sonar.api.test; -import org.sonar.api.component.MutablePerspective; - -public interface MutableTestPlan extends TestPlan, MutablePerspective { +public interface MutableTestPlan extends TestPlan { /** * Add a {@link TestCase} to this test file. * Note that a same physical test (for example in Java a single method annotated with @Test) * can be executed several times (parameterized tests, different test suites, ...). As a result it is perfectly valid to register several - * tests with the same name. Anyway in this situation the coverage per test. + * tests with the same name. Anyway in this situation the coverage per test will be merged for all tests with the same name. * @param name * @return */ diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestable.java b/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestable.java index be9c30892b1..c1812cef41e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestable.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestable.java @@ -19,8 +19,6 @@ */ package org.sonar.api.test; -import org.sonar.api.component.MutablePerspective; - -public interface MutableTestable extends Testable, MutablePerspective { +public interface MutableTestable extends Testable { } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/test/TestCase.java b/sonar-plugin-api/src/main/java/org/sonar/api/test/TestCase.java index 301d347f9af..f7296c4cf6c 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/test/TestCase.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/test/TestCase.java @@ -23,8 +23,9 @@ import javax.annotation.CheckForNull; import javax.annotation.Nullable; /** - * Represents a simple test execution result. + * @deprecated since 5.2 not used */ +@Deprecated public interface TestCase { enum Status { OK, FAILURE, ERROR, SKIPPED; @@ -75,5 +76,6 @@ public interface TestCase { Iterable coverageBlocks(); + @CheckForNull CoverageBlock coverageBlock(Testable testable); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/test/TestPlan.java b/sonar-plugin-api/src/main/java/org/sonar/api/test/TestPlan.java index 74b4291598e..ac1655c1522 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/test/TestPlan.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/test/TestPlan.java @@ -22,8 +22,9 @@ package org.sonar.api.test; import org.sonar.api.component.Perspective; /** - * A {@link TestPlan} is + * @deprecated since 5.2 not used */ +@Deprecated public interface TestPlan extends Perspective { Iterable testCases(); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/test/Testable.java b/sonar-plugin-api/src/main/java/org/sonar/api/test/Testable.java index 7091b6bee86..7b1c0c35a68 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/test/Testable.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/test/Testable.java @@ -19,12 +19,15 @@ */ package org.sonar.api.test; -import org.sonar.api.component.Perspective; - import java.util.List; import java.util.Map; import java.util.SortedSet; +import org.sonar.api.component.Perspective; +/** + * @deprecated since 5.2 + */ +@Deprecated public interface Testable extends Perspective { List testCases(); -- 2.39.5