diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2018-11-26 11:53:51 -0600 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2019-01-16 09:43:02 +0100 |
commit | 056023aba07e95f5e9bb1d5d2c4e611955458986 (patch) | |
tree | bfc5466d4328502b01c20d87759132057e709320 /sonar-scanner-engine/src/main/java/org/sonar/scanner/report | |
parent | f686185f25130fe4d84ae3b9307b784895414d5a (diff) | |
download | sonarqube-056023aba07e95f5e9bb1d5d2c4e611955458986.tar.gz sonarqube-056023aba07e95f5e9bb1d5d2c4e611955458986.zip |
SONAR-11463 Remove path from scanner report and add module directories
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org/sonar/scanner/report')
-rw-r--r-- | sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java index 26ca46ace2c..2b36b3b5d28 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java @@ -21,11 +21,13 @@ package org.sonar.scanner.report; import java.io.File; import java.nio.file.Path; +import java.util.LinkedList; import java.util.Map.Entry; import java.util.Optional; import java.util.regex.Pattern; import javax.annotation.Nullable; import org.sonar.api.batch.fs.internal.AbstractProjectOrModule; +import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.InputModuleHierarchy; import org.sonar.api.batch.scm.ScmProvider; import org.sonar.api.utils.log.Logger; @@ -59,8 +61,8 @@ public class MetadataPublisher implements ReportPublisherStep { private final ScmConfiguration scmConfiguration; public MetadataPublisher(ProjectAnalysisInfo projectAnalysisInfo, InputModuleHierarchy moduleHierarchy, ScanProperties properties, - QualityProfiles qProfiles, CpdSettings cpdSettings, ScannerPluginRepository pluginRepository, BranchConfiguration branchConfiguration, - @Nullable ScmConfiguration scmConfiguration) { + QualityProfiles qProfiles, CpdSettings cpdSettings, ScannerPluginRepository pluginRepository, BranchConfiguration branchConfiguration, + @Nullable ScmConfiguration scmConfiguration) { this.projectAnalysisInfo = projectAnalysisInfo; this.moduleHierarchy = moduleHierarchy; this.properties = properties; @@ -72,7 +74,7 @@ public class MetadataPublisher implements ReportPublisherStep { } public MetadataPublisher(ProjectAnalysisInfo projectAnalysisInfo, InputModuleHierarchy moduleHierarchy, ScanProperties properties, - QualityProfiles qProfiles, CpdSettings cpdSettings, ScannerPluginRepository pluginRepository, BranchConfiguration branchConfiguration) { + QualityProfiles qProfiles, CpdSettings cpdSettings, ScannerPluginRepository pluginRepository, BranchConfiguration branchConfiguration) { this(projectAnalysisInfo, moduleHierarchy, properties, qProfiles, cpdSettings, pluginRepository, branchConfiguration, null); } @@ -99,20 +101,37 @@ public class MetadataPublisher implements ReportPublisherStep { } for (QProfile qp : qProfiles.findAll()) { - builder.getMutableQprofilesPerLanguage().put(qp.getLanguage(), ScannerReport.Metadata.QProfile.newBuilder() + builder.putQprofilesPerLanguage(qp.getLanguage(), ScannerReport.Metadata.QProfile.newBuilder() .setKey(qp.getKey()) .setLanguage(qp.getLanguage()) .setName(qp.getName()) .setRulesUpdatedAt(qp.getRulesUpdatedAt().getTime()).build()); } for (Entry<String, ScannerPlugin> pluginEntry : pluginRepository.getPluginsByKey().entrySet()) { - builder.getMutablePluginsByKey().put(pluginEntry.getKey(), ScannerReport.Metadata.Plugin.newBuilder() + builder.putPluginsByKey(pluginEntry.getKey(), ScannerReport.Metadata.Plugin.newBuilder() .setKey(pluginEntry.getKey()) .setUpdatedAt(pluginEntry.getValue().getUpdatedAt()).build()); } + + addModulesRelativePaths(builder); + writer.writeMetadata(builder.build()); } + private void addModulesRelativePaths(ScannerReport.Metadata.Builder builder) { + LinkedList<DefaultInputModule> queue = new LinkedList<>(); + queue.add(moduleHierarchy.root()); + + while (!queue.isEmpty()) { + DefaultInputModule module = queue.removeFirst(); + queue.addAll(moduleHierarchy.children(module)); + String relativePath = moduleHierarchy.relativePath(module); + if (relativePath != null) { + builder.putModulesProjectRelativePathByKey(module.key(), relativePath); + } + } + } + private void addScmInformation(ScannerReport.Metadata.Builder builder) { ScmProvider scmProvider = scmConfiguration.provider(); if (scmProvider != null) { |