[英]How to Add custom JAR to the “eclipse-pmd” plugin?
Installed the Eclipse PMD plugin (written by Philip Graf ) from here . 从这里安装了Eclipse PMD插件 (由Philip Graf编写)。 I tried to associate a custom PMD rule classes JAR but couldn't find a provision for it.
我尝试关联自定义PMD规则类JAR但无法找到它的规定。 This JAR contains custom rule classes (that
extends AbstractJavaRule
indirectly). 此JAR包含自定义规则类(间接
extends AbstractJavaRule
)。
So is there any way to configure eclipse-pmd plugin to accept this custom JAR? 那么有没有办法配置eclipse-pmd插件来接受这个自定义JAR?
My custompmd.jar
has this structure: 我的
custompmd.jar
有这样的结构:
custompmd.jar
custompmd.jar
└─com/pmd/custom└─com/ PMD /自定义
└─AvoidHardcodingRule.class└─AvoidHardcodingRule.class
└─AvoidCatchWithoutLogErrorRule.class└─AvoidCatchWithoutLogErrorRule.class
└─etc...└─etc...
Simply putting it in plugins
directory didn't help. 简单地将它放在
plugins
目录中没有帮助。 One of the SO question suggests a solution but that's for a different plugin . 其中一个问题提出了一个解决方案,但这是针对不同的 插件 。
[UPDATE] [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. 我目前正在考虑编辑其中一个
eclipse\\plugins\\ch.acanda.eclipse.pmd.BLAHBLAH.jar
,将custompmd.jar
添加到lib
文件夹中,并通过在JAR信息中附加JAR信息来更新META-INF\\MANIFEST.MF
文件。 Bundle-ClassPath:部分。 Is it the right practice as patching the plugin JAR seems ugly to me? 这是正确的做法,因为修补插件JAR对我来说似乎很丑陋吗?
[UPDATE] [UPDATE]
The above approach didn't work. 上述方法不起作用。
Any of you Eclipse gurus know how to crack it? 你们中的任何一个Eclipse大师都知道如何破解它?
[UPDATE] [UPDATE]
I cracked it by myself. 我自己解决了这个问题。
[UPDATE] [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. 每当我更改
custompmd.jar
,我每次都必须更新插件JAR,这很乏味。 Is there a clean and neat solution? 有干净整洁的解决方案吗?
(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). (我应该在我之前的尝试中使用它,但是由于ANT任务失败而导致
custompmd.jar
过时,但是那段时间不起作用)。
Step-by-step: 一步步:
ch.acanda.eclipse.pmd.core_<blahblah#>.jar
from plugins
directory into a temp directory. ch.acanda.eclipse.pmd.core_<blahblah#>.jar
从plugins
目录复制到临时目录中。 custompmd.jar
into the lib
directory. custompmd.jar
添加到lib
目录中。 META-INF/MANIFEST.MF
file, append this string ,lib/custompmd.jar
at the end of Bundle-Classpath:
META-INF/MANIFEST.MF
文件,在Bundle-Classpath:
末尾附加此字符串,lib/custompmd.jar
Bundle-Classpath:
/plugins/ch.acanda.eclipse.pmd.core_<blahblah#>.jar
and replace it with this temp jar. /plugins/ch.acanda.eclipse.pmd.core_<blahblah#>.jar
并将其替换为此临时jar。 You can use your custom rule classes if you add your jar as an Eclipse plug-in fragment to your Eclipse installation. 如果将jar作为Eclipse插件片段添加到Eclipse安装中,则可以使用自定义规则类。 The host of the plug-in fragment must be
ch.acanda.eclipse.pmd.core
. 插件片段的主机必须是
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. 要将jar转换为插件片段,您必须修改文件
MANIFEST.MF
文件并添加一些清单头。 The following is a complete manifest of an Eclipse plug-in fragment: 以下是Eclipse插件片段的完整清单:
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
. 您可以为标题
Bundle-Name
, Bundle-SymbolicName
和Bundle-Version
选择自己的值。 The value of the header Bundle-ManifestVersion
must be 2
. 标头
Bundle-ManifestVersion
的值必须为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. Fragment-Host
必须包含主机包的符号名称ch.acanda.eclipse.pmd.core
以及您已安装的eclipse-pmd的版本。 Bundle-RequiredExecutionEnvironment
specifies the minimum execution environment the plug-in fragment requires. Bundle-RequiredExecutionEnvironment
指定插件片段Bundle-RequiredExecutionEnvironment
的最小执行环境。 Its value is JavaSE-1.7
if you compiled it with Java 7 or JavaSE-1.8
if you used Java 8. 如果使用Java 8编译它,则使用Java 7或
JavaSE-1.8
编译它的值为JavaSE-1.7
。
Once you changed the manifest of your jar you can copy it into the folder dropins
of your eclipse installation. 更改jar的清单后,可以将其复制到eclipse安装的文件夹
dropins
中。 Your plug-in fragment is installed when you start Eclipse. 启动Eclipse时会安装插件片段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.