checkstyle-idea icon indicating copy to clipboard operation
checkstyle-idea copied to clipboard

Unable to use ${basedir} property

Open prenagha opened this issue 11 years ago • 14 comments

In my checks.xml I have the following:

<module name="SuppressionFilter">
  <property name="file" value="${basedir}/conf/checkstyle/suppressions.xml"/>
</module>

In idea.log on startup I see that base dir is pointing to ea.checkstyle.CheckStylePlugin - CheckStyle Plugin loaded with project base dir: "/Users/prenagha/Dev/er88"

I have the suppressions.xml in the resolved directory: ls -l /Users/prenagha/Dev/er88/conf/checkstyle/suppressions.xml -rw-r--r-- 1 prenagha staff 603 Jan 14 14:53 /Users/prenagha/Dev/er88/conf/checkstyle/suppressions.xml

However when the plugin runs it is unable to resolve and find the suppressions file. I get a popup within IntelliJ that says "The Checkstyle suppression filter file was not found and will be ignored"

I also tried setting basedir as a property in the plugin config window, but it is not saved, disappears after I enter it in the properties popup

Using latest IntelliJ (12.0.2) and latest plugin version (4.0.1) Let me know if you have any ideas on how to resolve this

prenagha avatar Jan 17 '13 14:01 prenagha

Variables used in the rules file will need to be defined in the properties for the rules file - i.e. there's no integration with IDEA here. So defining it in the plugin config window was correct, and if it's not being saved then that sounds like a bug.

However, from memory there is logic to try relative paths, so if suppressions.xml sits alongside the rules file and is referenced as suppressions.xml then I believe it'll work.

jshiell avatar Jan 17 '13 14:01 jshiell

Need to use the ${basedir} since that was the only way coworkers using the esclipse-cs can get suppressions to work there. So the property is definitely not saving. I have screenshots below of my setting. No matter what value I enter for the basedir property in the plugin config, it disappears, never saved. I've tried ".", "foo", "/User"... I also don't see anything in the checkstyle-idea.xml file related to the property - happy to just enter it there directly if you can tell me the format.

plugin config plugin-config

plugin third party config plugin-config-3p

property edit value attempt edit-property-attempt

property value disappeared after-save-property-disappear

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="CheckStyle-IDEA">
    <option name="configuration">
      <map>
        <entry key="active-configuration" value="FILE:$PROJECT_DIR$/conf/checkstyle/checks.xml:ER Checks" />
        <entry key="check-nonjava-files" value="false" />
        <entry key="check-test-classes" value="false" />
        <entry key="config-file" value="$PROJECT_DIR$/conf/build/checkstyle/checks.xml" />
        <entry key="location-0" value="CLASSPATH:/sun_checks.xml:The default CheckStyle rules" />
        <entry key="location-1" value="FILE:$PROJECT_DIR$/conf/checkstyle/checks.xml:ER Checks" />
        <entry key="thirdparty-classpath" value="$PROJECT_DIR$/../Tools/erchecks-201301.jar" />
      </map>
    </option>
  </component>
</project>

prenagha avatar Jan 17 '13 15:01 prenagha

I'll try have a look at the bug ASAP, although it's likely to be this weekend. In the meantime, here's a dump of one of my checkstyle config XMLs which shows a property (checkstyle.suppressions.file) in place - at least this might get you going while I try fix it!

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="CheckStyle-IDEA">
    <option name="configuration">
      <map>
        <entry key="active-configuration" value="file:$PROJECT_DIR$/../../../support/build/checkstyle-loose/src/main/resources/xxx-checkstyle-rules.xml:XXX" />
        <entry key="check-nonjava-files" value="false" />
        <entry key="check-test-classes" value="false" />
        <entry key="location-0" value="CLASSPATH:/sun_checks.xml:The default CheckStyle rules" />
        <entry key="location-1" value="file:$PROJECT_DIR$/../../../support/build/checkstyle-loose/src/main/resources/xxx-checkstyle-rules.xml:XXX" />
        <entry key="property-1.checkstyle.suppressions.file" value="$PROJECT_DIR$/../../../support/build/checkstyle-loose/src/main/resources/xxx-checkstyle-suppressions.xml" />
        <entry key="thirdparty-classpath" value="" />
      </map>
    </option>
  </component>
</project>


jshiell avatar Jan 17 '13 15:01 jshiell

Added the below to checkstyle-idea.xml and got it working. Thanks for the help.

  <entry key="property-1.basedir" value="$PROJECT_DIR$" />

