use of com.intellij.openapi.roots.impl.libraries.LibraryEx 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.impl.libraries.LibraryEx in project intellij-community by JetBrains.
the class RootModelImpl method addLibraryEntry.
@NotNull
@Override
public LibraryOrderEntry addLibraryEntry(@NotNull Library library) {
assertWritable();
final LibraryOrderEntry libraryOrderEntry = new LibraryOrderEntryImpl(library, this, myProjectRootManager);
if (!libraryOrderEntry.isValid()) {
LibraryEx libraryEx = ObjectUtils.tryCast(library, LibraryEx.class);
boolean libraryDisposed = libraryEx != null ? libraryEx.isDisposed() : Disposer.isDisposed(library);
throw new AssertionError("Invalid libraryOrderEntry, library: " + library + " of type " + library.getClass() + ", disposed: " + libraryDisposed + ", kind: " + (libraryEx != null ? libraryEx.getKind() : "<undefined>"));
}
myOrderEntries.add(libraryOrderEntry);
return libraryOrderEntry;
}
use of com.intellij.openapi.roots.impl.libraries.LibraryEx 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.impl.libraries.LibraryEx in project intellij-community by JetBrains.
the class LibraryItem method getTooltipText.
@Override
public String getTooltipText() {
if (myEntry == null)
return null;
final Library library = myEntry.getLibrary();
if (library == null)
return null;
final String name = library.getName();
if (name != null) {
final List<String> invalidUrls = ((LibraryEx) library).getInvalidRootUrls(OrderRootType.CLASSES);
if (!invalidUrls.isEmpty()) {
return ProjectBundle.message("project.roots.tooltip.library.has.broken.paths", name, invalidUrls.size());
}
}
final List<String> descriptions = LibraryPresentationManager.getInstance().getDescriptions(library, myContext);
if (descriptions.isEmpty())
return null;
return XmlStringUtil.wrapInHtml(StringUtil.join(descriptions, "<br>"));
}
use of com.intellij.openapi.roots.impl.libraries.LibraryEx in project intellij-community by JetBrains.
the class LibraryEditingUtil method getNotAddedSuitableLibrariesCondition.
public static Predicate<Library> getNotAddedSuitableLibrariesCondition(final ModuleRootModel rootModel, final FacetsProvider facetsProvider) {
final OrderEntry[] orderEntries = rootModel.getOrderEntries();
final Set<Library> result = new HashSet<>(orderEntries.length);
for (OrderEntry orderEntry : orderEntries) {
if (orderEntry instanceof LibraryOrderEntry && orderEntry.isValid()) {
final LibraryImpl library = (LibraryImpl) ((LibraryOrderEntry) orderEntry).getLibrary();
if (library != null) {
final Library source = library.getSource();
result.add(source != null ? source : library);
}
}
}
return new Predicate<Library>() {
@Override
public boolean apply(Library library) {
if (result.contains(library))
return false;
if (library instanceof LibraryImpl) {
final Library source = ((LibraryImpl) library).getSource();
if (source != null && result.contains(source))
return false;
}
PersistentLibraryKind<?> kind = ((LibraryEx) library).getKind();
if (kind != null) {
LibraryType type = LibraryType.findByKind(kind);
if (type != null && !type.isSuitableModule(rootModel.getModule(), facetsProvider)) {
return false;
}
}
return true;
}
};
}
Aggregations