How to add Ant properties to the AntBuildFile?

Hello IDEA gurus.

Could you please advise me on how can I add my properties to the AntBuildFile?
For example I have property "clean" and want set its value to "on" for my AntBuildFile.
I want to do this through the API of course .
I've searched through the code of ant-plugin but cannot figure out the way how.

Thanks for the IDE.

8 comments
Comment actions Permalink

Hi Ilya,
Such properties are not supposed to be added programmatically so there is no dedicated open API to do this.
However, you may try add them in a the way the "AntExplorer" class manages them:

First, ensure your file is added to the AntConfiguration:
AntBuildFile buildFile = AntConfiguration.getInstance(project).addBuildFile(file);

Then you may add properties:

    final AbstractProperty.AbstractPropertyContainer options = ((AntBuildFileBase)buildFile).getAllOptions();
    final ArrayList<BuildFileProperty> properties = AntBuildFileImpl.ANT_PROPERTIES.getModifiableList(options);
    properties.add(new BuildFileProperty("aaa", "aaaValue"));
    properties.add(new BuildFileProperty("bbb", "bbbValue"));
    AntConfiguration.getInstance(myProject).updateBuildFile(buildFile);

0
Comment actions Permalink

I work with IDEA 8.1.3.
I've tried the suggested code and here is what I got:

Error during dispatching of java.awt.event.MouseEvent[MOUSE_RELEASED,(277,683),absolute(273,679),button=1,modifiers=Button1,clickCount=1] on frame0: com.intellij.lang.ant.config.impl.AntBuildFileImpl cannot be cast to com.intellij.lang.ant.config.impl.AntBuildFileImpl
java.lang.ClassCastException: com.intellij.lang.ant.config.impl.AntBuildFileImpl cannot be cast to com.intellij.lang.ant.config.impl.AntBuildFileImpl
    at com.jnetx.ide.intellij.IdeaModule.tryAddAntBuildFile(IdeaModule.java:497)
    at com.jnetx.ide.intellij.IdeaModule.addAntBuildFile(IdeaModule.java:480)
    at com.jnetx.ide.intellij.IdeaProject.updateLibraries(IdeaProject.java:444)
    at com.jnetx.ide.intellij.JnetxTab$7$1.run(JnetxTab.java:203)
    at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:365)
    at com.jnetx.ide.intellij.JnetxTab$7.actionPerformed(JnetxTab.java:201)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.java:6263)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
    at java.awt.Component.processEvent(Component.java:6028)
    at java.awt.Container.processEvent(Container.java:2041)
    at java.awt.Component.dispatchEventImpl(Component.java:4630)
    at java.awt.Container.dispatchEventImpl(Container.java:2099)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
    at java.awt.Container.dispatchEventImpl(Container.java:2085)
    at java.awt.Window.dispatchEventImpl(Window.java:2478)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at com.intellij.ide.IdeEventQueue.c(IdeEventQueue.java:57)
    at com.intellij.ide.IdeEventQueue.b(IdeEventQueue.java:11)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:189)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Similar exception happens with cast to AntBuildFileBase interface.
Seems strange for me - is it classloaders issue?

0
Comment actions Permalink

Yep, classloaders are the reason. Please check that the classpath of your plugin does not contain any libraries from Ant plugin. Instead your plugin should depend on Ant plugin

0
Comment actions Permalink

Thanks a lot Eugene. Everything works fine.

I use the following trick:

- to compile my plugin I have to add AntSupport jar to plugin module dependencies
- but to debug my plugin I have to remove AntSupport jar from the module dependencies

Also I've added <depends>AntSupport</depends> to my pluging.xml.

0
Comment actions Permalink

You are welcome ;-)
Doesn't DevKit plugin do the job for you?

0
Comment actions Permalink

Hello Ilya,

Thanks a lot Eugene. Everything works fine.

I use the following trick:

- to compile my plugin I have to add AntSupport jar to plugin module
dependencies - but to debug my plugin I have to remove AntSupport jar
from the module dependencies


It's easier to add AntSupport.jar to the classpath of the IDEA SDK - then
you can keep it there and it won't cause classloading issues.

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Brilliant, Dmitry! Exactly what is needed.

Thanks for the support guys.

0
Comment actions Permalink

I have also added the AntSupport jar into the SDK classpath but that doesn't work for me.
I try to execute some Ant script in the scope of a ClassPostProcessingCompiler and I get also a cast exepction

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:37)
 at com.intellij.lang.ant.config.AntConfigurationBase.getInstance(AntConfigurationBase.java:37)
 at com.avid.intellij.build.ant.AntHandler.test(AntHandler.java:51)
 at com.avid.intellij.build.BundleCompiler.process(BundleCompiler.java:54)


Any idea?
0

Please sign in to leave a comment.