@Override public ModuleConfigurationEditor[] createEditors(@NotNull ModuleConfigurationState state) { ModifiableRootModel rootModel = state.getRootModel(); Module module = rootModel.getModule(); if (!(ModuleType.get(module) instanceof GoModuleType)) { return ModuleConfigurationEditor.EMPTY; } String moduleName = module.getName(); List<ModuleConfigurationEditor> editors = ContainerUtil.newArrayList(); editors.add(new ContentEntriesEditor(moduleName, state)); editors.add(new OutputEditorEx(state)); editors.add(new ClasspathEditor(state)); return editors.toArray(new ModuleConfigurationEditor[editors.size()]); }
private static void updateModules(@NotNull Project project, @NotNull Library lib, boolean remove) { Module[] modules = ModuleManager.getInstance(project).getModules(); for (Module module : modules) { ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel(); if (!remove) { if (model.findLibraryOrderEntry(lib) == null) { LibraryOrderEntry entry = model.addLibraryEntry(lib); entry.setScope(DependencyScope.PROVIDED); } } else { LibraryOrderEntry entry = model.findLibraryOrderEntry(lib); if (entry != null) { model.removeOrderEntry(entry); } } model.commit(); } }
private void addContentRoot(@NotNull VirtualFile contentRoot) { ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel(); try { model.addContentEntry(contentRoot); contentRootsToClean.add(contentRoot); model.commit(); } finally { if (!model.isDisposed()) model.dispose(); } }
for (ContentEntry entry : model.getContentEntries()) { if (contentRootsToClean.contains(entry.getFile())) { model.removeContentEntry(entry); if (!model.isDisposed()) model.dispose();
addListener(this); final Module module = rootModel.getModule(); final MonkeySdkType sdkType = MonkeySdkType.getInstance(); CompilerModuleExtension compilerModuleExtension = rootModel.getModuleExtension(CompilerModuleExtension.class); compilerModuleExtension.setExcludeOutput(true); compilerModuleExtension.inheritCompilerOutputPath(true); rootModel.setSdk(getModuleJdk()); } else { rootModel.inheritSdk(); Optional<ContentEntry> existingContentEntry = Arrays.stream(rootModel.getContentEntries()).findFirst(); if (existingContentEntry.isPresent()) { final TargetDeviceModuleExtension targetDeviceModuleExtension = rootModel.getModuleExtension(TargetDeviceModuleExtension.class); targetDeviceModuleExtension.setTargetDevice(DEFAULT_TARGET_DEVICE); targetDeviceModuleExtension.setTargetSdkVersion(DEFAULT_TARGET_SDK_VERSION); final Project project = rootModel.getProject(); VirtualFile[] files = rootModel.getContentRoots();
/** * Add global protobuf library to given module. Visible for testing. */ public void addLibrary(Module module) { ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); ModifiableRootModel modifiableRootModel = moduleRootManager.getModifiableModel(); AtomicBoolean found = new AtomicBoolean(false); OrderEnumerator.orderEntries(module).forEachLibrary(library1 -> { if (LIB_NAME.equals(library1.getName())) { found.set(true); return false; } return true; }); if (!found.get()) { ApplicationManager.getApplication().runWriteAction(() -> { modifiableRootModel.addLibraryEntry(globalLibrary); modifiableRootModel.commit(); }); } }
@Override public void setupRootModel(final ModifiableRootModel rootModel) throws ConfigurationException { if (myJdk != null) { rootModel.setSdk(myJdk); } else { rootModel.inheritSdk(); final Project project = rootModel.getProject(); final RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(project); final ConfigurationFactory factory = configurationType.getConfigurationFactories()[0]; runDmdSettings = runManager.createRunConfiguration(COMPILE_CONFIG_NAME, factory); ((ModuleBasedConfiguration) runDmdSettings.getConfiguration()).setModule(rootModel.getModule()); final ConfigurationFactory factory = configurationType.getConfigurationFactories()[0]; runAppSettings = runManager.createRunConfiguration(RUN_CONFIG_NAME, factory); ((ModuleBasedConfiguration) runAppSettings.getConfiguration()).setModule(rootModel.getModule());
@Override public void afterLibraryAdded(final Library addedLibrary) { Optional<AppEngineStandardMavenLibrary> libraryOptional = AppEngineStandardMavenLibrary.getLibraryByMavenDisplayName(addedLibrary.getName()); libraryOptional.ifPresent( library -> { final DependencyScope scope = library.getScope(); ApplicationManager.getApplication() .runWriteAction( () -> { ModifiableRootModel model = ModuleRootManager.getInstance(context.getModule()).getModifiableModel(); model.addLibraryEntry(addedLibrary); Arrays.stream(model.getOrderEntries()) .filter( orderEntry -> orderEntry.getPresentableName().equals(addedLibrary.getName())) .forEach( orderEntry -> ((ExportableOrderEntry) orderEntry).setScope(scope)); model.commit(); }); Artifact artifact = AppEngineStandardSupportProvider.findOrCreateWebArtifact( (AppEngineStandardFacet) context.getFacet()); AppEngineStandardWebIntegration.getInstance() .addLibraryToArtifact(addedLibrary, artifact, context.getProject()); appEngineStandardLibraryPanel.toggleLibrary(library, true /* select */); }); }
@Override public void setupRootModel(ModifiableRootModel rootModel) { final CompilerModuleExtension compilerModuleExtension = rootModel.getModuleExtension(CompilerModuleExtension.class); compilerModuleExtension.setExcludeOutput(true); if (myJdk != null) { rootModel.setSdk(myJdk); rootModel.inheritSdk(); LibraryTable libraryTable = rootModel.getModuleLibraryTable(); for (Pair<String, String> libInfo : myModuleLibraries) { final String moduleLibraryPath = libInfo.first;
private static void toggleGrammarKitSrc(Module module, String testDataPath) { String absolutePath = new File("").getAbsolutePath(); JavaPsiFacade facade = JavaPsiFacade.getInstance(module.getProject()); boolean add = facade.findPackage("org.intellij.grammar.psi") == null; if (add) { VfsRootAccess.allowRootAccess(absolutePath); } else { VfsRootAccess.disallowRootAccess(absolutePath); } WriteAction.run(() -> { ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel(); String supportUrl = getUrl(testDataPath + "/../../src"); String genUrl = getUrl(testDataPath + "/../../gen"); if (add) { model.addContentEntry(supportUrl).addSourceFolder(supportUrl, false); model.addContentEntry(genUrl).addSourceFolder(genUrl, false); } else { for (ContentEntry entry : model.getContentEntries()) { if (supportUrl.equals(entry.getUrl()) || genUrl.equals(entry.getUrl())) { model.removeContentEntry(entry); } } } model.commit(); }); assertTrue("GrammarKit src problem", add == (null != facade.findPackage("org.intellij.grammar.psi"))); }
@Override MathematicaLanguageLevelModuleExtensionImpl getModuleExtension() { return getModel().getModuleExtension(MathematicaLanguageLevelModuleExtensionImpl.class); } };
private void addLibsToModule( @NotNull final ModifiableRootModel modifiableRootModel, @NotNull IdeModifiableModelsProvider modifiableModelsProvider, @NotNull final String libraryName, final boolean export ) { Validate.notNull(modifiableRootModel); final LibraryTable.ModifiableModel libraryTableModifiableModel = modifiableModelsProvider .getModifiableProjectLibrariesModel(); Library library = libraryTableModifiableModel.getLibraryByName(libraryName); if (null == library) { library = libraryTableModifiableModel.createLibrary(libraryName); } modifiableRootModel.addLibraryEntry(library); if (export) { setLibraryEntryExported(modifiableRootModel, library); } }
@Override public void setupRootModel(final ModifiableRootModel rootModel) throws ConfigurationException { super.setupRootModel(rootModel); final Project project = rootModel.getProject(); final RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(project); if (dubBinary != null) { ToolKey.DUB_KEY.setPath(dubBinary); } //Create "Run dub" configuration RunnerAndConfigurationSettings runDubSettings = runManager.findConfigurationByName(RUN_DUB_CONFIG_NAME); if (runDubSettings == null) { final DlangRunDubConfigurationType configurationType = Extensions.findExtension(ConfigurationType.CONFIGURATION_TYPE_EP, DlangRunDubConfigurationType.class); final ConfigurationFactory factory = configurationType.getConfigurationFactories()[0]; runDubSettings = runManager.createRunConfiguration(RUN_DUB_CONFIG_NAME, factory); ((ModuleBasedConfiguration) runDubSettings.getConfiguration()).setModule(rootModel.getModule()); runManager.addConfiguration(runDubSettings, false); } }
ContentEntry contentEntry = doAddContentEntry(rootModel); final MathematicaLanguageLevelModuleExtensionImpl moduleExtension = rootModel.getModuleExtension(MathematicaLanguageLevelModuleExtensionImpl.class); moduleExtension.setMathematicaLanguageLevel(myLanguageLevel); myPackageName = StringUtil.strip(getName(), CharFilter.NOT_WHITESPACE_FILTER); if (sourceRoot != null) { contentEntry.addSourceFolder(sourceRoot, false); final Project project = rootModel.getProject(); MathematicaTemplateProperties props = MathematicaTemplateProperties.create(); props.setProperty(MathematicaTemplateProperties.CONTEXT, myPackageName + "`");
@Override protected void doOKAction() { if (getOKAction().isEnabled()) { ApplicationManager.getApplication() .runWriteAction( () -> { ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel(); IdeaModifiableModelsProvider modelsProvider = new IdeaModifiableModelsProvider(); moduleConfigurable.addSupport(module, model, modelsProvider); model.commit(); }); } super.doOKAction(); }
VirtualFile root = ArrayUtil.getFirstElement(rootModel.getContentRoots()); if (root != null) { try {
private static LibraryOrderEntry findOrderEntryForLibrary( final @NotNull ModifiableRootModel modifiableRootModel, final @NotNull Library library ) { // Workaround of using Library.equals in findLibraryOrderEntry, which doesn't work here, because all empty libs are equal. Use == instead. return (LibraryOrderEntry) Arrays .stream(modifiableRootModel.getOrderEntries()) .filter(entry -> entry instanceof LibraryOrderEntry && ((LibraryOrderEntry) entry).getLibrary() == library) .findFirst() .orElse(modifiableRootModel.findLibraryOrderEntry(library)); } }
ClasspathStorage.setStorageType(modifiableRootModel, ClassPathStorageUtil.DEFAULT_STORAGE); modifiableRootModel.inheritSdk();
Validate.notNull(moduleDescriptor); final ContentEntry contentEntry = modifiableRootModel.addContentEntry(VfsUtil.pathToUrl( moduleDescriptor.getRootDirectory().getAbsolutePath() ));
try { Optional<ContentEntry> existingContentEntry = Arrays.stream(modifiableModel.getContentEntries()).findFirst(); if (existingContentEntry.isPresent()) { ContentEntry contentEntry = existingContentEntry.get();