prenagha avatar Jan 17 '13 15:01 prenagha

My pleasure. Sorry for the bug.

jshiell avatar Jan 17 '13 15:01 jshiell

Hmm. This is more curious than it appears. I'm unable to reproduce it - editing properties is working perfectly here. So there's obviously something odd going on.

My system in Mac OS 10.8.2, IDEA 12.0.2, IDEA running on JDK 1.6.0_33 (same result with _37, 1.7.0_11). Could you please let me know the JDK IDEA is running on, and attach your rules file if you're able? Thank you!

jshiell avatar Jan 20 '13 14:01 jshiell

OSX 10.8.2 IDEA 12.0.2 JDK 1.6.0_37-b06-434-11M3909

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE module PUBLIC
    "-//Puppy Crawl//DTD Check Configuration 1.1//EN"
    "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<module name="Checker">

  <property name="severity" value="warning"/>

  <module name="SuppressionFilter">
    <property name="file" value="${basedir}/conf/checkstyle/suppressions.xml"/>
  </module>

  <module name="SuppressionCommentFilter">
    <property name="offCommentFormat" value="CHECKSTYLE-OFF"/>
    <property name="onCommentFormat" value="CHECKSTYLE-ON"/>
  </module>

  <!-- Checks for Size Violations.                    -->
  <!-- See http://checkstyle.sourceforge.net/config_sizes.html -->
  <module name="FileLength" >
    <property name="max" value="3000" />
  </module>

  <module name="FileTabCharacter"/>

  <module name="TreeWalker">
    <module name="FileContentsHolder"/>
    <property name="tabWidth" value="2" />

    <!-- Write doc comments for all exposed API elements -->
    <module name="JavadocType">
      <property name="scope" value="protected"/>
      <property name="authorFormat" value="^[a-zA-Z0-9 ']{3,}$"/>
    </module>

    <!-- Extend Standard Checkstyle JavadocMethodCheck to skip constructors, equals(), compareTo(), hashcode() -->
    <module name="com.abc.checks.JavadocMethodSkipCtorCheck">
      <property name="scope" value="protected"/>
      <property name="allowUndeclaredRTE" value="true"/>
      <property name="allowMissingPropertyJavadoc" value="true"/>
    </module>

    <module name="JavadocVariable">
      <property name="scope" value="protected"/>
    </module>

    <!-- Adhere to generally accepted naming conventions -->
    <module name="AbstractClassName">
      <property name="format" value="^(Abstract.*|.*Base.*)$" />
    </module>
    <!-- logger isn't really a constant, so we let it slide past this check -->
    <module name="ConstantName">
      <property name="format" value="^([A-Z][A-Z0-9]*(_[A-Z0-9]+)*|log)$"/>
    </module>
    <module name="LocalFinalVariableName" />
    <module name="LocalVariableName" />
    <module name="MemberName" />
    <module name="MethodName" />
    <module name="PackageName">
      <property name="severity" value="error"/>
      <!-- no uppercase letters, at least 2 characters -->
      <property name="format" value="^pattern$" />
    </module>
    <module name="ParameterName" />
    <module name="StaticVariableName" />
    <module name="TypeName" />

    <!-- Checks for imports                              -->
    <!-- See http://checkstyle.sourceforge.net/config_import.html -->
    <module name="AvoidStarImport" />
    <module name="IllegalImport">
      <property name="severity" value="error"/>
      <property name="illegalPkgs" value="sun, com.objectspace.jgl" />
    </module>
    <module name="RedundantImport" />
    <module name="UnusedImports" />

    <module name="LineLength">
      <property name="max" value="120" />
      <property name="ignorePattern" value="^import"/>
    </module>
    <module name="MethodLength">
      <property name="max" value="300" />
      <property name="countEmpty" value="false" />
    </module>
    <module name="AnonInnerLength">
      <property name="max" value="50" />
    </module>
    <module name="ParameterNumber">
      <property name="max" value="25" />
      <property name="tokens" value="METHOD_DEF" />
    </module>

    <!-- Checks for whitespace                               -->
    <!-- See http://checkstyle.sourceforge.net/config_whitespace.html -->
    <module name="GenericWhitespace"/>
<!--
    <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"/>
