@NotNull public static Collection<String> collectPythonPath( @Nullable Module module, boolean addContentRoots, boolean addSourceRoots) { Collection<String> pythonPathList = Sets.newLinkedHashSet(); if (module != null) { Set<Module> dependencies = new HashSet<Module>(); ModuleUtilCore.getDependencies(module, dependencies); if (addContentRoots) { addRoots(pythonPathList, ModuleRootManager.getInstance(module).getContentRoots()); for (Module dependency : dependencies) { addRoots(pythonPathList, ModuleRootManager.getInstance(dependency).getContentRoots()); } } if (addSourceRoots) { addRoots(pythonPathList, ModuleRootManager.getInstance(module).getSourceRoots()); for (Module dependency : dependencies) { addRoots(pythonPathList, ModuleRootManager.getInstance(dependency).getSourceRoots()); } } addLibrariesFromModule(module, pythonPathList); addRootsFromModule(module, pythonPathList); for (Module dependency : dependencies) { addLibrariesFromModule(dependency, pythonPathList); addRootsFromModule(dependency, pythonPathList); } } return pythonPathList; }
public void collectCommonPluginRoots( Map<String, VirtualFile> result, @NotNull Module module, boolean refresh) { if (isCommonPluginsModule(module)) { for (VirtualFile root : ModuleRootManager.getInstance(module).getContentRoots()) { String pluginName = getInstalledPluginNameByPath(module.getProject(), root); if (pluginName != null) { result.put(pluginName, root); } } } else { VirtualFile root = findAppRoot(module); if (root == null) return; extractPlugins( module.getProject(), root.findChild(MvcModuleStructureUtil.PLUGINS_DIRECTORY), result); extractPlugins( module.getProject(), MvcModuleStructureUtil.findFile(getCommonPluginsDir(module), refresh), result); extractPlugins( module.getProject(), MvcModuleStructureUtil.findFile(getGlobalPluginsDir(module), refresh), result); } }
public static void addJavaHome(@NotNull JavaParameters params, @NotNull Module module) { final Sdk sdk = ModuleRootManager.getInstance(module).getSdk(); if (sdk != null && sdk.getSdkType() instanceof JavaSdkType) { String path = StringUtil.trimEnd(sdk.getHomePath(), File.separator); if (StringUtil.isNotEmpty(path)) { params.addEnv("JAVA_HOME", FileUtil.toSystemDependentName(path)); } } }
@Nullable public VirtualFile findAppRoot(@Nullable Module module) { if (module == null) return null; String appDirName = getApplicationDirectoryName(); for (VirtualFile root : ModuleRootManager.getInstance(module).getContentRoots()) { if (root.findChild(appDirName) != null) return root; } return null; }
public void createApplicationIfNeeded(@NotNull final Module module) { if (findAppRoot(module) == null && module.getUserData(CREATE_APP_STRUCTURE) == Boolean.TRUE) { while (ModuleRootManager.getInstance(module).getSdk() == null) { if (Messages.showYesNoDialog( module.getProject(), "Cannot generate " + getDisplayName() + " project structure because JDK is not specified for module \"" + module.getName() + "\".\n" + getDisplayName() + " project will not be created if you don't specify JDK.\nDo you want to specify JDK?", "Error", Messages.getErrorIcon()) == Messages.NO) { return; } ProjectSettingsService.getInstance(module.getProject()) .showModuleConfigurationDialog(module.getName(), ClasspathEditor.NAME); } module.putUserData(CREATE_APP_STRUCTURE, null); final GeneralCommandLine commandLine = getCreationCommandLine(module); if (commandLine == null) return; MvcConsole.executeProcess( module, commandLine, new Runnable() { public void run() { VirtualFile root = findAppRoot(module); if (root == null) return; PsiDirectory psiDir = PsiManager.getInstance(module.getProject()).findDirectory(root); IdeView ide = LangDataKeys.IDE_VIEW.getData(DataManager.getInstance().getDataContext()); if (ide != null) ide.selectElement(psiDir); // also here comes fileCreated(application.properties) which manages roots and run // configuration } }, true); } }
private static void addLibrariesFromModule(Module module, Collection<String> list) { final OrderEntry[] entries = ModuleRootManager.getInstance(module).getOrderEntries(); for (OrderEntry entry : entries) { if (entry instanceof LibraryOrderEntry) { final String name = ((LibraryOrderEntry) entry).getLibraryName(); if (name != null && name.endsWith(LibraryContributingFacet.PYTHON_FACET_LIBRARY_NAME_SUFFIX)) { // skip libraries from Python facet continue; } for (VirtualFile root : ((LibraryOrderEntry) entry).getRootFiles(OrderRootType.CLASSES)) { final Library library = ((LibraryOrderEntry) entry).getLibrary(); if (!PlatformUtils.isPyCharm()) { addToPythonPath(root, list); } else if (library instanceof LibraryImpl) { final PersistentLibraryKind<?> kind = ((LibraryImpl) library).getKind(); if (kind == PythonLibraryType.getInstance().getKind()) { addToPythonPath(root, list); } } } } } }
private static void removeModuleOutput(Module module, List<VirtualFile> from) { final CompilerModuleExtension extension = ModuleRootManager.getInstance(module).getModuleExtension(CompilerModuleExtension.class); from.remove(extension.getCompilerOutputPath()); from.remove(extension.getCompilerOutputPathForTests()); }