use of com.intellij.openapi.roots.LibraryOrderEntry in project ballerina by ballerina-lang.
the class BallerinaModuleLibrariesInitializer method attachLibraries.
private void attachLibraries(@NotNull Collection<VirtualFile> libraryRoots, Set<VirtualFile> exclusions) {
ApplicationManager.getApplication().assertIsDispatchThread();
if (!libraryRoots.isEmpty()) {
ApplicationManager.getApplication().runWriteAction(() -> {
ModuleRootManager model = ModuleRootManager.getInstance(myModule);
LibraryOrderEntry ballerinaLibraryEntry = OrderEntryUtil.findLibraryOrderEntry(model, getLibraryName());
if (ballerinaLibraryEntry != null && ballerinaLibraryEntry.isValid()) {
Library library = ballerinaLibraryEntry.getLibrary();
if (library != null && !((LibraryEx) library).isDisposed()) {
fillLibrary(library, libraryRoots, exclusions);
}
} else {
LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(myModule.getProject());
Library library = libraryTable.createLibrary(getLibraryName());
fillLibrary(library, libraryRoots, exclusions);
ModuleRootModificationUtil.addDependency(myModule, library);
}
});
showNotification(myModule.getProject());
} else {
removeLibraryIfNeeded();
}
}
use of com.intellij.openapi.roots.LibraryOrderEntry in project ballerina by ballerina-lang.
the class BallerinaModuleLibrariesInitializer method removeLibraryIfNeeded.
private void removeLibraryIfNeeded() {
ApplicationManager.getApplication().assertIsDispatchThread();
ModifiableModelsProvider modelsProvider = ModifiableModelsProvider.SERVICE.getInstance();
ModifiableRootModel model = modelsProvider.getModuleModifiableModel(myModule);
LibraryOrderEntry ballerinaLibraryEntry = OrderEntryUtil.findLibraryOrderEntry(model, getLibraryName());
if (ballerinaLibraryEntry != null) {
ApplicationManager.getApplication().runWriteAction(() -> {
Library library = ballerinaLibraryEntry.getLibrary();
if (library != null) {
LibraryTable table = library.getTable();
if (table != null) {
table.removeLibrary(library);
model.removeOrderEntry(ballerinaLibraryEntry);
modelsProvider.commitModuleModifiableModel(model);
}
} else {
modelsProvider.disposeModuleModifiableModel(model);
}
});
} else {
ApplicationManager.getApplication().runWriteAction(() -> modelsProvider.disposeModuleModifiableModel(model));
}
}
use of com.intellij.openapi.roots.LibraryOrderEntry in project sonarlint-intellij by SonarSource.
the class JavaAnalysisConfigurator method getProjectClasspath.
private static VirtualFile[] getProjectClasspath(@Nullable final Module module) {
if (module == null) {
return new VirtualFile[0];
}
final List<VirtualFile> found = new LinkedList<>();
final ModuleRootManager mrm = ModuleRootManager.getInstance(module);
final OrderEntry[] orderEntries = mrm.getOrderEntries();
for (final OrderEntry entry : orderEntries) {
if (entry instanceof ModuleOrderEntry) {
// Add dependent module output dir as library
Module dependentModule = ((ModuleOrderEntry) entry).getModule();
found.addAll(getModuleEntries(dependentModule));
} else if (entry instanceof LibraryOrderEntry) {
Library lib = ((LibraryOrderEntry) entry).getLibrary();
found.addAll(getLibraryEntries(lib));
}
}
return found.toArray(new VirtualFile[found.size()]);
}
use of com.intellij.openapi.roots.LibraryOrderEntry in project moe-ide-integration by multi-os-engine.
the class ModuleObserver method addMOEDependencies.
private void addMOEDependencies(@NotNull final Module module) {
final String home = MOESdkPlugin.getSdkRootPath(module);
if (home == null || home.isEmpty()) {
LOG.debug("Unable to find MOE home");
return;
}
ApplicationManager.getApplication().runWriteAction(new DumbAwareRunnable() {
@Override
public void run() {
for (String jar : MOE_JARS) {
String jarPath = home + File.separator + MOE_JARS_PATH + File.separator + jar;
VirtualFile file = LocalFileSystem.getInstance().findFileByPath(jarPath);
if (file == null) {
return;
}
final ModuleRootManager manager = ModuleRootManager.getInstance(module);
final ModifiableRootModel rootModel = manager.getModifiableModel();
final Library jarLibrary = rootModel.getModuleLibraryTable().createLibrary();
final Library.ModifiableModel libraryModel = jarLibrary.getModifiableModel();
libraryModel.setName("Maven: " + jar);
String url = VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL, jarPath) + JarFileSystem.JAR_SEPARATOR;
libraryModel.addRoot(url, OrderRootType.CLASSES);
libraryModel.commit();
final LibraryOrderEntry orderEntry = rootModel.findLibraryOrderEntry(jarLibrary);
orderEntry.setScope(DependencyScope.COMPILE);
rootModel.commit();
}
checkRunConfiguration(module.getProject(), module);
}
});
}
use of com.intellij.openapi.roots.LibraryOrderEntry in project intellij by bazelbuild.
the class AddLibraryTargetDirectoryToProjectViewAttachSourcesProvider method getActions.
@NotNull
@Override
public Collection<AttachSourcesAction> getActions(List<LibraryOrderEntry> orderEntries, final PsiFile psiFile) {
Project project = psiFile.getProject();
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (blazeProjectData == null) {
return ImmutableList.of();
}
List<Library> librariesToAttachSourceTo = Lists.newArrayList();
for (LibraryOrderEntry orderEntry : orderEntries) {
Library library = orderEntry.getLibrary();
WorkspacePath workspacePath = AddLibraryTargetDirectoryToProjectViewAction.getDirectoryToAddForLibrary(project, library);
if (workspacePath == null) {
continue;
}
librariesToAttachSourceTo.add(library);
}
if (librariesToAttachSourceTo.isEmpty()) {
return ImmutableList.of();
}
return ImmutableList.of(new AttachSourcesAction() {
@Override
public String getName() {
return "Add Source Directories To Project View";
}
@Override
public String getBusyText() {
return "Adding directories...";
}
@Override
public ActionCallback perform(List<LibraryOrderEntry> orderEntriesContainingFile) {
AddLibraryTargetDirectoryToProjectViewAction.addDirectoriesToProjectView(project, librariesToAttachSourceTo);
return ActionCallback.DONE;
}
});
}
Aggregations