From: Julien HENRY Date: Wed, 19 Oct 2016 08:33:11 +0000 (+0200) Subject: Move old test API to deprecated package X-Git-Tag: 6.2-RC1~309 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=87660673df0efcb981b8bd1c831d3df33e75810a;p=sonarqube.git Move old test API to deprecated package --- 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 new file mode 100644 index 00000000000..95d8e2a2b77 --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultCoverageBlock.java @@ -0,0 +1,54 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.batch.fs.internal.DefaultInputFile; +import org.sonar.api.test.CoverageBlock; +import org.sonar.api.test.TestCase; +import org.sonar.api.test.Testable; + +public class DefaultCoverageBlock implements CoverageBlock { + + private final TestCase testCase; + private final DefaultInputFile testable; + private final List lines; + + public DefaultCoverageBlock(TestCase testCase, DefaultInputFile testable, List 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 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 new file mode 100644 index 00000000000..522b47307f8 --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestCase.java @@ -0,0 +1,163 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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 com.google.common.base.Preconditions; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +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; + +public class DefaultTestCase implements MutableTestCase { + + private final DefaultTestPlan testPlan; + private String type; + private Long durationInMs; + private Status status; + private String name; + private String message; + private String stackTrace; + private Map coverageBlocksByTestedFile = new LinkedHashMap<>(); + + public DefaultTestCase(DefaultTestPlan testPlan) { + this.testPlan = testPlan; + } + + @Override + public String type() { + return type; + } + + @Override + public MutableTestCase setType(@Nullable String s) { + this.type = s; + return this; + } + + @Override + public Long durationInMs() { + return durationInMs; + } + + @Override + public MutableTestCase setDurationInMs(@Nullable Long l) { + if (l != null && l < 0) { + throw new IllegalDurationException("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) { + this.status = s; + return this; + } + + @Override + public String name() { + return name; + } + + public MutableTestCase setName(String s) { + this.name = s; + return this; + } + + @Override + public String message() { + return message; + } + + @Override + public MutableTestCase 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 lines) { + DefaultInputFile coveredFile = ((DefaultTestable) testable).inputFile(); + return setCoverageBlock(coveredFile, lines); + } + + @Override + public MutableTestCase setCoverageBlock(InputFile mainFile, List lines) { + Preconditions.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 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 new file mode 100644 index 00000000000..0c64de43637 --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestPlan.java @@ -0,0 +1,57 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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 com.google.common.collect.Lists; +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 testCases = new ArrayList<>(); + + @Override + @CheckForNull + public Iterable testCasesByName(String name) { + List result = Lists.newArrayList(); + 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); + testCase.setName(name); + testCases.add(testCase); + return testCase; + } + + @Override + public Iterable 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 new file mode 100644 index 00000000000..e59067275b6 --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestable.java @@ -0,0 +1,86 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.batch.fs.internal.DefaultInputFile; +import org.sonar.api.test.CoverageBlock; +import org.sonar.api.test.MutableTestable; +import org.sonar.api.test.TestCase; + +public class DefaultTestable implements MutableTestable { + + private final DefaultInputFile inputFile; + + public DefaultTestable(DefaultInputFile inputFile) { + this.inputFile = inputFile; + } + + public DefaultInputFile inputFile() { + return inputFile; + } + + @Override + public List testCases() { + throw unsupported(); + } + + @Override + public TestCase testCaseByName(final String name) { + throw unsupported(); + } + + @Override + public int countTestCasesOfLine(Integer line) { + throw unsupported(); + } + + @Override + public Map testCasesByLines() { + throw unsupported(); + } + + @Override + public List testCasesOfLine(int line) { + throw unsupported(); + } + + @Override + public SortedSet testedLines() { + throw unsupported(); + } + + @Override + public CoverageBlock coverageBlock(final TestCase testCase) { + throw unsupported(); + } + + @Override + public Iterable 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 new file mode 100644 index 00000000000..94fbfd0ef18 --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/TestPlanBuilder.java @@ -0,0 +1,54 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.HashMap; +import java.util.Map; +import javax.annotation.CheckForNull; +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.scanner.index.BatchComponent; + +public class TestPlanBuilder extends PerspectiveBuilder { + + private Map testPlanByFile = new HashMap<>(); + + public TestPlanBuilder() { + super(MutableTestPlan.class); + } + + @CheckForNull + @Override + public MutableTestPlan loadPerspective(Class perspectiveClass, BatchComponent component) { + if (component.isFile()) { + InputFile inputFile = (InputFile) component.inputComponent(); + if (inputFile.type() == Type.TEST) { + if (!testPlanByFile.containsKey(inputFile)) { + testPlanByFile.put(inputFile, new DefaultTestPlan()); + } + return testPlanByFile.get(inputFile); + } + } + return null; + } + +} 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 new file mode 100644 index 00000000000..4c9c3de46fb --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/TestableBuilder.java @@ -0,0 +1,47 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.InputFile; +import org.sonar.api.batch.fs.InputFile.Type; +import org.sonar.api.batch.fs.internal.DefaultInputFile; +import org.sonar.api.test.MutableTestable; +import org.sonar.scanner.deprecated.perspectives.PerspectiveBuilder; +import org.sonar.scanner.index.BatchComponent; + +public class TestableBuilder extends PerspectiveBuilder { + + public TestableBuilder() { + super(MutableTestable.class); + } + + @CheckForNull + @Override + public MutableTestable loadPerspective(Class perspectiveClass, BatchComponent component) { + if (component.isFile()) { + InputFile inputFile = (InputFile) component.inputComponent(); + if (inputFile.type() == Type.MAIN) { + return new DefaultTestable((DefaultInputFile) inputFile); + } + } + return null; + } +} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/package-info.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/package-info.java new file mode 100644 index 00000000000..d0d8c9b59ed --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.test; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisher.java index c920a34f0fe..e5f7cc0cbe1 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisher.java @@ -30,14 +30,14 @@ import org.sonar.api.test.CoverageBlock; import org.sonar.api.test.MutableTestCase; import org.sonar.api.test.MutableTestPlan; import org.sonar.api.test.TestCase; +import org.sonar.scanner.deprecated.test.DefaultTestable; +import org.sonar.scanner.deprecated.test.TestPlanBuilder; import org.sonar.scanner.index.BatchComponent; import org.sonar.scanner.index.BatchComponentCache; import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.protocol.output.ScannerReport.CoverageDetail; import org.sonar.scanner.protocol.output.ScannerReport.Test; import org.sonar.scanner.protocol.output.ScannerReport.Test.TestStatus; -import org.sonar.scanner.test.DefaultTestable; -import org.sonar.scanner.test.TestPlanBuilder; import org.sonar.scanner.protocol.output.ScannerReportWriter; public class TestExecutionAndCoveragePublisher implements ReportPublisherStep { 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 310acabe741..c7c34eb64d2 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 @@ -42,6 +42,8 @@ import org.sonar.scanner.bootstrap.ExtensionUtils; import org.sonar.scanner.bootstrap.MetricProvider; import org.sonar.scanner.cpd.CpdExecutor; 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.events.EventBus; import org.sonar.scanner.index.BatchComponentCache; import org.sonar.scanner.index.DefaultIndex; @@ -90,8 +92,6 @@ import org.sonar.scanner.scan.measure.DeprecatedMetricFinder; import org.sonar.scanner.scan.measure.MeasureCache; import org.sonar.scanner.source.CodeColorizers; import org.sonar.scanner.storage.Storages; -import org.sonar.scanner.test.TestPlanBuilder; -import org.sonar.scanner.test.TestableBuilder; public class ProjectScanContainer extends ComponentContainer { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/test/DefaultCoverageBlock.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/test/DefaultCoverageBlock.java deleted file mode 100644 index 003a099b8d6..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/test/DefaultCoverageBlock.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.test; - -import java.util.List; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.test.CoverageBlock; -import org.sonar.api.test.TestCase; -import org.sonar.api.test.Testable; - -public class DefaultCoverageBlock implements CoverageBlock { - - private final TestCase testCase; - private final DefaultInputFile testable; - private final List lines; - - public DefaultCoverageBlock(TestCase testCase, DefaultInputFile testable, List 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 lines() { - return lines; - } -} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/test/DefaultTestCase.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/test/DefaultTestCase.java deleted file mode 100644 index b87cee936d5..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/test/DefaultTestCase.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.test; - -import com.google.common.base.Preconditions; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -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; - -public class DefaultTestCase implements MutableTestCase { - - private final DefaultTestPlan testPlan; - private String type; - private Long durationInMs; - private Status status; - private String name; - private String message; - private String stackTrace; - private Map coverageBlocksByTestedFile = new LinkedHashMap<>(); - - public DefaultTestCase(DefaultTestPlan testPlan) { - this.testPlan = testPlan; - } - - @Override - public String type() { - return type; - } - - @Override - public MutableTestCase setType(@Nullable String s) { - this.type = s; - return this; - } - - @Override - public Long durationInMs() { - return durationInMs; - } - - @Override - public MutableTestCase setDurationInMs(@Nullable Long l) { - if (l != null && l < 0) { - throw new IllegalDurationException("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) { - this.status = s; - return this; - } - - @Override - public String name() { - return name; - } - - public MutableTestCase setName(String s) { - this.name = s; - return this; - } - - @Override - public String message() { - return message; - } - - @Override - public MutableTestCase 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 lines) { - DefaultInputFile coveredFile = ((DefaultTestable) testable).inputFile(); - return setCoverageBlock(coveredFile, lines); - } - - @Override - public MutableTestCase setCoverageBlock(InputFile mainFile, List lines) { - Preconditions.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 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/test/DefaultTestPlan.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/test/DefaultTestPlan.java deleted file mode 100644 index 65f7da160a9..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/test/DefaultTestPlan.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.test; - -import com.google.common.collect.Lists; -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 testCases = new ArrayList<>(); - - @Override - @CheckForNull - public Iterable testCasesByName(String name) { - List result = Lists.newArrayList(); - 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); - testCase.setName(name); - testCases.add(testCase); - return testCase; - } - - @Override - public Iterable testCases() { - return testCases; - } - -} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/test/DefaultTestable.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/test/DefaultTestable.java deleted file mode 100644 index cf99ba2cc75..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/test/DefaultTestable.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.test; - -import java.util.List; -import java.util.Map; -import java.util.SortedSet; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.test.CoverageBlock; -import org.sonar.api.test.MutableTestable; -import org.sonar.api.test.TestCase; - -public class DefaultTestable implements MutableTestable { - - private final DefaultInputFile inputFile; - - public DefaultTestable(DefaultInputFile inputFile) { - this.inputFile = inputFile; - } - - public DefaultInputFile inputFile() { - return inputFile; - } - - @Override - public List testCases() { - throw unsupported(); - } - - @Override - public TestCase testCaseByName(final String name) { - throw unsupported(); - } - - @Override - public int countTestCasesOfLine(Integer line) { - throw unsupported(); - } - - @Override - public Map testCasesByLines() { - throw unsupported(); - } - - @Override - public List testCasesOfLine(int line) { - throw unsupported(); - } - - @Override - public SortedSet testedLines() { - throw unsupported(); - } - - @Override - public CoverageBlock coverageBlock(final TestCase testCase) { - throw unsupported(); - } - - @Override - public Iterable 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/test/TestPlanBuilder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/test/TestPlanBuilder.java deleted file mode 100644 index 7376eb0a174..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/test/TestPlanBuilder.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.test; - -import java.util.HashMap; -import java.util.Map; -import javax.annotation.CheckForNull; -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.scanner.index.BatchComponent; - -public class TestPlanBuilder extends PerspectiveBuilder { - - private Map testPlanByFile = new HashMap<>(); - - public TestPlanBuilder() { - super(MutableTestPlan.class); - } - - @CheckForNull - @Override - public MutableTestPlan loadPerspective(Class perspectiveClass, BatchComponent component) { - if (component.isFile()) { - InputFile inputFile = (InputFile) component.inputComponent(); - if (inputFile.type() == Type.TEST) { - if (!testPlanByFile.containsKey(inputFile)) { - testPlanByFile.put(inputFile, new DefaultTestPlan()); - } - return testPlanByFile.get(inputFile); - } - } - return null; - } - -} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/test/TestableBuilder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/test/TestableBuilder.java deleted file mode 100644 index 2f327a344f2..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/test/TestableBuilder.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.test; - -import javax.annotation.CheckForNull; -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.MutableTestable; -import org.sonar.scanner.deprecated.perspectives.PerspectiveBuilder; -import org.sonar.scanner.index.BatchComponent; - -public class TestableBuilder extends PerspectiveBuilder { - - public TestableBuilder() { - super(MutableTestable.class); - } - - @CheckForNull - @Override - public MutableTestable loadPerspective(Class perspectiveClass, BatchComponent component) { - if (component.isFile()) { - InputFile inputFile = (InputFile) component.inputComponent(); - if (inputFile.type() == Type.MAIN) { - return new DefaultTestable((DefaultInputFile) inputFile); - } - } - return null; - } -} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/test/package-info.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/test/package-info.java deleted file mode 100644 index e52c37000b7..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/test/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.test; - -import javax.annotation.ParametersAreNonnullByDefault;