/** * Deletes given directory. * * @param dir directory */ private void deleteDir(File dir) { if (dir == null) { return; } if (dir.isFile()) { return; } for (File file : dir.listFiles()) { if (file.isDirectory()) { deleteDir(file); } else { file.delete(); } } dir.delete(); }
/** * Deletes given directory. * * @param dir directory */ private void deleteDir(final File dir) { if (dir == null) { return; } if (dir.isFile()) { return; } final File[] files = dir.listFiles(); if (files != null) { for (final File file : files) { if (file.isDirectory()) { deleteDir(file); } else { if (!file.delete()) { file.deleteOnExit(); } } } } if (!dir.delete()) { dir.deleteOnExit(); } }
/** * {@inheritDoc} */ @Override public void afterStop(StandardServer standardServer) { // clean ear based webapps after shutdown for (ContextInfo contextInfo : infos.values()) { if (contextInfo != null && contextInfo.deployer != null) { StandardContext standardContext = contextInfo.standardContext; HostConfig deployer = contextInfo.deployer; deployer.unmanageApp(standardContext.getPath()); String realPath = standardContext.getServletContext().getRealPath(""); if (realPath != null) { deleteDir(new File(realPath)); } } } }
/** * {@inheritDoc} */ @Override public synchronized void afterStop(final StandardServer standardServer) { // clean ear based webapps after shutdown for (final ContextInfo contextInfo : infos.values()) { if (contextInfo != null && contextInfo.deployer != null) { final StandardContext standardContext = contextInfo.standardContext; final HostConfig deployer = contextInfo.deployer; deployer.unmanageApp(standardContext.getPath()); final File realPath = Contexts.warPath(standardContext); if (realPath != null) { deleteDir(realPath); } } } TomcatLoader.destroy(); }
/** * {@inheritDoc} */ @Override public void undeployWebApps(AppInfo appInfo) throws Exception { for (WebAppInfo webApp : appInfo.webApps) { ContextInfo contextInfo = getContextInfo(webApp.host, webApp.contextRoot); if (contextInfo != null && contextInfo.deployer != null) { StandardContext standardContext = contextInfo.standardContext; HostConfig deployer = contextInfo.deployer; if (deployer != null) { deployer.unmanageApp(standardContext.getPath()); } else if (contextInfo.host != null) { contextInfo.host.removeChild(standardContext); } deleteDir(new File(standardContext.getServletContext().getRealPath(""))); removeContextInfo(standardContext); } } }
/** * {@inheritDoc} */ @Override public void undeployWebApps(final AppInfo appInfo) throws Exception { final String version = appVersion(appInfo); for (final WebAppInfo webApp : appInfo.webApps) { final ContextInfo contextInfo = getContextInfo(webApp.host, webApp.contextRoot, version); if (contextInfo != null) { final StandardContext standardContext = contextInfo.standardContext; if (!appInfo.webAppAlone || !appInfo.properties.containsKey("tomee.destroying")) { undeploy(standardContext, contextInfo); final File extracted = Contexts.warPath(standardContext); if (isExtracted(extracted)) { deleteDir(extracted); } removeContextInfo(standardContext); } } } }