consulo.roots.types.BinariesOrderRootType Java Examples

The following examples show how to use consulo.roots.types.BinariesOrderRootType. 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: ModuleLibraryOrderEntryImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public String getPresentableName() {
  final String name = myLibrary.getName();
  if (name != null) {
    return name;
  }
  else {
    if (myLibrary instanceof LibraryEx && ((LibraryEx)myLibrary).isDisposed()) {
      return "<unknown>";
    }

    final String[] urls = myLibrary.getUrls(BinariesOrderRootType.getInstance());
    if (urls.length > 0) {
      String url = urls[0];
      return PathUtil.toPresentableUrl(url);
    }
    else {
      return ProjectBundle.message("library.empty.library.item");
    }
  }
}
 
Example #2
Source File: PsiTestUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void addProjectLibrary(final Module module,
                                      final ModifiableRootModel model,
                                      final String libName,
                                      final VirtualFile... classesRoots) {
  new WriteCommandAction.Simple(module.getProject()) {
    @Override
    protected void run() throws Throwable {
      final LibraryTable libraryTable = ProjectLibraryTable.getInstance(module.getProject());
      final Library library = libraryTable.createLibrary(libName);
      final Library.ModifiableModel libraryModel = library.getModifiableModel();
      for (VirtualFile root : classesRoots) {
        libraryModel.addRoot(root, BinariesOrderRootType.getInstance());
      }
      libraryModel.commit();
      model.addLibraryEntry(library);
      final OrderEntry[] orderEntries = model.getOrderEntries();
      OrderEntry last = orderEntries[orderEntries.length - 1];
      System.arraycopy(orderEntries, 0, orderEntries, 1, orderEntries.length - 1);
      orderEntries[0] = last;
      model.rearrangeOrderEntries(orderEntries);
    }
  }.execute().throwException();
}
 
Example #3
Source File: OrderEntryAppearanceServiceImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public CellAppearanceEx forLibrary(Project project, @Nonnull final Library library, final boolean hasInvalidRoots) {
  final StructureConfigurableContext context = ProjectStructureConfigurable.getInstance(project).getContext();
  final Image icon = LibraryPresentationManager.getInstance().getCustomIcon(library, context);

  final String name = library.getName();
  if (name != null) {
    return normalOrRedWaved(name, (icon != null ? icon :  AllIcons.Nodes.PpLib), hasInvalidRoots);
  }

  final String[] files = library.getUrls(BinariesOrderRootType.getInstance());
  if (files.length == 0) {
    return SimpleTextCellAppearance.invalid(ProjectBundle.message("library.empty.library.item"),  AllIcons.Nodes.PpLib);
  }
  else if (files.length == 1) {
    return forVirtualFilePointer(new LightFilePointer(files[0]));
  }

  final String url = StringUtil.trimEnd(files[0], URLUtil.ARCHIVE_SEPARATOR);
  return SimpleTextCellAppearance.regular(PathUtil.getFileName(url),  AllIcons.Nodes.PpLib);
}
 
Example #4
Source File: PackagingElementFactoryImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public List<? extends PackagingElement<?>> createLibraryElements(@Nonnull Library library) {
  final LibraryTable table = library.getTable();
  final String libraryName = library.getName();
  if (table != null) {
    return Collections.singletonList(createLibraryFiles(libraryName, table.getTableLevel(), null));
  }
  if (libraryName != null) {
    final Module module = ((LibraryImpl)library).getModule();
    if (module != null) {
      return Collections.singletonList(createLibraryFiles(libraryName, LibraryTableImplUtil.MODULE_LEVEL, module.getName()));
    }
  }
  final List<PackagingElement<?>> elements = new ArrayList<>();
  for (VirtualFile file : library.getFiles(BinariesOrderRootType.getInstance())) {
    final String path = FileUtil.toSystemIndependentName(PathUtil.getLocalPath(file));
    elements.add(file.isDirectory() && file.isInLocalFileSystem() ? new DirectoryCopyPackagingElement(path) : new FileCopyPackagingElement(path));
  }
  return elements;
}
 
Example #5
Source File: ModulesAndLibrariesSourceItemsProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static List<? extends Library> getNotAddedLibraries(@Nonnull final ArtifactEditorContext context,
                                                            @Nonnull Artifact artifact,
                                                            List<Library> librariesList) {
  final Set<VirtualFile> roots = new HashSet<VirtualFile>();
  ArtifactUtil
    .processPackagingElements(artifact, FileCopyElementType.getInstance(), new Processor<FileCopyPackagingElement>() {
      @Override
      public boolean process(FileCopyPackagingElement fileCopyPackagingElement) {
        final VirtualFile root = fileCopyPackagingElement.getLibraryRoot();
        if (root != null) {
          roots.add(root);
        }
        return true;
      }
    }, context, true);
  final List<Library> result = new ArrayList<Library>();
  for (Library library : librariesList) {
    if (!roots.containsAll(Arrays.asList(library.getFiles(BinariesOrderRootType.getInstance())))) {
      result.add(library);
    }
  }
  return result;
}
 
Example #6
Source File: LibraryGroupNode.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void addLibraryChildren(final OrderEntry entry, final List<AbstractTreeNode> children, Project project, ProjectViewNode node) {
  final PsiManager psiManager = PsiManager.getInstance(project);
  VirtualFile[] files =
    entry instanceof LibraryOrderEntry ? getLibraryRoots((LibraryOrderEntry)entry) : entry.getFiles(BinariesOrderRootType.getInstance());
  for (final VirtualFile file : files) {
    if (!file.isValid()) continue;
    if (file.isDirectory()) {
      final PsiDirectory psiDir = psiManager.findDirectory(file);
      if (psiDir == null) {
        continue;
      }
      children.add(new PsiDirectoryNode(project, psiDir, node.getSettings()));
    }
    else {
      final PsiFile psiFile = psiManager.findFile(file);
      if (psiFile == null) continue;
      children.add(new PsiFileNode(project, psiFile, node.getSettings()));
    }
  }
}
 
Example #7
Source File: LibraryClasspathTableItem.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public String getTooltipText() {
  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(BinariesOrderRootType.getInstance());
    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>"));
}
 
Example #8
Source File: LibrarySourceItem.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void render(@Nonnull PresentationData presentationData, SimpleTextAttributes mainAttributes,
                   SimpleTextAttributes commentAttributes) {
  final String name = myLibrary.getName();
  if (name != null) {
    presentationData.setIcon(AllIcons.Nodes.PpLib);
    presentationData.addText(name, mainAttributes);
    presentationData.addText(LibraryElementPresentation.getLibraryTableComment(myLibrary), commentAttributes);
  }
  else {
    if (((LibraryEx)myLibrary).isDisposed()) {
      //todo[nik] disposed library should not be shown in the tree
      presentationData.addText("Invalid Library", SimpleTextAttributes.ERROR_ATTRIBUTES);
      return;
    }
    final VirtualFile[] files = myLibrary.getFiles(BinariesOrderRootType.getInstance());
    if (files.length > 0) {
      final VirtualFile file = files[0];
      presentationData.setIcon(VirtualFilePresentation.getIcon(file));
      presentationData.addText(file.getName(), mainAttributes);
    }
    else {
      presentationData.addText("Empty Library", SimpleTextAttributes.ERROR_ATTRIBUTES);
    }
  }
}
 
Example #9
Source File: ExistingLibraryEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
private LibraryType detectType() {
  if (!myDetectedTypeComputed) {
    final Pair<LibraryType<?>,LibraryProperties<?>> pair = LibraryDetectionManager.getInstance().detectType(Arrays.asList(getFiles(
            BinariesOrderRootType.getInstance())));
    if (pair != null) {
      myDetectedType = pair.getFirst();
      myDetectedLibraryProperties = pair.getSecond();
    }
    myDetectedTypeComputed = true;
  }
  return myDetectedType;
}
 
Example #10
Source File: LibraryRootsComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void updatePropertiesLabel() {
  StringBuilder text = new StringBuilder();
  final LibraryType<?> type = getLibraryEditor().getType();
  final Set<LibraryKind> excluded =
    type != null ? Collections.<LibraryKind>singleton(type.getKind()) : Collections.<LibraryKind>emptySet();
  for (String description : LibraryPresentationManager.getInstance().getDescriptions(getLibraryEditor().getFiles(BinariesOrderRootType.getInstance()),
                                                                                     excluded)) {
    if (text.length() > 0) {
      text.append("\n");
    }
    text.append(description);
  }
  myPropertiesLabel.setText(text.toString());
}
 
Example #11
Source File: LibraryPresentationManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static VirtualFile[] getLibraryFiles(@Nonnull Library library, @Nullable StructureConfigurableContext context) {
  if (((LibraryEx)library).isDisposed()) {
    return VirtualFile.EMPTY_ARRAY;
  }
  return context != null ? context.getLibraryFiles(library, BinariesOrderRootType.getInstance()) : library.getFiles(BinariesOrderRootType.getInstance());
}
 
Example #12
Source File: LibraryPresentationManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isLibraryOfKind(@Nonnull Library library,
                               @Nonnull LibrariesContainer librariesContainer,
                               @Nonnull final Set<? extends LibraryKind> acceptedKinds) {
  final LibraryKind type = ((LibraryEx)library).getKind();
  if (type != null && acceptedKinds.contains(type)) return true;

  final VirtualFile[] files = librariesContainer.getLibraryFiles(library, BinariesOrderRootType.getInstance());
  return !LibraryDetectionManager.getInstance().processProperties(Arrays.asList(files), new LibraryDetectionManager.LibraryPropertiesProcessor() {
    @Override
    public <P extends LibraryProperties> boolean processProperties(@Nonnull LibraryKind processedKind, @Nonnull P properties) {
      return !acceptedKinds.contains(processedKind);
    }
  });
}
 
Example #13
Source File: LibrariesContainerFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Library createLibrary(@Nonnull @NonNls String name,
                             @Nonnull LibraryLevel level,
                             @Nonnull VirtualFile[] classRoots,
                             @Nonnull VirtualFile[] sourceRoots) {
  NewLibraryEditor editor = new NewLibraryEditor();
  editor.setName(name);
  for (VirtualFile classRoot : classRoots) {
    editor.addRoot(classRoot, BinariesOrderRootType.getInstance());
  }
  for (VirtualFile sourceRoot : sourceRoots) {
    editor.addRoot(sourceRoot, SourcesOrderRootType.getInstance());
  }
  return createLibrary(editor, level);
}
 
Example #14
Source File: LibraryProjectStructureElement.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void check(ProjectStructureProblemsHolder problemsHolder) {
  if (((LibraryEx)myLibrary).isDisposed()) return;
  final LibraryEx library = (LibraryEx)myContext.getLibraryModel(myLibrary);
  if (library == null || library.isDisposed()) return;

  reportInvalidRoots(problemsHolder, library, BinariesOrderRootType.getInstance(), "classes", ProjectStructureProblemType.error("library-invalid-classes-path"));
  final String libraryName = library.getName();
  if (libraryName == null || !libraryName.startsWith("Maven: ")) {
    reportInvalidRoots(problemsHolder, library, SourcesOrderRootType.getInstance(), "sources",
                       ProjectStructureProblemType.warning("library-invalid-source-javadoc-path"));
    reportInvalidRoots(problemsHolder, library, DocumentationOrderRootType.getInstance(), "javadoc",
                       ProjectStructureProblemType.warning("library-invalid-source-javadoc-path"));
  }
}
 
Example #15
Source File: LibraryUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static String getPresentableName(@Nonnull Library library) {
  final String name = library.getName();
  if (name != null) {
    return name;
  }
  if (library instanceof LibraryEx && ((LibraryEx)library).isDisposed()) {
    return "Disposed Library";
  }
  String[] urls = library.getUrls(BinariesOrderRootType.getInstance());
  if (urls.length > 0) {
    return PathUtil.getFileName(VfsUtilCore.urlToPath(urls[0]));
  }
  return "Empty Library";
}
 
Example #16
Source File: LibrarySourceItem.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public String getPresentableName() {
  final String name = myLibrary.getName();
  if (name != null) {
    return name;
  }
  final VirtualFile[] files = myLibrary.getFiles(BinariesOrderRootType.getInstance());
  return files.length > 0 ? files[0].getName() : "Empty Library";
}
 
Example #17
Source File: LibraryDataService.java    From consulo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("MethodMayBeStatic")
public void registerPaths(@Nonnull final Map<OrderRootType, Collection<File>> libraryFiles, @Nonnull Library.ModifiableModel model, @Nonnull String libraryName) {
  for (Map.Entry<OrderRootType, Collection<File>> entry : libraryFiles.entrySet()) {
    for (File file : entry.getValue()) {
      VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
      if (virtualFile == null) {
        if (ExternalSystemConstants.VERBOSE_PROCESSING && entry.getKey() == BinariesOrderRootType.getInstance()) {
          LOG.warn(String.format("Can't find %s of the library '%s' at path '%s'", entry.getKey(), libraryName, file.getAbsolutePath()));
        }
        String url = VfsUtil.getUrlForLibraryRoot(file);
        model.addRoot(url, entry.getKey());
        continue;
      }
      if (virtualFile.isDirectory()) {
        model.addRoot(virtualFile, entry.getKey());
      }
      else {
        VirtualFile archiveRoot = ArchiveVfsUtil.getArchiveRootForLocalFile(virtualFile);
        if (archiveRoot == null) {
          LOG.warn(String.format("Can't parse contents of the jar file at path '%s' for the library '%s''", file.getAbsolutePath(), libraryName));
          continue;
        }
        model.addRoot(archiveRoot, entry.getKey());
      }
    }
  }
}
 
Example #18
Source File: LibraryScope.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public String getDisplayName() {
  String name = myLibrary.getName();
  if (name == null) {
    String[] urls = myLibrary.getUrls(BinariesOrderRootType.getInstance());
    if (urls.length > 0) {
      name = PathUtil.getFileName(VfsUtilCore.urlToPath(urls[0]));
    }
    else {
      name = "empty";
    }
  }
  return "Library '" + name + "'";
}
 
Example #19
Source File: LibraryElementPresentation.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static String getLibraryItemText(final @Nonnull Library library, final boolean includeTableName) {
  String name = library.getName();
  VirtualFile[] files = library.getFiles(BinariesOrderRootType.getInstance());
  if (name != null) {
    return name + (includeTableName ? getLibraryTableComment(library) : "");
  }
  else if (files.length > 0) {
    return files[0].getName() + (includeTableName ? getLibraryTableComment(library) : "");
  }
  else {
    return ProjectBundle.message("library.empty.item");
  }
}
 
Example #20
Source File: LibraryPackagingElement.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static PackagingElementOutputKind getKindForLibrary(final Library library) {
  boolean containsDirectories = false;
  boolean containsJars = false;
  for (VirtualFile file : library.getFiles(BinariesOrderRootType.getInstance())) {
    if (file.isInLocalFileSystem()) {
      containsDirectories = true;
    }
    else {
      containsJars = true;
    }
  }
  return new PackagingElementOutputKind(containsDirectories, containsJars);
}
 
Example #21
Source File: LibraryPackagingElement.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public List<? extends PackagingElement<?>> getSubstitution(@Nonnull PackagingElementResolvingContext context, @Nonnull ArtifactType artifactType) {
  final Library library = findLibrary(context);
  if (library != null) {
    final VirtualFile[] files = library.getFiles(BinariesOrderRootType.getInstance());
    final List<PackagingElement<?>> elements = new ArrayList<PackagingElement<?>>();
    for (VirtualFile file : files) {
      final String path = FileUtil.toSystemIndependentName(PathUtil.getLocalPath(file));
      elements.add(file.isDirectory() && file.isInLocalFileSystem() ? new DirectoryCopyPackagingElement(path) : new FileCopyPackagingElement(path));
    }
    return elements;
  }
  return null;
}
 
Example #22
Source File: PackagingElementsTestCase.java    From consulo with Apache License 2.0 5 votes vote down vote up
static Library addProjectLibrary(final Project project, final @javax.annotation.Nullable Module module, final String name, final DependencyScope scope, final VirtualFile[] jars) {
  return WriteAction.compute(() -> {
    final Library library = LibraryTablesRegistrar.getInstance().getLibraryTable(project).createLibrary(name);
    final Library.ModifiableModel libraryModel = library.getModifiableModel();
    for (VirtualFile jar : jars) {
      libraryModel.addRoot(jar, BinariesOrderRootType.getInstance());
    }
    libraryModel.commit();
    if (module != null) {
      ModuleRootModificationUtil.addDependency(module, library, scope, false);
    }
    return library;
  });
}
 
Example #23
Source File: ExternalLibrariesNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
public static void addLibraryChildren(final LibraryOrderEntry entry, final List<AbstractTreeNode> children, Project project, ProjectViewNode node) {
  final PsiManager psiManager = PsiManager.getInstance(project);
  final VirtualFile[] files = entry.getFiles(BinariesOrderRootType.getInstance());
  for (final VirtualFile file : files) {
    final PsiDirectory psiDir = psiManager.findDirectory(file);
    if (psiDir == null) {
      continue;
    }
    children.add(new PsiDirectoryNode(project, psiDir, node.getSettings()));
  }
}
 
Example #24
Source File: ModuleRootManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static OrderRootsEnumerator getEnumeratorForType(OrderRootType type, Module module) {
  OrderEnumerator base = OrderEnumerator.orderEntries(module);
  if (type == BinariesOrderRootType.getInstance()) {
    return base.exportedOnly().withoutModuleSourceEntries().recursively().classes();
  }
  if (type == SourcesOrderRootType.getInstance()) {
    return base.exportedOnly().recursively().sources();
  }
  return base.roots(type);
}
 
Example #25
Source File: Unity3dPackageOrderEntry.java    From consulo-unity3d with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
@RequiredReadAction
public String[] getUrls(@Nonnull OrderRootType rootType)
{
	List<String> urls = new SmartList<>();

	if(rootType == BinariesOrderRootType.getInstance() || rootType == SourcesOrderRootType.getInstance())
	{
		// moved to project files
		String projectPackageCache = getProjectPackageCache();
		if(new File(projectPackageCache, myNameWithVersion).exists())
		{
			urls.add(StandardFileSystems.FILE_PROTOCOL_PREFIX + FileUtil.toSystemIndependentName(projectPackageCache + "/" + myNameWithVersion));
		}

		if(urls.isEmpty())
		{
			Unity3dPackageWatcher watcher = Unity3dPackageWatcher.getInstance();
			for(String path : watcher.getPackageDirPaths())
			{
				if(new File(path, myNameWithVersion).exists())
				{
					urls.add(StandardFileSystems.FILE_PROTOCOL_PREFIX + FileUtil.toSystemIndependentName(path + "/" + myNameWithVersion));
				}
			}
		}
	}

	if(urls.isEmpty())
	{
		Sdk sdk = getSdk();
		if(sdk != null)
		{
			String builtInPath = sdk.getHomePath() + "/" + getBuiltInPackagesRelativePath();
			String packageName = getPackageName();
			if(new File(builtInPath, packageName).exists())
			{
				urls.add(StandardFileSystems.FILE_PROTOCOL_PREFIX + FileUtil.toSystemIndependentName(builtInPath + "/" + packageName));
			}
		}
	}

	return ArrayUtil.toStringArray(urls);
}
 
Example #26
Source File: SandBundleType.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isRootTypeApplicable(OrderRootType type) {
  return type == BinariesOrderRootType.getInstance();
}
 
Example #27
Source File: BinariesOrderRootTypeUIFactory.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public SdkPathEditor createPathEditor(Sdk sdk) {
  return new SdkPathEditor(ProjectBundle.message("library.binaries.node"), BinariesOrderRootType.getInstance(),
                           new FileChooserDescriptor(true, true, true, false, true, true), sdk);
}
 
Example #28
Source File: LibraryType.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static OrderRootType[] getDefaultExternalRootTypes() {
  return new OrderRootType[]{BinariesOrderRootType.getInstance()};
}
 
Example #29
Source File: LibraryUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isClassAvailableInLibrary(final Library library, final String fqn) {
  return isClassAvailableInLibrary(library.getFiles(BinariesOrderRootType.getInstance()), fqn);
}
 
Example #30
Source File: LibraryScope.java    From consulo with Apache License 2.0 4 votes vote down vote up
public LibraryScope(Project project, Library library) {
  super(project, library.getFiles(BinariesOrderRootType.getInstance()), library.getFiles(SourcesOrderRootType.getInstance()));
  myLibrary = library;
}