@NotNull
  private static String getFileFqn(final PsiFile file) {
    final VirtualFile virtualFile = file.getVirtualFile();
    if (virtualFile == null) {
      return file.getName();
    }
    final Project project = file.getProject();
    final LogicalRoot logicalRoot =
        LogicalRootsManager.getLogicalRootsManager(project).findLogicalRoot(virtualFile);
    if (logicalRoot != null) {
      String logical =
          FileUtil.toSystemIndependentName(
              VfsUtil.virtualToIoFile(logicalRoot.getVirtualFile()).getPath());
      String path =
          FileUtil.toSystemIndependentName(VfsUtil.virtualToIoFile(virtualFile).getPath());
      return "/" + FileUtil.getRelativePath(logical, path, '/');
    }

    final VirtualFile contentRoot =
        ProjectRootManager.getInstance(project).getFileIndex().getContentRootForFile(virtualFile);
    if (contentRoot != null) {
      return "/"
          + FileUtil.getRelativePath(
              VfsUtil.virtualToIoFile(contentRoot), VfsUtil.virtualToIoFile(virtualFile));
    }
    return virtualFile.getPath();
  }
 protected static void touch(VirtualFile file) throws IOException {
   file.setBinaryContent(
       file.contentsToByteArray(), file.getModificationStamp() + 1, file.getTimeStamp() + 1);
   File ioFile = VfsUtil.virtualToIoFile(file);
   assert ioFile.setLastModified(ioFile.lastModified() - 100000);
   file.refresh(false, false);
 }
Пример #3
0
  protected static synchronized void closeAndDeleteProject() {
    if (ourProject != null) {
      final VirtualFile projFile = ((ProjectEx) ourProject).getStateStore().getProjectFile();
      final File projectFile = projFile == null ? null : VfsUtil.virtualToIoFile(projFile);
      if (!ourProject.isDisposed()) Disposer.dispose(ourProject);

      if (projectFile != null) {
        FileUtil.delete(projectFile);
      }
    }
  }
 public void actionPerformed(ActionEvent e) {
   VirtualFile[] files =
       FileChooser.chooseFiles(myEditorContext.getProject(), CHOOSER_DESCRIPTOR);
   tablePlugins.clearSelection();
   for (VirtualFile file : files) {
     String path =
         CompilerPlugin.pathTo(VfsUtil.virtualToIoFile(file), myEditorContext.getModule());
     CompilerPlugin item = new CompilerPlugin(path, myEditorContext.getModule());
     getPluginsModel().addRow(item);
     tablePlugins.addSelection(item);
   }
   tablePlugins.requestFocusInWindow();
 }
Пример #5
0
  protected List<File> getImplicitClasspathRoots(@NotNull Module module) {
    final List<File> toExclude = new ArrayList<File>();

    VirtualFile sdkRoot = getSdkRoot(module);
    if (sdkRoot != null) toExclude.add(VfsUtil.virtualToIoFile(sdkRoot));

    ContainerUtil.addIfNotNull(getCommonPluginsDir(module), toExclude);
    final VirtualFile appRoot = findAppRoot(module);
    if (appRoot != null) {
      VirtualFile pluginDir = appRoot.findChild(MvcModuleStructureUtil.PLUGINS_DIRECTORY);
      if (pluginDir != null) toExclude.add(VfsUtil.virtualToIoFile(pluginDir));

      VirtualFile libDir = appRoot.findChild("lib");
      if (libDir != null) toExclude.add(VfsUtil.virtualToIoFile(libDir));
    }

    final Library library = MvcModuleStructureUtil.findUserLibrary(module, getUserLibraryName());
    if (library != null) {
      for (VirtualFile file : library.getFiles(OrderRootType.CLASSES)) {
        toExclude.add(VfsUtil.virtualToIoFile(PathUtil.getLocalFile(file)));
      }
    }
    return toExclude;
  }
 private static void addLibraryJar(
     final VirtualFile virtualFile,
     final File zipFile,
     final String pluginName,
     final ZipOutputStream zos,
     final Set<String> usedJarNames,
     final ProgressIndicator progressIndicator)
     throws IOException {
   File ioFile = VfsUtil.virtualToIoFile(virtualFile);
   final String jarName = getLibraryJarName(ioFile.getName(), usedJarNames, null);
   ZipUtil.addFileOrDirRecursively(
       zos,
       zipFile,
       ioFile,
       getZipPath(pluginName, jarName),
       createFilter(progressIndicator, null),
       null);
 }
Пример #7
0
  private PathsList removeFrameworkStuff(Module module, List<VirtualFile> rootFiles) {
    final List<File> toExclude = getImplicitClasspathRoots(module);
    if (LOG.isDebugEnabled()) {
      LOG.debug("Before removing framework stuff: " + rootFiles);
      LOG.debug("Implicit roots:" + toExclude);
    }

    PathsList scriptClassPath = new PathsList();
    eachRoot:
    for (VirtualFile file : rootFiles) {
      for (final File excluded : toExclude) {
        if (VfsUtil.isAncestor(excluded, VfsUtil.virtualToIoFile(file), false)) {
          continue eachRoot;
        }
      }
      scriptClassPath.add(file);
    }
    return scriptClassPath;
  }
Пример #8
0
  /**
   * Here we check if a given file belongs to our plugin. We take this road because we need the
   * actual file and not a filename to check files without extension.
   *
   * <p>A file is checked according to the rules defined in the facet settings. A file can be set to
   * ignored, accepted or auto. Auto means that the content is checked.
   *
   * @param file The file to check
   * @return True if BashSupport wants to take that file
   */
  public boolean isMyFileType(VirtualFile file) {
    if (file == null) {
      return false;
    }

    if (file.isDirectory()) {
      return false;
    }

    if (extensionList.contains(file.getExtension())) {
      return true;
    } else if (!file.isInLocalFileSystem()) {
      return false;
    } else if (StringUtils.isEmpty(file.getExtension())) {
      BashFacet facet = null;
      try {
        // no extensions, special checks (looking at the content, etc)

        // guess project
        Project project = ProjectUtil.guessProjectForFile(file);
        if (project == null) {
          return false;
        }

        DumbServiceImpl dumbService = DumbServiceImpl.getInstance(project);
        if (dumbService == null || dumbService.isDumb()) {
          return false;
        }

        DirectoryIndex directoryIndex = DirectoryIndex.getInstance(project);
        if (directoryIndex == null || !directoryIndex.isInitialized()) {
          return false;
        }

        Module module = ModuleUtil.findModuleForFile(file, project);
        if (module == null) {
          return false;
        }

        facet = BashFacet.getInstance(module);
        if (facet == null) {
          return false;
        }

        BashFacetConfiguration config = facet.getConfiguration();
        FileMode mode = config.findMode(file);

        if (mode == FileMode.accept()) {
          return true;
        } else if (mode == FileMode.ignore()) {
          return false;
        } else if (mode == FileMode.auto()) {
          return BashContentUtil.isProbablyBashFile(
              VfsUtil.virtualToIoFile(file),
              MIN_FILE_PROBABILIY,
              ProjectUtil.guessProjectForFile(file));
        }
      } catch (Exception e) {
        // ignore this
        LOG.warn("Could not check the file type due to exception", e);
      }
    }

    return false;
  }
 public BuckKillCommandHandler(
     final Project project, final VirtualFile root, final BuckCommand command) {
   super(project, VfsUtil.virtualToIoFile(root), command);
 }