tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: adding DeleteBaseOnStartup option to tomee embedded and ensuring properties are filtered
Date Tue, 04 Oct 2016 14:04:08 GMT
Repository: tomee
Updated Branches:
  refs/heads/master 8143fc0fd -> f86f5a355


adding DeleteBaseOnStartup option to tomee embedded and ensuring properties are filtered


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

Branch: refs/heads/master
Commit: f86f5a355d7f324df989613ee61ae501d4343ec0
Parents: 8143fc0
Author: rmannibucau <rmannibucau@apache.org>
Authored: Tue Oct 4 16:04:00 2016 +0200
Committer: rmannibucau <rmannibucau@apache.org>
Committed: Tue Oct 4 16:04:00 2016 +0200

----------------------------------------------------------------------
 .../apache/tomee/embedded/Configuration.java    | 35 ++++++++++++++++++++
 .../org/apache/tomee/embedded/Container.java    | 19 ++++++-----
 .../TomEEEmbeddedApplicationRunner.java         |  4 ++-
 .../embedded/SingleInstanceRunnerTest.java      |  7 +++-
 4 files changed, 54 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/f86f5a35/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 b74ad95..e55f0cf 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
@@ -18,6 +18,8 @@ package org.apache.tomee.embedded;
 
 import org.apache.catalina.Realm;
 import org.apache.catalina.connector.Connector;
+import org.apache.commons.lang3.text.StrLookup;
+import org.apache.commons.lang3.text.StrSubstitutor;
 import org.apache.openejb.loader.IO;
 import org.apache.openejb.util.NetworkUtil;
 import org.apache.xbean.finder.filter.Filter;
