在将自定义checkstyle文件上传到声纳配置文件时,获取错误页面“我们很抱歉,但出了点问题”。
通过声纳日志,发现规则模块名称 RegexpSinglelineJava 存在问题。
将checkstyle文件上传到声纳时,模块名称为RegexpSinglelineJava的规则不允许上传。
我试过了:
我列出了创建问题和声纳日志的规则。我找不到问题所在。
请告诉我这个声纳版本有什么问题?这些规则有什么问题吗?没有规则模块名称 RegexpSinglelineJava 我可以上传文件。
还有一件事是我在其他checkstyle配置文件中看到相同的规则我不确定这些规则是如何添加的。
上传checkstyle文件后,有没有办法将规则添加到配置文件中?请指导我继续前进..
我们使用的声纳版本是3.4.1 Java版本:1.6.0_81-b08
我上传的自定义checkstyle文件:
<module name="RegexpSinglelineJava">
<property name="format" value="UserContext.set*" />
<property name="ignoreComments" value="true" />
<property name="message"
value="Only architecture should be using UserContext.set* methods " />
<property name="severity" value="error" />
</module>
<module name="RegexpSinglelineJava">
<property name="format"
value="import org.springframework.beans.factory.annotation.*" />
<property name="message"
value="beans.factory.annotation.* is not allowed with import org.springframework statement." />
<property name="severity" value="error" />
</module>
<module name="RegexpSinglelineJava">
<property name="format"
value="@org.springframework.beans.factory.annotation.Scope" />
<property name="message"
value="Use of @org.springframework.beans.factory.annotation.Scope is not allowed." />
<property name="severity" value="error" />
</module>
<module name="RegexpSinglelineJava">
<property name="format" value="import org.springframework.[{stereotype}].*" />
<property name="message"
value="stereotype.* is not allowed with import org.springframework statement." />
<property name="severity" value="error" />
</module>
<module name="RegexpSinglelineJava">
<property name="format" value="\?.*:.*\?.*:" />
<property name="message" value="Inline Ifs cannot be nested." />
<property name="severity" value="error" />
<property name="ignoreComments" value="true" />
</module>
<module name="RegexpSinglelineJava">
<property name="format" value="import sf.jra.framework.eventing.Log" />
<property name="message"
value="Logger must be obtained from com.meridea.cs.logging.Logger rather than from than sf.jra.framework.eventing.Log" />
<property name="severity" value="error" />
</module>
<module name="RegexpSinglelineJava">
<property name="format"
value="com\.thoughtworks\.xstream\.converters\.(basic\.DateConverter|extended\.Sql(Date|Time(stamp)?)Converter)" />
<property name="message"
value="This class is not time zone safe. Please use one of the converters in statefarm.framework.ccs.cbb.xstream.converters instead." />
<property name="severity" value="error" />
<property name="ignoreComments" value="true" />
</module>
<module name="RegexpSinglelineJava">
<property name="format"
value="(new\s+GregorianCalendar\s*\()|(Calendar\s*\.getInstance\s*\()" />
<property name="message"
value="Not time zone safe. Please use DateTimeUtil.createUTCCalendar() instead." />
<property name="severity" value="error" />
<property name="ignoreComments" value="true" />
</module>
<module name="RegexpSinglelineJava">
<property name="format" value="(Date|Time(stamp)?)\s*\.valueOf\s*\(" />
<property name="message"
value="The valueOf methods on Date, Time, and Timestamp are not time zone safe. Please use createUTCXXXX methods in DateTimeUtil instead." />
<property name="severity" value="error" />
<property name="ignoreComments" value="true" />
</module>
<module name="RegexpSinglelineJava">
<property name="format"
value="(new\s+GregorianCalendar\s*\()|(Calendar\s*\.getInstance\s*\()" />
<property name="message"
value="Not time zone safe. Please use DateTimeUtil.createUTCCalendar() instead." />
<property name="severity" value="error" />
<property name="ignoreComments" value="true" />
</module>
<module name="RegexpSinglelineJava">
<property name="format" value="java\.text\.(Simple)?DateFormat" />
<property name="message"
value="Not time zone safe. For converting Strings to Dates, please use DateTimeUtil.createUTCDate(). For converting Dates to Strings, please use DateTimeUtil.toUTCString()." />
<property name="severity" value="error" />
<property name="ignoreComments" value="true" />
</module>
<module name="RegexpSinglelineJava">
<property name="format" value="Externalizable" />
<property name="ignoreComments" value="true" />
<property name="message"
value="Classes implementing ''Externalizable'' are not allowed." />
<property name="severity" value="warning" />
</module>
<module name="RegexpSinglelineJava">
<property name="format" value="@deprecated\s*$" />
<property name="ignoreComments" value="false" />
<property name="message" value="@deprecated should provide an alternative." />
<property name="severity" value="warning" />
</module>
<module name="RegexpSinglelineJava">
<property name="id"
value="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck_1343392848" />
<property name="severity" value="error" />
<property name="ignoreComments" value="true" />
<property name="format"
value="import com\.ibm\.(?!.*(pdq|CacheableCommandImpl|DistributedMap))" />
<property name="message"
value="Should not import platform-specific code. For example, com.ibm.*, com.sun.* etc.," />
</module>
<module name="RegexpSinglelineJava">
<property name="id"
value="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck_1343393550" />
<property name="severity" value="info" />
<property name="format" value="org.apache.struts.action.Action" />
<property name="message"
value="Use SFCC Framework classes BaseAction or URLDispatchAction when extending Struts Actions." />
<property name="ignoreComments" value="true" />
</module>
<module name="RegexpSinglelineJava">
<property name="id"
value="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck_1343393122" />
<property name="severity" value="warning" />
<property name="ignoreComments" value="true" />
<property name="format" value="InitialContext.lookup" />
<property name="message"
value="For ejb/webservice lookups, JRA2+ offers the framework classes RemoteEJBBDFactory or JAXRPCBusinessDelegateFactory that are easier to use and maintain than InitialContext.lookup" />
</module>
<module name="RegexpSinglelineJava">
<property name="id"
value="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck_1343393814" />
<property name="severity" value="error" />
<property name="message"
value="Runtime.getRuntime() is a security violation. You must get approval and a code review to use Runtime.getRuntime()" />
<property name="ignoreComments" value="true" />
<property name="format" value="Runtime.getRuntime" />
</module>
<module name="RegexpSinglelineJava">
<property name="id"
value="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck_1343393755" />
<property name="severity" value="error" />
<property name="ignoreCase" value="true" />
<property name="message"
value="Use SF Eventing Framework Log class instead of using printstacktrace in production-level code. It is ok to use locally for debugging but not on formal environments." />
<property name="format" value="printstacktrace" />
<property name="ignoreComments" value="true" />
</module>
<module name="RegexpSinglelineJava">
<property name="id"
value="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck_1343393049" />
<property name="severity" value="error" />
<property name="ignoreComments" value="true" />
<property name="format" value="import com.sun." />
<property name="message"
value="Should not import platform-specific code. For example, com.ibm.*, com.sun.* etc.," />
</module>
<module name="RegexpSinglelineJava">
<property name="id"
value="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck_1343393376" />
<property name="severity" value="error" />
<property name="format" value="\bnative\b" />
<property name="message"
value="Applications must not use the ''native'' keyword" />
<property name="ignoreComments" value="true" />
</module>
<module name="RegexpSinglelineJava">
<property name="id"
value="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck_1343394411" />
<property name="severity" value="warning" />
<property name="message"
value="Try not to use ''synch'' or ''synchronized''. Double check the usage of it in the code. Developers must acknowledge their use is not trivial, and requires a compelling reason." />
<property name="ignoreComments" value="true" />
<property name="format" value="synch" />
</module>
<module name="RegexpSinglelineJava">
<property name="id"
value="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck_1343392917" />
<property name="severity" value="warning" />
<property name="ignoreComments" value="true" />
<property name="format"
value="import com\.ibm\.(?=.*(CacheableCommandImpl|DistributedMap))" />
<property name="message"
value="Should consider moving away from platform-specific (com.ibm.*) code such as DynaCache" />
</module>
<module name="RegexpSinglelineJava">
<property name="id"
value="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck_1343393884" />
<property name="severity" value="warning" />
<property name="message"
value="For ejb/webservice lookups, JRA2+ offers the framework classes RemoteEJBBDFactory or JAXRPCBusinessDelegateFactory that are easier to use and maintain than ServiceLocator.newInstance" />
<property name="ignoreComments" value="true" />
<property name="format" value="ServiceLocator.newInstance" />
</module>
<module name="RegexpSinglelineJava">
<property name="id"
value="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck_1343394457" />
<property name="severity" value="error" />
<property name="format" value="System\.exit" />
<property name="message" value="Never use ''System.exit''" />
<property name="ignoreComments" value="true" />
</module>
<module name="RegexpSinglelineJava">
<property name="id"
value="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck_1343392491" />
<property name="severity" value="error" />
<property name="ignoreComments" value="true" />
<property name="format" value="IBMSession" />
<property name="message" value="Do not use IBMSession" />
</module>
<module name="RegexpSinglelineJava">
<property name="id"
value="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck_1343393943" />
<property name="severity" value="error" />
<property name="message"
value="Applications must not use the ''strictfp'' keyword" />
<property name="ignoreComments" value="true" />
<property name="format" value="strictfp" />
</module>
<module name="RegexpSinglelineJava">
<property name="id"
value="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck_1343394497" />
<property name="severity" value="error" />
<property name="format" value="volatile" />
<property name="message"
value="Applications must not use the ''volatile'' keyword" />
<property name="ignoreComments" value="true" />
</module>
从sonar.log中提取
2015.08.03 07:58:55 ERROR o.s.s.ui.JRubyFacade Fail to render: http://lt00nxam0060000.opr.abc.org/sonar/profiles/create
Expected single result, but got : [Rule[id=1937,name=RegexpSinglelineJava printstacktrace,key=com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck_13
43393755,configKey=Checker/TreeWalker/RegexpSinglelineJava,plugin=checkstyle,enabled=true,severity=<null>,cardinality=SINGLE], Rule[id=1938,name=RegexpSinglelineJava vo
latile,key=com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck_1343394497,configKey=Checker/TreeWalker/RegexpSinglelineJava,plugin=checkstyle,enable
d=true,severity=<null>,cardinality=SINGLE], Rule[id=1940,name=RegexpSinglelineJava synch,key=com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck_134
3394411,configKey=Checker/TreeWalker/RegexpSinglelineJava,plugin=checkstyle,enabled=true,severity=<null>,cardinality=SINGLE], Rule[id=1969,name=RegexpSinglelineJava Dat
eFormat,key=com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck_1395066936,configKey=Checker/TreeWalker/RegexpSinglelineJava,plugin=checkstyle,enabl
ed=true,severity=<null>,cardinality=SINGLE], Rule[id=1970,name=RegexpSinglelineJava ThreadLocal,key=com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCh
eck_1395066574,configKey=Checker/TreeWalker/RegexpSinglelineJava,plugin=checkstyle,enabled=true,severity=<null>,cardinality=SINGLE], Rule[id=1943,name=RegexpSinglelineJ
ava IBMSession,key=com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck_1343392491,configKey=Checker/TreeWalker/RegexpSinglelineJava,plugin=checkstyl
e,enabled=true,severity=<null>,cardinality=SINGLE], Rule[id=1944,name=RegexpSinglelineJava import com.sun.,key=com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSingl
elineJavaCheck_1343393049,configKey=Checker/TreeWalker/RegexpSinglelineJava,plugin=checkstyle,enabled=true,severity=<null>,cardinality=SINGLE], Rule[id=1949,name=Regexp
SinglelineJava InitialContext.lookup,key=com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck_1343393122,configKey=Checker/TreeWalker/RegexpSinglelin
eJava,plugin=checkstyle,enabled=true,severity=<null>,cardinality=SINGLE], Rule[id=1950,name=RegexpSinglelineJava System.exit,key=com.puppycrawl.tools.checkstyle.checks.
regexp.RegexpSinglelineJavaCheck_1343394457,configKey=Checker/TreeWalker/RegexpSinglelineJava,plugin=checkstyle,enabled=true,severity=<null>,cardinality=SINGLE], Rule[i
d=1951,name=RegexpSinglelineJava import com\.ibm\.(?=.*(CacheableCommandImpl|DistributedMap)),key=com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaChec
k_1343392917,configKey=Checker/TreeWalker/RegexpSinglelineJava,plugin=checkstyle,enabled=true,severity=<null>,cardinality=SINGLE], Rule[id=1952,name=RegexpSinglelineJav
a org.apache.struts.action.Action,key=com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck_1343393550,configKey=Checker/TreeWalker/RegexpSinglelineJa
va,plugin=checkstyle,enabled=true,severity=<null>,cardinality=SINGLE], Rule[id=1953,name=RegexpSinglelineJava import com.ibm,key=com.puppycrawl.tools.checkstyle.checks.
regexp.RegexpSinglelineJavaCheck_1343392848,configKey=Checker/TreeWalker/RegexpSinglelineJava,plugin=checkstyle,enabled=true,severity=<null>,cardinality=SINGLE], Rule[i
d=1954,name=RegexpSinglelineJava Runtime.getRuntime,key=com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck_1343393814,configKey=Checker/TreeWalker/
RegexpSinglelineJava,plugin=checkstyle,enabled=true,severity=<null>,cardinality=SINGLE], Rule[id=1959,name=RegexpSinglelineJava native,key=com.puppycrawl.tools.checksty
le.checks.regexp.RegexpSinglelineJavaCheck_1343393376,configKey=Checker/TreeWalker/RegexpSinglelineJava,plugin=checkstyle,enabled=true,severity=<null>,cardinality=SINGL
E], Rule[id=1960,name=RegexpSinglelineJava strictfp,key=com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck_1343393943,configKey=Checker/TreeWalker/
RegexpSinglelineJava,plugin=checkstyle,enabled=true,severity=<null>,cardinality=SINGLE], Rule[id=1961,name=RegexpSinglelineJava ServiceLocator.newInstance,key=com.puppy
crawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck_1343393884,configKey=Checker/TreeWalker/RegexpSinglelineJava,plugin=checkstyle,enabled=true,severity=<nul
l>,cardinality=SINGLE], Rule[id=1872,name=Regexp Singleline Java,key=com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck,configKey=Checker/TreeWalke
r/RegexpSinglelineJava,plugin=checkstyle,enabled=true,severity=MAJOR,cardinality=MULTIPLE]]
org.sonar.jpa.session.JpaDatabaseSession.getSingleResult(JpaDatabaseSession.java:210)
org.sonar.core.rule.DefaultRuleFinder.find(DefaultRuleFinder.java:60)
org.sonar.plugins.checkstyle.CheckstyleProfileImporter.processRule(CheckstyleProfileImporter.java:123)
org.sonar.plugins.checkstyle.CheckstyleProfileImporter.processModule(CheckstyleProfileImporter.java:96)
org.sonar.plugins.checkstyle.CheckstyleProfileImporter.importProfile(CheckstyleProfileImporter.java:69)
org.sonar.server.rules.ProfilesConsole.importProfile(ProfilesConsole.java:133)
org.sonar.server.ui.JRubyFacade.importProfile(JRubyFacade.java:297)
答案 0 :(得分:0)
我认为这仅涉及模板规则。规则“布尔表达式复杂性”的示例(checkstyle:com.puppycrawl.tools.checkstyle.checks.metrics.BooleanExpressionComplexityCheck)请参阅声纳检查样式导入:无法在质量配置文件上激活规则模板以获取更多详细信息。
这些规则没有激活按钮,您可以使用默认属性或使用自定义属性创建它们。
在您的情况下,必须在sonarqube中创建RegexpSinglelineCheck模板规则,您无法通过导入xml文件来激活它(这实际上是一个限制)。并且规则不能转换为模板,既不能创建模板也不能创建模板被删除(当前在sonarqube checkstyle存储库中有大约44个规则模板)。
我建议使用谷歌使用的属性激活它们(但谷歌不使用它们中的一些,因此根据您的需要激活它们)
请参阅此链接:https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml