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 testCompilerOutputInheritance() throws Exception { File moduleFile = new File(getTestRoot(), "test.iml"); Module module = createModule(moduleFile); final ModuleRootManagerImpl moduleRootManager = (ModuleRootManagerImpl) ModuleRootManager.getInstance(module); final ModifiableRootModel rootModel = moduleRootManager.getModifiableModel(); rootModel.getModuleExtension(CompilerModuleExtension.class).inheritCompilerOutputPath(true); ApplicationManager.getApplication() .runWriteAction( new Runnable() { @Override public void run() { rootModel.commit(); } }); Element element = new Element("root"); moduleRootManager.getState().writeExternal(element); assertElementEquals( element, "<root inherit-compiler-output=\"true\">" + "<exclude-output />" + "<orderEntry type=\"sourceFolder\" forTests=\"false\" />" + "</root>", module); }
public void setLanguageLevel(LanguageLevel level) { try { myRootModel.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(level); } catch (IllegalArgumentException e) { // bad value was stored } }
@Override public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException { final VirtualFile virtualFile = file.getVirtualFile(); LOG.assertTrue(virtualFile != null); final Module module = ModuleUtilCore.findModuleForFile(virtualFile, project); final LanguageLevel moduleLevel = module == null ? null : LanguageLevelModuleExtensionImpl.getInstance(module).getLanguageLevel(); if (moduleLevel != null && isLanguageLevelAcceptable(project, module, myLevel)) { final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel(); rootModel.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(myLevel); rootModel.commit(); } else { LanguageLevelProjectExtension.getInstance(project).setLanguageLevel(myLevel); ProjectRootManagerEx.getInstanceEx(project) .makeRootsChange(EmptyRunnable.INSTANCE, false, true); } }
@Override public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException { final VirtualFile virtualFile = file.getVirtualFile(); LOG.assertTrue(virtualFile != null); final Module module = ModuleUtilCore.findModuleForFile(virtualFile, project); final LanguageLevel moduleLevel = module == null ? null : LanguageLevelModuleExtension.getInstance(module).getLanguageLevel(); if (moduleLevel != null && isLanguageLevelAcceptable(project, module, myLevel)) { final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel(); rootModel.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(myLevel); ApplicationManager.getApplication() .runWriteAction( new Runnable() { @Override public void run() { rootModel.commit(); } }); } else { LanguageLevelProjectExtension.getInstance(project).setLanguageLevel(myLevel); } }
private CompilerModuleExtension getCompilerExtension() { return myRootModel.getModuleExtension(CompilerModuleExtension.class); }
public static void setOutputUrl(ModifiableRootModel rootModel, String path) { final CompilerModuleExtension compilerModuleExtension = rootModel.getModuleExtension(CompilerModuleExtension.class); compilerModuleExtension.setCompilerOutputPath(pathToUrl(path)); compilerModuleExtension.inheritCompilerOutputPath(false); }
@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; }