aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-xoo-plugin
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2018-06-22 16:03:36 +0200
committersonartech <sonartech@sonarsource.com>2018-06-29 09:10:16 +0200
commitca183f7f3f45e1ae2338f3a5c37d44fc0e295111 (patch)
tree53fe65285d19dd6874315c664bf89e61980a3eac /plugins/sonar-xoo-plugin
parente5827b3671013c14776ca189e400e3687bfa0983 (diff)
downloadsonarqube-ca183f7f3f45e1ae2338f3a5c37d44fc0e295111.tar.gz
sonarqube-ca183f7f3f45e1ae2338f3a5c37d44fc0e295111.zip
SONAR-10138 Remove support for API < 5.6
Diffstat (limited to 'plugins/sonar-xoo-plugin')
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java14
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/CpdTokenizerSensor.java3
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/LineMeasureSensor.java8
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java60
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SyntaxHighlightingSensor.java34
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooCpdMapping.java46
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooTokenizer.java60
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/AbstractDeprecatedXooRuleSensor.java71
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/CustomMessageSensor.java35
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/DeprecatedResourceApiSensor.java90
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneBlockerIssuePerFileSensor.java31
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneDayDebtPerFileSensor.java28
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerFileSensor.java31
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java2
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java3
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/test/TestExecutionSensor.java5
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java17
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java38
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SyntaxHighlightingSensorTest.java24
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/XooTokenizerTest.java87
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/XooRulesDefinitionTest.java2
21 files changed, 128 insertions, 561 deletions
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java
index 639d51c2172..82162851aa8 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java
@@ -37,13 +37,10 @@ import org.sonar.xoo.lang.MeasureSensor;
import org.sonar.xoo.lang.SignificantCodeSensor;
import org.sonar.xoo.lang.SymbolReferencesSensor;
import org.sonar.xoo.lang.SyntaxHighlightingSensor;
-import org.sonar.xoo.lang.XooCpdMapping;
-import org.sonar.xoo.lang.XooTokenizer;
import org.sonar.xoo.rule.AnalysisErrorSensor;
import org.sonar.xoo.rule.ChecksSensor;
import org.sonar.xoo.rule.CreateIssueByInternalKeySensor;
import org.sonar.xoo.rule.CustomMessageSensor;
-import org.sonar.xoo.rule.DeprecatedResourceApiSensor;
import org.sonar.xoo.rule.HasTagSensor;
import org.sonar.xoo.rule.MultilineIssuesSensor;
import org.sonar.xoo.rule.NoSonarSensor;
@@ -114,10 +111,6 @@ public class XooPlugin implements Plugin {
XooScmProvider.class,
XooBlameCommand.class,
- // CPD
- XooCpdMapping.class,
- XooTokenizer.class,
-
// sensors
HasTagSensor.class,
LineMeasureSensor.class,
@@ -127,6 +120,7 @@ public class XooPlugin implements Plugin {
RandomAccessSensor.class,
SaveDataTwiceSensor.class,
NoSonarSensor.class,
+ CpdTokenizerSensor.class,
OneBlockerIssuePerFileSensor.class,
OneIssuePerLineSensor.class,
@@ -161,13 +155,9 @@ public class XooPlugin implements Plugin {
XooPostJob.class);
if (context.getRuntime().getProduct() != SonarProduct.SONARLINT) {
- context.addExtensions(MeasureSensor.class,
- DeprecatedResourceApiSensor.class);
+ context.addExtension(MeasureSensor.class);
}
- if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(5, 5))) {
- context.addExtension(CpdTokenizerSensor.class);
- }
if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(6, 6))) {
context.addExtension(XooBuiltInQualityProfilesDefinition.class);
}
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/CpdTokenizerSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/CpdTokenizerSensor.java
index 591112eede2..9cf73d13429 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/CpdTokenizerSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/CpdTokenizerSensor.java
@@ -35,8 +35,6 @@ import org.sonar.xoo.Xoo;
*/
public class CpdTokenizerSensor implements Sensor {
- public static final String ENABLE_PROP = "sonar.xoo.useNewCpdTokenizerApi";
-
private void tokenize(InputFile inputFile, SensorContext context) {
int lineIdx = 1;
NewCpdTokens newCpdTokens = context.newCpdTokens().onFile(inputFile);
@@ -74,7 +72,6 @@ public class CpdTokenizerSensor implements Sensor {
public void describe(SensorDescriptor descriptor) {
descriptor
.name("Xoo Cpd Tokenizer Sensor")
- .onlyWhenConfiguration(conf -> conf.hasKey(ENABLE_PROP) || conf.hasKey(ENABLE_PROP + ".old"))
.onlyOnLanguages(Xoo.KEY);
}
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/LineMeasureSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/LineMeasureSensor.java
index fd43be898ac..1cf154658ad 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/LineMeasureSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/LineMeasureSensor.java
@@ -65,7 +65,7 @@ public class LineMeasureSensor implements Sensor {
if (StringUtils.isBlank(line) || line.startsWith("#")) {
continue;
}
- processMeasure(inputFile, linesContext, measureFile, lineNumber, line);
+ processMeasure(linesContext, measureFile, lineNumber, line);
}
linesContext.save();
} catch (IOException e) {
@@ -74,18 +74,18 @@ public class LineMeasureSensor implements Sensor {
}
}
- private void processMeasure(InputFile inputFile, FileLinesContext context, File measureFile, int lineNumber, String line) {
+ private void processMeasure(FileLinesContext context, File measureFile, int lineNumber, String line) {
try {
String metricKey = StringUtils.substringBefore(line, ":");
String value = line.substring(metricKey.length() + 1);
- saveMeasure(context, inputFile, metricKey, KeyValueFormat.parseIntInt(value));
+ saveMeasure(context, metricKey, KeyValueFormat.parseIntInt(value));
} catch (Exception e) {
LOG.error("Error processing line " + lineNumber + " of file " + measureFile.getAbsolutePath(), e);
throw new IllegalStateException("Error processing line " + lineNumber + " of file " + measureFile.getAbsolutePath(), e);
}
}
- private void saveMeasure(FileLinesContext context, InputFile xooFile, String metricKey, Map<Integer, Integer> values) {
+ private void saveMeasure(FileLinesContext context, String metricKey, Map<Integer, Integer> values) {
for (Map.Entry<Integer, Integer> entry : values.entrySet()) {
context.setIntValue(metricKey, entry.getKey(), entry.getValue());
}
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java
index 7eb5f8289d2..d3882c3f15b 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java
@@ -30,9 +30,8 @@ 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.api.component.ResourcePerspectives;
-import org.sonar.api.source.Symbol;
-import org.sonar.api.source.Symbolizable;
+import org.sonar.api.batch.sensor.symbol.NewSymbol;
+import org.sonar.api.batch.sensor.symbol.NewSymbolTable;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.xoo.Xoo;
@@ -43,15 +42,8 @@ import org.sonar.xoo.Xoo;
public class SymbolReferencesSensor implements Sensor {
private static final Logger LOG = Loggers.get(SymbolReferencesSensor.class);
-
private static final String SYMBOL_EXTENSION = ".symbol";
- private ResourcePerspectives perspectives;
-
- public SymbolReferencesSensor(ResourcePerspectives perspectives) {
- this.perspectives = perspectives;
- }
-
private void processFileSymbol(InputFile inputFile, SensorContext context) {
File ioFile = inputFile.file();
File symbolFile = new File(ioFile.getParentFile(), ioFile.getName() + SYMBOL_EXTENSION);
@@ -60,57 +52,55 @@ public class SymbolReferencesSensor implements Sensor {
try {
List<String> lines = FileUtils.readLines(symbolFile, context.fileSystem().encoding().name());
int lineNumber = 0;
- Symbolizable symbolizable = perspectives.as(Symbolizable.class, inputFile);
- if (symbolizable != null) {
- Symbolizable.SymbolTableBuilder symbolTableBuilder = symbolizable.newSymbolTableBuilder();
- for (String line : lines) {
- lineNumber++;
- if (StringUtils.isBlank(line) || line.startsWith("#")) {
- continue;
- }
- processLine(symbolFile, lineNumber, symbolTableBuilder, line);
+ NewSymbolTable symbolTable = context.newSymbolTable()
+ .onFile(inputFile);
+
+ for (String line : lines) {
+ lineNumber++;
+ if (StringUtils.isBlank(line) || line.startsWith("#")) {
+ continue;
}
- symbolizable.setSymbolTable(symbolTableBuilder.build());
+ processLine(symbolFile, lineNumber, symbolTable, line);
}
+ symbolTable.save();
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
}
- private static void processLine(File symbolFile, int lineNumber, Symbolizable.SymbolTableBuilder symbolTableBuilder, String line) {
+ private static void processLine(File symbolFile, int lineNumber, NewSymbolTable symbolTable, String line) {
try {
Iterator<String> split = Splitter.on(",").split(line).iterator();
+ Iterator<String> symbolOffsets = Splitter.on(":").split(split.next()).iterator();
+
+ int startOffset = Integer.parseInt(symbolOffsets.next());
+ int endOffset = Integer.parseInt(symbolOffsets.next());
+ int defaultLen = endOffset - startOffset;
+
+ NewSymbol s = symbolTable.newSymbol(startOffset, endOffset);
- Symbol s = addSymbol(symbolTableBuilder, split.next());
while (split.hasNext()) {
- addReference(symbolTableBuilder, s, split.next());
+ addReference(s, split.next(), defaultLen);
}
} catch (Exception e) {
throw new IllegalStateException("Error processing line " + lineNumber + " of file " + symbolFile.getAbsolutePath(), e);
}
}
- private static void addReference(Symbolizable.SymbolTableBuilder symbolTableBuilder, Symbol s, String str) {
+ private static void addReference(NewSymbol s, String str, int defaultLen) {
if (str.contains(":")) {
Iterator<String> split = Splitter.on(":").split(str).iterator();
int startOffset = Integer.parseInt(split.next());
int toOffset = Integer.parseInt(split.next());
- symbolTableBuilder.newReference(s, startOffset, toOffset);
+
+ s.newReference(startOffset, toOffset);
} else {
- symbolTableBuilder.newReference(s, Integer.parseInt(str));
+ int startOffset = Integer.parseInt(str);
+ s.newReference(startOffset, startOffset + defaultLen);
}
}
- private static Symbol addSymbol(Symbolizable.SymbolTableBuilder symbolTableBuilder, String str) {
- Iterator<String> split = Splitter.on(":").split(str).iterator();
-
- int startOffset = Integer.parseInt(split.next());
- int endOffset = Integer.parseInt(split.next());
-
- return symbolTableBuilder.newSymbol(startOffset, endOffset);
- }
-
@Override
public void describe(SensorDescriptor descriptor) {
descriptor
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 c1a848a1c28..8012f6152e3 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
@@ -30,9 +30,8 @@ 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.api.component.ResourcePerspectives;
-import org.sonar.api.source.Highlightable;
-import org.sonar.api.source.Highlightable.HighlightingBuilder;
+import org.sonar.api.batch.sensor.highlighting.NewHighlighting;
+import org.sonar.api.batch.sensor.highlighting.TypeOfText;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.xoo.Xoo;
@@ -43,15 +42,8 @@ import org.sonar.xoo.Xoo;
public class SyntaxHighlightingSensor implements Sensor {
private static final Logger LOG = Loggers.get(SyntaxHighlightingSensor.class);
-
private static final String HIGHLIGHTING_EXTENSION = ".highlighting";
- private final ResourcePerspectives perspectives;
-
- public SyntaxHighlightingSensor(ResourcePerspectives perspectives) {
- this.perspectives = perspectives;
- }
-
private void processFileHighlighting(InputFile inputFile, SensorContext context) {
File ioFile = inputFile.file();
File highlightingFile = new File(ioFile.getParentFile(), ioFile.getName() + HIGHLIGHTING_EXTENSION);
@@ -60,30 +52,28 @@ public class SyntaxHighlightingSensor implements Sensor {
try {
List<String> lines = FileUtils.readLines(highlightingFile, context.fileSystem().encoding().name());
int lineNumber = 0;
- Highlightable highlightable = perspectives.as(Highlightable.class, inputFile);
- if (highlightable != null) {
- HighlightingBuilder highlightingBuilder = highlightable.newHighlighting();
- for (String line : lines) {
- lineNumber++;
- if (StringUtils.isBlank(line) || line.startsWith("#")) {
- continue;
- }
- processLine(highlightingFile, lineNumber, highlightingBuilder, line);
+ NewHighlighting highlighting = context.newHighlighting()
+ .onFile(inputFile);
+ for (String line : lines) {
+ lineNumber++;
+ if (StringUtils.isBlank(line) || line.startsWith("#")) {
+ continue;
}
- highlightingBuilder.done();
+ processLine(highlightingFile, lineNumber, highlighting, line);
}
+ highlighting.save();
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
}
- private static void processLine(File highlightingFile, int lineNumber, HighlightingBuilder highlightingBuilder, String line) {
+ private static void processLine(File highlightingFile, int lineNumber, NewHighlighting highlighting, String line) {
try {
Iterator<String> split = Splitter.on(":").split(line).iterator();
int startOffset = Integer.parseInt(split.next());
int endOffset = Integer.parseInt(split.next());
- highlightingBuilder.highlight(startOffset, endOffset, split.next());
+ highlighting.highlight(startOffset, endOffset, TypeOfText.forCssClass(split.next()));
} catch (Exception e) {
throw new IllegalStateException("Error processing line " + lineNumber + " of file " + highlightingFile.getAbsolutePath(), e);
}
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooCpdMapping.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooCpdMapping.java
deleted file mode 100644
index 44f51bd292b..00000000000
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooCpdMapping.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2018 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.xoo.lang;
-
-import net.sourceforge.pmd.cpd.Tokenizer;
-import org.sonar.api.batch.AbstractCpdMapping;
-import org.sonar.api.resources.Language;
-import org.sonar.xoo.Xoo;
-
-public class XooCpdMapping extends AbstractCpdMapping {
-
- private Xoo xoo;
- private XooTokenizer xooTokenizer;
-
- public XooCpdMapping(Xoo xoo, XooTokenizer xooTokenizer) {
- this.xoo = xoo;
- this.xooTokenizer = xooTokenizer;
- }
-
- @Override
- public Tokenizer getTokenizer() {
- return xooTokenizer;
- }
-
- @Override
- public Language getLanguage() {
- return xoo;
- }
-}
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooTokenizer.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooTokenizer.java
deleted file mode 100644
index 896ff1bd27f..00000000000
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooTokenizer.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2018 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.xoo.lang;
-
-import com.google.common.base.Splitter;
-import java.io.File;
-import java.io.IOException;
-import net.sourceforge.pmd.cpd.SourceCode;
-import net.sourceforge.pmd.cpd.TokenEntry;
-import net.sourceforge.pmd.cpd.Tokenizer;
-import net.sourceforge.pmd.cpd.Tokens;
-import org.apache.commons.io.FileUtils;
-import org.sonar.api.batch.ScannerSide;
-import org.sonar.api.batch.fs.FileSystem;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
-
-@ScannerSide
-public class XooTokenizer implements Tokenizer {
-
- private static final Logger LOG = Loggers.get(XooTokenizer.class);
-
- private FileSystem fs;
-
- public XooTokenizer(FileSystem fs) {
- this.fs = fs;
- }
-
- @Override
- public final void tokenize(SourceCode source, Tokens cpdTokens) {
- String fileName = source.getFileName();
- LOG.info("Using deprecated tokenizer extension point to tokenize {}", fileName);
- int lineIdx = 1;
- for (String line : source.getCode()) {
- for (String token : Splitter.on(" ").split(line)) {
- TokenEntry cpdToken = new TokenEntry(token, fileName, lineIdx);
- cpdTokens.add(cpdToken);
- }
- lineIdx++;
- }
- cpdTokens.add(TokenEntry.getEOF());
- }
-}
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/AbstractDeprecatedXooRuleSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/AbstractDeprecatedXooRuleSensor.java
deleted file mode 100644
index 23fa6922d94..00000000000
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/AbstractDeprecatedXooRuleSensor.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2018 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.xoo.rule;
-
-import org.sonar.api.batch.Sensor;
-import org.sonar.api.batch.SensorContext;
-import org.sonar.api.batch.fs.FileSystem;
-import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.rule.ActiveRules;
-import org.sonar.api.resources.File;
-import org.sonar.api.resources.Project;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.xoo.Xoo;
-
-/**
- * @deprecated to be replaced by {@link org.sonar.api.batch.sensor.Sensor}
- */
-public abstract class AbstractDeprecatedXooRuleSensor implements Sensor {
-
- private final FileSystem fs;
- private final ActiveRules activeRules;
-
- public AbstractDeprecatedXooRuleSensor(FileSystem fs, ActiveRules activeRules) {
- this.fs = fs;
- this.activeRules = activeRules;
- }
-
- protected abstract String getRuleKey();
-
- @Override
- public boolean shouldExecuteOnProject(Project project) {
- return fs.hasFiles(fs.predicates().hasLanguages(Xoo.KEY))
- && (activeRules.find(RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, getRuleKey())) != null);
- }
-
- @Override
- public final void analyse(Project project, SensorContext context) {
- doAnalyse(context, Xoo.KEY);
- }
-
- private void doAnalyse(SensorContext context, String languageKey) {
- RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, getRuleKey());
- if (activeRules.find(ruleKey) == null) {
- return;
- }
- for (InputFile inputFile : fs.inputFiles(fs.predicates().hasLanguage(languageKey))) {
- File sonarFile = File.create(inputFile.relativePath());
- sonarFile = context.getResource(sonarFile);
- processFile(inputFile, sonarFile, context, ruleKey, languageKey);
- }
- }
-
- protected abstract void processFile(InputFile inputFile, File sonarFile, SensorContext context, RuleKey ruleKey, String languageKey);
-}
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/CustomMessageSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/CustomMessageSensor.java
index 5032cd45eaa..f7d22a4c4e2 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/CustomMessageSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/CustomMessageSensor.java
@@ -19,27 +19,25 @@
*/
package org.sonar.xoo.rule;
-import org.sonar.api.batch.SensorContext;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.rule.ActiveRules;
-import org.sonar.api.component.ResourcePerspectives;
-import org.sonar.api.config.Settings;
-import org.sonar.api.issue.Issuable;
+import org.sonar.api.batch.sensor.SensorContext;
+import org.sonar.api.batch.sensor.issue.NewIssue;
+import org.sonar.api.batch.sensor.issue.NewIssueLocation;
+import org.sonar.api.config.Configuration;
import org.sonar.api.rule.RuleKey;
-public class CustomMessageSensor extends AbstractDeprecatedXooRuleSensor {
+public class CustomMessageSensor extends AbstractXooRuleSensor {
public static final String RULE_KEY = "CustomMessage";
private static final String MESSAGE_PROPERTY = "sonar.customMessage.message";
- private final ResourcePerspectives perspectives;
- private final Settings settings;
+ private final Configuration settings;
- public CustomMessageSensor(ResourcePerspectives perspectives, Settings settings, FileSystem fs, ActiveRules activeRules) {
+ public CustomMessageSensor(Configuration settings, FileSystem fs, ActiveRules activeRules) {
super(fs, activeRules);
- this.perspectives = perspectives;
this.settings = settings;
}
@@ -48,14 +46,15 @@ public class CustomMessageSensor extends AbstractDeprecatedXooRuleSensor {
return RULE_KEY;
}
- @Override
- protected void processFile(InputFile inputFile, org.sonar.api.resources.File sonarFile, SensorContext context, RuleKey ruleKey, String languageKey) {
- Issuable issuable = perspectives.as(Issuable.class, sonarFile);
- if (issuable != null) {
- issuable.addIssue(issuable.newIssueBuilder()
- .ruleKey(ruleKey)
- .message(settings.getString(MESSAGE_PROPERTY))
- .build());
- }
+ @Override protected void processFile(InputFile inputFile, SensorContext context, RuleKey ruleKey, String languageKey) {
+ NewIssue newIssue = context.newIssue()
+ .forRule(ruleKey);
+
+ NewIssueLocation location = newIssue.newLocation().on(inputFile);
+ settings.get(MESSAGE_PROPERTY).ifPresent(location::message);
+
+ newIssue
+ .at(location)
+ .save();
}
}
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/DeprecatedResourceApiSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/DeprecatedResourceApiSensor.java
deleted file mode 100644
index df3f9fc21c3..00000000000
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/DeprecatedResourceApiSensor.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2018 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.xoo.rule;
-
-import java.io.File;
-import org.sonar.api.batch.Sensor;
-import org.sonar.api.batch.fs.FileSystem;
-import org.sonar.api.batch.fs.InputFile.Type;
-import org.sonar.api.batch.rule.ActiveRules;
-import org.sonar.api.component.ResourcePerspectives;
-import org.sonar.api.issue.Issuable;
-import org.sonar.api.resources.Directory;
-import org.sonar.api.resources.Project;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.api.scan.filesystem.PathResolver;
-import org.sonar.xoo.Xoo;
-
-@SuppressWarnings("deprecation")
-public class DeprecatedResourceApiSensor implements Sensor {
-
- public static final String RULE_KEY = "DeprecatedResourceApi";
- private final FileSystem fs;
- private final ResourcePerspectives perspectives;
- private final ActiveRules activeRules;
-
- public DeprecatedResourceApiSensor(FileSystem fileSystem, ResourcePerspectives perspectives, ActiveRules activeRules) {
- this.fs = fileSystem;
- this.perspectives = perspectives;
- this.activeRules = activeRules;
- }
-
- @Override
- public boolean shouldExecuteOnProject(Project project) {
- return fs.hasFiles(fs.predicates().and(fs.predicates().hasType(Type.MAIN), fs.predicates().hasLanguage(Xoo.KEY)))
- && activeRules.find(RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY)) != null;
- }
-
- @Override
- public void analyse(Project module, org.sonar.api.batch.SensorContext context) {
- for (File f : fs.files(fs.predicates().and(fs.predicates().hasType(Type.MAIN), fs.predicates().hasLanguage(Xoo.KEY)))) {
- String relativePathFromBaseDir = new PathResolver().relativePath(fs.baseDir(), f);
- org.sonar.api.resources.File sonarFile = org.sonar.api.resources.File.create(relativePathFromBaseDir);
- Issuable issuable = perspectives.as(Issuable.class, sonarFile);
- issuable.addIssue(issuable.newIssueBuilder()
- .ruleKey(RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY))
- .message("Issue created using deprecated API")
- .line(1)
- .build());
-
- // Message and line are nullable
- issuable.addIssue(issuable.newIssueBuilder()
- .ruleKey(RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY))
- .message(null)
- .line(null)
- .build());
-
- sonarFile = context.getResource(sonarFile);
- Directory parent = sonarFile.getParent();
- createIssueOnDir(parent);
- }
-
- }
-
- private Directory createIssueOnDir(Directory dir) {
- Issuable issuable = perspectives.as(Issuable.class, dir);
- issuable.addIssue(issuable.newIssueBuilder()
- .ruleKey(RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY))
- .message("Issue created using deprecated API")
- .build());
- return dir;
- }
-
-}
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneBlockerIssuePerFileSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneBlockerIssuePerFileSensor.java
index 4eb1d9c5ba9..9766d528389 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneBlockerIssuePerFileSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneBlockerIssuePerFileSensor.java
@@ -19,24 +19,20 @@
*/
package org.sonar.xoo.rule;
-import org.sonar.api.batch.SensorContext;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.rule.ActiveRules;
-import org.sonar.api.component.ResourcePerspectives;
-import org.sonar.api.issue.Issuable;
+import org.sonar.api.batch.rule.Severity;
+import org.sonar.api.batch.sensor.SensorContext;
+import org.sonar.api.batch.sensor.issue.NewIssue;
import org.sonar.api.rule.RuleKey;
-import org.sonar.api.rule.Severity;
-public class OneBlockerIssuePerFileSensor extends AbstractDeprecatedXooRuleSensor {
+public class OneBlockerIssuePerFileSensor extends AbstractXooRuleSensor {
public static final String RULE_KEY = "OneBlockerIssuePerFile";
- private final ResourcePerspectives perspectives;
-
- public OneBlockerIssuePerFileSensor(ResourcePerspectives perspectives, FileSystem fs, ActiveRules activeRules) {
+ public OneBlockerIssuePerFileSensor(FileSystem fs, ActiveRules activeRules) {
super(fs, activeRules);
- this.perspectives = perspectives;
}
@Override
@@ -44,14 +40,13 @@ public class OneBlockerIssuePerFileSensor extends AbstractDeprecatedXooRuleSenso
return RULE_KEY;
}
- @Override
- protected void processFile(InputFile inputFile, org.sonar.api.resources.File sonarFile, SensorContext context, RuleKey ruleKey, String languageKey) {
- Issuable issuable = perspectives.as(Issuable.class, sonarFile);
- issuable.addIssue(issuable.newIssueBuilder()
- .ruleKey(ruleKey)
- .severity(Severity.BLOCKER)
- .message("This issue is generated on each file. Severity is blocker, whatever quality profile")
- .build());
+ @Override protected void processFile(InputFile inputFile, SensorContext context, RuleKey ruleKey, String languageKey) {
+ NewIssue newIssue = context.newIssue()
+ .overrideSeverity(Severity.BLOCKER)
+ .forRule(ruleKey);
+ newIssue.at(newIssue.newLocation()
+ .on(inputFile)
+ .message("This issue is generated on each file. Severity is blocker, whatever quality profile"))
+ .save();
}
-
}
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneDayDebtPerFileSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneDayDebtPerFileSensor.java
index 03619e69b0f..022feef7fc9 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneDayDebtPerFileSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneDayDebtPerFileSensor.java
@@ -19,23 +19,19 @@
*/
package org.sonar.xoo.rule;
-import org.sonar.api.batch.SensorContext;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.rule.ActiveRules;
-import org.sonar.api.component.ResourcePerspectives;
-import org.sonar.api.issue.Issuable;
+import org.sonar.api.batch.sensor.SensorContext;
+import org.sonar.api.batch.sensor.issue.NewIssue;
import org.sonar.api.rule.RuleKey;
-public class OneDayDebtPerFileSensor extends AbstractDeprecatedXooRuleSensor {
+public class OneDayDebtPerFileSensor extends AbstractXooRuleSensor {
public static final String RULE_KEY = "OneDayDebtPerFile";
- private final ResourcePerspectives perspectives;
-
- public OneDayDebtPerFileSensor(ResourcePerspectives perspectives, FileSystem fs, ActiveRules activeRules) {
+ public OneDayDebtPerFileSensor(FileSystem fs, ActiveRules activeRules) {
super(fs, activeRules);
- this.perspectives = perspectives;
}
@Override
@@ -43,15 +39,13 @@ public class OneDayDebtPerFileSensor extends AbstractDeprecatedXooRuleSensor {
return RULE_KEY;
}
- @Override
- protected void processFile(InputFile inputFile, org.sonar.api.resources.File sonarFile, SensorContext context, RuleKey ruleKey, String languageKey) {
- Issuable issuable = perspectives.as(Issuable.class, sonarFile);
- if (issuable != null) {
- issuable.addIssue(issuable.newIssueBuilder()
- .ruleKey(ruleKey)
- .message("This issue is generated on each file with a debt of one day")
- .build());
- }
+ @Override protected void processFile(InputFile inputFile, SensorContext context, RuleKey ruleKey, String languageKey) {
+ NewIssue newIssue = context.newIssue()
+ .forRule(ruleKey);
+ newIssue.at(newIssue.newLocation()
+ .on(inputFile)
+ .message("This issue is generated on each file with a debt of one day"))
+ .save();
}
}
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerFileSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerFileSensor.java
index b5de515d953..162fff4fced 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerFileSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerFileSensor.java
@@ -19,27 +19,24 @@
*/
package org.sonar.xoo.rule;
-import org.sonar.api.batch.SensorContext;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.rule.ActiveRules;
-import org.sonar.api.component.ResourcePerspectives;
-import org.sonar.api.config.Settings;
-import org.sonar.api.issue.Issuable;
+import org.sonar.api.batch.sensor.SensorContext;
+import org.sonar.api.batch.sensor.issue.NewIssue;
+import org.sonar.api.config.Configuration;
import org.sonar.api.rule.RuleKey;
-public class OneIssuePerFileSensor extends AbstractDeprecatedXooRuleSensor {
+public class OneIssuePerFileSensor extends AbstractXooRuleSensor {
public static final String RULE_KEY = "OneIssuePerFile";
private static final String EFFORT_TO_FIX_PROPERTY = "sonar.oneIssuePerFile.effortToFix";
- private final ResourcePerspectives perspectives;
- private final Settings settings;
+ private final Configuration settings;
- public OneIssuePerFileSensor(ResourcePerspectives perspectives, Settings settings, FileSystem fs, ActiveRules activeRules) {
+ public OneIssuePerFileSensor(Configuration settings, FileSystem fs, ActiveRules activeRules) {
super(fs, activeRules);
- this.perspectives = perspectives;
this.settings = settings;
}
@@ -48,13 +45,13 @@ public class OneIssuePerFileSensor extends AbstractDeprecatedXooRuleSensor {
return RULE_KEY;
}
- @Override
- protected void processFile(InputFile inputFile, org.sonar.api.resources.File sonarFile, SensorContext context, RuleKey ruleKey, String languageKey) {
- Issuable issuable = perspectives.as(Issuable.class, sonarFile);
- issuable.addIssue(issuable.newIssueBuilder()
- .ruleKey(ruleKey)
- .effortToFix(settings.getDouble(EFFORT_TO_FIX_PROPERTY))
- .message("This issue is generated on each file")
- .build());
+ @Override protected void processFile(InputFile inputFile, SensorContext context, RuleKey ruleKey, String languageKey) {
+ NewIssue newIssue = context.newIssue()
+ .forRule(ruleKey)
+ .gap(settings.getDouble(EFFORT_TO_FIX_PROPERTY).orElse(0.0));
+ newIssue.at(newIssue.newLocation()
+ .on(inputFile)
+ .message("This issue is generated on each file"))
+ .save();
}
}
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java
index f7467f9f4b2..33f2a8fc6a6 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java
@@ -76,7 +76,7 @@ public class OneIssuePerLineSensor implements Sensor {
if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(5, 5))) {
newIssue.gap(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY));
} else {
- newIssue.effortToFix(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY));
+ newIssue.gap(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY));
}
newIssue.save();
}
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java
index 4f119f9ebe0..5b072445cf4 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java
@@ -125,9 +125,6 @@ public class XooRulesDefinition implements RulesDefinition {
repo.createRule(RandomAccessSensor.RULE_KEY).setName("One Issue Per File with Random Access")
.setHtmlDescription("This issue is generated on each file");
- repo.createRule(DeprecatedResourceApiSensor.RULE_KEY).setName("Issue created using deprecated API")
- .setHtmlDescription("Issue created using deprecated API");
-
repo.createRule(MultilineIssuesSensor.RULE_KEY).setName("Creates issues with ranges/multiple locations")
.setHtmlDescription("Issue with range and multiple locations");
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/test/TestExecutionSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/test/TestExecutionSensor.java
index 19aff15e8f9..eb5543bb8c9 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/test/TestExecutionSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/test/TestExecutionSensor.java
@@ -37,7 +37,7 @@ import org.sonar.api.batch.sensor.SensorDescriptor;
import org.sonar.api.component.ResourcePerspectives;
import org.sonar.api.test.MutableTestCase;
import org.sonar.api.test.MutableTestPlan;
-import org.sonar.api.test.TestCase.Status;
+import org.sonar.api.test.TestCase;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.xoo.Xoo;
@@ -88,7 +88,7 @@ public class TestExecutionSensor implements Sensor {
testCase.setDurationInMs(duration);
testCase.setMessage(msg);
testCase.setStackTrace(stack);
- testCase.setStatus(Status.valueOf(status));
+ testCase.setStatus(TestCase.Status.valueOf(status));
testCase.setType(type);
} catch (Exception e) {
throw new IllegalStateException("Error processing line " + lineNumber + " of file " + testExecutionFile.getAbsolutePath(), e);
@@ -115,4 +115,5 @@ public class TestExecutionSensor implements Sensor {
}
}
+
}
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java
index e66d56e45c8..3efce09bee8 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java
@@ -28,25 +28,18 @@ import org.sonar.api.internal.SonarRuntimeImpl;
import org.sonar.api.utils.Version;
import org.sonar.xoo.lang.CpdTokenizerSensor;
import org.sonar.xoo.rule.OneExternalIssuePerLineSensor;
+import org.sonar.xoo.rule.XooBuiltInQualityProfilesDefinition;
import static org.assertj.core.api.Assertions.assertThat;
public class XooPluginTest {
@Test
- public void provide_extensions_for_5_4() {
+ public void provide_extensions_for_5_6() {
SonarRuntime runtime = SonarRuntimeImpl.forSonarLint(Version.parse("5.4"));
Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build();
new XooPlugin().define(context);
- assertThat(context.getExtensions()).hasSize(47).doesNotContain(CpdTokenizerSensor.class);
- }
-
- @Test
- public void provide_extensions_for_5_5() {
- SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("5.5"), SonarQubeSide.SCANNER);
- Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build();
- new XooPlugin().define(context);
- assertThat(context.getExtensions()).hasSize(50).contains(CpdTokenizerSensor.class);
+ assertThat(context.getExtensions()).hasSize(46).doesNotContain(XooBuiltInQualityProfilesDefinition.class);
}
@Test
@@ -54,7 +47,7 @@ public class XooPluginTest {
SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("6.6"), SonarQubeSide.SCANNER);
Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build();
new XooPlugin().define(context);
- assertThat(context.getExtensions()).hasSize(52).contains(CpdTokenizerSensor.class);
+ assertThat(context.getExtensions()).hasSize(49).contains(XooBuiltInQualityProfilesDefinition.class);
}
@Test
@@ -62,6 +55,6 @@ public class XooPluginTest {
SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("7.2"), SonarQubeSide.SCANNER);
Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build();
new XooPlugin().define(context);
- assertThat(context.getExtensions()).hasSize(55).contains(OneExternalIssuePerLineSensor.class);
+ assertThat(context.getExtensions()).hasSize(52).contains(OneExternalIssuePerLineSensor.class);
}
}
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java
index 9dc9f998316..cff6a4d332f 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java
@@ -27,32 +27,27 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.internal.DefaultTextPointer;
+import org.sonar.api.batch.fs.internal.DefaultTextRange;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
import org.sonar.api.batch.sensor.internal.SensorContextTester;
-import org.sonar.api.component.ResourcePerspectives;
-import org.sonar.api.source.Symbol;
-import org.sonar.api.source.Symbolizable;
+import org.sonar.xoo.Xoo;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.assertj.core.api.Assertions.assertThat;
public class SymbolReferencesSensorTest {
- private SymbolReferencesSensor sensor;
+ private SymbolReferencesSensor sensor = new SymbolReferencesSensor();
private SensorContextTester context;
@Rule
public TemporaryFolder temp = new TemporaryFolder();
private File baseDir;
- private ResourcePerspectives perspectives;
@Before
public void prepare() throws IOException {
baseDir = temp.newFolder();
- perspectives = mock(ResourcePerspectives.class);
- sensor = new SymbolReferencesSensor(perspectives);
context = SensorContextTester.create(baseDir);
}
@@ -72,24 +67,19 @@ public class SymbolReferencesSensorTest {
public void testExecution() throws IOException {
File symbol = new File(baseDir, "src/foo.xoo.symbol");
FileUtils.write(symbol, "1:4,7\n12:15,23:33\n\n#comment");
- InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage("xoo").setModuleBaseDir(baseDir.toPath()).build();
+ InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo")
+ .initMetadata("xoo file with some source code and length over 33")
+ .setLanguage(Xoo.KEY)
+ .setModuleBaseDir(baseDir.toPath())
+ .build();
context.fileSystem().add(inputFile);
- Symbolizable symbolizable = mock(Symbolizable.class);
- when(perspectives.as(Symbolizable.class, inputFile)).thenReturn(symbolizable);
- Symbolizable.SymbolTableBuilder symbolTableBuilder = mock(Symbolizable.SymbolTableBuilder.class);
- when(symbolizable.newSymbolTableBuilder()).thenReturn(symbolTableBuilder);
-
- Symbol symbol1 = mock(Symbol.class);
- when(symbolTableBuilder.newSymbol(1, 4)).thenReturn(symbol1);
- Symbol symbol2 = mock(Symbol.class);
- when(symbolTableBuilder.newSymbol(12, 15)).thenReturn(symbol2);
sensor.execute(context);
- verify(symbolTableBuilder).newSymbol(1, 4);
- verify(symbolTableBuilder).newReference(symbol1, 7);
- verify(symbolTableBuilder).newSymbol(12, 15);
- verify(symbolTableBuilder).newReference(symbol2, 23, 33);
+ assertThat(context.referencesForSymbolAt("foo:src/foo.xoo", 1, 2))
+ .containsOnly(new DefaultTextRange(new DefaultTextPointer(1, 7), new DefaultTextPointer(1,10)));
+ assertThat(context.referencesForSymbolAt("foo:src/foo.xoo", 1, 13))
+ .containsOnly(new DefaultTextRange(new DefaultTextPointer(1, 23), new DefaultTextPointer(1,33)));
}
}
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SyntaxHighlightingSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SyntaxHighlightingSensorTest.java
index 97f90433469..861f1ebee21 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SyntaxHighlightingSensorTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SyntaxHighlightingSensorTest.java
@@ -28,15 +28,11 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
+import org.sonar.api.batch.sensor.highlighting.TypeOfText;
import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
import org.sonar.api.batch.sensor.internal.SensorContextTester;
-import org.sonar.api.component.ResourcePerspectives;
-import org.sonar.api.source.Highlightable;
-import org.sonar.api.source.Highlightable.HighlightingBuilder;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.assertj.core.api.Assertions.assertThat;
public class SyntaxHighlightingSensorTest {
@@ -46,13 +42,11 @@ public class SyntaxHighlightingSensorTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
private File baseDir;
- private ResourcePerspectives perspectives;
@Before
public void prepare() throws IOException {
baseDir = temp.newFolder();
- perspectives = mock(ResourcePerspectives.class);
- sensor = new SyntaxHighlightingSensor(perspectives);
+ sensor = new SyntaxHighlightingSensor();
context = SensorContextTester.create(baseDir);
}
@@ -74,7 +68,7 @@ public class SyntaxHighlightingSensorTest {
@Test
public void testExecution() throws IOException {
File symbol = new File(baseDir, "src/foo.xoo.highlighting");
- FileUtils.write(symbol, "1:4:k\n12:15:cppd\n\n#comment");
+ FileUtils.write(symbol, "1:4:k\n12:15:cd\n\n#comment");
DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo")
.setLanguage("xoo")
.setModuleBaseDir(baseDir.toPath())
@@ -82,15 +76,9 @@ public class SyntaxHighlightingSensorTest {
.build();
context.fileSystem().add(inputFile);
- Highlightable highlightable = mock(Highlightable.class);
- when(perspectives.as(Highlightable.class, inputFile)).thenReturn(highlightable);
- HighlightingBuilder builder = mock(Highlightable.HighlightingBuilder.class);
- when(highlightable.newHighlighting()).thenReturn(builder);
-
sensor.execute(context);
- verify(builder).highlight(1, 4, "k");
- verify(builder).highlight(12, 15, "cppd");
- verify(builder).done();
+ assertThat(context.highlightingTypeAt("foo:src/foo.xoo", 1, 2)).containsOnly(TypeOfText.KEYWORD);
+ assertThat(context.highlightingTypeAt("foo:src/foo.xoo", 2, 8)).containsOnly(TypeOfText.COMMENT);
}
}
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/XooTokenizerTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/XooTokenizerTest.java
deleted file mode 100644
index 0b0cbbae932..00000000000
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/XooTokenizerTest.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2018 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.xoo.lang;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
-import net.sourceforge.pmd.cpd.SourceCode;
-import net.sourceforge.pmd.cpd.TokenEntry;
-import net.sourceforge.pmd.cpd.Tokens;
-import org.apache.commons.io.FileUtils;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.fs.internal.DefaultFileSystem;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
-import org.sonar.api.batch.sensor.SensorContext;
-import org.sonar.api.config.Settings;
-import org.sonar.api.config.internal.MapSettings;
-import org.sonar.duplications.cpd.FileCodeLoaderWithoutCache;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class XooTokenizerTest {
-
- private SensorContext context = mock(SensorContext.class);
- private DefaultFileSystem fileSystem;
-
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
- private File baseDir;
- private Settings settings;
-
- @Before
- public void prepare() throws IOException {
- baseDir = temp.newFolder();
- fileSystem = new DefaultFileSystem(baseDir.toPath());
- when(context.fileSystem()).thenReturn(fileSystem);
- settings = new MapSettings();
- when(context.settings()).thenReturn(settings);
- }
-
- @Test
- public void testExecution() throws IOException {
- File source = new File(baseDir, "src/foo.xoo");
- FileUtils.write(source, "token1 token2 token3\ntoken4", StandardCharsets.UTF_8);
- DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo")
- .setLanguage("xoo")
- .setModuleBaseDir(baseDir.toPath())
- .setCharset(StandardCharsets.UTF_8)
- .build();
- fileSystem.add(inputFile);
-
- XooTokenizer tokenizer = new XooTokenizer(fileSystem);
- Tokens cpdTokens = new Tokens();
- try (InputStreamReader reader = new InputStreamReader(inputFile.inputStream(), inputFile.charset())) {
- SourceCode sourceCode = new SourceCode(new FileCodeLoaderWithoutCache(inputFile.absolutePath(), reader));
- tokenizer.tokenize(sourceCode, cpdTokens);
- }
-
- // 4 tokens + EOF
- assertThat(cpdTokens.getTokens()).hasSize(5);
- assertThat(cpdTokens.getTokens().get(3)).isEqualTo(new TokenEntry("token4", "src/foo.xoo", 2));
- }
-}
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/XooRulesDefinitionTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/XooRulesDefinitionTest.java
index 9658ab8e3a4..48d04ccc20e 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/XooRulesDefinitionTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/XooRulesDefinitionTest.java
@@ -42,7 +42,7 @@ public class XooRulesDefinitionTest {
assertThat(repo).isNotNull();
assertThat(repo.name()).isEqualTo("Xoo");
assertThat(repo.language()).isEqualTo("xoo");
- assertThat(repo.rules()).hasSize(19);
+ assertThat(repo.rules()).hasSize(18);
RulesDefinition.Rule rule = repo.rule(OneIssuePerLineSensor.RULE_KEY);
assertThat(rule.name()).isNotEmpty();