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

0
5 comments

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.

 

0

Thanks, Yann Cebron. Is there a way in the #projectOpened method to determine that the 'first initial import' has not ended yet?

0

What do you want to do with ProjectComponent and projectOpened now?

0

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.

0

Why? What do you want to achieve?

0

Please sign in to leave a comment.