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, 37 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/kryshen/catalina/userconfig/UserConfig.java	Tue Nov 03 04:06:30 2009 +0300
+++ b/src/kryshen/catalina/userconfig/UserConfig.java	Tue Nov 03 04:48:52 2009 +0300
@@ -17,6 +17,8 @@
 package kryshen.catalina.userconfig;
 
 import java.io.File;
+import java.util.Arrays;
+import java.util.List;
 import org.apache.catalina.startup.HostConfig;
 import org.apache.juli.logging.LogFactory;
 
@@ -125,7 +127,13 @@
 
         if (appsPerUser == 1) {
             // Single application mode.
-            deployUserApp(user, base, "ROOT");
+            String contextPath = getContextPath(user, "ROOT");
+
+            if (isServiced(contextPath)) {
+                return;
+            }
+
+            deployDirectory(contextPath, base, base.getAbsolutePath());
         } else {
             // Multiple applications mode.
             deployUserDirectories(user, base, files);
@@ -144,7 +152,23 @@
 
         int appCount = 0;
 
+        if (appsPerUser > 0) {
+            // Count number of already deployed user applications.
+            for (int i = 0; i < files.length; i++) {
+                String contextPath = getContextPath(user, files[i]);
+
+                if (isDeployed(contextPath)) {
+                    appCount++;
+                }
+            }
+        }
+
+        // Deploy new applications
         for (int i = 0; i < files.length; i++) {
+            if (appsPerUser > 0 && appCount >= appsPerUser) {
+                break;
+            }
+
             if (files[i].equalsIgnoreCase("META-INF")) {
                 continue;
             }
@@ -159,36 +183,26 @@
                 continue;
             }
 
-            deployUserApp(user, dir, files[i]);
+            String contextPath = getContextPath(user, files[i]);
 
-            appCount++;
+            if (isDeployed(contextPath)) {
+                continue;
+            }
 
-            if (appsPerUser > 0 && appCount >= appsPerUser) {
-                break;
+            if (isServiced(contextPath)) {
+                continue;
             }
+
+            deployDirectory(contextPath, dir, dir.getAbsolutePath());
+            appCount++;
         }
     }
 
-    /**
-     * Deploy user application.
-     *
-     * @param user Username.
-     * @param dir Application directory.
-     * @param app Application name.
-     */
-    protected void deployUserApp(String user, File dir, String app) {
-        String contextPath;
-
+    protected String getContextPath(String user, String app) {
         if (app.equals("ROOT")) {
-            contextPath = "/~" + user;
-        } else {
-            contextPath = "/~" + user + '/' + app.replace('#', '/');
+            return "/~" + user;
         }
 
-        if (isServiced(contextPath)) {
-            return;
-        }
-
-        deployDirectory(contextPath, dir, dir.getAbsolutePath());
+        return "/~" + user + '/' + app.replace('#', '/');
     }
 }