CAMEL-7038: Provide an option for the JNDI properties file by the Guice Maven 
Plugin.

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

Branch: refs/heads/camel-gora
Commit: 4ca362155eaced0453c1220affb86d896037ebb1
Parents: ae1a956
Author: Babak Vahdat <bvah...@apache.org>
Authored: Wed Dec 4 13:18:04 2013 +0100
Committer: Babak Vahdat <bvah...@apache.org>
Committed: Wed Dec 4 13:18:04 2013 +0100

----------------------------------------------------------------------
 .../main/java/org/apache/camel/guice/Main.java  | 11 ++++++++--
 examples/camel-example-guice-jms/README.txt     |  6 +++++
 examples/camel-example-guice-jms/pom.xml        | 11 ++++++++++
 .../apache/camel/guice/maven/EmbeddedMojo.java  | 23 ++++++++++++++++++++
 .../org/apache/camel/guice/maven/RunMojo.java   | 14 ++++++++++++
 5 files changed, 63 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/4ca36215/components/camel-guice/src/main/java/org/apache/camel/guice/Main.java
----------------------------------------------------------------------
diff --git 
a/components/camel-guice/src/main/java/org/apache/camel/guice/Main.java 
b/components/camel-guice/src/main/java/org/apache/camel/guice/Main.java
index 76af353..1d6d375 100644
--- a/components/camel-guice/src/main/java/org/apache/camel/guice/Main.java
+++ b/components/camel-guice/src/main/java/org/apache/camel/guice/Main.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.guice;
 
+import java.io.BufferedInputStream;
 import java.net.URL;
 import java.util.LinkedList;
 import java.util.Map;
@@ -32,12 +33,12 @@ import com.google.common.collect.Maps;
 import com.google.inject.Binding;
 import com.google.inject.Injector;
 import com.google.inject.Key;
-
 import org.apache.camel.CamelContext;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.guice.inject.Injectors;
 import org.apache.camel.main.MainSupport;
 import org.apache.camel.model.Constants;
+import org.apache.camel.util.IOHelper;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.view.ModelFileGenerator;
 
@@ -107,7 +108,13 @@ public class Main extends MainSupport {
         }
         if (jndiPropertiesUrl != null) {
             Properties properties = new Properties();
-            properties.load(jndiPropertiesUrl.openStream());
+            BufferedInputStream bis = null;
+            try {
+                bis = IOHelper.buffered(jndiPropertiesUrl.openStream());
+                properties.load(bis);
+            } finally {
+                IOHelper.close(bis);
+            }
             context = new InitialContext(properties);
         } else {
             context = new InitialContext();

http://git-wip-us.apache.org/repos/asf/camel/blob/4ca36215/examples/camel-example-guice-jms/README.txt
----------------------------------------------------------------------
diff --git a/examples/camel-example-guice-jms/README.txt 
b/examples/camel-example-guice-jms/README.txt
index b6228ca..fb378f3 100644
--- a/examples/camel-example-guice-jms/README.txt
+++ b/examples/camel-example-guice-jms/README.txt
@@ -13,6 +13,12 @@ You will need to compile this example first:
 To run the example type
   mvn exec:java
 
+Alternatively to run the example you can also make use of the Guice Maven
+Plugin provided by Camel, so you can instead type
+  mvn guice:run
+
+See the POM of this example about how to make use of this Maven Plugin
+
 You can see the routing rules by looking at the java code in the
 src/main/java directory and the guicejndi.properties file lives in
 src/main/resources/guicejndi.properties

http://git-wip-us.apache.org/repos/asf/camel/blob/4ca36215/examples/camel-example-guice-jms/pom.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-guice-jms/pom.xml 
b/examples/camel-example-guice-jms/pom.xml
index 20c00da..7342686 100644
--- a/examples/camel-example-guice-jms/pom.xml
+++ b/examples/camel-example-guice-jms/pom.xml
@@ -128,6 +128,17 @@
                     </arguments>
                 </configuration>
             </plugin>
+
+            <!-- Allows the example to be run via 'mvn guice:run' -->
+            <plugin>
+                <groupId>org.apache.camel</groupId>
+                <artifactId>guice-maven-plugin</artifactId>
+                <version>${project.version}</version>
+                <configuration>
+                    <duration>5s</duration>
+                    <jndiProperties>/guicejndi.properties</jndiProperties>
+              </configuration>
+            </plugin>        
         </plugins>
 
     </build>

http://git-wip-us.apache.org/repos/asf/camel/blob/4ca36215/tooling/maven/guice-maven-plugin/src/main/java/org/apache/camel/guice/maven/EmbeddedMojo.java
----------------------------------------------------------------------
diff --git 
a/tooling/maven/guice-maven-plugin/src/main/java/org/apache/camel/guice/maven/EmbeddedMojo.java
 
b/tooling/maven/guice-maven-plugin/src/main/java/org/apache/camel/guice/maven/EmbeddedMojo.java
index ced1a95..a120f9a 100644
--- 
a/tooling/maven/guice-maven-plugin/src/main/java/org/apache/camel/guice/maven/EmbeddedMojo.java
+++ 
b/tooling/maven/guice-maven-plugin/src/main/java/org/apache/camel/guice/maven/EmbeddedMojo.java
@@ -75,6 +75,16 @@ public class EmbeddedMojo extends AbstractExecMojo {
     protected boolean dotAggregationEnabled;
 
     /**
+     * Allows to provide a custom properties file to initialize a
+     * {@link javax.naming.InitialContext} object with. As an exmaple this
+     * argument can be be passed when making use of the GuiceyFruit JNDI
+     * Provider
+     * 
+     * @parameter property="jndiProperties"
+     */
+    protected String jndiProperties;
+
+    /**
      * Project classpath.
      *
      * @parameter property="project.testClasspathElements"
@@ -176,6 +186,14 @@ public class EmbeddedMojo extends AbstractExecMojo {
         this.mainClass = mainClass;
     }
 
+    public String getJndiProperties() {
+        return jndiProperties;
+    }
+
+    public void setJndiProperties(String jndiProperties) {
+        this.jndiProperties = jndiProperties;
+    }
+
     // Implementation methods
     //-------------------------------------------------------------------------
 
@@ -212,6 +230,11 @@ public class EmbeddedMojo extends AbstractExecMojo {
         args.add("-duration");
         args.add(getDuration());
 
+        if (getJndiProperties() != null) {
+            args.add("-j");
+            args.add(getJndiProperties());
+        }
+
         return args.toArray(new String[0]);
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/4ca36215/tooling/maven/guice-maven-plugin/src/main/java/org/apache/camel/guice/maven/RunMojo.java
----------------------------------------------------------------------
diff --git 
a/tooling/maven/guice-maven-plugin/src/main/java/org/apache/camel/guice/maven/RunMojo.java
 
b/tooling/maven/guice-maven-plugin/src/main/java/org/apache/camel/guice/maven/RunMojo.java
index 2b3d83c..eae01f0 100644
--- 
a/tooling/maven/guice-maven-plugin/src/main/java/org/apache/camel/guice/maven/RunMojo.java
+++ 
b/tooling/maven/guice-maven-plugin/src/main/java/org/apache/camel/guice/maven/RunMojo.java
@@ -108,6 +108,16 @@ public class RunMojo extends AbstractExecMojo {
     protected boolean dotEnabled;
 
     /**
+     * Allows to provide a custom properties file to initialize a
+     * {@link javax.naming.InitialContext} object with. As an exmaple this
+     * argument can be be passed when making use of the GuiceyFruit JNDI
+     * Provider
+     * 
+     * @parameter property="jndiProperties"
+     */
+    protected String jndiProperties;
+
+    /**
      * @component
      */
     private ArtifactResolver artifactResolver;
@@ -328,6 +338,10 @@ public class RunMojo extends AbstractExecMojo {
             args.add("-o");
             args.add(dotDir);
         }
+        if (jndiProperties != null) {
+            args.add("-j");
+            args.add(jndiProperties);
+        }
         if (debug) {
             args.add("-x");
         }

Reply via email to