Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SonarQube - Import existing checkstyle xml-file into SonarQube fails

I have installed SonarQube 5.1.2 and Checkstyle Plugin 2.3.

Problem: How can I import a Checkstyle XML configuration file? When I try to export a pre-installed FindBugs or Checkstyle rules configuration into an XML file, the export works. Then I try to import the same rules with other name and it doesn't work.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
  <property name="severity" value="warning"/>
  <module name="TreeWalker">
    <module name="JavadocMethod">
      <property name="scope" value="public"/>
      <property name="suppressLoadErrors" value="true"/>
    </module>
    <module name="JavadocType">
      <property name="scope" value="public"/>
      <property name="authorFormat" value="^.../[^,]+(,\s.../[^,]+)*$"/>
    </module>
    <module name="JavadocVariable">
      <property name="scope" value="public"/>
    </module>
    <module name="JavadocStyle"/>
    <module name="ConstantName"/>
    <module name="LocalFinalVariableName">
      <property name="format" value="^[a-z_][a-zA-Z0-9]*$"/>
    </module>
    <module name="LocalVariableName">
      <property name="format" value="^[a-z_][a-zA-Z0-9]*$"/>
    </module>
    <module name="MemberName"/>
    <module name="MethodName"/>
    <module name="PackageName"/>
    <module name="ParameterName"/>
    <module name="StaticVariableName"/>
    <module name="TypeName"/>
    <module name="AvoidStarImport"/>
    <module name="IllegalImport"/>
    <module name="RedundantImport"/>
    <module name="UnusedImports"/>
    <module name="MethodLength"/>
    <module name="ParameterNumber"/>
    <module name="LineLength">
      <property name="max" value="180"/>
      <property name="tabWidth" value="4"/>
    </module>
    <module name="EmptyForIteratorPad"/>
    <module name="MethodParamPad"/>
    <module name="NoWhitespaceAfter"/>
    <module name="NoWhitespaceBefore"/>
    <module name="OperatorWrap"/>
    <module name="ParenPad"/>
    <module name="TypecastParenPad"/>
    <module name="WhitespaceAfter"/>
    <module name="WhitespaceAround">
      <property name="tokens" value="ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,COLON,DIV,DIV_ASSIGN,EQUAL,GE,GT,LAND,LCURLY,LE,LITERAL_ASSERT,LITERAL_CATCH,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_FOR,LITERAL_IF,LITERAL_RETURN,LITERAL_SYNCHRONIZED,LITERAL_TRY,LITERAL_WHILE,LOR,LT,MINUS,MINUS_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS,PLUS_ASSIGN,QUESTION,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN,LITERAL_ASSERT,TYPE_EXTENSION_AND,WILDCARD_TYPE"/>
    </module>
    <module name="ModifierOrder"/>
    <module name="RedundantModifier">
      <property name="tokens" value="VARIABLE_DEF,ANNOTATION_FIELD_DEF"/>
    </module>
    <module name="AvoidNestedBlocks"/>
    <module name="EmptyBlock">
      <property name="severity" value="ignore"/>
      <metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
    </module>
    <module name="LeftCurly"/>
    <module name="NeedBraces"/>
    <module name="RightCurly"/>
    <module name="AvoidInlineConditionals"/>
    <module name="EmptyStatement"/>
    <module name="EqualsHashCode"/>
    <module name="HiddenField">
      <property name="severity" value="ignore"/>
      <metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
    </module>
    <module name="IllegalInstantiation"/>
    <module name="InnerAssignment">
      <property name="severity" value="ignore"/>
      <metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
    </module>
    <module name="MagicNumber">
      <property name="severity" value="ignore"/>
      <metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
    </module>
    <module name="MissingSwitchDefault"/>
    <module name="RedundantThrows">
      <property name="suppressLoadErrors" value="true"/>
    </module>
    <module name="SimplifyBooleanExpression"/>
    <module name="SimplifyBooleanReturn"/>
    <module name="DesignForExtension">
      <property name="severity" value="ignore"/>
      <metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
    </module>
    <module name="FinalClass"/>
    <module name="HideUtilityClassConstructor"/>
    <module name="InterfaceIsType"/>
    <module name="VisibilityModifier">
      <property name="severity" value="ignore"/>
      <property name="packageAllowed" value="true"/>
      <property name="protectedAllowed" value="true"/>
      <metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
    </module>
    <module name="ArrayTypeStyle"/>
    <module name="FinalParameters">
      <property name="severity" value="ignore"/>
      <metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
    </module>
    <module name="TodoComment"/>
    <module name="UpperEll"/>
    <module name="GenericWhitespace"/>
    <module name="MissingOverride"/>
  </module>
  <module name="JavadocPackage">
    <property name="severity" value="ignore"/>
    <metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
  </module>
  <module name="NewlineAtEndOfFile"/>
  <module name="Translation"/>
  <module name="FileLength"/>
  <module name="FileTabCharacter">
    <property name="severity" value="ignore"/>
    <metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
  </module>
  <module name="RegexpSingleline">
    <property name="severity" value="ignore"/>
    <property name="format" value="\s+$"/>
    <property name="message" value="Line has trailing spaces."/>
    <metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
  </module>
  <module name="RegexpSingleline">
    <property name="format" value="^\s*@[A-Za-z]+(\([^\)]*\))?\s+[^\(].+$"/>
    <property name="message" value="Do not use inline annotations"/>
  </module>
  <module name="RegexpSingleline">
    <property name="format" value="\([^)]*@[^\s]+\s\s+.*\)"/>
    <property name="message" value="Use single space after inline annotation"/>
  </module>
</module>

I have already tried to export an existing pre-installed rule-set and tried to import it back with other name. But that causes the same failure.

Is this also a bug?

like image 616
Stipan Beljan Avatar asked Oct 26 '25 11:10

Stipan Beljan


1 Answers

You speak of importing a profile, but show what appears to be a tool-specific XML file, not one related to a SonarQube quality profile.

There are two types of things you can export and import:

  1. SonarQube Quality Profiles - these can be imported to a SonarQube server to create the profile named in the file. If a profile of that name already exists, you will indeed get an error.
  2. Tool-specific rule sets - for certain languages, these can be exported from a profile and imported when a new profile is created

Neither type of import functionality can be used to update an existing profile.

The functionality used to exist to import Checkstyle, PMD, and FindBugs rule sets at the creation of a Java profile, but since the SonarQube Java plugin has replaced a majority of rules from each of those plugins, that functionality has been removed.

like image 80
G. Ann - SonarSource Team Avatar answered Oct 29 '25 07:10

G. Ann - SonarSource Team