Skip to content

IntelliJ IDEA specific development instructions

Cedric Bosdonnat edited this page Sep 24, 2021 · 12 revisions

Get started

  • download IntelliJ IDEA Community from the official site, tarball with bundled JDK for Linux

  • mseidl recommends using the jb toolbox(https://www.jetbrains.com/toolbox/) if you use this to install it, it makes upgrading easier. intellij cannot upgrade it self, nor can you upgrade by untarring the new version. But the toolbox makes upgrades easy.

  • create the file ~/.IntelliJIdea*/config/idea64.vmoptions with -Xmx4G

  • run bin/idea.sh and go through the installation wizard

  • click on Import Project, select the spacewalk directory

  • select Create project from existing sources

  • accept project format defaults and auto-discovered source directories by clicking Next

  • from the Libaries list, uncheck all items

  • from the Modules list, only check the items corresponding to the following directories:

    • spacewalk/java/code (change the name to code)
    • spacewalk/branding/java/code (change the name to branding)
  • add an appropriate JDK location (1.8 for 3.0 and 3.1) and click on Finish

  • enable automatic building:

    • click on File -> Settings... -> Build, Execution, Deployment -> Compiler and flag Build project automatically
  • configure import organization rules consistent with the project:

    • click on File -> Settings... -> Editor -> Code Style -> Java -> Imports

Either click on the cog icon > Import Scheme > IntelliJ IDEA code style XML and select the <repo_root>/java/conf/intellij-codestyle.xml file, or do the following changes:

 - check *Use single class import*
 - check *Layout static imports separately*
 - edit the *Import Layout* list to contain:
   - *import static all other imports*
   - *`<blank line>`*
   - *import com.redhat.rhn.**
   - *`<blank line>`*
   - *import com.suse.**
   - *`<blank line>`*
   - *import com.**
   - *`<blank line>`*
   - *import org.**
   - *`<blank line>`*
   - *import java.**
   - *`<blank line>`*
   - *import javax.**
   - *`<blank line>`*
   - *import all other imports*

Run JUnit tests

  • click on File -> Project Structure... -> Modules -> code -> Dependencies -> + -> Module dependency -> branding -> OK to include branding classes and files in the build
  • click on File -> Project Structure... -> Modules -> code and mark the directory webapp as Resources
  • click on Run -> Edit Configurations... -> Defaults -> JUnit and edit the form on the right hand side panel
  • if you need to limit the tests to be run to a package, add the package name in Package:
  • select In single module
  • add the following VM options: -ea -Drhn.config.dir=$MODULE_DIR$/../buildconf/test/ -Dlog4j.threshold=debug
  • click OK
  • click on Run -> Run:

Debugging

  • to debug a remote instance:
    • click on Run -> Edit Configurations... -> + sign. Accept all defaults apart from Host and Port:
      • 8000 for Tomcat, 8001 for Taskomatic, 8002 for Search by default on sumaform

Ivy integration

  • click on File -> Settings... -> Plugins -> Browse repositories... -> type "IvyIDEA" -> Install to install the Ivy plugin
    • click on Restart IntelliJ IDEA to activate the plugin
    • click on File -> Project Structure... -> Modules -> right click on code -> + -> ivyIDEA to enable the plugin for the project
    • click on ... (top) to select the Ivy configuration path: spacewalk/java/buildconf/ivy/ivy-suse.xml
    • flag Use module specific ivy settings
    • click on ... (bottom) to select the Ivy configuration path: spacewalk/java/buildconf/ivy/ivyconf.xml
  • click on Tools -> IvyIDEA -> Resolve for all modules to get updated Ivy dependencies

When switching branches that have different dependencies (notably, major versions) you will have to click on:

  • Tools -> IvyIDEA -> Remove all resolved libraries
  • Tools -> IvyIDEA -> Resolve for all modules
  • Build -> Rebuild project

CheckStyle integration

  • click on File -> Settings... -> Plugins -> Browse repositories... -> type "CheckStyle-IDEA" -> Install to install the CheckStyle plugin
  • click on Restart IntelliJ IDEA to activate the plugin
  • click on File -> Settings... -> Other Settings -> Checkstyle and change Checkstyle version to the version in buildconf/ivy/ivy-suse.xml (currently 8.30), click on Apply
  • click on the + sign next to Configuration File
    • Description: SUSE Manager
    • select Use a local Checkstyle file, select spacewalk/java/buildconf/checkstyle.xml
    • flag Store relative to project location, click on Next
    • set the following values for properties:
      • checkstyle.cache.file: <PATH_TO>/spacewalk/java/build/checkstyle.cache.src
      • checkstyle.header.file: <PATH_TO>/spacewalk/java/buildconf/LICENSE.txt
      • javadoc.lazy: false
      • javadoc.method.scope: public
      • javadoc.type.scope: package
      • javadoc.var.scope: package
    • click on Finish, then flag the file as Active, then click on Apply one more time
    • one new mini-tab will appear at the bottom of the screen with options

Further settings to avoid CheckStyle violations

These are recommended IDE settings that help respecting style guidelines independent of the CheckStyle plugin:

  • enabling automatic import completion: click on File -> Settings... -> Editor -> General -> Auto Import -> Insert imports on paste: -> select All. On the same form, check Add unambiguous imports on the fly and Optimize imports on the fly (for current project)
  • disabling "star imports": click on File -> Settings... -> Editor -> Code Style -> Java -> Imports -> Class count to use import with '*' -> 999 and Names count to use static import with '*' -> 999
  • wrapping and braces: Settings... -> Editor -> Code Style -> Java -> Wrapping and Braces. Under 'try' statement check 'catch' on new line and 'finally' on new line; under 'if' statement check 'else' on new line

Faster deployments via manager-build.xml

  • change the output directory to enable quick manager-build.xml deploys:
    • click on File -> Project Structure... -> Modules -> code -> Paths, click on Use module compile output path and set:
    • Output path to spacewalk/java/build/classes
    • Test output path to spacewalk/java/build/tests
  • grab Ivy dependencies in the spacewalk/lib directory: ant -f manager-build.xml ivy
  • enable precompiled file use by adding a precompiled=true line in buildconf/manager-developer-build.properties (e.g. make a copy of buildconf/manager-developer-build.properties.example, then rename and edit the new file).

Issues

All imports red? Try any the following:

File -> Synchronize
File -> Invalidate caches / Restart

Tips

IntelliJ-Idea-tips

Clone this wiki locally