Repository: camel
Updated Branches:
  refs/heads/master f2fa80268 -> 8081351ff


CAMEL-7999: apt compiler to generate json schema documentation for the model, 
whcih we later use to enrich the xml xsd to include documentation. Work in 
progress.


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

Branch: refs/heads/master
Commit: f93e1d54a63f3459e3999dac03fdbe3a9956d480
Parents: f2fa802
Author: Claus Ibsen <davscl...@apache.org>
Authored: Wed Dec 31 13:49:37 2014 +0100
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Wed Dec 31 15:10:21 2014 +0100

----------------------------------------------------------------------
 camel-core/pom.xml                              |   8 ++
 .../java/org/apache/camel/CamelContext.java     |   9 ++
 .../management/mbean/CamelOpenMBeanTypes.java   |  11 ++
 .../mbean/ManagedCamelContextMBean.java         |  27 ++++
 .../apache/camel/impl/DefaultCamelContext.java  |   4 +
 .../management/mbean/ManagedCamelContext.java   |  42 ++++++
 .../apache/camel/util/CamelContextHelper.java   |  99 +++++++++++++-
 .../management/ManagedCamelContextTest.java     |  69 ++++++++++
 .../camel/maven/packaging/PackageHelper.java    |  51 +++++++
 .../camel/maven/packaging/PackageModelMojo.java | 134 +++++++++++++++++++
 .../camel/maven/packaging/PackageMojo.java      |   2 +-
 .../maven/packaging/PrepareCatalogMojo.java     |  25 +---
 12 files changed, 455 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f93e1d54/camel-core/pom.xml
----------------------------------------------------------------------
diff --git a/camel-core/pom.xml b/camel-core/pom.xml
index b6328e0..7a3b86b 100644
--- a/camel-core/pom.xml
+++ b/camel-core/pom.xml
@@ -278,11 +278,19 @@
         <version>${project.version}</version>
         <executions>
           <execution>
+            <id>components</id>
             <goals>
               <goal>generate-components-list</goal>
             </goals>
             <phase>generate-resources</phase>
           </execution>
+          <execution>
+            <id>eips</id>
+            <goals>
+              <goal>generate-eips-list</goal>
+            </goals>
+            <phase>process-classes</phase>
+          </execution>
         </executions>
       </plugin>
     </plugins>

