Search in sources :

Example 1 with ModuleRootModel

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

the class ProductionModuleOutputPackagingElement method getSourceRoots.

@NotNull
@Override
public Collection<VirtualFile> getSourceRoots(PackagingElementResolvingContext context) {
    Module module = findModule(context);
    if (module == null)
        return Collections.emptyList();
    ModuleRootModel rootModel = context.getModulesProvider().getRootModel(module);
    return rootModel.getSourceRoots(JavaModuleSourceRootTypes.PRODUCTION);
}
Also used : ModuleRootModel(com.intellij.openapi.roots.ModuleRootModel) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ModuleRootModel

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

the class EclipseEmlTest method checkModule.

protected static void checkModule(String path, Module module) throws WriteExternalException, IOException, JDOMException {
    ModuleRootModel rootModel = ModuleRootManager.getInstance(module);
    final Element root = new Element("component");
    IdeaSpecificSettings.writeIdeaSpecificClasspath(root, rootModel);
    assertThat(root).isEqualTo(Paths.get(path, module.getName() + EclipseXml.IDEA_SETTINGS_POSTFIX));
}
Also used : Element(org.jdom.Element) ModuleRootModel(com.intellij.openapi.roots.ModuleRootModel)

Example 3 with ModuleRootModel

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

the class ArtifactEditorContextImpl method selectLibrary.

@Override
public void selectLibrary(@NotNull Library library) {
    final LibraryTable table = library.getTable();
    if (table != null) {
        ProjectStructureConfigurable.getInstance(getProject()).selectProjectOrGlobalLibrary(library, true);
    } else {
        final Module module = ((LibraryImpl) library).getModule();
        if (module != null) {
            final ModuleRootModel rootModel = myParent.getModulesProvider().getRootModel(module);
            final String libraryName = library.getName();
            for (OrderEntry entry : rootModel.getOrderEntries()) {
                if (entry instanceof ModuleLibraryOrderEntryImpl) {
                    final ModuleLibraryOrderEntryImpl libraryEntry = (ModuleLibraryOrderEntryImpl) entry;
                    if (libraryName != null && libraryName.equals(libraryEntry.getLibraryName()) || libraryName == null && library.equals(libraryEntry.getLibrary())) {
                        ProjectStructureConfigurable.getInstance(getProject()).selectOrderEntry(module, libraryEntry);
                        return;
                    }
                }
            }
        }
    }
}
Also used : LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryImpl(com.intellij.openapi.roots.impl.libraries.LibraryImpl) ModuleRootModel(com.intellij.openapi.roots.ModuleRootModel) ModuleLibraryOrderEntryImpl(com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl) Module(com.intellij.openapi.module.Module)

Example 4 with ModuleRootModel

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

the class AppEngineFacetEditor method doAdd.

private void doAdd() {
    final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, false, false, false, true);
    final ModuleRootModel rootModel = myContext.getRootModel();
    descriptor.setRoots(rootModel.getSourceRoots(JavaModuleSourceRootTypes.SOURCES));
    final VirtualFile[] files = FileChooser.chooseFiles(descriptor, myContext.getProject(), null);
    for (VirtualFile file : files) {
        myFilesListModel.addElement(file.getPath());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ModuleRootModel(com.intellij.openapi.roots.ModuleRootModel)

Example 5 with ModuleRootModel

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

the class MavenProjectImporter method removeUnusedProjectLibraries.

private boolean removeUnusedProjectLibraries() {
    Set<Library> unusedLibraries = new HashSet<>();
    Collections.addAll(unusedLibraries, myModelsProvider.getAllLibraries());
    for (ModuleRootModel eachModel : collectModuleModels()) {
        for (OrderEntry eachEntry : eachModel.getOrderEntries()) {
            if (eachEntry instanceof LibraryOrderEntry) {
                unusedLibraries.remove(((LibraryOrderEntry) eachEntry).getLibrary());
            }
        }
    }
    boolean removed = false;
    for (Library each : unusedLibraries) {
        if (!isDisposed(each) && MavenRootModelAdapter.isMavenLibrary(each) && !MavenRootModelAdapter.isChangedByUser(each)) {
            myModelsProvider.removeLibrary(each);
            removed = true;
        }
    }
    return removed;
}
Also used : OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) ModuleRootModel(com.intellij.openapi.roots.ModuleRootModel) Library(com.intellij.openapi.roots.libraries.Library) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) THashSet(gnu.trove.THashSet)

Aggregations

ModuleRootModel (com.intellij.openapi.roots.ModuleRootModel)9 Module (com.intellij.openapi.module.Module)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 Element (org.jdom.Element)3 OrderEntry (com.intellij.openapi.roots.OrderEntry)2 File (java.io.File)2 NotNull (org.jetbrains.annotations.NotNull)2 EclipseClasspathWriter (org.jetbrains.idea.eclipse.conversion.EclipseClasspathWriter)2 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)1 Logger (com.intellij.openapi.diagnostic.Logger)1 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 ModuleManager (com.intellij.openapi.module.ModuleManager)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 DumbAware (com.intellij.openapi.project.DumbAware)1 Project (com.intellij.openapi.project.Project)1 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)1 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)1 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)1