diff options
Diffstat (limited to 'sonar-scanner-engine')
34 files changed, 118 insertions, 858 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; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/DefaultAnalysisModeTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/DefaultAnalysisModeTest.java deleted file mode 100644 index 34f2d0d9e9d..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/DefaultAnalysisModeTest.java +++ /dev/null @@ -1,36 +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 org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class DefaultAnalysisModeTest { - - @Test - public void test() { - DefaultAnalysisMode mode = new DefaultAnalysisMode(); - assertThat(mode.isPublish()).isTrue(); - assertThat(mode.isIssues()).isFalse(); - assertThat(mode.isPreview()).isFalse(); - } - -} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ExtensionInstallerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ExtensionInstallerTest.java index e60676ce65f..364567e4633 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ExtensionInstallerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ExtensionInstallerTest.java @@ -22,7 +22,6 @@ package org.sonar.scanner.bootstrap; import java.util.Arrays; import org.apache.commons.lang.ClassUtils; import org.junit.Test; -import org.sonar.api.ExtensionProvider; import org.sonar.api.Plugin; import org.sonar.api.SonarRuntime; import org.sonar.api.batch.ScannerSide; @@ -56,41 +55,9 @@ public class ExtensionInstallerTest { assertThat(container.getComponentByType(Bar.class)).isNull(); } - @Test - public void should_execute_extension_provider() { - when(pluginRepository.getPluginInfos()).thenReturn(Arrays.asList(new PluginInfo("foo"))); - when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(new FooProvider(), new BarProvider())); - ComponentContainer container = new ComponentContainer(); - ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, settings.asConfig()); - - installer.install(container, new FooMatcher()); - - assertThat(container.getComponentByType(Foo.class)).isNotNull(); - assertThat(container.getComponentByType(Bar.class)).isNull(); - } - - @Test - public void should_provide_list_of_extensions() { - when(pluginRepository.getPluginInfos()).thenReturn(Arrays.asList(new PluginInfo("foo"))); - when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(new FooBarProvider())); - ComponentContainer container = new ComponentContainer(); - ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, settings.asConfig()); - - installer.install(container, new TrueMatcher()); - - assertThat(container.getComponentByType(Foo.class)).isNotNull(); - assertThat(container.getComponentByType(Bar.class)).isNotNull(); - } - private static class FooMatcher implements ExtensionMatcher { public boolean accept(Object extension) { - return extension.equals(Foo.class) || ClassUtils.isAssignable(Foo.class, extension.getClass()) || ClassUtils.isAssignable(FooProvider.class, extension.getClass()); - } - } - - private static class TrueMatcher implements ExtensionMatcher { - public boolean accept(Object extension) { - return true; + return extension.equals(Foo.class) || ClassUtils.isAssignable(Foo.class, extension.getClass()); } } @@ -103,29 +70,4 @@ public class ExtensionInstallerTest { public static class Bar { } - - @ScannerSide - public static class FooProvider extends ExtensionProvider { - @Override - public Object provide() { - return new Foo(); - } - } - - @ScannerSide - public static class BarProvider extends ExtensionProvider { - @Override - public Object provide() { - return new Bar(); - } - } - - @ScannerSide - public static class FooBarProvider extends ExtensionProvider { - @Override - public Object provide() { - return Arrays.asList(new Foo(), new Bar()); - } - } - } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/MetricProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/MetricProviderTest.java deleted file mode 100644 index fbc809e8960..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/MetricProviderTest.java +++ /dev/null @@ -1,50 +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.Arrays; -import java.util.List; -import org.junit.Test; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Metric; -import org.sonar.api.measures.Metrics; - -import static org.assertj.core.api.Assertions.assertThat; - -public class MetricProviderTest { - @Test - public void should_provide_at_least_core_metrics() { - MetricProvider provider = new MetricProvider(); - List<Metric> metrics = provider.provide(); - - assertThat(metrics).hasSize(CoreMetrics.getMetrics().size()); - assertThat(metrics).extracting("key").contains("ncloc"); - } - - @Test - public void should_provide_plugin_metrics() { - Metrics factory = () -> Arrays.asList(new Metric.Builder("custom", "Custom", Metric.ValueType.FLOAT).create()); - MetricProvider provider = new MetricProvider(new Metrics[] {factory}); - List<Metric> metrics = provider.provide(); - - assertThat(metrics.size()).isEqualTo(1 + CoreMetrics.getMetrics().size()); - assertThat(metrics).extracting("key").contains("custom"); - } -} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/deprecated/perspectives/PerspectiveBuilderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/deprecated/test/DefaultTestCaseTest.java index ce4cf0529c9..27d4884a227 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/deprecated/perspectives/PerspectiveBuilderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/deprecated/test/DefaultTestCaseTest.java @@ -17,29 +17,28 @@ * 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; +package org.sonar.scanner.deprecated.test; import org.junit.Test; -import org.sonar.api.batch.fs.InputComponent; -import org.sonar.api.component.Perspective; import static org.assertj.core.api.Assertions.assertThat; -public class PerspectiveBuilderTest { +public class DefaultTestCaseTest { + private final DefaultTestCase testCase = new DefaultTestCase(); @Test - public void testGetPerspectiveClass() { - PerspectiveBuilder<FakePerspective> builder = new PerspectiveBuilder<FakePerspective>(FakePerspective.class) { - @Override - public FakePerspective loadPerspective(Class<FakePerspective> perspectiveClass, InputComponent component) { - return null; - } - }; - - assertThat(builder.getPerspectiveClass()).isEqualTo(FakePerspective.class); - } - - interface FakePerspective extends Perspective { + public void getters_after_setters() { + testCase + .setMessage("message") + .setName("name") + .setType("type") + .setDurationInMs(1234L) + .setStatus(DefaultTestCase.Status.FAILURE); + assertThat(testCase.status()).isEqualTo(DefaultTestCase.Status.FAILURE); + assertThat(testCase.name()).isEqualTo("name"); + assertThat(testCase.type()).isEqualTo("type"); + assertThat(testCase.durationInMs()).isEqualTo(1234L); + assertThat(testCase.message()).isEqualTo("message"); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParserTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParserTest.java index dc3ee60b081..8afe338e6e3 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParserTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParserTest.java @@ -27,19 +27,18 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.test.MutableTestCase; -import org.sonar.api.test.MutableTestPlan; -import org.sonar.api.utils.MessageException; -import org.sonar.scanner.deprecated.test.TestPlanBuilder; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.sensor.internal.SensorContextTester; +import org.sonar.api.utils.MessageException; +import org.sonar.scanner.deprecated.test.DefaultTestCase; +import org.sonar.scanner.deprecated.test.DefaultTestPlan; +import org.sonar.scanner.deprecated.test.TestPlanBuilder; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -53,7 +52,7 @@ public class GenericTestExecutionReportParserTest { private DefaultInputFile fileWithBranches; private DefaultInputFile emptyFile; private SensorContextTester context; - private MutableTestPlan testPlan; + private DefaultTestPlan testPlan; @Before public void before() { @@ -62,10 +61,10 @@ public class GenericTestExecutionReportParserTest { emptyFile = setupFile("src/main/java/com/example/EmptyClass.java"); testPlanBuilder = mock(TestPlanBuilder.class); - MutableTestCase testCase = mockMutableTestCase(); + DefaultTestCase testCase = mockMutableTestCase(); testPlan = mockMutableTestPlan(testCase); - when(testPlanBuilder.loadPerspective(eq(MutableTestPlan.class), any(InputFile.class))).thenReturn(testPlan); + when(testPlanBuilder.getTestPlan(any(InputFile.class))).thenReturn(testPlan); } @Test @@ -159,18 +158,17 @@ public class GenericTestExecutionReportParserTest { .build(); } - private MutableTestPlan mockMutableTestPlan(MutableTestCase testCase) { - MutableTestPlan testPlan = mock(MutableTestPlan.class); + private DefaultTestPlan mockMutableTestPlan(DefaultTestCase testCase) { + DefaultTestPlan testPlan = mock(DefaultTestPlan.class); when(testPlan.addTestCase(anyString())).thenReturn(testCase); return testPlan; } - private MutableTestCase mockMutableTestCase() { - MutableTestCase testCase = mock(MutableTestCase.class); + private DefaultTestCase mockMutableTestCase() { + DefaultTestCase testCase = mock(DefaultTestCase.class); when(testCase.setDurationInMs(anyLong())).thenReturn(testCase); - when(testCase.setStatus(any(org.sonar.api.test.TestCase.Status.class))).thenReturn(testCase); + when(testCase.setStatus(any(DefaultTestCase.Status.class))).thenReturn(testCase); when(testCase.setMessage(anyString())).thenReturn(testCase); - when(testCase.setStackTrace(anyString())).thenReturn(testCase); when(testCase.setType(anyString())).thenReturn(testCase); return testCase; } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/highlighting/HighlightingMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/highlighting/HighlightingMediumTest.java index 076a5309626..84eeccad942 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/highlighting/HighlightingMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/highlighting/HighlightingMediumTest.java @@ -60,7 +60,7 @@ public class HighlightingMediumTest { File xooFile = new File(srcDir, "sample.xoo"); File xoohighlightingFile = new File(srcDir, "sample.xoo.highlighting"); FileUtils.write(xooFile, "Sample xoo\ncontent plop"); - FileUtils.write(xoohighlightingFile, "0:10:s\n11:18:k"); + FileUtils.write(xoohighlightingFile, "1:0:2:0:s\n2:0:2:8:k"); AnalysisResult result = tester.newAnalysis() .properties(ImmutableMap.<String, String>builder() @@ -115,7 +115,7 @@ public class HighlightingMediumTest { File xooFile = new File(srcDir, "sample.xoo"); File xoohighlightingFile = new File(srcDir, "sample.xoo.highlighting"); FileUtils.write(xooFile, "Sample xoo\ncontent plop"); - FileUtils.write(xoohighlightingFile, "0:10:s\n18:18:k"); + FileUtils.write(xoohighlightingFile, "1:0:1:10:s\n2:18:2:18:k"); exception.expect(IllegalStateException.class); exception.expectMessage("Error processing line 2"); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/symbol/SymbolMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/symbol/SymbolMediumTest.java index f9d333716fd..085b1b3b5e6 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/symbol/SymbolMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/symbol/SymbolMediumTest.java @@ -55,7 +55,7 @@ public class SymbolMediumTest { File xooSymbolFile = new File(srcDir, "sample.xoo.symbol"); FileUtils.write(xooFile, "Sample xoo\ncontent\nanother xoo"); // Highlight xoo symbol - FileUtils.write(xooSymbolFile, "7:10,27"); + FileUtils.write(xooSymbolFile, "1:7:1:10,3:8:3:11"); AnalysisResult result = tester.newAnalysis() .properties(ImmutableMap.<String, String>builder() @@ -84,7 +84,7 @@ public class SymbolMediumTest { File xooSymbolFile = new File(srcDir, "sample.xoo.symbol"); FileUtils.write(xooFile, "Sample xoo\ncontent\nanother xoo\nyet another"); // Highlight xoo symbol - FileUtils.write(xooSymbolFile, "7:10,27:32"); + FileUtils.write(xooSymbolFile, "1:7:1:10,3:8:4:1"); AnalysisResult result = tester.newAnalysis() .properties(ImmutableMap.<String, String>builder() diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java index 246daa29d8c..09c043d88d3 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java @@ -19,12 +19,12 @@ */ package org.sonar.scanner.platform; -import org.sonar.api.SonarEdition; import org.junit.Test; import org.sonar.api.CoreProperties; +import org.sonar.api.SonarEdition; import org.sonar.api.SonarQubeSide; -import org.sonar.api.config.internal.Settings; import org.sonar.api.config.internal.MapSettings; +import org.sonar.api.config.internal.Settings; import org.sonar.api.internal.SonarRuntimeImpl; import org.sonar.api.utils.Version; import org.sonar.scanner.bootstrap.DefaultScannerWsClient; @@ -49,12 +49,10 @@ public class DefaultServerTest { assertThat(metadata.getId()).isEqualTo("123"); assertThat(metadata.getVersion()).isEqualTo("2.2"); assertThat(metadata.getStartedAt()).isNotNull(); - assertThat(metadata.getURL()).isEqualTo("http://foo.com"); + assertThat(metadata.getPublicRootUrl()).isEqualTo("http://foo.com"); assertThat(metadata.getPermanentServerId()).isEqualTo("123"); - assertThat(metadata.getRootDir()).isNull(); assertThat(metadata.getContextPath()).isNull(); - assertThat(metadata.isDev()).isFalse(); assertThat(metadata.isSecured()).isFalse(); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java index ebce30b77dd..47ca50c01d3 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java @@ -21,30 +21,26 @@ package org.sonar.scanner.postjob; import org.junit.Before; import org.junit.Test; -import org.sonar.api.batch.AnalysisMode; +import org.sonar.api.config.Configuration; import org.sonar.api.config.internal.MapSettings; -import static org.mockito.Mockito.mock; +import static org.assertj.core.api.Assertions.assertThat; public class DefaultPostJobContextTest { private DefaultPostJobContext context; private MapSettings settings; + private Configuration configuration; @Before public void setUp() { settings = new MapSettings(); - AnalysisMode analysisMode = mock(AnalysisMode.class); - context = new DefaultPostJobContext(settings.asConfig(), analysisMode); + configuration = settings.asConfig(); + context = new DefaultPostJobContext(configuration); } - @Test(expected=UnsupportedOperationException.class) - public void testIssues() { - context.issues(); - } - - @Test(expected=UnsupportedOperationException.class) - public void testResolvedIssues() { - context.resolvedIssues(); + @Test + public void getConfig() { + assertThat(context.config()).isEqualTo(configuration); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectScanContainerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectScanContainerTest.java index ac730ff28da..9769c914d97 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectScanContainerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectScanContainerTest.java @@ -23,7 +23,6 @@ import org.junit.Test; import org.sonar.api.batch.InstantiationStrategy; import org.sonar.api.batch.ScannerSide; import org.sonar.api.server.ServerSide; -import org.sonar.api.task.TaskExtension; import org.sonar.scanner.bootstrap.ExtensionMatcher; import static org.assertj.core.api.Assertions.assertThat; @@ -41,8 +40,6 @@ public class ProjectScanContainerTest { assertThat(filter.accept(MyProjectExtension.class)).isFalse(); assertThat(filter.accept(new MyServerExtension())).isFalse(); assertThat(filter.accept(MyServerExtension.class)).isFalse(); - assertThat(filter.accept(new MyTaskExtension())).isFalse(); - assertThat(filter.accept(MyTaskExtension.class)).isFalse(); } @ScannerSide @@ -61,8 +58,4 @@ public class ProjectScanContainerTest { static class MyServerExtension { } - - static class MyTaskExtension implements TaskExtension { - - } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmConfigurationTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmConfigurationTest.java index 9e87bf87ae9..70dcfe524ee 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmConfigurationTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmConfigurationTest.java @@ -31,7 +31,6 @@ import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.mockito.Answers; import org.sonar.api.CoreProperties; -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; @@ -45,7 +44,7 @@ import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; import static org.mockito.Mockito.withSettings; import static org.sonar.scanner.scm.ScmConfiguration.MESSAGE_SCM_EXCLUSIONS_IS_DISABLED_BY_CONFIGURATION; @@ -55,7 +54,6 @@ import static org.sonar.scanner.scm.ScmConfiguration.MESSAGE_SCM_STEP_IS_DISABLE public class ScmConfigurationTest { private final InputModuleHierarchy inputModuleHierarchy = mock(InputModuleHierarchy.class, withSettings().defaultAnswer(Answers.RETURNS_MOCKS)); - private final AnalysisMode analysisMode = mock(AnalysisMode.class); private final AnalysisWarnings analysisWarnings = mock(AnalysisWarnings.class); private final Configuration settings = mock(Configuration.class); @@ -71,10 +69,9 @@ public class ScmConfigurationTest { public ExpectedException thrown = ExpectedException.none(); public ScmConfigurationTest() { - when(analysisMode.isIssues()).thenReturn(false); when(scmProvider.key()).thenReturn(scmProviderKey); - underTest = new ScmConfiguration(inputModuleHierarchy, analysisMode, settings, analysisWarnings, scmProvider); + underTest = new ScmConfiguration(inputModuleHierarchy, settings, analysisWarnings, scmProvider); } @Test @@ -84,7 +81,14 @@ public class ScmConfigurationTest { underTest.start(); assertThat(underTest.provider()).isNotNull(); - verifyZeroInteractions(analysisWarnings); + verifyNoInteractions(analysisWarnings); + } + + @Test + public void no_provider_if_no_provider_is_available() { + ScmConfiguration underTest = new ScmConfiguration(inputModuleHierarchy, settings, analysisWarnings); + assertThat(underTest.provider()).isNull(); + verifyNoInteractions(analysisWarnings); } @Test @@ -135,23 +139,12 @@ public class ScmConfigurationTest { } @Test - public void return_early_from_start_in_issues_mode() { - // return early = doesn't reach the logging when disabled - when(settings.getBoolean(CoreProperties.SCM_DISABLED_KEY)).thenReturn(Optional.of(true)); - when(analysisMode.isIssues()).thenReturn(true); - - underTest.start(); - - assertThat(logTester.logs()).isEmpty(); - } - - @Test public void fail_when_multiple_scm_providers_claim_support() { when(scmProvider.supports(any())).thenReturn(true); when(scmProvider.key()).thenReturn("key1", "key2"); ScmProvider[] providers = {scmProvider, scmProvider}; - ScmConfiguration underTest = new ScmConfiguration(inputModuleHierarchy, analysisMode, settings, analysisWarnings, providers); + ScmConfiguration underTest = new ScmConfiguration(inputModuleHierarchy, settings, analysisWarnings, providers); thrown.expect(MessageException.class); thrown.expectMessage( diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java index a9c2ebb510f..96b1b58dccb 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java @@ -213,7 +213,7 @@ public class DefaultSensorStorageTest { DefaultInputFile file = new TestInputFileBuilder("foo", "src/Foo.php") .setContents("// comment").build(); - DefaultHighlighting highlighting = new DefaultHighlighting(underTest).onFile(file).highlight(0, 1, TypeOfText.KEYWORD); + DefaultHighlighting highlighting = new DefaultHighlighting(underTest).onFile(file).highlight(1, 0, 1, 1, TypeOfText.KEYWORD); underTest.store(highlighting); assertThat(reportWriter.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, file.scannerId())).isTrue(); @@ -226,7 +226,7 @@ public class DefaultSensorStorageTest { .setStatus(InputFile.Status.SAME).build(); when(branchConfiguration.isPullRequest()).thenReturn(true); - DefaultHighlighting highlighting = new DefaultHighlighting(underTest).onFile(file).highlight(0, 1, TypeOfText.KEYWORD); + DefaultHighlighting highlighting = new DefaultHighlighting(underTest).onFile(file).highlight(1, 0, 1, 1, TypeOfText.KEYWORD); underTest.store(highlighting); assertThat(reportWriter.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, file.scannerId())).isFalse(); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorOptimizerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorOptimizerTest.java index 08c1e3d97d7..f0054ef1546 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorOptimizerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorOptimizerTest.java @@ -25,14 +25,14 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.rule.ActiveRules; -import org.sonar.api.batch.rule.internal.NewActiveRule; -import org.sonar.api.config.internal.MapSettings; import org.sonar.api.batch.fs.internal.DefaultFileSystem; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; +import org.sonar.api.batch.rule.ActiveRules; +import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; +import org.sonar.api.batch.rule.internal.NewActiveRule; import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor; +import org.sonar.api.config.internal.MapSettings; import org.sonar.api.rule.RuleKey; -import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; import static org.assertj.core.api.Assertions.assertThat; @@ -123,8 +123,8 @@ public class ModuleSensorOptimizerTest { @Test public void should_optimize_on_settings() { - DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor() - .requireProperty("sonar.foo.reportPath"); + DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor(); + descriptor.onlyWhenConfiguration(c -> c.hasKey("sonar.foo.reportPath")); assertThat(optimizer.shouldExecute(descriptor)).isFalse(); settings.setProperty("sonar.foo.reportPath", "foo"); |