Versions Compared

Key

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

...

  • Install the IntelliJ IDEA checkstyle plugin: https://plugins.jetbrains.com/plugin/1065-checkstyle-idea
    • File →  Settings →  Plugins
    • Restart IDE
  • Configure it to use our custom checkstyle.xml for DSpace
    • File →  Settings →  Checkstyle
      • In older versions of IntelliJ, this menu may be under File → Settings → Other 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
  • After importing the Checkstyle settings, your "Copyright profiles" may get reset (if you had them previously configured).  If you want IntelliJ to automatically add a copyright statement / license at the top of every Java class, you should ensure this is (re)configured:
    • File → Settings → Editor → Copyright 
    • Add a Copyright profile.  If you wish to use the DSpace copyright/license statement, the text of it is available in the LICENSE_HEADER file in the codebase (or see the Code Style Guide above)
    • Select the profile from the list, and adjust the formatting (unchecking the option "Add blank line after")
  • Optionally, you also may wish to change some default IntelliJ settings, to allow the IDE to automatically reformat code for you (when making bulk edits). This is especially important if you plan to do any bulk cleanup of existing code using IntelliJ tools
    • First, fix the default order import statements per our CheckStyle rules (these don't seem to be auto updated by the Checkstyle plugin at this time)
      • 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
    • Then, OPTIONALLY, for better looking bulk reformatting (i.e. results in more human-readable code), you may want to tweak which types of statements are set to "Wrap if long" 
      • (NOTE: Without these settings, IDEA's bulk "Reformat Code" option sometimes will generate line breaks wherever the line ends, which can result in somewhat odd looking code. These settings cleanup some of the more odd line wrappings that may occur.)
      • File → Settings → Editor → Code Style → Java → Wrapping and Braces
      • Optionally, set all of the following to "Wrap if long":
        • Extends/implements list (also check "align when multiline")
        • Extends/implements keyword
        • Throws list
        • Throws keyword
        • Method declaration parameters (also check "align when multiline")
        • Method call arguments (also check "align when multiline")
        • Chained method calls (also check "align when multiline")
        • "for()" statement (also check "align when multiline")
        • "try-with-resources" (also check "align when multiline")
      • Click OK
    • Finally, update IDEA's Javadoc settings to not insert "<p>" on blank Javadoc lines (as this seems to cause IDEA to change all our DSpace license headings improperly during bulk editing)
      • File → Settings → Editor → Code Style → Java → JavaDoc
      • UNCHECK "Generate <p> on empty lines"
      • Make sure "Keep empty lines" is checked
      • Click OK

Eclipse

These instructions were created using Eclipse Neon.  Note: Eclipse Che (Codenvy) does not seem to support checkstyle.

  • Use the Eclipse Checkstyle plugin: http://eclipse-cs.sourceforge.net/
    • Note that you can drag the plugin into your Eclipse installation
  • Right click your DSpace project; select Properties → Checkstyle
  • Go to "Checkstyle → Local check configurations" and click "New"
    • Create a "Project Relative Configuration"
    • Name: DSpace Internal
    • Location: checkstyle.xml
  • An "Unresolved Properties Error" box will appear; click "Edit Properties"
    • Add a new property
      • Name: checkstyle.suppressions.file
      • Value: checkstyle-suppressions.xml
    • Click OK
  • Go to "Checkstyle → Main"
    • Select "DSpace Internal" from the drop down
    • Check "Checkstyle active for this project"
    • Click OK
  • Code will be rebuilt
  • Edit a java file.  Place a curly brace on a line by itself.
    • The line of code should get highlighted in red.

...