-->

    <!-- Modifier Checks                                    -->
    <!-- See http://checkstyle.sourceforge.net/config_modifiers.html -->
    <module name="RedundantModifier" />

    <!-- Checks for blocks. You know, those {}'s         -->
    <!-- See http://checkstyle.sourceforge.net/config_blocks.html -->
    <module name="EmptyBlock">
      <property name="tokens" value="LITERAL_CATCH" />
      <!-- require a comment, change to stmt to require a statement -->
      <property name="option" value="text" />
    </module>
    <module name="LeftCurly" />
    <module name="NeedBraces">
      <property name="tokens" value="LITERAL_DO, LITERAL_FOR, LITERAL_WHILE, LITERAL_ELSE"/>
    </module>
    <module name="RightCurly" />
    <module name="AvoidNestedBlocks" />

    <!-- Checks for common coding problems               -->
    <!-- See http://checkstyle.sourceforge.net/config_coding.html -->
    <module name="CovariantEquals" />
    <module name="EmptyStatement" />
    <module name="EqualsHashCode">
      <property name="severity" value="error"/>
    </module>
    <module name="HiddenField">
      <property name="tokens" value="VARIABLE_DEF" />
    </module>
    <module name="IllegalInstantiation">
      <property name="severity" value="error"/>
      <property name="classes" value="java.lang.Boolean, java.lang.String" />
    </module>
<!--    <module name="IllegalType"/> -->
    <module name="InnerAssignment" />
    <module name="MissingSwitchDefault" />
    <module name="ModifiedControlVariable" />
<!-- get class not found errors in checkclipse
    <module name="RedundantThrows" />
-->
    <module name="SimplifyBooleanExpression" />
    <module name="SimplifyBooleanReturn" />
    <module name="StringLiteralEquality" />
    <module name="SuperClone" />
    <module name="SuperFinalize" />
    <module name="PackageDeclaration" />
    <module name="ParameterAssignment" />
    <module name="DefaultComesLast" />
    <module name="MultipleVariableDeclarations" />
    <module name="UnnecessaryParentheses" />
    <module name="FallThrough"/>

    <!-- Checks for class design                         -->
    <!-- See http://checkstyle.sourceforge.net/config_design.html -->
    <module name="VisibilityModifier">
      <property name="protectedAllowed" value="true" />
    </module>
    <module name="FinalClass" />
    <module name="InterfaceIsType" />
    <module name="HideUtilityClassConstructor" />
    <module name="MutableException" />

    <!-- Code metrics related checks -->
    <!-- http://checkstyle.sourceforge.net/config_metrics.html -->
    <module name="BooleanExpressionComplexity">
      <property name="max" value="15" />
    </module>

    <!-- Miscellaneous other checks.                   -->
    <!-- See http://checkstyle.sourceforge.net/config_misc.html -->
    <module name="ArrayTypeStyle" />
    <module name="UpperEll" />
    <module name="TrailingComment" />

    <!-- Check code usage related -->
    <!-- http://checkstyle.sourceforge.net/config_usage.html -->
    <!--
    <module name="usage.UnusedLocalVariable"/>
    <module name="usage.UnusedParameter">
      <property name="ignoreNonLocal" value="true" />
      <property name="ignoreFormat" value="args" />
    </module>
    <module name="usage.UnusedPrivateField">
      <property name="ignoreFormat" value="^(serialVersionUID|log|LOG)$"/>
    </module>
    <module name="usage.UnusedPrivateMethod" />
