com.intellij.openapi.roots.OrderEntry Java Examples

The following examples show how to use com.intellij.openapi.roots.OrderEntry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PsiDirectoryNode.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@RequiredUIAccess
public void navigate(final boolean requestFocus) {
  Module module = ModuleUtil.findModuleForPsiElement(getValue());
  if (module != null) {
    final VirtualFile file = getVirtualFile();
    final Project project = getProject();
    ProjectSettingsService service = ProjectSettingsService.getInstance(myProject);
    if (ProjectRootsUtil.isModuleContentRoot(file, project)) {
      service.openModuleSettings(module);
    }
    else if (ProjectRootsUtil.isLibraryRoot(file, project)) {
      final OrderEntry orderEntry = LibraryUtil.findLibraryEntry(file, module.getProject());
      if (orderEntry != null) {
        service.openLibraryOrSdkSettings(orderEntry);
      }
    }
    else {
      service.openContentEntriesSettings(module);
    }
  }
}
 
Example #2
Source File: AbstractLibraryManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected static void removeFlutterLibraryDependency(@NotNull Module module, @NotNull Library library) {
  final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();

  try {
    boolean wasFound = false;

    for (final OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
      if (orderEntry instanceof LibraryOrderEntry &&
          LibraryTablesRegistrar.PROJECT_LEVEL.equals(((LibraryOrderEntry)orderEntry).getLibraryLevel()) &&
          StringUtil.equals(library.getName(), ((LibraryOrderEntry)orderEntry).getLibraryName())) {
        wasFound = true;
        modifiableModel.removeOrderEntry(orderEntry);
      }
    }

    if (wasFound) {
      ApplicationManager.getApplication().invokeAndWait(() -> WriteAction.run(modifiableModel::commit));
    }
  }
  finally {
    if (!modifiableModel.isDisposed()) {
      modifiableModel.dispose();
    }
  }
}
 
Example #3
Source File: AbstractLibraryManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected static void addFlutterLibraryDependency(@NotNull Module module, @NotNull Library library) {
  final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();

  try {
    for (final OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
      if (orderEntry instanceof LibraryOrderEntry &&
          LibraryTablesRegistrar.PROJECT_LEVEL.equals(((LibraryOrderEntry)orderEntry).getLibraryLevel()) &&
          StringUtil.equals(library.getName(), ((LibraryOrderEntry)orderEntry).getLibraryName())) {
        return; // dependency already exists
      }
    }

    modifiableModel.addLibraryEntry(library);

    ApplicationManager.getApplication().invokeAndWait(() -> WriteAction.run(modifiableModel::commit));
  }
  finally {
    if (!modifiableModel.isDisposed()) {
      modifiableModel.dispose();
    }
  }
}
 
Example #4
Source File: AbstractLibraryManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected static void removeFlutterLibraryDependency(@NotNull Module module, @NotNull Library library) {
  final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();

  try {
    boolean wasFound = false;

    for (final OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
      if (orderEntry instanceof LibraryOrderEntry &&
          LibraryTablesRegistrar.PROJECT_LEVEL.equals(((LibraryOrderEntry)orderEntry).getLibraryLevel()) &&
          StringUtil.equals(library.getName(), ((LibraryOrderEntry)orderEntry).getLibraryName())) {
        wasFound = true;
        modifiableModel.removeOrderEntry(orderEntry);
      }
    }

    if (wasFound) {
      ApplicationManager.getApplication().invokeAndWait(() -> WriteAction.run(modifiableModel::commit));
    }
  }
  finally {
    if (!modifiableModel.isDisposed()) {
      modifiableModel.dispose();
    }
  }
}
 
