This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit d21a5100befbd745e1d1f4b738e7a9a059f7b5ac
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Mon Jun 17 12:56:23 2019 +0200

    CAMEL-13647: Allow to do autowrire by classpath.
---
 .../java/org/apache/camel/maven/AutowireMojo.java  | 27 +++++++++++++++++++++-
 .../main/resources/camel-main-mappings.properties  | 23 ++++++++++++++++++
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git 
a/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/AutowireMojo.java
 
b/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/AutowireMojo.java
index a05e5b6..6a1b647 100644
--- 
a/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/AutowireMojo.java
+++ 
b/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/AutowireMojo.java
@@ -17,6 +17,7 @@
 package org.apache.camel.maven;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -115,6 +116,12 @@ public class AutowireMojo extends AbstractExecMojo {
     @Parameter(property = "camel.mappings")
     protected String[] mappings;
 
+    /**
+     * Optional mappings file loaded from classpath, with mapping that 
override any default mappings
+     */
+    @Parameter(defaultValue = 
"${project.build.directory}/classes/camel-main-mappings.properties")
+    protected File mappingsFile;
+
     @Component
     private ArtifactFactory artifactFactory;
 
@@ -197,10 +204,15 @@ public class AutowireMojo extends AbstractExecMojo {
                 String value = StringHelper.after(m, "=");
                 if (key != null && value != null) {
                     mappingProperties.setProperty(key, value);
-                    getLog().debug("Added mapping: " + key + "=" + value);
+                    getLog().debug("Added mapping from pom.xml: " + key + "=" 
+ value);
                 }
             }
         }
+        Properties mappingFileProperties = loadMappingsFile();
+        if (!mappingFileProperties.isEmpty()) {
+            getLog().debug("Loaded mappings file: " + mappingsFile + " with 
mappings: " + mappingFileProperties);
+            mappingProperties.putAll(mappingFileProperties);
+        }
 
         // find the autowire via classpath scanning
         List<String> autowires = 
findAutowireComponentOptionsByClasspath(catalog, components, reflections, 
mappingProperties);
@@ -236,6 +248,19 @@ public class AutowireMojo extends AbstractExecMojo {
         return mappings;
     }
 
+    protected Properties loadMappingsFile() throws MojoFailureException {
+        Properties mappings = new OrderedProperties();
+        if (mappingsFile.exists() && mappingsFile.isFile()) {
+            try {
+                InputStream is = new FileInputStream(mappingsFile);
+                mappings.load(is);
+            } catch (IOException e) {
+                throw new MojoFailureException("Cannot load file: " + 
mappingsFile);
+            }
+        }
+        return mappings;
+    }
+
     protected List<String> 
findAutowireComponentOptionsByClasspath(CamelCatalog catalog, Set<String> 
components,
                                                                    Reflections 
reflections, Properties mappingProperties) {
         List<String> autowires = new ArrayList<>();
diff --git 
a/examples/camel-example-main-artemis/src/main/resources/camel-main-mappings.properties
 
b/examples/camel-example-main-artemis/src/main/resources/camel-main-mappings.properties
new file mode 100644
index 0000000..de62320
--- /dev/null
+++ 
b/examples/camel-example-main-artemis/src/main/resources/camel-main-mappings.properties
@@ -0,0 +1,23 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements.  See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License.  You may obtain a copy of the License at
+##
+##      http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+
+## this file allows end users to also define and override the default mappings
+## what you can configure here is the same as you can do in the pom.xml file in
+## the camel-main-maven-plugin configuration section: 
<configuration><mappings>...</mappings></configuration>
+
+# for example to use Spring's CachingConnectionFactory you can specify
+###javax.jms.ConnectionFactory=org.springframework.jms.connection.CachingConnectionFactory
\ No newline at end of file

Reply via email to