Exemplo n.º 1
0
  @Override
  public void recalculateOutputDirs() {
    final Module[] allModules = ModuleManager.getInstance(myProject).getModules();

    final Set<VirtualFile> allDirs = new OrderedSet<VirtualFile>();
    final Set<VirtualFile> testOutputDirs = new java.util.HashSet<VirtualFile>();
    final Set<VirtualFile> productionOutputDirs = new java.util.HashSet<VirtualFile>();

    CompilerPathsManager pathsManager = CompilerPathsManager.getInstance(getProject());
    for (Module module : allModules) {
      final VirtualFile output =
          pathsManager.getCompilerOutput(module, ProductionContentFolderTypeProvider.getInstance());
      if (output != null && output.isValid()) {
        allDirs.add(output);
        productionOutputDirs.add(output);
      }

      final VirtualFile testsOutput =
          pathsManager.getCompilerOutput(module, TestContentFolderTypeProvider.getInstance());
      if (testsOutput != null && testsOutput.isValid()) {
        allDirs.add(testsOutput);
        testOutputDirs.add(testsOutput);
      }
    }
    myOutputDirectories = VfsUtil.toVirtualFileArray(allDirs);
    // need this to ensure that the sent contains only _dedicated_ test output dirs
    // Directories that are configured for both test and production classes must not be added in the
    // resulting set
    testOutputDirs.removeAll(productionOutputDirs);
    myTestOutputDirectories = Collections.unmodifiableSet(testOutputDirs);
  }
  public void testFileCaseChange() throws Exception {
    if (SystemInfo.isFileSystemCaseSensitive) {
      System.err.println("Ignored: case-insensitive FS required");
      return;
    }

    File top = createTempDirectory(false);
    File file = IoTestUtil.createTestFile(top, "file.txt", "test");
    File intermediate = new File(top, "_intermediate_");

    LocalFileSystem lfs = LocalFileSystem.getInstance();
    VirtualFile topDir = lfs.refreshAndFindFileByIoFile(top);
    assertNotNull(topDir);
    VirtualFile sourceFile = lfs.refreshAndFindFileByIoFile(file);
    assertNotNull(sourceFile);

    String newName = StringUtil.capitalize(file.getName());
    FileUtil.rename(file, intermediate);
    FileUtil.rename(intermediate, new File(top, newName));
    topDir.refresh(false, true);
    assertFalse(((VirtualDirectoryImpl) topDir).allChildrenLoaded());
    assertTrue(sourceFile.isValid());
    assertEquals(newName, sourceFile.getName());

    topDir.getChildren();
    newName = newName.toLowerCase();
    FileUtil.rename(file, intermediate);
    FileUtil.rename(intermediate, new File(top, newName));
    topDir.refresh(false, true);
    assertTrue(((VirtualDirectoryImpl) topDir).allChildrenLoaded());
    assertTrue(sourceFile.isValid());
    assertEquals(newName, sourceFile.getName());
  }
  private void doSaveDocument(@NotNull final Document document)
      throws IOException, SaveVetoException {
    VirtualFile file = getFile(document);

    if (file == null
        || file instanceof LightVirtualFile
        || file.isValid() && !isFileModified(file)) {
      removeFromUnsaved(document);
      return;
    }

    if (file.isValid() && needsRefresh(file)) {
      file.refresh(false, false);
      if (!myUnsavedDocuments.contains(document)) return;
    }

    for (FileDocumentSynchronizationVetoer vetoer :
        Extensions.getExtensions(FileDocumentSynchronizationVetoer.EP_NAME)) {
      if (!vetoer.maySaveDocument(document)) {
        throw new SaveVetoException();
      }
    }

    final AccessToken token =
        ApplicationManager.getApplication().acquireWriteActionLock(getClass());
    try {
      doSaveDocumentInWriteAction(document, file);
    } finally {
      token.finish();
    }
  }
 @NotNull
 private VirtualFile getOrCreateExtractDirVirtualFile() {
   File extractDir = new File(myDirectoryTextField.getText());
   VirtualFile vFile = LocalFileSystem.getInstance().findFileByIoFile(extractDir);
   if (vFile == null || !vFile.isValid()) {
     vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(extractDir);
     if (vFile == null || !vFile.isValid()) {
       throw new RuntimeException(
           "Can't find valid VirtualFile for " + extractDir.getAbsolutePath());
     }
   }
   return vFile;
 }
Exemplo n.º 5
0
  public Object getData(String dataId) {
    if (PlatformDataKeys.VIRTUAL_FILE_ARRAY.getName().equals(dataId)) {
      List<VirtualFile> files = new LinkedList<VirtualFile>();
      TreePath[] treePaths = getSelectionPaths();
      if (treePaths != null) {
        for (TreePath tp : treePaths) {
          Object lastPathComponent = tp.getLastPathComponent();
          if (lastPathComponent instanceof AbstractFileTreeNode) {
            AbstractFileTreeNode node = (AbstractFileTreeNode) lastPathComponent;
            VirtualFile file = node.getFile();
            if (file.isValid()) {
              files.add(file);
            }
          }
        }
      }
      return files.toArray(new VirtualFile[files.size()]);
    } else if (PlatformDataKeys.VIRTUAL_FILE.getName().equals(dataId)) {
      TreePath tp = getSelectedPath();
      if (tp == null) {
        return super.getData(dataId);
      }
      Object lastPathComponent = tp.getLastPathComponent();
      if (lastPathComponent instanceof AbstractFileTreeNode) {
        AbstractFileTreeNode node = (AbstractFileTreeNode) lastPathComponent;
        VirtualFile file = node.getFile();
        if (file.isValid()) {
          return file;
        }
      }
    } else if (PlatformDataKeys.COPY_PROVIDER.getName().equals(dataId)) {
      return new FilePaneCopyProvider();
    } else if (PlatformDataKeys.PASTE_PROVIDER.getName().equals(dataId)) {
      return new FilePanePasteProvider();
    } else if (PlatformDataKeys.CUT_PROVIDER.getName().equals(dataId)) {
      return new FilePaneCopyProvider();
    } else if (dataId.equals(MPSDataKeys.PLACE.getName())) {
      TreeNode treeNode = getSelectedTreeNode(TreeNode.class);
      if (treeNode instanceof ModuleTreeNode) {
        return ActionPlace.PROJECT_PANE_MODULE;
      } else if (treeNode instanceof FileTreeNode) {
        return ActionPlace.PROJECT_PANE_FILE;
      } else if (treeNode instanceof FolderTreeNode) {
        return ActionPlace.PROJECT_PANE_FOLDER;
      }
    }

    return super.getData(dataId);
  }
Exemplo n.º 6
0
 private VirtualFile getVirtualFile(String relPath) {
   VirtualFile fileByPath = instance.findFileByPath(context.absPath(relPath));
   if (fileByPath != null && fileByPath.isValid()) {
     return fileByPath;
   }
   return null;
 }
    public Object getData(@NonNls final String dataId) {
      if (PlatformDataKeys.PROJECT.is(dataId)) {
        return myProject;
      }
      if (PlatformDataKeys.VIRTUAL_FILE.is(dataId)) {
        final VirtualFile selectedFile = myWindow.getSelectedFile();
        return selectedFile != null && selectedFile.isValid() ? selectedFile : null;
      }
      if (EditorWindow.DATA_KEY.is(dataId)) {
        return myWindow;
      }
      if (PlatformDataKeys.HELP_ID.is(dataId)) {
        return HELP_ID;
      }

      if (CloseAction.CloseTarget.KEY.is(dataId)) {
        TabInfo selected = myTabs.getSelectedInfo();
        if (selected != null) {
          return EditorTabbedContainer.this;
        }
      }

      if (EditorWindow.DATA_KEY.is(dataId)) {
        return myWindow;
      }

      return null;
    }
