Skip to content

Commit

Permalink
in multi module, run only at root level so that we dont duplicate data
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Costa committed Jan 6, 2015
1 parent 32eca48 commit c5125d6
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ public CxxCoverageSensor(Settings settings, ModuleFileSystem fs, ProjectReactor
*/
@Override
public void analyse(Project project, SensorContext context) {

if(!CxxUtils.isRoot(project)) {
return;
}

CxxUtils.LOG.debug("Parsing coverage reports");
List<File> reports = getReports(conf, reactor.getRoot().getBaseDir().getAbsolutePath(), REPORT_PATH_KEY, DEFAULT_REPORT_PATH);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,40 +98,42 @@ public boolean shouldExecuteOnProject(Project project) {
* {@inheritDoc}
*/
public void analyse(Project project, SensorContext context) {
if (!CxxUtils.isReactorProject(project)) {
try {
if (!CxxUtils.isRoot(project)) {
return;
}

try {
List<File> reports = getReports(conf, reactor.getRoot().getBaseDir().getCanonicalPath(),
reportPathKey(), defaultReportPath());
if (reports.isEmpty()) {
reports = getReports(conf, fs.baseDir().getPath(), reportPathKey(), defaultReportPath());
}
violationsCount = 0;
reportPathKey(), defaultReportPath());
if (reports.isEmpty()) {
reports = getReports(conf, fs.baseDir().getPath(), reportPathKey(), defaultReportPath());
}
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 SonarException(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 SonarException(msg, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public static String normalizePathFull(String filename, String baseDir) {
return filePath;
}

public static boolean isReactorProject(Project project) {
return project.isRoot() && !project.getModules().isEmpty();
public static boolean isRoot(Project project) {
return project.isRoot();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ public Class<?> dependsUponCoverageSensors() {
*/
@Override
public void analyse(Project project, SensorContext context) {
if(!CxxUtils.isRoot(project)) {
return;
}

try{
List<File> reports = getReports(conf, fs.baseDir().getPath(),
REPORT_PATH_KEY, DEFAULT_REPORT_PATH);
Expand Down Expand Up @@ -144,7 +148,7 @@ public void analyse(Project project, SensorContext context) {
.append("'")
.toString();
throw new SonarException(msg, e);
}
}
}

private void simpleMode(final Project project, final SensorContext context, List<TestCase> testcases)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public static Project mockProject(File baseDir, List<File> sourceDirs, List<File
when(fileSystem.getTestDirs()).thenReturn(testDirs);

Project project = mock(Project.class);
when(project.isRoot()).thenReturn(true);
when(project.getFileSystem()).thenReturn(fileSystem);
CxxLanguage lang = mockCxxLanguage();
when(project.getLanguage()).thenReturn(lang);
Expand Down

0 comments on commit c5125d6

Please sign in to comment.