EnvironmentBuilder.mergeEnvironments(module.getEnvironment(), defaultEnvironment);
WebModule webModule = (WebModule) module;
WebApp webApp = webModule.getSpecDD();
EARContext moduleContext = module.getEarContext();
Map sharedContext = module.getSharedContext();
GBeanData webAppData = (GBeanData) sharedContext.get(WebModule.WEB_APP_DATA);
AbstractName moduleName = module.getModuleName();
Map<EARContext.Key, Object> buildingContext = new HashMap<EARContext.Key, Object>();
buildingContext.put(NamingBuilder.GBEAN_NAME_KEY, moduleName);
//use the same holder object as the web app.
Holder holder = NamingBuilder.INJECTION_KEY.get(sharedContext);
buildingContext.put(NamingBuilder.INJECTION_KEY, holder);
XmlObject jettyWebApp = webModule.getVendorDD();
Set<String> listenerNames = new HashSet<String>();
Map<String, Bundle> tldLocationBundleMap = getTldFiles(webApp, webModule);
LinkedHashSet<Class<?>> classes = getListenerClasses(webApp, webModule, tldLocationBundleMap, listenerNames);
AbstractFinder originalClassFinder = webModule.getClassFinder();
ClassFinder classFinder = new ClassFinder(new ArrayList<Class<?>>(classes));
webModule.setClassFinder(classFinder);
namingBuilders.buildNaming(webApp, jettyWebApp, webModule, buildingContext);
webModule.setClassFinder(originalClassFinder);
//only try to install it if reference will work.
//Some users (tomcat?) may have back doors into jasper that make adding this gbean unnecessary.
GBeanInfo webAppGBeanInfo = webAppData.getGBeanInfo();
if (webAppGBeanInfo.getReference("ContextCustomizer") != null) {
AbstractName jspLifecycleName = moduleContext.getNaming().createChildName(moduleName, "jspLifecycleProvider", GBeanInfoBuilder.DEFAULT_J2EE_TYPE);
GBeanData gbeanData = new GBeanData(jspLifecycleName, JasperServletContextCustomizer.class);
gbeanData.setAttribute("holder", holder);
try {
moduleContext.addGBean(gbeanData);
} catch (GBeanAlreadyExistsException e) {
throw new DeploymentException("Duplicate jspLifecycleProvider", e);
}
webAppData.setReferencePattern("ContextCustomizer", jspLifecycleName);
}
WebAppInfoBuilder webAppInfoBuilder = (WebAppInfoBuilder)sharedContext.get(WebModule.WEB_APP_INFO);
if (webAppInfoBuilder != null) {
WebAppInfo webAppInfo = webAppInfoBuilder.getWebAppInfo();
webAppInfo.listeners.addAll(listenerNames);
//install default jsp servlet....
ServletInfo jspServlet = webAppInfoBuilder.copy(defaultJspServletInfo);
List<JspConfig> jspConfigs = webApp.getJspConfig();
List<String> jspMappings = new ArrayList<String>();
for (JspConfig jspConfig : jspConfigs) {
for (JspPropertyGroup propertyGroup : jspConfig.getJspPropertyGroup()) {
WebAppInfoBuilder.normalizeUrlPatterns(propertyGroup.getUrlPattern(), jspMappings);
}
}
jspServlet.servletMappings.addAll(jspMappings);
for (ServletInfo servletInfo: webAppInfo.servlets) {
servletInfo.servletMappings.removeAll(jspMappings);
}
webAppInfo.servlets.add(jspServlet);
} else {
GBeanData jspServletData = AbstractWebModuleBuilder.DEFAULT_JSP_SERVLET_KEY.get(sharedContext);
if (jspServletData != null) {
try {
moduleContext.addGBean(jspServletData);
} catch (GBeanAlreadyExistsException e) {
throw new DeploymentException("jsp servlet already present", e);
}
}
// add listeners