Exemplo n.º 8
0
 public static void addLibraryChildren(
     final LibraryOrSdkOrderEntry entry,
     final List<AbstractTreeNode> children,
     Project project,
     ProjectViewNode node) {
   final PsiManager psiManager = PsiManager.getInstance(project);
   VirtualFile[] files =
       entry instanceof LibraryOrderEntry
           ? getLibraryRoots((LibraryOrderEntry) entry)
           : entry.getRootFiles(OrderRootType.CLASSES);
   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()));
     }
   }
 }
  public void testSingleFileRootRefresh() throws Exception {
    File file = FileUtil.createTempFile("test.", ".txt");
    VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
    assertNotNull(virtualFile);
    assertTrue(virtualFile.exists());
    assertTrue(virtualFile.isValid());

    virtualFile.refresh(false, false);
    assertFalse(((VirtualFileSystemEntry) virtualFile).isDirty());

    FileUtil.delete(file);
    assertFalse(file.exists());
    virtualFile.refresh(false, false);
    assertFalse(virtualFile.exists());
    assertFalse(virtualFile.isValid());
  }
Exemplo n.º 10
0
  public static void flushCache(@Nullable VirtualFile finishedFile) {
    if (finishedFile == null || !myFinishedFiles.offer(finishedFile)) {
      VirtualFile[] files = null;
      synchronized (myFinishedFiles) {
        int size = myFinishedFiles.size();
        if ((finishedFile == null && size > 0) || size == CAPACITY) {
          files = myFinishedFiles.toArray(new VirtualFile[size]);
          myFinishedFiles.clear();
        }
      }

      if (files != null) {
        for (VirtualFile file : files) {
          synchronized (getStripedLock(file)) {
            Timestamps timestamp = myTimestampsCache.remove(file);
            if (timestamp == null) continue;
            try {
              if (timestamp.isDirty() && file.isValid()) {
                final DataOutputStream sink = Timestamps.PERSISTENCE.writeAttribute(file);
                timestamp.writeToStream(sink);
                sink.close();
              }
            } catch (IOException e) {
              throw new RuntimeException(e);
            }
          }
        }
      }
      if (finishedFile != null) myFinishedFiles.offer(finishedFile);
    }
  }
Exemplo n.º 11
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)};
 }
 public String getDirName() {
   if (myVDirectory == null || !myVDirectory.isValid()) return "";
   if (myCompactPackages && myCompactedDirNode != null) {
     return myVDirectory.getName() + "/" + myCompactedDirNode.getDirName();
   }
   return myDirName;
 }
  private MergeRequestImpl(
      @NotNull DiffContent left,
      @NotNull DiffContent base,
      @NotNull DiffContent right,
      @Nullable Project project,
      @Nullable final ActionButtonPresentation okButtonPresentation,
      @Nullable final ActionButtonPresentation cancelButtonPresentation) {
    super(project);
    myOkButtonPresentation = okButtonPresentation;
    myCancelButtonPresentation = cancelButtonPresentation;
    myDiffContents[0] = left;
    myDiffContents[1] = base;
    myDiffContents[2] = right;

    if (MergeTool.LOG.isDebugEnabled()) {
      VirtualFile file = base.getFile();
      MergeTool.LOG.debug(
          new Throwable(
              base.getClass()
                  + " - writable: "
                  + base.getDocument().isWritable()
                  + ", contentType: "
                  + base.getContentType()
                  + ", file: "
                  + (file != null ? "valid - " + file.isValid() : "null")
                  + ", presentation: "
                  + myOkButtonPresentation
                  + "-"
                  + myCancelButtonPresentation));
    }
  }
 /* Remoting */
 private static void checkTargetJPDAInstalled(JavaParameters parameters)
     throws ExecutionException {
   final Sdk jdk = parameters.getJdk();
   if (jdk == null) {
     throw new ExecutionException(DebuggerBundle.message("error.jdk.not.specified"));
   }
   final JavaSdkVersion version = JavaSdk.getInstance().getVersion(jdk);
   String versionString = jdk.getVersionString();
   if (version == JavaSdkVersion.JDK_1_0 || version == JavaSdkVersion.JDK_1_1) {
     throw new ExecutionException(
         DebuggerBundle.message("error.unsupported.jdk.version", versionString));
   }
   if (SystemInfo.isWindows && version == JavaSdkVersion.JDK_1_2) {
     final VirtualFile homeDirectory = jdk.getHomeDirectory();
     if (homeDirectory == null || !homeDirectory.isValid()) {
       throw new ExecutionException(
           DebuggerBundle.message("error.invalid.jdk.home", versionString));
     }
     //noinspection HardCodedStringLiteral
     File dllFile =
         new File(
             homeDirectory.getPath().replace('/', File.separatorChar)
                 + File.separator
                 + "bin"
                 + File.separator
                 + "jdwp.dll");
     if (!dllFile.exists()) {
       GetJPDADialog dialog = new GetJPDADialog();
       dialog.show();
       throw new ExecutionException(DebuggerBundle.message("error.debug.libraries.missing"));
     }
   }
 }
