예제 #1
0
  @NotNull
  private static List<VirtualFile> findClasses(File file, boolean isJre) {
    List<VirtualFile> result = ContainerUtil.newArrayList();
    VirtualFileManager fileManager = VirtualFileManager.getInstance();

    String path = file.getPath();
    if (JrtFileSystem.isModularJdk(path)) {
      String url =
          VirtualFileManager.constructUrl(
              JrtFileSystem.PROTOCOL,
              FileUtil.toSystemIndependentName(path) + JrtFileSystem.SEPARATOR);
      for (String module : JrtFileSystem.listModules(path)) {
        ContainerUtil.addIfNotNull(result, fileManager.findFileByUrl(url + module));
      }
    }

    for (File root : JavaSdkUtil.getJdkClassesRoots(file, isJre)) {
      String url = VfsUtil.getUrlForLibraryRoot(root);
      ContainerUtil.addIfNotNull(result, fileManager.findFileByUrl(url));
    }

    Collections.sort(result, (o1, o2) -> o1.getPath().compareTo(o2.getPath()));

    return result;
  }
예제 #2
0
 private static String correctRepositoryRule(String input) {
   String protocol = VirtualFileManager.extractProtocol(input);
   if (protocol == null) {
     input = VirtualFileManager.constructUrl(URLUtil.HTTP_PROTOCOL, input);
   }
   return input;
 }
예제 #3
0
  @Nullable
  public static String getAnnotationProcessorsGenerationPath(Module module) {
    final CompilerConfiguration config = CompilerConfiguration.getInstance(module.getProject());

    final String sourceDirName = config.getGeneratedSourceDirName(module);
    if (sourceDirName != null && sourceDirName.length() > 0) {
      final String[] roots = ModuleRootManager.getInstance(module).getContentRootUrls();
      if (roots.length == 0) {
        return null;
      }
      if (roots.length > 1) {
        Arrays.sort(roots, URLS_COMPARATOR);
      }
      return VirtualFileManager.extractPath(roots[0]) + "/" + sourceDirName;
    }

    final CompilerProjectExtension extension =
        CompilerProjectExtension.getInstance(module.getProject());
    if (extension == null) {
      return null;
    }
    final String url = extension.getCompilerOutputUrl();
    if (url == null) {
      return null;
    }
    return VirtualFileManager.extractPath(url)
        + "/"
        + DEFAULT_GENERATED_DIR_NAME
        + "/"
        + module.getName().toLowerCase();
  }
예제 #4
0
  private static Set<VirtualFile> getFilteredResourcesRoots(@NotNull MavenProject mavenProject) {
    Pair<Long, Set<VirtualFile>> cachedValue =
        mavenProject.getCachedValue(FILTERED_RESOURCES_ROOTS_KEY);

    if (cachedValue == null
        || cachedValue.first != VirtualFileManager.getInstance().getModificationCount()) {
      Set<VirtualFile> set = null;

      for (MavenResource resource :
          ContainerUtil.concat(mavenProject.getResources(), mavenProject.getTestResources())) {
        if (!resource.isFiltered()) continue;

        VirtualFile resourceDir =
            LocalFileSystem.getInstance().findFileByPath(resource.getDirectory());
        if (resourceDir == null) continue;

        if (set == null) {
          set = new HashSet<VirtualFile>();
        }

        set.add(resourceDir);
      }

      if (set == null) {
        set = Collections.emptySet();
      }

      cachedValue = Pair.create(VirtualFileManager.getInstance().getModificationCount(), set);
      mavenProject.putCachedValue(FILTERED_RESOURCES_ROOTS_KEY, cachedValue);
    }

    return cachedValue.second;
  }
  @NotNull
  private VirtualFilePointer create(
      @Nullable("null means the pointer will be created from the (not null) url") VirtualFile file,
      @Nullable("null means url has to be computed from the (not-null) file path") String url,
      @NotNull Disposable parentDisposable,
      @Nullable VirtualFilePointerListener listener) {
    VirtualFileSystem fileSystem;
    String protocol;
    String path;
    if (file == null) {
      int protocolEnd = url.indexOf(URLUtil.SCHEME_SEPARATOR);
      if (protocolEnd == -1) {
        protocol = null;
        fileSystem = null;
      } else {
        protocol = url.substring(0, protocolEnd);
        fileSystem = myVirtualFileManager.getFileSystem(protocol);
      }
      path = url.substring(protocolEnd + URLUtil.SCHEME_SEPARATOR.length());
    } else {
      fileSystem = file.getFileSystem();
      protocol = fileSystem.getProtocol();
      path = file.getPath();
      url = VirtualFileManager.constructUrl(protocol, path);
    }

    if (fileSystem == TEMP_FILE_SYSTEM) {
      // for tests, recreate always
      VirtualFile found = file == null ? VirtualFileManager.getInstance().findFileByUrl(url) : file;
      return new IdentityVirtualFilePointer(found, url);
    }

    boolean isJar = fileSystem == JAR_FILE_SYSTEM;
    if (fileSystem != LOCAL_FILE_SYSTEM && !isJar) {
      // we are unable to track alien file systems for now
      VirtualFile found =
          fileSystem == null
              ? null
              : file != null ? file : VirtualFileManager.getInstance().findFileByUrl(url);
      // if file is null, this pointer will never be alive
      return getOrCreateIdentity(url, found);
    }

    if (file == null) {
      String cleanPath = cleanupPath(path, isJar);
      // if newly created path is the same as substringed from url one then the url did not change,
      // we can reuse it
      //noinspection StringEquality
      if (cleanPath != path) {
        url = VirtualFileManager.constructUrl(protocol, cleanPath);
        path = cleanPath;
      }
    }
    // else url has come from VirtualFile.getPath() and is good enough

    VirtualFilePointerImpl pointer =
        getOrCreate(parentDisposable, listener, path, Pair.create(file, url));
    DelegatingDisposable.registerDisposable(parentDisposable, pointer);
    return pointer;
  }
 private String dubImportPath(String rootPath) {
   String pathUrl = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, rootPath);
   VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(pathUrl);
   if (file == null) {
     return null;
   }
   final List<String> sourcesDir = new ArrayList<>();
   VfsUtilCore.visitChildrenRecursively(
       file,
       new VirtualFileVisitor() {
         @Override
         public boolean visitFile(@NotNull VirtualFile file) {
           if (file.isDirectory()) {
             if (file.getName().equals("source")) {
               sourcesDir.add("source");
             }
             if (file.getName().equals("src")) {
               sourcesDir.add("src");
             }
           }
           return true;
         }
       });
   return sourcesDir.isEmpty() ? null : rootPath + File.separator + sourcesDir.get(0);
 }
  @NotNull
  private VirtualFilePointer create(
      @Nullable VirtualFile file,
      @NotNull String url,
      @NotNull final Disposable parentDisposable,
      @Nullable VirtualFilePointerListener listener) {
    String protocol;
    VirtualFileSystem fileSystem;
    if (file == null) {
      protocol = VirtualFileManager.extractProtocol(url);
      fileSystem = myVirtualFileManager.getFileSystem(protocol);
    } else {
      protocol = null;
      fileSystem = file.getFileSystem();
    }
    if (fileSystem == TempFileSystem.getInstance()) {
      // for tests, recreate always since
      VirtualFile found =
          fileSystem == null
              ? null
              : file != null ? file : VirtualFileManager.getInstance().findFileByUrl(url);
      return new IdentityVirtualFilePointer(found, url);
    }
    if (fileSystem != LocalFileSystem.getInstance() && fileSystem != JarFileSystem.getInstance()) {
      // we are unable to track alien file systems for now
      VirtualFile found =
          fileSystem == null
              ? null
              : file != null ? file : VirtualFileManager.getInstance().findFileByUrl(url);
      // if file is null, this pointer will never be alive
      return getOrCreateIdentity(url, found);
    }

    String path;
    if (file == null) {
      path = VirtualFileManager.extractPath(url);
      path = cleanupPath(path, protocol);
      url = VirtualFileManager.constructUrl(protocol, path);
    } else {
      path = file.getPath();
      // url has come from VirtualFile.getUrl() and is good enough
    }

    VirtualFilePointerImpl pointer = getOrCreate(file, url, parentDisposable, listener, path);

    int newCount = pointer.incrementUsageCount();

    if (newCount == 1) {
      Disposer.register(parentDisposable, pointer);
    } else {
      // already registered
      register(parentDisposable, pointer);
    }

    return pointer;
  }
예제 #8
0
 private void disposeListeners() {
   FileStatusManager.getInstance(myProject).removeFileStatusListener(myFileStatusListener);
   VirtualFileManager.getInstance().removeVirtualFileListener(myFileListener);
   VirtualFileManager.getInstance().removeVirtualFileManagerListener(myVirtualFileManagerListener);
   myProject
       .getComponent(ProjectLevelVcsManager.class)
       .removeVcsListener(myDirectoryMappingListener);
   ChangeListManager.getInstance(myProject).removeChangeListListener(myChangeListListener);
   myMessageBusConnection.disconnect();
 }
예제 #9
0
 @Nullable
 private static VirtualFile findFileByUrl(@Nullable String url) {
   if (url == null) {
     return null;
   }
   VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url);
   if (file == null) {
     // groovy stubs may be placed in completely random directories which aren't refreshed
     // automatically
     return VirtualFileManager.getInstance().refreshAndFindFileByUrl(url);
   }
   return file;
 }
  @Nullable
  private static VirtualFile getHelpFile(final PsiElement element) {
    final XmlTag xmlTag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
    if (xmlTag == null) {
      return null;
    }
    final AntDomElement antElement = AntSupport.getAntDomElement(xmlTag);
    if (antElement == null) {
      return null;
    }
    final AntDomProject antProject = antElement.getAntProject();
    if (antProject == null) {
      return null;
    }
    final AntInstallation installation = antProject.getAntInstallation();
    if (installation == null) {
      return null; // not configured properly and bundled installation missing
    }
    final String antHomeDir = AntInstallation.HOME_DIR.get(installation.getProperties());

    if (antHomeDir == null) {
      return null;
    }

    @NonNls String path = antHomeDir + "/docs/manual";
    String url;
    if (new File(path).exists()) {
      url =
          VirtualFileManager.constructUrl(
              LocalFileSystem.PROTOCOL, FileUtil.toSystemIndependentName(path));
    } else {
      path = antHomeDir + "/docs.zip";
      if (new File(path).exists()) {
        url =
            VirtualFileManager.constructUrl(
                JarFileSystem.PROTOCOL,
                FileUtil.toSystemIndependentName(path)
                    + JarFileSystem.JAR_SEPARATOR
                    + "docs/manual");
      } else {
        return null;
      }
    }

    final VirtualFile documentationRoot = VirtualFileManager.getInstance().findFileByUrl(url);
    if (documentationRoot == null) {
      return null;
    }

    return getHelpFile(antElement, documentationRoot);
  }
  public void testFindRoot() throws IOException {
    VirtualFile root = LocalFileSystem.getInstance().findFileByPath("wrong_path");
    assertNull(root);

    VirtualFile root2;
    if (SystemInfo.isWindows) {
      root = LocalFileSystem.getInstance().findFileByPath("\\\\unit-133");
      assertNotNull(root);
      root2 = LocalFileSystem.getInstance().findFileByPath("//UNIT-133");
      assertNotNull(root2);
      assertEquals(String.valueOf(root2), root, root2);
      RefreshQueue.getInstance().processSingleEvent(new VFileDeleteEvent(this, root, false));

      root = LocalFileSystem.getInstance().findFileByIoFile(new File("\\\\unit-133"));
      assertNotNull(root);
      RefreshQueue.getInstance().processSingleEvent(new VFileDeleteEvent(this, root, false));

      if (new File("c:").exists()) {
        root = LocalFileSystem.getInstance().findFileByPath("c:");
        assertNotNull(root);
        assertEquals("C:/", root.getPath());

        root2 = LocalFileSystem.getInstance().findFileByPath("C:\\");
        assertEquals(String.valueOf(root2), root, root2);
      }
    } else if (SystemInfo.isUnix) {
      root = LocalFileSystem.getInstance().findFileByPath("/");
      assertNotNull(root);
      assertEquals(root.getPath(), "/");
    }

    root = LocalFileSystem.getInstance().findFileByPath("");
    assertNotNull(root);

    File jarFile = IoTestUtil.createTestJar();
    root = VirtualFileManager.getInstance().findFileByUrl("jar://" + jarFile.getPath() + "!/");
    assertNotNull(root);

    root2 =
        VirtualFileManager.getInstance()
            .findFileByUrl("jar://" + jarFile.getPath().replace(File.separator, "//") + "!/");
    assertEquals(String.valueOf(root2), root, root2);

    if (!SystemInfo.isFileSystemCaseSensitive) {
      root2 =
          VirtualFileManager.getInstance()
              .findFileByUrl("jar://" + jarFile.getPath().toUpperCase(Locale.US) + "!/");
      assertEquals(String.valueOf(root2), root, root2);
    }
  }
  public Location getLocation(String url) {
    String protocol = VirtualFileManager.extractProtocol(url);
    String path = VirtualFileManager.extractPath(url);

    if (protocol != null) {
      List<Location> locations =
          JavaTestLocator.INSTANCE.getLocation(
              protocol, path, myProject, GlobalSearchScope.allScope(myProject));
      if (!locations.isEmpty()) {
        return locations.get(0);
      }
    }

    return null;
  }
예제 #13
0
    private void updateTree() {
      if (myFileSystemTree != null) {
        Disposer.dispose(myFileSystemTree);
        myFileSystemTree = null;
      }

      myFileSystemTree =
          new FileSystemTreeImpl(
              null, new FileChooserDescriptor(true, true, true, true, true, false));
      AbstractTreeUi ui = myFileSystemTree.getTreeBuilder().getUi();

      String path = myModelRoot.getPath() == null ? "" : myModelRoot.getPath();
      VirtualFile virtualFile =
          VirtualFileManager.getInstance()
              .findFileByUrl(VirtualFileManager.constructUrl("file", path));
      if (myModelRoot.getModule() != null && (virtualFile == null || path.isEmpty())) {
        if (myModelRoot.getModule() instanceof AbstractModule) {
          virtualFile =
              VirtualFileManager.getInstance()
                  .findFileByUrl(
                      VirtualFileManager.constructUrl(
                          "file",
                          ((AbstractModule) myModelRoot.getModule())
                              .getModuleSourceDir()
                              .getPath()));
        }
      }

      if (virtualFile != null) myFileSystemTree.select(virtualFile, null);

      myFileSystemTree.addListener(
          new Listener() {
            @Override
            public void selectionChanged(List<VirtualFile> selection) {
              if (selection.size() > 0) {
                myModelRoot.setPath(FileUtil.getCanonicalPath(selection.get(0).getPath()));
                myEventDispatcher.getMulticaster().fireDataChanged();
              }
            }
          },
          SModelRootEntry.this);

      Disposer.register(SModelRootEntry.this, myFileSystemTree);

      myTreePanel.removeAll();
      myTreePanel.add(ui.getTree(), BorderLayout.CENTER);
      ui.scrollSelectionToVisible(null, true);
    }
예제 #14
0
 /**
  * The same as {@link #getModuleOutputDirectory} but returns String. The method still returns a
  * non-null value if the output path is specified in Settings but does not exist on disk.
  */
 @Nullable
 public static String getModuleOutputPath(final Module module, boolean forTestClasses) {
   final String outPathUrl;
   final Application application = ApplicationManager.getApplication();
   final CompilerModuleExtension extension = CompilerModuleExtension.getInstance(module);
   if (forTestClasses) {
     if (application.isDispatchThread()) {
       final String url = extension.getCompilerOutputUrlForTests();
       outPathUrl = url != null ? url : extension.getCompilerOutputUrl();
     } else {
       outPathUrl =
           application.runReadAction(
               new Computable<String>() {
                 public String compute() {
                   final String url = extension.getCompilerOutputUrlForTests();
                   return url != null ? url : extension.getCompilerOutputUrl();
                 }
               });
     }
   } else { // for ordinary classes
     if (application.isDispatchThread()) {
       outPathUrl = extension.getCompilerOutputUrl();
     } else {
       outPathUrl =
           application.runReadAction(
               new Computable<String>() {
                 public String compute() {
                   return extension.getCompilerOutputUrl();
                 }
               });
     }
   }
   return outPathUrl != null ? VirtualFileManager.extractPath(outPathUrl) : null;
 }
 @Nullable
 @Override
 public RefEntity getReference(final String type, final String fqName) {
   for (RefManagerExtension extension : myExtensions.values()) {
     final RefEntity refEntity = extension.getReference(type, fqName);
     if (refEntity != null) return refEntity;
   }
   if (SmartRefElementPointer.FILE.equals(type)) {
     return RefFileImpl.fileFromExternalName(this, fqName);
   }
   if (SmartRefElementPointer.MODULE.equals(type)) {
     return RefModuleImpl.moduleFromName(this, fqName);
   }
   if (SmartRefElementPointer.PROJECT.equals(type)) {
     return getRefProject();
   }
   if (SmartRefElementPointer.DIR.equals(type)) {
     String url =
         VfsUtilCore.pathToUrl(PathMacroManager.getInstance(getProject()).expandPath(fqName));
     VirtualFile vFile = VirtualFileManager.getInstance().findFileByUrl(url);
     if (vFile != null) {
       final PsiDirectory dir = PsiManager.getInstance(getProject()).findDirectory(vFile);
       return getReference(dir);
     }
   }
   return null;
 }
  private static void updateUrl(
      Library.ModifiableModel library,
      OrderRootType type,
      MavenArtifact artifact,
      MavenExtraArtifactType artifactType,
      MavenProject project,
      boolean clearAll) {
    String classifier = null;
    String extension = null;

    if (artifactType != null) {
      Pair<String, String> result = project.getClassifierAndExtension(artifact, artifactType);
      classifier = result.first;
      extension = result.second;
    }

    String newPath = artifact.getPathForExtraArtifact(classifier, extension);
    String newUrl =
        VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL, newPath)
            + JarFileSystem.JAR_SEPARATOR;
    for (String url : library.getUrls(type)) {
      if (newUrl.equals(url)) return;
      if (clearAll || isRepositoryUrl(artifact, url, classifier, extension)) {
        library.removeRoot(url, type);
      }
    }
    library.addRoot(newUrl, type);
  }
예제 #17
0
  public synchronized void runPostStartupActivities() {
    final Application app = ApplicationManager.getApplication();
    app.assertIsDispatchThread();

    if (myPostStartupActivitiesPassed) return;

    runActivities(myDumbAwarePostStartupActivities);
    DumbService.getInstance(myProject)
        .runWhenSmart(
            new Runnable() {
              public void run() {
                synchronized (StartupManagerImpl.this) {
                  app.assertIsDispatchThread();
                  if (myProject.isDisposed()) return;
                  runActivities(
                      myDumbAwarePostStartupActivities); // they can register activities while in
                                                         // the dumb mode
                  runActivities(myNotDumbAwarePostStartupActivities);

                  myPostStartupActivitiesPassed = true;
                }
              }
            });

    if (!app.isUnitTestMode()) {
      VirtualFileManager.getInstance().refresh(!app.isHeadlessEnvironment());
    }
  }
  public ExternalAnnotationsManagerImpl(
      @NotNull final Project project, final PsiManager psiManager) {
    super(psiManager);
    myBus = project.getMessageBus();
    final MessageBusConnection connection = myBus.connect(project);
    connection.subscribe(
        ProjectTopics.PROJECT_ROOTS,
        new ModuleRootAdapter() {
          @Override
          public void rootsChanged(ModuleRootEvent event) {
            dropCache();
          }
        });

    final MyVirtualFileListener fileListener = new MyVirtualFileListener();
    VirtualFileManager.getInstance().addVirtualFileListener(fileListener);
    Disposer.register(
        myPsiManager.getProject(),
        new Disposable() {
          @Override
          public void dispose() {
            VirtualFileManager.getInstance().removeVirtualFileListener(fileListener);
          }
        });
  }
예제 #19
0
  @Override
  public void deactivate() {
    FrameStateManager.getInstance().removeListener(myFrameStateListener);

    final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
    if (myVcsListener != null) {
      vcsManager.removeVcsListener(myVcsListener);
    }

    if (myEntriesFileListener != null) {
      VirtualFileManager.getInstance().removeVirtualFileListener(myEntriesFileListener);
    }
    SvnApplicationSettings.getInstance().svnDeactivated();
    if (myCommittedChangesProvider != null) {
      myCommittedChangesProvider.deactivate();
    }
    if (myChangeListListener != null && !myProject.isDefault()) {
      ChangeListManager.getInstance(myProject).removeChangeListListener(myChangeListListener);
    }
    vcsManager.removeVcsListener(myRootsToWorkingCopies);
    myRootsToWorkingCopies.clear();

    myAuthNotifier.stop();
    myAuthNotifier.clear();

    mySvnBranchPointsCalculator.deactivate();
    mySvnBranchPointsCalculator = null;
    myWorkingCopiesContent.deactivate();
    myLoadedBranchesStorage.deactivate();
    myPool.dispose();
    myPool = null;
  }
예제 #20
0
 public Object[] createPath(final Project project) {
   final VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url);
   if (file == null || !file.isValid()) {
     return null;
   }
   return new Object[] {PsiManager.getInstance(project).findFile(file)};
 }
  @Override
  public void moduleAdded() {
    if (!myModuleInitialized) {
      myConnection.subscribe(
          ProjectTopics.PROJECT_ROOTS,
          new ModuleRootAdapter() {
            @Override
            public void rootsChanged(ModuleRootEvent event) {
              scheduleUpdate();
            }
          });
      myConnection.subscribe(GoLibrariesService.LIBRARIES_TOPIC, newRootUrls -> scheduleUpdate());

      Project project = myModule.getProject();
      StartupManager.getInstance(project)
          .runWhenProjectIsInitialized(
              () -> {
                if (!project.isDisposed() && !myModule.isDisposed()) {
                  for (PsiFileSystemItem vendor :
                      FilenameIndex.getFilesByName(
                          project, GoConstants.VENDOR, GoUtil.moduleScope(myModule), true)) {
                    if (vendor.isDirectory()) {
                      showVendoringNotification();
                      break;
                    }
                  }
                }
              });

      VirtualFileManager.getInstance().addVirtualFileListener(myFilesListener);
    }
    scheduleUpdate(0);
    myModuleInitialized = true;
  }
  @Nullable
  public static VirtualFile getDirectory(@NotNull final FindModel findModel) {
    String directoryName = findModel.getDirectoryName();
    if (findModel.isProjectScope() || StringUtil.isEmpty(directoryName)) {
      return null;
    }

    String path = directoryName.replace(File.separatorChar, '/');
    VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(path);
    if (virtualFile == null || !virtualFile.isDirectory()) {
      virtualFile = null;
      for (LocalFileProvider provider :
          ((VirtualFileManagerEx) VirtualFileManager.getInstance()).getLocalFileProviders()) {
        VirtualFile file = provider.findLocalVirtualFileByPath(path);
        if (file != null && file.isDirectory()) {
          if (file.getChildren().length > 0) {
            virtualFile = file;
            break;
          }
          if (virtualFile == null) {
            virtualFile = file;
          }
        }
      }
    }
    return virtualFile;
  }
  private static void attachJdkAnnotations(Sdk jdk) {
    LocalFileSystem lfs = LocalFileSystem.getInstance();
    VirtualFile root = null;
    if (root == null) { // community idea under idea
      root =
          lfs.findFileByPath(
              FileUtil.toSystemIndependentName(PathManager.getHomePath()) + "/java/jdkAnnotations");
    }
    if (root == null) { // idea under idea
      root =
          lfs.findFileByPath(
              FileUtil.toSystemIndependentName(PathManager.getHomePath())
                  + "/community/java/jdkAnnotations");
    }
    if (root == null) { // build
      root =
          VirtualFileManager.getInstance()
              .findFileByUrl(
                  "jar://"
                      + FileUtil.toSystemIndependentName(PathManager.getHomePath())
                      + "/lib/jdkAnnotations.jar!/");
    }
    if (root == null) {
      LOG.error(
          "jdk annotations not found in: "
              + FileUtil.toSystemIndependentName(PathManager.getHomePath())
              + "/lib/jdkAnnotations.jar!/");
      return;
    }

    SdkModificator modificator = jdk.getSdkModificator();
    modificator.removeRoot(root, AnnotationOrderRootType.getInstance());
    modificator.addRoot(root, AnnotationOrderRootType.getInstance());
    modificator.commitChanges();
  }
