Search in sources :

Example 21 with ModifiableRootModel

use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-community by JetBrains.

the class IntegrationTestCase method addExcludedDir.

protected void addExcludedDir(final String path) {
    ApplicationManager.getApplication().runWriteAction(() -> {
        ModuleRootManager rm = ModuleRootManager.getInstance(myModule);
        ModifiableRootModel m = rm.getModifiableModel();
        for (ContentEntry e : m.getContentEntries()) {
            if (!Comparing.equal(e.getFile(), myRoot))
                continue;
            e.addExcludeFolder(VfsUtilCore.pathToUrl(FileUtil.toSystemIndependentName(path)));
        }
        m.commit();
    });
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ContentEntry(com.intellij.openapi.roots.ContentEntry) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager)

Example 22 with ModifiableRootModel

use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-community by JetBrains.

the class EclipseEmlTest method doLoadModule.

private static Module doLoadModule(@NotNull String path, @NotNull Project project) throws IOException, JDOMException, InvalidDataException {
    Module module = WriteAction.compute(() -> ModuleManager.getInstance(project).newModule(path + '/' + EclipseProjectFinder.findProjectName(path) + ModuleManagerImpl.IML_EXTENSION, StdModuleTypes.JAVA.getId()));
    replaceRoot(path, EclipseXml.DOT_CLASSPATH_EXT, project);
    ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
    new EclipseClasspathConverter(module).readClasspath(rootModel);
    WriteAction.run(() -> rootModel.commit());
    return module;
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) EclipseClasspathConverter(org.jetbrains.idea.eclipse.config.EclipseClasspathConverter) Module(com.intellij.openapi.module.Module)

Example 23 with ModifiableRootModel

use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-community by JetBrains.

the class EclipseImlTest method doTest.

protected static void doTest(final String relativePath, final Project project) throws Exception {
    final String path = project.getBaseDir().getPath() + relativePath;
    final File classpathFile = new File(path, EclipseXml.DOT_CLASSPATH_EXT);
    String fileText = FileUtil.loadFile(classpathFile).replaceAll("\\$ROOT\\$", project.getBaseDir().getPath());
    if (!SystemInfo.isWindows) {
        fileText = fileText.replaceAll(EclipseXml.FILE_PROTOCOL + "/", EclipseXml.FILE_PROTOCOL);
    }
    String communityLib = FileUtil.toSystemIndependentName(PathManagerEx.findFileUnderCommunityHome("lib").getAbsolutePath());
    fileText = fileText.replaceAll("\\$" + JUNIT + "\\$", communityLib);
    final Element classpathElement = JdomKt.loadElement(fileText);
    final Module module = WriteCommandAction.runWriteCommandAction(null, (Computable<Module>) () -> ModuleManager.getInstance(project).newModule(new File(path) + File.separator + EclipseProjectFinder.findProjectName(path) + ModuleManagerImpl.IML_EXTENSION, StdModuleTypes.JAVA.getId()));
    final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
    EclipseClasspathReader classpathReader = new EclipseClasspathReader(path, project, null);
    classpathReader.init(rootModel);
    classpathReader.readClasspath(rootModel, classpathElement);
    ApplicationManager.getApplication().runWriteAction(rootModel::commit);
    final Element actualImlElement = new Element("root");
    ((ModuleRootManagerImpl) ModuleRootManager.getInstance(module)).getState().writeExternal(actualImlElement);
    PathMacros.getInstance().setMacro(JUNIT, communityLib);
    PathMacroManager.getInstance(module).collapsePaths(actualImlElement);
    PathMacroManager.getInstance(project).collapsePaths(actualImlElement);
    PathMacros.getInstance().removeMacro(JUNIT);
    assertThat(actualImlElement).isEqualTo(Paths.get(project.getBaseDir().getPath(), "expected", "expected.iml"));
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Element(org.jdom.Element) EclipseClasspathReader(org.jetbrains.idea.eclipse.conversion.EclipseClasspathReader) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 24 with ModifiableRootModel

use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-community by JetBrains.

the class CloudGitChooseAccountStepImpl method updateDataModel.

@Override
public void updateDataModel() {
    super.updateDataModel();
    final MultiMap<CloudGitProjectRoot, DetectedSourceRoot> project2sourceRoots = new MultiMap<>();
    new RootIterator() {

        CloudGitProjectRoot lastProjectRoot = null;

        @Override
        protected void processProjectRoot(CloudGitProjectRoot root) {
            lastProjectRoot = root;
            project2sourceRoots.put(lastProjectRoot, new ArrayList<>());
        }

        @Override
        protected void processJavaSourceRoot(DetectedSourceRoot root) {
            project2sourceRoots.putValue(lastProjectRoot, root);
        }
    }.iterate();
    List<ModuleDescriptor> modules = new ArrayList<>(myProjectDescriptor.getModules());
    for (Map.Entry<CloudGitProjectRoot, Collection<DetectedSourceRoot>> project2sourceRootsEntry : project2sourceRoots.entrySet()) {
        final CloudGitProjectRoot projectRoot = project2sourceRootsEntry.getKey();
        final File directory = projectRoot.getDirectory();
        ModuleDescriptor moduleDescriptor = new ModuleDescriptor(directory, StdModuleTypes.JAVA, project2sourceRootsEntry.getValue());
        final String applicationName = projectRoot.getApplicationName();
        moduleDescriptor.addConfigurationUpdater(new ModuleBuilder.ModuleConfigurationUpdater() {

            @Override
            public void update(@NotNull final Module module, @NotNull ModifiableRootModel rootModel) {
                final MessageBusConnection connection = module.getProject().getMessageBus().connect();
                connection.subscribe(ProjectTopics.MODULES, new ModuleListener() {

                    @Override
                    public void moduleAdded(@NotNull Project project, @NotNull Module addedModule) {
                        if (addedModule == module) {
                            StartupManager.getInstance(project).runWhenProjectIsInitialized(() -> onModuleAdded(module));
                            connection.disconnect();
                        }
                    }
                });
            }

            private void onModuleAdded(Module module) {
                createRunConfiguration(module, applicationName);
                GitInit.refreshAndConfigureVcsMappings(module.getProject(), projectRoot.getRepositoryRoot(), directory.getAbsolutePath());
            }
        });
        modules.add(moduleDescriptor);
    }
    myProjectDescriptor.setModules(modules);
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ModuleListener(com.intellij.openapi.project.ModuleListener) ModuleBuilder(com.intellij.ide.util.projectWizard.ModuleBuilder) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull) DetectedSourceRoot(com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) MultiMap(com.intellij.util.containers.MultiMap) ModuleDescriptor(com.intellij.ide.util.importProject.ModuleDescriptor) Project(com.intellij.openapi.project.Project) Collection(java.util.Collection) Module(com.intellij.openapi.module.Module) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap) File(java.io.File)

