Java 类com.intellij.openapi.vfs.VfsUtil 实例源码

项目:hybris-integration-intellij-idea-plugin    文件:DefaultHybrisProjectDescriptor.java   
@NotNull
protected Set<HybrisModuleDescriptor> getAlreadyOpenedModules(@NotNull final Project project) {
    Validate.notNull(project);

    final HybrisModuleDescriptorFactory hybrisModuleDescriptorFactory = ServiceManager.getService(
        HybrisModuleDescriptorFactory.class
    );

    final Set<HybrisModuleDescriptor> existingModules = new THashSet<HybrisModuleDescriptor>();

    for (Module module : ModuleManager.getInstance(project).getModules()) {
        try {
            final VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots();

            if (!ArrayUtils.isEmpty(contentRoots)) {
                existingModules.add(hybrisModuleDescriptorFactory.createDescriptor(
                    VfsUtil.virtualToIoFile(contentRoots[0]), this
                ));
            }
        } catch (HybrisConfigurationException e) {
            LOG.error(e);
        }
    }

    return existingModules;
}
项目:hybris-integration-intellij-idea-plugin    文件:OotbHybrisModuleDescriptor.java   
public void createGlobalLibrary(
    @NotNull final IdeModifiableModelsProvider modifiableModelsProvider,
    @NotNull final File libraryDirRoot,
    @NotNull final String libraryName
) {
    final LibraryTable.ModifiableModel libraryTableModifiableModel = modifiableModelsProvider
        .getModifiableProjectLibrariesModel();

    Library library = libraryTableModifiableModel.getLibraryByName(libraryName);
    if (null == library) {
        library = libraryTableModifiableModel.createLibrary(libraryName);
    }

    if (libraryTableModifiableModel instanceof LibrariesModifiableModel) {
        final ExistingLibraryEditor existingLibraryEditor = ((LibrariesModifiableModel) libraryTableModifiableModel)
            .getLibraryEditor(library);
        existingLibraryEditor.addJarDirectory(
            VfsUtil.getUrlForLibraryRoot(libraryDirRoot), true, OrderRootType.CLASSES
        );
    } else {
        final Library.ModifiableModel libraryModifiableModel = modifiableModelsProvider
            .getModifiableLibraryModel(library);
        libraryModifiableModel.addJarDirectory(VfsUtil.getUrlForLibraryRoot(libraryDirRoot), true);
    }
}
项目:hybris-integration-intellij-idea-plugin    文件:DefaultAntConfigurator.java   
private AntBuildFileBase findBuildFile(final File dir) {
    final File buildxml = new File(dir, HybrisConstants.ANT_BUILD_XML);
    if (!buildxml.exists()) {
        return null;
    }

    final VirtualFile buildFile = VfsUtil.findFileByIoFile(buildxml, true);
    if (buildFile == null) {
        return null;
    }

    final AntBuildFile antBuildFile;
    try {
        antBuildFile = antConfiguration.addBuildFile(buildFile);
    } catch (AntNoFileException e) {
        return null;
    }

    if (antBuildFile instanceof AntBuildFileBase) {
        return (AntBuildFileBase) antBuildFile;
    }
    return null;
}
项目:hybris-integration-intellij-idea-plugin    文件:DefaultLibRootsConfigurator.java   
@Nullable
private VirtualFile getSourceCodeRoot(final @NotNull HybrisModuleDescriptor moduleDescriptor) {
    final VirtualFile sourceCodeRoot;
    final File sourceCodeFile = moduleDescriptor.getRootProjectDescriptor().getSourceCodeFile();

    if (null != sourceCodeFile) {
        final VirtualFile sourceVFile = VfsUtil.findFileByIoFile(sourceCodeFile, true);
        if (null == sourceVFile) {
            sourceCodeRoot = null;
        } else if (sourceVFile.isDirectory()) {
            sourceCodeRoot = sourceVFile;
        } else {
            sourceCodeRoot = JarFileSystem.getInstance().getJarRootForLocalFile(sourceVFile);
        }
    } else {
        sourceCodeRoot = null;
    }

    return sourceCodeRoot;
}
项目:hybris-integration-intellij-idea-plugin    文件:RegularContentRootConfigurator.java   
protected void configureBackOfficeRoots(
    @NotNull final HybrisModuleDescriptor moduleDescriptor,
    @NotNull final ContentEntry contentEntry
) {
    Validate.notNull(moduleDescriptor);
    Validate.notNull(contentEntry);

    final File backOfficeModuleDirectory = new File(
        moduleDescriptor.getRootDirectory(), BACK_OFFICE_MODULE_DIRECTORY
    );

    final File backOfficeSrcDirectory = new File(backOfficeModuleDirectory, SRC_DIRECTORY);
    contentEntry.addSourceFolder(
        VfsUtil.pathToUrl(backOfficeSrcDirectory.getAbsolutePath()),
        JavaSourceRootType.SOURCE
    );

    addTestSourceRoots(contentEntry, backOfficeModuleDirectory);

    final File hmcResourcesDirectory = new File(backOfficeModuleDirectory, RESOURCES_DIRECTORY);
    contentEntry.addSourceFolder(
        VfsUtil.pathToUrl(hmcResourcesDirectory.getAbsolutePath()),
        JavaResourceRootType.RESOURCE
    );
    excludeDirectory(contentEntry, new File(backOfficeModuleDirectory, CLASSES_DIRECTORY));
}
项目:hybris-integration-intellij-idea-plugin    文件:RegularContentRootConfigurator.java   
protected void configurePlatformRoots(
    @NotNull final HybrisModuleDescriptor moduleDescriptor,
    @NotNull final ContentEntry contentEntry
) {
    Validate.notNull(moduleDescriptor);
    Validate.notNull(contentEntry);

    if (!HybrisConstants.PLATFORM_EXTENSION_NAME.equalsIgnoreCase(moduleDescriptor.getName())) {
        return;
    }
    final File rootDirectory = moduleDescriptor.getRootDirectory();
    final File platformBootstrapDirectory = new File(rootDirectory, PLATFORM_BOOTSTRAP_DIRECTORY);

    if (!moduleDescriptor.getRootProjectDescriptor().isImportOotbModulesInReadOnlyMode()) {

        final File platformBootstrapResourcesDirectory = new File(platformBootstrapDirectory, RESOURCES_DIRECTORY);
        contentEntry.addSourceFolder(
            VfsUtil.pathToUrl(platformBootstrapResourcesDirectory.getAbsolutePath()),
            JavaResourceRootType.RESOURCE
        );
    }

    excludeDirectory(contentEntry, new File(platformBootstrapDirectory, PLATFORM_MODEL_CLASSES_DIRECTORY));
    excludeDirectory(contentEntry, new File(rootDirectory, PLATFORM_TOMCAT_DIRECTORY));
    contentEntry.addExcludePattern("apache-ant-*");
}
项目:hybris-integration-intellij-idea-plugin    文件:ReadOnlyContentRootConfigurator.java   
protected void configureAdditionalRoots(
    @NotNull final HybrisModuleDescriptor moduleDescriptor,
    @NotNull final String directoryName,
    @NotNull final ContentEntry contentEntry,
    @NotNull final File parentDirectory
) {
    Validate.notNull(moduleDescriptor);
    Validate.notNull(directoryName);
    Validate.notNull(contentEntry);
    Validate.notNull(parentDirectory);

    final File additionalModuleDirectory = new File(parentDirectory, directoryName);
    if (!additionalModuleDirectory.exists() || additionalModuleDirectory.isFile()) {
        return;
    }

    final File additionalClassesDirectory = new File(additionalModuleDirectory, CLASSES_DIRECTORY);
    contentEntry.addExcludeFolder(
        VfsUtil.pathToUrl(additionalClassesDirectory.getAbsolutePath())
    );
}
项目:hybris-integration-intellij-idea-plugin    文件:ReadOnlyContentRootConfigurator.java   
protected void configureBackOfficeRoots(
    @NotNull final HybrisModuleDescriptor moduleDescriptor,
    @NotNull final ContentEntry contentEntry
) {
    Validate.notNull(moduleDescriptor);
    Validate.notNull(contentEntry);

    final File backOfficeModuleDirectory = new File(
        moduleDescriptor.getRootDirectory(), BACK_OFFICE_MODULE_DIRECTORY
    );

    final File hmcClassesDirectory = new File(backOfficeModuleDirectory, CLASSES_DIRECTORY);
    contentEntry.addExcludeFolder(
        VfsUtil.pathToUrl(hmcClassesDirectory.getAbsolutePath())
    );
}
项目:hybris-integration-intellij-idea-plugin    文件:ReadOnlyContentRootConfigurator.java   
protected void configureWebModuleRoots(
    @NotNull final HybrisModuleDescriptor moduleDescriptor,
    final @NotNull ContentEntry contentEntry,
    final File webModuleDirectory
) {
    Validate.notNull(moduleDescriptor);

    final File webAddonSrcDirectory = new File(webModuleDirectory, ADDON_SRC_DIRECTORY);
    contentEntry.addExcludeFolder(
        VfsUtil.pathToUrl(webAddonSrcDirectory.getAbsolutePath())
    );

    final File webTestClassesDirectory = new File(webModuleDirectory, TEST_CLASSES_DIRECTORY);
    contentEntry.addExcludeFolder(
        VfsUtil.pathToUrl(webTestClassesDirectory.getAbsolutePath())
    );

    final File commonWebSrcDirectory = new File(webModuleDirectory, COMMON_WEB_SRC_DIRECTORY);
    contentEntry.addExcludeFolder(
        VfsUtil.pathToUrl(commonWebSrcDirectory.getAbsolutePath())
    );
}
项目:hybris-integration-intellij-idea-plugin    文件:HybrisProjectOpenProcessor.java   
@Override
public boolean doQuickImport(final VirtualFile file, final WizardContext wizardContext) {
    this.getBuilder().cleanup();
    this.getBuilder().setRootProjectDirectory(VfsUtil.virtualToIoFile(file.getParent()));

    final List<HybrisModuleDescriptor> projects = this.getBuilder().getList();
    if (null == projects || 1 != projects.size()) {
        return false;
    }

    try {
        this.getBuilder().setList(projects);
    } catch (ConfigurationException e) {
        LOG.error(e);
    }

    wizardContext.setProjectName(projects.get(0).getName());

    return true;
}
项目:educational-plugin    文件:EduTaskModuleBuilder.java   
@NotNull
@Override
public Module createModule(@NotNull ModifiableModuleModel moduleModel) throws InvalidDataException, IOException, ModuleWithNameAlreadyExists, JDOMException, ConfigurationException {
  Module module = super.createModule(moduleModel);
  Course course = myTask.getLesson().getCourse();
  String directory = getModuleFileDirectory();
  if (directory == null) {
    return module;
  }
  VirtualFile moduleDir = VfsUtil.findFileByIoFile(new File(directory), true);
  if (moduleDir == null) {
    return module;
  }
  VirtualFile src = moduleDir.findChild(EduNames.SRC);
  if (src == null) {
    return module;
  }
  createTask(module.getProject(), course, src);
  ModuleRootModificationUtil.addDependency(module, myUtilModule);
  EduIntellijUtils.addJUnit(module);
  return module;
}
项目:educational-plugin    文件:StudyGenerator.java   
public static void createChildFile(@NotNull VirtualFile taskDir, @NotNull String name, @NotNull String text) throws IOException {
  String newDirectories = null;
  String fileName = name;
  VirtualFile dir = taskDir;
  if (name.contains("/")) {
    int pos = name.lastIndexOf("/");
    fileName = name.substring(pos + 1);
    newDirectories = name.substring(0, pos);
  }
  if (newDirectories != null) {
    dir = VfsUtil.createDirectoryIfMissing(taskDir, newDirectories);
  }
  if (dir != null) {
    VirtualFile virtualTaskFile = dir.findChild(fileName);
    if (virtualTaskFile == null) {
      virtualTaskFile = dir.createChildData(taskDir, fileName);
    }
    if (EduUtils.isImage(name)) {
      virtualTaskFile.setBinaryContent(Base64.decodeBase64(text));
    }
    else {
      VfsUtil.saveText(virtualTaskFile, text);
    }
  }
}
项目:educational-plugin    文件:EduKotlinPyCharmTaskChecker.java   
@Nullable
@Override
protected VirtualFile getTestsFile() {
  VirtualFile taskDir = myTask.getTaskDir(myProject);
  if (taskDir == null) {
    return null;
  }
  for (String testFileName : myTask.getTestsText().keySet()) {
    VirtualFile testFile = VfsUtil.findRelativeFile(taskDir, testFileName);
    if (testFile != null) {
      return testFile;
    }
  }
  VirtualFile testsFile = taskDir.findChild(EduKotlinPluginConfigurator.LEGACY_TESTS_KT);
  if (testsFile != null) {
    return testsFile;
  }
  return taskDir.findChild(EduKotlinPluginConfigurator.TESTS_KT);
}
项目:intellij-ce-playground    文件:MavenModuleBuilderTest.java   
public void testAddingNewlyCreatedModuleToTheAggregator() throws Exception {
  if (!hasMavenInstallation()) return;

  importProject("<groupId>test</groupId>" +
                "<artifactId>project</artifactId>" +
                "<version>1</version>");

  setModuleNameAndRoot("module", getProjectPath() + "/module");
  setAggregatorProject(myProjectPom);
  createNewModule(new MavenId("org.foo", "module", "1.0"));

  assertEquals(createPomXml("<groupId>test</groupId>" +
                            "<artifactId>project</artifactId>\n" +
                            "    <packaging>pom</packaging>\n" +
                            "    <version>1</version>\n" +
                            "    <modules>\n" +
                            "        <module>module</module>\n" +
                            "    </modules>\n"),
               StringUtil.convertLineSeparators(VfsUtil.loadText(myProjectPom)));
}
项目:intellij-ce-playground    文件:IgnoreFileAction.java   
private static CvsContextAdapter createContext(final Collection<VirtualFile> createdCvsIgnoreFiles, final CvsContext context) {
  return new CvsContextAdapter() {
    @NotNull
    public VirtualFile[] getSelectedFiles() {
      return VfsUtil.toVirtualFileArray(createdCvsIgnoreFiles);
    }

    public Refreshable getRefreshableDialog() {
      return context.getRefreshableDialog();
    }

    public Project getProject() {
      return context.getProject();
    }
  };
}
项目:lua-for-idea    文件:LuaResourceUnpacker.java   
@Override
public void initComponent() {
    VirtualFile pluginVirtualDirectory = LuaFileUtil.getPluginVirtualDirectory();

    if (pluginVirtualDirectory != null) {
        VirtualFile lib = pluginVirtualDirectory.findChild("lib");
        if (lib != null) {
            VirtualFile pluginJar = lib.findChild("IDLua.jar");

            JarFileSystem jfs = JarFileSystem.getInstance();

            VirtualFile std = jfs.findLocalVirtualFileByPath("include/stdlibrary");

            try {
                VfsUtil.copyDirectory(this, std, pluginVirtualDirectory, null);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
项目:intellij-ce-playground    文件:GitStashChangesSaver.java   
/**
 * Returns true if the root was loaded with conflict.
 * False is returned in all other cases: in the case of success and in case of some other error.
 */
private boolean loadRoot(final VirtualFile root) {
  LOG.info("loadRoot " + root);
  myProgressIndicator.setText(GitHandlerUtil.formatOperationName("Unstashing changes to", root));

  GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
  if (repository == null) {
    LOG.error("Repository is null for root " + root);
    return false;
  }

  GitSimpleEventDetector conflictDetector = new GitSimpleEventDetector(GitSimpleEventDetector.Event.MERGE_CONFLICT_ON_UNSTASH);
  GitCommandResult result = myGit.stashPop(repository, conflictDetector);
  VfsUtil.markDirtyAndRefresh(false, true, false, root);
  if (result.success()) {
    return false;
  }
  else if (conflictDetector.hasHappened()) {
    return true;
  }
  else {
    LOG.info("unstash failed " + result.getErrorOutputAsJoinedString());
    GitUIUtil.notifyImportantError(myProject, "Couldn't unstash", "<br/>" + result.getErrorOutputAsHtmlString());
    return false;
  }
}
项目:intellij-ce-playground    文件:OpenFileAction.java   
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
  final Project project = e.getProject();
  final boolean showFiles = project != null || PlatformProjectOpenProcessor.getInstanceIfItExists() != null;
  final FileChooserDescriptor descriptor = showFiles ? new ProjectOrFileChooserDescriptor() : new ProjectOnlyFileChooserDescriptor();
  descriptor.putUserData(PathChooserDialog.PREFER_LAST_OVER_EXPLICIT, showFiles);

  FileChooser.chooseFiles(descriptor, project, VfsUtil.getUserHomeDir(), new Consumer<List<VirtualFile>>() {
    @Override
    public void consume(final List<VirtualFile> files) {
      for (VirtualFile file : files) {
        if (!descriptor.isFileSelectable(file)) {
          String message = IdeBundle.message("error.dir.contains.no.project", file.getPresentableUrl());
          Messages.showInfoMessage(project, message, IdeBundle.message("title.cannot.open.project"));
          return;
        }
      }
      doOpenFile(project, files);
    }
  });
}
项目:intellij-ce-playground    文件:PathsVerifier.java   
@Nullable
private VirtualFile makeSureParentPathExists(final String[] pieces) throws IOException {
  VirtualFile child = myBaseDirectory;

  final int size = (pieces.length - 1);
  for (int i = 0; i < size; i++) {
    final String piece = pieces[i];
    if ("".equals(piece)) {
      continue;
    }
    if ("..".equals(piece)) {
      child = child.getParent();
      continue;
    }

    VirtualFile nextChild = child.findChild(piece);
    if (nextChild == null) {
      nextChild = VfsUtil.createDirectories(child.getPath() + '/' + piece);
      myCreatedDirectories.add(nextChild);
    }
    child = nextChild;
  }
  return child;
}
项目:intellij-ce-playground    文件:LocalChangesUnderRoots.java   
@Nullable
private VirtualFile getRootForPath(@NotNull FilePath file, @NotNull Collection<VirtualFile> rootsToSave) {
  final VirtualFile vf = ChangesUtil.findValidParentUnderReadAction(file);
  if (vf == null) {
    return null;
  }
  VirtualFile rootCandidate = null;
  for (VcsRoot root : myRoots) {
    if (VfsUtilCore.isAncestor(root.getPath(), vf, false)) {
      if (rootCandidate == null || VfsUtil.isAncestor(rootCandidate, root.getPath(), true)) { // in the case of nested roots choose the closest root
        rootCandidate = root.getPath();
      }
    }
  }
  if (! rootsToSave.contains(rootCandidate)) return null;
  return rootCandidate;
}
项目:intellij-ce-playground    文件:PsiTestCase.java   
@NotNull
protected PsiFile createFile(@NotNull final Module module, @NotNull final VirtualFile vDir, @NotNull final String fileName, @NotNull final String text) throws IOException {
  return new WriteAction<PsiFile>() {
    @Override
    protected void run(@NotNull Result<PsiFile> result) throws Throwable {
      if (!ModuleRootManager.getInstance(module).getFileIndex().isInSourceContent(vDir)) {
        addSourceContentToRoots(module, vDir);
      }

      final VirtualFile vFile = vDir.createChildData(vDir, fileName);
      VfsUtil.saveText(vFile, text);
      assertNotNull(vFile);
      final PsiFile file = myPsiManager.findFile(vFile);
      assertNotNull(file);
      result.setResult(file);
    }
  }.execute().getResultObject();
}
项目:intellij-ce-playground    文件:LogicalRootsManagerImpl.java   
@Override
@Nullable
public LogicalRoot findLogicalRoot(@NotNull final VirtualFile file) {
  final Module module = ModuleUtil.findModuleForFile(file, myProject);
  if (module == null) return null;

  LogicalRoot result = null;
  final List<LogicalRoot> list = getLogicalRoots(module);
  for (final LogicalRoot root : list) {
    final VirtualFile rootFile = root.getVirtualFile();
    if (rootFile != null && VfsUtil.isAncestor(rootFile, file, false)) {
      result = root;
      break;
    }
  }

  return result;
}
项目:intellij-ce-playground    文件:ExternalChangesDetectionVcsTest.java   
@Test
public void testGeneration() throws Exception {
  for (int i = 0; i < 100; i++) {
    final File f = new File(myClientRoot, "f" + i + ".txt");
    f.createNewFile();
  }
  myWorkingCopyDir.refresh(false, true);
  myChangeListManager.ensureUpToDate(false);
  final List<VirtualFile> unversionedFiles = ((ChangeListManagerImpl)myChangeListManager).getUnversionedFiles();
  final Pattern pattern = Pattern.compile("f([0-9])+\\.txt");
  int cnt = 0;
  for (VirtualFile unversionedFile : unversionedFiles) {
    if (VfsUtil.isAncestor(myWorkingCopyDir, unversionedFile, true)) {
      ++ cnt;
      Assert.assertTrue(pattern.matcher(unversionedFile.getName()).matches());
    }
  }
  Assert.assertEquals(100, cnt);
}
项目:intellij-ce-playground    文件:MiscPsiTest.java   
public void testCopyBinaryToTextFile() throws Exception{
  String text = "1234567890";
  VirtualFile vFile = myFixture.addFileToProject("Test.xxx", text).getVirtualFile();

  VirtualFile vDir = myFixture.getTempDirFixture().findOrCreateDir("dir");

  PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
  PsiFile file = getPsiManager().findFile(vFile);
  PsiDirectory dir = getPsiManager().findDirectory(vDir);
  PsiFile fileCopy = (PsiFile)file.copy();
  fileCopy = (PsiFile) fileCopy.setName("NewTest.txt");
  PsiFile newFile = (PsiFile)dir.add(fileCopy);
  assertInstanceOf(newFile, PsiPlainTextFile.class);

  assertEquals(text, VfsUtil.loadText(newFile.getVirtualFile()));
  assertEquals(newFile.getVirtualFile().getModificationStamp(), newFile.getViewProvider().getModificationStamp());
  assertFalse(FileDocumentManager.getInstance().isFileModified(newFile.getVirtualFile()));
}
项目:intellij-ce-playground    文件:AddHandler.java   
private CvsContext createDataContext(final Collection<VirtualFile> files) {
  final Iterator<VirtualFile> first = files.iterator();
  return new CvsContextAdapter() {
    public Project getProject() {
      return myProject;
    }

    public VirtualFile getSelectedFile() {
      return first.hasNext() ? first.next() : null;
    }

    @NotNull
    public VirtualFile[] getSelectedFiles() {
      return VfsUtil.toVirtualFileArray(files);
    }
  };
}
项目:intellij-ce-playground    文件:PsiModificationTrackerTest.java   
public void testClassShouldNotDisappearWithoutEvents_NoDocument() throws IOException {
  PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
  final PsiManagerEx psiManager = (PsiManagerEx)PsiManager.getInstance(getProject());

  final VirtualFile file = myFixture.addFileToProject("Foo.java", "class Foo {}").getVirtualFile();
  assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
  long count1 = tracker.getJavaStructureModificationCount();

  // gc softly-referenced file and document
  PlatformTestUtil.tryGcSoftlyReachableObjects();
  assertNull(FileDocumentManager.getInstance().getCachedDocument(file));
  assertNull(psiManager.getFileManager().getCachedPsiFile(file));

  VfsUtil.saveText(file, "");
  assertNull(FileDocumentManager.getInstance().getCachedDocument(file));

  assertNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
  assertFalse(count1 == tracker.getJavaStructureModificationCount());
}
项目:intellij-ce-playground    文件:CaptureService.java   
public void update() {
  CaptureTypeService service = CaptureTypeService.getInstance();
  VirtualFile dir = getCapturesDirectory();
  Multimap<CaptureType, Capture> updated = LinkedListMultimap.create();
  if (dir != null) {
    VirtualFile[] children = VfsUtil.getChildren(dir);
    for (CaptureType type : service.getCaptureTypes()) {
      Set<VirtualFile> files = findCaptureFiles(children, type);
      for (Capture capture : myCaptures.get(type)) {
        // If an existing capture exists for a file, use it: Remove it from the files and add the already existing one.
        if (files.remove(capture.getFile())) {
          updated.put(type, capture);
        }
      }
      for (VirtualFile newFile : files) {
        updated.put(type, type.createCapture(newFile));
      }
    }
  }
  myCaptures = updated;
}
项目:intellij-ce-playground    文件:MvcProjectWithoutLibraryNotificator.java   
@Nullable
private static Pair<Module, MvcFramework> findModuleWithoutLibrary(Project project) {
  MvcFramework[] frameworks = MvcFramework.EP_NAME.getExtensions();

  for (Module module : ModuleManager.getInstance(project).getModules()) {
    for (MvcFramework framework : frameworks) {
      if (framework.hasFrameworkStructure(module) && !framework.hasFrameworkJar(module)) {
        if (VfsUtil.findRelativeFile(framework.findAppRoot(module), "application.properties") != null) {
          return Pair.create(module, framework);
        }
      }
    }
  }

  return null;
}
项目:intellij-ce-playground    文件:EditAction.java   
public static void editFiles(final Project project, final List<VirtualFile> files, final List<VcsException> exceptions) {
  ChangesUtil.processVirtualFilesByVcs(project, files, new ChangesUtil.PerVcsProcessor<VirtualFile>() {
    public void process(final AbstractVcs vcs, final List<VirtualFile> items) {
      final EditFileProvider provider = vcs.getEditFileProvider();
      if (provider != null) {
        try {
          provider.editFiles(VfsUtil.toVirtualFileArray(items));
        }
        catch (VcsException e1) {
          exceptions.add(e1);
        }
        for(VirtualFile file: items) {
          VcsDirtyScopeManager.getInstance(project).fileDirty(file);
          FileStatusManager.getInstance(project).fileStatusChanged(file);
        }
      }
    }
  });
}
项目:intellij-ce-playground    文件:LogFilter.java   
public Icon getIcon() {
  if (myIcon != null) {
    return myIcon;
  }
  if (myIconPath != null && new File(FileUtil.toSystemDependentName(myIconPath)).exists()) {
    Image image = null;
    try {
      image = ImageLoader.loadFromStream(VfsUtilCore.convertToURL(VfsUtil.pathToUrl(myIconPath)).openStream());
    }
    catch (IOException e) {
      LOG.debug(e);
    }

    if (image != null){
      return IconLoader.getIcon(image);
    }
  }
  //return IconLoader.getIcon("/ant/filter.png");
  return null;
}
项目:intellij-ce-playground    文件:GitCrlfProblemsDetectorTest.java   
public void test_warning_if_various_files_with_various_attributes_one_doesnt_match() throws IOException {
  gitattributes("\nwin1 text crlf diff\nwin2 -text\nwin3 text=auto\nwin4 crlf\nwin5 -crlf\nwin6 crlf=input\n");

  createFile("unix", "Unix file\nNice separators\nOnly LF\n");
  createCrlfFile("win1");
  createCrlfFile("win2");
  createCrlfFile("win3");
  createCrlfFile("src/win4");
  createCrlfFile("src/win5");
  createCrlfFile("src/win6");
  createCrlfFile("src/win7");

  List<VirtualFile> files = ContainerUtil.map(asList("unix", "win1", "win2", "win3", "src/win4", "src/win5", "src/win6", "src/win7"),
    new Function<String, VirtualFile>() {
      @Override
      public VirtualFile fun(String s) {
        return VfsUtil.findFileByIoFile(new File(myProjectRoot.getPath(), s), true);
      }
  });
  assertTrue("Warning should be done, since one of the files has CRLFs and no related attributes",
             GitCrlfProblemsDetector.detect(myProject, myPlatformFacade, myGit, files).shouldWarn());
}
项目:intellij-ce-playground    文件:FindClassTest.java   
public void testSynchronizationAfterChange() {
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    public void run() {
      FileDocumentManager.getInstance().saveAllDocuments();
      PsiClass psiClass = myJavaFacade.findClass("p.A");
      final VirtualFile vFile = psiClass.getContainingFile().getVirtualFile();
      File ioFile = VfsUtil.virtualToIoFile(vFile);
      ioFile.setLastModified(5);

      LocalFileSystem.getInstance().refresh(false);

      ModuleRootModificationUtil.setModuleSdk(myModule, null);

      psiClass = myJavaFacade.findClass("p.A");
      assertNotNull(psiClass);
    }
  });
}
项目:intellij-ce-playground    文件:IdCacheTest.java   
public void testFileModification() throws Exception {
  final CacheManager cache = CacheManager.SERVICE.getInstance(myProject);
  final TodoCacheManager todocache = TodoCacheManager.SERVICE.getInstance(myProject);
  checkCache(cache, todocache);

  VirtualFile child = myRootDir.findChild("1.java");

  checkCache(cache, todocache);

  VfsUtil.saveText(child, "xxx");
  PsiDocumentManager.getInstance(myProject).commitAllDocuments();

  final GlobalSearchScope scope = GlobalSearchScope.projectScope(myProject);
  checkResult(new String[] {"1.java"}, convert(cache.getFilesWithWord("xxx", UsageSearchContext.ANY, scope, false)));
  checkResult(new String[]{}, convert(cache.getFilesWithWord("a", UsageSearchContext.ANY, scope, false)));
  checkResult(new String[]{"2.java"}, convert(cache.getFilesWithWord("b", UsageSearchContext.ANY, scope, false)));
  checkResult(new String[]{"2.java", "3.java"}, convert(cache.getFilesWithWord("c", UsageSearchContext.ANY, scope, false)));
  checkResult(new String[]{"2.java", "3.java"}, convert(cache.getFilesWithWord("d", UsageSearchContext.ANY, scope, false)));
  checkResult(new String[]{"3.java"}, convert(cache.getFilesWithWord("e", UsageSearchContext.ANY, scope, false)));

  checkResult(new String[]{"3.java"}, convert(todocache.getFilesWithTodoItems()));
  assertEquals(0, todocache.getTodoCount(myRootDir.findChild("1.java"), TodoIndexPatternProvider.getInstance()));
  assertEquals(0, todocache.getTodoCount(myRootDir.findChild("2.java"), TodoIndexPatternProvider.getInstance()));
  assertEquals(2, todocache.getTodoCount(myRootDir.findChild("3.java"), TodoIndexPatternProvider.getInstance()));
}
项目:intellij-ce-playground    文件:AppEngineSupportProvider.java   
@Nullable
public static VirtualFile createFileFromTemplate(final String templateName, final VirtualFile parent, final String fileName) {
  parent.refresh(false, false);
  final FileTemplate template = FileTemplateManager.getDefaultInstance().getJ2eeTemplate(templateName);
  try {
    final String text = template.getText(FileTemplateManager.getDefaultInstance().getDefaultProperties());
    VirtualFile file = parent.findChild(fileName);
    if (file == null) {
      file = parent.createChildData(AppEngineSupportProvider.class, fileName);
    }
    VfsUtil.saveText(file, text);
    return file;
  }
  catch (IOException e) {
    LOG.error(e);
    return null;
  }
}
项目:intellij-ce-playground    文件:AntDomLoadFileTask.java   
protected String calcPropertyValue(String propertyName) {
  String text = myCachedText;
  if (text != null) {
    return text; 
  }
  final PsiFileSystemItem file = getSrcFile().getValue();
  if (!(file instanceof PsiFile)) {
    return "";
  }
  final VirtualFile vFile = ((PsiFile)file).getOriginalFile().getVirtualFile();
  if (vFile == null) {
    return "";
  }
  try {
    text = VfsUtil.loadText(vFile);
    myCachedText = text;
  }
  catch (IOException e) {
    LOG.info(e);
    text = "";
  }
  return text;
}
项目:intellij-ce-playground    文件:BookmarkManagerTest.java   
public void testBookmarkManagerDoesNotHardReferenceDocuments() throws IOException {
  @NonNls String text =
    "public class Test {\n" +
    "}";

  myVFile = getSourceRoot().createChildData(null, getTestName(false) + ".txt");
  VfsUtil.saveText(myVFile, text);
  PsiDocumentManager.getInstance(getProject()).commitAllDocuments();

  Bookmark bookmark = getManager().addTextBookmark(myVFile, 1, "xxx");
  assertNotNull(bookmark);
  LeakHunter.checkLeak(getManager(), Document.class);

  Document document = FileDocumentManager.getInstance().getDocument(myVFile);
  assertNotNull(document);

  document.insertString(0, "line 0\n");
  assertEquals(2, bookmark.getLine());

  myEditor = createEditor(myVFile);
  checkBookmarkNavigation(bookmark);
}
项目:intellij-ce-playground    文件:StudyUtils.java   
@Nullable
public static Document getPatternDocument(@NotNull final TaskFile taskFile, String name) {
  Task task = taskFile.getTask();
  String lessonDir = EduNames.LESSON + String.valueOf(task.getLesson().getIndex());
  String taskDir = EduNames.TASK + String.valueOf(task.getIndex());
  Course course = task.getLesson().getCourse();
  File resourceFile = new File(course.getCourseDirectory());
  if (!resourceFile.exists()) {
    return  null;
  }
  String patternPath = FileUtil.join(resourceFile.getPath(), lessonDir, taskDir, name);
  VirtualFile patternFile = VfsUtil.findFileByIoFile(new File(patternPath), true);
  if (patternFile == null) {
    return null;
  }
  return FileDocumentManager.getInstance().getDocument(patternFile);
}
项目:intellij-ce-playground    文件:DomVirtualFileEventsTest.java   
public void testDeleteFile() throws Throwable {
  new WriteCommandAction.Simple(getProject()) {
    @Override
    protected void run() throws Throwable {
      final VirtualFile dir = getVirtualFile(createTempDirectory());
      PsiTestUtil.addSourceContentToRoots(getModule(), dir);
      final VirtualFile childData = dir.createChildData(this, "abc.xml");
      assertResultsAndClear();
      VfsUtil.saveText(childData, "<a/>");
      final DomFileElementImpl<DomElement> fileElement = getFileElement(childData);
      assertResultsAndClear();

      childData.delete(this);
      assertEventCount(1);
      putExpected(new DomEvent(fileElement, false));
      assertResultsAndClear();
      assertFalse(fileElement.isValid());
    }
  }.execute().throwException();
}
项目:intellij-ce-playground    文件:MavenFrameworkSupportProvider.java   
private static void prepareProjectStructure(@NotNull ModifiableRootModel model, @NotNull VirtualFile root) {
  VirtualFile src = root.findChild("src");
  if (src == null || !src.isDirectory()) return;

  if (ArrayUtil.contains(src, model.getSourceRoots())) {
    try {
      VirtualFile java = VfsUtil.createDirectories(src.getPath() + "/main/java");
      if (java != null && java.isDirectory()) {
        for (VirtualFile child : src.getChildren()) {
          if (!child.getName().equals("main")) {
            child.move(null, java);
          }
        }
      }
    }
    catch (IOException e) {
      MavenLog.LOG.info(e);
    }
  }
}
项目:intellij-ce-playground    文件:GantLibraryPresentationProvider.java   
@Override
protected void fillLibrary(String path, LibraryEditor libraryEditor) {
  File srcRoot = new File(path + "/src/main");
  if (srcRoot.exists()) {
    libraryEditor.addRoot(VfsUtil.getUrlForLibraryRoot(srcRoot), OrderRootType.SOURCES);
  }

  // Add Gant jars
  File lib = new File(path + "/lib");
  File[] jars = lib.exists() ? lib.listFiles() : new File[0];
  if (jars != null) {
    for (File file : jars) {
      if (file.getName().endsWith(".jar")) {
        libraryEditor.addRoot(VfsUtil.getUrlForLibraryRoot(file), OrderRootType.CLASSES);
      }
    }
  }
}