Example #5
Source File: AbstractLibraryManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected static void addFlutterLibraryDependency(@NotNull Module module, @NotNull Library library) {
  final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();

  try {
    for (final OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
      if (orderEntry instanceof LibraryOrderEntry &&
          LibraryTablesRegistrar.PROJECT_LEVEL.equals(((LibraryOrderEntry)orderEntry).getLibraryLevel()) &&
          StringUtil.equals(library.getName(), ((LibraryOrderEntry)orderEntry).getLibraryName())) {
        return; // dependency already exists
      }
    }

    modifiableModel.addLibraryEntry(library);

    ApplicationManager.getApplication().invokeAndWait(() -> WriteAction.run(modifiableModel::commit));
  }
  finally {
    if (!modifiableModel.isDisposed()) {
      modifiableModel.dispose();
    }
  }
}
 
Example #6
Source File: OrderEntrySerializationUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public static OrderEntry loadOrderEntry(@Nonnull Element element, @Nonnull ModuleRootLayer moduleRootLayer) {
  String type = element.getAttributeValue(ORDER_ENTRY_TYPE_ATTR);
  if(type == null) {
    return null;
  }
  OrderEntryType orderEntryType = getProvidersAsMap().get(type);
  if(orderEntryType == null) {
    return new UnknownOrderEntryImpl(new UnknownOrderEntryType(type, element), (ModuleRootLayerImpl)moduleRootLayer);
  }

  try {
    return orderEntryType.loadOrderEntry(element, moduleRootLayer);
  }
  catch (InvalidDataException e) {
    return new UnknownOrderEntryImpl(new UnknownOrderEntryType(type, element), (ModuleRootLayerImpl)moduleRootLayer);
  }
}
 
Example #7
Source File: ModuleLibraryTable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void removeLibrary(@Nonnull Library library) {
  final Iterator<OrderEntry> orderIterator = myRootLayer.getOrderIterator();
  while (orderIterator.hasNext()) {
    OrderEntry orderEntry = orderIterator.next();
    if (orderEntry instanceof LibraryOrderEntry) {
      final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) orderEntry;
      if (libraryOrderEntry.isModuleLevel()) {
        if (library.equals(libraryOrderEntry.getLibrary())) {
          myRootLayer.removeOrderEntry(orderEntry);
          //Disposer.dispose(library);
          return;
        }
      }
    }
  }
}
 
Example #8
Source File: ModuleGroupingRule.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public UsageGroup groupUsage(@Nonnull Usage usage) {
  if (usage instanceof UsageInModule) {
    UsageInModule usageInModule = (UsageInModule)usage;
    Module module = usageInModule.getModule();
    if (module != null) return new ModuleUsageGroup(module);
  }

  if (usage instanceof UsageInLibrary) {
    UsageInLibrary usageInLibrary = (UsageInLibrary)usage;
    OrderEntry entry = usageInLibrary.getLibraryEntry();
    if (entry != null) return new LibraryUsageGroup(entry);
  }

  return null;
}
 
Example #9
Source File: ModuleStructureConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void addLibraryOrderEntry(final Module module, final Library library) {
  Component parent = TargetAWT.to(WindowManager.getInstance().suggestParentWindow(module.getProject()));

  final ModuleEditor moduleEditor = myContext.myModulesConfigurator.getModuleEditor(module);
  LOG.assertTrue(moduleEditor != null, "Current module editor was not initialized");
  final ModifiableRootModel modelProxy = moduleEditor.getModifiableRootModelProxy();
  final OrderEntry[] entries = modelProxy.getOrderEntries();
  for (OrderEntry entry : entries) {
    if (entry instanceof LibraryOrderEntry && Comparing.strEqual(entry.getPresentableName(), library.getName())) {
      if (Messages.showYesNoDialog(parent,
                                   ProjectBundle.message("project.roots.replace.library.entry.message", entry.getPresentableName()),
                                   ProjectBundle.message("project.roots.replace.library.entry.title"),
                                   Messages.getInformationIcon()) == Messages.YES) {
        modelProxy.removeOrderEntry(entry);
        break;
      }
    }
  }
  modelProxy.addLibraryEntry(library);
  myContext.getDaemonAnalyzer().queueUpdate(new ModuleProjectStructureElement(myContext, module));
  myTree.repaint();
}
 
