如何将自定义JAR添加到“eclipse-pmd”插入? [英] How to Add custom JAR to the "eclipse-pmd" plugin?
问题描述
从 Eclipse PMD插件 (由Philip Graf撰写) / eclipse-pmd /rel =nofollow noreferrer>这里。我试图关联一个自定义的PMD规则类JAR,但找不到一个规定。此JAR包含自定义规则类(即间接扩展AbstractJavaRule
)。
所以有什么办法配置> eclipse-pmd 插件来接受这个自定义JAR?
我的 custompmd.jar
有这个结构:
custompmd.jar
└─com/ pmd / custom
  ; └─AvoidHardcodingRule.class
└─AvoidCatchWithoutLogErrorRule.class
└ ─etc...
只需将其放在 plugins
目录中即可帮帮我。 SO问题之一提出了一种解决方案,但这是一种不同的 插件。
[更新]
我正在考虑编辑 eclipse\\ \\ plugins\ch.acanda.eclipse.pmd.BLAHBLAH.jar
,将 custompmd.jar
添加到 lib
文件夹,并通过在 Bundle-ClassPath:部分中附加JAR信息来更新 META-INF \MANIFEST.MF
。是否正确的做法是修补插件JAR对我来说似乎很丑陋?
[更新]
以上方法没有工作。
你们任何一个Eclipse大师都知道如何解决它?
[更新]
我自己破解了。
[更新]
虽然下面的解决方案是有效的,但这是一个维护噩梦。每当我更改 custompmd.jar
时,我必须每次更新插件JAR,这是乏味的。有没有一个干净整洁的解决方案?
如果将jar添加为Eclipse插件,则可以使用自定义规则类,分段到Eclipse安装。插件片段的主机必须是 ch.acanda.eclipse.pmd.core
。
要转换该jar到一个插件片段,你必须修改文件 MANIFEST.MF
文件并添加几个清单标题。以下是Eclipse插件片段的完整清单:
Manifest-Version:1.0
Bundle-ManifestVersion :2
Bundle-Name:自定义PMD规则
Bundle-SymbolicName:org.example.customrules
Bundle-Version:1.0.0
Fragment-Host:ch.acanda.eclipse .pmd.core; bundle-version =1.4.1
Bundle-RequiredExecutionEnvironment:JavaSE-1.7
您可以为标题 Bundle-Name
, Bundle-SymbolicName
和捆绑-版
。标题 Bundle-ManifestVersion
的值必须为 2
。 Fragment-Host
必须包含主机束的符号名称 ch.acanda.eclipse.pmd.core
,并且可选地您已安装的eclipse-pmd版本。 Bundle-RequiredExecutionEnvironment
指定插件片段所需的最小执行环境。如果您使用Java 8或$ code> JavaSE-1.8 如果您使用Java 8,则它的值为 JavaSE-1.7
/ p>
一旦您更改了您的jar的清单,您可以将其复制到eclipse安装的文件夹 dropins
中。您的插件片段在启动Eclipse时已安装。
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:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Custom PMD Rules
Bundle-SymbolicName: org.example.customrules
Bundle-Version: 1.0.0
Fragment-Host: ch.acanda.eclipse.pmd.core;bundle-version="1.4.1"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
You can choose your own values for the headers Bundle-Name
, Bundle-SymbolicName
and Bundle-Version
. The value of the header Bundle-ManifestVersion
must be 2
. Fragment-Host
must contain the symbolic name of the host bundle ch.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 is JavaSE-1.7
if you compiled it with Java 7 or JavaSE-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.
这篇关于如何将自定义JAR添加到“eclipse-pmd”插入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!