예제 #24
0
 public VirtualFile getOutputDir(IceComponent c) {
   VirtualFile file = outputDir.get(c);
   if (outputDirPath.get(c) != null && file == null) {
     file = VirtualFileManager.getInstance().findFileByUrl(outputDirPath.get(c));
     outputDir.put(c, file);
   }
   return file;
 }
 public static VirtualFile findVirtualFile(String systemId) {
   try {
     return VfsUtil.findFileByURL(new URL(systemId));
   } catch (Exception e) {
     LOG.warn("Failed to build file from uri <" + systemId + ">", e);
     return VirtualFileManager.getInstance().findFileByUrl(VfsUtilCore.fixURLforIDEA(systemId));
   }
 }
    public CachedValueProvider.Result<VirtualFile[]> compute(PsiFile psiFile) {
      VirtualFile[] value = computeFiles(psiFile, myRuntimeOnly);
      // todo: we need "url modification tracker" for VirtualFile
      Object[] deps = new Object[value.length + 2];
      deps[deps.length - 2] = psiFile;
      deps[deps.length - 1] = VirtualFileManager.getInstance();

      return CachedValueProvider.Result.create(value, deps);
    }
예제 #27
0
 public TableItem(String url) {
   myUrl = url;
   final VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url);
   if (file != null) {
     myCellAppearance = CellAppearanceUtils.forVirtualFile(file);
   } else {
     myCellAppearance = SimpleTextCellAppearance.invalid(url, CellAppearanceUtils.INVALID_ICON);
   }
 }
  public ProjectRootManagerComponent(Project project, StartupManager startupManager) {
    super(project);

    myConnection = project.getMessageBus().connect(project);
    myConnection.subscribe(
        FileTypeManager.TOPIC,
        new FileTypeListener() {
          @Override
          public void beforeFileTypesChanged(@NotNull FileTypeEvent event) {
            beforeRootsChange(true);
          }

          @Override
          public void fileTypesChanged(@NotNull FileTypeEvent event) {
            rootsChanged(true);
          }
        });

    VirtualFileManager.getInstance()
        .addVirtualFileManagerListener(
            new VirtualFileManagerAdapter() {
              @Override
              public void afterRefreshFinish(boolean asynchronous) {
                doUpdateOnRefresh();
              }
            },
            project);

    startupManager.registerStartupActivity(
        new Runnable() {
          @Override
          public void run() {
            myStartupActivityPerformed = true;
          }
        });

    myHandler =
        new BatchUpdateListener() {
          @Override
          public void onBatchUpdateStarted() {
            myRootsChanged.levelUp();
            myFileTypesChanged.levelUp();
          }

          @Override
          public void onBatchUpdateFinished() {
            myRootsChanged.levelDown();
            myFileTypesChanged.levelDown();
          }
        };

    myConnection.subscribe(VirtualFilePointerListener.TOPIC, new MyVirtualFilePointerListener());
    myDoLogCachesUpdate =
        ApplicationManager.getApplication().isInternal()
            && !ApplicationManager.getApplication().isUnitTestMode();
  }
  public void testCreationOfExcludedDirWithFilesDuringRefreshShouldNotThrowException()
      throws Exception {
    // there was a problem with the DirectoryIndex - the files that were created during the refresh
    // were not correctly excluded, thereby causing the LocalHistory to fail during addition of
    // files under the excluded dir.

    File targetDir = createTargetDir();
    FileUtil.copyDir(targetDir, new File(myRoot.getPath(), "target"));
    VirtualFileManager.getInstance().syncRefresh();

    String classesPath = myRoot.getPath() + "/target/classes";
    addExcludedDir(classesPath);
    final VirtualFile classesDir = LocalFileSystem.getInstance().findFileByPath(classesPath);
    assertNotNull(classesDir);
    delete(classesDir.getParent());

    FileUtil.copyDir(targetDir, new File(myRoot.getPath(), "target"));
    VirtualFileManager.getInstance().syncRefresh(); // shouldn't throw
  }
 @Override
 public void disposeComponent() {
   Disposer.dispose(myConnection);
   Disposer.dispose(myAlarm);
   VirtualFileManager.getInstance().removeVirtualFileListener(myFilesListener);
   myLastHandledGoPathSourcesRoots.clear();
   myLastHandledExclusions.clear();
   LocalFileSystem.getInstance().removeWatchedRoots(myWatchedRequests);
   myWatchedRequests.clear();
 }