From: Julien HENRY
Date: Wed, 27 Aug 2014 08:31:46 +0000 (+0200)
Subject: Fix some quality flaws
X-Git-Tag: 4.5-RC1~77
X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b5e8fd0ef143c9309c30854ce6d8a1d19c2b138d;p=sonarqube.git
Fix some quality flaws
---
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/MeasureSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/MeasureSensor.java
index 56e013b3716..bc796808f19 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/MeasureSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/MeasureSensor.java
@@ -60,28 +60,32 @@ public class MeasureSensor implements Sensor {
int lineNumber = 0;
for (String line : lines) {
lineNumber++;
- if (StringUtils.isBlank(line)) {
+ if (StringUtils.isBlank(line) || line.startsWith("#")) {
continue;
}
- if (line.startsWith("#")) {
- continue;
- }
- try {
- String metricKey = StringUtils.substringBefore(line, ":");
- String value = line.substring(metricKey.length() + 1);
- context.addMeasure(createMeasure(context, inputFile, metricKey, value));
- } catch (Exception e) {
- throw new IllegalStateException("Error processing line " + lineNumber + " of file " + measureFile.getAbsolutePath(), e);
- }
+ processMeasure(inputFile, context, measureFile, lineNumber, line);
}
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new IllegalStateException(e);
}
}
}
+ private void processMeasure(InputFile inputFile, SensorContext context, File measureFile, int lineNumber, String line) {
+ try {
+ String metricKey = StringUtils.substringBefore(line, ":");
+ String value = line.substring(metricKey.length() + 1);
+ context.addMeasure(createMeasure(context, inputFile, metricKey, value));
+ } catch (Exception e) {
+ throw new IllegalStateException("Error processing line " + lineNumber + " of file " + measureFile.getAbsolutePath(), e);
+ }
+ }
+
private Measure> createMeasure(SensorContext context, InputFile xooFile, String metricKey, String value) {
org.sonar.api.batch.measure.Metric metric = metricFinder.findByKey(metricKey);
+ if (metric == null) {
+ throw new IllegalStateException("Unknow metric with key: " + metricKey);
+ }
MeasureBuilder builder = context.measureBuilder()
.forMetric(metric)
.onFile(xooFile);
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SyntaxHighlightingSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SyntaxHighlightingSensor.java
index 0ae23954442..ca2f6b5e0ac 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SyntaxHighlightingSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SyntaxHighlightingSensor.java
@@ -19,6 +19,8 @@
*/
package org.sonar.xoo.lang;
+import org.sonar.api.batch.sensor.highlighting.TypeOfText;
+
import com.google.common.base.Splitter;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
@@ -64,7 +66,7 @@ public class SyntaxHighlightingSensor implements Sensor {
Iterator split = Splitter.on(":").split(line).iterator();
int startOffset = Integer.parseInt(split.next());
int endOffset = Integer.parseInt(split.next());
- HighlightingBuilder.TypeOfText type = HighlightingBuilder.TypeOfText.forCssClass(split.next());
+ TypeOfText type = TypeOfText.forCssClass(split.next());
highlightingBuilder.highlight(startOffset, endOffset, type);
} catch (Exception e) {
throw new IllegalStateException("Error processing line " + lineNumber + " of file " + highlightingFile.getAbsolutePath(), e);
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
index 1399f66a438..6682e32536c 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/highlighting/DefaultHighlightingBuilder.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/highlighting/DefaultHighlightingBuilder.java
@@ -19,6 +19,8 @@
*/
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;
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 aba6bd66029..80e784d4211 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
@@ -19,10 +19,11 @@
*/
package org.sonar.batch.highlighting;
+import org.sonar.api.batch.sensor.highlighting.TypeOfText;
+
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Ordering;
import org.elasticsearch.common.collect.Sets;
-import org.sonar.api.batch.sensor.highlighting.HighlightingBuilder;
import javax.annotation.Nullable;
@@ -52,7 +53,7 @@ public class SyntaxHighlightingDataBuilder {
return syntaxHighlightingRuleSet;
}
- public SyntaxHighlightingDataBuilder registerHighlightingRule(int startOffset, int endOffset, HighlightingBuilder.TypeOfText typeOfText) {
+ public SyntaxHighlightingDataBuilder registerHighlightingRule(int startOffset, int endOffset, TypeOfText typeOfText) {
SyntaxHighlightingRule syntaxHighlightingRule = SyntaxHighlightingRule.create(startOffset, endOffset,
typeOfText);
this.syntaxHighlightingRuleSet.add(syntaxHighlightingRule);
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
index 9ccf5758557..bcfab67f476 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingRule.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingRule.java
@@ -19,7 +19,7 @@
*/
package org.sonar.batch.highlighting;
-import org.sonar.api.batch.sensor.highlighting.HighlightingBuilder;
+import org.sonar.api.batch.sensor.highlighting.TypeOfText;
import java.io.Serializable;
@@ -27,15 +27,15 @@ public class SyntaxHighlightingRule implements Serializable {
private final int startPosition;
private final int endPosition;
- private final HighlightingBuilder.TypeOfText textType;
+ private final TypeOfText textType;
- private SyntaxHighlightingRule(int startPosition, int endPosition, HighlightingBuilder.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, HighlightingBuilder.TypeOfText textType) {
+ public static SyntaxHighlightingRule create(int startPosition, int endPosition, TypeOfText textType) {
return new SyntaxHighlightingRule(startPosition, endPosition, textType);
}
@@ -47,7 +47,7 @@ public class SyntaxHighlightingRule implements Serializable {
return endPosition;
}
- public HighlightingBuilder.TypeOfText getTextType() {
+ public TypeOfText getTextType() {
return textType;
}
}
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 4cc9ea53ab8..3d69f717c6b 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,10 +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.HighlightingBuilder;
class SyntaxHighlightingRuleValueCoder implements ValueCoder {
@@ -38,7 +39,7 @@ class SyntaxHighlightingRuleValueCoder implements ValueCoder {
public Object get(Value value, Class clazz, CoderContext context) {
int startPosition = value.getInt();
int endPosition = value.getInt();
- HighlightingBuilder.TypeOfText type = HighlightingBuilder.TypeOfText.values()[value.getInt()];
+ TypeOfText type = TypeOfText.values()[value.getInt()];
return SyntaxHighlightingRule.create(startPosition, endPosition, type);
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java
index 2905cc6b0d7..bdb052ddc1e 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java
@@ -19,6 +19,8 @@
*/
package org.sonar.batch.mediumtest;
+import org.sonar.api.batch.sensor.highlighting.TypeOfText;
+
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,7 +32,6 @@ 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.sensor.duplication.DuplicationGroup;
-import org.sonar.api.batch.sensor.highlighting.HighlightingBuilder;
import org.sonar.api.batch.sensor.issue.Issue;
import org.sonar.api.batch.sensor.measure.Measure;
import org.sonar.api.batch.sensor.symbol.Symbol;
@@ -291,12 +292,12 @@ public class BatchMediumTester {
* @param charIndex 0-based offset in file
*/
@CheckForNull
- public List highlightingTypeFor(InputFile file, int charIndex) {
+ public List highlightingTypeFor(InputFile file, int charIndex) {
SyntaxHighlightingData syntaxHighlightingData = highlightingPerFile.get(file);
if (syntaxHighlightingData == null) {
return null;
}
- List result = new ArrayList();
+ List result = new ArrayList();
for (SyntaxHighlightingRule sortedRule : syntaxHighlightingData.syntaxHighlightingRuleSet()) {
if (sortedRule.getStartPosition() <= charIndex && sortedRule.getEndPosition() > charIndex) {
result.add(sortedRule.getTextType());
@@ -341,6 +342,7 @@ public class BatchMediumTester {
}
public FakeGlobalReferentialsLoader add(Metric metric) {
+ Boolean optimizedBestValue = metric.isOptimizedBestValue();
ref.metrics().add(new org.sonar.batch.protocol.input.Metric(metricId,
metric.key(),
metric.getType().name(),
@@ -351,7 +353,7 @@ public class BatchMediumTester {
metric.getUserManaged(),
metric.getWorstValue(),
metric.getBestValue(),
- metric.isOptimizedBestValue()));
+ optimizedBestValue != null ? optimizedBestValue : false));
metricId++;
return this;
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileEventsDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileEventsDecorator.java
index 28c1fea24c3..3de4a4b985b 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileEventsDecorator.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileEventsDecorator.java
@@ -84,7 +84,20 @@ public class QProfileEventsDecorator implements Decorator {
Measure currentMeasure = context.getMeasure(CoreMetrics.QUALITY_PROFILES);
Map currentProfiles = UsedQProfiles.fromJson(currentMeasure.getData()).profilesByKey();
- // Detect new profiles or updated profiles
+ detectNewOrUpdatedProfiles(context, previousProfiles, currentProfiles);
+
+ detectNoMoreUsedProfiles(context, previousProfiles, currentProfiles);
+ }
+
+ private void detectNoMoreUsedProfiles(DecoratorContext context, Map previousProfiles, Map currentProfiles) {
+ for (QProfile previousProfile : previousProfiles.values()) {
+ if (!currentProfiles.containsKey(previousProfile.getKey())) {
+ markAsRemoved(context, previousProfile);
+ }
+ }
+ }
+
+ private void detectNewOrUpdatedProfiles(DecoratorContext context, Map previousProfiles, Map currentProfiles) {
for (QProfile profile : currentProfiles.values()) {
QProfile previousProfile = previousProfiles.get(profile.getKey());
if (previousProfile != null) {
@@ -95,13 +108,6 @@ public class QProfileEventsDecorator implements Decorator {
markAsAdded(context, profile);
}
}
-
- // Detect profiles that are not used anymore
- for (QProfile previousProfile : previousProfiles.values()) {
- if (!currentProfiles.containsKey(previousProfile.getKey())) {
- markAsRemoved(context, previousProfile);
- }
- }
}
private void markAsChanged(DecoratorContext context, QProfile previousProfile, QProfile profile) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultSensorContext.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultSensorContext.java
index afd21a8d358..74b13c2e43e 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultSensorContext.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultSensorContext.java
@@ -130,8 +130,9 @@ public class DefaultSensorContext implements SensorContext {
@Override
public void addMeasure(Measure> measure) {
- if (measure.inputFile() != null) {
- measureCache.put(def.getKey(), ComponentKeys.createEffectiveKey(def.getKey(), measure.inputFile()), (DefaultMeasure) measure);
+ InputFile inputFile = measure.inputFile();
+ if (inputFile != null) {
+ measureCache.put(def.getKey(), ComponentKeys.createEffectiveKey(def.getKey(), inputFile), (DefaultMeasure) measure);
} else {
measureCache.put(def.getKey(), def.getKey(), (DefaultMeasure) measure);
}
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 b290c9a0dc9..0fbedcaeb22 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
@@ -19,7 +19,8 @@
*/
package org.sonar.batch.source;
-import org.sonar.api.batch.sensor.highlighting.HighlightingBuilder.TypeOfText;
+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;
@@ -71,7 +72,7 @@ public class DefaultHighlightable implements Highlightable {
@Override
public HighlightingBuilder highlight(int startOffset, int endOffset, String typeOfText) {
- TypeOfText type = org.sonar.api.batch.sensor.highlighting.HighlightingBuilder.TypeOfText.forCssClass(typeOfText);
+ TypeOfText type = org.sonar.api.batch.sensor.highlighting.TypeOfText.forCssClass(typeOfText);
builder.registerHighlightingRule(startOffset, endOffset, type);
return this;
}
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
index aefc5afd732..dcfdb8a1430 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/highlighting/DefaultHighlightingBuilderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/highlighting/DefaultHighlightingBuilderTest.java
@@ -21,7 +21,7 @@ package org.sonar.batch.highlighting;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
-import org.sonar.api.batch.sensor.highlighting.HighlightingBuilder.TypeOfText;
+import org.sonar.api.batch.sensor.highlighting.TypeOfText;
import org.sonar.batch.index.ComponentDataCache;
import org.sonar.core.source.SnapshotDataTypes;
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 4b192a47731..c132dcba477 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
@@ -27,9 +27,9 @@ import org.junit.rules.ExpectedException;
import java.util.Collection;
import static org.fest.assertions.Assertions.assertThat;
-import static org.sonar.api.batch.sensor.highlighting.HighlightingBuilder.TypeOfText.CLASSIC_COMMENT;
-import static org.sonar.api.batch.sensor.highlighting.HighlightingBuilder.TypeOfText.CPP_DOC;
-import static org.sonar.api.batch.sensor.highlighting.HighlightingBuilder.TypeOfText.KEYWORD;
+import static org.sonar.api.batch.sensor.highlighting.TypeOfText.COMMENT;
+import static org.sonar.api.batch.sensor.highlighting.TypeOfText.CPP_DOC;
+import static org.sonar.api.batch.sensor.highlighting.TypeOfText.KEYWORD;
public class SyntaxHighlightingDataBuilderTest {
@@ -42,12 +42,12 @@ public class SyntaxHighlightingDataBuilderTest {
public void setUpSampleRules() {
SyntaxHighlightingDataBuilder highlightingDataBuilder = new SyntaxHighlightingDataBuilder();
- highlightingDataBuilder.registerHighlightingRule(0, 10, CLASSIC_COMMENT);
+ highlightingDataBuilder.registerHighlightingRule(0, 10, COMMENT);
highlightingDataBuilder.registerHighlightingRule(10, 12, KEYWORD);
highlightingDataBuilder.registerHighlightingRule(24, 38, KEYWORD);
highlightingDataBuilder.registerHighlightingRule(42, 50, KEYWORD);
highlightingDataBuilder.registerHighlightingRule(24, 65, CPP_DOC);
- highlightingDataBuilder.registerHighlightingRule(12, 20, CLASSIC_COMMENT);
+ highlightingDataBuilder.registerHighlightingRule(12, 20, COMMENT);
highlightingRules = highlightingDataBuilder.getSyntaxHighlightingRuleSet();
}
@@ -61,7 +61,7 @@ public class SyntaxHighlightingDataBuilderTest {
public void should_order_by_start_then_end_offset() throws Exception {
assertThat(highlightingRules).onProperty("startPosition").containsOnly(0, 10, 12, 24, 24, 42);
assertThat(highlightingRules).onProperty("endPosition").containsOnly(10, 12, 20, 38, 65, 50);
- assertThat(highlightingRules).onProperty("textType").containsOnly(CLASSIC_COMMENT, KEYWORD, CLASSIC_COMMENT, KEYWORD, CPP_DOC, KEYWORD);
+ assertThat(highlightingRules).onProperty("textType").containsOnly(COMMENT, KEYWORD, COMMENT, KEYWORD, CPP_DOC, KEYWORD);
}
@Test
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 75a78d1becd..c7ab820408c 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
@@ -25,9 +25,9 @@ import org.junit.Test;
import java.util.List;
import static org.fest.assertions.Assertions.assertThat;
-import static org.sonar.api.batch.sensor.highlighting.HighlightingBuilder.TypeOfText.CLASSIC_COMMENT;
-import static org.sonar.api.batch.sensor.highlighting.HighlightingBuilder.TypeOfText.CPP_DOC;
-import static org.sonar.api.batch.sensor.highlighting.HighlightingBuilder.TypeOfText.KEYWORD;
+import static org.sonar.api.batch.sensor.highlighting.TypeOfText.COMMENT;
+import static org.sonar.api.batch.sensor.highlighting.TypeOfText.CPP_DOC;
+import static org.sonar.api.batch.sensor.highlighting.TypeOfText.KEYWORD;
public class SyntaxHighlightingDataTest {
@@ -35,9 +35,9 @@ public class SyntaxHighlightingDataTest {
public void should_serialize_rules_to_string() throws Exception {
List orderedHighlightingRules = Lists.newArrayList(
- SyntaxHighlightingRule.create(0, 10, CLASSIC_COMMENT),
+ SyntaxHighlightingRule.create(0, 10, COMMENT),
SyntaxHighlightingRule.create(10, 12, KEYWORD),
- SyntaxHighlightingRule.create(12, 20, CLASSIC_COMMENT),
+ SyntaxHighlightingRule.create(12, 20, COMMENT),
SyntaxHighlightingRule.create(24, 38, KEYWORD),
SyntaxHighlightingRule.create(24, 65, CPP_DOC),
SyntaxHighlightingRule.create(42, 50, KEYWORD)
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/highlighting/HighlightingMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/highlighting/HighlightingMediumTest.java
index b55a2125cbe..b6ce7fb7d52 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/highlighting/HighlightingMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/highlighting/HighlightingMediumTest.java
@@ -19,6 +19,8 @@
*/
package org.sonar.batch.mediumtest.highlighting;
+import org.sonar.api.batch.sensor.highlighting.TypeOfText;
+
import com.google.common.collect.ImmutableMap;
import org.apache.commons.io.FileUtils;
import org.junit.After;
@@ -28,7 +30,6 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestName;
import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.sensor.highlighting.HighlightingBuilder;
import org.sonar.batch.mediumtest.BatchMediumTester;
import org.sonar.batch.mediumtest.BatchMediumTester.TaskResult;
import org.sonar.xoo.XooPlugin;
@@ -87,10 +88,10 @@ public class HighlightingMediumTest {
.start();
InputFile file = result.inputFiles().get(0);
- assertThat(result.highlightingTypeFor(file, 0)).containsExactly(HighlightingBuilder.TypeOfText.STRING);
- assertThat(result.highlightingTypeFor(file, 9)).containsExactly(HighlightingBuilder.TypeOfText.STRING);
+ assertThat(result.highlightingTypeFor(file, 0)).containsExactly(TypeOfText.STRING);
+ assertThat(result.highlightingTypeFor(file, 9)).containsExactly(TypeOfText.STRING);
assertThat(result.highlightingTypeFor(file, 10)).isEmpty();
- assertThat(result.highlightingTypeFor(file, 11)).containsExactly(HighlightingBuilder.TypeOfText.KEYWORD);
+ assertThat(result.highlightingTypeFor(file, 11)).containsExactly(TypeOfText.KEYWORD);
}
@@ -126,7 +127,7 @@ public class HighlightingMediumTest {
System.out.println("Duration: " + (System.currentTimeMillis() - start));
InputFile file = result.inputFiles().get(0);
- assertThat(result.highlightingTypeFor(file, 0)).containsExactly(HighlightingBuilder.TypeOfText.STRING);
+ assertThat(result.highlightingTypeFor(file, 0)).containsExactly(TypeOfText.STRING);
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/ProjectClasspath.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/ProjectClasspath.java
index eac312f7cfc..6af187f6315 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/ProjectClasspath.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/ProjectClasspath.java
@@ -33,7 +33,9 @@ import java.util.List;
/**
* @since 2.2
+ * @deprecated since 4.5 this is some Java specific stuff that should by handled by SQ Java plugin
*/
+@Deprecated
public class ProjectClasspath implements BatchComponent {
protected MavenProject pom;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java
index 39888e030c3..34611ea5d98 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java
@@ -22,8 +22,6 @@ package org.sonar.api.batch.fs.internal;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.utils.PathUtils;
-import javax.annotation.CheckForNull;
-
import java.io.File;
import java.io.Serializable;
@@ -50,12 +48,7 @@ public class DefaultInputFile implements InputFile, Serializable {
return relativePath;
}
- /**
- * Marked as nullable just for the unit tests that do not call {@link #setFile(java.io.File)}
- * previously.
- */
@Override
- @CheckForNull
public String absolutePath() {
return absolutePath;
}
@@ -68,11 +61,6 @@ public class DefaultInputFile implements InputFile, Serializable {
return new File(absolutePath);
}
- /**
- * Marked as nullable just for the unit tests that do not call {@link #setLanguage(String)}
- * previously.
- */
- @CheckForNull
@Override
public String language() {
return language;
@@ -84,20 +72,16 @@ public class DefaultInputFile implements InputFile, Serializable {
}
/**
- * Marked as nullable just for the unit tests that do not previously call
* {@link #setStatus(org.sonar.api.batch.fs.InputFile.Status)}
*/
- @CheckForNull
@Override
public Status status() {
return status;
}
/**
- * Digest hash of the file. Marked as nullable just for the unit tests
- * that do not previously call {@link #setHash(String)}
+ * Digest hash of the file.
*/
- @CheckForNull
public String hash() {
return hash;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/DependsUponMavenPlugin.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/DependsUponMavenPlugin.java
index 0e590c84593..87b75459373 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/DependsUponMavenPlugin.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/DependsUponMavenPlugin.java
@@ -33,7 +33,9 @@ import org.sonar.api.resources.Project;
*
*
* @since 1.10
+ * @deprecated since 4.5 we don't want any dependency on Maven anymore
*/
+@Deprecated
@SupportedEnvironment("maven")
public interface DependsUponMavenPlugin extends BatchExtension {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenPlugin.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenPlugin.java
index 0f3da165a07..7df378027eb 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenPlugin.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenPlugin.java
@@ -34,7 +34,9 @@ import java.util.List;
* A class to handle maven plugins
*
* @since 1.10
+ * @deprecated since 4.5 we don't want any dependency on Maven anymore
*/
+@Deprecated
public class MavenPlugin {
private static final String CONFIGURATION_ELEMENT = "configuration";
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenPluginHandler.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenPluginHandler.java
index 6e98b50219d..5f98c19c528 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenPluginHandler.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenPluginHandler.java
@@ -27,7 +27,9 @@ import javax.annotation.Nullable;
/**
* @since 1.10
+ * @deprecated since 4.5 we don't want any dependency on Maven anymore
*/
+@Deprecated
public interface MavenPluginHandler extends BatchExtension {
/**
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenSurefireUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenSurefireUtils.java
index 2a3aed4cb32..fed72d6f041 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenSurefireUtils.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenSurefireUtils.java
@@ -23,7 +23,9 @@ import org.sonar.api.resources.Project;
/**
* @since 1.10
+ * @deprecated since 4.5 we don't want any dependency on Maven anymore
*/
+@Deprecated
public final class MavenSurefireUtils {
public static final String GROUP_ID = MavenUtils.GROUP_ID_APACHE_MAVEN;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenUtils.java
index 5419b7bc1e0..6fc76d56d9a 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenUtils.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenUtils.java
@@ -32,7 +32,9 @@ import java.util.Collection;
* An utility class to manipulate Maven concepts
*
* @since 1.10
+ * @deprecated since 4.5 we don't want any dependency on Maven anymore
*/
+@Deprecated
public final class MavenUtils {
private static final String MAVEN_COMPILER_PLUGIN = "maven-compiler-plugin";
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java
index d572d974af4..7465126c3e1 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java
@@ -134,7 +134,7 @@ public interface SensorContext {
// ------------ DUPLICATIONS ------------
/**
- * Builder to define tokens in a file. Tokens are used to compute duplication by the core.
+ * Builder to define tokens in a file. Tokens are used to compute duplication using default SonarQube engine.
* @since 4.5
*/
DuplicationTokenBuilder duplicationTokenBuilder(InputFile inputFile);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorDescriptor.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorDescriptor.java
index 3d4a3d913a5..9fcd030e553 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorDescriptor.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorDescriptor.java
@@ -56,7 +56,7 @@ public interface SensorDescriptor {
/**
* List {@link InputFile.Type} this {@link Sensor} work on. May be used by the platform to skip execution of the {@link Sensor} when
* no file for given type are present in the project.
- * If not type is provided then it will be executed for all types.
+ * If you don't call this method then it means sensor is working on all input file types.
*/
SensorDescriptor workOnFileTypes(InputFile.Type... types);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/DuplicationGroup.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/DuplicationGroup.java
index 9061e9165e3..280e8106246 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/DuplicationGroup.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/DuplicationGroup.java
@@ -20,6 +20,7 @@
package org.sonar.api.batch.sensor.duplication;
import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.batch.sensor.SensorContext;
@@ -137,6 +138,17 @@ public class DuplicationGroup {
return equalsBuilder.isEquals();
}
+ @Override
+ public int hashCode() {
+ HashCodeBuilder hcBuilder = new HashCodeBuilder(17, 37)
+ .append(originBlock)
+ .append(duplicates.size());
+ for (int i = 0; i < duplicates.size(); i++) {
+ hcBuilder.append(duplicates.get(i));
+ }
+ return hcBuilder.toHashCode();
+ }
+
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/HighlightingBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/HighlightingBuilder.java
index 0acc7848e22..d969ba49a03 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/HighlightingBuilder.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/HighlightingBuilder.java
@@ -25,43 +25,6 @@ package org.sonar.api.batch.sensor.highlighting;
*/
public interface HighlightingBuilder {
- /**
- * See sonar-colorizer.css
- */
- enum TypeOfText {
- ANNOTATION("a"),
- CONSTANT("c"),
- JAVADOC("j"),
- CLASSIC_COMMENT("cd"),
- CPP_DOC("cppd"),
- KEYWORD("k"),
- STRING("s"),
- KEYWORD_LIGHT("h"),
- PREPROCESS_DIRECTIVE("p");
-
- private final String cssClass;
-
- private TypeOfText(String cssClass) {
- this.cssClass = cssClass;
- }
-
- public static TypeOfText forCssClass(String cssClass) {
- for (TypeOfText typeOfText : TypeOfText.values()) {
- if (typeOfText.cssClass().equals(cssClass)) {
- return typeOfText;
- }
- }
- throw new IllegalArgumentException("No TypeOfText for CSS class " + cssClass);
- }
-
- /**
- * For internal use
- */
- public String cssClass() {
- return cssClass;
- }
- }
-
/**
* Call this method to indicate the type of text in a range.
* @param startOffset Starting position in file for this type of text. Beginning of a file starts with offset '0'.
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/TypeOfText.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/TypeOfText.java
new file mode 100644
index 00000000000..ae427944052
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/TypeOfText.java
@@ -0,0 +1,66 @@
+/*
+ * 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.batch.sensor.highlighting;
+
+/**
+ * Possible types for highlighting code.
+ * See sonar-colorizer.css
+ * @since 4.5
+ */
+public enum TypeOfText {
+ ANNOTATION("a"),
+ CONSTANT("c"),
+ COMMENT("cd"),
+ /**
+ * @deprecated use {@link #COMMENT}
+ */
+ @Deprecated
+ CPP_DOC("cppd"),
+ /**
+ * For example Javadoc
+ */
+ STRUCTURED_COMMENT("j"),
+ KEYWORD("k"),
+ STRING("s"),
+ KEYWORD_LIGHT("h"),
+ PREPROCESS_DIRECTIVE("p");
+
+ private final String cssClass;
+
+ private TypeOfText(String cssClass) {
+ this.cssClass = cssClass;
+ }
+
+ public static TypeOfText forCssClass(String cssClass) {
+ for (TypeOfText typeOfText : TypeOfText.values()) {
+ if (typeOfText.cssClass().equals(cssClass)) {
+ return typeOfText;
+ }
+ }
+ throw new IllegalArgumentException("No TypeOfText for CSS class " + cssClass);
+ }
+
+ /**
+ * For internal use
+ */
+ public String cssClass() {
+ return cssClass;
+ }
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java
index 870a8519271..af202228252 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java
@@ -679,9 +679,10 @@ public class Measure implements Serializable {
* @since 3.2
*/
public boolean isBestValue() {
+ Double bestValue = metric.getBestValue();
return metric.isOptimizedBestValue() == Boolean.TRUE
- && metric.getBestValue() != null
- && (value == null || NumberUtils.compare(metric.getBestValue(), value) == 0)
+ && bestValue != null
+ && (value == null || NumberUtils.compare(bestValue, value) == 0)
&& allNull(alertStatus, description, tendency, url, data)
&& isZeroVariation(variation1, variation2, variation3, variation4, variation5);
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java
index 93f874c8af7..5e16b420c2e 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java
@@ -475,7 +475,7 @@ public class Metric implements ServerExtension, BatchExt
/**
* @return this
*/
- public Metric setWorstValue(Double d) {
+ public Metric setWorstValue(@Nullable Double d) {
this.worstValue = d;
return this;
}
@@ -484,7 +484,7 @@ public class Metric implements ServerExtension, BatchExt
* @param bestValue the best value. It can be null.
* @return this
*/
- public Metric setBestValue(Double bestValue) {
+ public Metric setBestValue(@Nullable Double bestValue) {
this.bestValue = bestValue;
return this;
}
@@ -516,7 +516,7 @@ public class Metric implements ServerExtension, BatchExt
return ValueType.PERCENT.equals(type);
}
- public Metric setOptimizedBestValue(Boolean b) {
+ public Metric setOptimizedBestValue(@Nullable Boolean b) {
this.optimizedBestValue = b;
return this;
}