diff --git a/.travis.yml b/.travis.yml index 96bb4aa11f..e3d59395f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,4 +51,4 @@ script: after_failure: - cat $SONARHOME/logs/sonar.log - - find . -name _cpp-multimodule-project-2_.log | xargs cat + - find . -name "*.log" | xargs cat diff --git a/integration-tests/testdata/cpp-multimodule-project/sonar-project.properties b/integration-tests/testdata/cpp-multimodule-project/sonar-project.properties index ba2f42ced9..906d1a1cf0 100644 --- a/integration-tests/testdata/cpp-multimodule-project/sonar-project.properties +++ b/integration-tests/testdata/cpp-multimodule-project/sonar-project.properties @@ -1,18 +1,22 @@ sonar.host.url=http://localhost:9000 sonar.modules=cli,lib,package1,package2 -cli.sonar.projectBaseDir=cli -cli.sonar.sources=. + +cli.sonar.projectBaseDir=/home/travis/build/SonarOpenCommunity/sonar-cxx/integration-tests/testdata/cpp-multimodule-project/ +cli.sonar.sources=cli cli.sonar.projectName=cli cli.sonar.cxx.includeDirectories=../../googletest_project/tests/gtest-1.6.0/include/gtest -lib.sonar.projectBaseDir=lib -lib.sonar.sources=. + +lib.sonar.projectBaseDir=/home/travis/build/SonarOpenCommunity/sonar-cxx/integration-tests/testdata/cpp-multimodule-project/ +lib.sonar.sources=lib lib.sonar.projectName=lib -package1.sonar.projectBaseDir=package1 -package1.sonar.sources=. + +package1.sonar.projectBaseDir=/home/travis/build/SonarOpenCommunity/sonar-cxx/integration-tests/testdata/cpp-multimodule-project/ +package1.sonar.sources=package1 package1.sonar.projectName=package1 -package2.sonar.projectBaseDir=package2 -package2.sonar.sources=. + +package2.sonar.projectBaseDir=/home/travis/build/SonarOpenCommunity/sonar-cxx/integration-tests/testdata/cpp-multimodule-project/ +package2.sonar.sources=package2 package2.sonar.projectName=package2 sonar.projectKey=cpp-multimodule-project @@ -41,7 +45,7 @@ sonar.cxx.xunit.reportPath=sonarcpp/reports-xunit/*.xml sonar.cxx.coverage.reportPath=sonarcpp/bullseye-coverage-results/bullseyecoverage-result-0.xml sonar.cxx.coverage.itReportPath=sonarcpp/bullseye-coverage-results/bullseyecoverage-result-1.xml sonar.cxx.coverage.overallReportPath=sonarcpp/bullseye-coverage-results/bullseyecoverage-result-2.xml - + sonar.cxx.defines=__cdecl, \n\ __declspec(a), \n\ __pragma(a), \n\ diff --git a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/compiler/CxxCompilerSensor.java b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/compiler/CxxCompilerSensor.java index 5cca70791a..0ed22e16c6 100644 --- a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/compiler/CxxCompilerSensor.java +++ b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/compiler/CxxCompilerSensor.java @@ -35,7 +35,6 @@ import org.sonar.plugins.cxx.utils.CxxMetrics; import org.sonar.plugins.cxx.utils.CxxReportSensor; import org.sonar.plugins.cxx.utils.CxxUtils; -import org.sonar.api.batch.bootstrap.ProjectReactor; /** * compiler for C++ with advanced analysis features (e.g. for VC 2008 team edition or 2010/2012/2013 premium edition) @@ -56,8 +55,8 @@ public class CxxCompilerSensor extends CxxReportSensor { /** * {@inheritDoc} */ - public CxxCompilerSensor(ResourcePerspectives perspectives, Settings settings, FileSystem fs, RulesProfile profile, ProjectReactor reactor) { - super(perspectives, settings, fs, reactor, CxxMetrics.COMPILER); + public CxxCompilerSensor(ResourcePerspectives perspectives, Settings settings, FileSystem fs, RulesProfile profile) { + super(perspectives, settings, fs, CxxMetrics.COMPILER); this.profile = profile; addCompilerParser(new CxxCompilerVcParser()); diff --git a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/coverage/CxxCoverageSensor.java b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/coverage/CxxCoverageSensor.java index 600ebfe1ac..ab4d6e31cd 100644 --- a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/coverage/CxxCoverageSensor.java +++ b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/coverage/CxxCoverageSensor.java @@ -29,7 +29,6 @@ import javax.xml.stream.XMLStreamException; import org.sonar.api.batch.SensorContext; -import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.FilePredicates; import org.sonar.api.batch.fs.InputFile; @@ -61,15 +60,12 @@ private enum CoverageType { public static final String FORCE_ZERO_COVERAGE_KEY = "sonar.cxx.coverage.forceZeroCoverage"; private List parsers = new LinkedList<>(); - private final ProjectReactor reactor; /** * {@inheritDoc} */ - public CxxCoverageSensor(Settings settings, FileSystem fs, ProjectReactor reactor) { - super(settings, fs, reactor); - - this.reactor = reactor; + public CxxCoverageSensor(Settings settings, FileSystem fs) { + super(settings, fs); final String baseDir = fs.baseDir().getAbsolutePath(); parsers.add(new CoberturaParser(baseDir)); parsers.add(new BullseyeParser(baseDir)); @@ -97,30 +93,21 @@ public void analyse(Project project, SensorContext context) { if (settings.hasKey(REPORT_PATH_KEY)) { CxxUtils.LOG.debug("Parsing coverage reports"); - List reports = getReports(settings, - reactor.getRoot().getBaseDir().getAbsolutePath(), - fs.baseDir().getPath(), - REPORT_PATH_KEY); + List reports = getReports(settings, fs.baseDir(), REPORT_PATH_KEY); coverageMeasures = processReports(project, context, reports); saveMeasures(context, coverageMeasures, CoverageType.UT_COVERAGE); } if (settings.hasKey(IT_REPORT_PATH_KEY)) { CxxUtils.LOG.debug("Parsing integration test coverage reports"); - List itReports = getReports(settings, - reactor.getRoot().getBaseDir().getAbsolutePath(), - fs.baseDir().getPath(), - IT_REPORT_PATH_KEY); + List itReports = getReports(settings, fs.baseDir(), IT_REPORT_PATH_KEY); itCoverageMeasures = processReports(project, context, itReports); saveMeasures(context, itCoverageMeasures, CoverageType.IT_COVERAGE); } if (settings.hasKey(OVERALL_REPORT_PATH_KEY)) { CxxUtils.LOG.debug("Parsing overall test coverage reports"); - List overallReports = getReports(settings, - reactor.getRoot().getBaseDir().getAbsolutePath(), - fs.baseDir().getPath(), - OVERALL_REPORT_PATH_KEY); + List overallReports = getReports(settings, fs.baseDir(), OVERALL_REPORT_PATH_KEY); overallCoverageMeasures = processReports(project, context, overallReports); saveMeasures(context, overallCoverageMeasures, CoverageType.OVERALL_COVERAGE); } diff --git a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/cppcheck/CxxCppCheckSensor.java b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/cppcheck/CxxCppCheckSensor.java index ae8269b9a6..96a7cd6fb9 100644 --- a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/cppcheck/CxxCppCheckSensor.java +++ b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/cppcheck/CxxCppCheckSensor.java @@ -28,7 +28,6 @@ import org.sonar.api.batch.SensorContext; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.component.ResourcePerspectives; -import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.api.config.Settings; import org.sonar.api.profiles.RulesProfile; import org.sonar.api.resources.Project; @@ -52,8 +51,8 @@ public class CxxCppCheckSensor extends CxxReportSensor { * {@inheritDoc} */ public CxxCppCheckSensor(ResourcePerspectives perspectives, Settings settings, FileSystem fs, - RulesProfile profile, ProjectReactor reactor) { - super(perspectives, settings, fs, reactor, CxxMetrics.CPPCHECK); + RulesProfile profile) { + super(perspectives, settings, fs, CxxMetrics.CPPCHECK); this.profile = profile; parsers.add(new CppcheckParserV2(this)); parsers.add(new CppcheckParserV1(this)); diff --git a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/externalrules/CxxExternalRulesSensor.java b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/externalrules/CxxExternalRulesSensor.java index ac3a1b877e..d5320f69d7 100644 --- a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/externalrules/CxxExternalRulesSensor.java +++ b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/externalrules/CxxExternalRulesSensor.java @@ -34,7 +34,6 @@ import org.sonar.api.utils.StaxParser; import org.sonar.plugins.cxx.utils.CxxMetrics; import org.sonar.plugins.cxx.utils.CxxReportSensor; -import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.plugins.cxx.utils.CxxUtils; /** @@ -50,8 +49,8 @@ public class CxxExternalRulesSensor extends CxxReportSensor { /** * {@inheritDoc} */ - public CxxExternalRulesSensor(ResourcePerspectives perspectives, Settings settings, FileSystem fs, RulesProfile profile, ProjectReactor reactor) { - super(perspectives, settings, fs, reactor, CxxMetrics.EXTERNAL); + public CxxExternalRulesSensor(ResourcePerspectives perspectives, Settings settings, FileSystem fs, RulesProfile profile) { + super(perspectives, settings, fs, CxxMetrics.EXTERNAL); this.profile = profile; } diff --git a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/pclint/CxxPCLintSensor.java b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/pclint/CxxPCLintSensor.java index 259ac0959d..662768a252 100644 --- a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/pclint/CxxPCLintSensor.java +++ b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/pclint/CxxPCLintSensor.java @@ -39,7 +39,6 @@ import org.sonar.plugins.cxx.utils.CxxReportSensor; import org.sonar.plugins.cxx.utils.CxxUtils; import org.sonar.plugins.cxx.utils.EmptyReportException; -import org.sonar.api.batch.bootstrap.ProjectReactor; /** * PC-lint is an equivalent to pmd but for C++ The first version of the tool was @@ -57,8 +56,8 @@ public class CxxPCLintSensor extends CxxReportSensor { /** * {@inheritDoc} */ - public CxxPCLintSensor(ResourcePerspectives perspectives, Settings settings, FileSystem fs, RulesProfile profile, ProjectReactor reactor) { - super(perspectives, settings, fs, reactor, CxxMetrics.PCLINT); + public CxxPCLintSensor(ResourcePerspectives perspectives, Settings settings, FileSystem fs, RulesProfile profile) { + super(perspectives, settings, fs, CxxMetrics.PCLINT); this.profile = profile; } diff --git a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/rats/CxxRatsSensor.java b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/rats/CxxRatsSensor.java index 22bed54aa0..f3d757cd61 100644 --- a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/rats/CxxRatsSensor.java +++ b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/rats/CxxRatsSensor.java @@ -33,7 +33,6 @@ import org.sonar.plugins.cxx.utils.CxxMetrics; import org.sonar.plugins.cxx.utils.CxxReportSensor; import org.sonar.plugins.cxx.utils.CxxUtils; -import org.sonar.api.batch.bootstrap.ProjectReactor; /** * {@inheritDoc} @@ -46,8 +45,8 @@ public final class CxxRatsSensor extends CxxReportSensor { /** * {@inheritDoc} */ - public CxxRatsSensor(ResourcePerspectives perspectives, Settings settings, FileSystem fs, RulesProfile profile, ProjectReactor reactor) { - super(perspectives, settings, fs, reactor, CxxMetrics.RATS); + public CxxRatsSensor(ResourcePerspectives perspectives, Settings settings, FileSystem fs, RulesProfile profile) { + super(perspectives, settings, fs, CxxMetrics.RATS); this.profile = profile; } diff --git a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/squid/CxxSquidSensor.java b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/squid/CxxSquidSensor.java index ffa6d2d1f4..2caf606880 100644 --- a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/squid/CxxSquidSensor.java +++ b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/squid/CxxSquidSensor.java @@ -164,7 +164,7 @@ private CxxConfiguration createConfiguration(FileSystem fs, Settings settings) { String filePaths = settings.getString(CxxCompilerSensor.REPORT_PATH_KEY); if (filePaths != null && !"".equals(filePaths)) { - List reports = CxxReportSensor.getReports(settings, fs.baseDir().getPath(), "", CxxCompilerSensor.REPORT_PATH_KEY); + List reports = CxxReportSensor.getReports(settings, fs.baseDir(), CxxCompilerSensor.REPORT_PATH_KEY); cxxConf.setCompilationPropertiesWithBuildLog(reports, settings.getString(CxxCompilerSensor.PARSER_KEY_DEF), settings.getString(CxxCompilerSensor.REPORT_CHARSET_DEF)); diff --git a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/utils/CxxReportSensor.java b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/utils/CxxReportSensor.java index ec45c776d3..95fc1ef77a 100644 --- a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/utils/CxxReportSensor.java +++ b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/utils/CxxReportSensor.java @@ -24,14 +24,12 @@ import java.util.List; import java.util.ArrayList; import java.util.Set; - import org.apache.commons.io.FilenameUtils; import org.sonar.api.batch.Sensor; import org.sonar.api.batch.SensorContext; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.component.ResourcePerspectives; -import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.api.issue.Issuable; import org.sonar.api.issue.Issue; import org.sonar.api.measures.Measure; @@ -51,24 +49,22 @@ public abstract class CxxReportSensor implements Sensor { private ResourcePerspectives perspectives; - private Set notFoundFiles = new HashSet(); - private Set uniqueIssues = new HashSet(); + private Set notFoundFiles = new HashSet<>(); + private Set uniqueIssues = new HashSet<>(); private final Metric metric; private int violationsCount; protected FileSystem fs; protected CxxSettings settings; - private final ProjectReactor reactor; /** * Use this constructor if you dont have to save violations aka issues * * @param settings the Settings object used to access the configuration properties * @param fs file system access layer - * @param reactor */ - protected CxxReportSensor(Settings settings, FileSystem fs, ProjectReactor reactor) { - this(null, settings, fs, reactor, null); + protected CxxReportSensor(Settings settings, FileSystem fs) { + this(null, settings, fs, null); } /** @@ -79,19 +75,18 @@ protected CxxReportSensor(Settings settings, FileSystem fs, ProjectReactor react * @param fs file system access layer * @param metric this metrics will be used to save a measure of the overall * issue count. Pass 'null' to skip this. - * @param reactor */ - protected CxxReportSensor(ResourcePerspectives perspectives, Settings settings, FileSystem fs, ProjectReactor reactor, Metric metric) { + protected CxxReportSensor(ResourcePerspectives perspectives, Settings settings, FileSystem fs, Metric metric) { this.settings = new CxxSettings(settings); this.fs = fs; this.metric = metric; - this.reactor = reactor; this.perspectives = perspectives; } /** * {@inheritDoc} */ + @Override public boolean shouldExecuteOnProject(Project project) { return fs.hasFiles(fs.predicates().hasLanguage(CxxLanguage.KEY)) && settings.hasKey(reportPathKey()); @@ -100,40 +95,36 @@ public boolean shouldExecuteOnProject(Project project) { /** * {@inheritDoc} */ + @Override public void analyse(Project project, SensorContext context) { - if (!CxxUtils.isReactorProject(project)) { - try { - List reports = getReports(settings, - reactor.getRoot().getBaseDir().getCanonicalPath(), - fs.baseDir().getPath(), - reportPathKey()); - violationsCount = 0; + try { + List reports = getReports(settings, fs.baseDir(), reportPathKey()); + violationsCount = 0; - for (File report : reports) { - CxxUtils.LOG.info("Processing report '{}'", report); - try { - int prevViolationsCount = violationsCount; - processReport(project, context, report); - CxxUtils.LOG.info("{} processed = {}", metric == null ? "Issues" : metric.getName(), - violationsCount - prevViolationsCount); - } catch (EmptyReportException e) { - CxxUtils.LOG.warn("The report '{}' seems to be empty, ignoring.", report); - } + for (File report : reports) { + CxxUtils.LOG.info("Processing report '{}'", report); + try { + int prevViolationsCount = violationsCount; + processReport(project, context, report); + CxxUtils.LOG.info("{} processed = {}", metric == null ? "Issues" : metric.getName(), + violationsCount - prevViolationsCount); + } catch (EmptyReportException e) { + CxxUtils.LOG.warn("The report '{}' seems to be empty, ignoring.", report); } + } - if (metric != null) { - Measure measure = new Measure(metric); - measure.setIntValue(violationsCount); - context.saveMeasure(measure); - } - } catch (Exception e) { - String msg = new StringBuilder() - .append("Cannot feed the data into sonar, details: '") - .append(e) - .append("'") - .toString(); - throw new IllegalStateException(msg, e); + if (metric != null) { + Measure measure = new Measure(metric); + measure.setIntValue(violationsCount); + context.saveMeasure(measure); } + } catch (Exception e) { + String msg = new StringBuilder() + .append("Cannot feed the data into sonar, details: '") + .append(e) + .append("'") + .toString(); + throw new IllegalStateException(msg, e); } } @@ -150,12 +141,11 @@ protected String getStringProperty(String name, String def) { } public static List getReports(Settings settings, - String reactorBaseDir, - String moduleBaseDir, + File moduleBaseDir, String reportPathPropertyKey) { String reportPath = settings.getString(reportPathPropertyKey); - List reports = new ArrayList(); + List reports = new ArrayList<>(); if (reportPath != null && !reportPath.isEmpty()) { reportPath = FilenameUtils.normalize(reportPath); @@ -164,10 +154,7 @@ public static List getReports(Settings settings, reports.add(singleFile); } else { CxxUtils.LOG.debug("Using pattern '{}' to find reports", reportPath); - CxxUtils.GetReportForBaseDirAndPattern(reactorBaseDir, reportPath, reports); - if (reports.isEmpty() && !moduleBaseDir.isEmpty()) { - CxxUtils.GetReportForBaseDirAndPattern(moduleBaseDir, reportPath, reports); - } + CxxUtils.GetReportForBaseDirAndPattern(moduleBaseDir.getPath(), reportPath, reports); if (reports.isEmpty()) { CxxUtils.LOG.warn("Cannot find a report for '{}={}'", reportPathPropertyKey, reportPath); } @@ -204,7 +191,7 @@ private void saveViolation(Project project, SensorContext context, String ruleRe int lineNr = 0; // handles file="" situation -- file level if ((filename != null) && (filename.length() > 0)) { - String root = reactor.getRoot().getBaseDir().getAbsolutePath(); + String root = fs.baseDir().getAbsolutePath(); String normalPath = CxxUtils.normalizePathFull(filename, root); if (normalPath != null && !notFoundFiles.contains(normalPath)) { InputFile inputFile = fs.inputFile(fs.predicates().is(new File(normalPath))); diff --git a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/utils/CxxUtils.java b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/utils/CxxUtils.java index 87eb8179f5..ab47636e59 100644 --- a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/utils/CxxUtils.java +++ b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/utils/CxxUtils.java @@ -24,10 +24,8 @@ import java.nio.file.Path; import java.util.Collection; import java.util.List; -import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.commons.io.FilenameUtils; -import org.apache.tools.ant.DirectoryScanner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -146,9 +144,6 @@ public static String normalizePathFull(String filename, String baseDir) { } return filePath; } - - public static boolean isReactorProject(Project project) { - return project.isRoot() && !project.getModules().isEmpty(); - } + } diff --git a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/valgrind/CxxValgrindSensor.java b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/valgrind/CxxValgrindSensor.java index 70629d0180..16dac15f3e 100644 --- a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/valgrind/CxxValgrindSensor.java +++ b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/valgrind/CxxValgrindSensor.java @@ -31,7 +31,6 @@ import org.sonar.plugins.cxx.utils.CxxMetrics; import org.sonar.plugins.cxx.utils.CxxReportSensor; import org.sonar.plugins.cxx.utils.CxxUtils; -import org.sonar.api.batch.bootstrap.ProjectReactor; /** * {@inheritDoc} @@ -43,8 +42,8 @@ public class CxxValgrindSensor extends CxxReportSensor { /** * {@inheritDoc} */ - public CxxValgrindSensor(ResourcePerspectives perspectives, Settings settings, FileSystem fs, RulesProfile profile, ProjectReactor reactor) { - super(perspectives, settings, fs, reactor, CxxMetrics.VALGRIND); + public CxxValgrindSensor(ResourcePerspectives perspectives, Settings settings, FileSystem fs, RulesProfile profile) { + super(perspectives, settings, fs, CxxMetrics.VALGRIND); this.profile = profile; } diff --git a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/veraxx/CxxVeraxxSensor.java b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/veraxx/CxxVeraxxSensor.java index 04b6fd9b7a..8df7fb0ecd 100644 --- a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/veraxx/CxxVeraxxSensor.java +++ b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/veraxx/CxxVeraxxSensor.java @@ -26,7 +26,6 @@ import org.sonar.api.batch.SensorContext; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.component.ResourcePerspectives; -import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.api.config.Settings; import org.sonar.api.profiles.RulesProfile; import org.sonar.api.resources.Project; @@ -46,8 +45,8 @@ public class CxxVeraxxSensor extends CxxReportSensor { /** * {@inheritDoc} */ - public CxxVeraxxSensor(ResourcePerspectives perspectives, Settings settings, FileSystem fs, RulesProfile profile, ProjectReactor reactor) { - super(perspectives, settings, fs, reactor, CxxMetrics.VERAXX); + public CxxVeraxxSensor(ResourcePerspectives perspectives, Settings settings, FileSystem fs, RulesProfile profile) { + super(perspectives, settings, fs, CxxMetrics.VERAXX); this.profile = profile; } diff --git a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/xunit/CxxXunitSensor.java b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/xunit/CxxXunitSensor.java index d76b64f9e6..bf3e1dbbe7 100644 --- a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/xunit/CxxXunitSensor.java +++ b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/xunit/CxxXunitSensor.java @@ -62,7 +62,6 @@ import org.sonar.squidbridge.api.SourceCode; import org.sonar.squidbridge.api.SourceFile; import org.sonar.squidbridge.api.SourceFunction; -import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.api.batch.fs.InputFile; @@ -87,8 +86,8 @@ public class CxxXunitSensor extends CxxReportSensor { /** * {@inheritDoc} */ - public CxxXunitSensor(Settings settings, FileSystem fs, ProjectReactor reactor) { - super(settings, fs, reactor); + public CxxXunitSensor(Settings settings, FileSystem fs) { + super(settings, fs); xsltURL = settings.getString(XSLT_URL_KEY); } @@ -126,7 +125,7 @@ public boolean shouldExecuteOnProject(Project project) { @Override public void analyse(Project project, SensorContext context) { try{ - List reports = getReports(settings, fs.baseDir().getPath(), "", REPORT_PATH_KEY); + List reports = getReports(settings, fs.baseDir(), REPORT_PATH_KEY); if (!reports.isEmpty()) { XunitReportParser parserHandler = new XunitReportParser(); StaxParser parser = new StaxParser(parserHandler, false); diff --git a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/TestUtils.java b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/TestUtils.java index 27e0adfbfa..ad633e8f16 100644 --- a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/TestUtils.java +++ b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/TestUtils.java @@ -37,8 +37,6 @@ import org.sonar.api.batch.fs.internal.DefaultFileSystem; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.component.ResourcePerspectives; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.api.config.Settings; import org.sonar.api.issue.Issuable; import org.sonar.api.issue.Issue; @@ -112,16 +110,6 @@ public static DefaultFileSystem mockFileSystem(File baseDir) { return mockFileSystem(baseDir, Arrays.asList(new File(".")), null); } - public static ProjectReactor mockReactor(File baseDir, - List sourceDirs, List testDirs) { - ProjectReactor reactor = mock(ProjectReactor.class); - ProjectDefinition projectDef = mock(ProjectDefinition.class); - when(reactor.getRoot()).thenReturn(projectDef); - when(projectDef.getBaseDir()).thenReturn(baseDir); - - return reactor; - } - /** * Mocks the filesystem given the root directory and lists of source * and tests directories. The latter are given just as in sonar-project.properties @@ -141,12 +129,6 @@ public static DefaultFileSystem mockFileSystem(File baseDir, return fs; } - public static ProjectReactor mockReactor() { - File baseDir = loadResource("/org/sonar/plugins/cxx/reports-project"); - List empty = new ArrayList(); - return mockReactor(baseDir, empty, empty); - } - /** * Returns the default filesystem mock */ diff --git a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/compiler/CxxCompilerSensorTest.java b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/compiler/CxxCompilerSensorTest.java index a2d326d770..6ecdc05a6a 100644 --- a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/compiler/CxxCompilerSensorTest.java +++ b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/compiler/CxxCompilerSensorTest.java @@ -63,7 +63,7 @@ public void shouldReportACorrectVcViolations() { settings.setProperty(CxxCompilerSensor.REPORT_PATH_KEY, "compiler-reports/BuildLog.htm"); settings.setProperty(CxxCompilerSensor.REPORT_CHARSET_DEF, "UTF-16"); TestUtils.addInputFile(fs, perspectives, issuable, "zipmanager.cpp"); - CxxCompilerSensor sensor = new CxxCompilerSensor(perspectives, settings, fs, profile, TestUtils.mockReactor()); + CxxCompilerSensor sensor = new CxxCompilerSensor(perspectives, settings, fs, profile); sensor.analyse(project, context); verify(issuable, times(9)).addIssue(any(Issue.class)); } @@ -75,7 +75,7 @@ public void shouldReportCorrectGccViolations() { settings.setProperty(CxxCompilerSensor.REPORT_PATH_KEY, "compiler-reports/build.log"); settings.setProperty(CxxCompilerSensor.REPORT_CHARSET_DEF, "UTF-8"); TestUtils.addInputFile(fs, perspectives, issuable, "/home/test/src/zip/src/zipmanager.cpp"); - CxxCompilerSensor sensor = new CxxCompilerSensor(perspectives, settings, fs, profile, TestUtils.mockReactor()); + CxxCompilerSensor sensor = new CxxCompilerSensor(perspectives, settings, fs, profile); sensor.analyse(project, context); verify(issuable, times(4)).addIssue(any(Issue.class)); } @@ -88,7 +88,7 @@ public void shouldReportBCorrectVcViolations() { settings.setProperty(CxxCompilerSensor.REPORT_CHARSET_DEF, "UTF-8"); settings.setProperty(CxxCompilerSensor.REPORT_REGEX_DEF, "^.*>(?.*)\\((?\\d+)\\):\\x20warning\\x20(?C\\d+):(?.*)$"); TestUtils.addInputFile(fs, perspectives, issuable, "Server/source/zip/zipmanager.cpp"); - CxxCompilerSensor sensor = new CxxCompilerSensor(perspectives, settings, fs, profile, TestUtils.mockReactor()); + CxxCompilerSensor sensor = new CxxCompilerSensor(perspectives, settings, fs, profile); sensor.analyse(project, context); verify(issuable, times(9)).addIssue(any(Issue.class)); } diff --git a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/coverage/CxxBullseyeCoverageSensorTest.java b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/coverage/CxxBullseyeCoverageSensorTest.java index fd9d5a1816..7d3d850eb3 100644 --- a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/coverage/CxxBullseyeCoverageSensorTest.java +++ b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/coverage/CxxBullseyeCoverageSensorTest.java @@ -89,7 +89,7 @@ public void shouldReportCorrectCoverage() { TestUtils.addInputFile(fs, perspectives, issuable, "/home/path/TESTCOV/main.cpp"); TestUtils.addInputFile(fs, perspectives, issuable, "/home/path/TESTCOV/testclass.h"); } - sensor = new CxxCoverageSensor(settings, fs, TestUtils.mockReactor()); + sensor = new CxxCoverageSensor(settings, fs); sensor.analyse(project, context); verify(context, times(90)).saveMeasure((InputFile) anyObject(), any(Measure.class)); } @@ -110,7 +110,7 @@ public void shoulParseTopLevelFiles() { TestUtils.addInputFile(fs, perspectives, issuable, "/c/test/test2/test2.c"); TestUtils.addInputFile(fs, perspectives, issuable, "/c/test/main.c"); } - sensor = new CxxCoverageSensor(settings, fs, TestUtils.mockReactor()); + sensor = new CxxCoverageSensor(settings, fs); sensor.analyse(project, context); verify(context, times(28)).saveMeasure((InputFile) anyObject(), any(Measure.class)); } @@ -132,7 +132,7 @@ public void shoulCorrectlyHandleDriveLettersWithoutSlash() { TestUtils.addInputFile(fs, perspectives, issuable, "/c/test2/test2.c"); TestUtils.addInputFile(fs, perspectives, issuable, "/c/anotherincludeattop.h"); } - sensor = new CxxCoverageSensor(settings, fs, TestUtils.mockReactor()); + sensor = new CxxCoverageSensor(settings, fs); sensor.analyse(project, context); verify(context, times(28)).saveMeasure((InputFile) anyObject(), any(Measure.class)); } diff --git a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/coverage/CxxCoverageSensorTest.java b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/coverage/CxxCoverageSensorTest.java index 364e2d448b..13053c11a5 100644 --- a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/coverage/CxxCoverageSensorTest.java +++ b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/coverage/CxxCoverageSensorTest.java @@ -22,7 +22,6 @@ import org.sonar.api.batch.SensorContext; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultFileSystem; -import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.api.config.Settings; import org.sonar.api.measures.Measure; import org.sonar.api.resources.Project; @@ -47,7 +46,6 @@ public class CxxCoverageSensorTest { private SensorContext context; private Project project; private DefaultFileSystem fs; - private ProjectReactor reactor; private Issuable issuable; private ResourcePerspectives perspectives; @@ -57,7 +55,6 @@ public void setUp() { issuable = TestUtils.mockIssuable(); perspectives = TestUtils.mockPerspectives(issuable); fs = TestUtils.mockFileSystem(); - reactor = TestUtils.mockReactor(); context = mock(SensorContext.class); } @@ -72,7 +69,7 @@ public void shouldReportCorrectCoverageOnUnitTestCoverage() { TestUtils.addInputFile(fs, perspectives, issuable, "sources/utils/code_chunks.cpp"); TestUtils.addInputFile(fs, perspectives, issuable, "sources/application/main.cpp"); TestUtils.addInputFile(fs, perspectives, issuable, "builds/Unix Makefiles/COVERAGE/tests/moc_SAMPLE-test.cxx"); - sensor = new CxxCoverageSensor(settings, fs, TestUtils.mockReactor()); + sensor = new CxxCoverageSensor(settings, fs); sensor.analyse(project, context); verify(context, times(33)).saveMeasure((InputFile) anyObject(), any(Measure.class)); } @@ -90,14 +87,14 @@ public void shouldReportCorrectCoverageForAllTypesOfCoverage() { TestUtils.addInputFile(fs, perspectives, issuable, "sources/utils/code_chunks.cpp"); TestUtils.addInputFile(fs, perspectives, issuable, "sources/application/main.cpp"); TestUtils.addInputFile(fs, perspectives, issuable, "builds/Unix Makefiles/COVERAGE/tests/moc_SAMPLE-test.cxx"); - sensor = new CxxCoverageSensor(settings, fs, TestUtils.mockReactor()); + sensor = new CxxCoverageSensor(settings, fs); sensor.analyse(project, context); verify(context, times(99)).saveMeasure((InputFile) anyObject(), any(Measure.class)); } @Test public void shouldReportNoCoverageSaved() { - sensor = new CxxCoverageSensor(new Settings(), fs, TestUtils.mockReactor()); + sensor = new CxxCoverageSensor(new Settings(), fs); when(context.getResource((InputFile) anyObject())).thenReturn(null); sensor.analyse(project, context); verify(context, times(0)).saveMeasure((InputFile) anyObject(), any(Measure.class)); @@ -107,7 +104,7 @@ public void shouldReportNoCoverageSaved() { public void shouldNotCrashWhenProcessingReportsContainingBigNumberOfHits() { Settings settings = new Settings(); settings.setProperty(CxxCoverageSensor.REPORT_PATH_KEY, "coverage-reports/cobertura/specific-cases/cobertura-bignumberofhits.xml"); - sensor = new CxxCoverageSensor(settings, fs, reactor); + sensor = new CxxCoverageSensor(settings, fs); sensor.analyse(project, context); } @@ -115,7 +112,7 @@ public void shouldNotCrashWhenProcessingReportsContainingBigNumberOfHits() { public void shouldReportNoCoverageWhenInvalidFilesEmpty() { Settings settings = new Settings(); settings.setProperty(CxxCoverageSensor.REPORT_PATH_KEY, "coverage-reports/cobertura/specific-cases/coverage-result-cobertura-empty.xml"); - sensor = new CxxCoverageSensor(settings, fs, TestUtils.mockReactor()); + sensor = new CxxCoverageSensor(settings, fs); sensor.analyse(project, context); verify(context, times(0)).saveMeasure((InputFile) anyObject(), any(Measure.class)); } @@ -124,7 +121,7 @@ public void shouldReportNoCoverageWhenInvalidFilesEmpty() { public void shouldReportNoCoverageWhenInvalidFilesInvalid() { Settings settings = new Settings(); settings.setProperty(CxxCoverageSensor.REPORT_PATH_KEY, "coverage-reports/cobertura/specific-cases/coverage-result-invalid.xml"); - sensor = new CxxCoverageSensor(settings, fs, TestUtils.mockReactor()); + sensor = new CxxCoverageSensor(settings, fs); sensor.analyse(project, context); verify(context, times(0)).saveMeasure((InputFile) anyObject(), any(Measure.class)); } @@ -143,7 +140,7 @@ public void shouldReportCoverageWhenVisualStudioCase() { TestUtils.addInputFile(fs, perspectives, issuable, "/x/coveragetest/project2/source1.cpp"); TestUtils.addInputFile(fs, perspectives, issuable, "/x/coveragetest/project2/source2.cpp"); } - sensor = new CxxCoverageSensor(settings, fs, TestUtils.mockReactor()); + sensor = new CxxCoverageSensor(settings, fs); sensor.analyse(project, context); verify(context, times(21)).saveMeasure((InputFile) anyObject(), any(Measure.class)); } diff --git a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/cppcheck/CxxCppCheckSensorTest.java b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/cppcheck/CxxCppCheckSensorTest.java index 66a317b566..af01f6411e 100644 --- a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/cppcheck/CxxCppCheckSensorTest.java +++ b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/cppcheck/CxxCppCheckSensorTest.java @@ -28,7 +28,6 @@ import org.sonar.api.profiles.RulesProfile; import org.sonar.api.resources.Project; import org.sonar.plugins.cxx.TestUtils; -import org.sonar.api.batch.bootstrap.ProjectReactor; import org.junit.Before; import org.junit.Test; @@ -46,7 +45,6 @@ public class CxxCppCheckSensorTest { private RulesProfile profile; private Settings settings; private DefaultFileSystem fs; - private ProjectReactor reactor; private Issuable issuable; private ResourcePerspectives perspectives; @@ -55,18 +53,18 @@ public void setUp() { project = TestUtils.mockProject(); fs = TestUtils.mockFileSystem(); issuable = TestUtils.mockIssuable(); - reactor = TestUtils.mockReactor(); perspectives = TestUtils.mockPerspectives(issuable); profile = mock(RulesProfile.class); settings = new Settings(); + sensor = new CxxCppCheckSensor(perspectives, settings, fs, profile); context = mock(SensorContext.class); } @Test public void shouldReportCorrectViolations() { settings.setProperty(CxxCppCheckSensor.REPORT_PATH_KEY, - "cppcheck-reports/cppcheck-result-*.xml"); - sensor = new CxxCppCheckSensor(perspectives, settings, fs, profile, reactor); + "cppcheck-reports/cppcheck-result-*.xml"); + sensor = new CxxCppCheckSensor(perspectives, settings, fs, profile); TestUtils.addInputFile(fs, perspectives, issuable, "sources/utils/code_chunks.cpp"); TestUtils.addInputFile(fs, perspectives, issuable, "sources/utils/utils.cpp"); sensor.analyse(project, context); @@ -77,7 +75,7 @@ public void shouldReportCorrectViolations() { public void shouldReportProjectLevelViolationsV1() { settings.setProperty(CxxCppCheckSensor.REPORT_PATH_KEY, "cppcheck-reports/cppcheck-result-projectlevelviolation-V1.xml"); - sensor = new CxxCppCheckSensor(perspectives, settings, fs, profile, reactor); + sensor = new CxxCppCheckSensor(perspectives, settings, fs, profile); sensor.analyse(project, context); verify(issuable, times(3)).addIssue(any(Issue.class)); } @@ -86,7 +84,7 @@ public void shouldReportProjectLevelViolationsV1() { public void shouldReportProjectLevelViolationsV2() { settings.setProperty(CxxCppCheckSensor.REPORT_PATH_KEY, "cppcheck-reports/cppcheck-result-projectlevelviolation-V2.xml"); - sensor = new CxxCppCheckSensor(perspectives, settings, fs, profile, reactor); + sensor = new CxxCppCheckSensor(perspectives, settings, fs, profile); sensor.analyse(project, context); verify(issuable, times(3)).addIssue(any(Issue.class)); } @@ -95,7 +93,7 @@ public void shouldReportProjectLevelViolationsV2() { public void shouldIgnoreAViolationWhenTheResourceCouldntBeFoundV1() { settings.setProperty(CxxCppCheckSensor.REPORT_PATH_KEY, "cppcheck-reports/cppcheck-result-SAMPLE-V1.xml"); - sensor = new CxxCppCheckSensor(perspectives, settings, fs, profile, reactor); + sensor = new CxxCppCheckSensor(perspectives, settings, fs, profile); sensor.analyse(project, context); verify(issuable, times(0)).addIssue(any(Issue.class)); } @@ -104,7 +102,7 @@ public void shouldIgnoreAViolationWhenTheResourceCouldntBeFoundV1() { public void shouldIgnoreAViolationWhenTheResourceCouldntBeFoundV2() { settings.setProperty(CxxCppCheckSensor.REPORT_PATH_KEY, "cppcheck-reports/cppcheck-result-SAMPLE-V2.xml"); - sensor = new CxxCppCheckSensor(perspectives, settings, fs, profile, reactor); + sensor = new CxxCppCheckSensor(perspectives, settings, fs, profile); sensor.analyse(project, context); verify(issuable, times(0)).addIssue(any(Issue.class)); } diff --git a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/externalrules/CxxExternalRulesSensorTest.java b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/externalrules/CxxExternalRulesSensorTest.java index d9c9ec2554..26d1cc2267 100644 --- a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/externalrules/CxxExternalRulesSensorTest.java +++ b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/externalrules/CxxExternalRulesSensorTest.java @@ -20,7 +20,6 @@ package org.sonar.plugins.cxx.externalrules; import org.sonar.api.batch.SensorContext; -import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.api.batch.fs.internal.DefaultFileSystem; import org.sonar.api.component.ResourcePerspectives; import org.sonar.api.config.Settings; @@ -47,7 +46,6 @@ public class CxxExternalRulesSensorTest { private Settings settings; private DefaultFileSystem fs; private Issuable issuable; - private ProjectReactor reactor; private ResourcePerspectives perspectives; @Before @@ -56,7 +54,6 @@ public void setUp() { issuable = TestUtils.mockIssuable(); perspectives = TestUtils.mockPerspectives(issuable); fs = TestUtils.mockFileSystem(); - reactor = TestUtils.mockReactor(); profile = mock(RulesProfile.class); context = mock(SensorContext.class); settings = new Settings(); @@ -67,7 +64,7 @@ public void shouldReportCorrectViolations() { settings.setProperty(CxxExternalRulesSensor.REPORT_PATH_KEY, "externalrules-reports/externalrules-result-ok.xml"); TestUtils.addInputFile(fs, perspectives, issuable, "sources/utils/code_chunks.cpp"); TestUtils.addInputFile(fs, perspectives, issuable, "sources/utils/utils.cpp"); - sensor = new CxxExternalRulesSensor(perspectives, settings, fs, profile, reactor); + sensor = new CxxExternalRulesSensor(perspectives, settings, fs, profile); sensor.analyse(project, context); verify(issuable, times(2)).addIssue(any(Issue.class)); } @@ -77,7 +74,7 @@ public void shouldReportFileLevelViolations() { settings.setProperty(CxxExternalRulesSensor.REPORT_PATH_KEY, "externalrules-reports/externalrules-result-filelevelviolation.xml"); TestUtils.addInputFile(fs, perspectives, issuable, "sources/utils/code_chunks.cpp"); - sensor = new CxxExternalRulesSensor(perspectives, settings, fs, profile, reactor); + sensor = new CxxExternalRulesSensor(perspectives, settings, fs, profile); sensor.analyse(project, context); verify(issuable, times(1)).addIssue(any(Issue.class)); } @@ -86,7 +83,7 @@ public void shouldReportFileLevelViolations() { public void shouldReportProjectLevelViolations() { settings.setProperty(CxxExternalRulesSensor.REPORT_PATH_KEY, "externalrules-reports/externalrules-result-projectlevelviolation.xml"); - sensor = new CxxExternalRulesSensor(perspectives, settings, fs, profile, reactor); + sensor = new CxxExternalRulesSensor(perspectives, settings, fs, profile); sensor.analyse(project, context); verify(issuable, times(1)).addIssue(any(Issue.class)); } @@ -94,7 +91,7 @@ public void shouldReportProjectLevelViolations() { @Test(expected = IllegalStateException.class) public void shouldThrowExceptionWhenReportEmpty() { settings.setProperty(CxxExternalRulesSensor.REPORT_PATH_KEY, "externalrules-reports/externalrules-result-empty.xml"); - sensor = new CxxExternalRulesSensor(perspectives, settings, fs, profile, reactor); + sensor = new CxxExternalRulesSensor(perspectives, settings, fs, profile); sensor.analyse(project, context); verify(issuable, times(0)).addIssue(any(Issue.class)); } @@ -103,7 +100,7 @@ public void shouldThrowExceptionWhenReportEmpty() { public void shouldReportNoViolationsIfNoReportFound() { settings = new Settings(); settings.setProperty(CxxExternalRulesSensor.REPORT_PATH_KEY, "externalrules-reports/noreport.xml"); - sensor = new CxxExternalRulesSensor(perspectives, settings, fs, profile, reactor); + sensor = new CxxExternalRulesSensor(perspectives, settings, fs, profile); sensor.analyse(project, context); verify(issuable, times(0)).addIssue(any(Issue.class)); } @@ -112,7 +109,7 @@ public void shouldReportNoViolationsIfNoReportFound() { public void shouldThrowInCaseOfATrashyReport() { settings = new Settings(); settings.setProperty(CxxExternalRulesSensor.REPORT_PATH_KEY, "externalrules-reports/externalrules-result-invalid.xml"); - sensor = new CxxExternalRulesSensor(perspectives, settings, fs, profile, reactor); + sensor = new CxxExternalRulesSensor(perspectives, settings, fs, profile); sensor.analyse(project, context); } @@ -121,7 +118,7 @@ public void shouldReportOnlyOneViolationAndRemoveDuplicates() { settings = new Settings(); settings.setProperty(CxxExternalRulesSensor.REPORT_PATH_KEY, "externalrules-reports/externalrules-with-duplicates.xml"); TestUtils.addInputFile(fs, perspectives, issuable, "sources/utils/code_chunks.cpp"); - sensor = new CxxExternalRulesSensor(perspectives, settings, fs, profile, reactor); + sensor = new CxxExternalRulesSensor(perspectives, settings, fs, profile); sensor.analyse(project, context); verify(issuable, times(1)).addIssue(any(Issue.class)); } diff --git a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/pclint/CxxPCLintSensorTest.java b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/pclint/CxxPCLintSensorTest.java index de3aefcc00..148082978d 100644 --- a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/pclint/CxxPCLintSensorTest.java +++ b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/pclint/CxxPCLintSensorTest.java @@ -28,7 +28,6 @@ import org.sonar.api.profiles.RulesProfile; import org.sonar.api.resources.Project; import org.sonar.plugins.cxx.TestUtils; -import org.sonar.api.batch.bootstrap.ProjectReactor; import org.junit.Before; import org.junit.Test; @@ -46,14 +45,12 @@ public class CxxPCLintSensorTest { private ResourcePerspectives perspectives; private Issuable issuable; private DefaultFileSystem fs; - private ProjectReactor reactor; @Before public void setUp() { project = TestUtils.mockProject(); fs = TestUtils.mockFileSystem(); issuable = TestUtils.mockIssuable(); - reactor = TestUtils.mockReactor(); perspectives = TestUtils.mockPerspectives(issuable); profile = mock(RulesProfile.class); context = mock(SensorContext.class); @@ -66,7 +63,7 @@ public void shouldReportCorrectViolations() { TestUtils.addInputFile(fs, perspectives, issuable, "FileZip.cpp"); TestUtils.addInputFile(fs, perspectives, issuable, "FileZip.h"); TestUtils.addInputFile(fs, perspectives, issuable, "ZipManager.cpp"); - CxxPCLintSensor sensor = new CxxPCLintSensor(perspectives, settings, fs, profile, reactor); + CxxPCLintSensor sensor = new CxxPCLintSensor(perspectives, settings, fs, profile); sensor.analyse(project, context); verify(issuable, times(14)).addIssue(any(Issue.class)); } @@ -76,7 +73,7 @@ public void shouldReportCorrectMisra2004Violations() { Settings settings = new Settings(); settings.setProperty(CxxPCLintSensor.REPORT_PATH_KEY, "pclint-reports/pclint-result-MISRA2004-SAMPLE1.xml"); TestUtils.addInputFile(fs, perspectives, issuable, "test.c"); - CxxPCLintSensor sensor = new CxxPCLintSensor(perspectives, settings, fs, profile, reactor); + CxxPCLintSensor sensor = new CxxPCLintSensor(perspectives, settings, fs, profile); sensor.analyse(project, context); verify(issuable, times(29)).addIssue(any(Issue.class)); } @@ -86,7 +83,7 @@ public void shouldReportCorrectMisra2004PcLint9Violations() { Settings settings = new Settings(); settings.setProperty(CxxPCLintSensor.REPORT_PATH_KEY, "pclint-reports/pclint-result-MISRA2004-SAMPLE2.xml"); TestUtils.addInputFile(fs, perspectives, issuable, "test.c"); - CxxPCLintSensor sensor = new CxxPCLintSensor(perspectives, settings, fs, profile, reactor); + CxxPCLintSensor sensor = new CxxPCLintSensor(perspectives, settings, fs, profile); sensor.analyse(project, context); verify(issuable, times(1)).addIssue(any(Issue.class)); } @@ -96,7 +93,7 @@ public void shouldThrowExceptionWhenMisra2004DescIsWrong() { Settings settings = new Settings(); settings.setProperty(CxxPCLintSensor.REPORT_PATH_KEY, "pclint-reports/incorrect-pclint-MISRA2004-desc.xml"); TestUtils.addInputFile(fs, perspectives, issuable, "test.c"); - CxxPCLintSensor sensor = new CxxPCLintSensor(perspectives, settings, fs, profile, reactor); + CxxPCLintSensor sensor = new CxxPCLintSensor(perspectives, settings, fs, profile); sensor.analyse(project, context); } @@ -105,7 +102,7 @@ public void shouldThrowExceptionWhenMisra2004RuleDoNotExist() { Settings settings = new Settings(); settings.setProperty(CxxPCLintSensor.REPORT_PATH_KEY, "pclint-reports/incorrect-pclint-MISRA2004-rule-do-not-exist.xml"); TestUtils.addInputFile(fs, perspectives, issuable, "test.c"); - CxxPCLintSensor sensor = new CxxPCLintSensor(perspectives, settings, fs, profile, reactor); + CxxPCLintSensor sensor = new CxxPCLintSensor(perspectives, settings, fs, profile); sensor.analyse(project, context); } @@ -114,7 +111,7 @@ public void shouldNotRemapMisra1998Rules() { Settings settings = new Settings(); settings.setProperty(CxxPCLintSensor.REPORT_PATH_KEY, "pclint-reports/pclint-result-MISRA1998-SAMPLE.xml"); TestUtils.addInputFile(fs, perspectives, issuable, "test.c"); - CxxPCLintSensor sensor = new CxxPCLintSensor(perspectives, settings, fs, profile, reactor); + CxxPCLintSensor sensor = new CxxPCLintSensor(perspectives, settings, fs, profile); sensor.analyse(project, context); verify(issuable, times(1)).addIssue(any(Issue.class)); } @@ -123,7 +120,7 @@ public void shouldNotRemapMisra1998Rules() { public void shouldReportProjectLevelViolations() { Settings settings = new Settings(); settings.setProperty(CxxPCLintSensor.REPORT_PATH_KEY, "pclint-reports/pclint-result-projectlevelviolation.xml"); - CxxPCLintSensor sensor = new CxxPCLintSensor(perspectives, settings, fs, profile, reactor); + CxxPCLintSensor sensor = new CxxPCLintSensor(perspectives, settings, fs, profile); sensor.analyse(project, context); verify(issuable, times(1)).addIssue(any(Issue.class)); } @@ -132,7 +129,7 @@ public void shouldReportProjectLevelViolations() { public void shouldThrowExceptionInvalidChar() { Settings settings = new Settings(); settings.setProperty(CxxPCLintSensor.REPORT_PATH_KEY, "pclint-reports/pclint-result-invalid-char.xml"); - CxxPCLintSensor sensor = new CxxPCLintSensor(perspectives, settings, fs, profile, reactor); + CxxPCLintSensor sensor = new CxxPCLintSensor(perspectives, settings, fs, profile); sensor.analyse(project, context); } } diff --git a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/rats/CxxRatsSensorTest.java b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/rats/CxxRatsSensorTest.java index 1b9a2114d6..4a151ea2f8 100644 --- a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/rats/CxxRatsSensorTest.java +++ b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/rats/CxxRatsSensorTest.java @@ -54,7 +54,7 @@ public void setUp() { perspectives = TestUtils.mockPerspectives(issuable); Settings settings = new Settings(); settings.setProperty(CxxRatsSensor.REPORT_PATH_KEY, "rats-reports/rats-result-*.xml"); - sensor = new CxxRatsSensor(perspectives, settings, fs, mock(RulesProfile.class), TestUtils.mockReactor()); + sensor = new CxxRatsSensor(perspectives, settings, fs, mock(RulesProfile.class)); context = mock(SensorContext.class); } diff --git a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/utils/CxxReportSensorTest.java b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/utils/CxxReportSensorTest.java index 1cd46ca96d..739589eaa9 100644 --- a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/utils/CxxReportSensorTest.java +++ b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/utils/CxxReportSensorTest.java @@ -29,7 +29,6 @@ import org.sonar.api.config.Settings; import org.sonar.api.resources.Project; import org.sonar.plugins.cxx.TestUtils; -import org.sonar.api.batch.bootstrap.ProjectReactor; public class CxxReportSensorTest { private final String VALID_REPORT_PATH = "cppcheck-reports/cppcheck-result-*.xml"; @@ -37,8 +36,8 @@ public class CxxReportSensorTest { private final String REPORT_PATH_PROPERTY_KEY = "cxx.reportPath"; private class CxxReportSensorImpl extends CxxReportSensor { - public CxxReportSensorImpl(Settings settings, FileSystem fs, ProjectReactor reactor){ - super(settings, fs, reactor); + public CxxReportSensorImpl(Settings settings, FileSystem fs){ + super(settings, fs); } @Override @@ -50,15 +49,12 @@ public void analyse(Project p, SensorContext sc) { private File baseDir; private Settings settings; private static FileSystem fs; - private ProjectReactor reactor; @Before public void init() { settings = new Settings(); fs = TestUtils.mockFileSystem(); - reactor = TestUtils.mockReactor(); - - sensor = new CxxReportSensorImpl(settings, fs, reactor); + sensor = new CxxReportSensorImpl(settings, fs); try { baseDir = new File(getClass().getResource("/org/sonar/plugins/cxx/reports-project/").toURI()); } catch (java.net.URISyntaxException e) { @@ -68,46 +64,34 @@ public void init() { @Test public void shouldntThrowWhenInstantiating() { - new CxxReportSensorImpl(settings, fs, reactor); + new CxxReportSensorImpl(settings, fs); } @Test public void getReports_shouldFindNothingIfNoKey() { settings.setProperty(REPORT_PATH_PROPERTY_KEY, INVALID_REPORT_PATH); - List reports = sensor.getReports(settings, baseDir.getPath(), "", - ""); + List reports = sensor.getReports(settings, baseDir, ""); assertNotFound(reports); } @Test public void getReports_shouldFindNothingIfNoPath() { settings.setProperty(REPORT_PATH_PROPERTY_KEY, ""); - List reports = sensor.getReports(settings, baseDir.getPath(), "", - REPORT_PATH_PROPERTY_KEY); + List reports = sensor.getReports(settings, baseDir, REPORT_PATH_PROPERTY_KEY); assertNotFound(reports); } @Test public void getReports_shouldFindNothingIfInvalidPath() { settings.setProperty(REPORT_PATH_PROPERTY_KEY, INVALID_REPORT_PATH); - List reports = sensor.getReports(settings, baseDir.getPath(), "", - REPORT_PATH_PROPERTY_KEY); + List reports = sensor.getReports(settings, baseDir, REPORT_PATH_PROPERTY_KEY); assertNotFound(reports); } @Test public void getReports_shouldFindSomethingBaseDir1() { settings.setProperty(REPORT_PATH_PROPERTY_KEY, VALID_REPORT_PATH); - List reports = sensor.getReports(settings, baseDir.getPath(), "", - REPORT_PATH_PROPERTY_KEY); - assertFound(reports); - } - - @Test - public void getReports_shouldFindSomethingBaseDir2() { - settings.setProperty(REPORT_PATH_PROPERTY_KEY, VALID_REPORT_PATH); - List reports = sensor.getReports(settings, baseDir.getPath()+"Invalid", baseDir.getPath(), - REPORT_PATH_PROPERTY_KEY); + List reports = sensor.getReports(settings, baseDir, REPORT_PATH_PROPERTY_KEY); assertFound(reports); } diff --git a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/utils/CxxReportSensor_getReports_Test.java b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/utils/CxxReportSensor_getReports_Test.java index 724e0f246a..1395c4bc8a 100644 --- a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/utils/CxxReportSensor_getReports_Test.java +++ b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/utils/CxxReportSensor_getReports_Test.java @@ -42,7 +42,7 @@ public class CxxReportSensor_getReports_Test { private class CxxReportSensorImpl extends CxxReportSensor { public CxxReportSensorImpl(Settings settings, FileSystem fs) { - super(settings, fs, TestUtils.mockReactor()); + super(settings, fs); } }; @@ -88,7 +88,7 @@ public void getReports_patternMatching() throws java.io.IOException, java.lang.I setupExample(allpaths); settings.setProperty(property, pattern); - reports = sensor.getReports(settings, base.getRoot().getPath(), "", property); + reports = sensor.getReports(settings, base.getRoot(), property); assertMatch(reports, match, example[0]); deleteExample(base.getRoot()); diff --git a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/valgrind/CxxValgrindSensorTest.java b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/valgrind/CxxValgrindSensorTest.java index 003520f291..3a349d0c92 100644 --- a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/valgrind/CxxValgrindSensorTest.java +++ b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/valgrind/CxxValgrindSensorTest.java @@ -55,7 +55,7 @@ public void setUp() { project = TestUtils.mockProject(); issuable = TestUtils.mockIssuable(); perspectives = TestUtils.mockPerspectives(issuable); - sensor = new CxxValgrindSensor(perspectives, new Settings(), fs, mock(RulesProfile.class), TestUtils.mockReactor()); + sensor = new CxxValgrindSensor(perspectives, new Settings(), fs, mock(RulesProfile.class)); context = mock(SensorContext.class); } diff --git a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/veraxx/CxxVeraxxSensorTest.java b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/veraxx/CxxVeraxxSensorTest.java index 19a606a81b..f4e2c69dfd 100644 --- a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/veraxx/CxxVeraxxSensorTest.java +++ b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/veraxx/CxxVeraxxSensorTest.java @@ -53,7 +53,7 @@ public void setUp() { perspectives = TestUtils.mockPerspectives(issuable); Settings settings = new Settings(); settings.setProperty(CxxVeraxxSensor.REPORT_PATH_KEY, "vera++-reports/vera++-result-*.xml"); - sensor = new CxxVeraxxSensor(perspectives, settings, fs, mock(RulesProfile.class), TestUtils.mockReactor()); + sensor = new CxxVeraxxSensor(perspectives, settings, fs, mock(RulesProfile.class)); context = mock(SensorContext.class); } diff --git a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/xunit/CxxXunitSensorTest.java b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/xunit/CxxXunitSensorTest.java index 69b97ba3b4..1f148c3efe 100644 --- a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/xunit/CxxXunitSensorTest.java +++ b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/xunit/CxxXunitSensorTest.java @@ -40,7 +40,6 @@ import org.sonar.api.measures.CoreMetrics; import org.sonar.api.resources.Project; import org.sonar.plugins.cxx.TestUtils; -import org.sonar.api.batch.bootstrap.ProjectReactor; public class CxxXunitSensorTest { private CxxXunitSensor sensor; @@ -48,16 +47,14 @@ public class CxxXunitSensorTest { private Project project; private FileSystem fs; private Settings settings; - private ProjectReactor reactor; @Before public void setUp() { project = TestUtils.mockProject(); fs = TestUtils.mockFileSystem(); settings = new Settings(); - reactor = TestUtils.mockReactor(); context = mock(SensorContext.class); - sensor = new CxxXunitSensor(settings, fs, reactor); + sensor = new CxxXunitSensor(settings, fs); } @Test @@ -69,7 +66,7 @@ public void shouldFindTheSourcesOfTheTestfiles() { fs = TestUtils.mockFileSystem(baseDir, Arrays.asList(new File("src")), Arrays.asList(new File("tests1"), new File("tests2"))); - sensor = new CxxXunitSensor(settings, fs, reactor); + sensor = new CxxXunitSensor(settings, fs); sensor.buildLookupTables(); // case 1: @@ -128,7 +125,7 @@ public void shouldFindTheSourcesOfTheTestfiles() { public void shouldReportNothingWhenNoReportFound() { Settings settings = new Settings(); settings.setProperty(CxxXunitSensor.REPORT_PATH_KEY, "notexistingpath"); - sensor = new CxxXunitSensor(settings, fs, TestUtils.mockReactor()); + sensor = new CxxXunitSensor(settings, fs); sensor.analyse(project, context); @@ -139,7 +136,7 @@ public void shouldReportNothingWhenNoReportFound() { public void shouldThrowWhenGivenInvalidTime() { Settings settings = new Settings(); settings.setProperty(CxxXunitSensor.REPORT_PATH_KEY, "xunit-reports/invalid-time-xunit-report.xml"); - sensor = new CxxXunitSensor(settings, fs, reactor); + sensor = new CxxXunitSensor(settings, fs); sensor.analyse(project, context); } @@ -151,7 +148,7 @@ public void transformReport_shouldThrowWhenGivenNotExistingStyleSheet() Settings settings = new Settings(); settings.setProperty(CxxXunitSensor.XSLT_URL_KEY, "whatever"); - sensor = new CxxXunitSensor(settings, fs, reactor); + sensor = new CxxXunitSensor(settings, fs); sensor.transformReport(cppunitReport()); } @@ -163,7 +160,7 @@ public void transformReport_shouldTransformCppunitReport() Settings settings = new Settings(); settings.setProperty(CxxXunitSensor.XSLT_URL_KEY, "cppunit-1.x-to-junit-1.0.xsl"); - sensor = new CxxXunitSensor(settings, fs, reactor); + sensor = new CxxXunitSensor(settings, fs); File reportBefore = cppunitReport(); File reportAfter = sensor.transformReport(reportBefore);