简体   繁体   English

Eclipse-PMD 全局配置规则集

[英]Eclipse-PMD Configure ruleset globally

So i am using the Plugin Eclipse-PMD ( http://sourceforge.net/projects/pmd/files/pmd-eclipse/update-site/ ) in a shared version control enviroment.所以我在共享版本控制环境中使用插件 Eclipse-PMD ( http://sourceforge.net/projects/pmd/files/pmd-eclipse/update-site/ )。

We have multiple smaller projects in the entire project.我们在整个项目中有多个较小的项目。

Out of the box it seems that this plugin requires individual configuration for every single project.开箱即用,这个插件似乎需要为每个项目单独配置。 The way it works it that it searched for a .pmd file in the project and read information from that.它的工作方式是在项目中搜索 .pmd 文件并从中读取信息。

But it's really inconvenient to do that for 10-20 subprojects.但是对于10-20个子项目这样做真的很不方便。

There is a general setting under Preferences -> PMD. Preferences -> PMD 下有一个通用设置。 But this doesn't seem to apply globally, even if that global checkbox is checked.但这似乎不适用于全局,即使选中了全局复选框。

What i basically want: I want to configure the plugin to respect a single ruleSet-file in one place.我基本上想要的是:我想将插件配置为在一个地方尊重单个规则集文件。

There is another problem with configuring it subproject-specific: I cannot configure a relative path for the ruleSetFile in the .pmd-file.配置它特定于子项目还有另一个问题:我无法为 .pmd 文件中的 ruleSetFile 配置相对路径。 The problem with absolute path is that the file is checked into version control ... so with every commit everyone else would have to readjust.绝对路径的问题是文件被检入版本控制......所以每次提交时,其他人都必须重新调整。 I found this commit: https://github.com/pmd/pmd/pull/36 but i cannot seem to make it work the way it's roughly described.我发现了这个提交: https : //github.com/pmd/pmd/pull/36但我似乎无法让它按照粗略描述的方式工作。

So, did anyone achieve what i am looking for?那么,有没有人实现我正在寻找的东西?

Edit: Actually i cannot even specify any other file that is not ".ruleset" in the .pmd-file as <ruleSetFile> without specifying an absolute path ??编辑:实际上我什至无法在 .pmd 文件中将任何其他不是“.ruleset”的文件指定<ruleSetFile>而不指定绝对路径??

The default value for ruleSetFile is ".ruleset". ruleSetFile 的默认值为“.ruleset”。 So i thought, analogous to that, i could create a file in the exact same dir , call it fooRules.xml, and specify it via <ruleSetFile>fooRules.xml</ruleSetFile> but it can only find it if put the entire path to fooRules.xml in there?!所以我想,与此类似,我可以在完全相同的目录中创建一个文件,将其命名为 fooRules.xml,并通过<ruleSetFile>fooRules.xml</ruleSetFile>指定它,但它只能在放置整个路径时才能找到它到 fooRules.xml 里面?!

Try eclipse-pmd (available in the Eclipse marketplace or via the update site http://www.acanda.ch/eclipse-pmd/release/latest ).尝试eclipse-pmd (可在 Eclipse 市场或通过更新站点http://www.acanda.ch/eclipse-pmd/release/latest )。 With eclipse-pmd you can configure your projects to use a single rule set file for several projects.使用 eclipse-pmd,您可以将项目配置为对多个项目使用单个规则集文件。 It also stores its path relative to the workspace.它还存储其相对于工作区的路径。 You still have to configure each project individually though (for now, this will change in a future release).不过,您仍然需要单独配置每个项目(目前,这将在未来版本中更改)。

To set up eclipse-pmd in the way you described you have to open the project properties of your first project, select the "PMD" property page and add the rule set.要按照您描述的方式设置 eclipse-pmd,您必须打开第一个项目的项目属性,选择“PMD”属性页面并添加规则集。 Select the rule set type "Workspace" and pick your rule set file.选择规则集类型“工作区”并选择您的规则集文件。 For every other project you have to open the project's PMD property page where you'll find the previously selected rule set file which simply needs to be checked to activate.对于每个其他项目,您必须打开项目的 PMD 属性页面,您将在其中找到之前选择的规则集文件,只需选中即可激活。

If you set it up this way there will be a .eclipse-pmd file in each project containing the settings.如果以这种方式进行设置,则每个项目中都会有一个包含设置的.eclipse-pmd文件。 If you check this into your version control system then no one else in your team has to set up anything (apart from installing eclipse-pmd).如果您将其检查到您的版本控制系统中,那么您团队中的其他人无需进行任何设置(除了安装 eclipse-pmd)。

Disclaimer: I wrote eclipse-pmd.免责声明:我写了 eclipse-pmd。 Mostly because I had the exact same problems as you with the other plugin.主要是因为我在使用其他插件时遇到了与您完全相同的问题。

I've been struggling a long time to get this working with PMD for Eclipse .我一直在努力让它与PMD for Eclipse一起工作。 While Eclipse-PMD has this feature built-in, I had some other issues with it (eg I think it is not meant to create reports).虽然Eclipse-PMD内置了此功能,但我遇到了一些其他问题(例如,我认为它不是用来创建报告的)。

The trick was adding the rules to the project as a link .诀窍是将规则作为链接添加到项目中。

Create the rule file, eg pmd.xml, in the parent folder of the project.在项目的父文件夹中创建规则文件,例如 pmd.xml。 Add the file to the projects to be checked, but add it as a reference.将文件添加到要检查的项目中,但将其添加为参考。 Therefore, drag the file from the explorer to the bundle and select:因此,将文件从资源管理器拖到包中并选择:

文件操作对话框

In the project properties, in the PMD section, check Enable PMD and Apply and Close the settings.在项目属性的PMD部分,选中启用 PMD应用并关闭设置。

Now close Eclipse.现在关闭 Eclipse。 Edit the file with the name .pmd in the project folder by replacing the content with the following:通过将内容替换为以下内容,编辑项目文件夹中名为.pmd的文件:

<?xml version="1.0" encoding="UTF-8"?>
<pmd>
<useProjectRuleSet>true</useProjectRuleSet>
<ruleSetFile>pmd.xml</ruleSetFile>
<includeDerivedFiles>false</includeDerivedFiles>
<violationsAsErrors>true</violationsAsErrors>
<fullBuildEnabled>true</fullBuildEnabled>
</pmd>

Restart Eclipse and right click the project.重新启动 Eclipse 并右键单击该项目。 Select PMD/Check Code.选择 PMD/校验码。 Now, only the violations defined in pmd.xml should be reported.现在,只应报告 pmd.xml 中定义的违规。

Configuring PMD only using the GUI does not seem to work for me.仅使用 GUI 配置 PMD 似乎对我不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM