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()));

0
11 comments

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?

0

2012-08-08 10:10:28,903 [71537973]   WARN - ution.process.OSProcessHandler - Cannot kill process tree. Trying to destroy process using Java API. Cmdline:
/Users/jzimmerman/Netflix/dev/apache-tomcat-6.0.32/bin/catalina.sh run 
2012-08-08 10:12:08,780 [71637850]   INFO - indexing.UnindexedFilesUpdater - Indexable files iterated in 19 ms 
2012-08-08 10:12:08,780 [71637850]   INFO - indexing.UnindexedFilesUpdater - Unindexed files update started: 0 files to update 
2012-08-08 10:12:08,780 [71637850]   INFO - indexing.UnindexedFilesUpdater - Unindexed files update done in 0 ms 
2012-08-08 10:12:08,946 [71638016]   INFO - api.vfs.impl.local.FileWatcher - 322 paths checked, 0 mapped, 40897 mks 



Check out that last line - 40897 for 322 paths.

0

The thread dumps are not written to the log file itself; they are written to separate files in a subdirectory of the 'logs' directory.

0

Here are some thread dumps. Let me know if you need anything else.



Attachment(s):
logs.zip
0

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.

0

That's a good idea. Is there doc on how to correctly start a background process in a plugin?

0

But why does IDEA completely hang while this is happening? How can I yield time back to IDEA?

0

ApplicationManager.getApplication().executeOnPooledThread()

0

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.

0

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

0

The problem was in my internal configuration. So, never mind - everything's good.

0

Please sign in to leave a comment.