private synchronized void assertAllPointersDisposed() {
    for (Map.Entry<VirtualFilePointerListener, FilePointerPartNode> entry : myPointers.entrySet()) {
      FilePointerPartNode root = entry.getValue();
      ArrayList<FilePointerPartNode> left = new ArrayList<FilePointerPartNode>();
      root.getPointersUnder(null, false, "", left);
      if (!left.isEmpty()) {
        VirtualFilePointerImpl p = left.get(0).leaf;
        try {
          p.throwDisposalError("Not disposed pointer: " + p);
        } finally {
          for (FilePointerPartNode pair : left) {
            VirtualFilePointerImpl pointer = pair.leaf;
            pointer.dispose();
          }
        }
      }
    }

    synchronized (myContainers) {
      if (!myContainers.isEmpty()) {
        VirtualFilePointerContainerImpl container = myContainers.iterator().next();
        container.throwDisposalError("Not disposed container");
      }
    }
  }
  @NotNull
  private static DartLibInfo collectPackagesLibraryRoots(
      @NotNull final Project project, @NotNull final DartSdk sdk) {
    final DartLibInfo libInfo = new DartLibInfo(false);

    final Collection<VirtualFile> pubspecYamlFiles =
        FilenameIndex.getVirtualFilesByName(
            project, PUBSPEC_YAML, GlobalSearchScope.projectScope(project));
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();

    for (VirtualFile pubspecFile : pubspecYamlFiles) {
      final VirtualFile dotPackagesFile =
          pubspecFile.getParent().findChild(DotPackagesFileUtil.DOT_PACKAGES);
      final Module module =
          dotPackagesFile == null ? null : fileIndex.getModuleForFile(dotPackagesFile);

      if (dotPackagesFile != null
          && !dotPackagesFile.isDirectory()
          && module != null
          && DartSdkGlobalLibUtil.isDartSdkEnabled(module)) {
        final Map<String, String> packagesMap = DotPackagesFileUtil.getPackagesMap(dotPackagesFile);
        if (packagesMap != null) {
          for (Map.Entry<String, String> entry : packagesMap.entrySet()) {
            final String packageName = entry.getKey();
            final String packagePath = entry.getValue();
            if (isPathOutsideProjectContent(fileIndex, packagePath)) {
              libInfo.addPackage(packageName, packagePath);
            }
          }
        }
      }
    }

    return libInfo;
  }
 private static void processLibrariesAndJpsPlugins(
     final File jarFile,
     final File zipFile,
     final String pluginName,
     final Set<Library> libs,
     Map<Module, String> jpsModules,
     final ProgressIndicator progressIndicator)
     throws IOException {
   if (FileUtil.ensureCanCreateFile(zipFile)) {
     ZipOutputStream zos = null;
     try {
       zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
       addStructure(pluginName, zos);
       addStructure(pluginName + "/" + MIDDLE_LIB_DIR, zos);
       final String entryName = pluginName + JAR_EXTENSION;
       ZipUtil.addFileToZip(
           zos,
           jarFile,
           getZipPath(pluginName, entryName),
           new HashSet<String>(),
           createFilter(progressIndicator, FileTypeManager.getInstance()));
       for (Map.Entry<Module, String> entry : jpsModules.entrySet()) {
         File jpsPluginJar = jarModulesOutput(Collections.singleton(entry.getKey()), null, null);
         ZipUtil.addFileToZip(
             zos, jpsPluginJar, getZipPath(pluginName, entry.getValue()), null, null);
       }
       Set<String> usedJarNames = new HashSet<String>();
       usedJarNames.add(entryName);
       Set<VirtualFile> jarredVirtualFiles = new HashSet<VirtualFile>();
       for (Library library : libs) {
         final VirtualFile[] files = library.getFiles(OrderRootType.CLASSES);
         for (VirtualFile virtualFile : files) {
           if (jarredVirtualFiles.add(virtualFile)) {
             if (virtualFile.getFileSystem() instanceof JarFileSystem) {
               addLibraryJar(
                   virtualFile, zipFile, pluginName, zos, usedJarNames, progressIndicator);
             } else {
               makeAndAddLibraryJar(
                   virtualFile,
                   zipFile,
                   pluginName,
                   zos,
                   usedJarNames,
                   progressIndicator,
                   library.getName());
             }
           }
         }
       }
     } finally {
       if (zos != null) zos.close();
     }
   }
 }
 private PropertiesFile getSelectedPropertiesFile() {
   if (mySelectedEditor == null) return null;
   PropertiesFile selectedFile = null;
   for (Map.Entry<PropertiesFile, Editor> entry : myEditors.entrySet()) {
     Editor editor = entry.getValue();
     if (editor == mySelectedEditor) {
       selectedFile = entry.getKey();
       break;
     }
   }
   return selectedFile;
 }
Пример #5
0
 public Collection<RequestFuture> cancelAutoMakeTasks(Project project) {
   final Collection<RequestFuture> futures = new ArrayList<RequestFuture>();
   synchronized (myAutomakeFutures) {
     for (Map.Entry<RequestFuture, Project> entry : myAutomakeFutures.entrySet()) {
       if (entry.getValue().equals(project)) {
         final RequestFuture future = entry.getKey();
         future.cancel(false);
         futures.add(future);
       }
     }
   }
   return futures;
 }
  @Override
  public void dispose() {
    if (mySelectedEditor != null) {
      for (final Map.Entry<PropertiesFile, Editor> entry : myEditors.entrySet()) {
        if (mySelectedEditor.equals(entry.getValue())) {
          writeEditorPropertyValue(mySelectedEditor, entry.getKey(), null);
        }
      }
    }

    VirtualFileManager.getInstance().removeVirtualFileListener(myVfsListener);
    myDisposed = true;
    Disposer.dispose(myStructureViewComponent);
    releaseAllEditors();
  }
  @NotNull
  private static String getPresentableFile(
      @NotNull String url, @Nullable Map<VirtualFile, VirtualFile> presentableFilesMap) {
    final VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url);
    if (file == null) {
      return url;
    }

    if (presentableFilesMap == null) {
      return url;
    }

    for (Map.Entry<VirtualFile, VirtualFile> entry : presentableFilesMap.entrySet()) {
      if (file == entry.getValue()) {
        return entry.getKey().getUrl();
      }
    }
    return url;
  }
Пример #8
0
  private static CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings buildGlobalSettings() {
    final Map<String, String> data = new HashMap<String, String>();

    for (Map.Entry<String, String> entry : PathMacrosImpl.getGlobalSystemMacros().entrySet()) {
      data.put(entry.getKey(), FileUtil.toSystemIndependentName(entry.getValue()));
    }

    final PathMacros pathVars = PathMacros.getInstance();
    for (String name : pathVars.getAllMacroNames()) {
      final String path = pathVars.getValue(name);
      if (path != null) {
        data.put(name, FileUtil.toSystemIndependentName(path));
      }
    }

    final List<GlobalLibrary> globals = new ArrayList<GlobalLibrary>();

    fillSdks(globals);
    fillGlobalLibraries(globals);

    final CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings.Builder cmdBuilder =
        CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings.newBuilder();

    if (!data.isEmpty()) {
      for (Map.Entry<String, String> entry : data.entrySet()) {
        final String var = entry.getKey();
        final String value = entry.getValue();
        if (var != null && value != null) {
          cmdBuilder.addPathVariable(CmdlineProtoUtil.createPair(var, value));
        }
      }
    }

    if (!globals.isEmpty()) {
      for (GlobalLibrary lib : globals) {
        final CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings.GlobalLibrary.Builder
            libBuilder =
                CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings.GlobalLibrary
                    .newBuilder();
        libBuilder.setName(lib.getName()).addAllPath(lib.getPaths());
        if (lib instanceof SdkLibrary) {
          final SdkLibrary sdk = (SdkLibrary) lib;
          libBuilder.setHomePath(sdk.getHomePath());
          libBuilder.setTypeName(sdk.getTypeName());
          final String additional = sdk.getAdditionalDataXml();
          if (additional != null) {
            libBuilder.setAdditionalDataXml(additional);
          }
          final String version = sdk.getVersion();
          if (version != null) {
            libBuilder.setVersion(version);
          }
        }
        cmdBuilder.addGlobalLibrary(libBuilder.build());
      }
    }

    final String defaultCharset = EncodingManager.getInstance().getDefaultCharsetName();
    if (defaultCharset != null) {
      cmdBuilder.setGlobalEncoding(defaultCharset);
    }

    final String ignoredFilesList = FileTypeManager.getInstance().getIgnoredFilesList();
    cmdBuilder.setIgnoredFilesPatterns(ignoredFilesList);
    return cmdBuilder.build();
  }