Example #10
Source File: ModuleDeleteProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void removeModule(@Nonnull final Module moduleToRemove,
                                 @Nullable ModifiableRootModel modifiableRootModelToRemove,
                                 @Nonnull Collection<ModifiableRootModel> otherModuleRootModels,
                                 @Nonnull final ModifiableModuleModel moduleModel) {
  // remove all dependencies on the module that is about to be removed
  for (final ModifiableRootModel modifiableRootModel : otherModuleRootModels) {
    final OrderEntry[] orderEntries = modifiableRootModel.getOrderEntries();
    for (final OrderEntry orderEntry : orderEntries) {
      if (orderEntry instanceof ModuleOrderEntry && orderEntry.isValid()) {
        final Module orderEntryModule = ((ModuleOrderEntry)orderEntry).getModule();
        if (orderEntryModule != null && orderEntryModule.equals(moduleToRemove)) {
          modifiableRootModel.removeOrderEntry(orderEntry);
        }
      }
    }
  }
  // destroyProcess editor
  if (modifiableRootModelToRemove != null) {
    modifiableRootModelToRemove.dispose();
  }
  // destroyProcess module
  moduleModel.disposeModule(moduleToRemove);
}
 
Example #11
Source File: ModuleStructureConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
public AsyncResult<Void> selectOrderEntry(@Nonnull final Module module, @Nullable final OrderEntry orderEntry) {
  Place p = new Place();
  p.putPath(ProjectStructureConfigurable.CATEGORY, this);
  Runnable r = null;

  final MasterDetailsComponent.MyNode node = findModuleNode(module);
  if (node != null) {
    p.putPath(TREE_OBJECT, module);
    p.putPath(ModuleEditor.SELECTED_EDITOR_NAME, ClasspathEditor.NAME);
    r = new Runnable() {
      @Override
      public void run() {
        if (orderEntry != null) {
          ModuleEditor moduleEditor = ((ModuleConfigurable)node.getConfigurable()).getModuleEditor();
          ModuleConfigurationEditor editor = moduleEditor.getEditor(ClasspathEditor.NAME);
          if (editor instanceof ClasspathEditor) {
            ((ClasspathEditor)editor).selectOrderEntry(orderEntry);
          }
        }
      }
    };
  }
  final AsyncResult<Void> result = ProjectStructureConfigurable.getInstance(myProject).navigateTo(p, true);
  return r != null ? result.doWhenDone(r) : result;
}
 
Example #12
Source File: LibraryPackagingElement.java    From consulo with Apache License 2.0 6 votes vote down vote up
@javax.annotation.Nullable
public Library findLibrary(@Nonnull PackagingElementResolvingContext context) {
  if (myModuleName == null) {
    return context.findLibrary(myLevel, myLibraryName);
  }
  final ModulesProvider modulesProvider = context.getModulesProvider();
  final Module module = modulesProvider.getModule(myModuleName);
  if (module != null) {
    for (OrderEntry entry : modulesProvider.getRootModel(module).getOrderEntries()) {
      if (entry instanceof LibraryOrderEntry) {
        final LibraryOrderEntry libraryEntry = (LibraryOrderEntry)entry;
        if (libraryEntry.isModuleLevel()) {
          final String libraryName = libraryEntry.getLibraryName();
          if (libraryName != null && libraryName.equals(myLibraryName)) {
            return libraryEntry.getLibrary();
          }
        }
      }
    }
  }
  return null;
}
 
