You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by an...@apache.org on 2012/04/23 12:13:57 UTC

svn commit: r1329161 [2/2] - in /openejb/trunk/openejb: arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ arquillian-tomee/arquillian-tomee-moviefun-example/src/test/java/org/superbiz/moviefun/ arquillian-tome...

Modified: openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java (original)
+++ openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java Mon Apr 23 10:13:56 2012
@@ -45,16 +45,7 @@ import org.apache.naming.ContextBindings
 import org.apache.openejb.AppContext;
 import org.apache.openejb.Injection;
 import org.apache.openejb.OpenEJBException;
-import org.apache.openejb.assembler.classic.AppInfo;
-import org.apache.openejb.assembler.classic.Assembler;
-import org.apache.openejb.assembler.classic.ClassListInfo;
-import org.apache.openejb.assembler.classic.ConnectorInfo;
-import org.apache.openejb.assembler.classic.DeploymentExceptionManager;
-import org.apache.openejb.assembler.classic.EjbJarInfo;
-import org.apache.openejb.assembler.classic.InjectionBuilder;
-import org.apache.openejb.assembler.classic.JndiEncBuilder;
-import org.apache.openejb.assembler.classic.WebAppBuilder;
-import org.apache.openejb.assembler.classic.WebAppInfo;
+import org.apache.openejb.assembler.classic.*;
 import org.apache.openejb.config.AppModule;
 import org.apache.openejb.config.ConfigurationFactory;
 import org.apache.openejb.config.DeploymentLoader;
