How to get a list of libraries when creating a project?
Answered
I have a component.
public class MyComponent implements ProjectComponent {
private Project project;
@Override
public void projectOpened() {
StartupManager.getInstance(project).runWhenProjectIsInitialized((DumbAwareRunnable) () ->
ApplicationManager.getApplication().invokeLater(() ->
DumbService.getInstance(project).runWhenSmart(() -> {
Library[] libraries = LibraryTablesRegistrar.getInstance().getLibraryTable(project).getLibraries();
//my logic
}), o -> (!project.isOpen()) || project.isDisposed()));
}
}
When opening an existing project the array(libraries) is correct - filled.
When creating a new project, the array(libraries) is empty. #runWhenProjectIsInitialized is called immediately, before any initialization or indexing or completion of the gradle build
Please sign in to leave a comment.
Register com.intellij.openapi.externalSystem.service.project.manage.AbstractProjectDataService with getTargetDataKey==ProjectKeys.MODULE, override onSuccessImport. Please note that on first initial import, library information will not yet be available.
Thanks, Yann Cebron. Is there a way in the #projectOpened method to determine that the 'first initial import' has not ended yet?
What do you want to do with ProjectComponent and projectOpened now?
Now everything is fine, I solved my problem. I wonder how inside the #projectOpened method to find out that libraries are not yet available or psi infrastructure not loaded.
Why? What do you want to achieve?