Creating module dependency
I have a pluing that adds dependencies to modules. Everything works fine but IDEA hangs - sometimes for several minutes - after the plugin does its work. Any idea what is causing this and what I can do to fix it? Here's the plugin code:
Library library = modifiableModel.getLibraryByName(libraryName); if ( library != null ) { moduleLibraryTable.removeLibrary(library); } library = modifiableModel.createLibrary(libraryName); Library.ModifiableModel libraryModifiableModel = library.getModifiableModel(); for ( File jar : f.listFiles() ) { String url; try { jar = jar.getCanonicalFile(); url = VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL, jar.getPath()) + JarFileSystem.JAR_SEPARATOR; } catch ( IOException e ) { addText(toolWindow, String.format("Can't resolve directory: %s\n", jar.getPath())); continue; } libraryModifiableModel.addRoot(url, OrderRootType.CLASSES); String sourceUrl = sourceFinder.getVirtualFileForJarSources(jar, url); if ( sourceUrl != null ) { libraryModifiableModel.addRoot(sourceUrl, OrderRootType.SOURCES); } } modelsToCommit.add(libraryModifiableModel); modifiableRootModel.findLibraryOrderEntry(library).setScope(getScope(f.getName()));
Please sign in to leave a comment.
I don't see anything obviously wrong with the code. Could you attach the thread dumps from the logs directory which are written during the hang?
The thread dumps are not written to the log file itself; they are written to separate files in a subdirectory of the 'logs' directory.
Here are some thread dumps. Let me know if you need anything else.
Attachment(s):
logs.zip
The thread dumps show that the time is spent in your com.netflix.nfivy.SourceFinder.getVirtualFileForJarSources() method. Looks like you do some scanning of the file system synchronously rather than in a background thread.
That's a good idea. Is there doc on how to correctly start a background process in a plugin?
But why does IDEA completely hang while this is happening? How can I yield time back to IDEA?
ApplicationManager.getApplication().executeOnPooledThread()
Because you're doing the processing in the event dispatch thread. You shouldn't try to yield the time; you might be able to but it's really very tricky to get right and error-prone.It's much easier to perform as much of the processing as possible in the background thread, and perform only the library updates themselves in the EDT.
Thanks again for your help - the plugin is working much better now.
However, the plugin runs 10x slower inside of the actual IDEA environment than when running in the debug IDEA environment. Any ideas on that? Is that common?
-Jordan
The problem was in my internal configuration. So, never mind - everything's good.