@myron-lee
2015-09-02T09:12:08.000000Z
字数 3988
阅读 2257
未分类
我们的自定义规则集是基于PMD 4.2.5的,而PMD插件是基于PMD 5.3.2的。规则名称没有变,规则类变了。我把我们的自定义规则集修改了,主要是修改了类名,把引用去掉了。见alipay.xml。
估计还是版本问题,我把一些菜单阉掉(修改了plugin.xml),否则会部署失败。
<!DOCTYPE idea-plugin PUBLIC "Plugin/DTD" "http://plugins.intellij.net/plugin.dtd">
<idea-plugin>
<name>AlipayPMDPlugin</name>
<description>A plugin to run static analysis using PMD in intelliJ.</description>
<change-notes>
Support for PMD 5.3.2
</change-notes>
<version>1.7.2</version>
<vendor>alipay</vendor>
<idea-version since-build="133.690"/>
<project-components>
<component>
<implementation-class>com.intellij.plugins.alipay.pmd.PMDProjectComponent</implementation-class>
<interface-class>com.intellij.plugins.alipay.pmd.PMDProjectComponent</interface-class>
</component>
</project-components>
<actions>
<!-- The Main menu item which includes predefined and custom rulesets -->
<group id="PMDMenuGroup" text="Run Alipay PMD" popup="true"
class="com.intellij.plugins.alipay.pmd.actions.PMDMenuGroup">
<add-to-group group-id="ToolsMenu" anchor="last"/>
<!--阉割了一些菜单
<add-to-group group-id="ProjectViewPopupMenu" anchor="last"/>
<add-to-group group-id="ChangesViewPopupMenu" anchor="last"/>
<add-to-group group-id="EditorPopupMenu" anchor="last"/>
-->
</group>
<!-- The pre defined menu group -->
<group id="PMDPredefined" text="Pre Defined" popup="true"
class="com.intellij.plugins.alipay.pmd.actions.PreDefinedMenuGroup">
<add-to-group anchor="first" group-id="PMDMenuGroup"/>
</group>
<!-- The Custom menu group -->
<group id="PMDCustom" text="Custom Rules" popup="true">
<add-to-group anchor="last" group-id="PMDMenuGroup"/>
</group>
<!-- The group representing toolbar items in settings -->
<group id="PMDSettingsEdit" text="Custom Rule"/>
</actions>
</idea-plugin>
/**
* This ActionGroup defines the actions for pre defined rulesets that
* comes with PMD. The actions are created dynamically.
*
* @author bodhi
* @version 1.0
*/
public class PreDefinedMenuGroup extends ActionGroup {
// A string that represents all the rulesets as comma separated value.
private static String allRules = "";
//All the children of this group
private AnAction[] children;
private PMDProjectComponent component;
//The ruleset property file which lists all the predefined rulesets
private static final String RULESETS_PROPERTY_FILE = "rulesets/java/rulesets.properties";
private static final String RULESETS_FILENAMES = "rulesets.filenames";
/**
* Loads all the predefined rulesets in PMD and create actions for them.
*/
public PreDefinedMenuGroup() {
AnAction action = new AnAction("All") {
public void actionPerformed(AnActionEvent e) {
PMDInvoker.getInstance().runPMD(e, allRules, false);
getComponent().setLastRunRules(allRules);
}
};
Properties props = new Properties();
try {
//Load the property file which has all the rulesets.
props.load(ResourceLoader.loadResourceAsStream(RULESETS_PROPERTY_FILE));
String[] rulesetFilenames = props.getProperty(RULESETS_FILENAMES).split(PMDInvoker.RULE_DELIMITER);
//We have 'All' rules in addition to the rulesets
children = new AnAction[rulesetFilenames.length + 2];
//First one is 'All'
children[0] = action;
children[1] = new AnAction("alipay") {
public void actionPerformed(AnActionEvent e) {
// PMDInvoker.getInstance().runPMD(e, getClass().getResource("/resource/alipay.xml").getPath().substring(1).replace('/', '\\'), true);
PMDInvoker.getInstance().runPMD(e, "C:\\Users\\myron.lg\\Desktop\\alipay.xml", true);
getComponent().setLastRunRules("alipay");
}
};
for (int i = 0; i < rulesetFilenames.length; ++i) {
int start = rulesetFilenames[i].indexOf('/');
int end = rulesetFilenames[i].indexOf('.');
final String name = rulesetFilenames[i].substring(start + 1, end);
allRules += name;
allRules += (i == rulesetFilenames.length - 1) ? "" : PMDInvoker.RULE_DELIMITER;
AnAction ruleAction = new AnAction(name) {
public void actionPerformed(AnActionEvent e) {
PMDInvoker.getInstance().runPMD(e, name, false);
getComponent().setLastRunRules(name);
}
};
children[i + 2] = ruleAction;
}
} catch (IOException e) {
//Should not happen
//e.printStackTrace();
} catch (Exception e) {
//Should not happen
//e.printStackTrace();
}
}
public AnAction[] getChildren(@Nullable AnActionEvent event) {
return this.children;
}
public void setComponent(PMDProjectComponent component) {
this.component = component;
}
public PMDProjectComponent getComponent() {
return component;
}
}