Package com.intellij.openapi.roots

Examples of com.intellij.openapi.roots.ModifiableRootModel


    else {
      VfsRootAccess.disallowRootAccess(absolutePath);
    }
    AccessToken accessToken = ApplicationManager.getApplication().acquireWriteActionLock(null);
    try {
      ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
      String supportUrl = getUrl(testDataPath + "/../../support");
      String genUrl = getUrl(testDataPath + "/../../gen");
      if (add) {
        model.addContentEntry(supportUrl).addSourceFolder(supportUrl, false);
        model.addContentEntry(genUrl).addSourceFolder(genUrl, false);
      }
      else {
        for (ContentEntry entry : model.getContentEntries()) {
          if (supportUrl.equals(entry.getUrl()) || genUrl.equals(entry.getUrl())) {
            model.removeContentEntry(entry);
          }
        }
      }
      model.commit();
    }
    finally {
      accessToken.finish();
    }
    assertTrue("GrammarKit src problem", add == (null != facade.findPackage("org.intellij.grammar.psi")));
View Full Code Here


            @Override
            protected void run() throws Throwable {
                ModuleRootManager instance =
                    ModuleRootManager.getInstance(myModule);

                ModifiableRootModel modifiableModel = instance.getModifiableModel();

                ContentEntry[] entries = instance.getContentEntries();
                for (ContentEntry entry : entries) {
                    modifiableModel.removeContentEntry(entry);
                }
                modifiableModel.commit();
            }
        }.execute().throwException();
    }
View Full Code Here

    @Override
    public List<Module> commit(final Project project, ModifiableModuleModel model, ModulesProvider modulesProvider, ModifiableArtifactModel artifactModel) {
        //Create Module and iml-file
        final ModifiableModuleModel moduleModel = model != null ? model : ModuleManager.getInstance(project).getModifiableModel();
        Module myModule = moduleModel.newModule(project.getBasePath() + File.separator + project.getName() + ".iml", "GO_MODULE");
        final ModifiableRootModel mrm = ModuleRootManager.getInstance(myModule).getModifiableModel();
        mrm.inheritSdk();

        ApplicationManager.getApplication().runWriteAction(new Runnable() {
            @Override
            public void run() {
                //Add the default content entry
                VirtualFile baseDir = project.getBaseDir();
                ContentEntry entry = mrm.addContentEntry(baseDir);

                //Set src-folder as SourceFolder, if it exists
                VirtualFile srcFolder = baseDir.findFileByRelativePath("src");
                if(srcFolder != null) {
                    entry.addSourceFolder(srcFolder, false);
                }

                mrm.commit();
                moduleModel.commit();
            }
        });

View Full Code Here

    addLibraryToRoots(myModule, jarFile, rootType);
  }

  protected static void addLibraryToRoots(final Module module, final VirtualFile jarFile, final OrderRootType rootType) {
    final ModuleRootManager manager = ModuleRootManager.getInstance(module);
    final ModifiableRootModel rootModel = manager.getModifiableModel();
    final Library jarLibrary = rootModel.getModuleLibraryTable().createLibrary();
    final Library.ModifiableModel libraryModel = jarLibrary.getModifiableModel();
    libraryModel.addRoot(jarFile, rootType);
    libraryModel.commit();
    rootModel.commit();
  }
View Full Code Here

    Module[] modules = ModuleManager.getInstance(myProject).getModules();
    for (Module module : modules) {
      final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
      ApplicationManager.getApplication().runWriteAction(new Runnable() {
        public void run() {
          final ModifiableRootModel rootModel = rootManager.getModifiableModel();
          rootModel.setJdk(jdk);
          rootModel.commit();
        }
      });
    }
  }
View Full Code Here

  private File getTestContentFile() {
    return new File(myTempDirectory, getTestDirectoryName());
  }

  private void setupContentRoot() {
    ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(myModule).getModifiableModel();
    ContentEntry contentEntry = modifiableModel.addContentEntry(getContentRoot());
    VirtualFile src = getContentRoot().findChild("src");
    if (src != null) {
      contentEntry.addSourceFolder(src, false);
    }
    modifiableModel.commit();
  }
