コード例 #1
0
ファイル: MvcFramework.java プロジェクト: Zeratyl-SK/consulo
  @NotNull
  public GeneralCommandLine createCommand(
      @NotNull Module module,
      @Nullable String jvmParams,
      boolean forCreation,
      @NotNull MvcCommand command)
      throws ExecutionException {
    final JavaParameters params =
        createJavaParameters(module, forCreation, false, true, jvmParams, command);
    addJavaHome(params, module);

    final GeneralCommandLine commandLine = createCommandLine(params);

    final VirtualFile griffonHome = getSdkRoot(module);
    if (griffonHome != null) {
      commandLine
          .getEnvironment()
          .put(getSdkHomePropertyName(), FileUtil.toSystemDependentName(griffonHome.getPath()));
    }

    final VirtualFile root = findAppRoot(module);
    final File ioRoot =
        root != null ? VfsUtilCore.virtualToIoFile(root) : new File(module.getModuleDirPath());
    commandLine.setWorkDirectory(forCreation ? ioRoot.getParentFile() : ioRoot);

    return commandLine;
  }
コード例 #2
0
  /**
   * Collects all files which are located in the passed directory.
   *
   * @throws IllegalArgumentException if <code>dir</code> isn't a directory.
   */
  public static void collectFiles(
      final VirtualFile dir,
      final List<VirtualFile> files,
      final boolean recursive,
      final boolean addDirectories) {
    if (!dir.isDirectory()) {
      throw new IllegalArgumentException(
          VcsBundle.message("exception.text.file.should.be.directory", dir.getPresentableUrl()));
    }

    final FileTypeManager fileTypeManager = FileTypeManager.getInstance();
    VfsUtilCore.visitChildrenRecursively(
        dir,
        new VirtualFileVisitor() {
          @Override
          public boolean visitFile(@NotNull VirtualFile file) {
            if (file.isDirectory()) {
              if (addDirectories) {
                files.add(file);
              }
              if (!recursive && !Comparing.equal(file, dir)) {
                return false;
              }
            } else if (fileTypeManager == null || file.getFileType() != FileTypes.UNKNOWN) {
              files.add(file);
            }
            return true;
          }
        });
  }
コード例 #3
0
 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);
 }
コード例 #4
0
 @Nullable
 private static ContentEntry findContentEntry(ModuleRootModel rootModel, VirtualFile file) {
   return ContainerUtil.find(
       rootModel.getContentEntries(),
       object -> {
         VirtualFile entryRoot = object.getFile();
         return entryRoot != null && VfsUtilCore.isAncestor(entryRoot, file, false);
       });
 }
コード例 #5
0
  public void testRelativePath() throws Exception {
    final File root = new File(PathManagerEx.getTestDataPath());
    final File testRoot = new File(new File(root, "vfs"), "relativePath");
    VirtualFile vTestRoot = LocalFileSystem.getInstance().findFileByIoFile(testRoot);
    assertNotNull(vTestRoot);
    assertTrue(vTestRoot.isDirectory());

    final File subDir = new File(testRoot, "subDir");
    final VirtualFile vSubDir = LocalFileSystem.getInstance().findFileByIoFile(subDir);
    assertNotNull(vSubDir);

    final File subSubDir = new File(subDir, "subSubDir");
    final VirtualFile vSubSubDir = LocalFileSystem.getInstance().findFileByIoFile(subSubDir);
    assertNotNull(vSubSubDir);

    assertEquals("subDir", VfsUtilCore.getRelativePath(vSubDir, vTestRoot, '/'));
    assertEquals("subDir/subSubDir", VfsUtilCore.getRelativePath(vSubSubDir, vTestRoot, '/'));
    assertEquals("", VfsUtilCore.getRelativePath(vTestRoot, vTestRoot, '/'));
  }
コード例 #6
0
ファイル: PersistentFSImpl.java プロジェクト: ernestp/consulo
 @Override
 @NotNull
 public VirtualFile[] getRoots() {
   myRootsLock.readLock().lock();
   try {
     Collection<VirtualFileSystemEntry> roots = myRoots.values();
     return VfsUtilCore.toVirtualFileArray(roots);
   } finally {
     myRootsLock.readLock().unlock();
   }
 }
コード例 #7
0
 @Nullable
 public static ContentEntry findContentEntryForRoot(
     @NotNull ModifiableRootModel model, @NotNull VirtualFile root) {
   ContentEntry contentEntry = null;
   for (ContentEntry candidate : model.getContentEntries()) {
     VirtualFile contentRoot = candidate.getFile();
     if (contentRoot != null && VfsUtilCore.isAncestor(contentRoot, root, false)) {
       contentEntry = candidate;
     }
   }
   return contentEntry;
 }
コード例 #8
0
    private void addPackage(@NotNull final String packageName, @NotNull final String packagePath) {
      myLibRootUrls.add(VfsUtilCore.pathToUrl(packagePath));

      List<String> paths = myPackagesMap.get((packageName));
      if (paths == null) {
        paths = new SmartList<String>();
        myPackagesMap.put(packageName, paths);
      }

      if (!paths.contains(packagePath)) {
        paths.add(packagePath);
      }
    }
コード例 #9
0
 public void testIsAncestor() {
   assertTrue(VfsUtilCore.isEqualOrAncestor("file:///my/dir", "file:///my/dir"));
   assertTrue(VfsUtilCore.isEqualOrAncestor("file:///my/dir", "file:///my/dir/file.txt"));
   assertTrue(VfsUtilCore.isEqualOrAncestor("file:///my/dir/", "file:///my/dir/file.txt"));
   assertFalse(VfsUtilCore.isEqualOrAncestor("file:///my/dir2", "file:///my/dir/file.txt"));
   assertFalse(VfsUtilCore.isEqualOrAncestor("file:///my/dir", "file:///my/dir2"));
   assertFalse(VfsUtilCore.isEqualOrAncestor("file:///my/dir/", "file:///my/dir2"));
 }
  @Override
  public void after(@NotNull final List<? extends VFileEvent> events) {
    incModificationCount();

    for (FilePointerPartNode node : myPointersToUpdateUrl) {
      synchronized (this) {
        VirtualFilePointerImpl pointer = node.leaf;
        String urlBefore = pointer.getUrlNoUpdate();
        Pair<VirtualFile, String> after = node.update();
        String urlAfter = after.second;
        if (URL_COMPARATOR.compare(urlBefore, urlAfter) != 0) {
          // url has changed, reinsert
          FilePointerPartNode root = myPointers.get(pointer.getListener());
          int useCount = node.useCount;
          node.remove();
          FilePointerPartNode newNode =
              root.findPointerOrCreate(VfsUtilCore.urlToPath(urlAfter), 0, after);
          VirtualFilePointerImpl existingPointer = newNode.leaf;
          if (existingPointer != null) {
            // can happen when e.g. file renamed to the existing file
            // merge two pointers
            pointer.myNode = newNode;
          } else {
            newNode.associate(pointer, after);
          }
          newNode.incrementUsageCount(useCount);
        }
      }
    }

    VirtualFilePointer[] pointersToFireArray = toPointers(myPointersToFire);
    for (VirtualFilePointer pointer : pointersToFireArray) {
      ((VirtualFilePointerImpl) pointer).myNode.update();
    }

    for (EventDescriptor event : myEvents) {
      event.fireAfter();
    }

    if (pointersToFireArray.length != 0) {
      myBus.syncPublisher(VirtualFilePointerListener.TOPIC).validityChanged(pointersToFireArray);
    }

    myPointersToUpdateUrl = Collections.emptyList();
    myEvents = Collections.emptyList();
    myPointersToFire = Collections.emptyList();
    for (FilePointerPartNode root : myPointers.values()) {
      root.checkConsistency();
    }
  }
コード例 #11
0
 private VirtualFile refresh(File file) {
   VirtualFile vFile = myFileSystem.refreshAndFindFileByIoFile(file);
   assertNotNull(file.toString(), vFile);
   VfsUtilCore.visitChildrenRecursively(
       vFile,
       new VirtualFileVisitor() {
         @Override
         public boolean visitFile(@NotNull VirtualFile file) {
           file.getChildren();
           return true;
         }
       });
   return vFile;
 }
コード例 #12
0
 private static void addSourceDirectoriesFromLibraries(
     @NotNull Project project,
     @NotNull VirtualFile directory,
     @NotNull Collection<VirtualFile> outSourceRoots) {
   ProjectFileIndex index = ProjectFileIndex.SERVICE.getInstance(project);
   VirtualFile classRoot = index.getClassRootForFile(directory);
   if (classRoot == null) return;
   String relativePath = VfsUtilCore.getRelativePath(directory, classRoot);
   if (relativePath == null) return;
   for (OrderEntry orderEntry : index.getOrderEntriesForFile(directory)) {
     for (VirtualFile sourceRoot : orderEntry.getFiles(OrderRootType.SOURCES)) {
       VirtualFile sourceFile = sourceRoot.findFileByRelativePath(relativePath);
       if (sourceFile != null) {
         outSourceRoots.add(sourceFile);
       }
     }
   }
 }
コード例 #13
0
ファイル: PersistentFSImpl.java プロジェクト: ernestp/consulo
  @Override
  @NotNull
  public VirtualFile[] getLocalRoots() {
    List<VirtualFile> roots = ContainerUtil.newSmartList();

    myRootsLock.readLock().lock();
    try {
      for (NewVirtualFile root : myRoots.values()) {
        if (root.isInLocalFileSystem() && !(root.getFileSystem() instanceof TempFileSystem)) {
          roots.add(root);
        }
      }
    } finally {
      myRootsLock.readLock().unlock();
    }

    return VfsUtilCore.toVirtualFileArray(roots);
  }
