Repository: tomee
Updated Branches:
  refs/heads/master 72fd11890 -> 0189b8403


support a file path to load tomee embedded configuration


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

Branch: refs/heads/master
Commit: 0189b840318bc1f0dc715621d56fcf0522b2e0b9
Parents: 72fd118
Author: rmannibucau <rmannibu...@apache.org>
Authored: Thu Sep 29 19:27:25 2016 +0200
Committer: rmannibucau <rmannibu...@apache.org>
Committed: Thu Sep 29 19:27:25 2016 +0200

----------------------------------------------------------------------
 .../embedded/EmbeddedTomEEContainer.java        |  2 +-
 .../apache/tomee/embedded/Configuration.java    | 22 +++++++++++++++-----
 .../java/org/apache/tomee/embedded/FatApp.java  |  2 +-
 .../java/org/apache/tomee/embedded/Main.java    |  8 +++----
 4 files changed, 23 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/0189b840/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java
----------------------------------------------------------------------
diff --git 
a/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java
 
b/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java
index 4c172c7..761bcbc 100644
--- 
a/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java
+++ 
b/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java
@@ -102,7 +102,7 @@ public class EmbeddedTomEEContainer extends 
TomEEContainer<EmbeddedTomEEConfigur
         
configuration.setWebResourceCached(tomeeConfiguration.isWebResourcesCached());
 
         if (tomeeConfiguration.getClasspathConfiguration() != null) {
-            
configuration.loadFromClasspath(tomeeConfiguration.getClasspathConfiguration());
+            
configuration.loadFrom(tomeeConfiguration.getClasspathConfiguration());
         }
 
         if (tomeeConfiguration.getConfigurationCustomizers() != null) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/0189b840/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 9c463eb..b74ad95 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
@@ -24,6 +24,8 @@ import org.apache.xbean.finder.filter.Filter;
 import org.apache.xbean.recipe.ObjectRecipe;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
@@ -84,11 +86,8 @@ public class Configuration {
 
     private String conf;
 
-    public Configuration loadFromClasspath(final String resource) {
-        try (final InputStream is = 
Thread.currentThread().getContextClassLoader().getResourceAsStream(resource)) {
-            if (is == null) {
-                throw new IllegalArgumentException(resource + " not found");
-            }
+    public Configuration loadFrom(final String resource) {
+        try (final InputStream is = findStream(resource)) {
             final Properties config = IO.readProperties(is, new Properties());
             loadFromProperties(config);
             return this;
@@ -97,6 +96,19 @@ public class Configuration {
         }
     }
 
+    private InputStream findStream(final String resource) throws 
FileNotFoundException {
+        InputStream stream = 
Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
+        if (stream == null) {
+            final File file = new File(resource);
+            if (file.exists()) {
+                return new FileInputStream(file);
+            } else {
+                throw new IllegalArgumentException("Didn't find: " + resource);
+            }
+        }
+        return stream;
+    }
+
     public void loadFromProperties(final Properties config) {
         final String http = config.getProperty("http");
         if (http != null) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/0189b840/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/FatApp.java
----------------------------------------------------------------------
diff --git 
a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/FatApp.java 
b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/FatApp.java
index 8a3f227..2d5cf4d 100644
--- a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/FatApp.java
+++ b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/FatApp.java
@@ -38,7 +38,7 @@ public final class FatApp {
             a.add("--single-classloader");
         }
         if 
(Thread.currentThread().getContextClassLoader().getResource("tomee-embedded.properties")
 != null) { // automatic
-            a.add("--classpath-configuration=tomee-embedded.properties");
+            a.add("--configuration-location=tomee-embedded.properties");
         }
         Main.main(a.toArray(new String[a.size()]));
     }

http://git-wip-us.apache.org/repos/asf/tomee/blob/0189b840/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java
----------------------------------------------------------------------
diff --git 
a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java 
b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java
index ab48183..dcb670e 100644
--- a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java
+++ b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java
@@ -74,7 +74,7 @@ public class Main {
     public static final String SIMPLE_LOG = "simple-log";
     public static final String PRE_TASK = "pre-task";
     public static final String INTERACTIVE = "interactive";
-    public static final String CLASSPATH_CONFIGURATION = 
"classpath-configuration";
+    public static final String CONFIGURATION = "configuration-location";
     public static final String CLASSES_FILTER = "classes-filter";
     public static final String HELP = "help";
 
@@ -259,7 +259,7 @@ public class Main {
         options.addOption(null, BASIC, true, "basic authentication if set");
         options.addOption(null, SIMPLE_LOG, false, "should tomee use simple 
log format (level - message) - demo intended");
         options.addOption("i", INTERACTIVE, false, "should tomee start and 
wait for SIGTERM signal or wait for 'exit' to be entered");
-        options.addOption(null, CLASSPATH_CONFIGURATION, true, "a properties 
file containing the configuration to load");
+        options.addOption(null, CONFIGURATION, true, "a properties file 
containing the configuration to load");
         options.addOption(null, SINGLE_CLASSLOADER, false, "if the application 
should use the same classloader as the boot one");
         options.addOption(null, CLASSES_FILTER, true, "A custom implementation 
of a xbean filter to exclude classes to not scan");
         options.addOption("h", HELP, false, "show help");
@@ -268,8 +268,8 @@ public class Main {
 
     private static Configuration createConfiguration(final CommandLine args) {
         final Configuration config = new Configuration();
-        if (args.hasOption(CLASSPATH_CONFIGURATION)) {
-            
config.loadFromClasspath(args.getOptionValue(CLASSPATH_CONFIGURATION));
+        if (args.hasOption(CONFIGURATION)) {
+            config.loadFrom(args.getOptionValue(CONFIGURATION));
         }
         config.setHttpPort(Integer.parseInt(args.getOptionValue(PORT, 
Integer.toString(config.getHttpPort()))));
         config.setStopPort(Integer.parseInt(args.getOptionValue(SHUTDOWN, 
Integer.toString(config.getHttpsPort()))));

Reply via email to