2015-10-07 49 views
0

獲取錯誤頁面將自定義checkstyle文件上傳到聲納配置文件時出現「我們很抱歉,但出錯了」。將自定義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 &apos;&apos;native&apos;&apos; 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 &apos;&apos;synch&apos;&apos; or &apos;&apos;synchronized&apos;&apos;. 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 &apos;&apos;System.exit&apos;&apos;" /> 
    <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 &apos;&apos;strictfp&apos;&apos; 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 &apos;&apos;volatile&apos;&apos; 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) 
+1

您是否嘗試過刪除所有* RegexpSingleLineJava *規則**除了一個**?這可能是問題在於你有這種類型的多個規則。 –

+0

非常感謝您的快速回復.. :)是的,我試着保留一個名字爲RegexpSingleLineJava的名字但沒有運氣的規則...... –

回答

0

我認爲這隻涉及模板規則。規則「布爾表達式複雜性」的示例(checkstyle:com.puppycrawl.tools.checkstyle.checks.metrics.BooleanExpressionComplexityCheck)請參閱Sonar Checkstyle導入:無法在質量配置文件上激活規則模板以獲取更多詳細信息。

這些規則沒有激活按鈕,您可以使用默認屬性或自定義屬性創建它們。

對你而言,RegexpSinglelineCheck模板規則必須在sonarqube中創建,你不能通過導入一個xml文件來激活它(這實際上是一個限制)。一個規則不能轉換成模板,既不能創建模板也不會被刪除(sonarqube checkstyle版本庫中目前有大約44個規則模板)。

我建議激活它們與谷歌使用的屬性(但其中一些不使用的谷歌這樣以根據自己的需要激活它們)

參考以下鏈接:https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml