@TestOnly
  private static VirtualFile[] getAllRoots(@NotNull Project project) {
    insideGettingRoots = true;
    final Set<VirtualFile> roots = new THashSet<VirtualFile>();

    final OrderEnumerator enumerator = ProjectRootManager.getInstance(project).orderEntries();
    ContainerUtil.addAll(roots, enumerator.getClassesRoots());
    ContainerUtil.addAll(roots, enumerator.getSourceRoots());

    insideGettingRoots = false;
    return VfsUtilCore.toVirtualFileArray(roots);
  }
  @NotNull
  private Map<VirtualFile, OrderEntry[]> getOrderEntries() {
    Map<VirtualFile, OrderEntry[]> result = myOrderEntries;
    if (result != null) return result;

    MultiMap<VirtualFile, OrderEntry> libClassRootEntries = MultiMap.createSmart();
    MultiMap<VirtualFile, OrderEntry> libSourceRootEntries = MultiMap.createSmart();
    MultiMap<VirtualFile, OrderEntry> depEntries = MultiMap.createSmart();

    for (final Module module : ModuleManager.getInstance(myProject).getModules()) {
      final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
      for (OrderEntry orderEntry : moduleRootManager.getOrderEntries()) {
        if (orderEntry instanceof ModuleOrderEntry) {
          final Module depModule = ((ModuleOrderEntry) orderEntry).getModule();
          if (depModule != null) {
            VirtualFile[] importedClassRoots =
                OrderEnumerator.orderEntries(depModule)
                    .exportedOnly()
                    .recursively()
                    .classes()
                    .usingCache()
                    .getRoots();
            for (VirtualFile importedClassRoot : importedClassRoots) {
              depEntries.putValue(importedClassRoot, orderEntry);
            }
          }
          for (VirtualFile sourceRoot : orderEntry.getFiles(OrderRootType.SOURCES)) {
            depEntries.putValue(sourceRoot, orderEntry);
          }
        } else if (orderEntry instanceof LibraryOrSdkOrderEntry) {
          final LibraryOrSdkOrderEntry entry = (LibraryOrSdkOrderEntry) orderEntry;
          for (final VirtualFile sourceRoot : entry.getRootFiles(OrderRootType.SOURCES)) {
            libSourceRootEntries.putValue(sourceRoot, orderEntry);
          }
          for (final VirtualFile classRoot : entry.getRootFiles(OrderRootType.CLASSES)) {
            libClassRootEntries.putValue(classRoot, orderEntry);
          }
        }
      }
    }

    RootInfo rootInfo = buildRootInfo(myProject);
    result = ContainerUtil.newHashMap();
    Set<VirtualFile> allRoots = rootInfo.getAllRoots();
    for (VirtualFile file : allRoots) {
      List<VirtualFile> hierarchy = getHierarchy(file, allRoots, rootInfo);
      result.put(
          file,
          hierarchy == null
              ? OrderEntry.EMPTY_ARRAY
              : calcOrderEntries(
                  rootInfo, depEntries, libClassRootEntries, libSourceRootEntries, hierarchy));
    }
    myOrderEntries = result;
    return result;
  }
 @Nullable
 public static VirtualFile suggestManifestFileDirectory(
     @NotNull Project project, @Nullable Module module) {
   OrderEnumerator enumerator =
       module != null
           ? OrderEnumerator.orderEntries(module)
           : OrderEnumerator.orderEntries(project);
   final VirtualFile[] files =
       enumerator
           .withoutDepModules()
           .withoutLibraries()
           .withoutSdk()
           .productionOnly()
           .sources()
           .getRoots();
   if (files.length > 0) {
     return files[0];
   }
   return suggestBaseDir(project, null);
 }
  private void assertClasspath(String moduleName, Scope scope, Type type, String... expectedPaths)
      throws Exception {
    createOutputDirectories();

    PathsList actualPathsList;
    Module module = getModule(moduleName);

    if (scope == Scope.RUNTIME) {
      JavaParameters params = new JavaParameters();
      params.configureByModule(
          module,
          type == Type.TESTS ? JavaParameters.CLASSES_AND_TESTS : JavaParameters.CLASSES_ONLY);
      actualPathsList = params.getClassPath();
    } else {
      OrderEnumerator en =
          OrderEnumerator.orderEntries(module).recursively().withoutSdk().compileOnly();
      if (type == Type.PRODUCTION) en.productionOnly();
      actualPathsList = en.classes().getPathsList();
    }

    assertPaths(expectedPaths, actualPathsList.getPathList());
  }
Exemplo n.º 5
0
  public static List<SDependency> calculateLibraryDependencies(
      OrderEnumerator orderEnumerator, final Project project, final boolean includeStubs) {
    final Map<SModule, Boolean> modules = new HashMap<SModule, Boolean>();
    orderEnumerator.forEach(
        new Processor<OrderEntry>() {
          public boolean process(OrderEntry oe) {
            if (!(oe instanceof LibraryOrderEntry)) {
              return true;
            }
            LibraryOrderEntry loe = (LibraryOrderEntry) oe;
            Library library = loe.getLibrary();
            if (loe.isModuleLevel() || library == null) {
              return true;
            }

            if (ModuleLibraryType.isModuleLibrary(library)) {
              Set<SModuleReference> moduleReferences = ModuleLibrariesUtil.getModules(library);
              for (SModuleReference moduleReference : moduleReferences) {
                SModule m =
                    moduleReference.resolve(MPSModuleRepository.getInstance()); // FIXME module repo
                if (m == null) {
                  continue;
                }
                if (modules.containsKey(moduleReference)) {
                  if (loe.isExported()) {
                    modules.put(m, true);
                  }
                } else {
                  modules.put(m, loe.isExported());
                }
              }
            } else if (includeStubs) {
              // try to find stub solution
              SModule s =
                  MPSModuleRepository.getInstance().getModule(ModuleId.foreign(library.getName()));
              if (s != null) {
                modules.put(s, loe.isExported());
              }
            }
            return true;
          }
        });
    List<SDependency> result = new ArrayList<SDependency>();
    for (Entry<SModule, Boolean> entry : modules.entrySet()) {
      result.add(new SDependencyImpl(entry.getKey(), SDependencyScope.DEFAULT, entry.getValue()));
    }
    return result;
  }
 @Nullable
 protected static VirtualFile findGroovyJar(@NotNull Module module) {
   final VirtualFile[] files =
       OrderEnumerator.orderEntries(module).getAllLibrariesAndSdkClassesRoots();
   for (VirtualFile root : files) {
     if (root.getName().matches(GroovyConfigUtils.GROOVY_JAR_PATTERN)
         || GroovyConfigUtils.matchesGroovyAll(root.getName())) {
       return root;
     }
   }
   for (VirtualFile file : files) {
     if (file.getName().contains("groovy") && "jar".equals(file.getExtension())) {
       return file;
     }
   }
   return null;
 }
Exemplo n.º 7
0
  public PathsList getApplicationClassPath(Module module) {
    final List<VirtualFile> classPath =
        OrderEnumerator.orderEntries(module)
            .recursively()
            .withoutSdk()
            .getPathsList()
            .getVirtualFiles();

    retainOnlyJarsAndDirectories(classPath);

    removeModuleOutput(module, classPath);

    final Module pluginsModule = findCommonPluginsModule(module);
    if (pluginsModule != null) {
      removeModuleOutput(pluginsModule, classPath);
    }

    return removeFrameworkStuff(module, classPath);
  }