com.intellij.openapi.roots.LibraryOrderEntry Java Examples

The following examples show how to use com.intellij.openapi.roots.LibraryOrderEntry. 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: SourceJarGenerator.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
public Collection<AttachSourcesAction> getActions(List<LibraryOrderEntry> orderEntries, PsiFile classFile) {
  JarMappings mappings = JarMappings.getInstance(classFile.getProject());

  return resolveJar(classFile).flatMap(jar -> {
    Optional<Set<AttachSourcesAction>> generateSourceJarForInternalDependency =
      mappings.findTargetForClassJar(jar)
        .flatMap(target -> mappings.findSourceJarForTarget(target)
          .map(sourceJar -> Collections.singleton(
            exists(sourceJar)
            ? new AttachExistingSourceJarAction(sourceJar)
            : new GenerateSourceJarAction(classFile, target, sourceJar))));

    Optional<Set<AttachSourcesAction>> attachSourceJarForLibrary =
      mappings.findSourceJarForLibraryJar(jar)
        .map(libraryJar -> Collections.singleton(new AttachExistingSourceJarAction(libraryJar)));

    return attachSourceJarForLibrary.map(Optional::of).orElse(generateSourceJarForInternalDependency);
  }).orElse(Collections.emptySet());
}
 
Example #2
Source File: NavBarPresentation.java    From consulo with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("MethodMayBeStatic")
@Nullable
public Icon getIcon(final Object object) {
  if (!NavBarModel.isValid(object)) return null;
  if (object instanceof Project) return AllIcons.Nodes.ProjectTab;
  if (object instanceof Module) return AllIcons.Nodes.Module;
  try {
    if (object instanceof PsiElement) {
      Icon icon = TargetAWT.to(AccessRule.read(() -> ((PsiElement)object).isValid() ? IconDescriptorUpdaters.getIcon(((PsiElement)object), 0) : null));

      if (icon != null && (icon.getIconHeight() > JBUI.scale(16) || icon.getIconWidth() > JBUI.scale(16))) {
        icon = IconUtil.cropIcon(icon, JBUI.scale(16), JBUI.scale(16));
      }
      return icon;
    }
  }
  catch (IndexNotReadyException e) {
    return null;
  }
  if (object instanceof ModuleExtensionWithSdkOrderEntry) {
    return TargetAWT.to(SdkUtil.getIcon(((ModuleExtensionWithSdkOrderEntry)object).getSdk()));
  }
  if (object instanceof LibraryOrderEntry) return AllIcons.Nodes.PpLibFolder;
  if (object instanceof ModuleOrderEntry) return AllIcons.Nodes.Module;
  return null;
}
 
Example #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
Source File: PantsIntegrationTestCase.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
protected void assertScalaLibrary(String moduleName) {
  OrderEntry[] entries = getRootManager(moduleName).getOrderEntries();
  List<String> libLists =
    Arrays.stream(entries).filter(s -> s instanceof LibraryOrderEntry).map(s -> ((LibraryOrderEntry) s).getLibraryName())
      .collect(Collectors.toList());
  assertContainsSubstring(libLists, "Pants: org.scala-lang:scala-library:");
}
 
Example #12
Source File: QuarkusModuleUtil.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
private static Integer computeHash(Module module) {
    ModuleRootManager manager = ModuleRootManager.getInstance(module);
    Set<String> files = manager.processOrder(new RootPolicy<Set<String>>() {
        @Override
        public Set<String> visitLibraryOrderEntry(@NotNull LibraryOrderEntry libraryOrderEntry, Set<String> value) {
            if (!libraryOrderEntry.getLibraryName().equalsIgnoreCase(QuarkusConstants.QUARKUS_DEPLOYMENT_LIBRARY_NAME) && isQuarkusExtensionWithDeploymentArtifact(libraryOrderEntry.getLibrary())) {
                for(VirtualFile file : libraryOrderEntry.getFiles(OrderRootType.CLASSES)) {
                    value.add(file.getPath());
                }
            }
            return value;
        }
    }, new HashSet<>());
    return files.isEmpty()?null:files.hashCode();
}
 
Example #13
Source File: SourceJarGenerator.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public ActionCallback perform(List<LibraryOrderEntry> orderEntriesContainingFile) {
  Collection<Library> libraries = orderEntriesContainingFile.stream()
    .map(LibraryOrderEntry::getLibrary)
    .filter(Objects::nonNull)
    .collect(Collectors.toSet());

  if (libraries.isEmpty()) return ActionCallback.REJECTED;
  return perform(libraries);
}
 
Example #14
Source File: ModuleLibraryTable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public Iterator<Library> getLibraryIterator() {
  FilteringIterator<OrderEntry, LibraryOrderEntry> filteringIterator =
    new FilteringIterator<OrderEntry, LibraryOrderEntry>(myRootLayer.getOrderIterator(), MODULE_LIBRARY_ORDER_ENTRY_FILTER);
  return new ConvertingIterator<LibraryOrderEntry, Library>(filteringIterator, ORDER_ENTRY_TO_LIBRARY_CONVERTOR);
}
 
Example #15
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 #16
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 #17
Source File: ProjectStructureConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public AsyncResult<Void> select(@Nonnull LibraryOrderEntry libraryOrderEntry, final boolean requestFocus) {
  final Library lib = libraryOrderEntry.getLibrary();
  if (lib == null || lib.getTable() == null) {
    return selectOrderEntry(libraryOrderEntry.getOwnerModule(), libraryOrderEntry);
  }
  Place place = createPlaceFor(getConfigurableFor(lib));
  place.putPath(BaseStructureConfigurable.TREE_NAME, libraryOrderEntry.getLibraryName());
  return navigateTo(place, requestFocus);
}
 
Example #18
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();
}
 
Example #19
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 #20
Source File: NamedLibraryElementNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(PresentationData presentation) {
  presentation.setPresentableText(getValue().getName());
  final OrderEntry orderEntry = getValue().getOrderEntry();

  if (orderEntry instanceof ModuleExtensionWithSdkOrderEntry) {
    final ModuleExtensionWithSdkOrderEntry sdkOrderEntry = (ModuleExtensionWithSdkOrderEntry)orderEntry;
    final Sdk sdk = sdkOrderEntry.getSdk();
    presentation.setIcon(SdkUtil.getIcon(((ModuleExtensionWithSdkOrderEntry)orderEntry).getSdk()));
    if (sdk != null) { //jdk not specified
      final String path = sdk.getHomePath();
      if (path != null) {
        presentation.setLocationString(FileUtil.toSystemDependentName(path));
      }
    }
    presentation.setTooltip(null);
  }
  else if (orderEntry instanceof LibraryOrderEntry) {
    presentation.setIcon(getIconForLibrary(orderEntry));
    presentation.setTooltip(StringUtil.capitalize(IdeBundle.message("node.projectview.library", ((LibraryOrderEntry)orderEntry).getLibraryLevel())));
  }
  else if(orderEntry instanceof OrderEntryWithTracking) {
    Image icon = null;
    CellAppearanceEx cellAppearance = OrderEntryAppearanceService.getInstance().forOrderEntry(orderEntry);
    if(cellAppearance instanceof ModifiableCellAppearanceEx) {
      icon = ((ModifiableCellAppearanceEx)cellAppearance).getIcon();
    }
    presentation.setIcon(icon == null ? AllIcons.Toolbar.Unknown : icon);
  }
}
 
Example #21
Source File: NamedLibraryElementNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static Image getIconForLibrary(OrderEntry orderEntry) {
  if (orderEntry instanceof LibraryOrderEntry) {
    Library library = ((LibraryOrderEntry)orderEntry).getLibrary();
    if (library != null) {
      return LibraryPresentationManager.getInstance().getNamedLibraryIcon(library, null);
    }
  }
  return AllIcons.Nodes.PpLib;
}
 
Example #22
Source File: BlazeSourceJarNavigationPolicy.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
private Library findLibrary(Project project, PsiJavaFile clsFile) {
  OrderEntry libraryEntry = LibraryUtil.findLibraryEntry(clsFile.getVirtualFile(), project);
  if (!(libraryEntry instanceof LibraryOrderEntry)) {
    return null;
  }
  return ((LibraryOrderEntry) libraryEntry).getLibrary();
}
 
Example #23
Source File: LibraryActionHelper.java    From intellij with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the first {@link LibraryOrderEntry} containing this file, or null if none are found.
 */
@Nullable
public static LibraryOrderEntry findLibraryForFile(VirtualFile vf, @NotNull Project project) {
  ProjectFileIndex index = ProjectFileIndex.SERVICE.getInstance(project);
  return index.getOrderEntriesForFile(vf).stream()
      .filter(e -> e instanceof LibraryOrderEntry)
      .map(e -> (LibraryOrderEntry) e)
      .findFirst()
      .orElse(null);
}
 
Example #24
Source File: QuarkusModuleUtil.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Check if the module is a Quarkus project. Should check if some class if present
 * but it seems PSI is not available when the module is added thus we rely on the
 * library names.
 *
 * @param module the module to check
 * @return yes if module is a Quarkus project
 */
public static boolean isQuarkusModule(Module module) {
    OrderEnumerator libraries = ModuleRootManager.getInstance(module).orderEntries().librariesOnly();
    return libraries.process(new RootPolicy<Boolean>() {
        @Override
        public Boolean visitLibraryOrderEntry(@NotNull LibraryOrderEntry libraryOrderEntry, Boolean value) {
            return value | isQuarkusLibrary(libraryOrderEntry);
        }
    }, false);
}
 
Example #25
Source File: MavenImportingTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
protected void assertModuleLibDep(String moduleName, String depName, String classesPath, String sourcePath, String javadocPath) {
  LibraryOrderEntry lib = getModuleLibDep(moduleName, depName);

  assertModuleLibDepPath(lib, OrderRootType.CLASSES, classesPath == null ? null : Collections.singletonList(classesPath));
  assertModuleLibDepPath(lib, OrderRootType.SOURCES, sourcePath == null ? null : Collections.singletonList(sourcePath));
  assertModuleLibDepPath(lib, JavadocOrderRootType.getInstance(), javadocPath == null ? null : Collections.singletonList(javadocPath));
}
 
