tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1357491 - in /openejb/trunk/openejb/tomee/tomee-embedded/src: main/java/org/apache/tomee/embedded/Container.java main/java/org/apache/tomee/embedded/Main.java test/java/org/apache/tomee/embedded/EmbeddedTomEEContainerTest.java
Date Thu, 05 Jul 2012 08:46:20 GMT
Author: rmannibucau
Date: Thu Jul  5 08:46:19 2012
New Revision: 1357491

URL: http://svn.apache.org/viewvc?rev=1357491&view=rev
Log:
TOMEE-268 tomme-embedded was ignoring overidding name if the app was deployed from war and
enhancing the runner to be able to specify the context name

Modified:
    openejb/trunk/openejb/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java
    openejb/trunk/openejb/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java
    openejb/trunk/openejb/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/EmbeddedTomEEContainerTest.java

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=1357491&r1=1357490&r2=1357491&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
Thu Jul  5 08:46:19 2012
@@ -251,8 +251,9 @@ public class Container {
                 }
             }
             for (WebAppInfo webApp : appInfo.webApps) {
-                if (file.getName().equals(webApp.moduleId)) {
+                if (sameApplication(file, webApp)) {
                     webApp.moduleId = name;
+                    webApp.contextRoot = lastPart(name, webApp.contextRoot);
                 }
             }
         }
@@ -265,6 +266,25 @@ public class Container {
         return context;
     }
 
+    private static boolean sameApplication(final File file, final WebAppInfo webApp) {
+        String filename = file.getName();
+        if (filename.endsWith(".war")) {
+            filename = filename.substring(0, filename.length() - 4);
+        }
+        return filename.equals(webApp.moduleId);
+    }
+
+    private static String lastPart(final String name, final String defaultValue) {
+        int idx = name.lastIndexOf("/");
+        int space = name.lastIndexOf(" ");
+        if (idx >= 0 && space < idx) {
+            return name.substring(idx);
+        } else if (idx < 0 && space < 0) {
+            return name;
+        }
+        return defaultValue;
+    }
+
     public AppInfo getInfo(final String name) {
         return infos.get(name);
     }

Modified: openejb/trunk/openejb/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java?rev=1357491&r1=1357490&r2=1357491&view=diff
==============================================================================
--- openejb/trunk/openejb/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java
(original)
+++ openejb/trunk/openejb/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java
Thu Jul  5 08:46:19 2012
@@ -29,6 +29,7 @@ public class Main {
     public static final String PORT = "port";
     public static final String SHUTDOWN = "shutdown";
     public static final String PATH = "path";
+    public static final String CONTEXT = "context";
     public static final String DIRECTORY = "directory";
 
     public static void main(final String[] args) {
@@ -51,15 +52,25 @@ public class Main {
 			container.start();
 
             if (line.hasOption(PATH)) {
+                final String[] contexts;
+                if (line.hasOption(CONTEXT)) {
+                    contexts = line.getOptionValues(CONTEXT);
+                } else {
+                    contexts = null;
+                }
+                int i = 0;
                 for (String path : line.getOptionValues(PATH)) {
                     final File file = new File(ProvisioningUtil.realLocation(path));
                     if (!file.exists()) {
-                        System.out.println(file.getAbsolutePath() + " does not exist, skipping");
+                        System.err.println(file.getAbsolutePath() + " does not exist, skipping");
                         continue;
                     }
 
-                    final String filenameWithoutExtension = file.getName().replaceAll("\\.[A-Za-z]+$",
"");
-                    container.deploy(filenameWithoutExtension, file);
+                    String name = file.getName().replaceAll("\\.[A-Za-z]+$", "");
+                    if (contexts != null) {
+                        name = contexts[i++];
+                    }
+                    container.deploy(name, file, true);
                 }
             }
 
@@ -82,6 +93,7 @@ public class Main {
     private static Options createOptions() {
         final Options options = new Options();
         options.addOption(null, PATH, true, "");
+        options.addOption(null, CONTEXT, true, "Context name for applications (same order
than paths)");
         options.addOption("p", PORT, true, "TomEE http port");
         options.addOption("s", SHUTDOWN, true, "TomEE shutdown port");
         options.addOption("d", DIRECTORY, true, "TomEE shutdown port");

Modified: openejb/trunk/openejb/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/EmbeddedTomEEContainerTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/EmbeddedTomEEContainerTest.java?rev=1357491&r1=1357490&r2=1357491&view=diff
==============================================================================
--- openejb/trunk/openejb/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/EmbeddedTomEEContainerTest.java
(original)
+++ openejb/trunk/openejb/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/EmbeddedTomEEContainerTest.java
Thu Jul  5 08:46:19 2012
@@ -54,7 +54,7 @@ public class EmbeddedTomEEContainerTest 
             EJBContainer container = EJBContainer.createEJBContainer(p);
             assertNotNull(container);
             assertNotNull(container.getContext());
-            URL url = new URL("http://127.0.0.1:" + System.getProperty(EmbeddedTomEEContainer.TOMEE_EJBCONTAINER_HTTP_PORT)
+ "/" + war.getName() + "/index.html");
+            URL url = new URL("http://127.0.0.1:" + System.getProperty(EmbeddedTomEEContainer.TOMEE_EJBCONTAINER_HTTP_PORT)
+ "/test/index.html");
             assertEquals("true", IO.readProperties(url).getProperty("ok"));
             container.close();
         } finally {



Mime
View raw message