Exemplo n.º 15
0
 @NotNull
 public static VirtualFile writeFile(
     @Nullable File file,
     @NotNull Object requestor,
     @Nullable VirtualFile virtualFile,
     @NotNull BufferExposingByteArrayOutputStream content,
     @Nullable LineSeparator lineSeparatorIfPrependXmlProlog)
     throws IOException {
   AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(null);
   try {
     if (file != null && (virtualFile == null || !virtualFile.isValid())) {
       virtualFile = getOrCreateVirtualFile(requestor, file);
     }
     assert virtualFile != null;
     OutputStream out = virtualFile.getOutputStream(requestor);
     try {
       if (lineSeparatorIfPrependXmlProlog != null) {
         out.write(XML_PROLOG);
         out.write(lineSeparatorIfPrependXmlProlog.getSeparatorBytes());
       }
       content.writeTo(out);
     } finally {
       out.close();
     }
     return virtualFile;
   } catch (FileNotFoundException e) {
     if (virtualFile == null) {
       throw e;
     } else {
       throw new ReadOnlyModificationException(virtualFile);
     }
   } finally {
     token.finish();
   }
 }
    @Override
    public void navigate(Project project) {
      VirtualFile currentVirtualFile = null;

      AccessToken accessToken = ReadAction.start();

      try {
        if (!myVirtualFile.isValid()) return;

        PsiFile psiFile = PsiManager.getInstance(project).findFile(myVirtualFile);
        if (psiFile != null) {
          PsiElement navigationElement =
              psiFile.getNavigationElement(); // Sources may be downloaded.
          if (navigationElement instanceof PsiFile) {
            currentVirtualFile = ((PsiFile) navigationElement).getVirtualFile();
          }
        }

        if (currentVirtualFile == null) {
          currentVirtualFile = myVirtualFile;
        }
      } finally {
        accessToken.finish();
      }

      new OpenFileHyperlinkInfo(myProject, currentVirtualFile, myLineNumber - 1).navigate(project);
    }
  public Object getData(String dataId) {
    if (myTreeBrowser != null && myTreeBrowser.isVisible()) {
      return null;
    }
    if (PlatformDataKeys.NAVIGATABLE.is(dataId)) {
      if (mySelectedFile == null || !mySelectedFile.isValid()) return null;
      return new OpenFileDescriptor(myProject, mySelectedFile);
    } else if (PlatformDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)) {
      return getVirtualFileArray();
    } else if (VcsDataKeys.IO_FILE_ARRAY.is(dataId)) {
      return getFileArray();
    } else if (PlatformDataKeys.TREE_EXPANDER.is(dataId)) {
      if (myGroupByChangeList) {
        return myTreeBrowser != null ? myTreeBrowser.getTreeExpander() : null;
      } else {
        return myTreeExpander;
      }
    } else if (VcsDataKeys.UPDATE_VIEW_SELECTED_PATH.is(dataId)) {
      return mySelectedUrl;
    } else if (VcsDataKeys.UPDATE_VIEW_FILES_ITERABLE.is(dataId)) {
      return myTreeIterable;
    } else if (VcsDataKeys.LABEL_BEFORE.is(dataId)) {
      return myBefore;
    } else if (VcsDataKeys.LABEL_AFTER.is(dataId)) {
      return myAfter;
    }

    return super.getData(dataId);
  }
 public static void clearCaches(
     @NotNull PsiFile injected, @NotNull DocumentWindowImpl documentWindow) {
   VirtualFileWindowImpl virtualFile = (VirtualFileWindowImpl) injected.getVirtualFile();
   PsiManagerEx psiManagerEx = (PsiManagerEx) injected.getManager();
   if (psiManagerEx.getProject().isDisposed()) return;
   psiManagerEx.getFileManager().setViewProvider(virtualFile, null);
   PsiElement context =
       InjectedLanguageManager.getInstance(injected.getProject()).getInjectionHost(injected);
   PsiFile hostFile;
   if (context != null) {
     hostFile = context.getContainingFile();
   } else {
     VirtualFile delegate = virtualFile.getDelegate();
     hostFile = delegate.isValid() ? psiManagerEx.findFile(delegate) : null;
   }
   if (hostFile != null) {
     // modification of cachedInjectedDocuments must be under PsiLock
     synchronized (PsiLock.LOCK) {
       List<DocumentWindow> cachedInjectedDocuments = getCachedInjectedDocuments(hostFile);
       for (int i = cachedInjectedDocuments.size() - 1; i >= 0; i--) {
         DocumentWindow cachedInjectedDocument = cachedInjectedDocuments.get(i);
         if (cachedInjectedDocument == documentWindow) {
           cachedInjectedDocuments.remove(i);
         }
       }
     }
   }
 }