Example 25 with ModifiableRootModel

use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.

the class ContentRootsModuleSetupStep method doSetUpModule.

@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull AndroidModuleModel androidModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
    ModifiableRootModel moduleModel = ideModelsProvider.getModifiableRootModel(module);
    boolean hasNativeModel = hasNativeModel(module, ideModelsProvider, gradleModels);
    AndroidContentEntriesSetup setup = myContentEntriesSetupFactory.create(androidModel, moduleModel, hasNativeModel);
    List<ContentEntry> contentEntries = findContentEntries(moduleModel, androidModel, hasNativeModel);
    setup.execute(contentEntries);
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ContentEntry(com.intellij.openapi.roots.ContentEntry)

Aggregations

ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)101 Module (com.intellij.openapi.module.Module)44 VirtualFile (com.intellij.openapi.vfs.VirtualFile)29 ContentEntry (com.intellij.openapi.roots.ContentEntry)27 File (java.io.File)18 Library (com.intellij.openapi.roots.libraries.Library)15 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)14 ModuleManager (com.intellij.openapi.module.ModuleManager)8 Sdk (com.intellij.openapi.projectRoots.Sdk)8 IOException (java.io.IOException)8 NotNull (org.jetbrains.annotations.NotNull)8 OrderEntry (com.intellij.openapi.roots.OrderEntry)7 Project (com.intellij.openapi.project.Project)6 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)6 Nullable (org.jetbrains.annotations.Nullable)6 ModifiableModuleModel (com.intellij.openapi.module.ModifiableModuleModel)5 ConfigurationException (com.intellij.openapi.options.ConfigurationException)5 THashMap (gnu.trove.THashMap)5 FlexProjectConfigurationEditor (com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor)4 AccessToken (com.intellij.openapi.application.AccessToken)4