@NotNull private static Artifact findOrCreateWebArtifact(AppEngineFacet appEngineFacet) { Module module = appEngineFacet.getModule(); ArtifactType webArtifactType = AppEngineWebIntegration.getInstance().getAppEngineWebArtifactType(); final Collection<Artifact> artifacts = ArtifactUtil.getArtifactsContainingModuleOutput(module); for (Artifact artifact : artifacts) { if (webArtifactType.equals(artifact.getArtifactType())) { return artifact; } } ArtifactManager artifactManager = ArtifactManager.getInstance(module.getProject()); PackagingElementFactory elementFactory = PackagingElementFactory.getInstance(); ArtifactRootElement<?> root = elementFactory.createArtifactRootElement(); elementFactory .getOrCreateDirectory(root, "WEB-INF/classes") .addOrFindChild(elementFactory.createModuleOutput(module)); return artifactManager.addArtifact(module.getName(), webArtifactType, root); }
public AppEngineSupportProvider() { super(AppEngineFacet.getFacetType()); }
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); } }