@@ -85,6 +87,7 @@ public class Configuration {
     private boolean webResourceCached = true;
 
     private String conf;
+    private boolean deleteBaseOnStartup = true;
 
     public Configuration loadFrom(final String resource) {
         try (final InputStream is = findStream(resource)) {
@@ -110,6 +113,26 @@ public class Configuration {
     }
 
     public void loadFromProperties(final Properties config) {
+        // filtering properties with system properties or themself
+        final StrSubstitutor strSubstitutor = new StrSubstitutor(new StrLookup<String>()
{
+            @Override
+            public String lookup(final String key) {
+                final String property = System.getProperty(key);
+                return property == null ? config.getProperty(key) : null;
+            }
+        });
+        for (final String key : config.stringPropertyNames()) {
+            final String val = config.getProperty(key);
+            if (val == null || val.trim().isEmpty()) {
+                continue;
+            }
+            final String newVal = strSubstitutor.replace(config.getProperty(key));
+            if (!val.equals(newVal)) {
+                config.setProperty(key, newVal);
+            }
+        }
+
+
         final String http = config.getProperty("http");
         if (http != null) {
             setHttpPort(Integer.parseInt(http));
@@ -154,6 +177,10 @@ public class Configuration {
         if (http2 != null) {
             setHttp2(Boolean.parseBoolean(http2));
         }
+        final String deleteBaseOnStartup = config.getProperty("deleteBaseOnStartup");
+        if (deleteBaseOnStartup != null) {
+            setDeleteBaseOnStartup(Boolean.parseBoolean(deleteBaseOnStartup));
+        }
         final String webResourceCached = config.getProperty("webResourceCached");
         if (webResourceCached != null) {
             setWebResourceCached(Boolean.parseBoolean(webResourceCached));
@@ -576,6 +603,14 @@ public class Configuration {
         return classesFilter;
     }
 
+    public boolean isDeleteBaseOnStartup() {
+        return deleteBaseOnStartup;
+    }
+
+    public void setDeleteBaseOnStartup(final boolean deleteBaseOnStartup) {
+        this.deleteBaseOnStartup = deleteBaseOnStartup;
+    }
+
     public interface ConfigurationCustomizer {
         void customize(Configuration configuration);
     }

http://git-wip-us.apache.org/repos/asf/tomee/blob/f86f5a35/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java
index 06b33dd..aa2d054 100644
--- a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java
+++ b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java
@@ -423,14 +423,13 @@ public class Container implements AutoCloseable {
 
         // create basic installation in setup to be able to handle anything the caller does
between setup() and start()
         base = new File(getBaseDir());
-        if (base.exists()) {
-            // TODO: get rid of Files which has its own shutdown hook which can mess up order
if started/shutdown multiple times?
+        if (base.exists() && configuration.isDeleteBaseOnStartup()) {
             Files.delete(base);
+        } else if (!base.exists()) {
+            Files.mkdirs(base);
+            Files.deleteOnExit(base);
         }
 
-        Files.mkdirs(base);
-        Files.deleteOnExit(base);
-
         final File conf = createDirectory(base, "conf");
         createDirectory(base, "lib");
         createDirectory(base, "logs");
@@ -842,10 +841,12 @@ public class Container implements AutoCloseable {
         } catch (final LifecycleException e) {
             e.printStackTrace();
         }
-        try {
-            deleteTree(base);
-        } catch (final Exception e) {
-            e.printStackTrace();
+        if (configuration.isDeleteBaseOnStartup()) {
+            try {
+                deleteTree(base);
+            } catch (final Exception e) {
+                e.printStackTrace();
+            }
         }
 
         OpenEJB.destroy();

http://git-wip-us.apache.org/repos/asf/tomee/blob/f86f5a35/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/TomEEEmbeddedApplicationRunner.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/TomEEEmbeddedApplicationRunner.java
b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/TomEEEmbeddedApplicationRunner.java
index 7f69d32..ffc4dcd 100644
--- a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/TomEEEmbeddedApplicationRunner.java
+++ b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/TomEEEmbeddedApplicationRunner.java
@@ -16,6 +16,7 @@
  */
 package org.apache.tomee.embedded;
 
+import org.apache.commons.lang3.text.StrSubstitutor;
 import org.apache.openejb.config.DeploymentsResolver;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.testing.Application;
@@ -147,9 +148,10 @@ public class TomEEEmbeddedApplicationRunner implements AutoCloseable
{
             for (final ContainerProperties.Property p : props.value()) {
                 final String name = p.name();
                 if (name.startsWith("tomee.embedded.application.runner.")) { // allow to
tune the Configuration
+                    // no need to filter there since it is done in loadFromProperties()
                     runnerProperties.setProperty(name.substring("tomee.embedded.application.runner.".length()),
p.value());
                 } else {
-                    configuration.property(name, p.value());
+                    configuration.property(name, StrSubstitutor.replaceSystemProperties(p.value()));
                 }
             }
             if (!runnerProperties.isEmpty()) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/f86f5a35/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/SingleInstanceRunnerTest.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/SingleInstanceRunnerTest.java
b/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/SingleInstanceRunnerTest.java
index 8bb73e7..7435205 100644
--- a/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/SingleInstanceRunnerTest.java
+++ b/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/SingleInstanceRunnerTest.java
@@ -53,6 +53,7 @@ public class SingleInstanceRunnerTest {
     @Test
     public void run() {
         assertNotNull(SystemInstance.get().getComponent(Assembler.class));
+        assertEquals("val", SystemInstance.get().getProperty("simple"));
         assertEquals("set", SystemInstance.get().getProperty("t"));
         assertEquals("p", SystemInstance.get().getProperty("prog"));
         assertEquals("128463", SystemInstance.get().getProperty("my.server.port"));
@@ -70,7 +71,11 @@ public class SingleInstanceRunnerTest {
 
     @Application
     @Classes(context = "app")
-    @ContainerProperties(@ContainerProperties.Property(name = "t", value = "set"))
+    @ContainerProperties({
+            @ContainerProperties.Property(name = "simple", value = "val"),
+            @ContainerProperties.Property(name = "tomee.embedded.application.runner.properties.t",
value = "${t.value}"),
+            @ContainerProperties.Property(name = "tomee.embedded.application.runner.t.value",
value = "set")
+    })
     @TomEEEmbeddedApplicationRunner.LifecycleTasks(MyTask.class)
     // can start a ftp/sftp/elasticsearch/mongo/... server before tomee
     @TomEEEmbeddedApplicationRunner.Configurers(SetMyProperty.class)


Mime
View raw message