Skip to content

Commit

Permalink
CAMEL-10844: Component docs - Remove .html generated files in components
Browse files Browse the repository at this point in the history
  • Loading branch information
davsclaus committed Feb 16, 2017
1 parent 6769dd2 commit 340fcab
Show file tree
Hide file tree
Showing 32 changed files with 44 additions and 439 deletions.
2 changes: 2 additions & 0 deletions camel-core/src/main/java/org/apache/camel/CamelContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,9 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration {
* 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.
* @deprecated use camel-catalog instead
*/
@Deprecated
String getComponentDocumentation(String componentName) throws IOException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,10 @@ public interface ManagedCamelContextMBean extends ManagedPerformanceCounterMBean
* Returns the HTML documentation for the given camel component
*
* @param componentName the component name
* @deprecated use camel-catalog instead
*/
@ManagedOperation(description = "Returns the HTML documentation for the given camel component")
@Deprecated
String getComponentDocumentation(String componentName) throws IOException;

@ManagedOperation(description = "Returns the JSON representation of all the static and dynamic endpoints defined in all the routes")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1414,51 +1414,7 @@ public Map<String, Properties> findEips() throws LoadPropertiesException, IOExce
}

public String getComponentDocumentation(String componentName) throws IOException {
// use the component factory finder to find the package name of the component class, which is the location
// where the documentation exists as well
FactoryFinder finder = getFactoryFinder(DefaultComponentResolver.RESOURCE_PATH);
try {
Class<?> clazz = null;
try {
clazz = finder.findClass(componentName);
} catch (NoFactoryAvailableException e) {
// ignore, i.e. if a component is an auto-configured spring-boot
// components
}

if (clazz == null) {
// fallback and find existing component
Component existing = hasComponent(componentName);
if (existing != null) {
clazz = existing.getClass();
} else {
return null;
}
}

String packageName = clazz.getPackage().getName();
packageName = packageName.replace('.', '/');
String path = packageName + "/" + componentName + ".html";

ClassResolver resolver = getClassResolver();
InputStream inputStream = resolver.loadResourceAsStream(path);
log.debug("Loading component documentation for: {} using class resolver: {} -> {}", new Object[]{componentName, resolver, inputStream});
if (inputStream != null) {
try {
return IOHelper.loadText(inputStream);
} finally {
IOHelper.close(inputStream);
}
}
// special for ActiveMQ as it is really just JMS
if ("ActiveMQComponent".equals(clazz.getSimpleName())) {
return getComponentDocumentation("jms");
} else {
return null;
}
} catch (ClassNotFoundException e) {
return null;
}
return null;
}

public String getComponentParameterJsonSchema(String componentName) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ public Map<String, Properties> findComponents() throws Exception {
}

public String getComponentDocumentation(String componentName) throws IOException {
return context.getComponentDocumentation(componentName);
return null;
}

public String createRouteStaticEndpointJson() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,4 @@ public void testComponentDiscovery() throws Exception {
}
}

@Test
public void testComponentDocumentation() throws Exception {
CamelContext context = new DefaultCamelContext();
String html = context.getComponentDocumentation("bean");
assertNotNull("Should have found some auto-generated HTML", html);
LOG.info("HTML: " + html);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,6 @@ public Map<String, Properties> findComponents() throws LoadPropertiesException,
return BundleContextUtils.findComponents(bundleContext, this);
}

@Override
public String getComponentDocumentation(String componentName) throws IOException {
return BundleContextUtils.getComponentDocumentation(bundleContext, this, componentName);
}

