Project setup plugin

Hi!

Hope to get a little guidance as I'm noob at plugin dev.

We have a homegrown way of setting jdk/maven up in our projects.

A bat file is called which contains e.g. call cfg jdk 1.6.0_55 maven 3.1.1

I would like an idea plugin which will call this bat file and setup project jdk and maven setting accordingly in IDEA.

It should:

* Be invoked when a project is opened
* Execute bat file in project root
* Put message in the open project progress dialog
* Extract info about jdk and maven version (from bat file)
* Alter maven settings to reflect maven version
* Alter sdk project settings to reflect sdk version (and create new sdk if it does not exist)
* Alter language level according to sdk version

So far I figured out I need a project component.

Any help and pointers to specific openapi classes appreciated.

0
14 comments

* To change the Maven home, add a dependency on the Maven plugin as described in http://confluence.jetbrains.com/display/IDEADEV/IntelliJ+IDEA+Plugin+Structure#IntelliJIDEAPluginStructure-PluginDependencies and callMavenProjectsManager.getInstance(myProject).getGeneralSettings().setMavenHome().
* To create a JDK, use ProjectJdkTable.createJdk() and pass JavaSdk.getInstance() as the sdkType parameter.
* To change the project JDK, use ProjectRootManager.setProjectSdk().
* To change the language level, use LanguageLevelProjectExtension.setLanguageLevel().

0

Thanks, very helpful. I've got the maven stuff working, and language level and setting project sdk.

But I have trouble creating new jdk.

I can not see how to specify java home on ProjectJdkTable.createJdk() so I tried:

Sdk sdk = JavaSdk.getInstance().createJdk("plugin 1.7", "D:/tools/oracle/jdk/1.7.0_55");

It executes without errors and takes some time, but the SDK is not created. What could be wrong here?

0

Found it could be something to do with missing write access so I tried:

    ApplicationManager.getApplication().runWriteAction(new Runnable() {
            @Override
            public void run() {
                Sdk sdk = JavaSdk.getInstance().createJdk("plugin 1.7", "D:/tools/oracle/jdk/1.7.0_55",false);
                ProjectRootManager.getInstance(project).setProjectSdk(sdk);
            }
        });

but then I get this error: Write access is allowed from event dispatch thread only

I'm executing this in method initComponent() of ProjectComponent.

0

If I move the code from initComponent to projectOpened it works :-)

I also had to add the sdk to the jdk table.

   ApplicationManager.getApplication().runWriteAction(new Runnable() {
            @Override
            public void run() {
                Sdk sdk = JavaSdk.getInstance().createJdk("plugin 1.7.1", "D:/tools/oracle/jdk/1.7.0_55",false);
                ProjectRootManager.getInstance(project).setProjectSdk(sdk);
                ProjectJdkTable.getInstance().addJdk(sdk);
            }
        });

0

A few more questions:

* I'm using Notifications.Bus.notify to show a message popup. This is not in openapi package. Should I not be using this?

* I would like to write a text to the "Loading project" dialog during loading. Is this possible? Can it be set in initComponent and will UI refresh?

0

The "openapi" package is mostly a historical artifact by this time. You can use any classes regardless of whether they are in the openapi package or not.

To write text to the project loading dialog, use ProgressManager.getInstance().getProgressIndicator().setText().

0

I'm almost there but have an issue with the loading dialog.

In initComponent I have

final ProgressManager progressManager = ProgressManager.getInstance();
        if(progressManager.hasProgressIndicator()){
            progressManager.getProgressIndicator().setText(text);
        }

After this I run a lengthy operation in initComponent.

If I open a project with IDEA configuration files it works as expected. I will see the progress indicator with my text.

But if I open a project from a pom.xml (without any existing idea config), progressManager.hasProgressIndicator() will return FALSE.

So what is different when opening from pom.xml. How can I handle this?

0

If the import from pom.xml doesn't show any progress indicator while initializing components, then it's a bug in IntelliJ IDEA, I don't think you need to do anything about it in your plugin.

0

Okay, I tried to debug to determine if it entered initComponent more than once. It didn't. I only noticed this behaviour because sometime my initComponent can take a few seconds.
I tried to make an notification but it does not pop up before initComponent is done.

0

Dimity, is this something you can look into. It's not critical, but it would be nice to have it fixed. If a patch is made I would be happy to test it.

0

Could you please attach the stacktrace of the call to initComponent() when you're importing a Maven project?


0

There is no stack trace.

The problem is that ProgressIndicator progressIndicator = progressManager.getProgressIndicator() returns NULL if i open pom.xml. If I open project with .ipr file it is OK and returns progressindicator.

That means that I can show progress message when i open project with idea files. If i open with pom.xml I cannot. Otherwise the plugin works in both situations.

0

Yes, I understand. Could you please put a breakpoint in initComponent() and attach the call stack from the debugger?

0

