[关闭]
@myron-lee 2015-09-02T09:12:08.000000Z 字数 3988 阅读 2257

AndroidStudio插件

未分类


  1. 我们的自定义规则集是基于PMD 4.2.5的,而PMD插件是基于PMD 5.3.2的。规则名称没有变,规则类变了。我把我们的自定义规则集修改了,主要是修改了类名,把引用去掉了。见alipay.xml。

  2. 估计还是版本问题,我把一些菜单阉掉(修改了plugin.xml),否则会部署失败。

  1. <!DOCTYPE idea-plugin PUBLIC "Plugin/DTD" "http://plugins.intellij.net/plugin.dtd">
  2. <idea-plugin>
  3. <name>AlipayPMDPlugin</name>
  4. <description>A plugin to run static analysis using PMD in intelliJ.</description>
  5. <change-notes>
  6. Support for PMD 5.3.2
  7. </change-notes>
  8. <version>1.7.2</version>
  9. <vendor>alipay</vendor>
  10. <idea-version since-build="133.690"/>
  11. <project-components>
  12. <component>
  13. <implementation-class>com.intellij.plugins.alipay.pmd.PMDProjectComponent</implementation-class>
  14. <interface-class>com.intellij.plugins.alipay.pmd.PMDProjectComponent</interface-class>
  15. </component>
  16. </project-components>
  17. <actions>
  18. <!-- The Main menu item which includes predefined and custom rulesets -->
  19. <group id="PMDMenuGroup" text="Run Alipay PMD" popup="true"
  20. class="com.intellij.plugins.alipay.pmd.actions.PMDMenuGroup">
  21. <add-to-group group-id="ToolsMenu" anchor="last"/>
  22. <!--阉割了一些菜单
  23. <add-to-group group-id="ProjectViewPopupMenu" anchor="last"/>
  24. <add-to-group group-id="ChangesViewPopupMenu" anchor="last"/>
  25. <add-to-group group-id="EditorPopupMenu" anchor="last"/>
  26. -->
  27. </group>
  28. <!-- The pre defined menu group -->
  29. <group id="PMDPredefined" text="Pre Defined" popup="true"
  30. class="com.intellij.plugins.alipay.pmd.actions.PreDefinedMenuGroup">
  31. <add-to-group anchor="first" group-id="PMDMenuGroup"/>
  32. </group>
  33. <!-- The Custom menu group -->
  34. <group id="PMDCustom" text="Custom Rules" popup="true">
  35. <add-to-group anchor="last" group-id="PMDMenuGroup"/>
  36. </group>
  37. <!-- The group representing toolbar items in settings -->
  38. <group id="PMDSettingsEdit" text="Custom Rule"/>
  39. </actions>
  40. </idea-plugin>
  1. 把我们的自定义规则集加到标准规则集里面
    修改了preDefinedMenuGroup类
  1. /**
  2. * This ActionGroup defines the actions for pre defined rulesets that
  3. * comes with PMD. The actions are created dynamically.
  4. *
  5. * @author bodhi
  6. * @version 1.0
  7. */
  8. public class PreDefinedMenuGroup extends ActionGroup {
  9. // A string that represents all the rulesets as comma separated value.
  10. private static String allRules = "";
  11. //All the children of this group
  12. private AnAction[] children;
  13. private PMDProjectComponent component;
  14. //The ruleset property file which lists all the predefined rulesets
  15. private static final String RULESETS_PROPERTY_FILE = "rulesets/java/rulesets.properties";
  16. private static final String RULESETS_FILENAMES = "rulesets.filenames";
  17. /**
  18. * Loads all the predefined rulesets in PMD and create actions for them.
  19. */
  20. public PreDefinedMenuGroup() {
  21. AnAction action = new AnAction("All") {
  22. public void actionPerformed(AnActionEvent e) {
  23. PMDInvoker.getInstance().runPMD(e, allRules, false);
  24. getComponent().setLastRunRules(allRules);
  25. }
  26. };
  27. Properties props = new Properties();
  28. try {
  29. //Load the property file which has all the rulesets.
  30. props.load(ResourceLoader.loadResourceAsStream(RULESETS_PROPERTY_FILE));
  31. String[] rulesetFilenames = props.getProperty(RULESETS_FILENAMES).split(PMDInvoker.RULE_DELIMITER);
  32. //We have 'All' rules in addition to the rulesets
  33. children = new AnAction[rulesetFilenames.length + 2];
  34. //First one is 'All'
  35. children[0] = action;
  36. children[1] = new AnAction("alipay") {
  37. public void actionPerformed(AnActionEvent e) {
  38. // PMDInvoker.getInstance().runPMD(e, getClass().getResource("/resource/alipay.xml").getPath().substring(1).replace('/', '\\'), true);
  39. PMDInvoker.getInstance().runPMD(e, "C:\\Users\\myron.lg\\Desktop\\alipay.xml", true);
  40. getComponent().setLastRunRules("alipay");
  41. }
  42. };
  43. for (int i = 0; i < rulesetFilenames.length; ++i) {
  44. int start = rulesetFilenames[i].indexOf('/');
  45. int end = rulesetFilenames[i].indexOf('.');
  46. final String name = rulesetFilenames[i].substring(start + 1, end);
  47. allRules += name;
  48. allRules += (i == rulesetFilenames.length - 1) ? "" : PMDInvoker.RULE_DELIMITER;
  49. AnAction ruleAction = new AnAction(name) {
  50. public void actionPerformed(AnActionEvent e) {
  51. PMDInvoker.getInstance().runPMD(e, name, false);
  52. getComponent().setLastRunRules(name);
  53. }
  54. };
  55. children[i + 2] = ruleAction;
  56. }
  57. } catch (IOException e) {
  58. //Should not happen
  59. //e.printStackTrace();
  60. } catch (Exception e) {
  61. //Should not happen
  62. //e.printStackTrace();
  63. }
  64. }
  65. public AnAction[] getChildren(@Nullable AnActionEvent event) {
  66. return this.children;
  67. }
  68. public void setComponent(PMDProjectComponent component) {
  69. this.component = component;
  70. }
  71. public PMDProjectComponent getComponent() {
  72. return component;
  73. }
  74. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注