@Override
public void blueprintEvent(BlueprintEvent event) {
if (LOG.isDebugEnabled()) {
Expand Down
28 changes: 28 additions & 0 deletions components/camel-blueprint/src/test/resources/log4j2.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## ---------------------------------------------------------------------------
## 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.
## ---------------------------------------------------------------------------

appender.file.type = File
appender.file.name = file
appender.file.fileName = target/camel-blueprint-test.log
appender.file.layout.type = PatternLayout
appender.file.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
appender.out.type = Console
appender.out.name = out
appender.out.layout.type = PatternLayout
appender.out.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
rootLogger.level = INFO
rootLogger.appenderRef.file.ref = file
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ public Map<String, Properties> findComponents() throws LoadPropertiesException,
return BundleContextUtils.findComponents(bundleContext, this);
}

@Override
public String getComponentDocumentation(String componentName) throws IOException {
return BundleContextUtils.getComponentDocumentation(bundleContext, this, componentName);
}

@Override
protected Registry createRegistry() {
if (registry != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
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.Enumeration;
Expand All @@ -28,7 +27,6 @@

import org.apache.camel.CamelContext;
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;
Expand Down Expand Up @@ -92,20 +90,4 @@ public static Map<String, Properties> findComponents(BundleContext bundleContext
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,19 @@
package org.apache.camel.component.twitter;

import org.apache.camel.CamelContext;
import org.apache.camel.ComponentConfiguration;
import org.apache.camel.Endpoint;
import org.apache.camel.EndpointConfiguration;
import org.apache.camel.impl.DefaultCamelContext;
import org.junit.Assert;
import org.junit.Test;

public class UriConfigurationTest extends Assert {
private CamelContext context = new DefaultCamelContext();

private CamelContext context = new DefaultCamelContext();
private CamelTwitterTestSupport support = new CamelTwitterTestSupport();

@Test
public void testBasicAuthentication() throws Exception {
Endpoint endpoint = context.getEndpoint("twitter:todo/todo?" + support.getUriTokens());
Endpoint endpoint = context.getEndpoint("twitter:search?" + support.getUriTokens());
assertTrue("Endpoint not a TwitterEndpoint: " + endpoint, endpoint instanceof TwitterEndpoint);
TwitterEndpoint twitterEndpoint = (TwitterEndpoint) endpoint;

Expand All @@ -43,7 +41,7 @@ public void testBasicAuthentication() throws Exception {

@Test
public void testPageSetting() throws Exception {
Endpoint endpoint = context.getEndpoint("twitter:todo/page?count=50&numberOfPages=2");
Endpoint endpoint = context.getEndpoint("twitter:search?count=50&numberOfPages=2");
assertTrue("Endpoint not a TwitterEndpoint: " + endpoint, endpoint instanceof TwitterEndpoint);
TwitterEndpoint twitterEndpoint = (TwitterEndpoint) endpoint;

Expand All @@ -53,7 +51,7 @@ public void testPageSetting() throws Exception {

@Test
public void testHttpProxySetting() throws Exception {
Endpoint endpoint = context.getEndpoint("twitter:todo/todo?httpProxyHost=example.com&httpProxyPort=3338&httpProxyUser=test&httpProxyPassword=pwd");
Endpoint endpoint = context.getEndpoint("twitter:search?httpProxyHost=example.com&httpProxyPort=3338&httpProxyUser=test&httpProxyPassword=pwd");
assertTrue("Endpoint not a TwitterEndpoint: " + endpoint, endpoint instanceof TwitterEndpoint);
TwitterEndpoint twitterEndpoint = (TwitterEndpoint) endpoint;

Expand All @@ -62,24 +60,5 @@ public void testHttpProxySetting() throws Exception {
assertEquals("test", twitterEndpoint.getProperties().getHttpProxyUser());
assertEquals("pwd", twitterEndpoint.getProperties().getHttpProxyPassword());
}

@Test
public void testComponentConfiguration() throws Exception {
TwitterComponent comp = context.getComponent("twitter", TwitterComponent.class);
EndpointConfiguration conf = comp.createConfiguration("twitter:search?keywords=camel");

assertEquals("camel", conf.getParameter("keywords"));

ComponentConfiguration compConf = comp.createComponentConfiguration();
String json = compConf.createParameterJsonSchema();
assertNotNull(json);
}

@Test
public void testComponentDocumentation() throws Exception {
CamelContext context = new DefaultCamelContext();
String html = context.getComponentDocumentation("twitter");
assertNotNull("Should have found some auto-generated HTML", html);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
*/
package org.apache.camel.itest.doc;

import org.apache.camel.CamelContext;
import org.apache.camel.ComponentConfiguration;
import org.apache.camel.EndpointConfiguration;
import org.apache.camel.component.bean.BeanComponent;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

Expand All @@ -46,11 +44,4 @@ public void testComponentConfiguration() throws Exception {
assertTrue(json.contains("\"cache\": { \"kind\": \"parameter\", \"group\": \"advanced\", \"label\": \"advanced\", \"type\": \"boolean\""));
}

@Test
public void testComponentDocumentation() throws Exception {
CamelContext context = new DefaultCamelContext();
String html = context.getComponentDocumentation("bean");
assertNotNull("Should have found some auto-generated HTML", html);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
*/
package org.apache.camel.itest.doc;

import org.apache.camel.CamelContext;
import org.apache.camel.ComponentConfiguration;
import org.apache.camel.EndpointConfiguration;
import org.apache.camel.component.browse.BrowseComponent;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

Expand All @@ -46,11 +44,4 @@ public void testComponentConfiguration() throws Exception {
assertTrue(json.contains("\"synchronous\": { \"kind\": \"parameter\", \"group\": \"advanced\", \"label\": \"advanced\", \"type\": \"boolean\""));
}

@Test
public void testComponentDocumentation() throws Exception {
CamelContext context = new DefaultCamelContext();
String html = context.getComponentDocumentation("browse");
assertNotNull("Should have found some auto-generated HTML", html);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
*/
package org.apache.camel.itest.doc;

import org.apache.camel.CamelContext;
import org.apache.camel.ComponentConfiguration;
import org.apache.camel.EndpointConfiguration;
import org.apache.camel.component.controlbus.ControlBusComponent;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

Expand All @@ -47,11 +45,4 @@ public void testComponentConfiguration() throws Exception {
assertTrue(json.contains("\"async\": { \"kind\": \"parameter\", \"group\": \"producer\", \"type\": \"boolean\""));
}

@Test
public void testComponentDocumentation() throws Exception {
CamelContext context = new DefaultCamelContext();
String html = context.getComponentDocumentation("controlbus");
assertNotNull("Should have found some auto-generated HTML", html);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@ public void testComponentConfiguration() throws Exception {
assertTrue(json.contains("\"synchronous\": { \"kind\": \"parameter\", \"group\": \"advanced\", \"label\": \"advanced\", \"type\": \"boolean\""));
}

@Test
public void testComponentDocumentation() throws Exception {
CamelContext context = new DefaultCamelContext();
String html = context.getComponentDocumentation("dataformat");
assertNotNull("Should have found some auto-generated HTML", html);
}

@Test
public void testFlatpackDefaultValue() throws Exception {
CamelContext context = new DefaultCamelContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
*/
package org.apache.camel.itest.doc;

import org.apache.camel.CamelContext;
import org.apache.camel.ComponentConfiguration;
import org.apache.camel.EndpointConfiguration;
import org.apache.camel.component.dataset.DataSetComponent;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

Expand Down Expand Up @@ -52,11 +50,4 @@ public void testComponentConfiguration() throws Exception {
assertTrue(json.contains("\"retainFirst\": { \"kind\": \"parameter\", \"group\": \"producer\", \"label\": \"producer\", \"type\": \"integer"));
}

@Test
public void testComponentDocumentation() throws Exception {
CamelContext context = new DefaultCamelContext();
String html = context.getComponentDocumentation("dataset");
assertNotNull("Should have found some auto-generated HTML", html);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ public void testComponentConfiguration() throws Exception {
assertTrue(json.contains("\"timeout\": { \"kind\": \"parameter\", \"group\": \"producer\", \"label\": \"producer\", \"type\": \"integer\""));
}

@Test
public void testComponentDocumentation() throws Exception {
CamelContext context = new DefaultCamelContext();
String html = context.getComponentDocumentation("direct");
assertNotNull("Should have found some auto-generated HTML", html);
}

@Test
public void testComponentJsonSchema() throws Exception {
CamelContext context = new DefaultCamelContext();
Expand Down
Loading

0 comments on commit 340fcab

Please sign in to comment.