AWT-EventQueue-0 14.0.2#IU-139.659.2, eap:false@2311, prio=6, in group 'main', status: 'RUNNING'


      at dk.nykredit.idea.plugins.toolsetup.ProjectComponentToolsetup.initComponent(ProjectComponentToolsetup.java:57)
      at com.intellij.openapi.components.impl.ComponentManagerImpl$ComponentConfigComponentAdapter$1.getComponentInstance(ComponentManagerImpl.java:563)
      at com.intellij.openapi.components.impl.ComponentManagerImpl$ComponentConfigComponentAdapter.getComponentInstance(ComponentManagerImpl.java:605)
      at com.intellij.util.pico.DefaultPicoContainer.getLocalInstance(DefaultPicoContainer.java:236)
      at com.intellij.util.pico.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:223)
      at com.intellij.util.pico.DefaultPicoContainer.getComponentInstance(DefaultPicoContainer.java:210)
      at org.picocontainer.alternatives.AbstractDelegatingMutablePicoContainer.getComponentInstance(AbstractDelegatingMutablePicoContainer.java:75)
      at com.intellij.openapi.components.impl.ComponentManagerImpl.createComponent(ComponentManagerImpl.java:124)
      at com.intellij.openapi.components.impl.ComponentManagerImpl.a(ComponentManagerImpl.java:115)
      at com.intellij.openapi.components.impl.ComponentManagerImpl.init(ComponentManagerImpl.java:86)
      at com.intellij.openapi.project.impl.ProjectImpl.init(ProjectImpl.java:297)
      at com.intellij.openapi.project.impl.ProjectManagerImpl.a(ProjectManagerImpl.java:300)
      at com.intellij.openapi.project.impl.ProjectManagerImpl.newProject(ProjectManagerImpl.java:252)
      at com.intellij.projectImport.ProjectOpenProcessorBase.doOpenProject(ProjectOpenProcessorBase.java:197)
      at com.intellij.ide.impl.ProjectUtil.openOrImport(ProjectUtil.java:123)
      at com.intellij.ide.actions.OpenFileAction.a(OpenFileAction.java:96)
      at com.intellij.ide.actions.OpenFileAction.access$000(OpenFileAction.java:50)
      at com.intellij.ide.actions.OpenFileAction$1.consume(OpenFileAction.java:68)
      at com.intellij.ide.actions.OpenFileAction$1.consume(OpenFileAction.java:58)
      at com.intellij.openapi.fileChooser.ex.FileChooserDialogImpl.choose(FileChooserDialogImpl.java:152)
      at com.intellij.openapi.fileChooser.FileChooser.chooseFiles(FileChooser.java:111)
      at com.intellij.openapi.fileChooser.FileChooser.chooseFiles(FileChooser.java:89)
      at com.intellij.ide.actions.OpenFileAction.actionPerformed(OpenFileAction.java:58)
      at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:164)
      at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter$1.run(ActionMenuItem.java:266)
      at com.intellij.openapi.wm.impl.FocusManagerImpl.runOnOwnContext(FocusManagerImpl.java:926)
      at com.intellij.openapi.wm.impl.IdeFocusManagerImpl.runOnOwnContext(IdeFocusManagerImpl.java:124)
      at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:236)
      at javax.swing.AbstractButton.fireActionPerformed(Unknown Source:-1)
      at com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:105)
      at com.intellij.ui.plaf.beg.BegMenuItemUI.a(BegMenuItemUI.java:512)
      at com.intellij.ui.plaf.beg.BegMenuItemUI.access$300(BegMenuItemUI.java:44)
      at com.intellij.ui.plaf.beg.BegMenuItemUI$MyMouseInputHandler.mouseReleased(BegMenuItemUI.java:532)
      at java.awt.Component.processMouseEvent(Unknown Source:-1)
      at javax.swing.JComponent.processMouseEvent(Unknown Source:-1)
      at java.awt.Component.processEvent(Unknown Source:-1)
      at java.awt.Container.processEvent(Unknown Source:-1)
      at java.awt.Component.dispatchEventImpl(Unknown Source:-1)
      at java.awt.Container.dispatchEventImpl(Unknown Source:-1)
      at java.awt.Component.dispatchEvent(Unknown Source:-1)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source:-1)
      at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source:-1)
      at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source:-1)
      at java.awt.Container.dispatchEventImpl(Unknown Source:-1)
      at java.awt.Window.dispatchEventImpl(Unknown Source:-1)
      at java.awt.Component.dispatchEvent(Unknown Source:-1)
      at java.awt.EventQueue.dispatchEventImpl(Unknown Source:-1)
      at java.awt.EventQueue.access$200(Unknown Source:-1)
      at java.awt.EventQueue$3.run(Unknown Source:-1)
      at java.awt.EventQueue$3.run(Unknown Source:-1)
      at java.security.AccessController.doPrivileged(Unknown Source:-1)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source:-1)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source:-1)
      at java.awt.EventQueue$4.run(Unknown Source:-1)
      at java.awt.EventQueue$4.run(Unknown Source:-1)
      at java.security.AccessController.doPrivileged(Unknown Source:-1)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source:-1)
      at java.awt.EventQueue.dispatchEvent(Unknown Source:-1)
      at com.intellij.ide.IdeEventQueue.e(IdeEventQueue.java:748)
      at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:573)
      at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:384)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source:-1)
      at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source:-1)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source:-1)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source:-1)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source:-1)
      at java.awt.EventDispatchThread.run(Unknown Source:-1)
0

Please sign in to leave a comment.