コード例 #14
0
ファイル: PersistentFSImpl.java プロジェクト: ernestp/consulo
  @Override
  @NotNull
  public VirtualFile[] getRoots(@NotNull final NewVirtualFileSystem fs) {
    final List<VirtualFile> roots = new ArrayList<VirtualFile>();

    myRootsLock.readLock().lock();
    try {
      for (NewVirtualFile root : myRoots.values()) {
        if (root.getFileSystem() == fs) {
          roots.add(root);
        }
      }
    } finally {
      myRootsLock.readLock().unlock();
    }

    return VfsUtilCore.toVirtualFileArray(roots);
  }
コード例 #15
0
  private void countAndMarkUnresolved(
      @NotNull VirtualFile file, @NotNull final Set<VirtualFile> result, final boolean inDbOnly) {
    if (file.isDirectory()) {
      VfsUtilCore.visitChildrenRecursively(
          file,
          new VirtualFileVisitor() {
            @Override
            public boolean visitFile(@NotNull VirtualFile file) {
              return doCountAndMarkUnresolved(file, result);
            }

            @Nullable
            @Override
            public Iterable<VirtualFile> getChildrenIterable(@NotNull VirtualFile file) {
              return inDbOnly ? ((NewVirtualFile) file).iterInDbChildren() : null;
            }
          });
    } else {
      doCountAndMarkUnresolved(file, result);
    }
  }
コード例 #16
0
  public void testFindFileByUrl() throws Exception {
    File file1 = new File(PathManagerEx.getTestDataPath());
    file1 = new File(file1, "vfs");
    file1 = new File(file1, "findFileByUrl");
    VirtualFile file0 = VfsUtil.findFileByURL(file1.toURI().toURL());
    assertNotNull(file0);
    assertTrue(file0.isDirectory());
    final VirtualFile[] children = file0.getChildren();
    List<VirtualFile> list = new ArrayList<VirtualFile>();
    final VirtualFileFilter fileFilter =
        new VirtualFileFilter() {
          @Override
          public boolean accept(VirtualFile file) {
            return !file.getName().endsWith(".new");
          }
        };
    for (VirtualFile child : children) {
      if (fileFilter.accept(child)) {
        list.add(child);
      }
    }
    assertEquals(2, list.size()); // "CVS" dir ignored

    File file2 = new File(file1, "test.zip");
    URL url2 = file2.toURI().toURL();
    url2 = new URL("jar", "", url2.toExternalForm() + "!/");
    url2 = new URL(url2, "com/intellij/installer");
    url2 = new URL(url2.toExternalForm());
    file0 = VfsUtil.findFileByURL(url2);
    assertNotNull(file0);
    assertTrue(file0.isDirectory());

    File file3 = new File(file1, "1.txt");
    file0 = VfsUtil.findFileByURL(file3.toURI().toURL());
    String content = VfsUtilCore.loadText(file0);
    assertNotNull(file0);
    assertFalse(file0.isDirectory());
    assertEquals(content, "test text");
  }
コード例 #17
0
  public void testVisitRecursively() throws Exception {
    final DirectoryData data = new DirectoryData(myProject.getBaseDir());
    try {
      data.clear();
      data.create();

      final File subDir = new File(data.getBase().getPath(), "DL0N1");
      final VirtualFile vSubDir = LocalFileSystem.getInstance().findFileByIoFile(subDir);
      assertNotNull(vSubDir);

      VfsUtilCore.visitChildrenRecursively(
          data.getBase(),
          new VirtualFileVisitor() {
            @Override
            public boolean visitFile(@NotNull VirtualFile file) {
              assertTrue(!VfsUtilCore.isAncestor(vSubDir, file, true));
              return !vSubDir.equals(file);
            }
          });
    } finally {
      data.clear();
    }
  }
コード例 #18
0
 private static void makeAndAddLibraryJar(
     final VirtualFile virtualFile,
     final File zipFile,
     final String pluginName,
     final ZipOutputStream zos,
     final Set<String> usedJarNames,
     final ProgressIndicator progressIndicator,
     final String preferredName)
     throws IOException {
   File libraryJar = FileUtil.createTempFile(TEMP_PREFIX, JAR_EXTENSION);
   libraryJar.deleteOnExit();
   ZipOutputStream jar = null;
   try {
     jar = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(libraryJar)));
     ZipUtil.addFileOrDirRecursively(
         jar,
         libraryJar,
         VfsUtilCore.virtualToIoFile(virtualFile),
         "",
         createFilter(progressIndicator, FileTypeManager.getInstance()),
         null);
   } finally {
     if (jar != null) jar.close();
   }
   final String jarName =
       getLibraryJarName(
           virtualFile.getName() + JAR_EXTENSION,
           usedJarNames,
           preferredName == null ? null : preferredName + JAR_EXTENSION);
   ZipUtil.addFileOrDirRecursively(
       zos,
       zipFile,
       libraryJar,
       getZipPath(pluginName, jarName),
       createFilter(progressIndicator, null),
       null);
 }
コード例 #19
0
 public void addRoots(final Collection<String> dirPaths) {
   for (String path : dirPaths) {
     myLibRootUrls.add(VfsUtilCore.pathToUrl(path));
   }
 }