Search in sources :

Example 76 with ModifiableRootModel

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

the class OrderEntryTest method removeLibs.

private void removeLibs() {
    ApplicationManager.getApplication().runWriteAction(() -> {
        try {
            for (Module module : ModuleManager.getInstance(getProject()).getModules()) {
                ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
                ModifiableRootModel model = rootManager.getModifiableModel();
                for (OrderEntry orderEntry : model.getOrderEntries()) {
                    model.removeOrderEntry(orderEntry);
                }
                model.commit();
            }
        } catch (Throwable e) {
            // when running test from within IDEA it would fail because junit.jar cache is locked by host IDEA instance
            e.printStackTrace();
        }
    });
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) OrderEntry(com.intellij.openapi.roots.OrderEntry) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Module(com.intellij.openapi.module.Module)

Example 77 with ModifiableRootModel

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

the class LibraryTest method testResolveDependencyToAddedLibrary.

public void testResolveDependencyToAddedLibrary() {
    final ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
    model.addInvalidLibrary("jdom", LibraryTablesRegistrar.PROJECT_LEVEL);
    commit(model);
    assertEmpty(getLibraries());
    Library library = createLibrary("jdom", getJDomJar(), null);
    assertSameElements(getLibraries(), library);
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Library(com.intellij.openapi.roots.libraries.Library)

Example 78 with ModifiableRootModel

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

the class LibraryTest method testResolveDependencyToRenamedLibrary.

public void testResolveDependencyToRenamedLibrary() {
    Library library = createLibrary("jdom2", getJDomJar(), null);
    final ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
    model.addInvalidLibrary("jdom", LibraryTablesRegistrar.PROJECT_LEVEL);
    commit(model);
    assertEmpty(getLibraries());
    Library.ModifiableModel libModel = library.getModifiableModel();
    libModel.setName("jdom");
    commit(libModel);
    assertSameElements(getLibraries(), library);
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Library(com.intellij.openapi.roots.libraries.Library)

Example 79 with ModifiableRootModel

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

the class ContentRootDataService method importData.

private static void importData(@NotNull IdeModifiableModelsProvider modelsProvider, @NotNull final Collection<DataNode<ContentRootData>> data, @NotNull final Module module, boolean forceDirectoriesCreation) {
    final ModifiableRootModel modifiableRootModel = modelsProvider.getModifiableRootModel(module);
    final ContentEntry[] contentEntries = modifiableRootModel.getContentEntries();
    final Map<String, ContentEntry> contentEntriesMap = ContainerUtilRt.newHashMap();
    for (ContentEntry contentEntry : contentEntries) {
        contentEntriesMap.put(contentEntry.getUrl(), contentEntry);
    }
    boolean createEmptyContentRootDirectories = forceDirectoriesCreation;
    if (!forceDirectoriesCreation && !data.isEmpty()) {
        ProjectSystemId projectSystemId = data.iterator().next().getData().getOwner();
        AbstractExternalSystemSettings externalSystemSettings = ExternalSystemApiUtil.getSettings(module.getProject(), projectSystemId);
        String path = module.getOptionValue(ExternalSystemConstants.ROOT_PROJECT_PATH_KEY);
        if (path != null) {
            ExternalProjectSettings projectSettings = externalSystemSettings.getLinkedProjectSettings(path);
            createEmptyContentRootDirectories = projectSettings != null && projectSettings.isCreateEmptyContentRootDirectories();
        }
    }
    final Set<ContentEntry> importedContentEntries = ContainerUtil.newIdentityTroveSet();
    for (final DataNode<ContentRootData> node : data) {
        final ContentRootData contentRoot = node.getData();
        final ContentEntry contentEntry = findOrCreateContentRoot(modifiableRootModel, contentRoot.getRootPath());
        if (!importedContentEntries.contains(contentEntry)) {
            // clear source folders but do not remove existing excluded folders
            contentEntry.clearSourceFolders();
            importedContentEntries.add(contentEntry);
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug(String.format("Importing content root '%s' for module '%s'", contentRoot.getRootPath(), module.getName()));
        }
        for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.SOURCE)) {
            createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.SOURCE, false, createEmptyContentRootDirectories);
        }
        for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.TEST)) {
            createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.TEST_SOURCE, false, createEmptyContentRootDirectories);
        }
        for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.SOURCE_GENERATED)) {
            createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.SOURCE, true, createEmptyContentRootDirectories);
        }
        for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.TEST_GENERATED)) {
            createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.TEST_SOURCE, true, createEmptyContentRootDirectories);
        }
        for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.RESOURCE)) {
            createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaResourceRootType.RESOURCE, false, createEmptyContentRootDirectories);
        }
        for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.TEST_RESOURCE)) {
            createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaResourceRootType.TEST_RESOURCE, false, createEmptyContentRootDirectories);
        }
        for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.EXCLUDED)) {
            createExcludedRootIfAbsent(contentEntry, path, module.getName(), module.getProject());
        }
        contentEntriesMap.remove(contentEntry.getUrl());
    }
    for (ContentEntry contentEntry : contentEntriesMap.values()) {
        modifiableRootModel.removeContentEntry(contentEntry);
    }
}
Also used : ContentRootData(com.intellij.openapi.externalSystem.model.project.ContentRootData) SourceRoot(com.intellij.openapi.externalSystem.model.project.ContentRootData.SourceRoot) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) ContentEntry(com.intellij.openapi.roots.ContentEntry)

