Installed the Eclipse PMD plugin (written by Philip Graf) from here. I tried to associate a custom PMD rule classes JAR but couldn't find a provision for it. This JAR contains custom rule classes (that extends AbstractJavaRule
indirectly).
So is there any way to configure eclipse-pmd plugin to accept this custom JAR?
My custompmd.jar
has this structure:
custompmd.jar
└─com/pmd/custom
└─AvoidHardcodingRule.class
└─AvoidCatchWithoutLogErrorRule.class
└─etc...
Simply putting it in plugins
directory didn't help. One of the SO question suggests a solution but that's for a different plugin.
[UPDATE]
I am currently thinking of editing one of the eclipse\plugins\ch.acanda.eclipse.pmd.BLAHBLAH.jar
, add custompmd.jar
into the lib
folder and updating META-INF\MANIFEST.MF
file by appending the JAR information in the Bundle-ClassPath: section. Is it the right practice as patching the plugin JAR seems ugly to me?
[UPDATE]
The above approach didn't work.
Any of you Eclipse gurus know how to crack it?
[UPDATE]
I cracked it by myself.
[UPDATE]
Although the below solution works, it is a maintenance nightmare. Whenever, I change the custompmd.jar
, I have to update the plugin JAR as well everytime, which is tedious. Is there a clean and neat solution?
You can use your custom rule classes if you add your jar as an Eclipse plug-in fragment to your Eclipse installation. The host of the plug-in fragment must be
ch.acanda.eclipse.pmd.core
.To convert the jar to a plug-in fragment you have to modify the file
MANIFEST.MF
file and add a few manifest headers. The following is a complete manifest of an Eclipse plug-in fragment:You can choose your own values for the headers
Bundle-Name
,Bundle-SymbolicName
andBundle-Version
. The value of the headerBundle-ManifestVersion
must be2
.Fragment-Host
must contain the symbolic name of the host bundlech.acanda.eclipse.pmd.core
and optionally the version of eclipse-pmd you have installed.Bundle-RequiredExecutionEnvironment
specifies the minimum execution environment the plug-in fragment requires. Its value isJavaSE-1.7
if you compiled it with Java 7 orJavaSE-1.8
if you used Java 8.Once you changed the manifest of your jar you can copy it into the folder
dropins
of your eclipse installation. Your plug-in fragment is installed when you start Eclipse.Finally figured it out myself !
(I should've got it working in my previous attempt itself, but due to a stale
custompmd.jar
because of failed ANT task, it didn't work that time).Step-by-step:
ch.acanda.eclipse.pmd.core_<blahblah#>.jar
fromplugins
directory into a temp directory.custompmd.jar
into thelib
directory.META-INF/MANIFEST.MF
file, append this string,lib/custompmd.jar
at the end ofBundle-Classpath:
/plugins/ch.acanda.eclipse.pmd.core_<blahblah#>.jar
and replace it with this temp jar.