Mercurial > hg > tomcat-userconfig
changeset 21:282500da9a6c
Fix appsPerUser limit calculation.
author | Mikhail Kryshen <mikhail@kryshen.net> |
---|---|
date | Tue, 03 Nov 2009 04:48:52 +0300 |
parents | d9b6abd14326 |
children | e67c9a4b6763 |
files | src/kryshen/catalina/userconfig/UserConfig.java |
diffstat | 1 files changed, 38 insertions(+), 24 deletions(-) [+] |
line diff
1.1 --- a/src/kryshen/catalina/userconfig/UserConfig.java Tue Nov 03 04:06:30 2009 +0300 1.2 +++ b/src/kryshen/catalina/userconfig/UserConfig.java Tue Nov 03 04:48:52 2009 +0300 1.3 @@ -17,6 +17,8 @@ 1.4 package kryshen.catalina.userconfig; 1.5 1.6 import java.io.File; 1.7 +import java.util.Arrays; 1.8 +import java.util.List; 1.9 import org.apache.catalina.startup.HostConfig; 1.10 import org.apache.juli.logging.LogFactory; 1.11 1.12 @@ -125,7 +127,13 @@ 1.13 1.14 if (appsPerUser == 1) { 1.15 // Single application mode. 1.16 - deployUserApp(user, base, "ROOT"); 1.17 + String contextPath = getContextPath(user, "ROOT"); 1.18 + 1.19 + if (isServiced(contextPath)) { 1.20 + return; 1.21 + } 1.22 + 1.23 + deployDirectory(contextPath, base, base.getAbsolutePath()); 1.24 } else { 1.25 // Multiple applications mode. 1.26 deployUserDirectories(user, base, files); 1.27 @@ -144,7 +152,23 @@ 1.28 1.29 int appCount = 0; 1.30 1.31 + if (appsPerUser > 0) { 1.32 + // Count number of already deployed user applications. 1.33 + for (int i = 0; i < files.length; i++) { 1.34 + String contextPath = getContextPath(user, files[i]); 1.35 + 1.36 + if (isDeployed(contextPath)) { 1.37 + appCount++; 1.38 + } 1.39 + } 1.40 + } 1.41 + 1.42 + // Deploy new applications 1.43 for (int i = 0; i < files.length; i++) { 1.44 + if (appsPerUser > 0 && appCount >= appsPerUser) { 1.45 + break; 1.46 + } 1.47 + 1.48 if (files[i].equalsIgnoreCase("META-INF")) { 1.49 continue; 1.50 } 1.51 @@ -159,36 +183,26 @@ 1.52 continue; 1.53 } 1.54 1.55 - deployUserApp(user, dir, files[i]); 1.56 + String contextPath = getContextPath(user, files[i]); 1.57 1.58 + if (isDeployed(contextPath)) { 1.59 + continue; 1.60 + } 1.61 + 1.62 + if (isServiced(contextPath)) { 1.63 + continue; 1.64 + } 1.65 + 1.66 + deployDirectory(contextPath, dir, dir.getAbsolutePath()); 1.67 appCount++; 1.68 - 1.69 - if (appsPerUser > 0 && appCount >= appsPerUser) { 1.70 - break; 1.71 - } 1.72 } 1.73 } 1.74 1.75 - /** 1.76 - * Deploy user application. 1.77 - * 1.78 - * @param user Username. 1.79 - * @param dir Application directory. 1.80 - * @param app Application name. 1.81 - */ 1.82 - protected void deployUserApp(String user, File dir, String app) { 1.83 - String contextPath; 1.84 - 1.85 + protected String getContextPath(String user, String app) { 1.86 if (app.equals("ROOT")) { 1.87 - contextPath = "/~" + user; 1.88 - } else { 1.89 - contextPath = "/~" + user + '/' + app.replace('#', '/'); 1.90 + return "/~" + user; 1.91 } 1.92 1.93 - if (isServiced(contextPath)) { 1.94 - return; 1.95 - } 1.96 - 1.97 - deployDirectory(contextPath, dir, dir.getAbsolutePath()); 1.98 + return "/~" + user + '/' + app.replace('#', '/'); 1.99 } 1.100 }