Example #13
Source File: ProjectRootManagerComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void addRootsFromModules(boolean includeSourceRoots, Set<String> recursive, Set<String> flat) {
  final Module[] modules = ModuleManager.getInstance(myProject).getModules();
  for (Module module : modules) {
    final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);

    addRootsToTrack(moduleRootManager.getContentRootUrls(), recursive, flat);

    if (includeSourceRoots) {
      addRootsToTrack(moduleRootManager.getContentFolderUrls(ContentFolderScopes.all(false)), recursive, flat);
    }

    final OrderEntry[] orderEntries = moduleRootManager.getOrderEntries();
    for (OrderEntry entry : orderEntries) {
      if (entry instanceof OrderEntryWithTracking) {
        for (OrderRootType orderRootType : OrderRootType.getAllTypes()) {
          addRootsToTrack(entry.getUrls(orderRootType), recursive, flat);
        }
      }
    }
  }
}
 
Example #14
Source File: DirectoryPathMatcher.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static List<Pair<VirtualFile, String>> getProjectRoots(GotoFileModel model) {
  Set<VirtualFile> roots = new HashSet<>();
  for (Module module : ModuleManager.getInstance(model.getProject()).getModules()) {
    Collections.addAll(roots, ModuleRootManager.getInstance(module).getContentRoots());
    for (OrderEntry entry : ModuleRootManager.getInstance(module).getOrderEntries()) {
      if (entry instanceof OrderEntryWithTracking) {
        Collections.addAll(roots, entry.getFiles(OrderRootType.CLASSES));
        Collections.addAll(roots, entry.getFiles(OrderRootType.SOURCES));
      }
    }
  }
  return roots.stream().map(root -> {
    VirtualFile top = model.getTopLevelRoot(root);
    return top != null ? top : root;
  }).distinct().map(r -> Pair.create(r, StringUtil.notNullize(model.getFullName(r)))).collect(Collectors.toList());
}
 
Example #15
Source File: ChooseLibrariesDialogBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void collectChildren(Object element, final List<Object> result) {
  if (element instanceof Application) {
    Collections.addAll(result, ProjectManager.getInstance().getOpenProjects());
    final LibraryTablesRegistrar instance = LibraryTablesRegistrar.getInstance();
    result.add(instance.getLibraryTable()); //1
    result.addAll(instance.getCustomLibraryTables()); //2
  }
  else if (element instanceof Project) {
    Collections.addAll(result, ModuleManager.getInstance((Project)element).getModules());
    result.add(LibraryTablesRegistrar.getInstance().getLibraryTable((Project)element));
  }
  else if (element instanceof LibraryTable) {
    Collections.addAll(result, ((LibraryTable)element).getLibraries());
  }
  else if (element instanceof Module) {
    for (OrderEntry entry : ModuleRootManager.getInstance((Module)element).getOrderEntries()) {
      if (entry instanceof LibraryOrderEntry) {
        final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry)entry;
        if (LibraryTableImplUtil.MODULE_LEVEL.equals(libraryOrderEntry.getLibraryLevel())) {
          final Library library = libraryOrderEntry.getLibrary();
          result.add(library);
        }
      }
    }
  }
}
 
Example #16
Source File: FindInProjectUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void addSourceDirectoriesFromLibraries(@Nonnull Project project, @Nonnull VirtualFile directory, @Nonnull Collection<? super VirtualFile> outSourceRoots) {
  ProjectFileIndex index = ProjectFileIndex.SERVICE.getInstance(project);
  // if we already are in the sources, search just in this directory only
  if (!index.isInLibraryClasses(directory)) return;
  VirtualFile classRoot = index.getClassRootForFile(directory);
  if (classRoot == null) return;
  String relativePath = VfsUtilCore.getRelativePath(directory, classRoot);
  if (relativePath == null) return;

  Collection<VirtualFile> otherSourceRoots = new THashSet<>();

  // if we are in the library sources, return (to search in this directory only)
  // otherwise, if we outside sources or in a jar directory, add directories from other source roots
  searchForOtherSourceDirs:
  for (OrderEntry entry : index.getOrderEntriesForFile(directory)) {
    if (entry instanceof LibraryOrderEntry) {
      Library library = ((LibraryOrderEntry)entry).getLibrary();
      if (library == null) continue;
      // note: getUrls() returns jar directories too
      String[] sourceUrls = library.getUrls(OrderRootType.SOURCES);
      for (String sourceUrl : sourceUrls) {
        if (VfsUtilCore.isEqualOrAncestor(sourceUrl, directory.getUrl())) {
          // already in this library sources, no need to look for another source root
          otherSourceRoots.clear();
          break searchForOtherSourceDirs;
        }
        // otherwise we may be inside the jar file in a library which is configured as a jar directory
        // in which case we have no way to know whether this is a source jar or classes jar - so try to locate the source jar
      }
    }
    for (VirtualFile sourceRoot : entry.getFiles(OrderRootType.SOURCES)) {
      VirtualFile sourceFile = sourceRoot.findFileByRelativePath(relativePath);
      if (sourceFile != null) {
        otherSourceRoots.add(sourceFile);
      }
    }
  }
  outSourceRoots.addAll(otherSourceRoots);
}
 
