在 Intellij/IDEA 插件中以编程方式调用 Ant 目标
Invoking an Ant Target Programmatically in an Intellij/IDEA plugin
我正在尝试根据插件中的用户操作调用 ant 目标。这样做曾经奏效:
AntConfiguration conf = AntConfiguration.getInstance(project);
我的 plugin.xml
包含条目:
<depends optional="false">AntSupport</depends>
如前所述here。
但是,对于当前版本的 IntelliJ,它会引发此异常:
java.lang.ClassCastException:
com.intellij.lang.ant.config.impl.AntConfigurationImpl cannot be cast
to com.intellij.lang.ant.config.AntConfiguration at
com.intellij.lang.ant.config.AntConfiguration.getInstance(AntConfiguration.java:38)
at
com.codename1.plugin.intellij.ant.AntRunner.getAntFile(AntRunner.java:133)
at
com.codename1.plugin.intellij.ant.AntRunner.runTarget(AntRunner.java:59)
at
com.codename1.plugin.intellij.actions.CodenameOneAction.runAntTarget(CodenameOneAction.java:61)
at
com.codename1.plugin.intellij.actions.SendAndroidBuild.actionPerformed(SendAndroidBuild.java:17)
at
com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:191)
at
com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.run(ActionMenuItem.java:311)
at
com.intellij.openapi.wm.impl.FocusManagerImpl.runOnOwnContext(FocusManagerImpl.java:958)
at
com.intellij.openapi.wm.impl.IdeFocusManagerImpl.runOnOwnContext(IdeFocusManagerImpl.java:124)
at
com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:281)
at
javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at
com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:109)
at
com.intellij.ui.plaf.beg.BegMenuItemUI.doClick(BegMenuItemUI.java:513)
at
com.intellij.ui.plaf.beg.BegMenuItemUI.access0(BegMenuItemUI.java:45)
at
com.intellij.ui.plaf.beg.BegMenuItemUI$MyMouseInputHandler.mouseReleased(BegMenuItemUI.java:533)
at java.awt.Component.processMouseEvent(Component.java:6525) at
javax.swing.JComponent.processMouseEvent(JComponent.java:3324) at
java.awt.Component.processEvent(Component.java:6290) at
java.awt.Container.processEvent(Container.java:2234) at
java.awt.Component.dispatchEventImpl(Component.java:4881) at
java.awt.Container.dispatchEventImpl(Container.java:2292) at
java.awt.Component.dispatchEvent(Component.java:4703) at
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
at
java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
at java.awt.Container.dispatchEventImpl(Container.java:2278) at
java.awt.Window.dispatchEventImpl(Window.java:2750) at
java.awt.Component.dispatchEvent(Component.java:4703) at
java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758) at
java.awt.EventQueue.access0(EventQueue.java:97) at
java.awt.EventQueue.run(EventQueue.java:709) at
java.awt.EventQueue.run(EventQueue.java:703) at
java.security.AccessController.doPrivileged(Native Method) at
java.security.ProtectionDomain.doIntersectionPrivilege(ProtectionDomain.java:75)
at
java.security.ProtectionDomain.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue.run(EventQueue.java:731) at
java.awt.EventQueue.run(EventQueue.java:729) at
java.security.AccessController.doPrivileged(Native Method) at
java.security.ProtectionDomain.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728) at
com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:857)
at
com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:654)
at
com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:386)
at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
这对我来说像是一个错误,但我可能在某种程度上滥用了 API,因为据我所知,这并不完全 "documented"。
好的,想通了。我忽略了将库依赖项设置为提供的状态并将它们置于 "compiled" 状态。这在某种程度上隐藏在依赖项 window:
中
我正在尝试根据插件中的用户操作调用 ant 目标。这样做曾经奏效:
AntConfiguration conf = AntConfiguration.getInstance(project);
我的 plugin.xml
包含条目:
<depends optional="false">AntSupport</depends>
如前所述here。
但是,对于当前版本的 IntelliJ,它会引发此异常:
java.lang.ClassCastException: com.intellij.lang.ant.config.impl.AntConfigurationImpl cannot be cast to com.intellij.lang.ant.config.AntConfiguration at com.intellij.lang.ant.config.AntConfiguration.getInstance(AntConfiguration.java:38) at com.codename1.plugin.intellij.ant.AntRunner.getAntFile(AntRunner.java:133) at com.codename1.plugin.intellij.ant.AntRunner.runTarget(AntRunner.java:59) at com.codename1.plugin.intellij.actions.CodenameOneAction.runAntTarget(CodenameOneAction.java:61) at com.codename1.plugin.intellij.actions.SendAndroidBuild.actionPerformed(SendAndroidBuild.java:17) at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:191) at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.run(ActionMenuItem.java:311) at com.intellij.openapi.wm.impl.FocusManagerImpl.runOnOwnContext(FocusManagerImpl.java:958) at com.intellij.openapi.wm.impl.IdeFocusManagerImpl.runOnOwnContext(IdeFocusManagerImpl.java:124) at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:281) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022) at com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:109) at com.intellij.ui.plaf.beg.BegMenuItemUI.doClick(BegMenuItemUI.java:513) at com.intellij.ui.plaf.beg.BegMenuItemUI.access0(BegMenuItemUI.java:45) at com.intellij.ui.plaf.beg.BegMenuItemUI$MyMouseInputHandler.mouseReleased(BegMenuItemUI.java:533) at java.awt.Component.processMouseEvent(Component.java:6525) at javax.swing.JComponent.processMouseEvent(JComponent.java:3324) at java.awt.Component.processEvent(Component.java:6290) at java.awt.Container.processEvent(Container.java:2234) at java.awt.Component.dispatchEventImpl(Component.java:4881) at java.awt.Container.dispatchEventImpl(Container.java:2292) at java.awt.Component.dispatchEvent(Component.java:4703) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462) at java.awt.Container.dispatchEventImpl(Container.java:2278) at java.awt.Window.dispatchEventImpl(Window.java:2750) at java.awt.Component.dispatchEvent(Component.java:4703) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758) at java.awt.EventQueue.access0(EventQueue.java:97) at java.awt.EventQueue.run(EventQueue.java:709) at java.awt.EventQueue.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain.doIntersectionPrivilege(ProtectionDomain.java:75) at java.security.ProtectionDomain.doIntersectionPrivilege(ProtectionDomain.java:86) at java.awt.EventQueue.run(EventQueue.java:731) at java.awt.EventQueue.run(EventQueue.java:729) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain.doIntersectionPrivilege(ProtectionDomain.java:75) at java.awt.EventQueue.dispatchEvent(EventQueue.java:728) at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:857) at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:654) at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:386) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
这对我来说像是一个错误,但我可能在某种程度上滥用了 API,因为据我所知,这并不完全 "documented"。
好的,想通了。我忽略了将库依赖项设置为提供的状态并将它们置于 "compiled" 状态。这在某种程度上隐藏在依赖项 window:
中