tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject [26/50] tomee git commit: TOMEE-1953 adding custom web resources list in tomee embedded configuration and wiring it in its mojo
Date Sat, 03 Dec 2016 16:37:52 GMT
TOMEE-1953 adding custom web resources list in tomee embedded configuration and wiring it in
its mojo


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/fb545612
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/fb545612
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/fb545612

Branch: refs/heads/tomee-1.7.x
Commit: fb545612f726039605e2a82187b97df74f919cad
Parents: 446c578
Author: rmannibucau <rmannibucau@apache.org>
Authored: Thu Oct 6 11:29:55 2016 +0200
Committer: rmannibucau <rmannibucau@apache.org>
Committed: Thu Oct 6 11:29:55 2016 +0200

----------------------------------------------------------------------
 .../gradle/embedded/TomEEEmbeddedExtension.java |   9 ++
 .../gradle/embedded/TomEEEmbeddedTask.java      |  12 +++
 .../maven/plugins/TomEEEmbeddedMojo.java        |  11 ++
 .../maven/plugins/TomEEEmbeddedMojoTest.java    | 105 ++++++++++++++-----
 tomee/tomee-embedded/pom.xml                    |   6 ++
 .../apache/tomee/embedded/Configuration.java    |  19 ++++
 .../internal/StandardContextCustomizer.java     |  17 +++
 7 files changed, 152 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/fb545612/gradle/gradle-tomee-embedded/src/main/java/org/apache/tomee/gradle/embedded/TomEEEmbeddedExtension.java