Example #17
Source File: SdkOrLibraryWeigher.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean isSdkElement(PsiElement element, @Nonnull final Project project) {
  final VirtualFile file = PsiUtilCore.getVirtualFile(element);
  if (file != null) {
    List<OrderEntry> orderEntries = ProjectRootManager.getInstance(project).getFileIndex().getOrderEntriesForFile(file);
    if (!orderEntries.isEmpty() && orderEntries.get(0) instanceof ModuleExtensionWithSdkOrderEntry) {
      return true;
    }
  }
  return false;
}
 
Example #18
Source File: FlutterUtils.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
private static ModuleSourceOrderEntry findModuleSourceEntry(@NotNull Module module) {
  ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
  OrderEntry[] orderEntries = moduleRootManager.getOrderEntries();
  for (OrderEntry entry : orderEntries) {
    if (entry instanceof ModuleSourceOrderEntry) {
      return (ModuleSourceOrderEntry)entry;
    }
  }
  return null;
}
 
Example #19
Source File: OrderEntryAppearanceServiceImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
@SuppressWarnings("unchecked")
public CellAppearanceEx forOrderEntry(@Nonnull OrderEntry orderEntry) {
  OrderEntryType<?> type = orderEntry.getType();
  OrderEntryTypeEditor editor = OrderEntryTypeEditor.FACTORY.getByKey(type);
  if(editor != null) {
    return editor.getCellAppearance(orderEntry);
  }
  return new SimpleTextCellAppearance(orderEntry.getPresentableName(), null, SimpleTextAttributes.REGULAR_ATTRIBUTES);
}
 
Example #20
Source File: LibraryNavigatable.java    From consulo with Apache License 2.0 5 votes vote down vote up
public LibraryNavigatable(@Nonnull Library library, @Nonnull Module module) {
  this.module = module;
  for (OrderEntry entry : ModuleRootManager.getInstance(module).getOrderEntries()) {
    if (entry instanceof LibraryOrderEntry) {
      if (((LibraryOrderEntry)entry).getLibrary() == library) {
        element = entry;
      }
    }
  }
}
 
Example #21
Source File: DocumentationComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
private String getLocationText() {
  PsiElement element = getElement();
  if (element != null) {
    PsiFile file = element.getContainingFile();
    VirtualFile vfile = file == null ? null : file.getVirtualFile();

    if (vfile == null) return null;

    ProjectFileIndex fileIndex = ProjectRootManager.getInstance(element.getProject()).getFileIndex();
    Module module = fileIndex.getModuleForFile(vfile);

    if (module != null) {
      if (ModuleManager.getInstance(element.getProject()).getModules().length == 1) return null;
      return "<icon src='/actions/module.png'>&nbsp;" + module.getName().replace("<", "&lt;");
    }
    else {
      List<OrderEntry> entries = fileIndex.getOrderEntriesForFile(vfile);
      for (OrderEntry order : entries) {
        if (order instanceof OrderEntryWithTracking) {
          return "<icon src='AllIcons.Nodes.PpLibFolder" + "'>&nbsp;" + order.getPresentableName().replace("<", "&lt;");
        }
      }
    }
  }

  return null;
}
 
