Sonar 质量扫描的输出日志--对应源码的跟踪(二){sonar engine源码}
生活随笔
收集整理的這篇文章主要介紹了
Sonar 质量扫描的输出日志--对应源码的跟踪(二){sonar engine源码}
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
一個(gè)project下面module完整的sonar分析日志:
[INFO] --- sonar-maven-plugin:3.2:sonar (default-cli) @ pcaic-parent --- [INFO] User cache: /root/.sonar/cache 5.475: [GC (Metadata GC Threshold) [PSYoungGen: 124155K->16378K(212992K)] 125048K->20534K(337920K), 0.0249154 secs] [Times: user=0.08 sys=0.00, real=0.03 secs] 5.500: [Full GC (Metadata GC Threshold) [PSYoungGen: 16378K->0K(212992K)] [ParOldGen: 4156K->19951K(172032K)] 20534K->19951K(385024K), [Metaspace: 20709K->20709K(1069056K)], 0.1078064 secs] [Times: user=0.46 sys=0.01, real=0.11 secs] [INFO] Load global repositories [INFO] Load global repositories (done) | time=143ms [WARNING] Property 'sonar.jdbc.url' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database. [WARNING] Property 'sonar.jdbc.username' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database. [WARNING] Property 'sonar.jdbc.password' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database. [INFO] User cache: /root/.sonar/cache [INFO] Load plugins index [INFO] Load plugins index (done) | time=2ms [INFO] Plugin [l10nzh] defines 'l10nen' as base plugin. This metadata can be removed from manifest of l10n plugins since version 5.2. [INFO] SonarQube version: 6.2 7.243: [GC (Allocation Failure) [PSYoungGen: 196608K->21479K(318976K)] 216559K->73599K(491008K), 0.0467409 secs] [Times: user=0.14 sys=0.04, real=0.05 secs] [WARNING] Missing POM for com.suning.framework:snf-zk-client:jar:1.1.1 [WARNING] Missing POM for com.suning.framework:snf-zk-client:jar:1.1.1 8.358: [GC (Allocation Failure) [PSYoungGen: 318951K->25791K(394240K)] 371071K->77919K(566272K), 0.0259672 secs] [Times: user=0.11 sys=0.02, real=0.02 secs] [INFO] artifact org.jxls:jxls: checking for updates from suning_maven_repo [INFO] artifact org.webjars.bower:jquery: checking for updates from suning_maven_repo [INFO] artifact org.webjars.bower:angular: checking for updates from suning_maven_repo [INFO] artifact org.webjars.bower:angular: checking for updates from suning_maven_repo [INFO] artifact org.webjars.bower:eonasdan-bootstrap-datetimepicker: checking for updates from suning_maven_repo [INFO] artifact org.webjars.bower:moment: checking for updates from suning_maven_repo [INFO] artifact org.webjars.bower:moment: checking for updates from suning_maven_repo [INFO] artifact org.webjars.bower:bootstrap: checking for updates from suning_maven_repo [INFO] artifact org.webjars.bower:jquery: checking for updates from suning_maven_repo [INFO] artifact org.webjars.bower:bootstrap: checking for updates from suning_maven_repo [INFO] artifact org.webjars.bower:jquery: checking for updates from suning_maven_repo [INFO] artifact org.webjars.bower:angular: checking for updates from suning_maven_repo [INFO] artifact org.webjars.bower:codemirror: checking for updates from suning_maven_repo [INFO] artifact org.webjars.bower:angular: checking for updates from suning_maven_repo [INFO] artifact org.webjars.bower:angular: checking for updates from suning_maven_repo [INFO] artifact org.webjars.bower:angular: checking for updates from suning_maven_repo [INFO] artifact org.webjars.bower:js-xlsx: checking for updates from suning_maven_repo 10.054: [GC (Allocation Failure) [PSYoungGen: 378047K->29227K(494080K)] 430175K->81362K(666112K), 0.0336199 secs] [Times: user=0.21 sys=0.02, real=0.04 secs] [INFO] Default locale: "zh_CN", source code encoding: "UTF-8" [INFO] Process project properties [INFO] Load project repositories [INFO] Load project repositories (done) | time=305ms 11.048: [GC (Metadata GC Threshold) [PSYoungGen: 125853K->36969K(494592K)] 177989K->89113K(666624K), 0.0228080 secs] [Times: user=0.09 sys=0.02, real=0.02 secs] 11.071: [Full GC (Metadata GC Threshold) [PSYoungGen: 36969K->0K(494592K)] [ParOldGen: 52143K->75639K(318976K)] 89113K->75639K(813568K), [Metaspace: 34292K->34292K(1081344K)], 0.1395758 secs] [Times: user=0.60 sys=0.03, real=0.14 secs] [INFO] Load quality profiles [INFO] Load quality profiles (done) | time=22ms [INFO] Load active rules [INFO] Load active rules (done) | time=647ms [INFO] Publish mode [INFO] ------------- Scan suning's pcids caic common 20180509 [INFO] Language is forced to java [INFO] Load server rules [INFO] Load server rules (done) | time=142ms [INFO] Initializer GenericCoverageSensor [INFO] Initializer GenericCoverageSensor (done) | time=1ms [INFO] Base dir: /data/jenkinsslave/workspace/pcids_caic20180509/pcaic-common [INFO] Working dir: /data/jenkinsslave/workspace/pcids_caic20180509/pcaic-common/target/sonar [INFO] Source paths: pom.xml, src/main/java [INFO] Source encoding: UTF-8, default locale: zh_CN [INFO] Index files [INFO] 47 files indexed [INFO] Quality profile for java: Sonarway54 [INFO] Sensor Lines Sensor [INFO] Sensor Lines Sensor (done) | time=17ms [INFO] Sensor JavaSquidSensor [INFO] Configured Java source version (sonar.java.source): 8 [INFO] JavaClasspath initialization [INFO] JavaClasspath initialization (done) | time=13ms [INFO] JavaTestClasspath initialization [INFO] JavaTestClasspath initialization (done) | time=3ms [INFO] Java Main Files AST scan [INFO] 47 source files to be analyzed [WARNING] Metric 'lines' is an internal metric computed by SonarQube. Provided value is ignored. 16.331: [GC (Allocation Failure) [PSYoungGen: 452608K->28914K(606208K)] 528247K->104581K(925184K), 0.0573675 secs] [Times: user=0.20 sys=0.02, real=0.06 secs] [INFO] [INFO] 47/47 source files have been analyzed Java Main Files AST scan (done) | time=3857ms [INFO] Java Test Files AST scan [INFO] 0 source files to be analyzed [INFO] Java Test Files AST scan (done) | time=0ms [INFO] Sensor JavaSquidSensor (done) | time=4341ms [INFO] [INFO] Sensor SCM Sensor 0/0 source files have been analyzed [INFO] Sensor SCM Sensor (done) | time=9ms [INFO] Sensor Coverage Report Import [INFO] Sensor Coverage Report Import (done) | time=0ms [INFO] Sensor Coverage Report Import [INFO] Sensor Coverage Report Import (done) | time=0ms [INFO] Sensor Unit Test Results Import [INFO] Sensor Unit Test Results Import (done) | time=0ms [INFO] Sensor FindBugs Sensor 18.146: [GC (Metadata GC Threshold) [PSYoungGen: 298260K->13640K(625152K)] 373927K->89315K(944128K), 0.0345552 secs] [Times: user=0.14 sys=0.01, real=0.04 secs] 18.181: [Full GC (Metadata GC Threshold) [PSYoungGen: 13640K->0K(625152K)] [ParOldGen: 75674K->81834K(407040K)] 89315K->81834K(1032192K), [Metaspace: 57175K->57175K(1099776K)], 0.3274191 secs] [Times: user=1.63 sys=0.02, real=0.33 secs] [INFO] Findbugs output report: /data/jenkinsslave/workspace/pcids_caic20180509/pcaic-common/target/sonar/findbugs-result.xml 23.374: [GC (Allocation Failure) [PSYoungGen: 580096K->34117K(734208K)] 661930K->115976K(1141248K), 0.0345130 secs] [Times: user=0.14 sys=0.01, real=0.04 secs] [INFO] Sensor FindBugs Sensor (done) | time=6416ms [INFO] Sensor SurefireSensor [INFO] parsing /data/jenkinsslave/workspace/pcids_caic20180509/pcaic-common/target/surefire-reports [INFO] Sensor SurefireSensor (done) | time=1ms [INFO] Sensor JaCoCoSensor [INFO] JaCoCoSensor: JaCoCo report not found : /data/jenkinsslave/workspace/pcids_caic20180509/pcaic-common/target/jacoco.exec [INFO] Sensor JaCoCoSensor (done) | time=0ms [INFO] Sensor JaCoCoItSensor [INFO] JaCoCoItSensor: JaCoCo IT report not found: /data/jenkinsslave/workspace/pcids_caic20180509/pcaic-common/target/jacoco-it.exec [INFO] Sensor JaCoCoItSensor (done) | time=0ms [INFO] Sensor JaCoCoOverallSensor [INFO] Sensor JaCoCoOverallSensor (done) | time=1ms [INFO] Sensor XmlFileSensor [INFO] Sensor XmlFileSensor (done) | time=0ms [INFO] Sensor Zero Coverage Sensor [INFO] Sensor Zero Coverage Sensor (done) | time=38ms [INFO] Sensor Code Colorizer Sensor [INFO] Sensor Code Colorizer Sensor (done) | time=2ms [INFO] Sensor CPD Block Indexer [INFO] JavaCpdBlockIndexer is used for java [INFO] Sensor CPD Block Indexer (done) | time=68msload global?repositories-> load plugin index -> load/process?project properties ->?Load project repositories
->?Load quality profiles ->?Load active rules ->?Language is forced to java ->Load server rules ->
Initializer GenericCoverageSensor
先看 sonar-scanner-protocol
GlobalRepositories bean:
ProjectRepositories bean 類:
sonar scanner 掃描文件讀取類ScannerReportReader
public class ScannerReportReader {private final FileStructure fileStructure;public ScannerReportReader(File dir) {this.fileStructure = new FileStructure(dir);}public ScannerReport.Metadata readMetadata() {File file = fileStructure.metadataFile();if (!fileExists(file)) {throw new IllegalStateException("Metadata file is missing in analysis report: " + file);}return Protobuf.read(file, ScannerReport.Metadata.parser());}public CloseableIterator<ScannerReport.ActiveRule> readActiveRules() {File file = fileStructure.activeRules();if (!fileExists(file)) {return emptyCloseableIterator();}return Protobuf.readStream(file, ScannerReport.ActiveRule.parser());}public CloseableIterator<ScannerReport.Measure> readComponentMeasures(int componentRef) {File file = fileStructure.fileFor(FileStructure.Domain.MEASURES, componentRef);if (fileExists(file)) {return Protobuf.readStream(file, ScannerReport.Measure.parser());}return emptyCloseableIterator();}@CheckForNullpublic ScannerReport.Changesets readChangesets(int componentRef) {File file = fileStructure.fileFor(FileStructure.Domain.CHANGESETS, componentRef);if (fileExists(file)) {return Protobuf.read(file, ScannerReport.Changesets.parser());}return null;}public ScannerReport.Component readComponent(int componentRef) {File file = fileStructure.fileFor(FileStructure.Domain.COMPONENT, componentRef);if (!fileExists(file)) {throw new IllegalStateException("Unable to find report for component #" + componentRef + ". File does not exist: " + file);}return Protobuf.read(file, ScannerReport.Component.parser());}public CloseableIterator<ScannerReport.Issue> readComponentIssues(int componentRef) {File file = fileStructure.fileFor(FileStructure.Domain.ISSUES, componentRef);if (fileExists(file)) {return Protobuf.readStream(file, ScannerReport.Issue.parser());}return emptyCloseableIterator();}public CloseableIterator<ScannerReport.Duplication> readComponentDuplications(int componentRef) {File file = fileStructure.fileFor(FileStructure.Domain.DUPLICATIONS, componentRef);if (fileExists(file)) {return Protobuf.readStream(file, ScannerReport.Duplication.parser());}return emptyCloseableIterator();}public CloseableIterator<ScannerReport.CpdTextBlock> readCpdTextBlocks(int componentRef) {File file = fileStructure.fileFor(FileStructure.Domain.CPD_TEXT_BLOCKS, componentRef);if (fileExists(file)) {return Protobuf.readStream(file, ScannerReport.CpdTextBlock.parser());}return emptyCloseableIterator();}public CloseableIterator<ScannerReport.Symbol> readComponentSymbols(int componentRef) {File file = fileStructure.fileFor(FileStructure.Domain.SYMBOLS, componentRef);if (fileExists(file)) {return Protobuf.readStream(file, ScannerReport.Symbol.parser());}return emptyCloseableIterator();}public boolean hasSyntaxHighlighting(int componentRef) {File file = fileStructure.fileFor(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, componentRef);return file.exists();}public CloseableIterator<ScannerReport.SyntaxHighlightingRule> readComponentSyntaxHighlighting(int fileRef) {File file = fileStructure.fileFor(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, fileRef);if (fileExists(file)) {return Protobuf.readStream(file, ScannerReport.SyntaxHighlightingRule.parser());}return emptyCloseableIterator();}public boolean hasCoverage(int componentRef) {File file = fileStructure.fileFor(FileStructure.Domain.COVERAGES, componentRef);return file.exists();}public CloseableIterator<ScannerReport.LineCoverage> readComponentCoverage(int fileRef) {File file = fileStructure.fileFor(FileStructure.Domain.COVERAGES, fileRef);if (fileExists(file)) {return Protobuf.readStream(file, ScannerReport.LineCoverage.parser());}return emptyCloseableIterator();}@CheckForNullpublic File readFileSource(int fileRef) {File file = fileStructure.fileFor(FileStructure.Domain.SOURCE, fileRef);if (fileExists(file)) {return file;}return null;}@CheckForNullpublic File readTests(int testFileRef) {File file = fileStructure.fileFor(FileStructure.Domain.TESTS, testFileRef);if (fileExists(file)) {return file;}return null;}@CheckForNullpublic File readCoverageDetails(int testFileRef) {File file = fileStructure.fileFor(FileStructure.Domain.COVERAGE_DETAILS, testFileRef);if (fileExists(file)) {return file;}return null;}public CloseableIterator<ScannerReport.ContextProperty> readContextProperties() {File file = fileStructure.contextProperties();if (!fileExists(file)) {return emptyCloseableIterator();}return Protobuf.readStream(file, ScannerReport.ContextProperty.parser());}private static boolean fileExists(File file) {return file.exists() && file.isFile();}public FileStructure getFileStructure() {return fileStructure;} }sonar 掃描生成的數(shù)據(jù)文件 寫類?ScannerReportWriterpublic class ScannerReportWriter {private final FileStructure fileStructure;public ScannerReportWriter(File dir) {if (!dir.exists() && !dir.mkdirs()) {throw new IllegalStateException("Unable to create directory: " + dir);}this.fileStructure = new FileStructure(dir);}public FileStructure getFileStructure() {return fileStructure;}public boolean hasComponentData(FileStructure.Domain domain, int componentRef) {File file = fileStructure.fileFor(domain, componentRef);return file.exists() && file.isFile();}/*** Metadata is mandatory*/public File writeMetadata(ScannerReport.Metadata metadata) {Protobuf.write(metadata, fileStructure.metadataFile());return fileStructure.metadataFile();}public File writeActiveRules(Iterable<ScannerReport.ActiveRule> activeRules) {Protobuf.writeStream(activeRules, fileStructure.activeRules(), false);return fileStructure.metadataFile();}public File writeComponent(ScannerReport.Component component) {File file = fileStructure.fileFor(FileStructure.Domain.COMPONENT, component.getRef());Protobuf.write(component, file);return file;}public File writeComponentIssues(int componentRef, Iterable<ScannerReport.Issue> issues) {File file = fileStructure.fileFor(FileStructure.Domain.ISSUES, componentRef);Protobuf.writeStream(issues, file, false);return file;}public void appendComponentIssue(int componentRef, ScannerReport.Issue issue) {File file = fileStructure.fileFor(FileStructure.Domain.ISSUES, componentRef);try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file, true))) {issue.writeDelimitedTo(out);} catch (Exception e) {throw ContextException.of("Unable to write issue", e).addContext("file", file);}}public File writeComponentMeasures(int componentRef, Iterable<ScannerReport.Measure> measures) {File file = fileStructure.fileFor(FileStructure.Domain.MEASURES, componentRef);Protobuf.writeStream(measures, file, false);return file;}public File writeComponentChangesets(ScannerReport.Changesets changesets) {File file = fileStructure.fileFor(FileStructure.Domain.CHANGESETS, changesets.getComponentRef());Protobuf.write(changesets, file);return file;}public File writeComponentDuplications(int componentRef, Iterable<ScannerReport.Duplication> duplications) {File file = fileStructure.fileFor(FileStructure.Domain.DUPLICATIONS, componentRef);Protobuf.writeStream(duplications, file, false);return file;}public File writeCpdTextBlocks(int componentRef, Iterable<ScannerReport.CpdTextBlock> blocks) {File file = fileStructure.fileFor(FileStructure.Domain.CPD_TEXT_BLOCKS, componentRef);Protobuf.writeStream(blocks, file, false);return file;}public File writeComponentSymbols(int componentRef, Iterable<ScannerReport.Symbol> symbols) {File file = fileStructure.fileFor(FileStructure.Domain.SYMBOLS, componentRef);Protobuf.writeStream(symbols, file, false);return file;}public File writeComponentSyntaxHighlighting(int componentRef, Iterable<ScannerReport.SyntaxHighlightingRule> syntaxHighlightingRules) {File file = fileStructure.fileFor(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, componentRef);Protobuf.writeStream(syntaxHighlightingRules, file, false);return file;}public File writeComponentCoverage(int componentRef, Iterable<ScannerReport.LineCoverage> coverageList) {File file = fileStructure.fileFor(FileStructure.Domain.COVERAGES, componentRef);Protobuf.writeStream(coverageList, file, false);return file;}public File writeTests(int componentRef, Iterable<ScannerReport.Test> tests) {File file = fileStructure.fileFor(FileStructure.Domain.TESTS, componentRef);Protobuf.writeStream(tests, file, false);return file;}public File writeCoverageDetails(int componentRef, Iterable<ScannerReport.CoverageDetail> tests) {File file = fileStructure.fileFor(FileStructure.Domain.COVERAGE_DETAILS, componentRef);Protobuf.writeStream(tests, file, false);return file;}public File writeContextProperties(Iterable<ScannerReport.ContextProperty> properties) {File file = fileStructure.contextProperties();Protobuf.writeStream(properties, file, false);return file;}public File getSourceFile(int componentRef) {return fileStructure.fileFor(FileStructure.Domain.SOURCE, componentRef);}}
InitializersExecutor類:
GenericCoverageSensor類:
package org.sonar.scanner.genericcoverage;import com.google.common.collect.ImmutableList; import java.io.File; import java.util.Arrays; import java.util.LinkedHashSet; import java.util.Set; import java.util.stream.Collectors; import org.sonar.api.batch.Initializer; import org.sonar.api.batch.sensor.Sensor; import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.SensorDescriptor; import org.sonar.api.config.PropertyDefinition; import org.sonar.api.config.Settings; import org.sonar.api.resources.Qualifiers; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers;import static org.sonar.api.CoreProperties.CATEGORY_CODE_COVERAGE;public class GenericCoverageSensor extends Initializer implements Sensor {private static final Logger LOG = Loggers.get(GenericCoverageSensor.class);static final String REPORT_PATHS_PROPERTY_KEY = "sonar.coverageReportPaths";/*** @deprecated since 6.2*/@Deprecatedstatic final String OLD_REPORT_PATH_PROPERTY_KEY = "sonar.genericcoverage.reportPath";/*** @deprecated since 6.2*/@Deprecatedstatic final String OLD_COVERAGE_REPORT_PATHS_PROPERTY_KEY = "sonar.genericcoverage.reportPaths";/*** @deprecated since 6.2*/@Deprecatedstatic final String OLD_IT_COVERAGE_REPORT_PATHS_PROPERTY_KEY = "sonar.genericcoverage.itReportPaths";/*** @deprecated since 6.2*/@Deprecatedstatic final String OLD_OVERALL_COVERAGE_REPORT_PATHS_PROPERTY_KEY = "sonar.genericcoverage.overallReportPaths";private final Settings settings;public GenericCoverageSensor(Settings settings) {this.settings = settings;}public static ImmutableList<PropertyDefinition> properties() {return ImmutableList.of(PropertyDefinition.builder(REPORT_PATHS_PROPERTY_KEY).name("Coverage report paths").description("List of comma-separated paths (absolute or relative) containing coverage report.").category(CATEGORY_CODE_COVERAGE).onQualifiers(Qualifiers.PROJECT).deprecatedKey(OLD_COVERAGE_REPORT_PATHS_PROPERTY_KEY).build());}/*** Use an initializer to migrate old properties to the new one before Sensor phase so that* Sensor will not be executed if there is no report (thanks to SensorDescriptor.requireProperty(REPORT_PATH_PROPERTY_KEY))*/@Overridepublic void execute() {Set<String> reportPaths = new LinkedHashSet<>();reportPaths.addAll(Arrays.asList(settings.getStringArray(REPORT_PATHS_PROPERTY_KEY)));loadDeprecated(reportPaths, OLD_REPORT_PATH_PROPERTY_KEY);loadDeprecated(reportPaths, OLD_COVERAGE_REPORT_PATHS_PROPERTY_KEY);loadDeprecated(reportPaths, OLD_IT_COVERAGE_REPORT_PATHS_PROPERTY_KEY);loadDeprecated(reportPaths, OLD_OVERALL_COVERAGE_REPORT_PATHS_PROPERTY_KEY);if (!reportPaths.isEmpty()) {settings.setProperty(REPORT_PATHS_PROPERTY_KEY, reportPaths.stream().collect(Collectors.joining(",")));}}private void loadDeprecated(Set<String> reportPaths, String propertyKey) {if (settings.hasKey(propertyKey)) {LOG.warn("Property '{}' is deprecated. Please use '{}' instead.", propertyKey, REPORT_PATHS_PROPERTY_KEY);reportPaths.addAll(Arrays.asList(settings.getStringArray(propertyKey)));}}@Overridepublic void describe(SensorDescriptor descriptor) {descriptor.name("Generic Coverage Report").requireProperty(REPORT_PATHS_PROPERTY_KEY);}@Overridepublic void execute(SensorContext context) {for (String reportPath : settings.getStringArray(REPORT_PATHS_PROPERTY_KEY)) {File reportFile = context.fileSystem().resolvePath(reportPath);LOG.info("Parsing {}", reportFile);GenericCoverageReportParser parser = new GenericCoverageReportParser();parser.parse(reportFile, context);LOG.info("Imported coverage data for {} files", parser.numberOfMatchedFiles());int numberOfUnknownFiles = parser.numberOfUnknownFiles();if (numberOfUnknownFiles > 0) {LOG.info("Coverage data ignored for " + numberOfUnknownFiles + " unknown files, including:\n" + parser.firstUnknownFiles().stream().collect(Collectors.joining("\n")));}}}}總結(jié)
以上是生活随笔為你收集整理的Sonar 质量扫描的输出日志--对应源码的跟踪(二){sonar engine源码}的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 马斯克称特斯拉有世界上最安全的车,受伤比
- 下一篇: 早报:虎牙公布一季度财报 腾讯音乐Q1营