eclipseeclipse-plugincheckstyle

How to make my own custom checkstyle checks available in eclipse checkstyle plug-in


I want to have my own check "check that method identifier of class X is not longer than 18 chars". I want eclipse to show violations to my custom rule in the IDE as warning or error.

However I cannot seem to install the custom eclipse plugin anymore...

I started by checking out the net.sf.eclipsecs.sample project which uses the eclipse extension point "net.sf.eclipsecs.core.checkstyleAddonProvider" so that it can contribute checks to the eclipse checkstyle plugin.

Without changing anything I exported it as deployabe plug-in and put the resulting jar in my eclipse's dropins folder. The plugin worked and I saw the MethodLimitCheck (from the sample project) in the UI of the eclipse checkstyle plugin's preferences page.

However I wanted to have my own rule active so I decided to add my own subclass of AbstractCheck and made the necessary changes to the configuration files. But nothing changed. I decided to remove the installed plugin and install a new export again and since then I was no longer able to install any custom check. I reverted the sample project to its original state and tried to install it again, but no change can be seen in the eclipse checkstyle plugin's UI anymore.

How can I debug why eclipse doesn't install my plug-in anymore? I see nothing in the Error Log or in the /.metadata/.log

When I try to install the plugin via osgi host console via "install file:///plugin.jar" and "start " it has the status "ACTIVE", but I guess it cannot make changes to the UI once it was loaded. I always start eclipse with "-clean -debug" having set debug options in .options file

[p2] Fri Mar 22 11:09:41 CET 2024 - [Start Level: Equinox Container: 35fb4e67-0f72-47e8-81fe-24cd62603c7f] [reconciler] Adding IU: net.sf.eclipsecs.sample 10.14.1.202403211910-unmodified
[p2] Fri Mar 22 11:09:41 CET 2024 - [Start Level: Equinox Container: 35fb4e67-0f72-47e8-81fe-24cd62603c7f] [reconciler] Adding IU property: net.sf.eclipsecs.sample 10.14.1.202403211910-unmodified->{org.eclipse.equinox.p2.type.lock=1, org.eclipse.equinox.p2.internal.inclusion.rules=OPTIONAL, org.eclipse.equinox.p2.reconciler.dropins=true}
[p2] Fri Mar 22 11:09:41 CET 2024 - [Start Level: Equinox Container: 35fb4e67-0f72-47e8-81fe-24cd62603c7f] [reconciler] No installable units to remove.
[p2] Fri Mar 22 11:09:41 CET 2024 - [Start Level: Equinox Container: 35fb4e67-0f72-47e8-81fe-24cd62603c7f] [reconciler] No IU properties to remove.
[p2] Fri Mar 22 11:09:41 CET 2024 - [Start Level: Equinox Container: 35fb4e67-0f72-47e8-81fe-24cd62603c7f] [reconciler] No installable units to move.
[p2] Fri Mar 22 11:09:41 CET 2024 - [Start Level: Equinox Container: 35fb4e67-0f72-47e8-81fe-24cd62603c7f] [reconciler] No extra requirements.
[p2] Fri Mar 22 11:09:42 CET 2024 - [Start Level: Equinox Container: 35fb4e67-0f72-47e8-81fe-24cd62603c7f] [reconciler] [plan] [R]net.sf.eclipsecs.sample 10.14.1.202403212020 will be removed
[p2] Fri Mar 22 11:09:42 CET 2024 - [Start Level: Equinox Container: 35fb4e67-0f72-47e8-81fe-24cd62603c7f] [reconciler] [plan] [R]net.sf.eclipsecs.sample 10.14.1.202403212020 will be added
[p2] Fri Mar 22 11:09:42 CET 2024 - [Start Level: Equinox Container: 35fb4e67-0f72-47e8-81fe-24cd62603c7f] [reconciler] [plan] Some units will not be installed, because they are already installed or there are dependency issues:
[p2] Fri Mar 22 11:09:42 CET 2024 - [Start Level: Equinox Container: 35fb4e67-0f72-47e8-81fe-24cd62603c7f] [reconciler] [plan] net.sf.eclipsecs.sample 10.14.1.202403211910-unmodified

Help, writing custom checks shouldn't be this hard :(

Eclipse 2024-03 (4.31.0) Eclipse Checkstyle Project 10.14.1.202403151842 (installed via Marketplace) Mac OS 14.4


Solution

  • I reinstalled eclipse. One grave mistake I was making was that I was deleting files from the file system, e.g. from the dropins directory.

    What now works for me is the following development workflow to update my custom checkstyle checks:

    1. uninstall my plugin from the "Eclipse IDE Installation Details" dialog via the "Uninstall..." button
    2. restart eclipse
    3. develop the eclipse checkstyle check plugin and increase the version numer in the
    4. export it as deployable plugin and choose the option to "install into host installation" in the export
    5. the export wizard will prompt you to restart eclipse, so restart eclipse

    Now the plugin is active and contributes the new checkers, now you need to go to the Checkstyle Preferences and "Copy" the built-in Check Configuration so you have a mutable config. Edit the copied configuration by removing all checks you don't need and only add your custom checks.

    Whenever an error occured, error log hat a pretty good hint on what went wrong.

    Another big mistake I was making was that on Mac OS I had several Eclipse installations and my Eclipse installation was named "Eclipse 4". This space threw the eclipse checkstyle plugin off and caused issues. Make sure to not have spaces in the name.

    And whatever you do: don't manually edit or remove plugins from eclipse. Only do it via p2, even if you placed files in the dropins directory.