Example #22
Source File: AddModuleDependencyTabContext.java    From consulo with Apache License 2.0 5 votes vote down vote up
public final void processAddOrderEntries(DialogWrapper dialogWrapper) {
  ModifiableModuleRootLayer currentLayer = (ModifiableModuleRootLayer)myClasspathPanel.getRootModel().getCurrentLayer();

  List<OrderEntry> orderEntries = createOrderEntries(currentLayer, dialogWrapper);
  if(orderEntries.isEmpty()) {
    return;
  }

  List<ClasspathTableItem<?>> items = new ArrayList<ClasspathTableItem<?>>(orderEntries.size());
  for (OrderEntry orderEntry : orderEntries) {
    ClasspathTableItem<?> item = ClasspathTableItem.createItem(orderEntry, myContext);
    items.add(item);
  }
  myClasspathPanel.addItems(items);
}
 
Example #23
Source File: ModuleDependencyTabContext.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public List<OrderEntry> createOrderEntries(@Nonnull ModifiableModuleRootLayer layer, DialogWrapper dialogWrapper) {
  Object[] selectedValues = myModuleList.getSelectedValues();
  List<OrderEntry> orderEntries = new ArrayList<OrderEntry>(selectedValues.length);
  for (Object selectedValue : selectedValues) {
    orderEntries.add(layer.addModuleOrderEntry((Module)selectedValue));
  }
  return orderEntries;
}
 
Example #24
Source File: DvcsUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
private static VirtualFile getVcsRootForLibraryFile(@Nonnull Project project, @Nonnull VirtualFile file) {
  ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
  // for a file inside .jar/.zip consider the .jar/.zip file itself
  VirtualFile root = vcsManager.getVcsRootFor(VfsUtilCore.getVirtualFileForJar(file));
  if (root != null) {
    LOGGER.debug("Found root for zip/jar file: " + root);
    return root;
  }

  // for other libs which don't have jars inside the project dir (such as JDK) take the owner module of the lib
  List<OrderEntry> entries = ProjectRootManager.getInstance(project).getFileIndex().getOrderEntriesForFile(file);
  Set<VirtualFile> libraryRoots = new HashSet<>();
  for (OrderEntry entry : entries) {
    if (entry instanceof LibraryOrderEntry || entry instanceof ModuleExtensionWithSdkOrderEntry) {
      VirtualFile moduleRoot = vcsManager.getVcsRootFor(entry.getOwnerModule().getModuleDir());
      if (moduleRoot != null) {
        libraryRoots.add(moduleRoot);
      }
    }
  }

  if (libraryRoots.size() == 0) {
    LOGGER.debug("No library roots");
    return null;
  }

  // if the lib is used in several modules, take the top module
  // (for modules of the same level we can't guess anything => take the first one)
  Iterator<VirtualFile> libIterator = libraryRoots.iterator();
  VirtualFile topLibraryRoot = libIterator.next();
  while (libIterator.hasNext()) {
    VirtualFile libRoot = libIterator.next();
    if (VfsUtilCore.isAncestor(libRoot, topLibraryRoot, true)) {
      topLibraryRoot = libRoot;
    }
  }
  LOGGER.debug("Several library roots, returning " + topLibraryRoot);
  return topLibraryRoot;
}
 
