Hi

Thanks for spotting. I have pushed a fix for this.

On Mon, Jun 10, 2013 at 11:07 AM, Christian Müller
<[email protected]> wrote:
> The test
> org.apache.camel.component.ComponentDiscoveryTest.testComponentDocumentation()
> fails on Java 6 [1].
> Could you please check it...
>
> [1]
> https://builds.apache.org/view/A-D/view/Camel/job/Camel.trunk.fulltest/org.apache.camel$camel-core/1376/testReport/org.apache.camel.component/ComponentDiscoveryTest/testComponentDocumentation/
>
> Best,
>
> Christian Müller
> -----------------
>
> Software Integration Specialist
>
> Apache Camel committer: https://camel.apache.org/team
> V.P. Apache Camel: https://www.apache.org/foundation/
> Apache Member: https://www.apache.org/foundation/members.html
>
> https://www.linkedin.com/pub/christian-mueller/11/551/642
>
>
> On Sun, Jun 9, 2013 at 3:59 PM, <[email protected]> wrote:
>
>> Updated Branches:
>>   refs/heads/master 868a358ad -> 3ec75ec79
>>
>>
>> expose the component HTML to the CamelContext and the MBean so it can be
>> displayed by tooling
>>
>>
>> Project: http://git-wip-us.apache.org/repos/asf/camel/repo
>> Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3ec75ec7
>> Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3ec75ec7
>> Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3ec75ec7
>>
>> Branch: refs/heads/master
>> Commit: 3ec75ec79f29658b2e840787701e71885a5bdaae
>> Parents: 868a358
>> Author: James Strachan <[email protected]>
>> Authored: Sun Jun 9 09:55:38 2013 -0400
>> Committer: James Strachan <[email protected]>
>> Committed: Sun Jun 9 09:58:09 2013 -0400
>>
>> ----------------------------------------------------------------------
>>  .../java/org/apache/camel/CamelContext.java     |  6 +++++
>>  .../mbean/ManagedCamelContextMBean.java         |  9 +++++++
>>  .../apache/camel/impl/DefaultCamelContext.java  | 12 ++++++++++
>>  .../management/mbean/ManagedCamelContext.java   |  5 ++++
>>  .../apache/camel/util/CamelContextHelper.java   |  1 +
>>  .../java/org/apache/camel/util/IOHelper.java    | 25 ++++++++++++++++++++
>>  .../camel/component/ComponentDiscoveryTest.java |  9 +++++++
>>  .../camel/blueprint/BlueprintCamelContext.java  |  5 ++++
>>  .../core/osgi/OsgiDefaultCamelContext.java      |  5 ++++
>>  .../core/osgi/utils/BundleContextUtils.java     | 19 +++++++++++++++
>>  10 files changed, 96 insertions(+)
>> ----------------------------------------------------------------------
>>
>>
>>
>> http://git-wip-us.apache.org/repos/asf/camel/blob/3ec75ec7/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 5b2b4f6..7f467f1 100644
>> --- a/camel-core/src/main/java/org/apache/camel/CamelContext.java
>> +++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java
>> @@ -1205,4 +1205,10 @@ public interface CamelContext extends
>> SuspendableService, RuntimeConfiguration {
>>       * @throws Exception is thrown if error occurred
>>       */
>>      Map<String,Properties> findComponents() throws
>> LoadPropertiesException, IOException;
>> +
>> +
>> +    /**
>> +     * Returns the HTML documentation for the given camel component
>> +     */
>> +    String getComponentDocumentation(String componentName) throws
>> IOException;
>>  }
>>
>>
>> http://git-wip-us.apache.org/repos/asf/camel/blob/3ec75ec7/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 4af6d3d..514fdbe 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
>> @@ -16,6 +16,7 @@
>>   */
>>  package org.apache.camel.api.management.mbean;
>>
>> +import java.io.IOException;
>>  import java.util.List;
>>  import java.util.Map;
>>  import java.util.Properties;
>> @@ -219,4 +220,12 @@ public interface ManagedCamelContextMBean extends
>> ManagedPerformanceCounterMBean
>>      @ManagedOperation(description = "Returns the list of available
>> endpoint paths for the given component name, endpoint properties and
>> completion text")
>>      List<String> completeEndpointPath(String componentName, Map<String,
>> Object> endpointParameters, String completionText) throws Exception;
>>
>> +    /**
>> +     * Returns the HTML documentation for the given camel component
>> +     *
>> +     * @param componentName  the component name
>> +     */
>> +    @ManagedOperation(description = "Returns the HTML documentation for
>> the given camel component")
>> +    String getComponentDocumentation(String componentName) throws
>> IOException;
>> +
>>  }
>> \ No newline at end of file
>>
>>
>> http://git-wip-us.apache.org/repos/asf/camel/blob/3ec75ec7/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 c61c79f..22fa6e1 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
>> @@ -18,11 +18,13 @@ package org.apache.camel.impl;
>>
>>  import java.io.IOException;
>>  import java.io.InputStream;
>> +import java.net.URL;
>>  import java.util.ArrayList;
>>  import java.util.Arrays;
>>  import java.util.Collection;
>>  import java.util.Collections;
>>  import java.util.Date;
>> +import java.util.Enumeration;
>>  import java.util.HashMap;
>>  import java.util.Iterator;
>>  import java.util.LinkedHashMap;
>> @@ -125,6 +127,7 @@ import org.apache.camel.support.ServiceSupport;
>>  import org.apache.camel.util.CamelContextHelper;
>>  import org.apache.camel.util.EndpointHelper;
>>  import org.apache.camel.util.EventHelper;
>> +import org.apache.camel.util.IOHelper;
>>  import org.apache.camel.util.IntrospectionSupport;
>>  import org.apache.camel.util.LoadPropertiesException;
>>  import org.apache.camel.util.ObjectHelper;
>> @@ -1011,6 +1014,15 @@ public class DefaultCamelContext extends
>> ServiceSupport implements ModelCamelCon
>>          return CamelContextHelper.findComponents(this);
>>      }
>>
>> +    public String getComponentDocumentation(String componentName) throws
>> IOException {
>> +        String path = CamelContextHelper.COMPONENT_DOCUMENTATION_PREFIX +
>> componentName + ".html";
>> +        InputStream inputStream =
>> getClassResolver().loadResourceAsStream(path);
>> +        if (inputStream != null) {
>> +            return IOHelper.loadText(inputStream);
>> +        }
>> +        return null;
>> +    }
>> +
>>      // Helper methods
>>      //
>> -----------------------------------------------------------------------
>>
>>
>>
>> http://git-wip-us.apache.org/repos/asf/camel/blob/3ec75ec7/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 d01d3d0..eed4cff 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
>> @@ -16,6 +16,7 @@
>>   */
>>  package org.apache.camel.management.mbean;
>>
>> +import java.io.IOException;
>>  import java.io.InputStream;
>>  import java.util.ArrayList;
>>  import java.util.Collection;
>> @@ -345,6 +346,10 @@ public class ManagedCamelContext extends
>> ManagedPerformanceCounter implements Ti
>>          return context.findComponents();
>>      }
>>
>> +    public String getComponentDocumentation(String componentName) throws
>> IOException {
>> +        return context.getComponentDocumentation(componentName);
>> +    }
>> +
>>      public List<String> findComponentNames() throws Exception {
>>          Map<String, Properties> map = findComponents();
>>          return new ArrayList<String>(map.keySet());
>>
>>
>> http://git-wip-us.apache.org/repos/asf/camel/blob/3ec75ec7/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 40d7a1c..fc81164 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
>> @@ -46,6 +46,7 @@ import static org.apache.camel.util.ObjectHelper.notNull;
>>   */
>>  public final class CamelContextHelper {
>>      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/";
>>
>>      /**
>>       * Utility classes should not have a public constructor.
>>
>>
>> http://git-wip-us.apache.org/repos/asf/camel/blob/3ec75ec7/camel-core/src/main/java/org/apache/camel/util/IOHelper.java
>> ----------------------------------------------------------------------
>> diff --git a/camel-core/src/main/java/org/apache/camel/util/IOHelper.java
>> b/camel-core/src/main/java/org/apache/camel/util/IOHelper.java
>> index 6799274..ca4b82f 100644
>> --- a/camel-core/src/main/java/org/apache/camel/util/IOHelper.java
>> +++ b/camel-core/src/main/java/org/apache/camel/util/IOHelper.java
>> @@ -24,6 +24,7 @@ import java.io.Closeable;
>>  import java.io.FileOutputStream;
>>  import java.io.IOException;
>>  import java.io.InputStream;
>> +import java.io.InputStreamReader;
>>  import java.io.OutputStream;
>>  import java.io.Reader;
>>  import java.io.UnsupportedEncodingException;
>> @@ -413,4 +414,28 @@ public final class IOHelper {
>>      private static String getDefaultCharsetName() {
>>          return
>> ObjectHelper.getSystemProperty(Exchange.DEFAULT_CHARSET_PROPERTY, "UTF-8");
>>      }
>> +
>> +    /**
>> +     * Loads the entire stream into memory as a String and returns it.
>> +     *
>> +     * Warning, don't use for crazy big streams :)
>> +     */
>> +    public static String loadText(InputStream in) throws IOException {
>> +        StringBuilder builder = new StringBuilder();
>> +        try {
>> +            BufferedReader reader = buffered(new InputStreamReader(in));
>> +            while (true) {
>> +                String line = reader.readLine();
>> +                if (line != null) {
>> +                    builder.append(line);
>> +                    builder.append("\n");
>> +                } else {
>> +                    break;
>> +                }
>> +            }
>> +            return builder.toString();
>> +        } finally {
>> +            close(in);
>> +        }
>> +    }
>>  }
>>
>>
>> http://git-wip-us.apache.org/repos/asf/camel/blob/3ec75ec7/camel-core/src/test/java/org/apache/camel/component/ComponentDiscoveryTest.java
>> ----------------------------------------------------------------------
>> diff --git
>> a/camel-core/src/test/java/org/apache/camel/component/ComponentDiscoveryTest.java
>> b/camel-core/src/test/java/org/apache/camel/component/ComponentDiscoveryTest.java
>> index 5ab56e1..903dff7 100644
>> ---
>> a/camel-core/src/test/java/org/apache/camel/component/ComponentDiscoveryTest.java
>> +++
>> b/camel-core/src/test/java/org/apache/camel/component/ComponentDiscoveryTest.java
>> @@ -56,4 +56,13 @@ public class ComponentDiscoveryTest {
>>              LOG.info("Found component " + entry.getKey() + " with
>> properties: " + entry.getValue());
>>          }
>>      }
>> +
>> +    @Test
>> +    public void testComponentDocumentation() throws Exception {
>> +        CamelContext context = new DefaultCamelContext();
>> +        String html = context.getComponentDocumentation("bean");
>> +        assertNotNull("Should have found some auto-generated HTML if on
>> Java 7", html);
>> +        LOG.info("HTML: " + html);
>> +    }
>> +
>>  }
>>
>>
>> http://git-wip-us.apache.org/repos/asf/camel/blob/3ec75ec7/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintCamelContext.java
>> ----------------------------------------------------------------------
>> diff --git
>> a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintCamelContext.java
>> b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintCamelContext.java
>> index 8a86bf6..60f0b4d 100644
>> ---
>> a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintCamelContext.java
>> +++
>> b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintCamelContext.java
>> @@ -120,6 +120,11 @@ public class BlueprintCamelContext extends
>> DefaultCamelContext implements Servic
>>      }
>>
>>      @Override
>> +    public String getComponentDocumentation(String componentName) throws
>> IOException {
>> +        return
>> BundleContextUtils.getComponentDocumentation(bundleContext, this,
>> componentName);
>> +    }
>> +
>> +    @Override
>>      public void blueprintEvent(BlueprintEvent event) {
>>          // noop as we just needed to enlist the BlueprintListener to have
>> events triggered to serviceChanged method
>>      }
>>
>>
>> http://git-wip-us.apache.org/repos/asf/camel/blob/3ec75ec7/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiDefaultCamelContext.java
>> ----------------------------------------------------------------------
>> diff --git
>> a/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiDefaultCamelContext.java
>> b/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiDefaultCamelContext.java
>> index d049f1c..7329a7b 100644
>> ---
>> a/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiDefaultCamelContext.java
>> +++
>> b/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiDefaultCamelContext.java
>> @@ -49,6 +49,11 @@ public class OsgiDefaultCamelContext extends
>> DefaultCamelContext {
>>      }
>>
>>      @Override
>> +    public String getComponentDocumentation(String componentName) throws
>> IOException {
>> +        return
>> BundleContextUtils.getComponentDocumentation(bundleContext, this,
>> componentName);
>> +    }
>> +
>> +    @Override
>>      protected Registry createRegistry() {
>>          if (registry != null) {
>>              return OsgiCamelContextHelper.wrapRegistry(this, registry,
>> bundleContext);
>>
>>
>> http://git-wip-us.apache.org/repos/asf/camel/blob/3ec75ec7/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/utils/BundleContextUtils.java
>> ----------------------------------------------------------------------
>> diff --git
>> a/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/utils/BundleContextUtils.java
>> b/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/utils/BundleContextUtils.java
>> index 85a0961..015f8a6 100644
>> ---
>> a/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/utils/BundleContextUtils.java
>> +++
>> b/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/utils/BundleContextUtils.java
>> @@ -17,6 +17,7 @@
>>  package org.apache.camel.core.osgi.utils;
>>
>>  import java.io.IOException;
>> +import java.io.InputStream;
>>  import java.lang.reflect.Method;
>>  import java.net.URL;
>>  import java.util.Arrays;
>> @@ -29,6 +30,7 @@ import java.util.TreeMap;
>>  import org.apache.camel.CamelContext;
>>  import org.apache.camel.spi.ComponentResolver;
>>  import org.apache.camel.util.CamelContextHelper;
>> +import org.apache.camel.util.IOHelper;
>>  import org.apache.camel.util.LoadPropertiesException;
>>  import org.osgi.framework.Bundle;
>>  import org.osgi.framework.BundleContext;
>> @@ -92,4 +94,21 @@ public final class BundleContextUtils {
>>          }
>>          return answer;
>>      }
>> +
>> +    public static String getComponentDocumentation(BundleContext
>> bundleContext,
>> +                                                   CamelContext
>> camelContext,
>> +                                                   String componentName)
>> throws IOException {
>> +        String path = CamelContextHelper.COMPONENT_DOCUMENTATION_PREFIX +
>> componentName + ".html";
>> +        Bundle[] bundles = bundleContext.getBundles();
>> +        for (Bundle bundle : bundles) {
>> +            URL resource = bundle.getResource(path);
>> +            if (resource != null) {
>> +                InputStream inputStream = resource.openStream();
>> +                if (inputStream != null) {
>> +                    return IOHelper.loadText(inputStream);
>> +                }
>> +            }
>> +        }
>> +        return null;
>> +    }
>>  }
>>
>>



-- 
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.

Red Hat, Inc.
FuseSource is now part of Red Hat
Email: [email protected]
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Reply via email to