-->

    <!-- Avoid using System.out -->
    <module name="Regexp">
      <property name="format" value="System\.out\." />
      <property name="message" value="Use Log, not System.out"/>
      <property name="illegalPattern" value="true"/>
    </module>

    <!-- Avoid finalizers -->
    <!-- this will not find violations that contain linebreaks -->
    <module name="Regexp">
      <property name="severity" value="error"/>
      <property name="format" value="((public)|(protected))\s+void\s+finalize\(\s*\)" />
      <property name="illegalPattern" value="true"/>
    </module>

    <!-- Avoid old school banners -->
    <module name="Regexp">
      <property name="format" value="/{3,}" />
      <property name="message" value="Old-School banners not permitted"/>
      <property name="illegalPattern" value="true"/>
    </module>

    <!-- Catch default eclipse comments -->
    <module name="Regexp">
      <property name="format" value="TODO \w+ class comment" />
      <property name="message" value="Replace Eclipse default with real javadoc"/>
      <property name="illegalPattern" value="true"/>
    </module>
    <module name="Regexp">
      <property name="format" value="TODO Auto-generated \w+ stub" />
      <property name="message" value="Remove/Replace default Eclipse code generation todo/comment"/>
      <property name="illegalPattern" value="true"/>
    </module>

    <module name="Regexp">
      <property name="severity" value="error"/>
      <property name="format" value="SimpleDateFormat\s\w" />
      <property name="message" value="Use FastDateFormat instead, it's faster and thread-safe"/>
      <property name="ignoreComments" value="true"/>
      <property name="illegalPattern" value="true"/>
    </module>

    <module name="Regexp">
      <property name="severity" value="error"/>
      <property name="format" value="ApplicationProperties" />
      <property name="message" value="Use SDMSConfig instead"/>
      <property name="ignoreComments" value="true"/>
      <property name="illegalPattern" value="true"/>
    </module>

    <module name="Regexp">
      <property name="severity" value="error"/>
      <property name="format" value="HashCodeBuilder" />
      <property name="message" value="HashCodeBuilder does not perform well, use HashCodeUtil instead"/>
      <property name="ignoreComments" value="true"/>
      <property name="illegalPattern" value="true"/>
    </module>

    <module name="Regexp">
      <property name="severity" value="error"/>
      <property name="format" value="EqualsBuilder" />
      <property name="message" value="EqualsBuilder does not perform well, use EqualsUtil instead"/>
      <property name="ignoreComments" value="true"/>
      <property name="illegalPattern" value="true"/>
    </module>

    <module name="Regexp">
      <property name="severity" value="error"/>
      <property name="format" value="CompareToBuilder" />
      <property name="message" value="CompareToBuilder does not perform well, write your own instead, see http://www.javapractices.com/Topic10.cjp"/>
      <property name="ignoreComments" value="true"/>
      <property name="illegalPattern" value="true"/>
    </module>

    <module name="Regexp">
      <property name="severity" value="error"/>
      <property name="format" value="\.getMethod\(\)" />
      <property name="message" value="Do not vary logic based on HTTP Method, use separate View*/forward= and Save* actions instead"/>
      <property name="ignoreComments" value="true"/>
      <property name="illegalPattern" value="true"/>
    </module>

    <module name="TodoComment">
      <property name="format" value="FIXME"/>
    </module>

    <module name="NoFinalizer"/>    
    <module name="EqualsAvoidNull"/>    
    <module name="AvoidStaticImport"/>    
    <module name="NoClone"/>
    <module name="ClassTypeParameterName"/>
    <module name="MethodTypeParameterName"/>
    <module name="OuterTypeFilename"/>
    <module name="OneStatementPerLine"/>
    <module name="MissingDeprecated"/>
    <module name="AnnotationUseStyle"/>
    <module name="MissingDeprecated"/>
    <module name="MissingOverride"/>
    <module name="OuterTypeNumber"/>

  </module>
</module>


prenagha avatar Jan 20 '13 16:01 prenagha

Thank you. This, I fear, is also working perfectly here. I can edit the dir as required, and the value is saved.

I'm obviously missing something, so I'll keep playing...

jshiell avatar Jan 20 '13 17:01 jshiell

Plugin or something in idea appears to want to rewrite the xml all the time. I set the property manually as per above. Now it shows up on diff repeatedly along with the case change on the file token. Anything I can do to keep this from showing a a version control diff over and over?

The left side is the manual xml change that i checked in. The right side is was the plugin/idea has rewritten it to.

Screen Shot 2013-01-29 at 10 59 32 AM

prenagha avatar Jan 29 '13 15:01 prenagha

Someone else has raised this as #59 (file:// case keeps changing). 'tis the next thing on my list of todos.

jshiell avatar Jan 29 '13 16:01 jshiell

ok, and looks like changing the property to add the relative path is causing me a problem - don't want that checked in since it is project dir specific, would like to just keep the $PROJECT_DIR reference as the property value so it is portable

prenagha avatar Jan 29 '13 16:01 prenagha

I have a similar problem, but I cannot even add any properties as shown in the screenshots. Did anything change for IDEA 13?

windmueller avatar Aug 11 '14 13:08 windmueller

I use 13 myself, and I fear it's working for me. The plugin was changed quite a while ago so you're forced to enter values for all properties when adding a file. However, it'll only list properties that are defined in the rules file already (i.e. you can't define extra properties in the plugin, and then alter the file to use them).

jshiell avatar Aug 11 '14 13:08 jshiell

Ah, I see, the existing property values already provided what I intended to do, no need to specify the base-dir. Thanks for the quick reply!

windmueller avatar Aug 11 '14 13:08 windmueller