Author: rmannibucau
Date: Thu Oct 20 07:26:33 2016
New Revision: 1765759

URL: http://svn.apache.org/viewvc?rev=1765759&view=rev
Log:
moving 'all params' related to the deployment in an object to be able to extend 
it without breaking the API each time

Modified:
    
openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/Microwave.java

Modified: 
openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/Microwave.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/Microwave.java?rev=1765759&r1=1765758&r2=1765759&view=diff
==============================================================================
--- 
openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/Microwave.java
 (original)
+++ 
openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/Microwave.java
 Thu Oct 20 07:26:33 2016
@@ -113,36 +113,48 @@ public class Microwave implements AutoCl
         tomcat.getHost().removeChild(context);
     }
 
+    public Microwave deployClasspath(final DeploymentMeta meta) {
+        final File dir = new File(configuration.tempDir, "classpath/fake-" + 
meta.context.replace("/", ""));
+        FileUtils.mkDir(dir);
+        final Consumer<Context> builtInCustomizer = c -> c.setLoader(new 
ProvidedLoader(Thread.currentThread().getContextClassLoader()));
+        return deployWebapp(new DeploymentMeta(meta.context, 
ofNullable(meta.consumer).map(c -> (Consumer<Context>) ctx -> {
+            builtInCustomizer.accept(ctx);
+            c.accept(ctx);
+        }).orElse(builtInCustomizer)), dir);
+    }
+
+    // shortcut
     public Microwave deployClasspath() {
         return deployClasspath("");
     }
 
+    // shortcut (used by plugins)
     public Microwave deployClasspath(final String context) {
-        final File dir = new File(configuration.tempDir, "classpath/fake-" + 
context.replace("/", ""));
-        FileUtils.mkDir(dir);
-        return deployWebapp(context, dir, c -> c.setLoader(new 
ProvidedLoader(Thread.currentThread().getContextClassLoader())));
+        return deployClasspath(new DeploymentMeta(context, null));
     }
 
+    // shortcut
     public Microwave deployWebapp(final File warOrDir) {
-        return deployWebapp("", warOrDir, null);
+        return deployWebapp("", warOrDir);
     }
 
+    // shortcut (used by plugins)
     public Microwave deployWebapp(final String context, final File warOrDir) {
-        return deployWebapp(context, warOrDir, null);
+        return deployWebapp(new DeploymentMeta(context, null), warOrDir);
     }
 
-    public Microwave deployWebapp(final String context, final File warOrDir, 
final Consumer<Context> customizer) {
-        if (contexts.containsKey(context)) {
-            throw new IllegalArgumentException("Already deployed: '" + context 
+ "'");
+    public Microwave deployWebapp(final DeploymentMeta meta, final File 
warOrDir) {
+        if (contexts.containsKey(meta.context)) {
+            throw new IllegalArgumentException("Already deployed: '" + 
meta.context + "'");
         }
         // always nice to see the deployment with something else than internals
         new LogFacade(Microwave.class.getName())
                 .info("--------------- " + configuration.getActiveProtocol() + 
"://"
-                        + tomcat.getHost().getName() + ':' + 
configuration.getActivePort() + context);
+                        + tomcat.getHost().getName() + ':' + 
configuration.getActivePort() + meta.context);
 
         final StandardContext ctx = new StandardContext();
-        ctx.setPath(context);
-        ctx.setName(context);
+        ctx.setPath(meta.context);
+        ctx.setName(meta.context);
         try {
             ctx.setDocBase(warOrDir.getCanonicalPath());
         } catch (final IOException e) {
@@ -181,10 +193,10 @@ public class Microwave implements AutoCl
             }
         }, emptySet());
 
-        ofNullable(customizer).ifPresent(c -> c.accept(ctx));
+        ofNullable(meta.consumer).ifPresent(c -> c.accept(ctx));
 
         tomcat.getHost().addChild(ctx);
-        contexts.put(context, ctx);
+        contexts.put(meta.context, ctx);
         return this;
     }
 
@@ -1548,4 +1560,14 @@ public class Microwave implements AutoCl
         }
     }
 
+    // there to be able to stack config later on without breaking all methods
+    public static class DeploymentMeta {
+        private final String context;
+        private final Consumer<Context> consumer;
+
+        public DeploymentMeta(final String context, final Consumer<Context> 
consumer) {
+            this.context = context;
+            this.consumer = consumer;
+        }
+    }
 }


Reply via email to