Example #26
Source File: MavenImportingTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
protected void assertModuleLibDep(String moduleName,
                                  String depName,
                                  List<String> classesPaths,
                                  List<String> sourcePaths,
                                  List<String> javadocPaths) {
  LibraryOrderEntry lib = getModuleLibDep(moduleName, depName);

  assertModuleLibDepPath(lib, OrderRootType.CLASSES, classesPaths);
  assertModuleLibDepPath(lib, OrderRootType.SOURCES, sourcePaths);
  assertModuleLibDepPath(lib, JavadocOrderRootType.getInstance(), javadocPaths);
}
 
Example #27
Source File: CamelService.java    From camel-idea-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * Scan for Camel project present and setup {@link CamelCatalog} to use same version of Camel as the project does.
 * These two version needs to be aligned to offer the best tooling support on the given project.
 */
public void scanForCamelProject(@NotNull Project project, @NotNull Module module) {
    for (OrderEntry entry : ModuleRootManager.getInstance(module).getOrderEntries()) {
        if (!(entry instanceof LibraryOrderEntry)) {
            continue;
        }
        LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) entry;

        String name = libraryOrderEntry.getPresentableName().toLowerCase();
        if (!libraryOrderEntry.getScope().isForProductionCompile() && !libraryOrderEntry.getScope().isForProductionRuntime()) {
            continue;
        }
        final Library library = libraryOrderEntry.getLibrary();
        if (library == null) {
            continue;
        }
        String[] split = name.split(":");
        if (split.length < 3) {
            continue;
        }
        int startIdx = 0;
        if (split[0].equalsIgnoreCase("maven")
                || split[0].equalsIgnoreCase("gradle")
                || split[0].equalsIgnoreCase("sbt")) {
            startIdx = 1;
        }
        boolean hasVersion = split.length > (startIdx + 2);

        String groupId = split[startIdx++].trim();
        String artifactId = split[startIdx++].trim();
        String version = null;
        if (hasVersion) {
            version = split[startIdx].trim();
            // adjust snapshot which must be in uppercase
            version = version.replace("snapshot", "SNAPSHOT");
        }

        projectLibraries.add(library);

        if (isSlf4jMavenDependency(groupId, artifactId)) {
            slf4japiLibrary = library;
        } else if (isCamelCoreMavenDependency(groupId, artifactId)) {
            camelCoreLibrary = library;

            // okay its a camel project
            setCamelPresent(true);

            String currentVersion = getCamelCatalogService(project).get().getLoadedVersion();
            if (currentVersion == null) {
                // okay no special version was loaded so its the catalog version we are using
                currentVersion = getCamelCatalogService(project).get().getCatalogVersion();
            }
            if (isThereDifferentVersionToBeLoaded(version, currentVersion)) {
                boolean notifyNewCamelCatalogVersionLoaded = false;

                boolean downloadAllowed = getCamelPreferenceService().isDownloadCatalog();
                if (downloadAllowed) {
                    notifyNewCamelCatalogVersionLoaded = downloadNewCamelCatalogVersion(project, module, version, notifyNewCamelCatalogVersionLoaded);
                }

                if (notifyNewCamelCatalogVersionLoaded(notifyNewCamelCatalogVersionLoaded)) {
                    expireOldCamelCatalogVersion();
                }
            }

            // only notify this once on startup (or if a new version was successfully loaded)
            if (camelVersionNotification == null) {
                currentVersion = getCamelCatalogService(project).get().getLoadedVersion();
                if (currentVersion == null) {
                    // okay no special version was loaded so its the catalog version we are using
                    currentVersion = getCamelCatalogService(project).get().getCatalogVersion();
                }
                showCamelCatalogVersionAtPluginStart(project, currentVersion);
            }
        }
    }
}
 
Example #28
Source File: GradleToolDelegate.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
private boolean isDependency(ModuleRootManager manager, String deploymentIdStr) {
    return Stream.of(manager.getOrderEntries()).filter(entry -> entry instanceof LibraryOrderEntry && (GRADLE_LIBRARY_PREFIX + deploymentIdStr).equals(((LibraryOrderEntry)entry).getLibraryName())).findFirst().isPresent();
}
 
Example #29
Source File: QuarkusModuleUtil.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
public static boolean isQuarkusLibrary(@NotNull LibraryOrderEntry libraryOrderEntry) {
    return libraryOrderEntry != null &&
            libraryOrderEntry.getLibraryName() != null &&
            libraryOrderEntry.getLibraryName().contains("io.quarkus:quarkus-core:");
}
 
Example #30
Source File: MavenImportingTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
private static void assertModuleLibDepPath(LibraryOrderEntry lib, OrderRootType type, List<String> paths) {
  if (paths == null) return;
  assertUnorderedPathsAreEqual(Arrays.asList(lib.getRootUrls(type)), paths);
  // also check the library because it may contain slight different set of urls (e.g. with duplicates)
  assertUnorderedPathsAreEqual(Arrays.asList(lib.getLibrary().getUrls(type)), paths);
}