http://git-wip-us.apache.org/repos/asf/camel/blob/f93e1d54/camel-core/src/main/java/org/apache/camel/CamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/CamelContext.java 
b/camel-core/src/main/java/org/apache/camel/CamelContext.java
index 830a625..0141473 100644
--- a/camel-core/src/main/java/org/apache/camel/CamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java
@@ -1386,6 +1386,15 @@ public interface CamelContext extends 
SuspendableService, RuntimeConfiguration {
     Map<String, Properties> findComponents() throws LoadPropertiesException, 
IOException;
 
     /**
+     * Find information about all the EIPs from camel-core.
+     *
+     * @return a map with node id, and value with EIP details.
+     * @throws LoadPropertiesException is thrown if error during classpath 
discovery of the EIPs
+     * @throws IOException is thrown if error during classpath discovery of 
the EIPs
+     */
+    Map<String, Properties> findEips() throws LoadPropertiesException, 
IOException;
+
+    /**
      * Returns the HTML documentation for the given Camel component
      *
      * @return the HTML or <tt>null</tt> if the component is <b>not</b> built 
with HTML document included.

http://git-wip-us.apache.org/repos/asf/camel/blob/f93e1d54/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
 
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
index bfb346d..5d1fa41 100644
--- 
a/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
+++ 
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
@@ -110,4 +110,15 @@ public final class CamelOpenMBeanTypes {
                 new OpenType[]{SimpleType.STRING, SimpleType.STRING, 
SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING});
     }
 
+    public static TabularType listEipsTabularType() throws OpenDataException {
+        CompositeType ct = listEipsCompositeType();
+        return new TabularType("listEips", "Lists all the EIPs", ct, new 
String[]{"name"});
+    }
+
+    public static CompositeType listEipsCompositeType() throws 
OpenDataException {
+        return new CompositeType("eips", "EIPs", new String[]{"name", 
"description", "label", "status", "type"},
+                new String[]{"Name", "Description", "Label", "Status", "Type"},
+                new OpenType[]{SimpleType.STRING, SimpleType.STRING, 
SimpleType.STRING, SimpleType.STRING, SimpleType.STRING});
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/f93e1d54/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
 
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
index fd2ebbb..fc9cf6e 100644
--- 
a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
+++ 
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
@@ -214,6 +214,24 @@ public interface ManagedCamelContextMBean extends 
ManagedPerformanceCounterMBean
     Map<String, Properties> findComponents() throws Exception;
 
     /**
+     * Find information about all the EIPs from camel-core.
+     *
+     * @return a map with node id, and value with EIP details.
+     * @throws Exception is thrown if error occurred
+     */
+    @ManagedOperation(description = "Find all Camel EIPs from camel-core")
+    Map<String, Properties> findEips() throws Exception;
+
+    /**
+     * Find the names of all the EIPs from camel-core.
+     *
+     * @return a list with the names of the camel EIPs
+     * @throws Exception is thrown if error occurred
+     */
+    @ManagedOperation(description = "Find all Camel EIP names from camel-core")
+    List<String> findEipNames() throws Exception;
+
+    /**
      * Find the names of all the Camel components available in the classpath 
and {@link org.apache.camel.spi.Registry}.
      *
      * @return a list with the names of the camel components
@@ -232,6 +250,15 @@ public interface ManagedCamelContextMBean extends 
ManagedPerformanceCounterMBean
     TabularData listComponents() throws Exception;
 
     /**
+     * Find information about all the EIPs from camel-core.
+     *
+     * @return a list with the data
+     * @throws Exception is thrown if error occurred
+     */
+    @ManagedOperation(description = "List all Camel EIPs from camel-core")
+    TabularData listEips() throws Exception;
+
+    /**
      * Returns the JSON schema representation with information about the 
component and the endpoint parameters it supports
      *
      * @param componentName the name of the component to lookup

http://git-wip-us.apache.org/repos/asf/camel/blob/f93e1d54/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java 
b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index f9c8bca..89d66b8 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -1133,6 +1133,10 @@ public class DefaultCamelContext extends ServiceSupport 
implements ModelCamelCon
         return CamelContextHelper.findComponents(this);
     }
 
+    public Map<String, Properties> findEips() throws LoadPropertiesException, 
IOException {
+        return CamelContextHelper.findEips(this);
+    }
+
     public String getComponentDocumentation(String componentName) throws 
IOException {
         String packageName = sanitizeComponentName(componentName);
         String path = CamelContextHelper.COMPONENT_DOCUMENTATION_PREFIX + 
packageName + "/" + componentName + ".html";

http://git-wip-us.apache.org/repos/asf/camel/blob/f93e1d54/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
 
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
index 7ebaeb0..191a567 100644
--- 
a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
+++ 
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
@@ -57,6 +57,7 @@ import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.model.RoutesDefinition;
 import org.apache.camel.model.rest.RestDefinition;
 import org.apache.camel.model.rest.RestsDefinition;
+import org.apache.camel.util.CamelContextHelper;
 import org.apache.camel.util.JsonSchemaHelper;
 import org.apache.camel.util.ObjectHelper;
 
@@ -456,6 +457,47 @@ public class ManagedCamelContext extends 
ManagedPerformanceCounter implements Ti
         return removed.size();
     }
 
+    public Map<String, Properties> findEips() throws Exception {
+        Map<String, Properties> answer = context.findEips();
+        for (Map.Entry<String, Properties> entry : answer.entrySet()) {
+            if (entry.getValue() != null) {
+                // remove model as its not serializable over JMX
+                entry.getValue().remove("model");
+            }
+        }
+        return answer;
+    }
+
+    public List<String> findEipNames() throws Exception {
+        Map<String, Properties> map = findEips();
+        return new ArrayList<String>(map.keySet());
+    }
+
+    public TabularData listEips() throws Exception {
+        try {
+            // find all EIPs
+            Map<String, Properties> eips = context.findEips();
+
+            TabularData answer = new 
TabularDataSupport(CamelOpenMBeanTypes.listEipsTabularType());
+
+            // gather EIP detail for each eip
+            for (Map.Entry<String, Properties> entry : eips.entrySet()) {
+                String name = entry.getKey();
+                String description = (String) 
entry.getValue().get("description");
+                String label = (String) entry.getValue().get("label");
+                String type = (String) entry.getValue().get("class");
+                String status = CamelContextHelper.isEipInUse(context, name) ? 
"in use" : "on classpath";
+                CompositeType ct = CamelOpenMBeanTypes.listEipsCompositeType();
+                CompositeData data = new CompositeDataSupport(ct, new 
String[]{"name", "description", "label", "status", "type"},
+                        new Object[]{name, description, label, status, type});
+                answer.put(data);
+            }
+            return answer;
+        } catch (Exception e) {
+            throw ObjectHelper.wrapRuntimeCamelException(e);
+        }
+    }
+
     public Map<String, Properties> findComponents() throws Exception {
         Map<String, Properties> answer = context.findComponents();
         for (Map.Entry<String, Properties> entry : answer.entrySet()) {

http://git-wip-us.apache.org/repos/asf/camel/blob/f93e1d54/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java 
b/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
index 06e0d6f..ce1432c 100644
--- a/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 import java.util.Enumeration;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -36,6 +37,10 @@ import org.apache.camel.Exchange;
 import org.apache.camel.NoSuchBeanException;
 import org.apache.camel.NoSuchEndpointException;
 import org.apache.camel.component.properties.PropertiesComponent;
+import org.apache.camel.model.FromDefinition;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.ProcessorDefinitionHelper;
+import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.spi.ClassResolver;
 import org.apache.camel.spi.RouteStartupOrder;
 import org.slf4j.Logger;
@@ -54,6 +59,7 @@ public final class CamelContextHelper {
     public static final String COMPONENT_BASE = 
"META-INF/services/org/apache/camel/component/";
     public static final String COMPONENT_DESCRIPTOR = 
"META-INF/services/org/apache/camel/component.properties";
     public static final String COMPONENT_DOCUMENTATION_PREFIX = 
"org/apache/camel/component/";
+    public static final String MODEL_DESCRIPTOR = 
"META-INF/services/org/apache/camel/model.properties";
     public static final String MODEL_DOCUMENTATION_PREFIX = 
"org/apache/camel/model/";
 
     private static final Logger LOG = 
LoggerFactory.getLogger(CamelContextHelper.class);
@@ -453,7 +459,7 @@ public final class CamelContextHelper {
                 Component component = entry.getValue();
                 if (component != null) {
                     Properties properties = new Properties();
-                    properties.put("component", name);
+                    properties.put("component", component);
                     properties.put("class", component.getClass().getName());
                     properties.put("name", name);
                     map.put(name, properties);
@@ -464,6 +470,73 @@ public final class CamelContextHelper {
     }
 
     /**
+     * Find information about all the EIPs from camel-core.
+     */
+    public static SortedMap<String, Properties> findEips(CamelContext 
camelContext) throws LoadPropertiesException {
+        SortedMap<String, Properties> answer = new TreeMap<String, 
Properties>();
+
+        ClassResolver resolver = camelContext.getClassResolver();
+        LOG.debug("Finding all EIPs using class resolver: {} -> {}", new 
Object[]{resolver});
+        URL url = resolver.loadResourceAsURL(MODEL_DESCRIPTOR);
+        if (url != null) {
+            InputStream is = null;
+            try {
+                is = url.openStream();
+                String all = IOHelper.loadText(is);
+                String[] lines = all.split("\n");
+                for (String line : lines) {
+                    if (line.startsWith("#")) {
+                        continue;
+                    }
+
+                    Properties prop = new Properties();
+                    prop.put("name", line);
+
+                    String description = null;
+                    String label = null;
+                    String javaType = null;
+
+                    // enrich with more meta-data
+                    String json = camelContext.explainEipJson(line, false);
+                    if (json != null) {
+                        List<Map<String, String>> rows = 
JsonSchemaHelper.parseJsonSchema("model", json, false);
+
+                        for (Map<String, String> row : rows) {
+                            if (row.get("description") != null) {
+                                description = row.get("description");
+                            }
+                            if (row.get("label") != null) {
+                                label = row.get("label");
+                            }
+                            if (row.get("javaType") != null) {
+                                javaType = row.get("javaType");
+                            }
+                        }
+                    }
+
+                    if (description != null) {
+                        prop.put("description", description);
+                    }
+                    if (label != null) {
+                        prop.put("label", label);
+                    }
+                    if (javaType != null) {
+                        prop.put("class", javaType);
+                    }
+
+                    answer.put(line, prop);
+                }
+            } catch (IOException e) {
+                throw new LoadPropertiesException(url, e);
+            } finally {
+                IOHelper.close(is);
+            }
+        }
+
+        return answer;
+    }
+
+    /**
      * Gets the route startup order for the given route id
      *
      * @param camelContext  the camel context
@@ -504,5 +577,29 @@ public final class CamelContextHelper {
         return answer;
     }
 
+    /**
+     * Checks if any of the Camel routes is using an EIP with the given name
+     *
+     * @param camelContext  the Camel context
+     * @param name          the name of the EIP
+     * @return <tt>true</tt> if in use, <tt>false</tt> if not
+     */
+    public static boolean isEipInUse(CamelContext camelContext, String name) {
+        for (RouteDefinition route : camelContext.getRouteDefinitions()) {
+            for (FromDefinition from : route.getInputs()) {
+                if (name.equals(from.getShortName())) {
+                    return true;
+                }
+            }
+            Iterator<ProcessorDefinition> it = 
ProcessorDefinitionHelper.filterTypeInOutputs(route.getOutputs(), 
ProcessorDefinition.class);
+            while (it.hasNext()) {
+                ProcessorDefinition def = it.next();
+                if (name.equals(def.getShortName())) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/f93e1d54/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
 
b/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
index 57c444e..dd69908 100644
--- 
a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
+++ 
b/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
@@ -17,15 +17,18 @@
 package org.apache.camel.management;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
+import javax.management.openmbean.TabularData;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.util.StringHelper;
+import org.junit.Ignore;
 
 /**
  * @version 
@@ -209,6 +212,72 @@ public class ManagedCamelContextTest extends 
ManagementTestSupport {
         assertEquals("camel-core", prop.get("artifactId"));
     }
 
+    @Ignore("need to be tested outside camel-core")
+    public void testFindEipNames() throws Exception {
+        // JMX tests dont work well on AIX CI servers (hangs them)
+        if (isPlatform("aix")) {
+            return;
+        }
+
+        MBeanServer mbeanServer = getMBeanServer();
+
+        ObjectName on = 
ObjectName.getInstance("org.apache.camel:context=19-camel-1,type=context,name=\"camel-1\"");
+
+        assertTrue("Should be registered", mbeanServer.isRegistered(on));
+
+        @SuppressWarnings("unchecked")
+        List<String> info = (List<String>) mbeanServer.invoke(on, 
"findEipNames", null, null);
+        assertNotNull(info);
+
+        assertEquals(152, info.size());
+        assertTrue(info.contains("transform"));
+        assertTrue(info.contains("split"));
+        assertTrue(info.contains("from"));
+    }
+
+    @Ignore("need to be tested outside camel-core")
+    public void testFindEips() throws Exception {
+        // JMX tests dont work well on AIX CI servers (hangs them)
+        if (isPlatform("aix")) {
+            return;
+        }
+
+        MBeanServer mbeanServer = getMBeanServer();
+
+        ObjectName on = 
ObjectName.getInstance("org.apache.camel:context=19-camel-1,type=context,name=\"camel-1\"");
+
+        assertTrue("Should be registered", mbeanServer.isRegistered(on));
+
+        @SuppressWarnings("unchecked")
+        Map<String, Properties> info = (Map<String, Properties>) 
mbeanServer.invoke(on, "findEips", null, null);
+        assertNotNull(info);
+
+        assertEquals(152, info.size());
+        Properties prop = info.get("transform");
+        assertNotNull(prop);
+        assertEquals("transform", prop.get("name"));
+        assertEquals("org.apache.camel.model.TransformDefinition", 
prop.get("class"));
+    }
+
+    @Ignore("need to be tested outside camel-core")
+    public void testListEips() throws Exception {
+        // JMX tests dont work well on AIX CI servers (hangs them)
+        if (isPlatform("aix")) {
+            return;
+        }
+
+        MBeanServer mbeanServer = getMBeanServer();
+
+        ObjectName on = 
ObjectName.getInstance("org.apache.camel:context=19-camel-1,type=context,name=\"camel-1\"");
+
+        assertTrue("Should be registered", mbeanServer.isRegistered(on));
+
+        @SuppressWarnings("unchecked")
+        TabularData data = (TabularData) mbeanServer.invoke(on, "listEips", 
null, null);
+        assertNotNull(data);
+        assertEquals(152, data.size());
+    }
+
     public void testManagedCamelContextCreateRouteStaticEndpointJson() throws 
Exception {
         // JMX tests dont work well on AIX CI servers (hangs them)
         if (isPlatform("aix")) {

http://git-wip-us.apache.org/repos/asf/camel/blob/f93e1d54/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageHelper.java
----------------------------------------------------------------------
diff --git 
a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageHelper.java
 
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageHelper.java
new file mode 100644
index 0000000..9e9abdf
--- /dev/null
+++ 
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageHelper.java
@@ -0,0 +1,51 @@
+/**
+ * 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.
+ */
+package org.apache.camel.maven.packaging;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.util.Set;
+
+public final class PackageHelper {
+
+    private PackageHelper() {
+    }
+
+    public static void findJsonFiles(File dir, Set<File> found, FileFilter 
filter) {
+        File[] files = dir.listFiles(filter);
+        if (files != null) {
+            for (File file : files) {
+                // skip files in root dirs as Camel does not store information 
there but others may do
+                boolean jsonFile = file.isFile() && 
file.getName().endsWith(".json");
+                if (jsonFile) {
+                    found.add(file);
+                } else if (file.isDirectory()) {
+                    findJsonFiles(file, found, filter);
+                }
+            }
+        }
+    }
+
+    public static class CamelComponentsModelFilter implements FileFilter {
+
+        @Override
+        public boolean accept(File pathname) {
+            return pathname.isDirectory() || 
pathname.getName().endsWith(".json");
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/f93e1d54/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageModelMojo.java
----------------------------------------------------------------------
diff --git 
a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageModelMojo.java
 
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageModelMojo.java
new file mode 100644
index 0000000..6a7be28
--- /dev/null
+++ 
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageModelMojo.java
@@ -0,0 +1,134 @@
+/**
+ * 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.
+ */
+package org.apache.camel.maven.packaging;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectHelper;
+
+/**
+ * Analyses the Camel EIPs in a project and generates extra descriptor 
information for easier auto-discovery in Camel.
+ *
+ * @goal generate-eips-list
+ * @execute phase="process-classes"
+ */
+public class PackageModelMojo extends AbstractMojo {
+
+    /**
+     * The maven project.
+     *
+     * @parameter property="project"
+     * @required
+     * @readonly
+     */
+    protected MavenProject project;
+
+    /**
+     * The camel-core directory
+     *
+     * @parameter default-value="${project.build.directory}"
+     */
+    protected File buildDir;
+
+    /**
+     * The output directory for generated models file
+     *
+     * @parameter 
default-value="${project.build.directory}/generated/camel/models"
+     */
+    protected File outDir;
+
+    /**
+     * Maven ProjectHelper.
+     *
+     * @component
+     * @readonly
+     */
+    private MavenProjectHelper projectHelper;
+
+    /**
+     * Execute goal.
+     *
+     * @throws org.apache.maven.plugin.MojoExecutionException execution of the 
main class or one of the
+     *                 threads it generated failed.
+     * @throws org.apache.maven.plugin.MojoFailureException something bad 
happened...
+     */
+    public void execute() throws MojoExecutionException, MojoFailureException {
+        File camelMetaDir = new File(outDir, 
"META-INF/services/org/apache/camel/");
+
+        Set<File> jsonFiles = new TreeSet<File>();
+
+        // find all json files in camel-core
+        if (buildDir != null && buildDir.isDirectory()) {
+            File target = new File(buildDir, "classes/org/apache/camel/model");
+            PackageHelper.findJsonFiles(target, jsonFiles, new 
PackageHelper.CamelComponentsModelFilter());
+        }
+
+        File outFile = new File(camelMetaDir, "model.properties");
+        try {
+            camelMetaDir.mkdirs();
+
+            Properties properties = new Properties();
+            properties.store(new FileWriter(outFile), "Generated by 
camel-package-maven-plugin");
+
+            List<String> models = new ArrayList<String>();
+            // sort the names
+            for (File file : jsonFiles) {
+                String name = file.getName();
+                if (name.endsWith(".json")) {
+                    // strip out .json from the name
+                    String modelName = name.substring(0, name.length() - 5);
+                    models.add(modelName);
+                }
+            }
+            Collections.sort(models);
+
+            FileOutputStream fos = new FileOutputStream(outFile, true);
+            for (String name : models) {
+                fos.write(name.getBytes());
+                fos.write("\n".getBytes());
+            }
+            fos.close();
+
+            getLog().info("Generated " + outFile + " containing " + 
models.size() + " Camel models");
+
+            if (projectHelper != null) {
+                List<String> includes = new ArrayList<String>();
+                includes.add("**/model.properties");
+                projectHelper.addResource(this.project, outDir.getPath(), 
includes, new ArrayList<String>());
+                projectHelper.attachArtifact(this.project, "properties", 
"camelModel", outFile);
+            }
+
+        } catch (IOException e) {
+            throw new MojoFailureException("Error writing to file " + outFile);
+        }
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/f93e1d54/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageMojo.java
----------------------------------------------------------------------
diff --git 
a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageMojo.java
 
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageMojo.java
index b97f426..6772d8f 100644
--- 
a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageMojo.java
+++ 
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageMojo.java
@@ -112,7 +112,7 @@ public class PackageMojo extends AbstractMojo {
             File outFile = new File(camelMetaDir, "component.properties");
             try {
                 properties.store(new FileWriter(outFile), "Generated by 
camel-package-maven-plugin");
-                getLog().info("Generated " + outFile + " containing the Camel 
" + (count > 1 ? "components " : "component ") + names);
+                getLog().info("Generated " + outFile + " containing " + count 
+ " Camel " + (count > 1 ? "components: " : "component: ") + names);
 
                 if (projectHelper != null) {
                     List<String> includes = new ArrayList<String>();

http://git-wip-us.apache.org/repos/asf/camel/blob/f93e1d54/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogMojo.java
----------------------------------------------------------------------
diff --git 
a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogMojo.java
 
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogMojo.java
index 0dbab08..935eca9 100644
--- 
a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogMojo.java
+++ 
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogMojo.java
@@ -124,7 +124,7 @@ public class PrepareCatalogMojo extends AbstractMojo {
         // find all json files in camel-core
         if (coreDir != null && coreDir.isDirectory()) {
             File target = new File(coreDir, 
"target/classes/org/apache/camel/model");
-            findModelFilesRecursive(target, jsonFiles, new 
CamelComponentsModelFilter());
+            PackageHelper.findJsonFiles(target, jsonFiles, new 
PackageHelper.CamelComponentsModelFilter());
         }
 
         getLog().info("Found " + jsonFiles.size() + " model json files");
@@ -428,21 +428,6 @@ public class PrepareCatalogMojo extends AbstractMojo {
         return name;
     }
 
-    private void findModelFilesRecursive(File dir, Set<File> found, FileFilter 
filter) {
-        File[] files = dir.listFiles(filter);
-        if (files != null) {
-            for (File file : files) {
-                // skip files in root dirs as Camel does not store information 
there but others may do
-                boolean jsonFile = file.isFile() && 
file.getName().endsWith(".json");
-                if (jsonFile) {
-                    found.add(file);
-                } else if (file.isDirectory()) {
-                    findModelFilesRecursive(file, found, filter);
-                }
-            }
-        }
-    }
-
     private void findComponentFilesRecursive(File dir, Set<File> found, 
Set<File> components, FileFilter filter) {
         File[] files = dir.listFiles(filter);
         if (files != null) {
@@ -462,14 +447,6 @@ public class PrepareCatalogMojo extends AbstractMojo {
         }
     }
 
-    private class CamelComponentsModelFilter implements FileFilter {
-
-        @Override
-        public boolean accept(File pathname) {
-            return pathname.isDirectory() || 
pathname.getName().endsWith(".json");
-        }
-    }
-
     private class CamelComponentsFileFilter implements FileFilter {
 
         @Override

Reply via email to