private static String url2path(String url) {
    String path = VfsUtilCore.urlToPath(url);

    int separatorIndex = path.indexOf(JarFileSystem.JAR_SEPARATOR);
    if (separatorIndex < 0) return path;
    return path.substring(0, separatorIndex);
  }
 @NotNull
 private static Collection<VirtualFile> gatherIncludeRoots(
     Collection<VirtualFile> goPathSourcesRoots, Set<VirtualFile> excludeRoots) {
   Collection<VirtualFile> includeRoots = ContainerUtil.newHashSet();
   for (VirtualFile goPathSourcesDirectory : goPathSourcesRoots) {
     ProgressIndicatorProvider.checkCanceled();
     boolean excludedRootIsAncestor = false;
     for (VirtualFile excludeRoot : excludeRoots) {
       ProgressIndicatorProvider.checkCanceled();
       if (VfsUtilCore.isAncestor(excludeRoot, goPathSourcesDirectory, false)) {
         excludedRootIsAncestor = true;
         break;
       }
     }
     if (excludedRootIsAncestor) {
       continue;
     }
     for (VirtualFile file : goPathSourcesDirectory.getChildren()) {
       ProgressIndicatorProvider.checkCanceled();
       if (file.isDirectory() && !excludeRoots.contains(file)) {
         includeRoots.add(file);
       }
     }
   }
   return includeRoots;
 }
Exemple #3
0
  @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;
  }
 @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);
       });
 }
 @NotNull
 private static VirtualFile[] filterByReadOnliness(@NotNull VirtualFile[] files) {
   List<VirtualFile> result = new ArrayList<VirtualFile>();
   for (VirtualFile file : files) {
     if (file.isInLocalFileSystem()) {
       result.add(file);
     }
   }
   return VfsUtilCore.toVirtualFileArray(result);
 }
  private void annotateExternally(
      @NotNull final VirtualFile file,
      @NotNull final PsiModifierListOwner listOwner,
      @NotNull Project project,
      @NotNull final String packageName,
      final VirtualFile virtualFile,
      @NotNull final String annotationFQName,
      @NotNull final PsiFile fromFile,
      final PsiNameValuePair[] value) {
    final XmlFile[] annotationsXml = new XmlFile[1];
    List<XmlFile> xmlFiles = findExternalAnnotationsXmlFiles(listOwner);
    if (xmlFiles != null) {
      for (XmlFile xmlFile : xmlFiles) {
        final VirtualFile vXmlFile = xmlFile.getVirtualFile();
        assert vXmlFile != null;
        if (VfsUtilCore.isAncestor(file, vXmlFile, false)) {
          annotationsXml[0] = xmlFile;
          if (!CodeInsightUtilBase.preparePsiElementForWrite(xmlFile)) return;
        }
      }
    } else {
      xmlFiles = new ArrayList<XmlFile>();
    }

    final List<PsiFile> annotationFiles = new ArrayList<PsiFile>(xmlFiles);
    new WriteCommandAction(project) {
      @Override
      protected void run(final Result result) throws Throwable {
        if (annotationsXml[0] == null) {
          annotationsXml[0] = createAnnotationsXml(file, packageName);
        }
        if (annotationsXml[0] != null) {
          annotationFiles.add(annotationsXml[0]);
          myExternalAnnotations.put(getFQN(packageName, virtualFile), annotationFiles);
          annotateExternally(listOwner, annotationFQName, annotationsXml[0], fromFile, value);
        }
      }
    }.execute();

    UndoManager.getInstance(project)
        .undoableActionPerformed(
            new BasicUndoableAction() {
              @Override
              public void undo() throws UnexpectedUndoException {
                dropCache();
              }

              @Override
              public void redo() throws UnexpectedUndoException {
                dropCache();
              }
            });
  }
 @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;
 }
    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);
      }
    }
 @Nullable
 private static XmlFile findXmlFileInRoot(
     @Nullable List<XmlFile> xmlFiles, @NotNull VirtualFile root) {
   if (xmlFiles != null) {
     for (XmlFile xmlFile : xmlFiles) {
       VirtualFile vf = xmlFile.getVirtualFile();
       if (vf != null) {
         if (VfsUtilCore.isAncestor(root, vf, false)) {
           return xmlFile;
         }
       }
     }
   }
   return null;
 }
 public static void addLibrary(
     final Module module,
     final ModifiableRootModel model,
     final String libName,
     final String libPath,
     final String... jarArr) {
   List<VirtualFile> classesRoots = new ArrayList<VirtualFile>();
   for (String jar : jarArr) {
     if (!libPath.endsWith("/") && !jar.startsWith("/")) {
       jar = "/" + jar;
     }
     final String path = libPath + jar;
     VirtualFile root;
     if (path.endsWith(".jar")) {
       root = JarFileSystem.getInstance().refreshAndFindFileByPath(path + "!/");
     } else {
       root = LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
     }
     assert root != null : "Library root folder not found: " + path + "!/";
     classesRoots.add(root);
   }
   addProjectLibrary(module, model, libName, VfsUtilCore.toVirtualFileArray(classesRoots));
 }
 public void addRoots(final Collection<String> dirPaths) {
   for (String path : dirPaths) {
     myLibRootUrls.add(VfsUtilCore.pathToUrl(path));
   }
 }