Java Code Examples for com.intellij.openapi.module.ModuleManager#getInstance()
The following examples show how to use
com.intellij.openapi.module.ModuleManager#getInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Platform.java From reasonml-idea-plugin with MIT License | 6 votes |
@NotNull private static Map<Module, VirtualFile> findContentRootsFor(@NotNull Project project, @NotNull String filename) { Map<Module, VirtualFile> rootContents = new HashMap<>(); ModuleManager moduleManager = ModuleManager.getInstance(project); for (Module module : moduleManager.getModules()) { for (VirtualFile contentRoot : ModuleRootManager.getInstance(module).getContentRoots()) { VirtualFile packageJson = contentRoot.findChild(filename); if (packageJson != null && !rootContents.containsKey(module)) { rootContents.put(module, packageJson); } } } return rootContents; }
Example 2
Source File: TomcatSettingsEditor.java From SmartTomcat with Apache License 2.0 | 6 votes |
@Override public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) { ModuleManager moduleManager = ModuleManager.getInstance(project); Module[] modules = moduleManager.getModules(); for (Module module : modules) { VirtualFile[] excludeRoots = ModuleRootManager.getInstance(module).getExcludeRoots(); for (VirtualFile excludeFile : excludeRoots) { if (excludeFile.getCanonicalPath().equals(file.getCanonicalPath())) { return false; } } } return super.isFileVisible(file, showHiddenFiles); }
Example 3
Source File: VcsStructureChooser.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull private Map<VirtualFile, String> calculateModules(@Nonnull List<VirtualFile> roots) { Map<VirtualFile, String> result = ContainerUtil.newHashMap(); final ModuleManager moduleManager = ModuleManager.getInstance(myProject); // assertion for read access inside Module[] modules = ApplicationManager.getApplication().runReadAction(new Computable<Module[]>() { public Module[] compute() { return moduleManager.getModules(); } }); TreeSet<VirtualFile> checkSet = new TreeSet<>(FilePathComparator.getInstance()); checkSet.addAll(roots); for (Module module : modules) { VirtualFile[] files = ModuleRootManager.getInstance(module).getContentRoots(); for (VirtualFile file : files) { VirtualFile floor = checkSet.floor(file); if (floor != null) { result.put(file, module.getName()); } } } return result; }
Example 4
Source File: FileReferenceNode.java From protobuf-jetbrains-plugin with Apache License 2.0 | 6 votes |
/** * Returns target proto PSI file root node. */ @Nullable public ProtoPsiFileRoot getTarget() { String filename = getFilename(); if (filename == null) { return null; } Module module = ModuleUtilCore.findModuleForPsiElement(this); if (module != null) { return getTarget(filename, module); } // fallback: if we are inside of a dependency, current module is null // in this case we try to resolve reference in all dependencies of all modules // (might be not fully correct, but better than nothing) ModuleManager moduleManager = ModuleManager.getInstance(getProject()); Module[] modules = moduleManager.getModules(); for (Module m : modules) { ProtoPsiFileRoot target = getTarget(filename, m); if (target != null) { return target; } } return null; }
Example 5
Source File: BlazeSampleDataDirectoryProviderTest.java From intellij with Apache License 2.0 | 6 votes |
@Before public void setup() { setProjectView( "directories:", " com/google/example", "targets:", " //com/google/example:main", "android_sdk_platform: android-25"); MockSdkUtil.registerSdk(workspace, "25"); workspaceDir = workspace.createDirectory(new WorkspacePath("com/google/example")); resDir = workspace.createFile(new WorkspacePath("com/google/example/res")); setTargetMap(android_binary("//com/google/example:main").res("res")); runFullBlazeSync(); ModuleManager moduleManager = ModuleManager.getInstance(getProject()); workspaceModule = moduleManager.findModuleByName(".workspace"); resModule = moduleManager.findModuleByName("com.google.example.main"); }
Example 6
Source File: FileTreeModelBuilder.java From consulo with Apache License 2.0 | 6 votes |
@Nullable private PackageDependenciesNode getModuleNode(Module module) { if (module == null || !myShowModules) { return myRoot; } ModuleNode node = myModuleNodes.get(module); if (node != null) return node; node = new ModuleNode(module); final ModuleManager moduleManager = ModuleManager.getInstance(myProject); final String[] groupPath = moduleManager.getModuleGroupPath(module); if (groupPath == null) { myModuleNodes.put(module, node); myRoot.add(node); return node; } myModuleNodes.put(module, node); if (myShowModuleGroups) { getParentModuleGroup(groupPath).add(node); } else { myRoot.add(node); } return node; }
Example 7
Source File: Unity3dProjectService.java From consulo-unity3d with Apache License 2.0 | 6 votes |
@Nullable @RequiredReadAction private static Module findRootModuleImpl(@Nonnull Project project) { VirtualFile baseDir = project.getBaseDir(); if(baseDir == null) { return null; } ModuleManager moduleManager = ModuleManager.getInstance(project); for(Module module : moduleManager.getModules()) { if(baseDir.equals(module.getModuleDir())) { return module; } } return null; }
Example 8
Source File: ModuleExtensionConditionImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean value(Project project) { ModuleManager moduleManager = ModuleManager.getInstance(project); for (Module module : moduleManager.getModules()) { ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); for (String extensionId : myExtensionIds) { ModuleExtension<?> extension = moduleRootManager.getExtension(extensionId); if(extension != null) { return true; } } } return false; }
Example 9
Source File: NewModuleAction.java From consulo with Apache License 2.0 | 5 votes |
@Override @RequiredUIAccess public void actionPerformed(@Nonnull AnActionEvent e) { final Project project = getEventProject(e); if (project == null) { return; } final VirtualFile virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE); final ModuleManager moduleManager = ModuleManager.getInstance(project); FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(false, true, false, false, false, false) { @Override @RequiredUIAccess public boolean isFileSelectable(VirtualFile file) { if (!super.isFileSelectable(file)) { return false; } for (Module module : moduleManager.getModules()) { VirtualFile moduleDir = module.getModuleDir(); if (moduleDir != null && moduleDir.equals(file)) { return false; } } return true; } }; fileChooserDescriptor.setTitle(ProjectBundle.message("choose.module.home")); AsyncResult<VirtualFile> chooseAsync = FileChooser.chooseFile(fileChooserDescriptor, project, virtualFile != null && virtualFile.isDirectory() ? virtualFile : null); chooseAsync.doWhenDone(moduleDir -> { NewProjectDialog dialog = new NewProjectDialog(project, moduleDir); dialog.showAsync().doWhenDone(() -> { NewProjectPanel panel = dialog.getProjectPanel(); NewOrImportModuleUtil.doCreate(panel, project, moduleDir); }); }); }
Example 10
Source File: MuleConfigUtils.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
public static List<Module> getMuleModules(Project project, boolean includeDomains) { final List<Module> muleModules = new ArrayList<>(); final ModuleManager moduleManager = ModuleManager.getInstance(project); Module[] allModules = moduleManager.getModules(); for (Module m : allModules) { if (MuleConfigUtils.isMuleModule(m) || (includeDomains && MuleConfigUtils.isMuleDomainModule(m))) muleModules.add(m); } return muleModules; }
Example 11
Source File: PlatformTestCase.java From consulo with Apache License 2.0 | 5 votes |
protected void simulateProjectOpen() { ModuleManagerImpl mm = (ModuleManagerImpl)ModuleManager.getInstance(myProject); StartupManagerImpl sm = (StartupManagerImpl)StartupManager.getInstance(myProject); mm.projectOpened(); sm.runStartupActivities(UIAccess.get()); // extra init for libraries sm.runPostStartupActivities(UIAccess.get()); }
Example 12
Source File: AndroidSyncTest.java From intellij with Apache License 2.0 | 5 votes |
@Test public void testSimpleSync_noRunConfigurationModules() { TestProjectArguments testEnvArgument = createTestProjectArguments(); // Set the disabling experiment to 100% to effectively switch it on. MockExperimentService experimentService = new MockExperimentService(); registerApplicationComponent(ExperimentService.class, experimentService); experimentService.setFeatureRolloutExperiment( BlazeAndroidProjectStructureSyncer.deprecateRunConfigModuleExperiment, 100); setProjectView( "directories:", " java/com/google", "targets:", " //java/com/google:lib", "android_sdk_platform: android-25"); setTargetMap(testEnvArgument.targetMap); runBlazeSync( BlazeSyncParams.builder() .setTitle("Sync") .setSyncMode(SyncMode.INCREMENTAL) .setSyncOrigin("test") .setBlazeBuildParams(BlazeBuildParams.fromProject(getProject())) .setAddProjectViewTargets(true) .build()); assertSyncSuccess(testEnvArgument.targetMap, testEnvArgument.javaRoot); ModuleManager moduleManager = ModuleManager.getInstance(getProject()); assertThat(moduleManager.findModuleByName(BlazeDataStorage.WORKSPACE_MODULE_NAME)).isNotNull(); assertThat(moduleManager.findModuleByName("java.com.google.lib")).isNotNull(); }
Example 13
Source File: Utils.java From idea-gitignore with MIT License | 5 votes |
/** * Searches for excluded roots in given {@link Project}. * * @param project current project * @return list of excluded roots */ public static List<VirtualFile> getExcludedRoots(@NotNull Project project) { List<VirtualFile> roots = new ArrayList<>(); ModuleManager manager = ModuleManager.getInstance(project); for (Module module : manager.getModules()) { ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel(); if (model.isDisposed()) { continue; } Collections.addAll(roots, model.getExcludeRoots()); model.dispose(); } return roots; }
Example 14
Source File: RunConfigurationModule.java From consulo with Apache License 2.0 | 4 votes |
private ModuleManager getModuleManager() { return ModuleManager.getInstance(myProject); }
Example 15
Source File: ProjectRootManagerImpl.java From consulo with Apache License 2.0 | 4 votes |
private ModuleManager getModuleManager() { return ModuleManager.getInstance(myProject); }
Example 16
Source File: ContactPopMenu.java From saros with GNU General Public License v2.0 | 4 votes |
/** * Creates the menu entries for the modules contained in the project. Returns the created entries * grouped by whether the described module is shareable or not. * * <p>Shareable module entries trigger the session negotiation when interacted with. Non-shareable * module entries are disabled and carry a tooltip explaining why the module can not be shared. * * @param project the project for whose modules to create menu entries * @return a <code>Pair</code> containing the entries for sharable modules (first element) and the * entries for non-shareable modules (second element) or <code>null</code> if the module * information for the project can not be read */ @Nullable private Pair<List<JMenuItem>, List<JMenuItem>> createModuleEntries(Project project) { ModuleManager moduleManager = ModuleManager.getInstance(project); if (moduleManager == null) { NotificationPanel.showError( MessageFormat.format( Messages.Contact_saros_message_conditional, Messages.ContactPopMenu_unsupported_ide_message_condition), Messages.ContactPopMenu_unsupported_ide_title); return null; } List<JMenuItem> shownModules = new ArrayList<>(); List<JMenuItem> nonCompliantModules = new ArrayList<>(); for (Module module : moduleManager.getModules()) { String moduleName = module.getName(); String fullModuleName = project.getName() + File.separator + moduleName; // TODO adjust once sharing multiple reference points is supported try { VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots(); if (contentRoots.length != 1) { throw new IllegalArgumentException("Unsupported number of content roots"); } VirtualFile contentRoot = contentRoots[0]; IReferencePoint wrappedModule = new IntellijReferencePoint(project, contentRoot); JMenuItem moduleItem = new JMenuItem(moduleName); moduleItem.setToolTipText(Messages.ContactPopMenu_menu_tooltip_share_module); moduleItem.addActionListener(new ShareDirectoryAction(project, moduleName, wrappedModule)); shownModules.add(moduleItem); } catch (IllegalArgumentException exception) { log.debug( "Ignoring module " + fullModuleName + " as it has multiple content roots and can't necessarily be completely shared."); JMenuItem invalidModuleEntry = new JMenuItem(moduleName); invalidModuleEntry.setEnabled(false); invalidModuleEntry.setToolTipText(Messages.ContactPopMenu_menu_tooltip_invalid_module); nonCompliantModules.add(invalidModuleEntry); } } return new Pair<>(shownModules, nonCompliantModules); }
Example 17
Source File: ProjectSettingsComponent.java From Plugin with MIT License | 4 votes |
private void syncGears(){ //Load settings SettingsManager.getInstance().loadSettings(); //Get all projects ProjectManager pm = ProjectManager.getInstance(); Project[] targetProjects = pm.getOpenProjects(); Project p = targetProjects[0]; //Load project settings SettingsManager.getInstance().loadProjectSettings(p); //Get all modules ModuleManager mm = ModuleManager.getInstance(p); Module[] targetModules = mm.getModules(); //Get main module String mainModule = SettingsManager.getInstance().getMainModule(); if (!mainModule.equals("")){ //Find the module object from module name for (int ii = 0; ii < targetModules.length; ii++){ //If module name matches target module, sync if (targetModules[ii].getName().equals(mainModule)){ //Sync gears if (SettingsManager.getInstance().getAutoSync()){ SyncGears syncWorker = new SyncGears(p, targetModules[ii]){ @Override protected void done() { super.done(); //Possibly show toast here... } }; syncWorker.execute(); } break; } } } }
Example 18
Source File: IdeaFrameFixture.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 4 votes |
@NotNull private ModuleManager getModuleManager() { return ModuleManager.getInstance(getProject()); }
Example 19
Source File: WeaveConfiguration.java From mule-intellij-plugins with Apache License 2.0 | 4 votes |
@Override public Collection<Module> getValidModules() { final ModuleManager moduleManager = ModuleManager.getInstance(this.project); return Arrays.asList(moduleManager.getModules()); }
Example 20
Source File: CodeGenerateServiceImpl.java From EasyCode with MIT License | 4 votes |
public CodeGenerateServiceImpl(Project project) { this.project = project; this.moduleManager = ModuleManager.getInstance(project); this.tableInfoService = TableInfoService.getInstance(project); this.cacheDataUtils = CacheDataUtils.getInstance(); }