我正在尝试创建自定义XML规则,但它们无法正常工作。 :(
首先我的配置:
我想在xpath中为XML Quality Profile创建自定义规则。 永远不会应用该规则,也不会检测到违规行为。
我的规则:
//ELEMENT/S_TAG/NAME[@tokenValue='root']
我的XML文件:
<?xml version="1.0" encoding="UTF-8" ?>
<root>
</root>
AST树:
<DOCUMENT tokenValue="<?xml" tokenLine="1" tokenColumn="0">
<PROLOG tokenValue="<?xml" tokenLine="1" tokenColumn="0">
<XML_DECL tokenValue="<?xml" tokenLine="1" tokenColumn="0">
<TOKEN tokenValue="<?xml" tokenLine="1" tokenColumn="0"/>
<VERSION_INFO tokenValue="version" tokenLine="1" tokenColumn="6">
<TOKEN tokenValue="version" tokenLine="1" tokenColumn="6"/>
<EQ tokenValue="=" tokenLine="1" tokenColumn="13">
<TOKEN tokenValue="=" tokenLine="1" tokenColumn="13"/>
</EQ>
<TOKEN tokenValue=""" tokenLine="1" tokenColumn="14"/>
<VERSION_NUM tokenValue="1." tokenLine="1" tokenColumn="15">
<TOKEN tokenValue="1." tokenLine="1" tokenColumn="15"/>
<TOKEN tokenValue="0" tokenLine="1" tokenColumn="17"/>
</VERSION_NUM>
<TOKEN tokenValue=""" tokenLine="1" tokenColumn="18"/>
</VERSION_INFO>
<ENCODING_DECL tokenValue="encoding" tokenLine="1" tokenColumn="20">
<TOKEN tokenValue="encoding" tokenLine="1" tokenColumn="20"/>
<EQ tokenValue="=" tokenLine="1" tokenColumn="28">
<TOKEN tokenValue="=" tokenLine="1" tokenColumn="28"/>
</EQ>
<TOKEN tokenValue=""" tokenLine="1" tokenColumn="29"/>
<ENC_NAME tokenValue="UTF-8" tokenLine="1" tokenColumn="30">
<TOKEN tokenValue="UTF-8" tokenLine="1" tokenColumn="30"/>
</ENC_NAME>
<TOKEN tokenValue=""" tokenLine="1" tokenColumn="35"/>
</ENCODING_DECL>
<TOKEN tokenValue="?>" tokenLine="1" tokenColumn="38"/>
</XML_DECL>
<MISC/>
</PROLOG>
<ELEMENT tokenValue="<" tokenLine="3" tokenColumn="0">
<S_TAG tokenValue="<" tokenLine="3" tokenColumn="0">
<TOKEN tokenValue="<" tokenLine="3" tokenColumn="0"/>
<NAME tokenValue="root" tokenLine="3" tokenColumn="1">
<TOKEN tokenValue="root" tokenLine="3" tokenColumn="1"/>
</NAME>
<TOKEN tokenValue=">" tokenLine="3" tokenColumn="5"/>
</S_TAG>
<CONTENT tokenValue="
" tokenLine="3" tokenColumn="6">
<CHAR_DATA tokenValue="
" tokenLine="3" tokenColumn="6">
<TOKEN tokenValue="
" tokenLine="3" tokenColumn="6"/>
</CHAR_DATA>
</CONTENT>
<E_TAG tokenValue="</" tokenLine="5" tokenColumn="0">
<TOKEN tokenValue="</" tokenLine="5" tokenColumn="0"/>
<NAME tokenValue="root" tokenLine="5" tokenColumn="2">
<TOKEN tokenValue="root" tokenLine="5" tokenColumn="2"/>
</NAME>
<TOKEN tokenValue=">" tokenLine="5" tokenColumn="6"/>
</E_TAG>
</ELEMENT>
<MISC/>
</DOCUMENT>
分析日志:
Retrieve remote issues of project prjtest...
Start SonarQube analysis on prjtest...
INFO: SonarQube Server 4.3
09:26:29.309 INFO - Preview mode
09:26:29.315 INFO - Load batch settings
09:26:29.329 DEBUG - Download: http://xxxx/sonar/batch_bootstrap/properties?dryRun=true (no proxy)
09:26:29.554 INFO - User cache: C:\Users\xxxxx-s\.sonar\cache
09:26:29.567 INFO - Install plugins
09:26:29.567 DEBUG - Download index of plugins
09:26:29.567 DEBUG - Download: http://xxxxxx/sonar/deploy/plugins/index.txt (no proxy)
09:26:29.598 INFO - Include plugins:
09:26:29.599 INFO - Exclude plugins: devcockpit, buildstability, pdfreport, report, buildbreaker, scmactivity, views, jira
09:26:29.847 DEBUG - Download: http://xxxx/sonar/batch_bootstrap/db?project=fr.sihm.eand:prjtest (no proxy)
09:26:30.111 DEBUG - Dry Run database size: 1 MB
09:26:30.119 INFO - Create JDBC datasource for jdbc:h2:D:\java\workspaces\wks-luna-SR1-01-Sonar\.metadata\.plugins\org.eclipse.core.resources\.projects\prjtest\org.sonar.ide.eclipse.core\.sonartmp\preview1414743989840-0
09:26:30.845 DEBUG - Testing JDBC connection
09:26:32.049 INFO - Initializing Hibernate
09:26:32.053 DEBUG - hibernate.generate_statistics: false
09:26:32.053 DEBUG - hibernate.dialect: org.hibernate.dialect.H2Dialect
09:26:32.053 DEBUG - hibernate.connection.provider_class: org.sonar.jpa.session.CustomHibernateConnectionProvider
09:26:33.503 DEBUG - Loaded 3276 properties from l10n bundles
09:26:35.161 INFO - Load project settings
09:26:35.161 DEBUG - Download: http://xxxxxx/sonar/batch_bootstrap/properties?project=fr.sihm.eand:prjtest&dryRun=true (no proxy)
09:26:35.216 INFO - Apply project exclusions
09:26:35.452 DEBUG - ooo Using Connection [jdbc:h2:D:\java\workspaces\wks-luna-SR1-01-Sonar\.metadata\.plugins\org.eclipse.core.resources\.projects\prjtest\org.sonar.ide.eclipse.core\.sonartmp\preview1414743989840-0, UserName=SONAR, H2 JDBC Driver]
09:26:35.457 DEBUG - ==> Preparing: select * from projects p where p.id=?
09:26:35.482 DEBUG - ==> Parameters: 14701(Long)
09:26:35.734 INFO - ------------- Scan prjtest
09:26:35.763 INFO - Load module settings
09:26:35.797 DEBUG - Download: http://xxxx/sonar/batch_bootstrap/properties?project=fr.sihm.eand:prjtest&dryRun=true (no proxy)
09:26:36.162 DEBUG - Available languages:
09:26:36.163 DEBUG - * Java => "java"
09:26:36.163 DEBUG - * Web => "web"
09:26:36.163 DEBUG - * XML => "xml"
09:26:36.163 DEBUG - * JavaScript => "js"
09:26:37.142 INFO - Loading technical debt model...
09:26:37.181 INFO - Loading technical debt model done: 39 ms
09:26:37.204 INFO - Loading rules...
09:26:37.711 INFO - Loading rules done: 507 ms
09:26:37.780 INFO - Configure Maven plugins
09:26:37.970 INFO - Compare to previous analysis (2014-10-30)
09:26:37.991 INFO - Compare over 30 days (2014-10-01, analysis of 2014-10-23 15:42:10.95)
09:26:37.993 INFO - No quality gate is configured.
09:26:38.340 DEBUG - Initializers :
09:26:38.340 INFO - Base dir: D:\001-Projets\Sonar\prjtest
09:26:38.340 INFO - Working dir: D:\java\workspaces\wks-luna-SR1-01-Sonar\.metadata\.plugins\org.eclipse.core.resources\.projects\prjtest\org.sonar.ide.eclipse.core
09:26:38.340 INFO - Source dirs: D:\001-Projets\Sonar\prjtest\src
09:26:38.340 INFO - Binary dirs: D:\001-Projets\Sonar\prjtest\bin
09:26:38.340 INFO - Source encoding: windows-1252, default locale: fr_FR
09:26:38.341 INFO - Index files
09:26:38.346 DEBUG - Declared extensions of language Java were converted to sonar.lang.patterns.java : **/*.java,**/*.jav
09:26:38.346 DEBUG - Declared extensions of language Web were converted to sonar.lang.patterns.web : **/*.html,**/*.xhtml,**/*.jsp,**/*.jspf,**/*.jsf,**/*.php,**/*.erb,**/*.rhtml
09:26:38.346 DEBUG - Declared extensions of language XML were converted to sonar.lang.patterns.xml : **/*.xml
09:26:38.347 DEBUG - Declared extensions of language JavaScript were converted to sonar.lang.patterns.js : **/*.js
09:26:38.438 DEBUG - Language of file 'src/Jx_bad.xml' is detected to be 'xml'
09:26:38.542 DEBUG - Language of file 'src/Jx_G_J_Ds2MoJoDs_good.xml' is detected to be 'xml'
09:26:38.544 DEBUG - Language of file 'src/NewFile.xml' is detected to be 'xml'
09:26:38.545 INFO - 3 files indexed
09:26:38.669 INFO - Quality profile for xml: SIHM - DTS - Général
09:26:38.726 DEBUG - Sensors : QProfileSensor -> CpdSensor -> XmlSensor -> LineCountSensor -> JaCoCoSensor -> JaCoCoItSensor -> JaCoCoOverallSensor -> InitialOpenIssuesSensor -> ProfileEventsSensor -> ProjectLinksSensor
09:26:38.727 INFO - Sensor QProfileSensor...
09:26:38.739 INFO - Sensor QProfileSensor done: 12 ms
09:26:38.740 INFO - Sensor CpdSensor...
09:26:38.740 DEBUG - Detection of duplicated code is not supported for xml
09:26:38.740 INFO - Sensor CpdSensor done: 0 ms
09:26:38.740 INFO - Sensor XmlSensor...
09:26:39.126 INFO - Sensor XmlSensor done: 386 ms
09:26:39.127 INFO - Sensor LineCountSensor...
09:26:39.137 DEBUG - Count comment in D:\001-Projets\Sonar\prjtest\src\Jx_G_J_Ds2MoJoDs_good.xml
09:26:39.167 DEBUG - LineCountSensor: src/Jx_G_J_Ds2MoJoDs_good.xml:920,17,0
09:26:39.168 DEBUG - Count comment in D:\001-Projets\Sonar\prjtest\src\Jx_bad.xml
09:26:39.172 DEBUG - LineCountSensor: src/Jx_bad.xml:10,0,0
09:26:39.174 DEBUG - Count comment in D:\001-Projets\Sonar\prjtest\src\NewFile.xml
09:26:39.177 DEBUG - LineCountSensor: src/NewFile.xml:5,2,0
09:26:39.177 INFO - Sensor LineCountSensor done: 51 ms
09:26:39.177 INFO - Sensor JaCoCoSensor...
09:26:39.188 INFO - Project coverage is set to 0% as no JaCoCo execution data has been dumped: D:\001-Projets\Sonar\prjtest\target\jacoco.exec
09:26:39.205 WARN - Coverage information was not collected. Perhaps you forget to include debug information into compiled classes?
09:26:39.205 INFO - Sensor JaCoCoSensor done: 28 ms
09:26:39.206 INFO - Sensor JaCoCoItSensor...
09:26:39.208 INFO - Project coverage is set to 0% as no JaCoCo execution data has been dumped: D:\001-Projets\Sonar\prjtest\target\jacoco-it.exec
09:26:39.209 WARN - Coverage information was not collected. Perhaps you forget to include debug information into compiled classes?
09:26:39.209 INFO - Sensor JaCoCoItSensor done: 3 ms
09:26:39.209 INFO - Sensor JaCoCoOverallSensor...
09:26:39.209 INFO - Sensor JaCoCoOverallSensor done: 0 ms
09:26:39.209 INFO - Sensor InitialOpenIssuesSensor...
09:26:39.232 INFO - Sensor InitialOpenIssuesSensor done: 23 ms
09:26:39.233 INFO - Sensor ProfileEventsSensor...
09:26:39.266 INFO - Sensor ProfileEventsSensor done: 33 ms
09:26:39.266 INFO - Sensor ProjectLinksSensor...
09:26:39.285 INFO - Sensor ProjectLinksSensor done: 19 ms
09:26:39.436 INFO - Execute decorators...
09:26:39.437 DEBUG - Decorators: ManualMeasureDecorator -> org.sonar.issuesreport.tree.ResourceTree@480994d3 -> SumDuplicationsDecorator -> org.sonar.plugins.design.batch.ProjectDsmDecorator@7146c6ea -> FileTangleIndexDecorator -> org.sonar.plugins.core.issue.IssueTrackingDecorator@a5d23c9 -> UnitTestDecorator -> org.sonar.plugins.core.sensors.DirectoriesDecorator@6065bcb7 -> org.sonar.plugins.core.sensors.FilesDecorator@1ee6434 -> org.sonar.plugins.core.timemachine.TimeMachineConfigurationPersister@59ec5a0b -> org.sonar.plugins.core.timemachine.NewCoverageAggregator@71d78cac -> org.sonar.plugins.uselesscodetracker.decorator.TempMethodLinesDecorator@550f522b -> org.sonar.plugins.uselesscodetracker.decorator.DuplicationsDecorator@6a7fc4c1 -> f(lines) -> f(generated_lines) -> f(ncloc) -> f(generated_ncloc) -> f(classes) -> f(packages) -> f(functions) -> f(accessors) -> f(statements) -> f(public_api) -> f(comment_lines) -> f(comment_blank_lines) -> f(public_undocumented_api) -> f(commented_out_code_lines) -> f(complexity) -> f(complexity_in_classes) -> f(complexity_in_functions) -> f(class_complexity_distribution) -> f(function_complexity_distribution) -> f(file_complexity_distribution) -> f(lines_to_cover) -> f(uncovered_lines) -> f(conditions_to_cover) -> f(uncovered_conditions) -> f(it_lines_to_cover) -> f(it_uncovered_lines) -> f(it_conditions_to_cover) -> f(it_uncovered_conditions) -> f(overall_lines_to_cover) -> f(overall_uncovered_lines) -> f(overall_conditions_to_cover) -> f(overall_uncovered_conditions) -> f(rfc) -> f(rfc_distribution) -> f(lcom4_distribution) -> f(package_cycles) -> f(package_tangles) -> f(package_feedback_edges) -> f(package_edges_weight) -> f(new_lines_to_cover) -> f(new_uncovered_lines) -> f(new_conditions_to_cover) -> f(new_uncovered_conditions) -> f(new_it_lines_to_cover) -> f(new_it_uncovered_lines) -> f(new_it_conditions_to_cover) -> f(new_it_uncovered_conditions) -> f(new_overall_lines_to_cover) -> f(new_overall_uncovered_lines) -> f(new_overall_conditions_to_cover) -> f(new_overall_uncovered_conditions) -> org.sonar.plugins.cpd.decorators.DuplicationDensityDecorator@2c7c898a -> PackageTangleIndexDecorator -> CountUnresolvedIssuesDecorator -> CountFalsePositivesDecorator -> org.sonar.plugins.core.technicaldebt.DebtDecorator@23dc70c1 -> org.sonar.plugins.core.technicaldebt.NewDebtDecorator@53b907d9 -> CommentDensityDecorator -> org.sonar.plugins.uselesscodetracker.decorator.TotalDecorator@1842dc39 -> f(file_complexity) -> f(class_complexity) -> f(function_complexity) -> org.sonar.plugins.core.sensors.CoverageDecorator@6167c42f -> org.sonar.plugins.core.sensors.LineCoverageDecorator@2cbc2db2 -> org.sonar.plugins.core.sensors.BranchCoverageDecorator@2de96eba -> org.sonar.plugins.core.sensors.ItLineCoverageDecorator@6296e4bf -> org.sonar.plugins.core.sensors.ItCoverageDecorator@220cda54 -> org.sonar.plugins.core.sensors.ItBranchCoverageDecorator@39109603 -> org.sonar.plugins.core.sensors.OverallLineCoverageDecorator@4d3990a5 -> org.sonar.plugins.core.sensors.OverallCoverageDecorator@18df26a1 -> org.sonar.plugins.core.sensors.OverallBranchCoverageDecorator@5c459194 -> org.sonar.plugins.core.issue.WeightedIssuesDecorator@fe38c0e -> ViolationDensityDecorator -> IssuesDensityDecorator -> VariationDecorator
09:26:39.617 DEBUG - Decorator time:
ManualMeasureDecorator: 12ms
org.sonar.issuesreport.tree.ResourceTree@480994d3: 1ms
SumDuplicationsDecorator: 7ms
org.sonar.plugins.design.batch.ProjectDsmDecorator@7146c6ea: 0ms
FileTangleIndexDecorator: 0ms
org.sonar.plugins.core.issue.IssueTrackingDecorator@a5d23c9: 75ms
UnitTestDecorator: 1ms
org.sonar.plugins.core.sensors.DirectoriesDecorator@6065bcb7: 1ms
org.sonar.plugins.core.sensors.FilesDecorator@1ee6434: 0ms
org.sonar.plugins.core.timemachine.TimeMachineConfigurationPersister@59ec5a0b: 5ms
org.sonar.plugins.core.timemachine.NewCoverageAggregator@71d78cac: 3ms
org.sonar.plugins.uselesscodetracker.decorator.TempMethodLinesDecorator@550f522b: 10ms
org.sonar.plugins.uselesscodetracker.decorator.DuplicationsDecorator@6a7fc4c1: 0ms
f(lines): 0ms
f(generated_lines): 0ms
f(ncloc): 0ms
f(generated_ncloc): 0ms
f(classes): 0ms
f(packages): 0ms
f(functions): 0ms
f(accessors): 0ms
f(statements): 0ms
f(public_api): 0ms
f(comment_lines): 0ms
f(comment_blank_lines): 0ms
f(public_undocumented_api): 0ms
f(commented_out_code_lines): 0ms
f(complexity): 0ms
f(complexity_in_classes): 1ms
f(complexity_in_functions): 0ms
f(class_complexity_distribution): 0ms
f(function_complexity_distribution): 0ms
f(file_complexity_distribution): 0ms
f(lines_to_cover): 0ms
f(uncovered_lines): 0ms
f(conditions_to_cover): 0ms
f(uncovered_conditions): 0ms
f(it_lines_to_cover): 1ms
f(it_uncovered_lines): 0ms
f(it_conditions_to_cover): 1ms
f(it_uncovered_conditions): 0ms
f(overall_lines_to_cover): 0ms
f(overall_uncovered_lines): 0ms
f(overall_conditions_to_cover): 1ms
f(overall_uncovered_conditions): 0ms
f(rfc): 0ms
f(rfc_distribution): 0ms
f(lcom4_distribution): 0ms
f(package_cycles): 0ms
f(package_tangles): 0ms
f(package_feedback_edges): 0ms
f(package_edges_weight): 0ms
f(new_lines_to_cover): 0ms
f(new_uncovered_lines): 0ms
f(new_conditions_to_cover): 0ms
f(new_uncovered_conditions): 0ms
f(new_it_lines_to_cover): 0ms
f(new_it_uncovered_lines): 0ms
f(new_it_conditions_to_cover): 0ms
f(new_it_uncovered_conditions): 0ms
f(new_overall_lines_to_cover): 0ms
f(new_overall_uncovered_lines): 0ms
f(new_overall_conditions_to_cover): 0ms
f(new_overall_uncovered_conditions): 0ms
org.sonar.plugins.cpd.decorators.DuplicationDensityDecorator@2c7c898a: 1ms
PackageTangleIndexDecorator: 0ms
CountUnresolvedIssuesDecorator: 14ms
CountFalsePositivesDecorator: 0ms
org.sonar.plugins.core.technicaldebt.DebtDecorator@23dc70c1: 5ms
org.sonar.plugins.core.technicaldebt.NewDebtDecorator@53b907d9: 2ms
CommentDensityDecorator: 4ms
org.sonar.plugins.uselesscodetracker.decorator.TotalDecorator@1842dc39: 0ms
f(file_complexity): 0ms
f(class_complexity): 0ms
f(function_complexity): 0ms
org.sonar.plugins.core.sensors.CoverageDecorator@6167c42f: 1ms
org.sonar.plugins.core.sensors.LineCoverageDecorator@2cbc2db2: 0ms
org.sonar.plugins.core.sensors.BranchCoverageDecorator@2de96eba: 0ms
org.sonar.plugins.core.sensors.ItLineCoverageDecorator@6296e4bf: 0ms
org.sonar.plugins.core.sensors.ItCoverageDecorator@220cda54: 0ms
org.sonar.plugins.core.sensors.ItBranchCoverageDecorator@39109603: 0ms
org.sonar.plugins.core.sensors.OverallLineCoverageDecorator@4d3990a5: 0ms
org.sonar.plugins.core.sensors.OverallCoverageDecorator@18df26a1: 0ms
org.sonar.plugins.core.sensors.OverallBranchCoverageDecorator@5c459194: 0ms
org.sonar.plugins.core.issue.WeightedIssuesDecorator@fe38c0e: 4ms
ViolationDensityDecorator: 1ms
IssuesDensityDecorator: 0ms
VariationDecorator: 25ms
09:26:39.619 DEBUG - 162 measures to dump
09:26:39.706 INFO - Export results to D:\java\workspaces\wks-luna-SR1-01-Sonar\.metadata\.plugins\org.eclipse.core.resources\.projects\prjtest\org.sonar.ide.eclipse.core\sonar-report.json
09:26:39.712 INFO - Store results in database
09:26:39.713 DEBUG - Execute org.sonar.batch.index.ComponentDataPersister
09:26:39.719 DEBUG - Execute org.sonar.batch.issue.IssuePersister
09:26:39.719 DEBUG - IssuePersister skipped in preview mode
09:26:39.719 DEBUG - Execute org.sonar.batch.phases.GraphPersister
09:26:39.804 INFO - ANALYSIS SUCCESSFUL
09:26:39.807 DEBUG - Post-jobs : org.sonar.issuesreport.ReportJob@276aa33f
09:26:39.807 INFO - Executing post-job class org.sonar.issuesreport.ReportJob
09:26:39.813 DEBUG - Generating HTML Report to: D:\java\workspaces\wks-luna-SR1-01-Sonar\.metadata\.plugins\org.eclipse.core.resources\.projects\prjtest\org.sonar.ide.eclipse.core\issues-report\issues-report.html
09:26:40.176 INFO - HTML Issues Report generated: D:\java\workspaces\wks-luna-SR1-01-Sonar\.metadata\.plugins\org.eclipse.core.resources\.projects\prjtest\org.sonar.ide.eclipse.core\issues-report\issues-report.html
09:26:40.176 DEBUG - Generating Light HTML Report to: D:\java\workspaces\wks-luna-SR1-01-Sonar\.metadata\.plugins\org.eclipse.core.resources\.projects\prjtest\org.sonar.ide.eclipse.core\issues-report\issues-report-light.html
09:26:40.212 INFO - Light HTML Issues Report generated: D:\java\workspaces\wks-luna-SR1-01-Sonar\.metadata\.plugins\org.eclipse.core.resources\.projects\prjtest\org.sonar.ide.eclipse.core\issues-report\issues-report-light.html
09:26:40.236 INFO -
------------- Issues Report -------------
No new issue
-------------------------------------------
我很困惑。有人能帮助我吗?
答案 0 :(得分:0)
我找到了解决方案:xml插件的自定义xpath规则直接在XML文件上工作,而不在AST树上工作...(与Java插件不同;))
在我的示例中,xpath规则必须是:
/root