----------------------------------------------------------------------
diff --git a/gradle/gradle-tomee-embedded/src/main/java/org/apache/tomee/gradle/embedded/TomEEEmbeddedExtension.java
b/gradle/gradle-tomee-embedded/src/main/java/org/apache/tomee/gradle/embedded/TomEEEmbeddedExtension.java
index 809667b..98ef2b0 100644
--- a/gradle/gradle-tomee-embedded/src/main/java/org/apache/tomee/gradle/embedded/TomEEEmbeddedExtension.java
+++ b/gradle/gradle-tomee-embedded/src/main/java/org/apache/tomee/gradle/embedded/TomEEEmbeddedExtension.java
@@ -60,6 +60,7 @@ public class TomEEEmbeddedExtension {
     private String inlinedTomEEXml;
     private File workDir;
     private List<File> modules;
+    private List<String> customWebResources;
     private File docBase;
     private String dir;
     private String conf;
@@ -343,4 +344,12 @@ public class TomEEEmbeddedExtension {
     public void setConf(final String conf) {
         this.conf = conf;
     }
+
+    public List<String> getCustomWebResources() {
+        return customWebResources;
+    }
+
+    public void setCustomWebResources(final List<String> customWebResources) {
+        this.customWebResources = customWebResources;
+    }
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/fb545612/gradle/gradle-tomee-embedded/src/main/java/org/apache/tomee/gradle/embedded/TomEEEmbeddedTask.java
----------------------------------------------------------------------
diff --git a/gradle/gradle-tomee-embedded/src/main/java/org/apache/tomee/gradle/embedded/TomEEEmbeddedTask.java
b/gradle/gradle-tomee-embedded/src/main/java/org/apache/tomee/gradle/embedded/TomEEEmbeddedTask.java
index b3ce50d..82c6526 100644
--- a/gradle/gradle-tomee-embedded/src/main/java/org/apache/tomee/gradle/embedded/TomEEEmbeddedTask.java
+++ b/gradle/gradle-tomee-embedded/src/main/java/org/apache/tomee/gradle/embedded/TomEEEmbeddedTask.java
@@ -126,6 +126,10 @@ public class TomEEEmbeddedTask extends DefaultTask {
 
     @Optional
     @Input
+    private Collection<String> customWebResources;
+
+    @Optional
+    @Input
     private boolean webResourceCached = true;
 
     @Optional
@@ -712,4 +716,12 @@ public class TomEEEmbeddedTask extends DefaultTask {
     public void setSingleClassloader(final boolean singleClassloader) {
         this.singleClassloader = singleClassloader;
     }
+
+    public Collection<String> getCustomWebResources() {
+        return customWebResources;
+    }
+
+    public void setCustomWebResources(final Collection<String> customWebResources)
{
+        this.customWebResources = customWebResources;
+    }
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/fb545612/maven/tomee-embedded-maven-plugin/src/main/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojo.java
----------------------------------------------------------------------
diff --git a/maven/tomee-embedded-maven-plugin/src/main/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojo.java
b/maven/tomee-embedded-maven-plugin/src/main/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojo.java
index 95038ab..da697cb 100644
--- a/maven/tomee-embedded-maven-plugin/src/main/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojo.java
+++ b/maven/tomee-embedded-maven-plugin/src/main/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojo.java
@@ -213,6 +213,12 @@ public class TomEEEmbeddedMojo extends AbstractMojo {
     protected List<File> modules;
 
     /**
+     * Additional web resources (directories).
+     */
+    @Parameter(property = "tomee-embedded-plugin.web-resources")
+    protected List<File> webResources;
+
+    /**
      * Where is docBase/web resources.
      */
     @Parameter(property = "tomee-embedded-plugin.docBase", defaultValue = "${project.basedir}/src/main/webapp")
@@ -662,6 +668,11 @@ public class TomEEEmbeddedMojo extends AbstractMojo {
             }
             config.getProperties().setProperty("tomee.force-reloadable", "true");
         }
+        if (webResources != null && !webResources.isEmpty()) {
+            for (final File f : webResources) {
+                config.addCustomWebResources(f.getAbsolutePath());
+            }
+        }
         return config;
     }
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/fb545612/maven/tomee-embedded-maven-plugin/src/test/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojoTest.java
----------------------------------------------------------------------
diff --git a/maven/tomee-embedded-maven-plugin/src/test/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojoTest.java
b/maven/tomee-embedded-maven-plugin/src/test/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojoTest.java
index 21a511a..3a51b51 100644
--- a/maven/tomee-embedded-maven-plugin/src/test/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojoTest.java
+++ b/maven/tomee-embedded-maven-plugin/src/test/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojoTest.java
@@ -40,6 +40,7 @@ import java.util.concurrent.atomic.AtomicReference;
 
 import static java.lang.System.lineSeparator;
 import static java.lang.Thread.sleep;
+import static java.util.Collections.singletonList;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -86,33 +87,7 @@ public class TomEEEmbeddedMojoTest {
             }
         });
 
-        final CountDownLatch stopped = new CountDownLatch(1);
-
-        final AtomicReference<Exception> error = new AtomicReference<>();
-        final Thread mojoThread = new Thread() {
-            {
-                setName("Mojo-Starter");
-            }
-
-            @Override
-            public void run() {
-                try {
-                    mojo.execute();
-                } catch (final Exception e) {
-                    error.set(e);
-                } finally {
-                    stopped.countDown();
-                }
-            }
-        };
-        mojoThread.start();
-        try {
-            started.await(10, TimeUnit.MINUTES);
-        } catch (final InterruptedException e) {
-            Thread.interrupted();
-        }
-
-        assertNull("all started fine", error.get());
+        final CountDownLatch stopped = doStart(started, mojo);
         assertEquals("ok", IO.slurp(new URL("http://localhost:" + mojo.httpPort + "/endpoint/")).trim());
 
         long initTs = timestamp(mojo);
@@ -156,6 +131,82 @@ public class TomEEEmbeddedMojoTest {
         input.close();
     }
 
+
+    @Test
+    public void customWebResource() throws Exception {
+        final File docBase = new File("target/TomEEEmbeddedMojoTest/customWebResource");
+        docBase.mkdirs();
+        try (final FileWriter w = new FileWriter(new File(docBase, "index.html"))) {
+            w.write("resource");
+        }
+
+        // we use a dynamic InputStream to be able to simulate commands without hacking System.in
+        final Input input = new Input();
+        final Semaphore reloaded = new Semaphore(0);
+        final CountDownLatch started = new CountDownLatch(1);
+        final TomEEEmbeddedMojo mojo = new TomEEEmbeddedMojo() {
+            @Override
+            protected Scanner newScanner() {
+                return new Scanner(input);
+            }
+        };
+        mojo.classpathAsWar = true;
+        mojo.httpPort = NetworkUtil.getNextAvailablePort();
+        mojo.ssl = false;
+        mojo.webResources = singletonList(docBase);
+        mojo.webResourceCached = false;
+        mojo.setLog(new SystemStreamLog() { // not the best solution but fine for now...
+            @Override
+            public void info(final CharSequence charSequence) {
+                final String string = charSequence.toString();
+                if (string.startsWith("TomEE embedded started on") || string.equals("can't
start TomEE")) {
+                    started.countDown();
+                } else if (string.contains("Redeployed /")) {
+                    reloaded.release();
+                }
+                super.info(charSequence);
+            }
+        });
+
+        final CountDownLatch stopped = doStart(started, mojo);
+        assertEquals("resource", IO.slurp(new URL("http://localhost:" + mojo.httpPort + "/")).trim());
+
+        input.write("exit");
+        stopped.await(5, TimeUnit.MINUTES);
+        input.close();
+    }
+
+    private CountDownLatch doStart(final CountDownLatch started, final TomEEEmbeddedMojo
mojo) {
+        final CountDownLatch stopped = new CountDownLatch(1);
+
+        final AtomicReference<Exception> error = new AtomicReference<>();
+        final Thread mojoThread = new Thread() {
+            {
+                setName("Mojo-Starter");
+            }
+
+            @Override
+            public void run() {
+                try {
+                    mojo.execute();
+                } catch (final Exception e) {
+                    error.set(e);
+                } finally {
+                    stopped.countDown();
+                }
+            }
+        };
+        mojoThread.start();
+        try {
+            started.await(10, TimeUnit.MINUTES);
+        } catch (final InterruptedException e) {
+            Thread.interrupted();
+        }
+
+        assertNull("all started fine", error.get());
+        return stopped;
+    }
+
     private long timestamp(final TomEEEmbeddedMojo mojo) throws IOException {
         return Long.parseLong(IO.slurp(new URL("http://localhost:" + mojo.httpPort + "/endpoint/timestamp")).trim());
     }

http://git-wip-us.apache.org/repos/asf/tomee/blob/fb545612/tomee/tomee-embedded/pom.xml
----------------------------------------------------------------------
diff --git a/tomee/tomee-embedded/pom.xml b/tomee/tomee-embedded/pom.xml
index 81e4cfe..99e1255 100644
--- a/tomee/tomee-embedded/pom.xml
+++ b/tomee/tomee-embedded/pom.xml
@@ -452,6 +452,12 @@
       <groupId>org.apache.tomcat</groupId>
       <artifactId>tomcat-websocket</artifactId>
       <version>${tomcat.version}</version>
+      <exclusions>
+        <exclusion>
+          <artifactId>tomcat-juli</artifactId>
+          <groupId>org.apache.tomcat</groupId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>commons-io</groupId>

http://git-wip-us.apache.org/repos/asf/tomee/blob/fb545612/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Configuration.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Configuration.java
b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Configuration.java
index e55f0cf..61f5530 100644
--- a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Configuration.java
+++ b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Configuration.java
@@ -37,6 +37,8 @@ import java.util.LinkedList;
 import java.util.Map;
 import java.util.Properties;
 
+import static java.util.Arrays.asList;
+
 /**
  * @version $Rev$ $Date$
  */
@@ -65,6 +67,7 @@ public class Configuration {
     private String webXml;
     private LoginConfigBuilder loginConfig;
     private Collection<SecurityConstaintBuilder> securityConstraints = new LinkedList<>();
+    private Collection<String> customWebResources = new LinkedList<>();
 
     private Realm realm;
 
@@ -225,6 +228,10 @@ public class Configuration {
         if (tempDir != null) {
             setTempDir(tempDir);
         }
+        final String customWebResources = config.getProperty("customWebResources");
+        if (customWebResources != null) {
+            setCustomWebResources(customWebResources);
+        }
         final String classesFilterType = config.getProperty("classesFilter");
         if (classesFilterType != null) {
             try {
@@ -611,6 +618,18 @@ public class Configuration {
         this.deleteBaseOnStartup = deleteBaseOnStartup;
     }
 
+    public void setCustomWebResources(final String web) {
+        customWebResources.addAll(asList(web.split(",")));
+    }
+
+    public void addCustomWebResources(final String web) {
+        customWebResources.add(web);
+    }
+
+    public Collection<String> getCustomWebResources() {
+        return customWebResources;
+    }
+
     public interface ConfigurationCustomizer {
         void customize(Configuration configuration);
     }

http://git-wip-us.apache.org/repos/asf/tomee/blob/fb545612/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/internal/StandardContextCustomizer.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/internal/StandardContextCustomizer.java
b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/internal/StandardContextCustomizer.java
index 3fa62a5..736a1f5 100644
--- a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/internal/StandardContextCustomizer.java
+++ b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/internal/StandardContextCustomizer.java
@@ -37,8 +37,10 @@ import org.apache.tomee.embedded.SecurityConstaintBuilder;
 
 import java.beans.PropertyChangeListener;
 import java.io.File;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.List;
+import java.util.logging.Logger;
 
 public class StandardContextCustomizer {
     private final WebModule module;
@@ -96,6 +98,21 @@ public class StandardContextCustomizer {
                         } // else endsWith .war => ignore
                     }
                 }
+                if (config.getCustomWebResources() != null) {
+                    for (final String web : config.getCustomWebResources()) {
+                        final File file = new File(web);
+                        if (file.isDirectory()) {
+                            try {
+                                resources.createWebResourceSet(WebResourceRoot.ResourceSetType.RESOURCE_JAR,
"/", file.toURI().toURL(), "/");
+                            } catch (final MalformedURLException e) {
+                                throw new IllegalArgumentException(e);
+                            }
+                        } else {
+                            Logger.getLogger(StandardContextCustomizer.class.getName())
+                                    .warning("'" + web + "' is not a directory, ignoring");
+                        }
+                    }
+                }
 
                 if (config.getLoginConfig() != null) {
                     context.setLoginConfig(config.getLoginConfig().build());


Mime
View raw message