Java 类com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess 实例源码

项目:intellij-ce-playground    文件:ExternalSystemTestCase.java   
public void registerAllowedRoots(List<String> roots, @NotNull Disposable disposable) {
  final List<String> newRoots = new ArrayList<String>(roots);
  newRoots.removeAll(myAllowedRoots);

  final String[] newRootsArray = ArrayUtil.toStringArray(newRoots);
  VfsRootAccess.allowRootAccess(newRootsArray);
  myAllowedRoots.addAll(newRoots);

  Disposer.register(disposable, new Disposable() {
    @Override
    public void dispose() {
      VfsRootAccess.disallowRootAccess(newRootsArray);
      myAllowedRoots.removeAll(newRoots);
    }
  });
}
项目:intellij-ce-playground    文件:AndroidTestCase.java   
public void registerAllowedRoots(List<String> roots, @NotNull Disposable disposable) {
  final List<String> newRoots = new ArrayList<String>(roots);
  newRoots.removeAll(myAllowedRoots);

  final String[] newRootsArray = ArrayUtil.toStringArray(newRoots);
  VfsRootAccess.allowRootAccess(newRootsArray);
  myAllowedRoots.addAll(newRoots);

  Disposer.register(disposable, new Disposable() {
    @Override
    public void dispose() {
      VfsRootAccess.disallowRootAccess(newRootsArray);
      myAllowedRoots.removeAll(newRoots);
    }
  });
}
项目:google-cloud-intellij    文件:AppEngineCodeInsightTestCase.java   
@Override
protected void setUp() throws Exception {
  super.setUp();
  // Fixes https://youtrack.jetbrains.com/issue/IDEA-129297. Only occurs in Jenkins.
  VfsRootAccess.allowRootAccess(System.getProperty("user.dir"));
  final TestFixtureBuilder<IdeaProjectTestFixture> fixtureBuilder =
      JavaTestFixtureFactory.createFixtureBuilder(getName());
  myModuleBuilder = fixtureBuilder.addModule(JavaModuleFixtureBuilder.class);
  myProjectFixture = fixtureBuilder.getFixture();
  myCodeInsightFixture = createCodeInsightFixture(getBaseDirectoryPath());
  new WriteAction() {
    @Override
    protected void run(@NotNull final Result result) {
      addAppEngineSupport(myProjectFixture.getModule());
    }
  }.execute();
}
项目:intellij-ce-playground    文件:CodeInsightTestCase.java   
private void allowRootAccess(final String filePath) {
  VfsRootAccess.allowRootAccess(filePath);
  Disposer.register(myTestRootDisposable, new Disposable() {
    @Override
    public void dispose() {
      VfsRootAccess.disallowRootAccess(filePath);
    }
  });
}
项目:intellij-ce-playground    文件:LocalFileSystemTest.java   
public void testWindowsHiddenDirectory() throws Exception {
  if (!SystemInfo.isWindows) {
    System.err.println(getName() + " skipped: " + SystemInfo.OS_NAME);
    return;
  }

  File file = new File("C:\\Documents and Settings\\desktop.ini");
  if (!file.exists()) {
    System.err.println(getName() + " skipped: missing " + file);
    return;
  }

  String parent = FileUtil.toSystemIndependentName(file.getParent());
  VfsRootAccess.allowRootAccess(parent);
  try {
    VirtualFile virtualFile = myFS.refreshAndFindFileByIoFile(file);
    assertNotNull(virtualFile);

    NewVirtualFileSystem fs = (NewVirtualFileSystem)virtualFile.getFileSystem();
    FileAttributes attributes = fs.getAttributes(virtualFile);
    assertNotNull(attributes);
    assertEquals(FileAttributes.Type.FILE, attributes.type);
    assertEquals(FileAttributes.HIDDEN, attributes.flags);
  }
  finally {
    VfsRootAccess.disallowRootAccess(parent);
  }
}
项目:intellij-ce-playground    文件:AndroidTestBase.java   
protected AndroidTestBase() {
  IdeaTestCase.initPlatformPrefix();

  // IDEA14 seems to be stricter regarding validating accesses against known roots. By default, it contains the entire idea folder,
  // but it doesn't seem to include our custom structure tools/idea/../adt/idea where the android plugin is placed.
  // The following line explicitly adds that folder as an allowed root.
  VfsRootAccess.allowRootAccess(FileUtil.toCanonicalPath(getAndroidPluginHome()));
}
项目:intellij-ce-playground    文件:AndroidProjectDataServiceTest.java   
public void testImportData() {
  String jdkPath = Jdks.getJdkHomePath(LanguageLevel.JDK_1_6);

  if (jdkPath != null) {
    VfsRootAccess.allowRootAccess(jdkPath);
  }
  List<DataNode<IdeaAndroidProject>> nodes = Lists.newArrayList();
  Key<IdeaAndroidProject> key = AndroidProjectKeys.IDE_ANDROID_PROJECT;
  nodes.add(new DataNode<IdeaAndroidProject>(key, myIdeaAndroidProject, null));

  assertEquals(key, service.getTargetDataKey());

  final IdeModifiableModelsProviderImpl modelsProvider = new IdeModifiableModelsProviderImpl(myProject);
  // ModuleCustomizers should be called.
  //noinspection ConstantConditions
  myCustomizer1.customizeModule(eq(myProject), eq(myModule), eq(modelsProvider), eq(myIdeaAndroidProject));
  expectLastCall();

  //noinspection ConstantConditions
  myCustomizer2.customizeModule(eq(myProject), eq(myModule), eq(modelsProvider), eq(myIdeaAndroidProject));
  expectLastCall();

  replay(myCustomizer1, myCustomizer2);

  service.importData(nodes, null, myProject, modelsProvider);
  modelsProvider.commit();

  verify(myCustomizer1, myCustomizer2);
}
项目:intellij-ce-playground    文件:MavenImportingTestCase.java   
@Override
protected void setUp() throws Exception {
  VfsRootAccess.allowRootAccess(PathManager.getConfigPath());
  super.setUp();
  myGlobalSettingsFile =
    MavenWorkspaceSettingsComponent.getInstance(myProject).getSettings().generalSettings.getEffectiveGlobalSettingsIoFile();
  if (myGlobalSettingsFile != null) {
    VfsRootAccess.allowRootAccess(myGlobalSettingsFile.getAbsolutePath());
  }
}
项目:intellij-ce-playground    文件:MavenImportingTestCase.java   
@Override
protected void tearDown() throws Exception {
  try {
    if (myGlobalSettingsFile != null) {
      VfsRootAccess.disallowRootAccess(myGlobalSettingsFile.getAbsolutePath());
    }
    VfsRootAccess.disallowRootAccess(PathManager.getConfigPath());
    Messages.setTestDialog(TestDialog.DEFAULT);
    removeFromLocalRepository("test");
    FileUtil.delete(BuildManager.getInstance().getBuildSystemDirectory());
  }
  finally {
    super.tearDown();
  }
}
项目:intellij    文件:BlazeTestSystemPropertiesRule.java   
/** Sets up the necessary system properties for running IntelliJ tests via blaze/bazel. */
private static void configureSystemProperties() throws IOException {
  File sandbox = new File(getTmpDirFile(), "_intellij_test_sandbox");

  setSandboxPath("idea.home.path", new File(sandbox, "home"));
  setSandboxPath("idea.config.path", new File(sandbox, "config"));
  setSandboxPath("idea.system.path", new File(sandbox, "system"));
  setIfEmpty(PlatformUtils.PLATFORM_PREFIX_KEY, "Idea");
  setIfEmpty("idea.classpath.index.enabled", "false");

  // Some plugins have a since-build and until-build restriction, so we need
  // to update the build number here
  PluginManagerCore.BUILD_NUMBER = readApiVersionNumber();

  // Tests fail if they access files outside of the project roots and other system directories.
  // Ensure runfiles and platform api are whitelisted.
  VfsRootAccess.allowRootAccess(RUNFILES_PATH);
  String platformApi = getPlatformApiPath();
  if (platformApi != null) {
    VfsRootAccess.allowRootAccess(platformApi);
  }

  List<String> pluginJars = Lists.newArrayList();
  try {
    Enumeration<URL> urls =
        BlazeTestSystemPropertiesRule.class.getClassLoader().getResources("META-INF/plugin.xml");
    while (urls.hasMoreElements()) {
      URL url = urls.nextElement();
      addArchiveFile(url, pluginJars);
    }
  } catch (IOException e) {
    System.err.println("Cannot find plugin.xml resources");
    e.printStackTrace();
  }

  setIfEmpty("idea.plugins.path", Joiner.on(File.pathSeparator).join(pluginJars));
}
项目:google-cloud-intellij    文件:DefaultAppEngineProjectServiceTest.java   
@Override
protected void setUp() throws Exception {
  super.setUp();
  // Fixes https://youtrack.jetbrains.com/issue/IDEA-129297. Only occurs in Jenkins.
  VfsRootAccess.allowRootAccess(System.getProperty("user.dir"));
  appEngineProjectService = new DefaultAppEngineProjectService();
}
项目:intellij-pants-plugin    文件:PantsIntegrationTestCase.java   
@Override
public void setUp() throws Exception {
  cleanProjectIdeaDir();
  super.setUp();
  VfsRootAccess.allowRootAccess("/");
  for (String pluginId : getRequiredPluginIds()) {
    final IdeaPluginDescriptor plugin = PluginManager.getPlugin(PluginId.getId(pluginId));
    assertNotNull(pluginId + " plugin should be in classpath for integration tests!", plugin);
    assertTrue(pluginId + " is not enabled!", plugin.isEnabled());
  }

  myProjectSettings = new PantsProjectSettings();
  myCompilerTester = null;
}
项目:lombok-intellij-plugin    文件:AbstractLombokLightCodeInsightTestCase.java   
@Override
public void setUp() throws Exception {
  VfsRootAccess.allowRootAccess(new File(getTestDataPath(), getBasePath()).getCanonicalPath(),
    new File(LOMBOK_SRC_PATH).getCanonicalPath(), new File(HRISEY_SRC_PATH).getCanonicalPath());

  super.setUp();
  loadFilesFrom(LOMBOK_SRC_PATH);
  loadFilesFrom(HRISEY_SRC_PATH);
}
项目:lombok-intellij-plugin    文件:LombokInspectionTest.java   
@Override
public void setUp() throws Exception {
  super.setUp();
  final String lombokLibPath = PathUtil.toSystemIndependentName(new File(TEST_DATA_INSPECTION_DIRECTORY, "lib").getAbsolutePath());
  VfsRootAccess.allowRootAccess(lombokLibPath);

  TestUtil.addLibrary(myFixture, getModule(), "Lombok", lombokLibPath, "lombok.jar");
}
项目:consulo    文件:LocalFileSystemTest.java   
public void testWindowsHiddenDirectory() throws Exception {
  if (!SystemInfo.isWindows) {
    System.err.println(getName() + " skipped: " + SystemInfo.OS_NAME);
    return;
  }

  File file = new File("C:\\Documents and Settings\\desktop.ini");
  if (!file.exists()) {
    System.err.println(getName() + " skipped: missing " + file);
    return;
  }

  String parent = FileUtil.toSystemIndependentName(file.getParent());
  VfsRootAccess.allowRootAccess(parent);
  try {
    VirtualFile virtualFile = myFS.refreshAndFindFileByIoFile(file);
    assertNotNull(virtualFile);

    NewVirtualFileSystem fs = (NewVirtualFileSystem)virtualFile.getFileSystem();
    FileAttributes attributes = fs.getAttributes(virtualFile);
    assertNotNull(attributes);
    assertEquals(FileAttributes.Type.FILE, attributes.type);
    assertEquals(FileAttributes.HIDDEN, attributes.flags);
  }
  finally {
    VfsRootAccess.disallowRootAccess(parent);
  }
}
项目:jgiven-intellij-plugin    文件:LibraryTestUtil.java   
private void addLibraryAt(String path) {
    VfsRootAccess.allowRootAccess(path.split("/")[0]);
    PsiTestUtil.addLibrary(myModule, path);
}
项目:intellij-ce-playground    文件:CodeInsightTestFixtureImpl.java   
@NotNull
@Override
public VirtualFile copyFileToProject(@NotNull @NonNls final String sourceFilePath, @NotNull @NonNls final String targetPath) {
  final String testDataPath = getTestDataPath();

  File fromFile = new File(testDataPath + "/" + sourceFilePath);
  if (!fromFile.exists()) {
    fromFile = new File(sourceFilePath);
  }

  VirtualFile result;
  final String path = fromFile.getAbsolutePath();
  if (myTempDirFixture instanceof LightTempDirTestFixtureImpl) {
    VfsRootAccess.allowRootAccess(path);
    Disposer.register(getTestRootDisposable(), new Disposable() {
      @Override
      public void dispose() {
        VfsRootAccess.disallowRootAccess(path);
      }
    });
    VirtualFile fromVFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(fromFile);
    if (fromVFile == null) {
      fromVFile = myTempDirFixture.getFile(sourceFilePath);
    }
    Assert.assertNotNull("can't find test data file " + sourceFilePath + " (" + testDataPath + ")", fromVFile);
    result = myTempDirFixture.copyFile(fromVFile, targetPath);
  }
  else {

    final File targetFile = new File(getTempDirPath() + "/" + targetPath);
    if (!targetFile.exists()) {
      if (fromFile.isDirectory()) {
        Assert.assertTrue(targetFile.toString(), targetFile.mkdirs());
      }
      else {
        if (!fromFile.exists()) {
          Assert.fail("Cannot find source file: '" + sourceFilePath + "'. getTestDataPath()='" + testDataPath + "'. ");
        }
        try {
          FileUtil.copy(fromFile, targetFile);
        }
        catch (IOException e) {
          throw new RuntimeException("Cannot copy " + fromFile + " to " + targetFile, e);
        }
      }
    }

    final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(targetFile);
    Assert.assertNotNull(targetFile.toString(), file);
    result = file;
  }
  result.putUserData(VfsTestUtil.TEST_DATA_FILE_PATH, path);
  return result;
}
项目:intellij-ce-playground    文件:FileWatcherTest.java   
public void testSubst() throws Exception {
  if (!SystemInfo.isWindows) {
    System.err.println("Ignored: Windows required");
    return;
  }

  File targetDir = createTestDir(myTempDirectory, "top");
  File subDir = createTestDir(targetDir, "sub");
  File file = createTestFile(subDir, "test.txt");
  File rootFile = createSubst(targetDir.getPath());
  VfsRootAccess.allowRootAccess(rootFile.getPath());
  VirtualFile vfsRoot = myFileSystem.findFileByIoFile(rootFile);

  try {
    assertNotNull(rootFile.getPath(), vfsRoot);
    File substDir = new File(rootFile, subDir.getName());
    File substFile = new File(substDir, file.getName());
    refresh(targetDir);
    refresh(substDir);

    LocalFileSystem.WatchRequest request = watch(substDir);
    try {
      myAccept = true;
      FileUtil.writeToFile(file, "new content");
      assertEvent(VFileContentChangeEvent.class, substFile.getPath());

      LocalFileSystem.WatchRequest request2 = watch(targetDir);
      try {
        myAccept = true;
        FileUtil.delete(file);
        assertEvent(VFileDeleteEvent.class, file.getPath(), substFile.getPath());
      }
      finally {
        unwatch(request2);
      }

      myAccept = true;
      FileUtil.writeToFile(file, "re-creation");
      assertEvent(VFileCreateEvent.class, substFile.getPath());
    }
    finally {
      unwatch(request);
    }
  }
  finally {
    delete(targetDir);
    deleteSubst(rootFile.getPath());
    if (vfsRoot != null) {
      ((NewVirtualFile)vfsRoot).markDirty();
      myFileSystem.refresh(false);
    }
    VfsRootAccess.disallowRootAccess(rootFile.getPath());
  }
}
项目:intellij-pants-plugin    文件:OSSPantsPythonIntegrationTest.java   
@Override
public void setUp() throws Exception {
  super.setUp();
  // todo: Remove if possible. Now the test fails with VfsRootAccess to python interpreter in /opt
  VfsRootAccess.allowRootAccess("/");
}
项目:lombok-intellij-plugin    文件:InspectionTest.java   
@Override
protected void setUp() throws Exception {
  VfsRootAccess.allowRootAccess(new File(getTestDataPath(), "lib").getCanonicalPath());
  super.setUp();
}
项目:consulo    文件:FileWatcherTest.java   
public void testSubst() throws Exception {
  if (!SystemInfo.isWindows) {
    System.err.println("Ignored: Windows required");
    return;
  }

  File targetDir = createTestDir("top");
  File subDir = createTestDir(targetDir, "sub");
  File file = createTestFile(subDir, "test.txt");
  File rootFile = createSubst(targetDir.getPath());
  VfsRootAccess.allowRootAccess(rootFile.getPath());
  VirtualFile vfsRoot = myFileSystem.findFileByIoFile(rootFile);

  try {
    assertNotNull(rootFile.getPath(), vfsRoot);
    File substDir = new File(rootFile, subDir.getName());
    File substFile = new File(substDir, file.getName());
    refresh(targetDir);
    refresh(substDir);
    myAcceptedDirectories.add(substDir.getPath());

    LocalFileSystem.WatchRequest request = watch(substDir);
    try {
      myAccept = true;
      FileUtil.writeToFile(file, "new content");
      assertEvent(VFileContentChangeEvent.class, substFile.getPath());

      LocalFileSystem.WatchRequest request2 = watch(targetDir);
      try {
        myAccept = true;
        FileUtil.delete(file);
        assertEvent(VFileDeleteEvent.class, file.getPath(), substFile.getPath());
      }
      finally {
        unwatch(request2);
      }

      myAccept = true;
      FileUtil.writeToFile(file, "re-creation");
      assertEvent(VFileCreateEvent.class, substFile.getPath());
    }
    finally {
      unwatch(request);
    }
  }
  finally {
    delete(targetDir);
    deleteSubst(rootFile.getPath());
    if (vfsRoot != null) {
      ((NewVirtualFile)vfsRoot).markDirty();
      myFileSystem.refresh(false);
    }
    VfsRootAccess.disallowRootAccess(rootFile.getPath());
  }
}