Exemplo n.º 19
0
  @Nullable
  public Object getData(String dataId) {

    if (CommonDataKeys.PROJECT.is(dataId)) {
      return editor != null ? editor.getProject() : null;
    } else if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) {
      return editor != null ? editor.getFile() : null;
    } else if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)) {
      return editor != null ? new VirtualFile[] {editor.getFile()} : new VirtualFile[] {};
    } else if (CommonDataKeys.PSI_FILE.is(dataId)) {
      return getData(CommonDataKeys.PSI_ELEMENT.getName());
    } else if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
      VirtualFile file = editor != null ? editor.getFile() : null;
      return file != null && file.isValid()
          ? PsiManager.getInstance(editor.getProject()).findFile(file)
          : null;
    } else if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
      return editor != null
          ? new PsiElement[] {(PsiElement) getData(CommonDataKeys.PSI_ELEMENT.getName())}
          : new PsiElement[] {};
    } else if (PlatformDataKeys.COPY_PROVIDER.is(dataId) && copyPasteSupport != null) {
      return this;
    } else if (PlatformDataKeys.CUT_PROVIDER.is(dataId) && copyPasteSupport != null) {
      return copyPasteSupport.getCutProvider();
    } else if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
      return deleteProvider;
    } else if (ImageComponentDecorator.DATA_KEY.is(dataId)) {
      return editor != null ? editor : this;
    }

    return null;
  }
  public void annotate(
      @NotNull final VirtualFile contentRoot,
      @NotNull final CoverageSuitesBundle suite,
      final @NotNull CoverageDataManager dataManager,
      @NotNull final ProjectData data,
      final Project project,
      final Annotator annotator) {
    if (!contentRoot.isValid()) {
      return;
    }

    // TODO: check name filter!!!!!

    final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();

    @SuppressWarnings("unchecked")
    final Set<String> files = data.getClasses().keySet();
    final Map<String, String> normalizedFiles2Files = ContainerUtil.newHashMap();
    for (final String file : files) {
      normalizedFiles2Files.put(normalizeFilePath(file), file);
    }
    collectFolderCoverage(
        contentRoot,
        dataManager,
        annotator,
        data,
        suite.isTrackTestFolders(),
        index,
        suite.getCoverageEngine(),
        ContainerUtil.newHashSet(),
        Collections.unmodifiableMap(normalizedFiles2Files));
  }
