diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2021-06-09 16:26:56 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-06-17 20:03:08 +0000 |
commit | 2754feca4e5fa8fdd804c827783250f48676296c (patch) | |
tree | 1ed9522bbc9eff9444fae6bf0a951d976da2b859 /plugins | |
parent | 97f2c01fdd4ae863134d4aa1bf32b7dcd512b10c (diff) | |
download | sonarqube-2754feca4e5fa8fdd804c827783250f48676296c.tar.gz sonarqube-2754feca4e5fa8fdd804c827783250f48676296c.zip |
SONAR-14925 Remove code deprecated before 7.0 in the Plugin API
Diffstat (limited to 'plugins')
20 files changed, 66 insertions, 417 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 ba4ffd9c554..e493d286402 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 @@ -78,8 +78,6 @@ import org.sonar.xoo.rule.XooSonarWayProfile; import org.sonar.xoo.scm.XooBlameCommand; import org.sonar.xoo.scm.XooIgnoreCommand; import org.sonar.xoo.scm.XooScmProvider; -import org.sonar.xoo.test.CoveragePerTestSensor; -import org.sonar.xoo.test.TestExecutionSensor; /** * Plugin entry-point, as declared in pom.xml. @@ -172,10 +170,6 @@ public class XooPlugin implements Plugin { // Analysis errors AnalysisErrorSensor.class, - // Tests - TestExecutionSensor.class, - CoveragePerTestSensor.class, - // Other XooProjectBuilder.class, XooPostJob.class, diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/coverage/AbstractCoverageSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/coverage/AbstractCoverageSensor.java index d01c96b1bf7..3e49638de9b 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/coverage/AbstractCoverageSensor.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/coverage/AbstractCoverageSensor.java @@ -30,7 +30,6 @@ 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.batch.sensor.coverage.CoverageType; import org.sonar.api.batch.sensor.coverage.NewCoverage; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; @@ -46,8 +45,7 @@ public abstract class AbstractCoverageSensor implements Sensor { try { List<String> lines = FileUtils.readLines(coverageFile, context.fileSystem().encoding().name()); NewCoverage coverageBuilder = context.newCoverage() - .onFile(inputFile) - .ofType(getCoverageType()); + .onFile(inputFile); int lineNumber = 0; for (String line : lines) { lineNumber++; @@ -80,8 +78,6 @@ public abstract class AbstractCoverageSensor implements Sensor { protected abstract String getCoverageExtension(); - protected abstract CoverageType getCoverageType(); - @Override public void describe(SensorDescriptor descriptor) { descriptor diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/coverage/ItCoverageSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/coverage/ItCoverageSensor.java index 45ba3770a73..046e7d13071 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/coverage/ItCoverageSensor.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/coverage/ItCoverageSensor.java @@ -19,8 +19,6 @@ */ package org.sonar.xoo.coverage; -import org.sonar.api.batch.sensor.coverage.CoverageType; - /** * Parse files *.xoo.itcoverage */ @@ -32,11 +30,6 @@ public class ItCoverageSensor extends AbstractCoverageSensor { } @Override - protected CoverageType getCoverageType() { - return CoverageType.IT; - } - - @Override protected String getSensorName() { return "Xoo IT Coverage Sensor"; } diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/coverage/OverallCoverageSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/coverage/OverallCoverageSensor.java index f654826a464..419b86fe606 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/coverage/OverallCoverageSensor.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/coverage/OverallCoverageSensor.java @@ -19,8 +19,6 @@ */ package org.sonar.xoo.coverage; -import org.sonar.api.batch.sensor.coverage.CoverageType; - /** * Parse files *.xoo.overallcoverage */ @@ -32,11 +30,6 @@ public class OverallCoverageSensor extends AbstractCoverageSensor { } @Override - protected CoverageType getCoverageType() { - return CoverageType.OVERALL; - } - - @Override protected String getSensorName() { return "Xoo Overall Coverage Sensor"; } diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/coverage/UtCoverageSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/coverage/UtCoverageSensor.java index cba44d76f76..3ff71222e2d 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/coverage/UtCoverageSensor.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/coverage/UtCoverageSensor.java @@ -19,8 +19,6 @@ */ package org.sonar.xoo.coverage; -import org.sonar.api.batch.sensor.coverage.CoverageType; - /** * Parse files *.xoo.coverage */ @@ -32,11 +30,6 @@ public class UtCoverageSensor extends AbstractCoverageSensor { } @Override - protected CoverageType getCoverageType() { - return CoverageType.UNIT; - } - - @Override protected String getSensorName() { return "Xoo UT Coverage Sensor"; } diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/extensions/XooPostJob.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/extensions/XooPostJob.java index 717402dd1c7..6b4dc103fd1 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/extensions/XooPostJob.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/extensions/XooPostJob.java @@ -19,7 +19,6 @@ */ package org.sonar.xoo.extensions; -import com.google.common.collect.Iterables; import org.sonar.api.batch.postjob.PostJob; import org.sonar.api.batch.postjob.PostJobContext; import org.sonar.api.batch.postjob.PostJobDescriptor; @@ -34,13 +33,11 @@ public class XooPostJob implements PostJob { public void describe(PostJobDescriptor descriptor) { descriptor.name("Xoo Post Job") .requireProperty("sonar.xoo.enablePostJob"); - } @Override public void execute(PostJobContext context) { - LOG.info("Resolved issues: " + Iterables.size(context.resolvedIssues())); - LOG.info("Open issues: " + Iterables.size(context.issues())); + LOG.info("Running Xoo PostJob"); } } 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 63778317a1b..9bd845064ce 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 @@ -24,7 +24,6 @@ import java.io.File; import java.io.IOException; import java.util.Iterator; import java.util.List; -import javax.annotation.Nullable; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.sonar.api.batch.fs.InputFile; @@ -77,54 +76,38 @@ public class SymbolReferencesSensor implements Sensor { Iterator<String> split = Splitter.on(",").split(line).iterator(); String[] symbolOffsets = split.next().split(":"); - if (symbolOffsets.length == 2) { - int startOffset = parseInt(symbolOffsets[0]); - int endOffset = parseInt(symbolOffsets[1]); - NewSymbol s = symbolTable.newSymbol(startOffset, endOffset); - parseReferences(s, split, endOffset - startOffset); - } else if (symbolOffsets.length == 4) { + if (symbolOffsets.length == 4) { int startLine = parseInt(symbolOffsets[0]); int startLineOffset = parseInt(symbolOffsets[1]); int endLine = parseInt(symbolOffsets[2]); int endLineOffset = parseInt(symbolOffsets[3]); NewSymbol s = symbolTable.newSymbol(startLine, startLineOffset, endLine, endLineOffset); - parseReferences(s, split, null); + parseReferences(s, split); } else { throw new IllegalStateException("Illegal number of elements separated by ':'. " + - "Must either be startOffset:endOffset (offset in whole file) or startLine:startLineOffset:endLine:endLineOffset"); + "Must be startLine:startLineOffset:endLine:endLineOffset"); } } catch (Exception e) { throw new IllegalStateException("Error processing line " + lineNumber + " of file " + symbolFile.getAbsolutePath(), e); } } - private static void parseReferences(NewSymbol s, Iterator<String> split, @Nullable Integer defaultLen) { + private static void parseReferences(NewSymbol s, Iterator<String> split) { while (split.hasNext()) { - addReference(s, split.next(), defaultLen); + addReference(s, split.next()); } } - private static void addReference(NewSymbol s, String str, @Nullable Integer defaultLen) { - if (str.contains(":")) { - String[] split = str.split(":"); - if (split.length == 2) { - int startOffset = parseInt(split[0]); - int endOffset = parseInt(split[1]); - s.newReference(startOffset, endOffset); - } else if (split.length == 4) { - int startLine = parseInt(split[0]); - int startLineOffset = parseInt(split[1]); - int endLine = parseInt(split[2]); - int endLineOffset = parseInt(split[3]); - s.newReference(startLine, startLineOffset, endLine, endLineOffset); - } else { - throw new IllegalStateException("Illegal number of elements separated by ':'"); - } - } else if (defaultLen == null) { - throw new IllegalStateException("Mix of new and old format. Use startLine:startLineOffset:endLine:endLineOffset for references too"); + private static void addReference(NewSymbol s, String str) { + String[] split = str.split(":"); + if (split.length == 4) { + int startLine = parseInt(split[0]); + int startLineOffset = parseInt(split[1]); + int endLine = parseInt(split[2]); + int endLineOffset = parseInt(split[3]); + s.newReference(startLine, startLineOffset, endLine, endLineOffset); } else { - int startOffset = parseInt(str); - s.newReference(startOffset, startOffset + defaultLen); + throw new IllegalStateException("Illegal number of elements separated by ':'"); } } 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 ec943a34432..628259e4e43 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 @@ -71,11 +71,7 @@ public class SyntaxHighlightingSensor implements Sensor { private static void processLine(File highlightingFile, int lineNumber, NewHighlighting highlighting, String line) { try { String[] split = line.split(":"); - if (split.length == 3) { - int startOffset = parseInt(split[0]); - int endOffset = parseInt(split[1]); - highlighting.highlight(startOffset, endOffset, TypeOfText.forCssClass(split[2])); - } else if (split.length == 5) { + if (split.length == 5) { int startLine = parseInt(split[0]); int startLineOffset = parseInt(split[1]); int endLine = parseInt(split[2]); @@ -83,7 +79,7 @@ public class SyntaxHighlightingSensor implements Sensor { highlighting.highlight(startLine, startLineOffset, endLine, endLineOffset, TypeOfText.forCssClass(split[4])); } else { throw new IllegalStateException("Illegal number of elements separated by ':'. " + - "Must either be startOffset:endOffset:class (offset in whole file) or startLine:startLineOffset:endLine:endLineOffset:class"); + "Must be startLine:startLineOffset:endLine:endLineOffset:class"); } } 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/rule/Xoo2BasicProfile.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/Xoo2BasicProfile.java index 2283c517f2a..6b2de61586d 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/Xoo2BasicProfile.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/Xoo2BasicProfile.java @@ -19,23 +19,15 @@ */ package org.sonar.xoo.rule; -import org.sonar.api.profiles.ProfileDefinition; -import org.sonar.api.profiles.RulesProfile; -import org.sonar.api.rules.Rule; -import org.sonar.api.rules.RulePriority; -import org.sonar.api.utils.ValidationMessages; +import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; import org.sonar.xoo.Xoo2; -public class Xoo2BasicProfile extends ProfileDefinition { - +public class Xoo2BasicProfile implements BuiltInQualityProfilesDefinition { @Override - public RulesProfile createProfile(ValidationMessages messages) { - RulesProfile profile = RulesProfile.create("Basic", Xoo2.KEY); - profile.setDefaultProfile(true); - - // so UGLY - profile.activateRule(Rule.create(XooRulesDefinition.XOO2_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR); - - return profile; + public void define(Context context) { + NewBuiltInQualityProfile qProfile = context.createBuiltInQualityProfile("Basic", Xoo2.KEY); + qProfile.setDefault(true); + qProfile.activateRule(XooRulesDefinition.XOO2_REPOSITORY, HasTagSensor.RULE_KEY); + qProfile.done(); } } diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/Xoo2SonarWayProfile.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/Xoo2SonarWayProfile.java index e611408aa6c..cf938351c5f 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/Xoo2SonarWayProfile.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/Xoo2SonarWayProfile.java @@ -19,22 +19,15 @@ */ package org.sonar.xoo.rule; -import org.sonar.api.profiles.ProfileDefinition; -import org.sonar.api.profiles.RulesProfile; -import org.sonar.api.rules.Rule; -import org.sonar.api.rules.RulePriority; -import org.sonar.api.utils.ValidationMessages; +import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; import org.sonar.xoo.Xoo2; -public class Xoo2SonarWayProfile extends ProfileDefinition { - +public class Xoo2SonarWayProfile implements BuiltInQualityProfilesDefinition { @Override - public RulesProfile createProfile(ValidationMessages messages) { - RulesProfile profile = RulesProfile.create("Sonar way", Xoo2.KEY); - - profile.activateRule(Rule.create(XooRulesDefinition.XOO2_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR); - profile.activateRule(Rule.create(XooRulesDefinition.XOO2_REPOSITORY, OneIssuePerLineSensor.RULE_KEY), RulePriority.MINOR); - - return profile; + public void define(Context context) { + NewBuiltInQualityProfile qProfile = context.createBuiltInQualityProfile("Sonar way", Xoo2.KEY); + qProfile.activateRule(XooRulesDefinition.XOO2_REPOSITORY, HasTagSensor.RULE_KEY); + qProfile.activateRule(XooRulesDefinition.XOO2_REPOSITORY, OneIssuePerLineSensor.RULE_KEY); + qProfile.done(); } } diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooBasicProfile.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooBasicProfile.java index 3b4b5f25e32..c68efdfc0ee 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooBasicProfile.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooBasicProfile.java @@ -19,22 +19,15 @@ */ package org.sonar.xoo.rule; -import org.sonar.api.profiles.ProfileDefinition; -import org.sonar.api.profiles.RulesProfile; -import org.sonar.api.rules.Rule; -import org.sonar.api.rules.RulePriority; -import org.sonar.api.utils.ValidationMessages; +import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; import org.sonar.xoo.Xoo; -public class XooBasicProfile extends ProfileDefinition { - +public class XooBasicProfile implements BuiltInQualityProfilesDefinition { @Override - public RulesProfile createProfile(ValidationMessages validation) { - final RulesProfile profile = RulesProfile.create("Basic", Xoo.KEY); - profile.setDefaultProfile(true); - - profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR); - - return profile; + public void define(Context context) { + NewBuiltInQualityProfile qProfile = context.createBuiltInQualityProfile("Basic", Xoo.KEY); + qProfile.setDefault(true); + qProfile.activateRule(XooRulesDefinition.XOO_REPOSITORY, HasTagSensor.RULE_KEY); + qProfile.done(); } } diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooEmptyProfile.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooEmptyProfile.java index 1f51a24e526..049735c0d8c 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooEmptyProfile.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooEmptyProfile.java @@ -19,15 +19,13 @@ */ package org.sonar.xoo.rule; -import org.sonar.api.profiles.ProfileDefinition; -import org.sonar.api.profiles.RulesProfile; -import org.sonar.api.utils.ValidationMessages; +import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; import org.sonar.xoo.Xoo; -public class XooEmptyProfile extends ProfileDefinition { - +public class XooEmptyProfile implements BuiltInQualityProfilesDefinition { @Override - public RulesProfile createProfile(ValidationMessages validation) { - return RulesProfile.create("empty", Xoo.KEY); + public void define(Context context) { + context.createBuiltInQualityProfile("empty", Xoo.KEY) + .done(); } } diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooSonarWayProfile.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooSonarWayProfile.java index 0c92f9b67aa..f35fd64ae99 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooSonarWayProfile.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooSonarWayProfile.java @@ -19,24 +19,18 @@ */ package org.sonar.xoo.rule; -import org.sonar.api.profiles.ProfileDefinition; -import org.sonar.api.profiles.RulesProfile; -import org.sonar.api.rules.Rule; -import org.sonar.api.rules.RulePriority; -import org.sonar.api.utils.ValidationMessages; +import org.sonar.api.rule.Severity; +import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; import org.sonar.xoo.Xoo; -public class XooSonarWayProfile extends ProfileDefinition { - +public class XooSonarWayProfile implements BuiltInQualityProfilesDefinition { @Override - public RulesProfile createProfile(ValidationMessages validation) { - final RulesProfile profile = RulesProfile.create("Sonar way", Xoo.KEY); - - profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR); - profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, OneIssuePerLineSensor.RULE_KEY), RulePriority.INFO); - profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, OneIssuePerFileSensor.RULE_KEY), RulePriority.CRITICAL); - profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, HotspotSensor.RULE_KEY), RulePriority.CRITICAL); - - return profile; + public void define(Context context) { + NewBuiltInQualityProfile qProfile = context.createBuiltInQualityProfile("Sonar way", Xoo.KEY); + qProfile.activateRule(XooRulesDefinition.XOO_REPOSITORY, HasTagSensor.RULE_KEY).overrideSeverity(Severity.MAJOR); + qProfile.activateRule(XooRulesDefinition.XOO_REPOSITORY, OneIssuePerLineSensor.RULE_KEY).overrideSeverity(Severity.INFO); + qProfile.activateRule(XooRulesDefinition.XOO_REPOSITORY, OneIssuePerFileSensor.RULE_KEY).overrideSeverity(Severity.CRITICAL); + qProfile.activateRule(XooRulesDefinition.XOO_REPOSITORY, HotspotSensor.RULE_KEY).overrideSeverity(Severity.CRITICAL); + qProfile.done(); } } diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/test/CoveragePerTestSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/test/CoveragePerTestSensor.java deleted file mode 100644 index 0c0c199ed38..00000000000 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/test/CoveragePerTestSensor.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2021 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.test; - -import com.google.common.base.Splitter; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.batch.DependsUpon; -import org.sonar.api.batch.fs.FilePredicates; -import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.InputFile.Type; -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.test.MutableTestCase; -import org.sonar.api.test.MutableTestPlan; -import org.sonar.api.test.MutableTestable; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.xoo.Xoo; - -/** - * Parse files *.xoo.testcoverage - */ -@DependsUpon("test-exec") -public class CoveragePerTestSensor implements Sensor { - private static final Logger LOG = Loggers.get(CoveragePerTestSensor.class); - - private static final String TEST_EXTENSION = ".testcoverage"; - - private final FileSystem fs; - private final ResourcePerspectives perspectives; - - public CoveragePerTestSensor(FileSystem fileSystem, ResourcePerspectives perspectives) { - this.fs = fileSystem; - this.perspectives = perspectives; - } - - private void processTestFile(InputFile inputFile, SensorContext context) { - File testExecutionFile = new File(inputFile.file().getParentFile(), inputFile.file().getName() + TEST_EXTENSION); - if (testExecutionFile.exists()) { - LOG.debug("Processing " + testExecutionFile.getAbsolutePath()); - try { - List<String> lines = FileUtils.readLines(testExecutionFile, fs.encoding().name()); - int lineNumber = 0; - MutableTestPlan testPlan = perspectives.as(MutableTestPlan.class, inputFile); - for (String line : lines) { - lineNumber++; - if (StringUtils.isBlank(line)) { - continue; - } - if (line.startsWith("#")) { - continue; - } - try { - Iterator<String> split = Splitter.on(";").split(line).iterator(); - String name = split.next(); - while (split.hasNext()) { - String coveredBlockStr = split.next(); - Iterator<String> splitCoveredBlock = Splitter.on(",").split(coveredBlockStr).iterator(); - String componentPath = splitCoveredBlock.next(); - InputFile coveredFile = context.fileSystem().inputFile(context.fileSystem().predicates().hasPath(componentPath)); - MutableTestable testable = perspectives.as(MutableTestable.class, coveredFile); - List<Integer> coveredLines = new ArrayList<>(); - while (splitCoveredBlock.hasNext()) { - coveredLines.add(Integer.parseInt(splitCoveredBlock.next())); - } - for (MutableTestCase testCase : testPlan.testCasesByName(name)) { - testCase.setCoverageBlock(testable, coveredLines); - } - } - } catch (Exception e) { - throw new IllegalStateException("Error processing line " + lineNumber + " of file " + testExecutionFile.getAbsolutePath(), e); - } - } - } catch (IOException e) { - throw new RuntimeException(e); - } - } - } - - @Override - public void describe(SensorDescriptor descriptor) { - descriptor - .name("Xoo Coverage Per Test Sensor") - .onlyOnLanguages(Xoo.KEY); - } - - @Override - public void execute(SensorContext context) { - FilePredicates p = context.fileSystem().predicates(); - for (InputFile file : context.fileSystem().inputFiles(p.and(p.hasLanguages(Xoo.KEY), p.hasType(Type.TEST)))) { - processTestFile(file, context); - } - } - -} 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 deleted file mode 100644 index b39b2cbb18f..00000000000 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/test/TestExecutionSensor.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2021 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.test; - -import com.google.common.base.Splitter; -import java.io.File; -import java.io.IOException; -import java.util.Iterator; -import java.util.List; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.batch.DependedUpon; -import org.sonar.api.batch.fs.FilePredicates; -import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.InputFile.Type; -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.test.MutableTestCase; -import org.sonar.api.test.MutableTestPlan; -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; - -/** - * Parse files *.xoo.test - */ -@DependedUpon("test-exec") -public class TestExecutionSensor implements Sensor { - private static final Logger LOG = Loggers.get(TestExecutionSensor.class); - - private static final String TEST_EXTENSION = ".test"; - - private final FileSystem fs; - private final ResourcePerspectives perspectives; - - public TestExecutionSensor(FileSystem fileSystem, ResourcePerspectives perspectives) { - this.fs = fileSystem; - this.perspectives = perspectives; - } - - private void processTestFile(InputFile inputFile, SensorContext context) { - File testExecutionFile = new File(inputFile.file().getParentFile(), inputFile.file().getName() + TEST_EXTENSION); - if (testExecutionFile.exists()) { - LOG.debug("Processing " + testExecutionFile.getAbsolutePath()); - try { - List<String> lines = FileUtils.readLines(testExecutionFile, fs.encoding().name()); - int lineNumber = 0; - MutableTestPlan testPlan = perspectives.as(MutableTestPlan.class, inputFile); - for (String line : lines) { - lineNumber++; - if (StringUtils.isBlank(line)) { - continue; - } - if (line.startsWith("#")) { - continue; - } - try { - Iterator<String> split = Splitter.on(":").split(line).iterator(); - String name = split.next(); - String durationStr = split.next(); - Long duration = StringUtils.isNotBlank(durationStr) ? Long.parseLong(durationStr) : null; - String msg = split.next(); - String stack = split.next(); - String status = split.next(); - String type = split.next(); - MutableTestCase testCase = testPlan.addTestCase(name); - testCase.setDurationInMs(duration); - testCase.setMessage(msg); - testCase.setStackTrace(stack); - testCase.setStatus(TestCase.Status.valueOf(status)); - testCase.setType(type); - } catch (Exception e) { - throw new IllegalStateException("Error processing line " + lineNumber + " of file " + testExecutionFile.getAbsolutePath(), e); - } - } - } catch (IOException e) { - throw new RuntimeException(e); - } - } - } - - @Override - public void describe(SensorDescriptor descriptor) { - descriptor - .name("Xoo Test Execution Sensor") - .onlyOnLanguages(Xoo.KEY); - } - - @Override - public void execute(SensorContext context) { - FilePredicates p = context.fileSystem().predicates(); - for (InputFile file : context.fileSystem().inputFiles(p.and(p.hasLanguages(Xoo.KEY), p.hasType(Type.TEST)))) { - processTestFile(file, context); - } - } - - -} diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/test/package-info.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/test/package-info.java deleted file mode 100644 index 8586ad8b37e..00000000000 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/test/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2021 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. - */ -@ParametersAreNonnullByDefault -package org.sonar.xoo.test; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/extensions/XooPostJobTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/extensions/XooPostJobTest.java index 7ee02b46c47..7ada6d09d07 100644 --- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/extensions/XooPostJobTest.java +++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/extensions/XooPostJobTest.java @@ -19,16 +19,14 @@ */ package org.sonar.xoo.extensions; -import java.util.Arrays; import org.junit.Rule; import org.junit.Test; import org.sonar.api.batch.postjob.PostJobContext; -import org.sonar.api.utils.log.LogTester; import org.sonar.api.batch.postjob.internal.DefaultPostJobDescriptor; +import org.sonar.api.utils.log.LogTester; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; public class XooPostJobTest { @@ -39,9 +37,7 @@ public class XooPostJobTest { public void increaseCoverage() { new XooPostJob().describe(new DefaultPostJobDescriptor()); PostJobContext context = mock(PostJobContext.class); - when(context.issues()).thenReturn(Arrays.asList()); - when(context.resolvedIssues()).thenReturn(Arrays.asList()); new XooPostJob().execute(context); - assertThat(logTester.logs()).contains("Resolved issues: 0", "Open issues: 0"); + assertThat(logTester.logs()).contains("Running Xoo PostJob"); } } 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 f525c39f4d9..6c681ba53fb 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 @@ -66,7 +66,7 @@ public class SymbolReferencesSensorTest { @Test 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"); + FileUtils.write(symbol, "1:1:1:4,1:7:1:10\n1:11:1:13,1:14:1:33\n\n#comment"); InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo") .initMetadata("xoo file with some source code and length over 33") .setLanguage(Xoo.KEY) @@ -78,8 +78,8 @@ public class SymbolReferencesSensorTest { 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))); + assertThat(context.referencesForSymbolAt("foo:src/foo.xoo", 1, 12)) + .containsOnly(new DefaultTextRange(new DefaultTextPointer(1, 14), 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 c00ddb270e6..3f4cd46a781 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 @@ -68,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:cd\n\n#comment"); + FileUtils.write(symbol, "1:1:1:4:k\n2:7:2:10:cd\n\n#comment"); DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo") .setLanguage("xoo") .setModuleBaseDir(baseDir.toPath()) diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java index 8214b783d40..fabca7a0567 100644 --- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java +++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java @@ -25,12 +25,13 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.SonarEdition; import org.sonar.api.SonarQubeSide; -import org.sonar.api.batch.rule.Severity; -import org.sonar.api.batch.sensor.issue.Issue; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; +import org.sonar.api.batch.rule.Severity; import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor; import org.sonar.api.batch.sensor.internal.SensorContextTester; +import org.sonar.api.batch.sensor.issue.Issue; +import org.sonar.api.config.internal.MapSettings; import org.sonar.api.internal.SonarRuntimeImpl; import org.sonar.api.utils.Version; import org.sonar.xoo.Xoo; @@ -77,7 +78,7 @@ public class OneIssuePerLineSensorTest { SensorContextTester context = SensorContextTester.create(temp.newFolder()); context.fileSystem().add(inputFile); - context.settings().setProperty(OneIssuePerLineSensor.FORCE_SEVERITY_PROPERTY, "MINOR"); + context.setSettings(new MapSettings().setProperty(OneIssuePerLineSensor.FORCE_SEVERITY_PROPERTY, "MINOR")); sensor.execute(context); @@ -96,7 +97,7 @@ public class OneIssuePerLineSensorTest { SensorContextTester context = SensorContextTester.create(temp.newFolder()); context.fileSystem().add(inputFile); - context.settings().setProperty(OneIssuePerLineSensor.EFFORT_TO_FIX_PROPERTY, "1.2"); + context.setSettings(new MapSettings().setProperty(OneIssuePerLineSensor.EFFORT_TO_FIX_PROPERTY, "1.2")); sensor.execute(context); @@ -115,7 +116,7 @@ public class OneIssuePerLineSensorTest { SensorContextTester context = SensorContextTester.create(temp.newFolder()); context.fileSystem().add(inputFile); - context.settings().setProperty(OneIssuePerLineSensor.EFFORT_TO_FIX_PROPERTY, "1.2"); + context.setSettings(new MapSettings().setProperty(OneIssuePerLineSensor.EFFORT_TO_FIX_PROPERTY, "1.2")); context.setRuntime(SonarRuntimeImpl.forSonarQube(Version.parse("5.4"), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY)); sensor.execute(context); |