11 Replies Last post: Feb 15, 2010 9:02 AM by Gaurav Joshi  
Shmulik  IDEA Plugin Contest Winner 12 posts since
Sep 23, 2002
Currently Being Moderated

May 19, 2008 12:21 PM

Programatic manipulation of project settings

Hi,

 

I need to perform the following operations programmatically from a plugin. I don't manage to find it in the openapi, I would appreciate if you can help me on this:

 

1. Modify the dependencies of a given module - specify that it uses a certain jar

2. Set a different output folder for a given module

3. Remove a named facet from the facets of a module

4. Add an Ant build file to the list of ant files included by the project, and later execute it (showing the output in IntelliJ console)

5. Given a certain VirtualFile that belongs to the project, make it the selected node in the project-view

 

Thanks,

Shmulik

Guest
Currently Being Moderated
May 19, 2008 1:25 PM in response to: Shmulik
Re: Programatic manipulation of project settings

Hello Shmulik,

 

I need to perform the following operations programmatically from a

plugin. I don't manage to find it in the openapi, I would appreciate

if you can help me on this:

 

1. Modify the dependencies of a given module - specify that it uses a

certain jar

 

There's a number of steps involved in here - see, for example, TestNGUtil.checkTestNGInClasspath()

for a code sample.

 

2. Set a different output folder for a given module

 

ModuleRootManager.getInstance(module).getModifiableRootModel().setCompilerOutputPath()

 

3. Remove a named facet from the facets of a module

 

FacetManager.getInstance(module).getModifiableModel().removeFacet()

 

4. Add an Ant build file to the list of ant files included by the

project, and later execute it (showing the output in IntelliJ console)

 

AntConfiguration.getInstance(project).addBuildFile()

 

5. Given a certain VirtualFile that belongs to the project, make it

the selected node in the project-view

 

SelectInManager.getInstance(project).getTarget(SelectInManager.PROJECT).selectIn()

 

--

Dmitry Jemerov

Development Lead

JetBrains, Inc.

http://www.jetbrains.com/

"Develop with Pleasure!"

 

 

 

Guest
Currently Being Moderated
May 19, 2008 7:27 PM in response to: Shmulik
Re: Programatic manipulation of project settings

Hello Shmulik,

 

You also need to call inheritCompilerOutputPath(false).

 

When I try to change the output path of the project, it is not changed

but no exception is thrown. The new output path exists and the output

path remains the same also after reloading the project.

 

Here is the code that I'm using:

 

ApplicationManager.getApplication().runWriteAction(new Runnable()

{

public void run() {

try {

VirtualFile moduleFile = module.getModuleFile();

VirtualFile classesFile =

moduleFile.getParent().findChild("bin").findChild("classes");

System.out.println("Exists? "classesFile.exists()"

"+classesFile.isDirectory());

ModifiableRootModel rootModel =

ModuleRootManager.getInstance(module).getModifiableModel();

rootModel.setCompilerOutputPath(classesFile);

rootModel.setCompilerOutputPathForTests(classesFile);

rootModel.commit();

} catch (Exception e) {

e.printStackTrace();

}

}

});

any ideas?

 

thanks,

Shmuliik

--

Dmitry Jemerov

Development Lead

JetBrains, Inc.

http://www.jetbrains.com/

"Develop with Pleasure!"

 

 

 

Gaurav  Joshi Newbie 20 posts since
Feb 8, 2010
Currently Being Moderated
Feb 8, 2010 8:37 AM in response to: Shmulik
Re: Programatic manipulation of project settings

I am Working on IntelliJ 9 and migrating my plugin from 5.x to 9.x, facing the same problem of how to set the output path as ModuleRootManager setOutputPath is removed altogther from the API.

Dmitry Jemerov JetBrains 11,708 posts since
Aug 19, 2002
Currently Being Moderated
Feb 8, 2010 1:43 PM in response to: Gaurav Joshi
Re: Programatic manipulation of project settings

Hello Gaurav,

 

I am Working on IntelliJ 9 and migrating my plugin from 5.x to 9.x,

facing the same problem of how to set the output path as

ModuleRootManager setOutputPath is removed altogther from the API.

 

The replacement API is CompilerModuleExtension.getInstance(module).setCompilerOutputPath().

 

--

Dmitry Jemerov

Development Lead

JetBrains, Inc.

http://www.jetbrains.com/

"Develop with Pleasure!"

 

 

 

Gaurav  Joshi Newbie 20 posts since
Feb 8, 2010
Currently Being Moderated
Feb 9, 2010 11:05 AM in response to: Dmitry Jemerov
Re: Programatic manipulation of project settings

Hello Dmitry,

 

Thnaks for replying but when I try and use CompilerModuleExtension.getInstance(module).setCompilerOutputPath(). I am thrown with an exception

Configuring project failed for unexpected reason
java.lang.AssertionError: Writable model can be retrieved from writable ModifiableRootModel
    at com.intellij.openapi.roots.impl.CompilerModuleExtensionImpl.a(CompilerModuleExtensionImpl.java:225)
    at com.intellij.openapi.roots.impl.CompilerModuleExtensionImpl.setCompilerOutputPath(CompilerModuleExtensionImpl.java:196)
    at com.intellij.openapi.roots.impl.CompilerModuleExtensionImpl.setCompilerOutputPath(CompilerModuleExtensionImpl.java:186)
    at com.yolus.intellij.yde.ProjectConfigurer$YDEModule.configureModuleOrFail(ProjectConfigurer.java:340)
    at com.yolus.intellij.yde.ProjectConfigurer$YDEModule.access$000(ProjectConfigurer.java:280)
    at com.yolus.intellij.yde.ProjectConfigurer.configureProjectOrFail(ProjectConfigurer.java:148)
    at com.yolus.intellij.yde.ProjectConfigurer.run(ProjectConfigurer.java:96)
    at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:748)
    at com.yolus.intellij.yde.ProjectSettingsAction.actionPerformed(ProjectSettingsAction.java:45)
    at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:214)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:82)
    at com.intellij.ui.plaf.beg.BegMenuItemUI.a(BegMenuItemUI.java:496)
    at com.intellij.ui.plaf.beg.BegMenuItemUI.access$300(BegMenuItemUI.java:43)
    at com.intellij.ui.plaf.beg.BegMenuItemUI$MyMouseInputHandler.mouseReleased(BegMenuItemUI.java:516)
    at java.awt.Component.processMouseEvent(Component.java:6263)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3255)
    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:2475)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at com.intellij.ide.IdeEventQueue.f(IdeEventQueue.java:621)
    at com.intellij.ide.IdeEventQueue.b(IdeEventQueue.java:507)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:372)
    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)

 

Can't I use ModifiableRootModel, setExplodedDirectory method instead.

Gaurav  Joshi Newbie 20 posts since
Feb 8, 2010
Currently Being Moderated
Feb 10, 2010 3:14 PM in response to: Gaurav Joshi
Re: Programatic manipulation of project settings

Well I am still not able to solve this puzzle

Gaurav  Joshi Newbie 20 posts since
Feb 8, 2010
Currently Being Moderated
Feb 15, 2010 9:02 AM in response to: Gaurav Joshi
Re: Programatic manipulation of project settings

Please help!


More Like This

  • Retrieving data ...