private void appendChosenAnnotationsRoot( @NotNull final OrderEntry entry, @NotNull final VirtualFile vFile) { if (entry instanceof LibraryOrderEntry) { Library library = ((LibraryOrderEntry) entry).getLibrary(); LOG.assertTrue(library != null); final ModifiableRootModel rootModel = ModuleRootManager.getInstance(entry.getOwnerModule()).getModifiableModel(); final Library.ModifiableModel model = library.getModifiableModel(); model.addRoot(vFile, AnnotationOrderRootType.getInstance()); model.commit(); rootModel.commit(); } else if (entry instanceof ModuleSourceOrderEntry) { final ModifiableRootModel model = ModuleRootManager.getInstance(entry.getOwnerModule()).getModifiableModel(); final JavaModuleExternalPaths extension = model.getModuleExtension(JavaModuleExternalPaths.class); extension.setExternalAnnotationUrls( ArrayUtil.mergeArrays(extension.getExternalAnnotationsUrls(), vFile.getUrl())); model.commit(); } else if (entry instanceof JdkOrderEntry) { final SdkModificator sdkModificator = ((JdkOrderEntry) entry).getJdk().getSdkModificator(); sdkModificator.addRoot(vFile, AnnotationOrderRootType.getInstance()); sdkModificator.commitChanges(); } myExternalAnnotations.clear(); }
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 AddModuleDependencyFix( Module currentModule, VirtualFile classVFile, PsiClass[] classes, PsiReference reference) { final PsiElement psiElement = reference.getElement(); final Project project = psiElement.getProject(); final JavaPsiFacade facade = JavaPsiFacade.getInstance(project); final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); for (PsiClass aClass : classes) { if (!facade.getResolveHelper().isAccessible(aClass, psiElement, aClass)) continue; PsiFile psiFile = aClass.getContainingFile(); if (psiFile == null) continue; VirtualFile virtualFile = psiFile.getVirtualFile(); if (virtualFile == null) continue; final Module classModule = fileIndex.getModuleForFile(virtualFile); if (classModule != null && classModule != currentModule && !ModuleRootManager.getInstance(currentModule).isDependsOn(classModule)) { myModules.add(classModule); } } myCurrentModule = currentModule; myClassVFile = classVFile; myClasses = classes; myReference = reference; }
@Nullable protected VirtualFile findClassFile(String className) { final CompilerModuleExtension extension = ModuleRootManager.getInstance(myModule).getModuleExtension(CompilerModuleExtension.class); //noinspection ConstantConditions return extension.getCompilerOutputPath().findChild(className + ".class"); }
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; }
@Nullable protected VirtualFile findClassFile(String className, Module module) { //noinspection ConstantConditions VirtualFile path = ModuleRootManager.getInstance(module) .getModuleExtension(CompilerModuleExtension.class) .getCompilerOutputPath(); path.getChildren(); assert path != null; path.refresh(false, true); return path.findChild(className + ".class"); }
@Override protected boolean hasAnyAnnotationsRoots() { if (myHasAnyAnnotationsRoots == ThreeState.UNSURE) { final Module[] modules = ModuleManager.getInstance(myPsiManager.getProject()).getModules(); for (Module module : modules) { for (OrderEntry entry : ModuleRootManager.getInstance(module).getOrderEntries()) { final String[] urls = AnnotationOrderRootType.getUrls(entry); if (urls.length > 0) { myHasAnyAnnotationsRoots = ThreeState.YES; return true; } } } myHasAnyAnnotationsRoots = ThreeState.NO; } return myHasAnyAnnotationsRoots == ThreeState.YES; }
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); } }
public static AddSupportForSingleFrameworkDialogFixed createDialog( @NotNull Module module, @NotNull FrameworkSupportInModuleProvider provider) { VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots(); if (roots.length == 0) return null; List<FrameworkSupportInModuleProvider> providers = FrameworkSupportUtil.getProviders(module, DefaultFacetsProvider.INSTANCE); if (providers.isEmpty()) return null; final LibrariesContainer container = LibrariesContainerFactory.createContainer(module.getProject()); final IdeaModifiableModelsProvider modifiableModelsProvider = new IdeaModifiableModelsProvider(); return new AddSupportForSingleFrameworkDialogFixed( module, roots[0].getPath(), provider.getFrameworkType(), provider, container, modifiableModelsProvider); }
private ModuleRootManager getRootManager(String module) { return ModuleRootManager.getInstance(getModule(module)); }
private CompilerModuleExtension getCompilerExtension(String module) { ModuleRootManager m = getRootManager(module); return CompilerModuleExtension.getInstance(m.getModule()); }
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()); }
@Override public List<Module> commit( @NotNull Project project, @Nullable ModifiableModuleModel moduleModel, @NotNull ModulesProvider modulesProvider, @Nullable ModifiableArtifactModel modifiableArtifactModel) { Set<String> selectedAppNames = ContainerUtil.newHashSet(); for (ImportedOtpApp importedOtpApp : mySelectedOtpApps) { selectedAppNames.add(importedOtpApp.getName()); } Sdk projectSdk = fixProjectSdk(project); List<Module> createdModules = new ArrayList<Module>(); final List<ModifiableRootModel> createdRootModels = new ArrayList<ModifiableRootModel>(); final ModifiableModuleModel obtainedModuleModel = moduleModel != null ? moduleModel : ModuleManager.getInstance(project).getModifiableModel(); for (ImportedOtpApp importedOtpApp : mySelectedOtpApps) { VirtualFile ideaModuleDir = importedOtpApp.getRoot(); String ideaModuleFile = ideaModuleDir.getCanonicalPath() + File.separator + importedOtpApp.getName() + ".iml"; Module module = obtainedModuleModel.newModule(ideaModuleFile, ErlangModuleType.getInstance().getId()); createdModules.add(module); importedOtpApp.setModule(module); if (importedOtpApp.getIdeaModuleFile() == null) { ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel(); // Make it inherit SDK from the project. rootModel.inheritSdk(); // Initialize source and test paths. ContentEntry content = rootModel.addContentEntry(importedOtpApp.getRoot()); addSourceDirToContent(content, ideaModuleDir, "src", false); addSourceDirToContent(content, ideaModuleDir, "test", true); addIncludeDirectories(content, importedOtpApp); // Exclude standard folders excludeDirFromContent(content, ideaModuleDir, "doc"); // Initialize output paths according to Rebar conventions. CompilerModuleExtension compilerModuleExt = rootModel.getModuleExtension(CompilerModuleExtension.class); compilerModuleExt.inheritCompilerOutputPath(false); compilerModuleExt.setCompilerOutputPath(ideaModuleDir + File.separator + "ebin"); compilerModuleExt.setCompilerOutputPathForTests(ideaModuleDir + File.separator + ".eunit"); createdRootModels.add(rootModel); // Set inter-module dependencies resolveModuleDeps(rootModel, importedOtpApp, projectSdk, selectedAppNames); } } // Commit project structure. LOG.info("Commit project structure"); ApplicationManager.getApplication() .runWriteAction( new Runnable() { public void run() { for (ModifiableRootModel rootModel : createdRootModels) { rootModel.commit(); } obtainedModuleModel.commit(); } }); addErlangFacets(mySelectedOtpApps); RebarSettings.getInstance(project).setRebarPath(myRebarPath); if (myIsImportingProject) { ErlangCompilerSettings.getInstance(project).setUseRebarCompilerEnabled(true); } CompilerWorkspaceConfiguration.getInstance(project).CLEAR_OUTPUT_DIRECTORY = false; return createdModules; }