diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-02-20 10:53:39 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-02-20 15:05:18 +0100 |
commit | 54beb6267d98d4e7429480bfbfaa70c8d1f73eff (patch) | |
tree | 996bac5291ac026eb7ce3d4fde217f4c5d300f55 /sonar-batch | |
parent | 884231b56a62223f15a52e98eb9ad1fcc0dcaefe (diff) | |
download | sonarqube-54beb6267d98d4e7429480bfbfaa70c8d1f73eff.tar.gz sonarqube-54beb6267d98d4e7429480bfbfaa70c8d1f73eff.zip |
SONAR-5931 Cleanup highlighting API
Diffstat (limited to 'sonar-batch')
14 files changed, 26 insertions, 175 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/highlighting/DefaultHighlightingBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/highlighting/DefaultHighlightingBuilder.java deleted file mode 100644 index 6682e32536c..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/highlighting/DefaultHighlightingBuilder.java +++ /dev/null @@ -1,54 +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.batch.highlighting; - -import org.sonar.api.batch.sensor.highlighting.TypeOfText; - -import com.google.common.base.Preconditions; -import org.sonar.api.batch.sensor.highlighting.HighlightingBuilder; -import org.sonar.batch.index.ComponentDataCache; -import org.sonar.core.source.SnapshotDataTypes; - -public class DefaultHighlightingBuilder implements HighlightingBuilder { - - private final SyntaxHighlightingDataBuilder builder; - private String componentKey; - private ComponentDataCache cache; - private boolean done = false; - - public DefaultHighlightingBuilder(String componentKey, ComponentDataCache cache) { - this.componentKey = componentKey; - this.cache = cache; - this.builder = new SyntaxHighlightingDataBuilder(); - } - - @Override - public HighlightingBuilder highlight(int startOffset, int endOffset, TypeOfText typeOfText) { - Preconditions.checkState(!done, "done() already called"); - builder.registerHighlightingRule(startOffset, endOffset, typeOfText); - return this; - } - - @Override - public void done() { - Preconditions.checkState(!done, "done() already called"); - cache.setData(componentKey, SnapshotDataTypes.SYNTAX_HIGHLIGHTING, builder.build()); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingData.java b/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingData.java index b1075a9ed19..7b9b334e15a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingData.java +++ b/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingData.java @@ -19,6 +19,7 @@ */ package org.sonar.batch.highlighting; +import org.sonar.api.batch.sensor.highlighting.internal.SyntaxHighlightingRule; import org.sonar.batch.index.Data; import java.util.ArrayList; diff --git a/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingDataBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingDataBuilder.java index da5166a9753..be0fa73a3e9 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingDataBuilder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingDataBuilder.java @@ -23,6 +23,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Ordering; import com.google.common.collect.Sets; import org.sonar.api.batch.sensor.highlighting.TypeOfText; +import org.sonar.api.batch.sensor.highlighting.internal.SyntaxHighlightingRule; import javax.annotation.Nullable; diff --git a/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingDataValueCoder.java b/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingDataValueCoder.java index 621c1e5c2f5..a748b499d57 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingDataValueCoder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingDataValueCoder.java @@ -22,6 +22,7 @@ package org.sonar.batch.highlighting; import com.persistit.Value; import com.persistit.encoding.CoderContext; import com.persistit.encoding.ValueCoder; +import org.sonar.api.batch.sensor.highlighting.internal.SyntaxHighlightingRule; import java.util.ArrayList; import java.util.List; diff --git a/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingRule.java b/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingRule.java deleted file mode 100644 index 81016289477..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingRule.java +++ /dev/null @@ -1,58 +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.batch.highlighting; - -import org.sonar.api.batch.sensor.highlighting.TypeOfText; - -import java.io.Serializable; - -public class SyntaxHighlightingRule implements Serializable { - - private final int startPosition; - private final int endPosition; - private final TypeOfText textType; - - private SyntaxHighlightingRule(int startPosition, int endPosition, TypeOfText textType) { - this.startPosition = startPosition; - this.endPosition = endPosition; - this.textType = textType; - } - - public static SyntaxHighlightingRule create(int startPosition, int endPosition, TypeOfText textType) { - return new SyntaxHighlightingRule(startPosition, endPosition, textType); - } - - public int getStartPosition() { - return startPosition; - } - - public int getEndPosition() { - return endPosition; - } - - public TypeOfText getTextType() { - return textType; - } - - @Override - public String toString() { - return "" + startPosition + "," + endPosition + "," + textType.cssClass(); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingRuleValueCoder.java b/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingRuleValueCoder.java index 3d69f717c6b..8700c81f345 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingRuleValueCoder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingRuleValueCoder.java @@ -19,11 +19,11 @@ */ package org.sonar.batch.highlighting; -import org.sonar.api.batch.sensor.highlighting.TypeOfText; - import com.persistit.Value; import com.persistit.encoding.CoderContext; import com.persistit.encoding.ValueCoder; +import org.sonar.api.batch.sensor.highlighting.TypeOfText; +import org.sonar.api.batch.sensor.highlighting.internal.SyntaxHighlightingRule; class SyntaxHighlightingRuleValueCoder implements ValueCoder { diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java b/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java index 6d1cfc1e7f1..edea3a94051 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java @@ -26,6 +26,7 @@ import org.sonar.api.BatchComponent; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.sensor.duplication.Duplication; import org.sonar.api.batch.sensor.duplication.internal.DefaultDuplication; +import org.sonar.api.batch.sensor.highlighting.internal.SyntaxHighlightingRule; import org.sonar.api.batch.sensor.symbol.Symbol; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Measure; @@ -33,7 +34,6 @@ import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.KeyValueFormat; import org.sonar.batch.duplication.DuplicationCache; import org.sonar.batch.highlighting.SyntaxHighlightingData; -import org.sonar.batch.highlighting.SyntaxHighlightingRule; import org.sonar.batch.scan.filesystem.InputFileMetadata; import org.sonar.batch.scan.measure.MeasureCache; import org.sonar.batch.source.CodeColorizers; 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 edde3baad06..8c07b72e5a6 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 @@ -29,6 +29,7 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.sensor.dependency.internal.DefaultDependency; import org.sonar.api.batch.sensor.duplication.Duplication; import org.sonar.api.batch.sensor.highlighting.TypeOfText; +import org.sonar.api.batch.sensor.highlighting.internal.SyntaxHighlightingRule; import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure; import org.sonar.api.batch.sensor.symbol.Symbol; import org.sonar.api.issue.Issue; @@ -37,7 +38,6 @@ import org.sonar.api.measures.Measure; import org.sonar.batch.dependency.DependencyCache; import org.sonar.batch.duplication.DuplicationCache; import org.sonar.batch.highlighting.SyntaxHighlightingData; -import org.sonar.batch.highlighting.SyntaxHighlightingRule; import org.sonar.batch.index.Cache.Entry; import org.sonar.batch.index.ComponentDataCache; import org.sonar.batch.issue.IssueCache; diff --git a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java b/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java index e010b83fca2..73a05a177b5 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java +++ b/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java @@ -29,7 +29,8 @@ import org.sonar.api.batch.sensor.dependency.NewDependency; import org.sonar.api.batch.sensor.dependency.internal.DefaultDependency; import org.sonar.api.batch.sensor.duplication.NewDuplication; import org.sonar.api.batch.sensor.duplication.internal.DefaultDuplication; -import org.sonar.api.batch.sensor.highlighting.HighlightingBuilder; +import org.sonar.api.batch.sensor.highlighting.NewHighlighting; +import org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting; import org.sonar.api.batch.sensor.internal.SensorStorage; import org.sonar.api.batch.sensor.issue.NewIssue; import org.sonar.api.batch.sensor.issue.internal.DefaultIssue; @@ -37,7 +38,6 @@ import org.sonar.api.batch.sensor.measure.NewMeasure; import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure; import org.sonar.api.batch.sensor.symbol.SymbolTableBuilder; import org.sonar.api.config.Settings; -import org.sonar.batch.highlighting.DefaultHighlightingBuilder; import org.sonar.batch.index.ComponentDataCache; import org.sonar.batch.symbol.DefaultSymbolTableBuilder; @@ -93,8 +93,8 @@ public class DefaultSensorContext implements SensorContext { } @Override - public HighlightingBuilder highlightingBuilder(InputFile inputFile) { - return new DefaultHighlightingBuilder(((DefaultInputFile) inputFile).key(), componentDataCache); + public NewHighlighting newHighlighting() { + return new DefaultHighlighting(sensorStorage); } @Override 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 170fd671daf..f91d3cdb25a 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 @@ -19,17 +19,18 @@ */ package org.sonar.batch.sensor; -import org.sonar.api.batch.sensor.internal.SensorStorage; - import com.google.common.base.Preconditions; import org.sonar.api.batch.fs.FileSystem; 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.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.measure.MetricFinder; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.batch.sensor.duplication.Duplication; import org.sonar.api.batch.sensor.duplication.internal.DefaultDuplication; +import org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting; +import org.sonar.api.batch.sensor.internal.SensorStorage; import org.sonar.api.batch.sensor.issue.Issue; import org.sonar.api.batch.sensor.issue.Issue.Severity; import org.sonar.api.batch.sensor.measure.Measure; @@ -51,12 +52,14 @@ import org.sonar.api.resources.Resource; import org.sonar.api.resources.Scopes; import org.sonar.api.rule.RuleKey; import org.sonar.batch.duplication.DuplicationCache; +import org.sonar.batch.highlighting.SyntaxHighlightingData; import org.sonar.batch.index.BatchResource; import org.sonar.batch.index.ComponentDataCache; import org.sonar.batch.index.DefaultIndex; import org.sonar.batch.index.ResourceCache; import org.sonar.batch.sensor.coverage.CoverageExclusions; import org.sonar.core.component.ComponentKeys; +import org.sonar.core.source.SnapshotDataTypes; public class DefaultSensorStorage implements SensorStorage { @@ -68,6 +71,7 @@ public class DefaultSensorStorage implements SensorStorage { private final CoverageExclusions coverageExclusions; private final DuplicationCache duplicationCache; private final ResourceCache resourceCache; + private final ComponentDataCache componentDataCache; public DefaultSensorStorage(MetricFinder metricFinder, Project project, ResourcePerspectives perspectives, @@ -77,6 +81,7 @@ public class DefaultSensorStorage implements SensorStorage { this.metricFinder = metricFinder; this.project = project; this.perspectives = perspectives; + this.componentDataCache = componentDataCache; this.sonarIndex = sonarIndex; this.coverageExclusions = coverageExclusions; this.duplicationCache = duplicationCache; @@ -238,4 +243,10 @@ public class DefaultSensorStorage implements SensorStorage { public void store(Duplication duplication) { duplicationCache.put(duplication.originBlock().resourceKey(), (DefaultDuplication) duplication); } + + @Override + public void store(DefaultHighlighting highlighting) { + String componentKey = ((DefaultInputFile) highlighting.inputFile()).key(); + componentDataCache.setData(componentKey, SnapshotDataTypes.SYNTAX_HIGHLIGHTING, new SyntaxHighlightingData(highlighting.getSyntaxHighlightingRuleSet())); + } } 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 0fbedcaeb22..bef343b872a 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 @@ -20,7 +20,6 @@ package org.sonar.batch.source; import org.sonar.api.batch.sensor.highlighting.TypeOfText; - import org.sonar.api.component.Component; import org.sonar.api.source.Highlightable; import org.sonar.batch.highlighting.SyntaxHighlightingDataBuilder; @@ -29,9 +28,7 @@ import org.sonar.core.source.SnapshotDataTypes; /** * @since 3.6 - * @deprecated since 4.5 no more used in batch 2.0 */ -@Deprecated public class DefaultHighlightable implements Highlightable { private final Component component; diff --git a/sonar-batch/src/test/java/org/sonar/batch/highlighting/DefaultHighlightingBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/highlighting/DefaultHighlightingBuilderTest.java deleted file mode 100644 index d5875d5c973..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/highlighting/DefaultHighlightingBuilderTest.java +++ /dev/null @@ -1,50 +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.batch.highlighting; - -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.sonar.api.batch.sensor.highlighting.TypeOfText; -import org.sonar.batch.index.ComponentDataCache; -import org.sonar.core.source.SnapshotDataTypes; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -public class DefaultHighlightingBuilderTest { - - @Test - public void should_apply_registered_highlighting() throws Exception { - - ComponentDataCache cache = mock(ComponentDataCache.class); - - DefaultHighlightingBuilder highlightable = new DefaultHighlightingBuilder("myComponent", cache); - highlightable - .highlight(0, 10, TypeOfText.KEYWORD) - .highlight(20, 30, TypeOfText.CPP_DOC) - .done(); - - ArgumentCaptor<SyntaxHighlightingData> argCaptor = ArgumentCaptor.forClass(SyntaxHighlightingData.class); - verify(cache).setData(eq("myComponent"), eq(SnapshotDataTypes.SYNTAX_HIGHLIGHTING), argCaptor.capture()); - assertThat(argCaptor.getValue().writeString()).isEqualTo("0,10,k;20,30,cppd"); - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/highlighting/SyntaxHighlightingDataBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/highlighting/SyntaxHighlightingDataBuilderTest.java index 40a8d5164f1..b4c4828b204 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/highlighting/SyntaxHighlightingDataBuilderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/highlighting/SyntaxHighlightingDataBuilderTest.java @@ -23,6 +23,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.sonar.api.batch.sensor.highlighting.internal.SyntaxHighlightingRule; import java.util.Collection; diff --git a/sonar-batch/src/test/java/org/sonar/batch/highlighting/SyntaxHighlightingDataTest.java b/sonar-batch/src/test/java/org/sonar/batch/highlighting/SyntaxHighlightingDataTest.java index cf8e825e5cb..dcebfe2893e 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/highlighting/SyntaxHighlightingDataTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/highlighting/SyntaxHighlightingDataTest.java @@ -21,6 +21,7 @@ package org.sonar.batch.highlighting; import com.google.common.collect.Lists; import org.junit.Test; +import org.sonar.api.batch.sensor.highlighting.internal.SyntaxHighlightingRule; import java.util.List; |