Example #25
Source File: ProjectUtilCore.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static String displayUrlRelativeToProject(@Nonnull VirtualFile file,
                                                 @Nonnull String url,
                                                 @Nonnull Project project,
                                                 boolean includeFilePath,
                                                 boolean keepModuleAlwaysOnTheLeft) {
  final VirtualFile baseDir = project.getBaseDir();
  if (baseDir != null && includeFilePath) {
    //noinspection ConstantConditions
    final String projectHomeUrl = baseDir.getPresentableUrl();
    if (url.startsWith(projectHomeUrl)) {
      url = "..." + url.substring(projectHomeUrl.length());
    }
  }

  if (SystemInfo.isMac && file.getFileSystem() instanceof LocalFileProvider) {
    final VirtualFile fileForJar = ((LocalFileProvider)file.getFileSystem()).getLocalVirtualFileFor(file);
    if (fileForJar != null) {
      final OrderEntry libraryEntry = LibraryUtil.findLibraryEntry(file, project);
      if (libraryEntry != null) {
        if (libraryEntry instanceof ModuleExtensionWithSdkOrderEntry) {
          url = url + " - [" + ((ModuleExtensionWithSdkOrderEntry)libraryEntry).getSdkName() + "]";
        }
        else {
          url = url + " - [" + libraryEntry.getPresentableName() + "]";
        }
      }
      else {
        url = url + " - [" + fileForJar.getName() + "]";
      }
    }
  }

  final Module module = ModuleUtilCore.findModuleForFile(file, project);
  if (module == null) return url;
  return !keepModuleAlwaysOnTheLeft && SystemInfo.isMac ?
         url + " - [" + module.getName() + "]" :
         "[" + module.getName() + "] - " + url;
}
 
Example #26
Source File: ModuleChunk.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean value(OrderEntry orderEntry) {
  if (orderEntry instanceof ModuleExtensionWithSdkOrderEntry) {
    final Sdk sdk = ((ModuleExtensionWithSdkOrderEntry)orderEntry).getSdk();
    if(sdk == null || sdk.getSdkType() != mySdkType) {
      return true;
    }

    mySdkFound = true;
    return false;
  }
  return mySdkFound;
}
 
Example #27
Source File: ModuleChunk.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean value(OrderEntry orderEntry) {
  if (orderEntry instanceof ModuleExtensionWithSdkOrderEntry && myOwnerModule.equals(orderEntry.getOwnerModule())) {
    final Sdk sdk = ((ModuleExtensionWithSdkOrderEntry)orderEntry).getSdk();
    if(sdk == null || sdk.getSdkType() != mySdkType) {
      return true;
    }

    mySdkFound = true;
  }
  return !mySdkFound;
}
 
Example #28
Source File: ModuleChunk.java    From consulo with Apache License 2.0 5 votes vote down vote up
private OrderEnumerator orderEnumerator(Module module, boolean exportedOnly, Condition<OrderEntry> condition) {
  OrderEnumerator enumerator = OrderEnumerator.orderEntries(module).compileOnly().satisfying(condition);
  if ((mySourcesFilter & TEST_SOURCES) == 0) {
    enumerator = enumerator.productionOnly();
  }
  enumerator = enumerator.recursively();
  return exportedOnly ? enumerator.exportedOnly() : enumerator;
}
 
Example #29
Source File: MavenImportingTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
private List<String> collectModuleDepsNames(String moduleName, Class clazz) {
  List<String> actual = new ArrayList<>();

  for (OrderEntry e : getRootManager(moduleName).getOrderEntries()) {
    if (clazz.isInstance(e)) {
      actual.add(e.getPresentableName());
    }
  }
  return actual;
}
 
Example #30
Source File: ModuleStructureConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void removeLibraryOrderEntry(final Module module, final Library library) {
  final ModuleEditor moduleEditor = myContext.myModulesConfigurator.getModuleEditor(module);
  LOG.assertTrue(moduleEditor != null, "Current module editor was not initialized");
  final ModifiableRootModel modelProxy = moduleEditor.getModifiableRootModelProxy();
  final OrderEntry[] entries = modelProxy.getOrderEntries();
  for (OrderEntry entry : entries) {
    if (entry instanceof LibraryOrderEntry && Comparing.strEqual(entry.getPresentableName(), library.getName())) {
      modelProxy.removeOrderEntry(entry);
      break;
    }
  }

  myContext.getDaemonAnalyzer().queueUpdate(new ModuleProjectStructureElement(myContext, module));
  myTree.repaint();
}