@@ -182,23 +173,23 @@ public class TomcatWebAppBuilder impleme
     public TomcatWebAppBuilder() {
 
         // TODO: re-write this bit, so this becomes part of the listener, and we register this with the mbean server.
-    	
-        StandardServer standardServer = TomcatHelper.getServer();
+
+        final StandardServer standardServer = TomcatHelper.getServer();
         globalListenerSupport = new GlobalListenerSupport(standardServer, this);
 
         // could search mbeans
-        
+
         //Getting host config listeners
-        for (Service service : standardServer.findServices()) {
+        for (final Service service : standardServer.findServices()) {
             if (service.getContainer() instanceof Engine) {
-                Engine engine = (Engine) service.getContainer();
-                for (Container engineChild : engine.findChildren()) {
+                final Engine engine = (Engine) service.getContainer();
+                for (final Container engineChild : engine.findChildren()) {
                     if (engineChild instanceof StandardHost) {
-                        StandardHost host = (StandardHost) engineChild;
+                        final StandardHost host = (StandardHost) engineChild;
                         hosts.put(host.getName(), host);
-                        for (LifecycleListener listener : host.findLifecycleListeners()) {
+                        for (final LifecycleListener listener : host.findLifecycleListeners()) {
                             if (listener instanceof HostConfig) {
-                                HostConfig hostConfig = (HostConfig) listener;
+                                final HostConfig hostConfig = (HostConfig) listener;
                                 deployers.put(host.getName(), hostConfig);
                             }
                         }
@@ -231,7 +222,7 @@ public class TomcatWebAppBuilder impleme
             return CONTEXT_DIGESTER;
         }
 
-        Digester digester = new Digester();
+        final Digester digester = new Digester();
         digester.setValidating(false);
         digester.addObjectCreate("Context", "org.apache.catalina.core.StandardContext", "className");
         digester.addSetProperties("Context");
@@ -253,24 +244,25 @@ public class TomcatWebAppBuilder impleme
     //
     // OpenEJB WebAppBuilder
     //
+
     /**
      * {@inheritDoc}
      */
     @Override
-    public void deployWebApps(AppInfo appInfo, final ClassLoader classLoader) throws Exception {
-        for (WebAppInfo webApp : appInfo.webApps) {
+    public void deployWebApps(final AppInfo appInfo, final ClassLoader classLoader) throws Exception {
+        for (final WebAppInfo webApp : appInfo.webApps) {
             // look for context.xml
-            File war = new File(webApp.path);
+            final File war = new File(webApp.path);
             InputStream contextXml = null;
             if (war.isDirectory()) {
-                File cXml = new File(war, Constants.ApplicationContextXml);
+                final File cXml = new File(war, Constants.ApplicationContextXml);
                 if (cXml.exists()) {
                     contextXml = IO.read(cXml);
                     System.out.println("using context file " + cXml.getAbsolutePath());
                 }
             } else { // war
-                JarFile warAsJar = new JarFile(war);
-                JarEntry entry = warAsJar.getJarEntry(Constants.ApplicationContextXml);
+                final JarFile warAsJar = new JarFile(war);
+                final JarEntry entry = warAsJar.getJarEntry(Constants.ApplicationContextXml);
                 if (entry != null) {
                     contextXml = warAsJar.getInputStream(entry);
                 }
@@ -307,7 +299,7 @@ public class TomcatWebAppBuilder impleme
                 webApp.host = standardContext.getHostname();
             }
 
-            ApplicationParameter appParam = new ApplicationParameter();
+            final ApplicationParameter appParam = new ApplicationParameter();
             appParam.setName(OPENEJB_WEBAPP_MODULE_ID);
             appParam.setValue(webApp.moduleId);
             standardContext.addApplicationParameter(appParam);
@@ -350,20 +342,20 @@ public class TomcatWebAppBuilder impleme
                     host = "localhost";
                     logger.warning("using default host: " + host);
                 }
-                
+
                 // TODO: instead of storing deployers, we could just lookup the right hostconfig for the server.
                 final HostConfig deployer = deployers.get(host);
                 if (isReady(deployer)) { // if not ready using directly host to avoid a NPE
                     // host isn't set until we call deployer.manageApp, so pass it
                     // ?? host is set through an event and it can be null here :(
-                    ContextInfo contextInfo = addContextInfo(host, standardContext);
+                    final ContextInfo contextInfo = addContextInfo(host, standardContext);
                     contextInfo.appInfo = appInfo;
                     contextInfo.deployer = deployer;
                     deployer.manageApp(standardContext);
                 } else if (hosts.containsKey(host)) {
-                    Host theHost = hosts.get(host);
+                    final Host theHost = hosts.get(host);
 
-                    ContextInfo contextInfo = addContextInfo(host, standardContext);
+                    final ContextInfo contextInfo = addContextInfo(host, standardContext);
                     contextInfo.appInfo = appInfo;
                     contextInfo.host = theHost;
 
@@ -375,6 +367,7 @@ public class TomcatWebAppBuilder impleme
 
     // TODO: find something more sexy
     private static Field HOST_CONFIG_HOST = null;
+
     static {
         try { // do it only once
             HOST_CONFIG_HOST = HostConfig.class.getDeclaredField("host");
@@ -382,7 +375,8 @@ public class TomcatWebAppBuilder impleme
             // no-op
         }
     }
-    private static boolean isReady(HostConfig deployer) {
+
+    private static boolean isReady(final HostConfig deployer) {
         if (deployer != null && HOST_CONFIG_HOST != null) {
             try {
                 return HOST_CONFIG_HOST.get(deployer) != null;
@@ -398,7 +392,7 @@ public class TomcatWebAppBuilder impleme
      *
      * @param context the servlet context to init.
      */
-    private static void addMyFacesDefaultParameters(ClassLoader classLoader, ServletContext context) {
+    private static void addMyFacesDefaultParameters(final ClassLoader classLoader, final ServletContext context) {
         if (!SystemInstance.get().getOptions().get(OPENEJB_MYFACES_DISABLE_DEFAULT_VALUES, false)) {
             if (classLoader != null) {
                 try { // if myfaces is not here we doesn't need any trick
@@ -412,7 +406,7 @@ public class TomcatWebAppBuilder impleme
         }
     }
 
-    private static void setInitParameter(ServletContext context, String key, String value) {
+    private static void setInitParameter(final ServletContext context, final String key, final String value) {
         if (context.getInitParameter(key) == null) {
             context.setInitParameter(key, value);
         }
@@ -422,13 +416,13 @@ public class TomcatWebAppBuilder impleme
      * {@inheritDoc}
      */
     @Override
-    public void undeployWebApps(AppInfo appInfo) throws Exception {
-        for (WebAppInfo webApp : appInfo.webApps) {
-            ContextInfo contextInfo = getContextInfo(webApp.host, webApp.contextRoot);
+    public void undeployWebApps(final AppInfo appInfo) throws Exception {
+        for (final WebAppInfo webApp : appInfo.webApps) {
+            final ContextInfo contextInfo = getContextInfo(webApp.host, webApp.contextRoot);
 
             if (contextInfo != null && contextInfo.deployer != null) {
-                StandardContext standardContext = contextInfo.standardContext;
-                HostConfig deployer = contextInfo.deployer;
+                final StandardContext standardContext = contextInfo.standardContext;
+                final HostConfig deployer = contextInfo.deployer;
 
                 if (deployer != null) {
                     deployer.unmanageApp(standardContext.getPath());
@@ -446,28 +440,35 @@ public class TomcatWebAppBuilder impleme
      *
      * @param dir directory
      */
-    private void deleteDir(File dir) {
+    private void deleteDir(final File dir) {
         if (dir == null) {
             return;
         }
         if (dir.isFile()) {
             return;
         }
-        for (File file : dir.listFiles()) {
-            if (file.isDirectory()) {
-                deleteDir(file);
-            } else {
-                file.delete();
+        final File[] files = dir.listFiles();
+        if (files != null) {
+            for (final File file : files) {
+                if (file.isDirectory()) {
+                    deleteDir(file);
+                } else {
+                    if (!file.delete()) {
+                        file.deleteOnExit();
+                    }
+                }
             }
         }
-        dir.delete();
+        if (!dir.delete()) {
+            dir.deleteOnExit();
+        }
     }
 
     /**
      * {@inheritDoc}
      */
     @Override
-    public void init(StandardContext standardContext) {
+    public void init(final StandardContext standardContext) {
         replaceHashSetForJspPropertyGroupsByLinkedHashSet(standardContext);
         standardContext.setCrossContext(SystemInstance.get().getOptions().get(OPENEJB_CROSSCONTEXT_PROPERTY, false));
         standardContext.setNamingResources(new OpenEJBNamingResource());
@@ -494,16 +495,16 @@ public class TomcatWebAppBuilder impleme
         }
 
         if (standardContext.getConfigFile() == null) {
-            String s = File.pathSeparator;
-            File contextXmlFile = new File(standardContext.getDocBase() + s + "META-INF" + s + "context.xml");
+            final String s = File.pathSeparator;
+            final File contextXmlFile = new File(standardContext.getDocBase() + s + "META-INF" + s + "context.xml");
             if (contextXmlFile.exists()) {
                 BackportUtil.getAPI().setConfigFile(standardContext, contextXmlFile);
                 standardContext.setOverride(true);
             }
         }
 
-        LifecycleListener[] listeners = standardContext.findLifecycleListeners();
-        for (LifecycleListener l : listeners) {
+        final LifecycleListener[] listeners = standardContext.findLifecycleListeners();
+        for (final LifecycleListener l : listeners) {
             if (l instanceof ContextConfig) {
                 standardContext.removeLifecycleListener(l);
             }
@@ -511,7 +512,7 @@ public class TomcatWebAppBuilder impleme
         standardContext.addLifecycleListener(new OpenEJBContextConfig(new StandardContextInfo(standardContext)));
 
         // force manually the namingContextListener to merge jndi in an easier way
-        NamingContextListener ncl = new NamingContextListener();
+        final NamingContextListener ncl = new NamingContextListener();
         ncl.setName(standardContext.getName());
         standardContext.setNamingContextListener(ncl);
         standardContext.addLifecycleListener(ncl);
@@ -522,7 +523,7 @@ public class TomcatWebAppBuilder impleme
 
         private final StandardContext standardContext;
 
-        public StandardContextInfo(StandardContext standardContext) {
+        public StandardContextInfo(final StandardContext standardContext) {
             this.standardContext = standardContext;
         }
 
@@ -530,8 +531,8 @@ public class TomcatWebAppBuilder impleme
             final ContextInfo contextInfo = getContextInfo(standardContext);
             System.out.println("contextInfo = " + contextInfo);
             System.out.println("standardContext = " + standardContext);
-            for (WebAppInfo webApp : contextInfo.appInfo.webApps) {
-                if (standardContext.getName().equals("/"+webApp.contextRoot)) {
+            for (final WebAppInfo webApp : contextInfo.appInfo.webApps) {
+                if (standardContext.getName().equals("/" + webApp.contextRoot)) {
                     return webApp;
                 }
             }
@@ -548,12 +549,12 @@ public class TomcatWebAppBuilder impleme
 
     /**
      * a small hack to preserve order of jsppropertygroups.
-     *
+     * <p/>
      * to remove if tomcat fixes it.
      *
      * @param standardContext
      */
-    private static void replaceHashSetForJspPropertyGroupsByLinkedHashSet(StandardContext standardContext) {
+    private static void replaceHashSetForJspPropertyGroupsByLinkedHashSet(final StandardContext standardContext) {
         try {
             ReflectionUtil.set(standardContext.getJspConfigDescriptor(), "jspPropertyGroups", new LinkedHashSet<JspPropertyGroupDescriptor>());
         } catch (OpenEJBException e) {
@@ -565,12 +566,12 @@ public class TomcatWebAppBuilder impleme
      * {@inheritDoc}
      */
     @Override
-    public void beforeStart(StandardContext standardContext) {
-        ServletContext sc = standardContext.getServletContext();
+    public void beforeStart(final StandardContext standardContext) {
+        final ServletContext sc = standardContext.getServletContext();
         if (sc != null && !SystemInstance.get().getOptions().get(OPENEJB_JSESSION_ID_SUPPORT, true)) {
-            Set<SessionTrackingMode> defaultTrackingModes = sc.getEffectiveSessionTrackingModes();
+            final Set<SessionTrackingMode> defaultTrackingModes = sc.getEffectiveSessionTrackingModes();
             if (defaultTrackingModes.contains(SessionTrackingMode.URL)) {
-                Set<SessionTrackingMode> newModes = new HashSet<SessionTrackingMode>();
+                final Set<SessionTrackingMode> newModes = new HashSet<SessionTrackingMode>();
                 newModes.remove(SessionTrackingMode.URL);
                 sc.setSessionTrackingModes(newModes);
             }
@@ -578,11 +579,11 @@ public class TomcatWebAppBuilder impleme
     }
 
     @Override
-    public void configureStart(StandardContext standardContext) {
+    public void configureStart(final StandardContext standardContext) {
         if (TomcatHelper.isTomcat7()) {
             TomcatHelper.configureJarScanner(standardContext);
 
-            ContextTransaction contextTransaction = new ContextTransaction();
+            final ContextTransaction contextTransaction = new ContextTransaction();
             contextTransaction.setProperty(org.apache.naming.factory.Constants.FACTORY, UserTransactionFactory.class.getName());
             standardContext.getNamingResources().setTransaction(contextTransaction);
             startInternal(standardContext);
@@ -598,22 +599,23 @@ public class TomcatWebAppBuilder impleme
     // context class loader is now defined, but no classes should have been loaded
     @SuppressWarnings("unchecked")
     @Override
-    public void start(StandardContext standardContext) {
+    public void start(final StandardContext standardContext) {
         if (!TomcatHelper.isTomcat7()) {
             startInternal(standardContext);
         }
     }
+
     /**
      * {@inheritDoc}
      */
 //    @Override
-    private void startInternal(StandardContext standardContext) {
+    private void startInternal(final StandardContext standardContext) {
         System.out.println("TomcatWebAppBuilder.start " + standardContext.getPath());
         if (isIgnored(standardContext)) return;
-        
-        CoreContainerSystem cs = getContainerSystem();
 
-        Assembler a = getAssembler();
+        final CoreContainerSystem cs = getContainerSystem();
+
+        final Assembler a = getAssembler();
         if (a == null) {
             logger.warning("OpenEJB has not been initialized so war will not be scanned for nested modules " + standardContext.getPath());
             return;
@@ -624,11 +626,11 @@ public class TomcatWebAppBuilder impleme
         ContextInfo contextInfo = getContextInfo(standardContext);
         final ClassLoader classLoader = standardContext.getLoader().getClassLoader();
         if (contextInfo == null) {
-            AppModule appModule = loadApplication(standardContext);
+            final AppModule appModule = loadApplication(standardContext);
             if (appModule != null) {
                 try {
                     contextInfo = addContextInfo(standardContext.getHostname(), standardContext);
-                    AppInfo appInfo = configurationFactory.configureApplication(appModule);
+                    final AppInfo appInfo = configurationFactory.configureApplication(appModule);
                     contextInfo.appInfo = appInfo;
 
                     appContext = a.createApplication(contextInfo.appInfo, classLoader);
@@ -639,7 +641,7 @@ public class TomcatWebAppBuilder impleme
                     // just to force tomee to start without EE part
                     if (System.getProperty(TOMEE_EAT_EXCEPTION_PROP) == null) {
                         final TomEERuntimeException tre = new TomEERuntimeException(e);
-                        DeploymentExceptionManager dem = SystemInstance.get().getComponent(DeploymentExceptionManager.class);
+                        final DeploymentExceptionManager dem = SystemInstance.get().getComponent(DeploymentExceptionManager.class);
                         dem.saveDeploymentException(contextInfo.appInfo, tre);
                         throw tre;
                     }
@@ -647,12 +649,12 @@ public class TomcatWebAppBuilder impleme
                 }
             }
         }
-        
+
         if (appContext == null) {
-        	String contextRoot = standardContext.getName();
-        	if (contextRoot.startsWith("/")) {
-        		contextRoot = contextRoot.replaceAll("^/+", "");
-        	}
+            String contextRoot = standardContext.getName();
+            if (contextRoot.startsWith("/")) {
+                contextRoot = contextRoot.replaceAll("^/+", "");
+            }
         }
 
         contextInfo.standardContext = standardContext;
@@ -660,14 +662,14 @@ public class TomcatWebAppBuilder impleme
         WebAppInfo webAppInfo = null;
         // appInfo is null when deployment fails
         if (contextInfo.appInfo != null) {
-            for (WebAppInfo w : contextInfo.appInfo.webApps) {
+            for (final WebAppInfo w : contextInfo.appInfo.webApps) {
                 if (("/" + w.contextRoot).equals(standardContext.getPath()) || isRootApplication(standardContext)) {
                     webAppInfo = w;
-                    
+
                     if (appContext == null) {
-                    	appContext = cs.getAppContext(contextInfo.appInfo.appId);
+                        appContext = cs.getAppContext(contextInfo.appInfo.appId);
                     }
-                    
+
                     break;
                 }
             }
@@ -680,7 +682,7 @@ public class TomcatWebAppBuilder impleme
 
             // save jsf stuff
             final Map<String, Set<String>> scannedJsfClasses = new HashMap<String, Set<String>>();
-            for (ClassListInfo info : webAppInfo.jsfAnnotatedClasses) {
+            for (final ClassListInfo info : webAppInfo.jsfAnnotatedClasses) {
                 scannedJsfClasses.put(info.name, info.list);
             }
             jsfClasses.put(standardContext.getLoader().getClassLoader(), scannedJsfClasses);
@@ -717,21 +719,21 @@ public class TomcatWebAppBuilder impleme
                 logger.error("Error merging Java EE JNDI entries in to war " + standardContext.getPath() + ": Exception: " + e.getMessage(), e);
             }
 
-            JspFactory factory = JspFactory.getDefaultFactory();
+            final JspFactory factory = JspFactory.getDefaultFactory();
             if (factory != null) {
-                JspApplicationContext applicationCtx = factory.getJspApplicationContext(standardContext.getServletContext());
-                WebBeansContext context = appContext.getWebBeansContext();
+                final JspApplicationContext applicationCtx = factory.getJspApplicationContext(standardContext.getServletContext());
+                final WebBeansContext context = appContext.getWebBeansContext();
                 if (context != null && context.getBeanManagerImpl().isInUse()) {
                     // Registering ELResolver with JSP container
-                    ELAdaptor elAdaptor = context.getService(ELAdaptor.class);
-                    ELResolver resolver = elAdaptor.getOwbELResolver();
+                    final ELAdaptor elAdaptor = context.getService(ELAdaptor.class);
+                    final ELResolver resolver = elAdaptor.getOwbELResolver();
                     applicationCtx.addELResolver(resolver);
                 }
             }
         }
     }
 
-    private static void undeploy(StandardContext standardContext, ContextInfo contextInfo) {
+    private static void undeploy(final StandardContext standardContext, final ContextInfo contextInfo) {
         if (isReady(contextInfo.deployer)) {
             contextInfo.deployer.unmanageApp(standardContext.getName());
         } else if (contextInfo.host != null) {
@@ -739,7 +741,7 @@ public class TomcatWebAppBuilder impleme
         }
     }
 
-    private JndiEncBuilder getJndiBuilder(ClassLoader classLoader, WebAppInfo webAppInfo, Set<Injection> injections) throws OpenEJBException {
+    private JndiEncBuilder getJndiBuilder(final ClassLoader classLoader, final WebAppInfo webAppInfo, final Set<Injection> injections) throws OpenEJBException {
         return new JndiEncBuilder(webAppInfo.jndiEnc, injections, webAppInfo.moduleId, "Bean", null, webAppInfo.uniqueId, classLoader);
     }
 
@@ -751,7 +753,7 @@ public class TomcatWebAppBuilder impleme
         if (isIgnored(standardContext)) return;
 
         // if appInfo is null this is a failed deployment... just ignore
-        ContextInfo contextInfo = getContextInfo(standardContext);
+        final ContextInfo contextInfo = getContextInfo(standardContext);
         if (contextInfo != null && contextInfo.appInfo == null) {
             return;
         } else if (contextInfo == null) { // openejb webapp loaded from the LoaderServlet
@@ -760,26 +762,26 @@ public class TomcatWebAppBuilder impleme
 
         // bind extra stuff at the java:comp level which can only be
         // bound after the context is created
-        NamingContextListener ncl = getNamingContextListener(standardContext);
-        String listenerName = ncl.getName();
+        final NamingContextListener ncl = getNamingContextListener(standardContext);
+        final String listenerName = ncl.getName();
         ContextAccessController.setWritable(listenerName, standardContext);
         try {
 
             Context openejbContext = getContainerSystem().getJNDIContext();
             openejbContext = (Context) openejbContext.lookup("openejb");
 
-            Context root = (Context) ContextBindings.getClassLoader().lookup("");
-            Context comp = (Context) ContextBindings.getClassLoader().lookup("comp"); // usually fails
+            final Context root = (Context) ContextBindings.getClassLoader().lookup("");
+            final Context comp = (Context) ContextBindings.getClassLoader().lookup("comp"); // usually fails
 
             // Context root = ncl.getNamingContext();
             // Context comp = (Context) root.lookup("comp");
             safeBind(root, "openejb", openejbContext);
 
             // add context to WebDeploymentInfo
-            for (WebAppInfo webAppInfo : contextInfo.appInfo.webApps) {
-                boolean isRoot = isRootApplication(standardContext);
+            for (final WebAppInfo webAppInfo : contextInfo.appInfo.webApps) {
+                final boolean isRoot = isRootApplication(standardContext);
                 if (("/" + webAppInfo.contextRoot).equals(standardContext.getPath()) || isRoot) {
-                    WebContext webContext = getContainerSystem().getWebContext(webAppInfo.moduleId);
+                    final WebContext webContext = getContainerSystem().getWebContext(webAppInfo.moduleId);
                     if (webContext != null) {
                         webContext.setJndiEnc(comp);
                     }
@@ -796,11 +798,11 @@ public class TomcatWebAppBuilder impleme
             }
 
             // bind TransactionManager
-            TransactionManager transactionManager = SystemInstance.get().getComponent(TransactionManager.class);
+            final TransactionManager transactionManager = SystemInstance.get().getComponent(TransactionManager.class);
             safeBind(comp, "TransactionManager", transactionManager);
 
             // bind TransactionSynchronizationRegistry
-            TransactionSynchronizationRegistry synchronizationRegistry = SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class);
+            final TransactionSynchronizationRegistry synchronizationRegistry = SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class);
             safeBind(comp, "TransactionSynchronizationRegistry", synchronizationRegistry);
 
             safeBind(comp, "ORB", new SystemComponentReference(ORB.class));
@@ -812,24 +814,24 @@ public class TomcatWebAppBuilder impleme
         // required for Pojo Web Services because when Assembler creates the application
         // the CoreContainerSystem does not contain the WebContext
         // see also the start method getContainerSystem().addWebDeployment(webContext);
-        WebDeploymentListeners listeners = SystemInstance.get().getComponent(WebDeploymentListeners.class);
+        final WebDeploymentListeners listeners = SystemInstance.get().getComponent(WebDeploymentListeners.class);
         if (listeners != null) {
-            for (WebAppInfo webApp : contextInfo.appInfo.webApps) {
+            for (final WebAppInfo webApp : contextInfo.appInfo.webApps) {
                 listeners.afterApplicationCreated(contextInfo.appInfo, webApp);
             }
         }
 
         if (!TomcatVersion.hasAnnotationProcessingSupport()) {
             try {
-                Context compEnv = (Context) ContextBindings.getClassLoader().lookup("comp/env");
+                final Context compEnv = (Context) ContextBindings.getClassLoader().lookup("comp/env");
 
-                LegacyAnnotationProcessor annotationProcessor = new LegacyAnnotationProcessor(compEnv);
+                final LegacyAnnotationProcessor annotationProcessor = new LegacyAnnotationProcessor(compEnv);
 
                 standardContext.addContainerListener(new ProcessAnnotatedListenersListener(annotationProcessor));
 
-                for (Container container : standardContext.findChildren()) {
+                for (final Container container : standardContext.findChildren()) {
                     if (container instanceof Wrapper) {
-                        Wrapper wrapper = (Wrapper) container;
+                        final Wrapper wrapper = (Wrapper) container;
                         wrapper.addInstanceListener(new ProcessAnnotatedServletsListener(annotationProcessor));
                     }
                 }
@@ -851,7 +853,7 @@ public class TomcatWebAppBuilder impleme
         pipeline.addValve(new OpenEJBValve());
 
         final String[] valves = SystemInstance.get().getOptions().get("tomee.valves", "").split(" *, *");
-        for (String className : valves) {
+        for (final String className : valves) {
             if ("".equals(className)) continue;
             try {
                 final Class<?> clazz = standardContext.getLoader().getClassLoader().loadClass(className);
@@ -865,7 +867,7 @@ public class TomcatWebAppBuilder impleme
         }
     }
 
-    private WebBeansListener getWebBeansContext(ContextInfo contextInfo) {
+    private WebBeansListener getWebBeansContext(final ContextInfo contextInfo) {
         final AppContext appContext = getContainerSystem().getAppContext(contextInfo.appInfo.appId);
 
         if (appContext == null) return null;
@@ -878,7 +880,7 @@ public class TomcatWebAppBuilder impleme
     }
 
 
-    private static boolean isIgnored(StandardContext standardContext) {
+    private static boolean isIgnored(final StandardContext standardContext) {
         // useful to disable web applications deployment
         // it can be placed in the context.xml file, server.xml, ...
         // see http://tomcat.apache.org/tomcat-5.5-doc/config/context.html#Context_Parameters
@@ -892,7 +894,7 @@ public class TomcatWebAppBuilder impleme
      * {@inheritDoc}
      */
     @Override
-    public void beforeStop(StandardContext standardContext) {
+    public void beforeStop(final StandardContext standardContext) {
         //No operation
     }
 
@@ -900,7 +902,7 @@ public class TomcatWebAppBuilder impleme
      * {@inheritDoc}
      */
     @Override
-    public void stop(StandardContext standardContext) {
+    public void stop(final StandardContext standardContext) {
         //No operation
     }
 
@@ -908,12 +910,12 @@ public class TomcatWebAppBuilder impleme
      * {@inheritDoc}
      */
     @Override
-    public void afterStop(StandardContext standardContext) {
+    public void afterStop(final StandardContext standardContext) {
         if (isIgnored(standardContext)) return;
 
-        ContextInfo contextInfo = getContextInfo(standardContext);
+        final ContextInfo contextInfo = getContextInfo(standardContext);
         if (contextInfo != null && contextInfo.appInfo != null && contextInfo.deployer == null
-            && getAssembler().getDeployedApplications().contains(contextInfo.appInfo)) {
+                && getAssembler().getDeployedApplications().contains(contextInfo.appInfo)) {
             try {
                 getAssembler().destroyApplication(contextInfo.appInfo.path);
             } catch (Exception e) {
@@ -927,7 +929,7 @@ public class TomcatWebAppBuilder impleme
      * {@inheritDoc}
      */
     @Override
-    public void destroy(StandardContext standardContext) {
+    public void destroy(final StandardContext standardContext) {
         //No operation
     }
 
@@ -935,14 +937,14 @@ public class TomcatWebAppBuilder impleme
      * {@inheritDoc}
      */
     @Override
-    public void afterStop(StandardServer standardServer) {
+    public void afterStop(final StandardServer standardServer) {
         // clean ear based webapps after shutdown
-        for (ContextInfo contextInfo : infos.values()) {
+        for (final ContextInfo contextInfo : infos.values()) {
             if (contextInfo != null && contextInfo.deployer != null) {
-                StandardContext standardContext = contextInfo.standardContext;
-                HostConfig deployer = contextInfo.deployer;
+                final StandardContext standardContext = contextInfo.standardContext;
+                final HostConfig deployer = contextInfo.deployer;
                 deployer.unmanageApp(standardContext.getPath());
-                String realPath = standardContext.getServletContext().getRealPath("");
+                final String realPath = standardContext.getServletContext().getRealPath("");
                 if (realPath != null) {
                     deleteDir(new File(realPath));
                 }
@@ -954,12 +956,12 @@ public class TomcatWebAppBuilder impleme
      * {@inheritDoc}
      */
     @Override
-    public synchronized void checkHost(StandardHost standardHost) {
+    public synchronized void checkHost(final StandardHost standardHost) {
         if (standardHost.getAutoDeploy()) {
             // Undeploy any modified application
-            for (Iterator<Map.Entry<String, DeployedApplication>> iterator = deployedApps.entrySet().iterator(); iterator.hasNext();) {
-                Map.Entry<String, DeployedApplication> entry = iterator.next();
-                DeployedApplication deployedApplication = entry.getValue();
+            for (Iterator<Map.Entry<String, DeployedApplication>> iterator = deployedApps.entrySet().iterator(); iterator.hasNext(); ) {
+                final Map.Entry<String, DeployedApplication> entry = iterator.next();
+                final DeployedApplication deployedApplication = entry.getValue();
                 if (deployedApplication.isModified()) {
                     if (deployedApplication.appInfo != null) { // can happen with badly formed config
                         try {
@@ -975,71 +977,73 @@ public class TomcatWebAppBuilder impleme
             }
 
             // Deploy new applications
-            File appBase = appBase(standardHost);
-            File[] files = appBase.listFiles();
-            for (File file : files) {
-                String name = file.getName();
-                // ignore war files
-                if (name.toLowerCase().endsWith(".war") || name.equals("ROOT") || name.equalsIgnoreCase("META-INF") || name.equalsIgnoreCase("WEB-INF")) {
-                    continue;
-                }
-                // ignore unpacked web apps
-                if (file.isDirectory() && new File(file, "WEB-INF").exists()) {
-                    continue;
-                }
-                // ignore unpacked apps where packed version is present (packed version is owner)
-                if (file.isDirectory() && (new File(file.getParent(), file.getName() + ".ear").exists()
-                        || new File(file.getParent(), file.getName() + ".war").exists()
-                        || new File(file.getParent(), file.getName() + ".rar").exists())) {
-                    continue;
-                }
-                // ignore already deployed apps
-                if (isDeployed(file, standardHost)) {
-                    continue;
-                }
+            final File appBase = appBase(standardHost);
+            final File[] files = appBase.listFiles();
+            if (null != files) {
+                for (File file : files) {
+                    final String name = file.getName();
+                    // ignore war files
+                    if (name.toLowerCase().endsWith(".war") || name.equals("ROOT") || name.equalsIgnoreCase("META-INF") || name.equalsIgnoreCase("WEB-INF")) {
+                        continue;
+                    }
+                    // ignore unpacked web apps
+                    if (file.isDirectory() && new File(file, "WEB-INF").exists()) {
+                        continue;
+                    }
+                    // ignore unpacked apps where packed version is present (packed version is owner)
+                    if (file.isDirectory() && (new File(file.getParent(), file.getName() + ".ear").exists()
+                            || new File(file.getParent(), file.getName() + ".war").exists()
+                            || new File(file.getParent(), file.getName() + ".rar").exists())) {
+                        continue;
+                    }
+                    // ignore already deployed apps
+                    if (isDeployed(file, standardHost)) {
+                        continue;
+                    }
 
-                AppInfo appInfo;
-                try {
-                    file = file.getCanonicalFile().getAbsoluteFile();
-                    AppModule appModule = deploymentLoader.load(file);
+                    final AppInfo appInfo;
+                    try {
+                        file = file.getCanonicalFile().getAbsoluteFile();
+                        final AppModule appModule = deploymentLoader.load(file);
 
-                    // Ignore any standalone web modules - this happens when the app is unpaked and doesn't have a WEB-INF dir
-                    if (appModule.getDeploymentModule().size() == 1 && appModule.getWebModules().size() == 1) {
-                        WebModule webModule = appModule.getWebModules().iterator().next();
-                        if (file.getAbsolutePath().equals(webModule.getJarLocation())) {
-                            continue;
+                        // Ignore any standalone web modules - this happens when the app is unpaked and doesn't have a WEB-INF dir
+                        if (appModule.getDeploymentModule().size() == 1 && appModule.getWebModules().size() == 1) {
+                            final WebModule webModule = appModule.getWebModules().iterator().next();
+                            if (file.getAbsolutePath().equals(webModule.getJarLocation())) {
+                                continue;
+                            }
                         }
-                    }
 
-                    // tell web modules to deploy using this host
-                    for (WebModule webModule : appModule.getWebModules()) {
-                        webModule.setHost(standardHost.getName());
-                    }
+                        // tell web modules to deploy using this host
+                        for (final WebModule webModule : appModule.getWebModules()) {
+                            webModule.setHost(standardHost.getName());
+                        }
 
-                    appInfo = configurationFactory.configureApplication(appModule);
+                        appInfo = configurationFactory.configureApplication(appModule);
 
-                    // if this is an unpacked dir, tomcat will pick it up as a webapp so undeploy it first
-                    if (file.isDirectory()) {
-                        ContainerBase context = (ContainerBase) standardHost.findChild("/" + name);
-                        if (context != null) {
-                            try {
-                                standardHost.removeChild(context);
-                            } catch (Throwable t) {
-                                logger.warning("Error undeploying wep application from Tomcat  " + name, t);
-                            }
-                            try {
-                                context.destroy();
-                            } catch (Throwable t) {
-                                logger.warning("Error destroying Tomcat web context " + name, t);
+                        // if this is an unpacked dir, tomcat will pick it up as a webapp so undeploy it first
+                        if (file.isDirectory()) {
+                            final ContainerBase context = (ContainerBase) standardHost.findChild("/" + name);
+                            if (context != null) {
+                                try {
+                                    standardHost.removeChild(context);
+                                } catch (Throwable t) {
+                                    logger.warning("Error undeploying wep application from Tomcat  " + name, t);
+                                }
+                                try {
+                                    context.destroy();
+                                } catch (Throwable t) {
+                                    logger.warning("Error destroying Tomcat web context " + name, t);
+                                }
                             }
                         }
-                    }
 
-                    getAssembler().createApplication(appInfo);
+                        getAssembler().createApplication(appInfo);
 
-                    deployedApps.put(file.getAbsolutePath(), new DeployedApplication(file, appInfo));
-                } catch (Throwable e) {
-                    logger.warning("Error deploying application " + file.getAbsolutePath(), e);
+                        deployedApps.put(file.getAbsolutePath(), new DeployedApplication(file, appInfo));
+                    } catch (Throwable e) {
+                        logger.warning("Error deploying application " + file.getAbsolutePath(), e);
+                    }
                 }
             }
         }
@@ -1053,7 +1057,7 @@ public class TomcatWebAppBuilder impleme
      * @param standardHost host
      * @return true if given application is deployed
      */
-    private boolean isDeployed(File file, StandardHost standardHost) {
+    private boolean isDeployed(final File file, final StandardHost standardHost) {
         if (deployedApps.containsKey(file.getAbsolutePath())) {
             return true;
         }
@@ -1076,7 +1080,7 @@ public class TomcatWebAppBuilder impleme
      * @param standardContext tomcat context
      * @return true if given context is root web appliction
      */
-    private boolean isRootApplication(StandardContext standardContext) {
+    private boolean isRootApplication(final StandardContext standardContext) {
         return "".equals(standardContext.getPath());
     }
 
@@ -1086,7 +1090,7 @@ public class TomcatWebAppBuilder impleme
      * @param standardHost tomcat host
      * @return application base of the given host
      */
-    protected File appBase(StandardHost standardHost) {
+    protected File appBase(final StandardHost standardHost) {
         File file = new File(standardHost.getAppBase());
         if (!file.isAbsolute()) {
             file = new File(System.getProperty("catalina.base"), standardHost.getAppBase());
@@ -1129,17 +1133,17 @@ public class TomcatWebAppBuilder impleme
      * @param standardContext tomcat context instance
      * @return a openejb web module
      */
-    private void loadWebModule(AppModule appModule, StandardContext standardContext) {
-        WebModule webModule = appModule.getWebModules().get(0);
-        WebApp webApp = webModule.getWebApp();
+    private void loadWebModule(final AppModule appModule, final StandardContext standardContext) {
+        final WebModule webModule = appModule.getWebModules().get(0);
+        final WebApp webApp = webModule.getWebApp();
 
         // create the web module
-        String path = standardContext.getPath();
+        final String path = standardContext.getPath();
         logger.debug("context path = " + path);
         webModule.setHost(standardContext.getHostname());
         // Add all Tomcat env entries to context so they can be overriden by the env.properties file
-        NamingResources naming = standardContext.getNamingResources();
-        for (ContextEnvironment environment : naming.findEnvironments()) {
+        final NamingResources naming = standardContext.getNamingResources();
+        for (final ContextEnvironment environment : naming.findEnvironments()) {
             EnvEntry envEntry = webApp.getEnvEntryMap().get(environment.getName());
             if (envEntry == null) {
                 envEntry = new EnvEntry();
@@ -1152,17 +1156,17 @@ public class TomcatWebAppBuilder impleme
         }
 
         // remove all jndi entries where there is a configured Tomcat resource or resource-link
-        for (ContextResource resource : naming.findResources()) {
-            String name = resource.getName();
+        for (final ContextResource resource : naming.findResources()) {
+            final String name = resource.getName();
             removeRef(webApp, name);
         }
-        for (ContextResourceLink resourceLink : naming.findResourceLinks()) {
-            String name = resourceLink.getName();
+        for (final ContextResourceLink resourceLink : naming.findResourceLinks()) {
+            final String name = resourceLink.getName();
             removeRef(webApp, name);
         }
 
         // remove all env entries from the web xml that are not overridable
-        for (ContextEnvironment environment : naming.findEnvironments()) {
+        for (final ContextEnvironment environment : naming.findEnvironments()) {
             if (!environment.getOverride()) {
                 // overrides are not allowed
                 webApp.getEnvEntryMap().remove(environment.getName());
@@ -1177,7 +1181,7 @@ public class TomcatWebAppBuilder impleme
      * @param webApp web application instance
      * @param name   jndi reference name
      */
-    private void removeRef(WebApp webApp, String name) {
+    private void removeRef(final WebApp webApp, final String name) {
         webApp.getEnvEntryMap().remove(name);
         webApp.getEjbRefMap().remove(name);
         webApp.getEjbLocalRefMap().remove(name);
@@ -1195,7 +1199,7 @@ public class TomcatWebAppBuilder impleme
      * @param name  name of the binding
      * @param value binded object
      */
-    private void safeBind(Context comp, String name, Object value) {
+    private void safeBind(final Context comp, final String name, final Object value) {
         try {
             comp.lookup(name);
             logger.info(name + " already bound, ignoring");
@@ -1240,7 +1244,7 @@ public class TomcatWebAppBuilder impleme
      * @param standardContext context instance
      * @return id of the context
      */
-    private String getId(StandardContext standardContext) {
+    private String getId(final StandardContext standardContext) {
         String contextRoot = standardContext.getName();
         if (!contextRoot.startsWith("/")) {
             contextRoot = "/" + contextRoot;
@@ -1254,9 +1258,9 @@ public class TomcatWebAppBuilder impleme
      * @param standardContext context
      * @return context info
      */
-    private ContextInfo getContextInfo(StandardContext standardContext) {
-        String id = getId(standardContext);
-        ContextInfo contextInfo = infos.get(id);
+    private ContextInfo getContextInfo(final StandardContext standardContext) {
+        final String id = getId(standardContext);
+        final ContextInfo contextInfo = infos.get(id);
         return contextInfo;
     }
 
@@ -1265,14 +1269,14 @@ public class TomcatWebAppBuilder impleme
      *
      * @return context info
      */
-    private ContextInfo getContextInfo(String webAppHost, String webAppContextRoot) {
+    private ContextInfo getContextInfo(final String webAppHost, final String webAppContextRoot) {
         String host = webAppHost;
         if (host == null) {
             host = "localhost";
         }
-        String contextRoot = webAppContextRoot;
-        String id = host + "/" + contextRoot;
-        ContextInfo contextInfo = infos.get(id);
+        final String contextRoot = webAppContextRoot;
+        final String id = host + "/" + contextRoot;
+        final ContextInfo contextInfo = infos.get(id);
         return contextInfo;
     }
 
@@ -1283,12 +1287,12 @@ public class TomcatWebAppBuilder impleme
      * @param standardContext context
      * @return context info
      */
-    private ContextInfo addContextInfo(String host, StandardContext standardContext) {
+    private ContextInfo addContextInfo(final String host, final StandardContext standardContext) {
         String contextRoot = standardContext.getName();
         if (!contextRoot.startsWith("/")) {
             contextRoot = "/" + contextRoot;
         }
-        String id = host + contextRoot;
+        final String id = host + contextRoot;
         ContextInfo contextInfo = infos.get(id);
         if (contextInfo == null) {
             contextInfo = new ContextInfo();
@@ -1303,8 +1307,8 @@ public class TomcatWebAppBuilder impleme
      *
      * @param standardContext context
      */
-    private void removeContextInfo(StandardContext standardContext) {
-        String id = getId(standardContext);
+    private void removeContextInfo(final StandardContext standardContext) {
+        final String id = getId(standardContext);
         infos.remove(id);
     }
 
@@ -1322,29 +1326,29 @@ public class TomcatWebAppBuilder impleme
         private AppInfo appInfo;
         private final Map<File, Long> watchedResource = new HashMap<File, Long>();
 
-        public DeployedApplication(File base, AppInfo appInfo) {
+        public DeployedApplication(final File base, final AppInfo appInfo) {
             this.appInfo = appInfo;
             watchedResource.put(base, base.lastModified());
             if (appInfo != null) {
-                for (String resource : appInfo.watchedResources) {
-                    File file = new File(resource);
+                for (final String resource : appInfo.watchedResources) {
+                    final File file = new File(resource);
                     watchedResource.put(file, file.lastModified());
                 }
-                for (EjbJarInfo info : appInfo.ejbJars) {
-                    for (String resource : info.watchedResources) {
-                        File file = new File(resource);
+                for (final EjbJarInfo info : appInfo.ejbJars) {
+                    for (final String resource : info.watchedResources) {
+                        final File file = new File(resource);
                         watchedResource.put(file, file.lastModified());
                     }
                 }
-                for (WebAppInfo info : appInfo.webApps) {
-                    for (String resource : info.watchedResources) {
-                        File file = new File(resource);
+                for (final WebAppInfo info : appInfo.webApps) {
+                    for (final String resource : info.watchedResources) {
+                        final File file = new File(resource);
                         watchedResource.put(file, file.lastModified());
                     }
                 }
-                for (ConnectorInfo info : appInfo.connectors) {
-                    for (String resource : info.watchedResources) {
-                        File file = new File(resource);
+                for (final ConnectorInfo info : appInfo.connectors) {
+                    for (final String resource : info.watchedResources) {
+                        final File file = new File(resource);
                         watchedResource.put(file, file.lastModified());
                     }
                 }
@@ -1352,9 +1356,9 @@ public class TomcatWebAppBuilder impleme
         }
 
         public boolean isModified() {
-            for (Map.Entry<File, Long> entry : watchedResource.entrySet()) {
-                File file = entry.getKey();
-                long lastModified = entry.getValue();
+            for (final Map.Entry<File, Long> entry : watchedResource.entrySet()) {
+                final File file = entry.getKey();
+                final long lastModified = entry.getValue();
                 if ((!file.exists() && lastModified != 0L)
                         || (file.lastModified() != lastModified)) {
                     return true;

Modified: openejb/trunk/openejb/tomee/tomee-common/src/main/java/org/apache/tomee/installer/Installer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-common/src/main/java/org/apache/tomee/installer/Installer.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/tomee/tomee-common/src/main/java/org/apache/tomee/installer/Installer.java (original)
+++ openejb/trunk/openejb/tomee/tomee-common/src/main/java/org/apache/tomee/installer/Installer.java Mon Apr 23 10:13:56 2012
@@ -124,16 +124,21 @@ public class Installer {
     private void moveLibs() {
 
         final File libs = paths.getCatalinaLibDir();
-        for (File file : paths.getOpenEJBLibDir().listFiles()) {
-            if (file.isDirectory()) continue;
-            if (!file.getName().endsWith(".jar")) continue;
-
-            try {
-                Installers.copyFile(file, new File(libs, file.getName()));
-                file.delete();
-                alerts.addInfo("Copy " + file.getName() + " to lib");
-            } catch (IOException e) {
-                alerts.addError("Unable to " + file.getName() + " to Tomcat lib directory.  This will need to be performed manually.", e);
+        final File[] files = paths.getOpenEJBLibDir().listFiles();
+        if (files != null) {
+            for (File file : files) {
+                if (file.isDirectory()) continue;
+                if (!file.getName().endsWith(".jar")) continue;
+
+                try {
+                    Installers.copyFile(file, new File(libs, file.getName()));
+                    if(!file.delete()){
+                        file.deleteOnExit();
+                    }
+                    alerts.addInfo("Copy " + file.getName() + " to lib");
+                } catch (IOException e) {
+                    alerts.addError("Unable to " + file.getName() + " to Tomcat lib directory.  This will need to be performed manually.", e);
+                }
             }
         }
     }

Modified: openejb/trunk/openejb/tomee/tomee-common/src/main/java/org/apache/tomee/installer/Paths.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-common/src/main/java/org/apache/tomee/installer/Paths.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/tomee/tomee-common/src/main/java/org/apache/tomee/installer/Paths.java (original)
+++ openejb/trunk/openejb/tomee/tomee-common/src/main/java/org/apache/tomee/installer/Paths.java Mon Apr 23 10:13:56 2012
@@ -255,9 +255,12 @@ public class Paths {
         if (dir == null) return null;
 
         File openejbLoaderJar = null;
-        for (File file : dir.listFiles()) {
-            if (file.getName().startsWith(namePrefix + "-") && file.getName().endsWith(".jar")) {
-                return file;
+        final File[] files = dir.listFiles();
+        if (files != null) {
+            for (File file : files) {
+                if (file.getName().startsWith(namePrefix + "-") && file.getName().endsWith(".jar")) {
+                    return file;
+                }
             }
         }
 

Modified: openejb/trunk/openejb/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java (original)
+++ openejb/trunk/openejb/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java Mon Apr 23 10:13:56 2012
@@ -87,7 +87,7 @@ public class Container {
 
         executor.execute(new JaxbJavaeeLoad(WebApp.class));
         executor.execute(new JaxbJavaeeLoad(TldTaglib.class));
-        executor.execute(new Runnable(){
+        executor.execute(new Runnable() {
             @Override
             public void run() {
                 try {
@@ -322,7 +322,9 @@ public class Container {
             return;
 
         if (file.isFile()) {
-            file.delete();
+            if (!file.delete()) {
+                file.deleteOnExit();
+            }
             return;
         }
 
@@ -334,11 +336,15 @@ public class Container {
 
             File[] children = file.listFiles();
 
-            for (File child : children) {
-                deleteTree(child);
+            if (children != null) {
+                for (File child : children) {
+                    deleteTree(child);
+                }
             }
 
-            file.delete();
+            if (!file.delete()) {
+                file.deleteOnExit();
+            }
         }
     }
 
@@ -387,9 +393,9 @@ public class Container {
 
         return dir;
     }
-    
+
     public void await() {
-    	tomcat.getServer().await();
+        tomcat.getServer().await();
     }
 
     private static class TomcatWithFastSessionIDs extends Tomcat {

Modified: openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/OpenEJBListener.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/OpenEJBListener.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/OpenEJBListener.java (original)
+++ openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/OpenEJBListener.java Mon Apr 23 10:13:56 2012
@@ -120,9 +120,12 @@ public class OpenEJBListener implements 
                         final StandardHost host = (StandardHost) child;
                         final File base = hostDir(System.getProperty("catalina.base"), host.getAppBase());
 
-                        for (File file : base.listFiles()) {
-                            if (isTomEEWar(file)) {
-                                return file;
+                        final File[] files = base.listFiles();
+                        if (files != null) {
+                            for (File file : files) {
+                                if (isTomEEWar(file)) {
+                                    return file;
+                                }
                             }
                         }
                     }
@@ -238,9 +241,12 @@ public class OpenEJBListener implements 
              return null;
         }
         // iterate over the libs looking for the openejb-loader-*.jar
-        for (File file : webInfLib.listFiles()) {
-            if (file.getName().startsWith("tomee-catalina-") && file.getName().endsWith(".jar")) {
-                return contextDir;
+        final File[] files = webInfLib.listFiles();
+        if (files != null) {
+            for (File file : files) {
+                if (file.getName().startsWith("tomee-catalina-") && file.getName().endsWith(".jar")) {
+                    return contextDir;
+                }
             }
         }
         return null;

Modified: openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomcatEmbedder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomcatEmbedder.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomcatEmbedder.java (original)
+++ openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomcatEmbedder.java Mon Apr 23 10:13:56 2012
@@ -168,9 +168,12 @@ public class TomcatEmbedder {
         if (openEJBLibDir == null) return null;
 
         File openejbLoaderJar = null;
-        for (File file : openEJBLibDir.listFiles()) {
-            if (file.getName().startsWith(namePrefix + "-") && file.getName().endsWith(".jar")) {
-                return file;
+        final File[] files = openEJBLibDir.listFiles();
+        if (files != null) {
+            for (File file : files) {
+                if (file.getName().startsWith(namePrefix + "-") && file.getName().endsWith(".jar")) {
+                    return file;
+                }
             }
         }
 

Modified: openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomcatHelper.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomcatHelper.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomcatHelper.java (original)
+++ openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomcatHelper.java Mon Apr 23 10:13:56 2012
@@ -174,22 +174,25 @@ public class TomcatHelper {
 		File openejbApp = new File(System.getProperty("tomee.war"));
 		File libFolder = new File(openejbApp, "lib");
 		StringBuilder builder = new StringBuilder();
-		
-		for (File f : libFolder.listFiles()) {
-			if (f.getName().startsWith("javaee-api-embedded")) continue;
-			if (f.getName().startsWith("myfaces")) continue;
-			
-			
-			
-			if (f.getName().toLowerCase().endsWith(".jar")) {
-				if (builder.length() > 0) {
-					builder.append(",");
-				}
-				
-				builder.append(f.getName());
-			}
-		}
-		
-		return builder.toString();
+
+        final File[] files = libFolder.listFiles();
+        if (files != null) {
+            for (File f : files) {
+                if (f.getName().startsWith("javaee-api-embedded")) continue;
+                if (f.getName().startsWith("myfaces")) continue;
+
+
+
+                if (f.getName().toLowerCase().endsWith(".jar")) {
+                    if (builder.length() > 0) {
+                        builder.append(",");
+                    }
+
+                    builder.append(f.getName());
+                }
+            }
+        }
+
+        return builder.toString();
 	}
 }

Modified: openejb/trunk/openejb/utils/webdeployer/src/main/java/org/apache/tomee/catalina/deployer/WebappDeployer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/utils/webdeployer/src/main/java/org/apache/tomee/catalina/deployer/WebappDeployer.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/utils/webdeployer/src/main/java/org/apache/tomee/catalina/deployer/WebappDeployer.java (original)
+++ openejb/trunk/openejb/utils/webdeployer/src/main/java/org/apache/tomee/catalina/deployer/WebappDeployer.java Mon Apr 23 10:13:56 2012
@@ -66,23 +66,28 @@ public class WebappDeployer implements D
 		mBeanServer = Registry.getRegistry(null, null).getMBeanServer();
 	}
 
-	public String getUniqueFile() {
+	@Override
+    public String getUniqueFile() {
 		throw new TomEERuntimeException("This method is not used");
 	}
 
-	public Collection<AppInfo> getDeployedApps() {
+	@Override
+    public Collection<AppInfo> getDeployedApps() {
 		return assembler.getDeployedApplications();
 	}
 
-	public AppInfo deploy(String location) throws OpenEJBException {
+	@Override
+    public AppInfo deploy(final String location) throws OpenEJBException {
 		return deploy(location, null);
 	}
 
-	public AppInfo deploy(Properties properties) throws OpenEJBException {
+	@Override
+    public AppInfo deploy(final Properties properties) throws OpenEJBException {
 		return deploy(null, properties);
 	}
 
-	public AppInfo deploy(String location, Properties properties) throws OpenEJBException {
+	@Override
+    public AppInfo deploy(String location, Properties properties) throws OpenEJBException {
 		try {
 			if (location == null && properties == null) {
 				throw new NullPointerException("location and properties are null");
@@ -94,8 +99,8 @@ public class WebappDeployer implements D
 				properties = new Properties();
 			}
 
-			File source = new File(location);
-			File destination = new File(System.getProperty(OPENEJB_HOME) + File.separator + WEBAPPS + File.separator + source.getName());
+			final File source = new File(location);
+			final File destination = new File(System.getProperty(OPENEJB_HOME) + File.separator + WEBAPPS + File.separator + source.getName());
             IO.copy(source, destination);
 
             String destinationWithoutExtension = destination.getAbsolutePath();
@@ -112,7 +117,7 @@ public class WebappDeployer implements D
 				check();
 			}
 
-			final AppInfo info = findAppInfo(new String[] { destination.getAbsolutePath(), destinationWithoutExtension });
+			final AppInfo info = findAppInfo(destination.getAbsolutePath(), destinationWithoutExtension);
             if (info == null) {
                 throw new NullPointerException("appinfo not found");
             }
@@ -131,13 +136,13 @@ public class WebappDeployer implements D
 		}
 	}
 
-	private AppInfo findAppInfo(String... paths) {
-		Collection<AppInfo> deployedApps = getDeployedApps();
+	private AppInfo findAppInfo(final String... paths) {
+		final Collection<AppInfo> deployedApps = getDeployedApps();
 
-		Iterator<AppInfo> iterator = deployedApps.iterator();
+		final Iterator<AppInfo> iterator = deployedApps.iterator();
 		while (iterator.hasNext()) {
-			AppInfo appInfo = iterator.next();
-			for (String path : paths) {
+			final AppInfo appInfo = iterator.next();
+			for (final String path : paths) {
 				if (appInfo.path.equals(path)) {
 					return appInfo;
 				}
@@ -148,13 +153,13 @@ public class WebappDeployer implements D
 	}
 
 	private void check() {
-		StandardServer server = TomcatHelper.getServer();
-		for (Service service : server.findServices()) {
+		final StandardServer server = TomcatHelper.getServer();
+		for (final Service service : server.findServices()) {
 			if (service.getContainer() instanceof Engine) {
-				Engine engine = (Engine) service.getContainer();
-				for (Container engineChild : engine.findChildren()) {
+				final Engine engine = (Engine) service.getContainer();
+				for (final Container engineChild : engine.findChildren()) {
 					if (engineChild instanceof StandardHost) {
-						StandardHost host = (StandardHost) engineChild;
+						final StandardHost host = (StandardHost) engineChild;
 						webappBuilder.checkHost(host);
 					}
 				}
@@ -162,34 +167,36 @@ public class WebappDeployer implements D
 		}
 	}
 
-	private void checkWebapp(String webappName) {
+	private void checkWebapp(final String webappName) {
 		try {
-			ContextName cn = new ContextName(webappName);
+			final ContextName cn = new ContextName(webappName);
 
-			String name = "Catalina:type=Deployer,host=localhost";
-			ObjectName oname = new ObjectName(name);
+			final String name = "Catalina:type=Deployer,host=localhost";
+			final ObjectName oname = new ObjectName(name);
 
-			String[] params = { cn.getName() };
-			String[] signature = { "java.lang.String" };
+			final String[] params = { cn.getName() };
+			final String[] signature = { "java.lang.String" };
 			mBeanServer.invoke(oname, "check", params, signature);
 		} catch (Exception e) {
+            //Ignore
 		}
 	}
 
-	public void undeploy(String moduleId) throws UndeployException, NoSuchApplicationException {
+	@Override
+    public void undeploy(final String moduleId) throws UndeployException, NoSuchApplicationException {
 		try {
-			AppInfo appInfo = findAppInfo(moduleId);
+			final AppInfo appInfo = findAppInfo(moduleId);
 			if (appInfo !=  null) {
 				webappBuilder.undeployWebApps(appInfo);
 			}
 			
 			assembler.destroyApplication(moduleId);
 
-			File moduleFile = new File(moduleId);
+			final File moduleFile = new File(moduleId);
 			
 			if (moduleFile.getName().contains(".")) {
 				// delete matching directory
-				File dir = new File(moduleFile.getAbsolutePath().substring(0, moduleFile.getAbsolutePath().lastIndexOf('.')));
+				final File dir = new File(moduleFile.getAbsolutePath().substring(0, moduleFile.getAbsolutePath().lastIndexOf('.')));
 				if (dir.exists() && dir.isDirectory()) {
 					delete(dir);
 				}
@@ -206,24 +213,30 @@ public class WebappDeployer implements D
 		}
 	}
 
-	private void delete(File f) {
+	private void delete(final File f) {
 		if (f == null || (!f.exists())) {
 			return;
 		}
 		
 		if (f.isFile()) {
-			f.delete();
+			if(!f.delete()){
+                f.deleteOnExit();
+            }
 			return;
 		}
 		
 		if (f.isDirectory()) {
-			File[] listFiles = f.listFiles();
-			for (File file : listFiles) {
-				if (file.getName().equals(".") || file.getName().equals("..")) continue;
-				delete(file);
-			}
-			
-			f.delete();
+			final File[] listFiles = f.listFiles();
+            if (listFiles != null) {
+                for (final File file : listFiles) {
+                    if (file.getName().equals(".") || file.getName().equals("..")) continue;
+                    delete(file);
+                }
+            }
+
+            if(!f.delete()){
+                f.deleteOnExit();
+            }
 		}
 	}