View Full Code Here

    if (sourceDir[0] == null) {
      sourceDir[0] = projectDir;
    }
    VirtualFile ext_src = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(testDir + "/ext_src"));
    final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule);
    final ModifiableRootModel rootModel = rootManager.getModifiableModel();
    rootModel.clear();
    // configure source and output path
    final ContentEntry contentEntry = rootModel.addContentEntry(projectDir);
    contentEntry.addSourceFolder(sourceDir[0], false);
    if (ext_src != null) {
      contentEntry.addSourceFolder(ext_src, false);
    }

    // IMPORTANT! The jdk must be obtained in a way it is obtained in the normal program!
    //ProjectJdkEx jdk = ProjectJdkTable.getInstance().getInternalJdk();
    ProjectJdk jdk;
    if ("java 1.5".equals(jdkName)) {
      jdk = JavaSdkImpl.getMockJdk15(jdkName);
      myPsiManager.setEffectiveLanguageLevel(LanguageLevel.JDK_1_5);
    }
    else {
      jdk = JavaSdkImpl.getMockJdk(jdkName);
    }

    rootModel.setJdk(jdk);

    rootModel.commit();
  }
View Full Code Here

    contentEntry.addSourceFolder(directory, ErlangIncludeSourceRootType.INSTANCE);
  }

  public static void markAsIncludeDirectory(@NotNull Module module, @NotNull VirtualFile directory) {
    ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
    ModifiableRootModel rootModel = rootManager.getModifiableModel();
    for (ContentEntry contentEntry : rootModel.getContentEntries()) {
      VirtualFile contentRootDirectory = contentEntry.getFile();
      if (contentRootDirectory != null && VfsUtilCore.isAncestor(contentRootDirectory, directory, false)) {
        markAsIncludeDirectory(contentEntry, directory);
        rootModel.commit();
        return;
      }
    }
    rootModel.dispose();
  }
View Full Code Here

    setSettings();
    setupLibraries();
  }

  private void setupLibraries() {
    ModifiableRootModel rootModel = null;
    final ModuleRootManager rootManager = ModuleRootManager.getInstance(myFixture.getModule());

    // Add Clojure Library
    OrderEnumerator libs = rootManager.orderEntries().librariesOnly();
    final List<Library.ModifiableModel> libModels = new ArrayList<Library.ModifiableModel>();

    rootModel = TestUtils.addLibrary(rootModel, rootManager, libs, libModels, "clojureLib", TestUtils.getMockClojureLib(), null);
    rootModel = TestUtils.addLibrary(rootModel, rootManager, libs, libModels, "clojureContrib", TestUtils.getMockClojureContribLib(), null);

    if (rootModel != null || !libModels.isEmpty()) {
      final ModifiableRootModel finalRootModel = rootModel;
      ApplicationManager.getApplication().runWriteAction(new Runnable() {
        public void run() {
          for (Library.ModifiableModel model : libModels) {
            model.commit();
          }
          if (finalRootModel != null) {
            finalRootModel.commit();
          }
          final StartupManagerImpl startupManager = (StartupManagerImpl) StartupManager.getInstance(myProject);
          startupManager.startCacheUpdate();
        }
      });
View Full Code Here

  }

  protected void setUp() throws Exception {
    super.setUp();

    ModifiableRootModel rootModel = null;
    final ModuleRootManager rootManager = ModuleRootManager.getInstance(getModule());

    if (isConfigureSourceFolder()) {
      rootModel = ModuleRootManager.getInstance(getModule()).getModifiableModel();
      final String testDir = getTestFolderPath();

      // Configure source folder
      final File dir = new File(testDir);
      assertTrue(dir.exists());

      VirtualFile vDir = LocalFileSystem.getInstance().
          refreshAndFindFileByPath(dir.getCanonicalPath().replace(File.separatorChar, '/'));
      assertNotNull(vDir);
      ContentEntry contentEntry = rootModel.addContentEntry(vDir);
      contentEntry.addSourceFolder(vDir, false);
    }

    // Add Clojure Library
    OrderEnumerator libs = rootManager.orderEntries().librariesOnly();
    final List<Library.ModifiableModel> libModels = new ArrayList<Library.ModifiableModel>();

    rootModel = TestUtils.addLibrary(rootModel, rootManager, libs, libModels, "clojureLib", TestUtils.getMockClojureLib(), null);
    rootModel = TestUtils.addLibrary(rootModel, rootManager, libs, libModels, "clojureContrib", TestUtils.getMockClojureContribLib(), null);

    if (rootModel != null || !libModels.isEmpty()) {
      final ModifiableRootModel finalRootModel = rootModel;
      ApplicationManager.getApplication().runWriteAction(new Runnable() {
        public void run() {
          for (Library.ModifiableModel model : libModels) {
            model.commit();
          }
          if (finalRootModel != null) {
            finalRootModel.commit();
          }
          final StartupManagerImpl startupManager = (StartupManagerImpl) StartupManager.getInstance(ourProject);
          startupManager.startCacheUpdate();
        }
      });
View Full Code Here

TOP

Related Classes of com.intellij.openapi.roots.ModifiableRootModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.