Exemplo n.º 21
0
 private void showVFInfo(VirtualFile virtualFile) {
   logger.info("showVFInfo(): XML");
   logger.info("virtualFile: isValid= " + virtualFile.isValid());
   logger.info("virtualFile: isSymLink=" + virtualFile.isSymLink());
   logger.info("virtualFile: url= " + virtualFile.getUrl());
   logger.info("virtualFile: fileType= " + virtualFile.getFileType());
 }
  @Override
  public void contentsChanged(VirtualFileEvent event) {
    if (event.isFromSave()) return;
    final VirtualFile file = event.getFile();
    final Document document = getCachedDocument(file);
    if (document == null) {
      myMultiCaster.fileWithNoDocumentChanged(file);
      return;
    }

    if (isBinaryWithDecompiler(file)) {
      myMultiCaster.fileWithNoDocumentChanged(
          file); // This will generate PSI event at FileManagerImpl
    }

    long documentStamp = document.getModificationStamp();
    long oldFileStamp = event.getOldModificationStamp();
    if (documentStamp != oldFileStamp) {
      LOG.info("reload from disk?");
      LOG.info("  documentStamp:" + documentStamp);
      LOG.info("  oldFileStamp:" + oldFileStamp);

      if (file.isValid() && askReloadFromDisk(file, document)) {
        reloadFromDisk(document);
      }
    } else {
      reloadFromDisk(document);
    }
  }
Exemplo n.º 23
0
 private static boolean areFilesValid(VirtualFile[] files) {
   for (VirtualFile file : files) {
     if (!file.isValid()) {
       return false;
     }
   }
   return true;
 }
 public static boolean filesInvalidated(Set<VirtualFile> files) {
   for (VirtualFile file : files) {
     if (!file.isValid()) {
       return true;
     }
   }
   return false;
 }
Exemplo n.º 25
0
 @Override
 public StructureViewBuilder getStructureViewBuilder() {
   Document document = myComponent.getEditor().getDocument();
   VirtualFile file = FileDocumentManager.getInstance().getFile(document);
   if (file == null || !file.isValid()) return null;
   return StructureViewBuilder.PROVIDER.getStructureViewBuilder(
       file.getFileType(), file, myProject);
 }
Exemplo n.º 26
0
 @Nullable
 private VirtualFile getJarRoot() {
   final VirtualFile file = getVirtualFile();
   if (file == null || !file.isValid() || !(file.getFileType() instanceof ArchiveFileType)) {
     return null;
   }
   return JarFileSystem.getInstance().getJarRootForLocalFile(file);
 }
Exemplo n.º 27
0
 @Nullable
 public static <T extends MavenDomElement> T getMavenDomModel(
     @NotNull Project project, @NotNull VirtualFile file, @NotNull Class<T> clazz) {
   if (!file.isValid()) return null;
   PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
   if (psiFile == null) return null;
   return getMavenDomModel(psiFile, clazz);
 }
  @Override
  public PsiFile getCachedPsiFile(@NotNull Document document) {
    final PsiFile userData = document.getUserData(HARD_REF_TO_PSI);
    if (userData != null) return userData;

    final VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document);
    if (virtualFile == null || !virtualFile.isValid()) return null;
    return getCachedPsiFile(virtualFile);
  }
 private void selectInTree(final VirtualFile vFile, String fromText) {
   if (vFile != null && vFile.isValid()) {
     if (fromText == null || fromText.equalsIgnoreCase(myPathTextField.getTextFieldText())) {
       selectInTree(new VirtualFile[] {vFile}, false);
     }
   } else {
     reportFileNotFound();
   }
 }
 @Nullable
 private PsiDirectory getPsiDirectory() {
   if (myDirectory == null) {
     if (myVDirectory.isValid() && !myProject.isDisposed()) {
       myDirectory = PsiManager.getInstance(myProject).findDirectory(myVDirectory);
     }
   }
   return myDirectory;
 }