Example 80 with ModifiableRootModel

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

the class ArtifactsStructureConfigurable method init.

public void init(StructureConfigurableContext context, ModuleStructureConfigurable moduleStructureConfigurable, ProjectLibrariesConfigurable projectLibrariesConfig, GlobalLibrariesConfigurable globalLibrariesConfig) {
    super.init(context);
    myPackagingEditorContext = new ArtifactsStructureConfigurableContextImpl(myContext, myProject, myDefaultSettings, new ArtifactAdapter() {

        @Override
        public void artifactAdded(@NotNull Artifact artifact) {
            final MyNode node = addArtifactNode(artifact);
            selectNodeInTree(node);
            myContext.getDaemonAnalyzer().queueUpdate(myPackagingEditorContext.getOrCreateArtifactElement(artifact));
        }
    });
    context.getModulesConfigurator().addAllModuleChangeListener(new ModuleEditor.ChangeListener() {

        @Override
        public void moduleStateChanged(ModifiableRootModel moduleRootModel) {
            for (ProjectStructureElement element : getProjectStructureElements()) {
                myContext.getDaemonAnalyzer().queueUpdate(element);
            }
        }
    });
    final ItemsChangeListener listener = new ItemsChangeListener() {

        @Override
        public void itemChanged(@Nullable Object deletedItem) {
            if (deletedItem instanceof Library || deletedItem instanceof Module) {
                onElementDeleted();
            }
        }

        @Override
        public void itemsExternallyChanged() {
        }
    };
    moduleStructureConfigurable.addItemsChangeListener(listener);
    projectLibrariesConfig.addItemsChangeListener(listener);
    globalLibrariesConfig.addItemsChangeListener(listener);
    context.addLibraryEditorListener(new LibraryEditorListener() {

        @Override
        public void libraryRenamed(@NotNull Library library, String oldName, String newName) {
            final Artifact[] artifacts = myPackagingEditorContext.getArtifactModel().getArtifacts();
            for (Artifact artifact : artifacts) {
                updateLibraryElements(artifact, library, oldName, newName);
            }
        }
    });
}
Also used : LibraryEditorListener(com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditorListener) ProjectStructureElement(com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement) NotNull(org.jetbrains.annotations.NotNull) ModuleEditor(com.intellij.openapi.roots.ui.configuration.ModuleEditor) InvalidArtifact(com.intellij.packaging.impl.artifacts.InvalidArtifact) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)102 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