コード例 #1
0
 public static void removeExcludedRoot(Module module, VirtualFile root) {
   ModuleRootModificationUtil.updateModel(
       module,
       model -> {
         ContentEntry entry = findContentEntryWithAssertion(model, root);
         entry.removeExcludeFolder(root.getUrl());
       });
 }
コード例 #2
0
 public static void removeAllRoots(Module module, Sdk jdk) {
   ModuleRootModificationUtil.updateModel(
       module,
       model -> {
         model.clear();
         model.setSdk(jdk);
       });
 }
コード例 #3
0
 public static void addExcludedRoot(Module module, VirtualFile dir) {
   ModuleRootModificationUtil.updateModel(
       module,
       model ->
           ApplicationManager.getApplication()
               .runReadAction(
                   () -> {
                     findContentEntryWithAssertion(model, dir).addExcludeFolder(dir);
                   }));
 }
コード例 #4
0
 public static <P extends JpsElement> void addSourceRoot(
     Module module, VirtualFile vDir, @NotNull JpsModuleSourceRootType<P> rootType, P properties) {
   ModuleRootModificationUtil.updateModel(
       module,
       model -> {
         ContentEntry entry = findContentEntry(model, vDir);
         if (entry == null) entry = model.addContentEntry(vDir);
         entry.addSourceFolder(vDir, rootType, properties);
       });
 }
コード例 #5
0
 public static Library addProjectLibrary(
     Module module,
     String libName,
     List<VirtualFile> classesRoots,
     List<VirtualFile> sourceRoots) {
   Ref<Library> result = Ref.create();
   ModuleRootModificationUtil.updateModel(
       module,
       model -> result.set(addProjectLibrary(module, model, libName, classesRoots, sourceRoots)));
   return result.get();
 }
コード例 #6
0
  public static ContentEntry addContentRoot(Module module, VirtualFile vDir) {
    ModuleRootModificationUtil.updateModel(module, model -> model.addContentEntry(vDir));

    for (ContentEntry entry : ModuleRootManager.getInstance(module).getContentEntries()) {
      if (Comparing.equal(entry.getFile(), vDir)) {
        Assert.assertFalse(((ContentEntryImpl) entry).isDisposed());
        return entry;
      }
    }

    return null;
  }
コード例 #7
0
 public static void removeSourceRoot(Module module, VirtualFile root) {
   ModuleRootModificationUtil.updateModel(
       module,
       model -> {
         ContentEntry entry = findContentEntryWithAssertion(model, root);
         for (SourceFolder sourceFolder : entry.getSourceFolders()) {
           if (root.equals(sourceFolder.getFile())) {
             entry.removeSourceFolder(sourceFolder);
             break;
           }
         }
       });
 }
コード例 #8
0
 public static void setCompilerOutputPath(Module module, String url, boolean forTests) {
   ModuleRootModificationUtil.updateModel(
       module,
       model -> {
         CompilerModuleExtension extension =
             model.getModuleExtension(CompilerModuleExtension.class);
         extension.inheritCompilerOutputPath(false);
         if (forTests) {
           extension.setCompilerOutputPathForTests(url);
         } else {
           extension.setCompilerOutputPath(url);
         }
       });
 }
コード例 #9
0
 public static void addLibrary(
     Module module, String libName, String libDir, String[] classRoots, String[] sourceRoots) {
   String proto =
       (classRoots.length > 0 ? classRoots[0] : sourceRoots[0]).endsWith(".jar!/")
           ? JarFileSystem.PROTOCOL
           : LocalFileSystem.PROTOCOL;
   String parentUrl = VirtualFileManager.constructUrl(proto, libDir);
   List<String> classesUrls = new ArrayList<>();
   List<String> sourceUrls = new ArrayList<>();
   for (String classRoot : classRoots) {
     classesUrls.add(parentUrl + classRoot);
   }
   for (String sourceRoot : sourceRoots) {
     sourceUrls.add(parentUrl + sourceRoot);
   }
   ModuleRootModificationUtil.addModuleLibrary(module, libName, classesUrls, sourceUrls);
 }
コード例 #10
0
 public static void setJavadocUrls(Module module, String... urls) {
   ModuleRootModificationUtil.updateModel(
       module,
       model -> model.getModuleExtension(JavaModuleExternalPaths.class).setJavadocUrls(urls));
 }
コード例 #11
0
 public static void setExcludeCompileOutput(Module module, boolean exclude) {
   ModuleRootModificationUtil.updateModel(
       module,
       model -> model.getModuleExtension(CompilerModuleExtension.class).setExcludeOutput(exclude));
 }
コード例 #12
0
 public static void addLibrary(Module module, String libName, String libPath, String... jarArr) {
   ModuleRootModificationUtil.updateModel(
       module, model -> addLibrary(module, model, libName, libPath, jarArr));
 }
コード例 #13
0
 public static void removeContentEntry(Module module, VirtualFile contentRoot) {
   ModuleRootModificationUtil.updateModel(
       module,
       model -> model.removeContentEntry(findContentEntryWithAssertion(model, contentRoot)));
 }
コード例 #14
0
 public static void addSourceContentToRoots(
     Module module, @NotNull VirtualFile vDir, boolean testSource) {
   ModuleRootModificationUtil.updateModel(
       module, model -> model.addContentEntry(vDir).addSourceFolder(vDir, testSource));
 }