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 /sonar-scanner-engine/src/main/java | |
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 'sonar-scanner-engine/src/main/java')
21 files changed, 56 insertions, 629 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/DefaultAnalysisMode.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/DefaultAnalysisMode.java deleted file mode 100644 index 62cc69b4485..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/DefaultAnalysisMode.java +++ /dev/null @@ -1,42 +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.scanner.analysis; - -import javax.annotation.concurrent.Immutable; -import org.sonar.api.batch.AnalysisMode; - -@Immutable -public class DefaultAnalysisMode implements AnalysisMode { - - @Override - public boolean isPreview() { - return false; - } - - @Override - public boolean isIssues() { - return false; - } - - @Override - public boolean isPublish() { - return true; - } -} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchComponents.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchComponents.java index 1330bda7efb..952d4003950 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchComponents.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchComponents.java @@ -25,6 +25,7 @@ import java.util.List; import org.sonar.core.component.DefaultResourceTypes; import org.sonar.core.config.CorePropertyDefinitions; import org.sonar.scanner.cpd.JavaCpdBlockIndexerSensor; +import org.sonar.scanner.deprecated.test.TestPlanBuilder; import org.sonar.scanner.externalissue.ExternalIssuesImportSensor; import org.sonar.scanner.genericcoverage.GenericCoverageSensor; import org.sonar.scanner.genericcoverage.GenericTestExecutionSensor; @@ -47,6 +48,7 @@ public class BatchComponents { components.addAll(GenericCoverageSensor.properties()); components.add(GenericTestExecutionSensor.class); components.addAll(GenericTestExecutionSensor.properties()); + components.add(TestPlanBuilder.class); // External issues components.add(ExternalIssuesImportSensor.class); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ExtensionInstaller.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ExtensionInstaller.java index 9374cf8704e..15c8b376e07 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ExtensionInstaller.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ExtensionInstaller.java @@ -19,9 +19,7 @@ */ package org.sonar.scanner.bootstrap; -import java.util.List; import javax.annotation.Nullable; -import org.sonar.api.ExtensionProvider; import org.sonar.api.Plugin; import org.sonar.api.SonarRuntime; import org.sonar.api.config.Configuration; @@ -62,17 +60,7 @@ public class ExtensionInstaller { doInstall(container, matcher, pluginInfo, extension); } } - List<ExtensionProvider> providers = container.getComponentsByType(ExtensionProvider.class); - for (ExtensionProvider provider : providers) { - Object object = provider.provide(); - if (object instanceof Iterable) { - for (Object extension : (Iterable) object) { - doInstall(container, matcher, null, extension); - } - } else { - doInstall(container, matcher, null, object); - } - } + return this; } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/MetricProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/MetricProvider.java deleted file mode 100644 index 1feaf6acd84..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/MetricProvider.java +++ /dev/null @@ -1,51 +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.scanner.bootstrap; - -import java.util.ArrayList; -import java.util.List; -import org.sonar.api.ExtensionProvider; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Metric; -import org.sonar.api.measures.Metrics; -import org.sonar.api.scanner.ScannerSide; - -@ScannerSide -public class MetricProvider extends ExtensionProvider { - - private Metrics[] factories; - - public MetricProvider(Metrics[] factories) { - this.factories = factories; - } - - public MetricProvider() { - this.factories = new Metrics[0]; - } - - @Override - public List<Metric> provide() { - List<Metric> metrics = new ArrayList<>(CoreMetrics.getMetrics()); - for (Metrics factory : factories) { - metrics.addAll(factory.getMetrics()); - } - return metrics; - } -} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/perspectives/PerspectiveBuilder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/perspectives/PerspectiveBuilder.java deleted file mode 100644 index bc898b6d7b8..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/perspectives/PerspectiveBuilder.java +++ /dev/null @@ -1,40 +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.scanner.deprecated.perspectives; - -import javax.annotation.CheckForNull; -import org.sonar.api.batch.fs.InputComponent; -import org.sonar.api.component.Perspective; - -public abstract class PerspectiveBuilder<T extends Perspective> { - - private final Class<T> perspectiveClass; - - protected PerspectiveBuilder(Class<T> perspectiveClass) { - this.perspectiveClass = perspectiveClass; - } - - public Class<T> getPerspectiveClass() { - return perspectiveClass; - } - - @CheckForNull - public abstract T loadPerspective(Class<T> perspectiveClass, InputComponent component); -} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/perspectives/ScannerPerspectives.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/perspectives/ScannerPerspectives.java deleted file mode 100644 index 6805e27f3ea..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/perspectives/ScannerPerspectives.java +++ /dev/null @@ -1,51 +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.scanner.deprecated.perspectives; - -import java.util.HashMap; -import java.util.Map; -import org.sonar.api.batch.fs.InputPath; -import org.sonar.api.component.Perspective; -import org.sonar.api.component.ResourcePerspectives; - -public class ScannerPerspectives implements ResourcePerspectives { - - private final Map<Class<?>, PerspectiveBuilder<?>> builders = new HashMap<>(); - - public ScannerPerspectives(PerspectiveBuilder[] builders) { - for (PerspectiveBuilder builder : builders) { - this.builders.put(builder.getPerspectiveClass(), builder); - } - } - - @Override - public <P extends Perspective> P as(Class<P> perspectiveClass, InputPath inputPath) { - PerspectiveBuilder<P> builder = builderFor(perspectiveClass); - return builder.loadPerspective(perspectiveClass, inputPath); - } - - private <T extends Perspective> PerspectiveBuilder<T> builderFor(Class<T> clazz) { - PerspectiveBuilder<T> builder = (PerspectiveBuilder<T>) builders.get(clazz); - if (builder == null) { - throw new IllegalStateException("Perspective class is not registered: " + clazz); - } - return builder; - } -} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/perspectives/package-info.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/perspectives/package-info.java deleted file mode 100644 index 25ff7b8a4dc..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/perspectives/package-info.java +++ /dev/null @@ -1,24 +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.scanner.deprecated.perspectives; - -import javax.annotation.ParametersAreNonnullByDefault; - diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultCoverageBlock.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultCoverageBlock.java deleted file mode 100644 index 5bebdb68679..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultCoverageBlock.java +++ /dev/null @@ -1,54 +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.scanner.deprecated.test; - -import java.util.List; -import org.sonar.api.test.CoverageBlock; -import org.sonar.api.test.TestCase; -import org.sonar.api.test.Testable; -import org.sonar.api.batch.fs.internal.DefaultInputFile; - -public class DefaultCoverageBlock implements CoverageBlock { - - private final TestCase testCase; - private final DefaultInputFile testable; - private final List<Integer> lines; - - public DefaultCoverageBlock(TestCase testCase, DefaultInputFile testable, List<Integer> lines) { - this.testCase = testCase; - this.testable = testable; - this.lines = lines; - } - - @Override - public TestCase testCase() { - return testCase; - } - - @Override - public Testable testable() { - return new DefaultTestable(testable); - } - - @Override - public List<Integer> lines() { - return lines; - } -} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestCase.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestCase.java index 35116b6ef2d..f7aff95dcfd 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestCase.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestCase.java @@ -19,146 +19,69 @@ */ package org.sonar.scanner.deprecated.test; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.Locale; import javax.annotation.Nullable; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.InputFile.Type; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.test.CoverageBlock; -import org.sonar.api.test.MutableTestCase; -import org.sonar.api.test.TestPlan; -import org.sonar.api.test.Testable; -import org.sonar.api.test.exception.CoverageAlreadyExistsException; -import org.sonar.api.test.exception.IllegalDurationException; -import static org.sonar.api.utils.Preconditions.checkArgument; +public class DefaultTestCase { + public enum Status { + OK, FAILURE, ERROR, SKIPPED; -public class DefaultTestCase implements MutableTestCase { + public static Status of(@Nullable String s) { + return s == null ? null : valueOf(s.toUpperCase(Locale.ENGLISH)); + } + } - private final DefaultTestPlan testPlan; private String type; private Long durationInMs; private Status status; private String name; private String message; - private String stackTrace; - private Map<DefaultInputFile, CoverageBlock> coverageBlocksByTestedFile = new LinkedHashMap<>(); - - public DefaultTestCase(DefaultTestPlan testPlan) { - this.testPlan = testPlan; - } - @Override public String type() { return type; } - @Override - public MutableTestCase setType(@Nullable String s) { + public DefaultTestCase setType(@Nullable String s) { this.type = s; return this; } - @Override public Long durationInMs() { return durationInMs; } - @Override - public MutableTestCase setDurationInMs(@Nullable Long l) { + public DefaultTestCase setDurationInMs(@Nullable Long l) { if (l != null && l < 0) { - throw new IllegalDurationException("Test duration must be positive (got: " + l + ")"); + throw new IllegalStateException("Test duration must be positive (got: " + l + ")"); } this.durationInMs = l; return this; } - @Override public Status status() { return status; } - @Override - public MutableTestCase setStatus(@Nullable Status s) { + public DefaultTestCase setStatus(@Nullable Status s) { this.status = s; return this; } - @Override public String name() { return name; } - public MutableTestCase setName(String s) { + public DefaultTestCase setName(String s) { this.name = s; return this; } - @Override public String message() { return message; } - @Override - public MutableTestCase setMessage(String s) { + public DefaultTestCase setMessage(String s) { this.message = s; return this; } - - @Override - public String stackTrace() { - return stackTrace; - } - - @Override - public MutableTestCase setStackTrace(String s) { - this.stackTrace = s; - return this; - } - - @Override - public MutableTestCase setCoverageBlock(Testable testable, List<Integer> lines) { - DefaultInputFile coveredFile = ((DefaultTestable) testable).inputFile(); - return setCoverageBlock(coveredFile, lines); - } - - @Override - public MutableTestCase setCoverageBlock(InputFile mainFile, List<Integer> lines) { - checkArgument(mainFile.type() == Type.MAIN, "Test file can only cover a main file"); - DefaultInputFile coveredFile = (DefaultInputFile) mainFile; - if (coverageBlocksByTestedFile.containsKey(coveredFile)) { - throw new CoverageAlreadyExistsException("The link between " + name() + " and " + coveredFile.key() + " already exists"); - } - coverageBlocksByTestedFile.put(coveredFile, new DefaultCoverageBlock(this, coveredFile, lines)); - return this; - } - - @Override - public TestPlan testPlan() { - return testPlan; - } - - @Override - public boolean doesCover() { - return !coverageBlocksByTestedFile.isEmpty(); - } - - @Override - public int countCoveredLines() { - throw new UnsupportedOperationException("Not supported since SQ 5.2"); - } - - @Override - public Iterable<CoverageBlock> coverageBlocks() { - return coverageBlocksByTestedFile.values(); - } - - @Override - public CoverageBlock coverageBlock(final Testable testable) { - DefaultInputFile coveredFile = ((DefaultTestable) testable).inputFile(); - return coverageBlocksByTestedFile.get(coveredFile); - } - } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestPlan.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestPlan.java index dc4e553947c..5a2a23a273f 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestPlan.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestPlan.java @@ -21,35 +21,18 @@ package org.sonar.scanner.deprecated.test; import java.util.ArrayList; import java.util.List; -import javax.annotation.CheckForNull; -import org.sonar.api.test.MutableTestCase; -import org.sonar.api.test.MutableTestPlan; -public class DefaultTestPlan implements MutableTestPlan { - private List<MutableTestCase> testCases = new ArrayList<>(); +public class DefaultTestPlan { + private final List<DefaultTestCase> testCases = new ArrayList<>(); - @Override - @CheckForNull - public Iterable<MutableTestCase> testCasesByName(String name) { - List<MutableTestCase> result = new ArrayList<>(); - for (MutableTestCase testCase : testCases()) { - if (name.equals(testCase.name())) { - result.add(testCase); - } - } - return result; - } - - @Override - public MutableTestCase addTestCase(String name) { - DefaultTestCase testCase = new DefaultTestCase(this); + public DefaultTestCase addTestCase(String name) { + DefaultTestCase testCase = new DefaultTestCase(); testCase.setName(name); testCases.add(testCase); return testCase; } - @Override - public Iterable<MutableTestCase> testCases() { + public Iterable<DefaultTestCase> testCases() { return testCases; } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestable.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestable.java deleted file mode 100644 index 87b0ff7e890..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestable.java +++ /dev/null @@ -1,86 +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.scanner.deprecated.test; - -import java.util.List; -import java.util.Map; -import java.util.SortedSet; -import org.sonar.api.test.CoverageBlock; -import org.sonar.api.test.MutableTestable; -import org.sonar.api.test.TestCase; -import org.sonar.api.batch.fs.internal.DefaultInputFile; - -public class DefaultTestable implements MutableTestable { - - private final DefaultInputFile inputFile; - - public DefaultTestable(DefaultInputFile inputFile) { - this.inputFile = inputFile; - } - - public DefaultInputFile inputFile() { - return inputFile; - } - - @Override - public List<TestCase> testCases() { - throw unsupported(); - } - - @Override - public TestCase testCaseByName(final String name) { - throw unsupported(); - } - - @Override - public int countTestCasesOfLine(Integer line) { - throw unsupported(); - } - - @Override - public Map<Integer, Integer> testCasesByLines() { - throw unsupported(); - } - - @Override - public List<TestCase> testCasesOfLine(int line) { - throw unsupported(); - } - - @Override - public SortedSet<Integer> testedLines() { - throw unsupported(); - } - - @Override - public CoverageBlock coverageBlock(final TestCase testCase) { - throw unsupported(); - } - - @Override - public Iterable<CoverageBlock> coverageBlocks() { - throw unsupported(); - } - - private static UnsupportedOperationException unsupported() { - return new UnsupportedOperationException("No more available since SQ 5.2"); - } - -} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/TestPlanBuilder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/TestPlanBuilder.java index 2dff6dc9960..b121f63246e 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/TestPlanBuilder.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/TestPlanBuilder.java @@ -22,40 +22,25 @@ package org.sonar.scanner.deprecated.test; import java.util.HashMap; import java.util.Map; import javax.annotation.CheckForNull; -import org.sonar.api.batch.fs.InputComponent; import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.InputFile.Type; -import org.sonar.api.test.MutableTestPlan; -import org.sonar.scanner.deprecated.perspectives.PerspectiveBuilder; import org.sonar.api.batch.fs.internal.DefaultInputFile; +import org.sonar.api.scanner.ScannerSide; -public class TestPlanBuilder extends PerspectiveBuilder<MutableTestPlan> { +@ScannerSide +public class TestPlanBuilder { + private final Map<InputFile, DefaultTestPlan> testPlanByFile = new HashMap<>(); - private Map<InputFile, DefaultTestPlan> testPlanByFile = new HashMap<>(); - - public TestPlanBuilder() { - super(MutableTestPlan.class); - } - - @CheckForNull - @Override - public MutableTestPlan loadPerspective(Class<MutableTestPlan> perspectiveClass, InputComponent component) { - if (component.isFile()) { - DefaultInputFile inputFile = (DefaultInputFile) component; - if (inputFile.type() == Type.TEST) { - inputFile.setPublished(true); - if (!testPlanByFile.containsKey(inputFile)) { - testPlanByFile.put(inputFile, new DefaultTestPlan()); - } - return testPlanByFile.get(inputFile); - } + public DefaultTestPlan getTestPlan(InputFile component) { + DefaultInputFile inputFile = (DefaultInputFile) component; + inputFile.setPublished(true); + if (!testPlanByFile.containsKey(inputFile)) { + testPlanByFile.put(inputFile, new DefaultTestPlan()); } - return null; + return testPlanByFile.get(inputFile); } @CheckForNull public DefaultTestPlan getTestPlanByFile(InputFile inputFile) { return testPlanByFile.get(inputFile); } - } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/TestableBuilder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/TestableBuilder.java deleted file mode 100644 index e83253b5746..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/TestableBuilder.java +++ /dev/null @@ -1,47 +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.scanner.deprecated.test; - -import javax.annotation.CheckForNull; -import org.sonar.api.batch.fs.InputComponent; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.InputFile.Type; -import org.sonar.api.test.MutableTestable; -import org.sonar.scanner.deprecated.perspectives.PerspectiveBuilder; -import org.sonar.api.batch.fs.internal.DefaultInputFile; - -public class TestableBuilder extends PerspectiveBuilder<MutableTestable> { - - public TestableBuilder() { - super(MutableTestable.class); - } - - @CheckForNull - @Override - public MutableTestable loadPerspective(Class<MutableTestable> perspectiveClass, InputComponent component) { - if (component.isFile()) { - InputFile inputFile = (InputFile) component; - if (inputFile.type() == Type.MAIN) { - return new DefaultTestable((DefaultInputFile) inputFile); - } - } - return null; - } -} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParser.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParser.java index 49c4093980e..e4cb78be0c4 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParser.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParser.java @@ -31,12 +31,12 @@ import org.codehaus.staxmate.in.SMHierarchicCursor; import org.codehaus.staxmate.in.SMInputCursor; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.sensor.SensorContext; -import org.sonar.api.test.MutableTestCase; -import org.sonar.api.test.MutableTestPlan; -import org.sonar.api.test.TestCase; import org.sonar.api.utils.MessageException; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; +import org.sonar.scanner.deprecated.test.DefaultTestCase; +import org.sonar.scanner.deprecated.test.DefaultTestCase.Status; +import org.sonar.scanner.deprecated.test.DefaultTestPlan; import org.sonar.scanner.deprecated.test.TestPlanBuilder; import static org.sonar.api.utils.Preconditions.checkState; @@ -128,7 +128,7 @@ public class GenericTestExecutionReportParser { filePath); matchedFileKeys.add(inputFile.absolutePath()); - MutableTestPlan testPlan = testPlanBuilder.loadPerspective(MutableTestPlan.class, inputFile); + DefaultTestPlan testPlan = testPlanBuilder.getTestPlan(inputFile); SMInputCursor testCaseCursor = fileCursor.childElementCursor(); while (testCaseCursor.getNext() != null) { parseTestCase(testCaseCursor, testPlan); @@ -136,25 +136,24 @@ public class GenericTestExecutionReportParser { } } - private void parseTestCase(SMInputCursor cursor, MutableTestPlan testPlan) throws XMLStreamException { + private static void parseTestCase(SMInputCursor cursor, DefaultTestPlan testPlan) throws XMLStreamException { checkElementName(cursor, "testCase"); - MutableTestCase testCase = testPlan.addTestCase(mandatoryAttribute(cursor, NAME_ATTR)); - TestCase.Status status = TestCase.Status.OK; + DefaultTestCase testCase = testPlan.addTestCase(mandatoryAttribute(cursor, NAME_ATTR)); + Status status = Status.OK; testCase.setDurationInMs(longValue(mandatoryAttribute(cursor, DURATION_ATTR), cursor, DURATION_ATTR, 0)); SMInputCursor child = cursor.descendantElementCursor(); if (child.getNext() != null) { String elementName = child.getLocalName(); if (SKIPPED.equals(elementName)) { - status = TestCase.Status.SKIPPED; + status = Status.SKIPPED; } else if (FAILURE.equals(elementName)) { - status = TestCase.Status.FAILURE; + status = Status.FAILURE; } else if (ERROR.equals(elementName)) { - status = TestCase.Status.ERROR; + status = Status.ERROR; } - if (TestCase.Status.OK != status) { + if (Status.OK != status) { testCase.setMessage(mandatoryAttribute(child, MESSAGE_ATTR)); - testCase.setStackTrace(child.collectDescendantText()); } } testCase.setStatus(status); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/platform/DefaultServer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/platform/DefaultServer.java index 77e294a2ff5..b6239eef78f 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/platform/DefaultServer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/platform/DefaultServer.java @@ -60,11 +60,6 @@ public class DefaultServer extends Server { } @Override - public File getRootDir() { - return null; - } - - @Override public String getContextPath() { return null; } @@ -80,21 +75,11 @@ public class DefaultServer extends Server { } @Override - public boolean isDev() { - return false; - } - - @Override public boolean isSecured() { return false; } @Override - public String getURL() { - return StringUtils.removeEnd(client.baseUrl(), "/"); - } - - @Override public String getPermanentServerId() { return getId(); } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/postjob/DefaultPostJobContext.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/postjob/DefaultPostJobContext.java index e926c020c59..b22bdbc8cce 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/postjob/DefaultPostJobContext.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/postjob/DefaultPostJobContext.java @@ -19,39 +19,19 @@ */ package org.sonar.scanner.postjob; -import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.postjob.PostJobContext; -import org.sonar.api.batch.postjob.issue.PostJobIssue; import org.sonar.api.config.Configuration; public class DefaultPostJobContext implements PostJobContext { private final Configuration config; - private final AnalysisMode analysisMode; - public DefaultPostJobContext(Configuration config, AnalysisMode analysisMode) { + public DefaultPostJobContext(Configuration config) { this.config = config; - this.analysisMode = analysisMode; } @Override public Configuration config() { return config; } - - @Override - public AnalysisMode analysisMode() { - return analysisMode; - } - - @Override - public Iterable<PostJobIssue> issues() { - throw new UnsupportedOperationException("Preview mode was dropped."); - } - - @Override - public Iterable<PostJobIssue> resolvedIssues() { - throw new UnsupportedOperationException("Preview mode was dropped."); - } - } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ScannerReportUtils.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ScannerReportUtils.java index f62716810fb..16371f82e75 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ScannerReportUtils.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ScannerReportUtils.java @@ -35,8 +35,6 @@ public class ScannerReportUtils { return HighlightingType.COMMENT; case CONSTANT: return HighlightingType.CONSTANT; - case CPP_DOC: - return HighlightingType.CPP_DOC; case KEYWORD: return HighlightingType.KEYWORD; case KEYWORD_LIGHT: @@ -60,8 +58,6 @@ public class ScannerReportUtils { return TypeOfText.COMMENT; case CONSTANT: return TypeOfText.CONSTANT; - case CPP_DOC: - return TypeOfText.CPP_DOC; case HIGHLIGHTING_STRING: return TypeOfText.STRING; case KEYWORD: diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionPublisher.java index 5c1591b0bee..d152d2b4990 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionPublisher.java @@ -26,11 +26,10 @@ import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultInputComponent; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure; -import org.sonar.api.test.MutableTestPlan; -import org.sonar.api.test.TestCase; -import org.sonar.api.test.TestCase.Status; +import org.sonar.scanner.deprecated.test.DefaultTestCase; +import org.sonar.scanner.deprecated.test.DefaultTestCase.Status; +import org.sonar.scanner.deprecated.test.DefaultTestPlan; import org.sonar.scanner.deprecated.test.TestPlanBuilder; -import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.protocol.output.ScannerReportWriter; import org.sonar.scanner.scan.filesystem.InputComponentStore; @@ -65,13 +64,14 @@ public class TestExecutionPublisher implements ReportPublisherStep { } private void updateTestExecutionFromTestPlan(final InputFile inputFile, ScannerReportWriter writer) { - final MutableTestPlan testPlan = testPlanBuilder.getTestPlanByFile(inputFile); + final DefaultTestPlan testPlan = testPlanBuilder.getTestPlanByFile(inputFile); if (testPlan == null || !testPlan.testCases().iterator().hasNext()) { return; } long nonSkippedTests = StreamSupport.stream(testPlan.testCases().spliterator(), false).filter(t -> t.status() != Status.SKIPPED).count(); appendMeasure(inputFile, writer, new DefaultMeasure<Integer>().forMetric(TESTS).withValue((int) nonSkippedTests)); - long executionTime = StreamSupport.stream(testPlan.testCases().spliterator(), false).map(TestCase::durationInMs).filter(Objects::nonNull).mapToLong(Long::longValue).sum(); + long executionTime = StreamSupport.stream(testPlan.testCases().spliterator(), false).map(DefaultTestCase::durationInMs).filter(Objects::nonNull).mapToLong(Long::longValue) + .sum(); appendMeasure(inputFile, writer, new DefaultMeasure<Long>().forMetric(TEST_EXECUTION_TIME).withValue(executionTime)); long errorTests = StreamSupport.stream(testPlan.testCases().spliterator(), false).filter(t -> t.status() == Status.ERROR).count(); appendMeasure(inputFile, writer, new DefaultMeasure<Integer>().forMetric(TEST_ERRORS).withValue((int) errorTests)); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleScanContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleScanContainer.java index e8f7ad17526..e67d65da9f1 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleScanContainer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleScanContainer.java @@ -19,11 +19,10 @@ */ package org.sonar.scanner.scan; +import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.scan.filesystem.FileExclusions; import org.sonar.core.platform.ComponentContainer; import org.sonar.scanner.bootstrap.ExtensionInstaller; -import org.sonar.scanner.deprecated.perspectives.ScannerPerspectives; -import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.scanner.scan.filesystem.DefaultModuleFileSystem; import org.sonar.scanner.scan.filesystem.ModuleInputComponentStore; import org.sonar.scanner.sensor.ModuleSensorContext; @@ -66,10 +65,8 @@ public class ModuleScanContainer extends ComponentContainer { ModuleSensorOptimizer.class, ModuleSensorContext.class, - ModuleSensorExtensionDictionnary.class, - - // Perspectives - ScannerPerspectives.class); + ModuleSensorExtensionDictionnary.class + ); } private void addExtensions() { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java index d6c494f76fb..e6bf8582814 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java @@ -38,11 +38,9 @@ import org.sonar.core.platform.ComponentContainer; import org.sonar.scanner.DefaultFileLinesContextFactory; import org.sonar.scanner.ProjectInfo; import org.sonar.scanner.analysis.AnalysisTempFolderProvider; -import org.sonar.scanner.analysis.DefaultAnalysisMode; import org.sonar.scanner.bootstrap.ExtensionInstaller; import org.sonar.scanner.bootstrap.ExtensionMatcher; import org.sonar.scanner.bootstrap.GlobalAnalysisMode; -import org.sonar.scanner.bootstrap.MetricProvider; import org.sonar.scanner.bootstrap.PostJobExtensionDictionnary; import org.sonar.scanner.ci.CiConfigurationProvider; import org.sonar.scanner.ci.vendors.AppVeyor; @@ -63,8 +61,6 @@ import org.sonar.scanner.ci.vendors.TravisCi; import org.sonar.scanner.cpd.CpdExecutor; import org.sonar.scanner.cpd.CpdSettings; import org.sonar.scanner.cpd.index.SonarCpdBlockIndex; -import org.sonar.scanner.deprecated.test.TestPlanBuilder; -import org.sonar.scanner.deprecated.test.TestableBuilder; import org.sonar.scanner.fs.InputModuleHierarchy; import org.sonar.scanner.issue.IssueFilters; import org.sonar.scanner.issue.IssuePublisher; @@ -168,13 +164,11 @@ public class ProjectScanContainer extends ComponentContainer { ProjectLock.class, ResourceTypes.class, ProjectReactorValidator.class, - MetricProvider.class, ProjectInfo.class, new RulesProvider(), new BranchConfigurationProvider(), new ProjectBranchesProvider(), new ProjectPullRequestsProvider(), - DefaultAnalysisMode.class, ProjectRepositoriesSupplier.class, new ProjectServerSettingsProvider(), @@ -211,10 +205,6 @@ public class ProjectScanContainer extends ComponentContainer { // metrics DefaultMetricFinder.class, - // tests - TestPlanBuilder.class, - TestableBuilder.class, - // lang Languages.class, DefaultLanguagesRepository.class, diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmConfiguration.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmConfiguration.java index 5e446aba869..a039a10d979 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmConfiguration.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmConfiguration.java @@ -29,7 +29,6 @@ import org.sonar.api.CoreProperties; import org.sonar.api.Properties; import org.sonar.api.Property; import org.sonar.api.PropertyType; -import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.scm.ScmProvider; import org.sonar.api.config.Configuration; import org.sonar.api.notifications.AnalysisWarnings; @@ -64,14 +63,12 @@ public class ScmConfiguration implements Startable { private final Configuration settings; private final AnalysisWarnings analysisWarnings; private final Map<String, ScmProvider> providerPerKey = new LinkedHashMap<>(); - private final AnalysisMode analysisMode; private final InputModuleHierarchy moduleHierarchy; private ScmProvider provider; - public ScmConfiguration(InputModuleHierarchy moduleHierarchy, AnalysisMode analysisMode, Configuration settings, AnalysisWarnings analysisWarnings, ScmProvider... providers) { + public ScmConfiguration(InputModuleHierarchy moduleHierarchy, Configuration settings, AnalysisWarnings analysisWarnings, ScmProvider... providers) { this.moduleHierarchy = moduleHierarchy; - this.analysisMode = analysisMode; this.settings = settings; this.analysisWarnings = analysisWarnings; for (ScmProvider scmProvider : providers) { @@ -79,15 +76,12 @@ public class ScmConfiguration implements Startable { } } - public ScmConfiguration(InputModuleHierarchy moduleHierarchy, AnalysisMode analysisMode, Configuration settings, AnalysisWarnings analysisWarnings) { - this(moduleHierarchy, analysisMode, settings, analysisWarnings, new ScmProvider[0]); + public ScmConfiguration(InputModuleHierarchy moduleHierarchy, Configuration settings, AnalysisWarnings analysisWarnings) { + this(moduleHierarchy, settings, analysisWarnings, new ScmProvider[0]); } @Override public void start() { - if (analysisMode.isIssues()) { - return; - } if (isDisabled()) { LOG.debug(MESSAGE_SCM_STEP_IS_DISABLED_BY_CONFIGURATION); return; |