Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Install checkstyle plugin: https://plugins.jetbrains.com/plugin/1065-checkstyle-idea
    • File →  Settings →  Plugins
    • Restart IDE
  • Configure it to use our custom checkstyle.xml
    • File →  Settings →  Checkstyle
    • Add a "Configuration File" (press the + in the table). Select our checkstyle.xml
    • Make it "Active"
    • Click Apply
  • Update IDEA's Code Style to obey the Checkstyle Rules (See also https://stackoverflow.com/a/35273850/3750035)
    • File → Settings → Editor → Code Style
    • Click the small gear icon next to "Scheme", Select "Import Scheme" → CheckStyle Configuration
    • Select our checkstyle.xml
    • Click OK
    • Click Apply
  • Update IDEA's Java code style to align with a few specific CheckStyle rules (which don't seem to be auto updated per previous step)
    • First, order import statements per our rules
      • File → Settings → Editor → Code Style → Java → Imports
      • In the "Import Layout" section, ensure  the settings are in this order
        • "import static all other imports"
        • <blank line>
        • "import java.*"
        • "import javax.*"
        • <blank line>
        • "import all other imports"
      • Once reordered, click OK
    • Then, update to auto-wrap lines at the right margin
      • File → Settings → Editor → Code Style → Java → Wrapping and Braces
      • CHECK "Ensure right margin is not exceeded"
      • Click OK
  • Update IDEA's Javadoc settings to not insert "<p>" on blank Javadoc lines (as this will cause IDEA to change all our DSpace license headings improperly)
    • File → Settings → Editor → Code Style → Java → JavaDoc
    • UNCHECK "Generate <p> on empty lines"
    • Make sure "Keep empty lines" is checked
    • Click OK
  • Now open up any Java source file. You'll see Checkstyle warnings appear (if any) in RED
  • Select "Code -> Reformat Code" (Ctrl + Alt + L) to reformat the open source file based on Checkstyle rules.
    • If any import statements use an asterisk, you will also need to do "Code -> Optimize Imports" (Ctrl + Alt + O) to correct those.
  • NOTE: You can also reformat code in bulk in IDEA: https://www.jetbrains.com/help/idea/editor-basics.html#reformat_rearrange_code
    • Right click on a single directory / module
    • Select "Reformat Code"
      • Check "Optimize imports"  (This will remove any import statements with an asterisk)
      • Leave "Rearrange entries" unchecked (This will rearrange methods/variables based on arrangement settings in IDEA. We don't need this)
      • Under "Filters" → Check "File Masks" and enter in "*.java, *.xml"  (As we'll only reformat Java and XML files)
      • Click Run
  • Finally, run Checkstyle against the module. There likely will still be a few failures to fix manually.

    Code Block
    mvn install
    mvn -U checkstyle:check