简体   繁体   中英

Getting error while uploading the custom checkstyle file to sonar profiles

Getting error page 'We're sorry, but something went wrong' while uploading the custom checkstyle file to sonar profiles.

Gone through the sonar logs and found there is problem with the rules module name RegexpSinglelineJava .

While uploading the checkstyle file to sonar the rules with the module name RegexpSinglelineJava were not allowing to upload.

I tried:

  • commented all the rules with that name then I am able to upload
  • uncommented rules one by one to check whether there is problem with any specific rule. As long as a single rule is uncommented in that module, I'm not allowed to upload

I have listed the rules which are creating issue and sonar log. I could n't find what is the issue.

Could please tell me what issue there is with this sonar version? is there any issue with the rules? without the rules module name RegexpSinglelineJava I am able to upload file.

One more thing is I am seeing the same rules in other checkstyle profile I am not sure how those got added.

Is there any way to add the rules to profile after uploading the checkstyle file? Could please guide me to move forward..

The sonar version we are using is 3.4.1 Java version:1.6.0_81-b08

The custom checkstyle file I upload:

<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>

extract from 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)

I think this concerns only template rules. Example with rule "Boolean Expression Complexity" (checkstyle:com.puppycrawl.tools.checkstyle.checks.metrics.BooleanExpressionComplexityCheck) See Sonar Checkstyle import: Rule template can't be activated on a Quality profile for more details.

there is no activation button for these rules,you can either create them with default properties or with your custom properties.

In your case RegexpSinglelineCheck template rule have to be created in sonarqube,you cannot activate it by importing an xml file(this is a actually a limitation).And a rule cannot be converted into template,a template can neither be created nor be deleted(there are about 44 rule templates currently in sonarqube checkstyle repository).

I would suggest activating them with the properties used by google(but some of them are not used by google so activate them with according to your needs)

refer this link: https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM