コード例 #1
0
 public LibraryRuntimeClasspathScope(Project project, LibraryOrderEntry entry) {
   super(project);
   myIndex = ProjectRootManager.getInstance(project).getFileIndex();
   Collections.addAll(myEntries, entry.getFiles(BinariesOrderRootType.getInstance()));
 }
  @NotNull
  protected String[] getSystemLibraryUrlsImpl(
      @NotNull Sdk sdk, String name, OrderRootType orderRootType) {
    if (orderRootType == BinariesOrderRootType.getInstance()) {
      File libraryByAssemblyName = getLibraryByAssemblyName(name, null);
      if (libraryByAssemblyName == null) {
        return ArrayUtil.EMPTY_STRING_ARRAY;
      }

      return new String[] {
        VirtualFileManager.constructUrl(
                DotNetModuleFileType.PROTOCOL, libraryByAssemblyName.getPath())
            + ArchiveFileSystem.ARCHIVE_SEPARATOR
      };
    } else if (orderRootType == DocumentationOrderRootType.getInstance()) {
      String[] systemLibraryUrls = getSystemLibraryUrls(name, BinariesOrderRootType.getInstance());
      if (systemLibraryUrls.length != 1) {
        return ArrayUtil.EMPTY_STRING_ARRAY;
      }
      VirtualFile libraryFile =
          VirtualFileManager.getInstance().findFileByUrl(systemLibraryUrls[0]);
      if (libraryFile == null) {
        return ArrayUtil.EMPTY_STRING_ARRAY;
      }
      VirtualFile localFile = ArchiveVfsUtil.getVirtualFileForArchive(libraryFile);
      if (localFile == null) {
        return ArrayUtil.EMPTY_STRING_ARRAY;
      }
      VirtualFile docFile =
          localFile.getParent().findChild(localFile.getNameWithoutExtension() + ".xml");
      if (docFile != null) {
        return new String[] {docFile.getUrl()};
      }
      return ArrayUtil.EMPTY_STRING_ARRAY;
    } else if (orderRootType == ExternalAttributesRootOrderType.getInstance()) {
      try {
        final Ref<Couple<String>> ref = Ref.create();
        File libraryFile = getLibraryByAssemblyName(name, ref);
        if (libraryFile == null) {
          return ArrayUtil.EMPTY_STRING_ARRAY;
        }

        assert ref.get() != null;

        PluginClassLoader classLoader = (PluginClassLoader) getClass().getClassLoader();
        IdeaPluginDescriptor plugin = PluginManager.getPlugin(classLoader.getPluginId());
        assert plugin != null;
        File dir = new File(plugin.getPath(), "externalAttributes");

        val urls = new SmartList<String>();
        val requiredFileName = name + ".xml";
        FileUtil.visitFiles(
            dir,
            new Processor<File>() {
              @Override
              public boolean process(File file) {
                if (file.isDirectory()) {
                  return true;
                }
                if (Comparing.equal(requiredFileName, file.getName(), false)
                    && isValidExternalFile(ref.get().getSecond(), file)) {
                  urls.add(VfsUtil.pathToUrl(file.getPath()));
                }
                return true;
              }
            });

        return ArrayUtil.toStringArray(urls);
      } catch (Exception e) {
        LOGGER.error(e);
      }
    }
    return ArrayUtil.EMPTY_STRING_ARRAY;
  }