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 VIVO/Vitro
    • File →  Settings → Tools → 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 VIVO/Vitro 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.*"
        • <blank line>
        • "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 
      • File → Settings → Editor → Code Style → Java → JavaDoc
      • UNCHECK "Generate <p> on empty lines"
      • Make sure "Keep empty lines" is checked
      • Click OK
  • Application of code style
    • Common shortcut for organizing imports is ctrl+alt+o
    • Common shortcut for code reformatting is ctrl+alt+l
Eclipse

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

  • Use the Eclipse Checkstyle plugin: https://checkstyle.org/eclipse-cs/#!/
    • Note that you can drag the plugin into your Eclipse installation
  • Right click your VIVO/Vitro project; select Properties → Checkstyle
  • Go to "Checkstyle → Local check configurations" and click "New"
    • Create a "Project Relative Configuration"
    • Name: Vitro Internal
    • Location: checkstyle.xml
  • An "Unresolved Properties Error" box will appear; click "Edit Properties"
    • Add a new property
      • Name: checkstyle.suppressions.file
      • Value: full path to checkstyle-suppressions.xml
    • Click OK
  • Go to "Checkstyle → Main"
    • Select "Vitro 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.

...

2022-03.

  • Apply Java Formatter configuration and imports order for workspace or project
    • For workspace
    • For project
      • Right click on the project, click on Properties.
      • In new window select on the left Java Code Style → Formatter.
      • Mark checkbox Enable project specific settings
      • Click "Import..." select VIVO and Vitro formatter profile.xml
      • Select Java → Code Style → Organize Imports.
      • Mark checkbox Enable project specific settings
      • Click "Import..." select vivo-vitro.importorder
NetBeans

These instructions worked for NetBeans 8.2.

...