public void addSupport( final @NotNull Module module, final @NotNull ModifiableRootModel rootModel) { List<Library> addedLibraries = new ArrayList<Library>(); List<FrameworkSupportNode> selectedFrameworks = getSelectedNodes(); sortFrameworks(selectedFrameworks); List<FrameworkSupportConfigurable> selectedConfigurables = new ArrayList<FrameworkSupportConfigurable>(); final IdeaModifiableModelsProvider modifiableModelsProvider = new IdeaModifiableModelsProvider(); for (FrameworkSupportNode node : selectedFrameworks) { FrameworkSupportInModuleConfigurable configurable = node.getConfigurable(); if (configurable instanceof OldFrameworkSupportProviderWrapper.FrameworkSupportConfigurableWrapper) { selectedConfigurables.add( ((OldFrameworkSupportProviderWrapper.FrameworkSupportConfigurableWrapper) configurable) .getConfigurable()); } final LibraryCompositionSettings settings = getLibraryCompositionSettings(node); Library library = settings != null ? settings.addLibraries(rootModel, addedLibraries, myLibrariesContainer) : null; if (configurable instanceof OldFrameworkSupportProviderWrapper.FrameworkSupportConfigurableWrapper) { ((OldFrameworkSupportProviderWrapper.FrameworkSupportConfigurableWrapper) configurable) .getConfigurable() .addSupport(module, rootModel, library); } else { configurable.addSupport(module, rootModel, modifiableModelsProvider); } } for (FrameworkSupportNode node : selectedFrameworks) { FrameworkSupportInModuleProvider provider = node.getUserObject(); if (provider instanceof OldFrameworkSupportProviderWrapper) { final FrameworkSupportProvider oldProvider = ((OldFrameworkSupportProviderWrapper) provider).getProvider(); if (oldProvider instanceof FacetBasedFrameworkSupportProvider && !addedLibraries.isEmpty()) { ((FacetBasedFrameworkSupportProvider) oldProvider) .processAddedLibraries(module, addedLibraries); } } } for (FrameworkSupportCommunicator communicator : FrameworkSupportCommunicator.EP_NAME.getExtensions()) { communicator.onFrameworkSupportAdded(module, rootModel, selectedConfigurables, myModel); } }
private void addSupport( final Module module, final ModifiableRootModel rootModel, FrameworkSupportModel frameworkSupportModel, String sdkPath, @Nullable PersistenceApi persistenceApi) { super.addSupport(module, rootModel, null, null); final AppEngineFacet appEngineFacet = AppEngineFacet.getAppEngineFacetByModule(module); LOG.assertTrue(appEngineFacet != null); AppEngineWebIntegration webIntegration = AppEngineWebIntegration.getInstance(); webIntegration.registerFrameworkInModel(frameworkSupportModel, appEngineFacet); final AppEngineFacetConfiguration facetConfiguration = appEngineFacet.getConfiguration(); facetConfiguration.setSdkHomePath(sdkPath); final AppEngineSdk sdk = appEngineFacet.getSdk(); final Artifact webArtifact = findOrCreateWebArtifact(appEngineFacet); final VirtualFile webDescriptorDir = webIntegration.suggestParentDirectoryForAppEngineWebXml(module, rootModel); if (webDescriptorDir != null) { VirtualFile descriptor = createFileFromTemplate( AppEngineTemplateGroupDescriptorFactory.APP_ENGINE_WEB_XML_TEMPLATE, webDescriptorDir, AppEngineUtil.APP_ENGINE_WEB_XML_NAME); if (descriptor != null) { webIntegration.addDescriptor(webArtifact, module.getProject(), descriptor); } } final Project project = module.getProject(); webIntegration.addDevServerToModuleDependencies(rootModel, sdk); final Library apiJar = addProjectLibrary( module, "AppEngine API", sdk.getUserLibraryPaths(), VirtualFile.EMPTY_ARRAY); rootModel.addLibraryEntry(apiJar); webIntegration.addLibraryToArtifact(apiJar, webArtifact, project); if (persistenceApi != null) { facetConfiguration.setRunEnhancerOnMake(true); facetConfiguration.setPersistenceApi(persistenceApi); facetConfiguration .getFilesToEnhance() .addAll(AppEngineUtil.getDefaultSourceRootsToEnhance(rootModel)); try { final VirtualFile[] sourceRoots = rootModel.getSourceRoots(); final VirtualFile sourceRoot; if (sourceRoots.length > 0) { sourceRoot = sourceRoots[0]; } else { sourceRoot = findOrCreateChildDirectory(rootModel.getContentRoots()[0], "src"); } VirtualFile metaInf = findOrCreateChildDirectory(sourceRoot, "META-INF"); if (persistenceApi == PersistenceApi.JDO || persistenceApi == PersistenceApi.JDO3) { createFileFromTemplate( AppEngineTemplateGroupDescriptorFactory.APP_ENGINE_JDO_CONFIG_TEMPLATE, metaInf, AppEngineUtil.JDO_CONFIG_XML_NAME); } else { final VirtualFile file = createFileFromTemplate( AppEngineTemplateGroupDescriptorFactory.APP_ENGINE_JPA_CONFIG_TEMPLATE, metaInf, AppEngineUtil.JPA_CONFIG_XML_NAME); if (file != null) { webIntegration.setupJpaSupport(module, file); } } } catch (IOException e) { LOG.error(e); } final Library library = addProjectLibrary( module, "AppEngine ORM", Collections.singletonList(sdk.getOrmLibDirectoryPath()), sdk.getOrmLibSources()); rootModel.addLibraryEntry(library); webIntegration.addLibraryToArtifact(library, webArtifact, project); } }