use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class RootIndex method buildRootInfo.
@NotNull
private RootInfo buildRootInfo(@NotNull Project project) {
final RootInfo info = new RootInfo();
for (final Module module : ModuleManager.getInstance(project).getModules()) {
final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
for (final VirtualFile contentRoot : moduleRootManager.getContentRoots()) {
if (!info.contentRootOf.containsKey(contentRoot) && ensureValid(contentRoot, module)) {
info.contentRootOf.put(contentRoot, module);
}
}
for (ContentEntry contentEntry : moduleRootManager.getContentEntries()) {
if (!(contentEntry instanceof ContentEntryImpl) || !((ContentEntryImpl) contentEntry).isDisposed()) {
for (VirtualFile excludeRoot : contentEntry.getExcludeFolderFiles()) {
if (!ensureValid(excludeRoot, contentEntry))
continue;
info.excludedFromModule.put(excludeRoot, module);
}
}
// Init module sources
for (final SourceFolder sourceFolder : contentEntry.getSourceFolders()) {
final VirtualFile sourceFolderRoot = sourceFolder.getFile();
if (sourceFolderRoot != null && ensureValid(sourceFolderRoot, sourceFolder)) {
info.rootTypeId.put(sourceFolderRoot, getRootTypeId(sourceFolder.getRootType()));
info.classAndSourceRoots.add(sourceFolderRoot);
info.sourceRootOf.putValue(sourceFolderRoot, module);
info.packagePrefix.put(sourceFolderRoot, sourceFolder.getPackagePrefix());
}
}
}
for (OrderEntry orderEntry : moduleRootManager.getOrderEntries()) {
if (orderEntry instanceof LibraryOrSdkOrderEntry) {
final LibraryOrSdkOrderEntry entry = (LibraryOrSdkOrderEntry) orderEntry;
final VirtualFile[] sourceRoots = entry.getRootFiles(OrderRootType.SOURCES);
final VirtualFile[] classRoots = entry.getRootFiles(OrderRootType.CLASSES);
// Init library sources
for (final VirtualFile sourceRoot : sourceRoots) {
if (!ensureValid(sourceRoot, entry))
continue;
info.classAndSourceRoots.add(sourceRoot);
info.libraryOrSdkSources.add(sourceRoot);
info.packagePrefix.put(sourceRoot, "");
}
// init library classes
for (final VirtualFile classRoot : classRoots) {
if (!ensureValid(classRoot, entry))
continue;
info.classAndSourceRoots.add(classRoot);
info.libraryOrSdkClasses.add(classRoot);
info.packagePrefix.put(classRoot, "");
}
if (orderEntry instanceof LibraryOrderEntry) {
Library library = ((LibraryOrderEntry) orderEntry).getLibrary();
if (library != null) {
for (VirtualFile root : ((LibraryEx) library).getExcludedRoots()) {
if (!ensureValid(root, library))
continue;
info.excludedFromLibraries.putValue(root, library);
}
for (VirtualFile root : sourceRoots) {
if (!ensureValid(root, library))
continue;
info.sourceOfLibraries.putValue(root, library);
}
for (VirtualFile root : classRoots) {
if (!ensureValid(root, library))
continue;
info.classOfLibraries.putValue(root, library);
}
}
}
}
}
}
for (AdditionalLibraryRootsProvider provider : Extensions.getExtensions(AdditionalLibraryRootsProvider.EP_NAME)) {
Collection<SyntheticLibrary> libraries = provider.getAdditionalProjectLibraries(project);
for (SyntheticLibrary descriptor : libraries) {
Collection<VirtualFile> roots = ContainerUtil.filter(descriptor.getSourceRoots(), file -> ensureValid(file, project));
info.libraryOrSdkSources.addAll(roots);
info.classAndSourceRoots.addAll(roots);
}
}
for (DirectoryIndexExcludePolicy policy : Extensions.getExtensions(DirectoryIndexExcludePolicy.EP_NAME, project)) {
info.excludedFromProject.addAll(ContainerUtil.filter(policy.getExcludeRootsForProject(), file -> ensureValid(file, policy)));
}
return info;
}
use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class RootModelImpl method orderEntriesEquals.
private static boolean orderEntriesEquals(@NotNull OrderEntry orderEntry1, @NotNull OrderEntry orderEntry2) {
if (!((OrderEntryBaseImpl) orderEntry1).sameType(orderEntry2))
return false;
if (orderEntry1 instanceof JdkOrderEntry) {
if (!(orderEntry2 instanceof JdkOrderEntry))
return false;
if (orderEntry1 instanceof InheritedJdkOrderEntry && orderEntry2 instanceof ModuleJdkOrderEntry) {
return false;
}
if (orderEntry2 instanceof InheritedJdkOrderEntry && orderEntry1 instanceof ModuleJdkOrderEntry) {
return false;
}
if (orderEntry1 instanceof ModuleJdkOrderEntry && orderEntry2 instanceof ModuleJdkOrderEntry) {
String name1 = ((ModuleJdkOrderEntry) orderEntry1).getJdkName();
String name2 = ((ModuleJdkOrderEntry) orderEntry2).getJdkName();
if (!Comparing.strEqual(name1, name2)) {
return false;
}
}
}
if (orderEntry1 instanceof ExportableOrderEntry) {
if (!(((ExportableOrderEntry) orderEntry1).isExported() == ((ExportableOrderEntry) orderEntry2).isExported())) {
return false;
}
if (!(((ExportableOrderEntry) orderEntry1).getScope() == ((ExportableOrderEntry) orderEntry2).getScope())) {
return false;
}
}
if (orderEntry1 instanceof ModuleOrderEntry) {
LOG.assertTrue(orderEntry2 instanceof ModuleOrderEntry);
ModuleOrderEntryImpl entry1 = (ModuleOrderEntryImpl) orderEntry1;
ModuleOrderEntryImpl entry2 = (ModuleOrderEntryImpl) orderEntry2;
return entry1.isProductionOnTestDependency() == entry2.isProductionOnTestDependency() && Comparing.equal(entry1.getModuleName(), entry2.getModuleName());
}
if (orderEntry1 instanceof LibraryOrderEntry) {
LOG.assertTrue(orderEntry2 instanceof LibraryOrderEntry);
LibraryOrderEntry libraryOrderEntry1 = (LibraryOrderEntry) orderEntry1;
LibraryOrderEntry libraryOrderEntry2 = (LibraryOrderEntry) orderEntry2;
boolean equal = Comparing.equal(libraryOrderEntry1.getLibraryName(), libraryOrderEntry2.getLibraryName()) && Comparing.equal(libraryOrderEntry1.getLibraryLevel(), libraryOrderEntry2.getLibraryLevel());
if (!equal)
return false;
Library library1 = libraryOrderEntry1.getLibrary();
Library library2 = libraryOrderEntry2.getLibrary();
if (library1 != null && library2 != null) {
if (!Arrays.equals(((LibraryEx) library1).getExcludedRootUrls(), ((LibraryEx) library2).getExcludedRootUrls())) {
return false;
}
}
}
final OrderRootType[] allTypes = OrderRootType.getAllTypes();
for (OrderRootType type : allTypes) {
final String[] orderedRootUrls1 = orderEntry1.getUrls(type);
final String[] orderedRootUrls2 = orderEntry2.getUrls(type);
if (!Arrays.equals(orderedRootUrls1, orderedRootUrls2)) {
return false;
}
}
return true;
}
use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class LibraryTableBase method createLibrary.
@Override
public Library createLibrary(String name) {
final ModifiableModel modifiableModel = getModifiableModel();
final Library library = modifiableModel.createLibrary(name);
modifiableModel.commit();
return library;
}
use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class LibraryTableBase method commit.
private void commit(LibraryModel model) {
myFirstLoad = false;
ApplicationManager.getApplication().assertWriteAccessAllowed();
if (!model.isChanged()) {
Disposer.dispose(model);
return;
}
incrementModificationCount();
//todo[nik] remove LibraryImpl#equals method instead of using identity sets
Set<Library> addedLibraries = ContainerUtil.newIdentityTroveSet(model.myLibraries);
addedLibraries.removeAll(myModel.myLibraries);
Set<Library> removedLibraries = ContainerUtil.newIdentityTroveSet(myModel.myLibraries);
removedLibraries.removeAll(model.myLibraries);
for (Library library : removedLibraries) {
fireBeforeLibraryRemoved(library);
}
myModel.copyFrom(model);
for (Library library : removedLibraries) {
Disposer.dispose(library);
fireAfterLibraryRemoved(library);
}
for (Library library : addedLibraries) {
fireLibraryAdded(library);
}
Disposer.dispose(model);
}
use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class JpsLibraryTableImpl method createLibrary.
@Override
public Library createLibrary(@NonNls String name) {
final ModifiableModel model = getModifiableModel();
final Library library = model.createLibrary(name);
model.commit();
return library;
}
Aggregations