http://git-wip-us.apache.org/repos/asf/camel/blob/75251730/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/springboot/WebsocketComponentConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/springboot/WebsocketComponentConfiguration.java b/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/springboot/WebsocketComponentConfiguration.java new file mode 100644 index 0000000..76a2821 --- /dev/null +++ b/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/springboot/WebsocketComponentConfiguration.java @@ -0,0 +1,192 @@ +/** + * 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.component.websocket.springboot; + +import java.util.Map; +import org.apache.camel.component.websocket.WebSocketFactory; +import org.apache.camel.util.jsse.SSLContextParameters; +import org.eclipse.jetty.util.thread.ThreadPool; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * The websocket component provides websocket endpoints for communicating with + * clients using websocket. + * + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@ConfigurationProperties(prefix = "camel.component.websocket") +public class WebsocketComponentConfiguration { + + /** + * Set a resource path for static resources (such as .html files etc). The + * resources can be loaded from classpath if you prefix with classpath: + * otherwise the resources is loaded from file system or from JAR files. For + * example to load from root classpath use classpath:. or + * classpath:WEB-INF/static If not configured (eg null) then no static + * resource is in use. + */ + private String staticResources; + /** + * The hostname. The default value is 0.0.0.0 + */ + private String host; + /** + * The port number. The default value is 9292 + */ + private Integer port; + /** + * The password for the keystore when using SSL. + */ + private String sslKeyPassword; + /** + * The password when using SSL. + */ + private String sslPassword; + /** + * The path to the keystore. + */ + private String sslKeystore; + /** + * If this option is true Jetty JMX support will be enabled for this + * endpoint. See Jetty JMX support for more details. + */ + private boolean enableJmx; + /** + * To set a value for minimum number of threads in server thread pool. + * MaxThreads/minThreads or threadPool fields are required due to switch to + * Jetty9. The default values for minThreads is 1. + */ + private Integer minThreads; + /** + * To set a value for maximum number of threads in server thread pool. + * MaxThreads/minThreads or threadPool fields are required due to switch to + * Jetty9. The default values for maxThreads is 1 2 noCores. + */ + private Integer maxThreads; + /** + * To use a custom thread pool for the server. MaxThreads/minThreads or + * threadPool fields are required due to switch to Jetty9. + */ + private ThreadPool threadPool; + /** + * To configure security using SSLContextParameters + */ + private SSLContextParameters sslContextParameters; + /** + * To configure a map which contains custom WebSocketFactory for sub + * protocols. The key in the map is the sub protocol. The default key is + * reserved for the default implementation. + */ + private Map<java.lang.String, org.apache.camel.component.websocket.WebSocketFactory> socketFactory; + + public String getStaticResources() { + return staticResources; + } + + public void setStaticResources(String staticResources) { + this.staticResources = staticResources; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public Integer getPort() { + return port; + } + + public void setPort(Integer port) { + this.port = port; + } + + public String getSslKeyPassword() { + return sslKeyPassword; + } + + public void setSslKeyPassword(String sslKeyPassword) { + this.sslKeyPassword = sslKeyPassword; + } + + public String getSslPassword() { + return sslPassword; + } + + public void setSslPassword(String sslPassword) { + this.sslPassword = sslPassword; + } + + public String getSslKeystore() { + return sslKeystore; + } + + public void setSslKeystore(String sslKeystore) { + this.sslKeystore = sslKeystore; + } + + public boolean isEnableJmx() { + return enableJmx; + } + + public void setEnableJmx(boolean enableJmx) { + this.enableJmx = enableJmx; + } + + public Integer getMinThreads() { + return minThreads; + } + + public void setMinThreads(Integer minThreads) { + this.minThreads = minThreads; + } + + public Integer getMaxThreads() { + return maxThreads; + } + + public void setMaxThreads(Integer maxThreads) { + this.maxThreads = maxThreads; + } + + public ThreadPool getThreadPool() { + return threadPool; + } + + public void setThreadPool(ThreadPool threadPool) { + this.threadPool = threadPool; + } + + public SSLContextParameters getSslContextParameters() { + return sslContextParameters; + } + + public void setSslContextParameters( + SSLContextParameters sslContextParameters) { + this.sslContextParameters = sslContextParameters; + } + + public Map<String, WebSocketFactory> getSocketFactory() { + return socketFactory; + } + + public void setSocketFactory(Map<String, WebSocketFactory> socketFactory) { + this.socketFactory = socketFactory; + } +} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/75251730/components/camel-websocket/src/main/resources/META-INF/spring.factories ---------------------------------------------------------------------- diff --git a/components/camel-websocket/src/main/resources/META-INF/spring.factories b/components/camel-websocket/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..f5a3522 --- /dev/null +++ b/components/camel-websocket/src/main/resources/META-INF/spring.factories @@ -0,0 +1,19 @@ +# +# 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. +# + +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.apache.camel.component.websocket.springboot.WebsocketComponentAutoConfiguration http://git-wip-us.apache.org/repos/asf/camel/blob/75251730/components/camel-xmlbeans/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-xmlbeans/pom.xml b/components/camel-xmlbeans/pom.xml index c40aa92..9353cf2 100644 --- a/components/camel-xmlbeans/pom.xml +++ b/components/camel-xmlbeans/pom.xml @@ -15,7 +15,8 @@ See the License for the specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> @@ -69,57 +70,79 @@ <artifactId>junit</artifactId> <scope>test</scope> </dependency> + + <!-- xmlbeans-maven-plugin do not work with spring-boot so we need + to change the dependencies from provided to test so they are not in use --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot</artifactId> + <version>${spring-boot-version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-autoconfigure</artifactId> + <version>${spring-boot-version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-configuration-processor</artifactId> + <version>${spring-boot-version}</version> + <scope>test</scope> + </dependency> + </dependencies> - <build> - <pluginManagement> - <plugins> - <!-- Eclipse m2e Lifecycle Management --> - <plugin> - <groupId>org.eclipse.m2e</groupId> - <artifactId>lifecycle-mapping</artifactId> - <version>${lifecycle-mapping-version}</version> - <configuration> - <lifecycleMappingMetadata> - <pluginExecutions> - <pluginExecution> - <pluginExecutionFilter> - <groupId>org.codehaus.mojo</groupId> - <artifactId>xmlbeans-maven-plugin</artifactId> - <versionRange>${xmlbeans-maven-plugin-version}</versionRange> - <goals> - <goal>xmlbeans-test</goal> - </goals> - </pluginExecutionFilter> - <action> - <ignore /> - </action> - </pluginExecution> - </pluginExecutions> - </lifecycleMappingMetadata> - </configuration> - </plugin> - </plugins> - </pluginManagement> - <plugins> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>xmlbeans-maven-plugin</artifactId> - <version>${xmlbeans-maven-plugin-version}</version> - <executions> - <execution> - <id>generate-sources</id> - <phase>generate-sources</phase> - <goals> - <goal>xmlbeans-test</goal> - </goals> - </execution> - </executions> - <inherited>true</inherited> - <configuration> - <schemaDirectory>src/test/resources/xsd</schemaDirectory> - </configuration> - </plugin> - </plugins> - </build> + <build> + <pluginManagement> + <plugins> + <!-- Eclipse m2e Lifecycle Management --> + <plugin> + <groupId>org.eclipse.m2e</groupId> + <artifactId>lifecycle-mapping</artifactId> + <version>${lifecycle-mapping-version}</version> + <configuration> + <lifecycleMappingMetadata> + <pluginExecutions> + <pluginExecution> + <pluginExecutionFilter> + <groupId>org.codehaus.mojo</groupId> + <artifactId>xmlbeans-maven-plugin</artifactId> + <versionRange>${xmlbeans-maven-plugin-version}</versionRange> + <goals> + <goal>xmlbeans-test</goal> + </goals> + </pluginExecutionFilter> + <action> + <ignore/> + </action> + </pluginExecution> + </pluginExecutions> + </lifecycleMappingMetadata> + </configuration> + </plugin> + </plugins> + </pluginManagement> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>xmlbeans-maven-plugin</artifactId> + <version>${xmlbeans-maven-plugin-version}</version> + <executions> + <execution> + <id>generate-sources</id> + <phase>generate-sources</phase> + <goals> + <goal>xmlbeans-test</goal> + </goals> + </execution> + </executions> + <inherited>true</inherited> + <configuration> + <schemaDirectory>src/test/resources/xsd</schemaDirectory> + </configuration> + </plugin> + </plugins> + </build> </project> http://git-wip-us.apache.org/repos/asf/camel/blob/75251730/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/springboot/XmlSignatureComponentAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/springboot/XmlSignatureComponentAutoConfiguration.java b/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/springboot/XmlSignatureComponentAutoConfiguration.java new file mode 100644 index 0000000..fab9d14 --- /dev/null +++ b/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/springboot/XmlSignatureComponentAutoConfiguration.java @@ -0,0 +1,50 @@ +/** + * 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.component.xmlsecurity.springboot; + +import java.util.HashMap; +import java.util.Map; +import org.apache.camel.CamelContext; +import org.apache.camel.component.xmlsecurity.XmlSignatureComponent; +import org.apache.camel.util.IntrospectionSupport; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@Configuration +@EnableConfigurationProperties(XmlSignatureComponentConfiguration.class) +public class XmlSignatureComponentAutoConfiguration { + + @Bean + @ConditionalOnClass(CamelContext.class) + @ConditionalOnMissingBean(XmlSignatureComponent.class) + public XmlSignatureComponent configureComponent(CamelContext camelContext, + XmlSignatureComponentConfiguration configuration) throws Exception { + XmlSignatureComponent component = new XmlSignatureComponent(); + component.setCamelContext(camelContext); + Map<String, Object> parameters = new HashMap<>(); + IntrospectionSupport.getProperties(configuration, parameters, null); + IntrospectionSupport.setProperties(camelContext, + camelContext.getTypeConverter(), component, parameters); + return component; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/75251730/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/springboot/XmlSignatureComponentConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/springboot/XmlSignatureComponentConfiguration.java b/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/springboot/XmlSignatureComponentConfiguration.java new file mode 100644 index 0000000..0a34deb --- /dev/null +++ b/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/springboot/XmlSignatureComponentConfiguration.java @@ -0,0 +1,59 @@ +/** + * 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.component.xmlsecurity.springboot; + +import org.apache.camel.component.xmlsecurity.processor.XmlSignerConfiguration; +import org.apache.camel.component.xmlsecurity.processor.XmlVerifierConfiguration; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * Used to sign and verify exchanges using the XML signature specification. + * + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@ConfigurationProperties(prefix = "camel.component.xmlsecurity") +public class XmlSignatureComponentConfiguration { + + /** + * To use a shared XmlSignerConfiguration configuration to use as base for + * configuring endpoints. + */ + private XmlSignerConfiguration signerConfiguration; + /** + * To use a shared XmlVerifierConfiguration configuration to use as base for + * configuring endpoints. + */ + private XmlVerifierConfiguration verifierConfiguration; + + public XmlSignerConfiguration getSignerConfiguration() { + return signerConfiguration; + } + + public void setSignerConfiguration( + XmlSignerConfiguration signerConfiguration) { + this.signerConfiguration = signerConfiguration; + } + + public XmlVerifierConfiguration getVerifierConfiguration() { + return verifierConfiguration; + } + + public void setVerifierConfiguration( + XmlVerifierConfiguration verifierConfiguration) { + this.verifierConfiguration = verifierConfiguration; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/75251730/components/camel-xmlsecurity/src/main/resources/META-INF/spring.factories ---------------------------------------------------------------------- diff --git a/components/camel-xmlsecurity/src/main/resources/META-INF/spring.factories b/components/camel-xmlsecurity/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..04f85dd --- /dev/null +++ b/components/camel-xmlsecurity/src/main/resources/META-INF/spring.factories @@ -0,0 +1,19 @@ +# +# 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. +# + +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.apache.camel.component.xmlsecurity.springboot.XmlSignatureComponentAutoConfiguration http://git-wip-us.apache.org/repos/asf/camel/blob/75251730/components/camel-yammer/src/main/java/org/apache/camel/component/yammer/springboot/YammerComponentAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-yammer/src/main/java/org/apache/camel/component/yammer/springboot/YammerComponentAutoConfiguration.java b/components/camel-yammer/src/main/java/org/apache/camel/component/yammer/springboot/YammerComponentAutoConfiguration.java new file mode 100644 index 0000000..aae8ff3 --- /dev/null +++ b/components/camel-yammer/src/main/java/org/apache/camel/component/yammer/springboot/YammerComponentAutoConfiguration.java @@ -0,0 +1,50 @@ +/** + * 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.component.yammer.springboot; + +import java.util.HashMap; +import java.util.Map; +import org.apache.camel.CamelContext; +import org.apache.camel.component.yammer.YammerComponent; +import org.apache.camel.util.IntrospectionSupport; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@Configuration +@EnableConfigurationProperties(YammerComponentConfiguration.class) +public class YammerComponentAutoConfiguration { + + @Bean + @ConditionalOnClass(CamelContext.class) + @ConditionalOnMissingBean(YammerComponent.class) + public YammerComponent configureComponent(CamelContext camelContext, + YammerComponentConfiguration configuration) throws Exception { + YammerComponent component = new YammerComponent(); + component.setCamelContext(camelContext); + Map<String, Object> parameters = new HashMap<>(); + IntrospectionSupport.getProperties(configuration, parameters, null); + IntrospectionSupport.setProperties(camelContext, + camelContext.getTypeConverter(), component, parameters); + return component; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/75251730/components/camel-yammer/src/main/java/org/apache/camel/component/yammer/springboot/YammerComponentConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-yammer/src/main/java/org/apache/camel/component/yammer/springboot/YammerComponentConfiguration.java b/components/camel-yammer/src/main/java/org/apache/camel/component/yammer/springboot/YammerComponentConfiguration.java new file mode 100644 index 0000000..1ba82a4 --- /dev/null +++ b/components/camel-yammer/src/main/java/org/apache/camel/component/yammer/springboot/YammerComponentConfiguration.java @@ -0,0 +1,79 @@ +/** + * 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.component.yammer.springboot; + +import org.apache.camel.component.yammer.YammerConfiguration; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * The yammer component allows you to interact with the Yammer enterprise social + * network. + * + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@ConfigurationProperties(prefix = "camel.component.yammer") +public class YammerComponentConfiguration { + + /** + * The consumer key + */ + private String consumerKey; + /** + * The consumer secret + */ + private String consumerSecret; + /** + * The access token + */ + private String accessToken; + /** + * To use a shared yammer configuration + */ + private YammerConfiguration config; + + public String getConsumerKey() { + return consumerKey; + } + + public void setConsumerKey(String consumerKey) { + this.consumerKey = consumerKey; + } + + public String getConsumerSecret() { + return consumerSecret; + } + + public void setConsumerSecret(String consumerSecret) { + this.consumerSecret = consumerSecret; + } + + public String getAccessToken() { + return accessToken; + } + + public void setAccessToken(String accessToken) { + this.accessToken = accessToken; + } + + public YammerConfiguration getConfig() { + return config; + } + + public void setConfig(YammerConfiguration config) { + this.config = config; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/75251730/components/camel-yammer/src/main/resources/META-INF/spring.factories ---------------------------------------------------------------------- diff --git a/components/camel-yammer/src/main/resources/META-INF/spring.factories b/components/camel-yammer/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..898e683 --- /dev/null +++ b/components/camel-yammer/src/main/resources/META-INF/spring.factories @@ -0,0 +1,19 @@ +# +# 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. +# + +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.apache.camel.component.yammer.springboot.YammerComponentAutoConfiguration http://git-wip-us.apache.org/repos/asf/camel/blob/75251730/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/springboot/ZooKeeperComponentAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/springboot/ZooKeeperComponentAutoConfiguration.java b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/springboot/ZooKeeperComponentAutoConfiguration.java new file mode 100644 index 0000000..35d9d34 --- /dev/null +++ b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/springboot/ZooKeeperComponentAutoConfiguration.java @@ -0,0 +1,50 @@ +/** + * 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.component.zookeeper.springboot; + +import java.util.HashMap; +import java.util.Map; +import org.apache.camel.CamelContext; +import org.apache.camel.component.zookeeper.ZooKeeperComponent; +import org.apache.camel.util.IntrospectionSupport; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@Configuration +@EnableConfigurationProperties(ZooKeeperComponentConfiguration.class) +public class ZooKeeperComponentAutoConfiguration { + + @Bean + @ConditionalOnClass(CamelContext.class) + @ConditionalOnMissingBean(ZooKeeperComponent.class) + public ZooKeeperComponent configureComponent(CamelContext camelContext, + ZooKeeperComponentConfiguration configuration) throws Exception { + ZooKeeperComponent component = new ZooKeeperComponent(); + component.setCamelContext(camelContext); + Map<String, Object> parameters = new HashMap<>(); + IntrospectionSupport.getProperties(configuration, parameters, null); + IntrospectionSupport.setProperties(camelContext, + camelContext.getTypeConverter(), component, parameters); + return component; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/75251730/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/springboot/ZooKeeperComponentConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/springboot/ZooKeeperComponentConfiguration.java b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/springboot/ZooKeeperComponentConfiguration.java new file mode 100644 index 0000000..a3902ad --- /dev/null +++ b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/springboot/ZooKeeperComponentConfiguration.java @@ -0,0 +1,42 @@ +/** + * 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.component.zookeeper.springboot; + +import org.apache.camel.component.zookeeper.ZooKeeperConfiguration; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * The zookeeper component allows interaction with a ZooKeeper cluster. + * + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@ConfigurationProperties(prefix = "camel.component.zookeeper") +public class ZooKeeperComponentConfiguration { + + /** + * To use a shared ZooKeeperConfiguration + */ + private ZooKeeperConfiguration configuration; + + public ZooKeeperConfiguration getConfiguration() { + return configuration; + } + + public void setConfiguration(ZooKeeperConfiguration configuration) { + this.configuration = configuration; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/75251730/components/camel-zookeeper/src/main/resources/META-INF/spring.factories ---------------------------------------------------------------------- diff --git a/components/camel-zookeeper/src/main/resources/META-INF/spring.factories b/components/camel-zookeeper/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..998f9e1 --- /dev/null +++ b/components/camel-zookeeper/src/main/resources/META-INF/spring.factories @@ -0,0 +1,19 @@ +# +# 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. +# + +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.apache.camel.component.zookeeper.springboot.ZooKeeperComponentAutoConfiguration http://git-wip-us.apache.org/repos/asf/camel/blob/75251730/components/pom.xml ---------------------------------------------------------------------- diff --git a/components/pom.xml b/components/pom.xml index 724f757..09c56aa 100644 --- a/components/pom.xml +++ b/components/pom.xml @@ -31,6 +31,22 @@ <description>Camel Components</description> <packaging>pom</packaging> + <!-- to support spring-boot auto configuration in the Camel components --> + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot</artifactId> + <version>${spring-boot-version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-autoconfigure</artifactId> + <version>${spring-boot-version}</version> + <scope>provided</scope> + </dependency> + </dependencies> + <modules> <!-- we want to test these modules first to catch any errors early as possible --> <module>camel-test</module> @@ -286,15 +302,16 @@ <goal>prepare-components</goal> </goals> <phase>generate-resources</phase> - </execution> + </execution> <execution> <id>validate</id> <goals> <goal>validate-components</goal> + <goal>prepare-spring-boot-auto-configuration</goal> </goals> <phase>prepare-package</phase> - </execution> - <execution> + </execution> + <execution> <id>readme</id> <goals> <goal>update-readme</goal> @@ -317,14 +334,22 @@ </activation> <dependencies> - <!-- enable the APT processor --> + <!-- enable Camel APT processors --> <dependency> <groupId>org.apache.camel</groupId> <artifactId>apt</artifactId> <version>${project.version}</version> <scope>provided</scope> </dependency> + <!-- enable Spring Boot configuration APT processor --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-configuration-processor</artifactId> + <version>${spring-boot-version}</version> + <scope>provided</scope> + </dependency> </dependencies> </profile> </profiles> + </project> http://git-wip-us.apache.org/repos/asf/camel/blob/75251730/examples/camel-example-spring-boot/src/main/resources/application.yml ---------------------------------------------------------------------- diff --git a/examples/camel-example-spring-boot/src/main/resources/application.yml b/examples/camel-example-spring-boot/src/main/resources/application.yml index 59fc3f5..dc362f5 100644 --- a/examples/camel-example-spring-boot/src/main/resources/application.yml +++ b/examples/camel-example-spring-boot/src/main/resources/application.yml @@ -17,3 +17,7 @@ spring.main.sources: org.apache.camel.example.spring.boot.MySpringBootRouter shell.auth.simple.user.password: password + +camel: + springboot: + allow-use-original-message: false http://git-wip-us.apache.org/repos/asf/camel/blob/75251730/parent/pom.xml ---------------------------------------------------------------------- diff --git a/parent/pom.xml b/parent/pom.xml index 7224373..d6079b1 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -476,6 +476,7 @@ <rhino-bundle-version>1.7R2_3</rhino-bundle-version> <rhino-version>1.7R2</rhino-version> <ribbon-version>2.2.0</ribbon-version> + <roaster-version>2.18.3.Final</roaster-version> <rome-bundle-version>1.0_3</rome-bundle-version> <rome-version>1.0</rome-version> <rxjava-version>1.1.5</rxjava-version> http://git-wip-us.apache.org/repos/asf/camel/blob/75251730/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index d062d59..dc1823f 100755 --- a/pom.xml +++ b/pom.xml @@ -138,6 +138,7 @@ <module>buildingtools</module> <module>camel-core</module> <module>components</module> + <module>components-starter</module> <module>tooling</module> <module>platforms</module> <module>tests</module> http://git-wip-us.apache.org/repos/asf/camel/blob/75251730/tooling/maven/camel-package-maven-plugin/pom.xml ---------------------------------------------------------------------- diff --git a/tooling/maven/camel-package-maven-plugin/pom.xml b/tooling/maven/camel-package-maven-plugin/pom.xml index 4393469..604624e 100644 --- a/tooling/maven/camel-package-maven-plugin/pom.xml +++ b/tooling/maven/camel-package-maven-plugin/pom.xml @@ -15,7 +15,8 @@ See the License for the specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -87,6 +88,28 @@ <artifactId>commons-io</artifactId> </dependency> + <!-- roaster to create java source for Spring Boot auto configuration support --> + <dependency> + <groupId>org.jboss.forge.roaster</groupId> + <artifactId>roaster-api</artifactId> + <version>${roaster-version}</version> + </dependency> + <dependency> + <groupId>org.jboss.forge.roaster</groupId> + <artifactId>roaster-jdt</artifactId> + <version>${roaster-version}</version> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot</artifactId> + <version>${spring-boot-version}</version> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-autoconfigure</artifactId> + <version>${spring-boot-version}</version> + </dependency> + <!-- add some logging to the classpath --> <dependency> <groupId>log4j</groupId> http://git-wip-us.apache.org/repos/asf/camel/blob/75251730/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java ---------------------------------------------------------------------- diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java new file mode 100644 index 0000000..f87660f --- /dev/null +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java @@ -0,0 +1,498 @@ +/** + * 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.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import org.apache.camel.maven.packaging.model.ComponentModel; +import org.apache.camel.maven.packaging.model.ComponentOptionModel; +import org.apache.camel.maven.packaging.model.EndpointOptionModel; +import org.apache.commons.io.FileUtils; +import org.apache.maven.model.Resource; +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.jboss.forge.roaster.Roaster; +import org.jboss.forge.roaster.model.source.AnnotationSource; +import org.jboss.forge.roaster.model.source.Import; +import org.jboss.forge.roaster.model.source.JavaClassSource; +import org.jboss.forge.roaster.model.source.MethodSource; +import org.jboss.forge.roaster.model.source.PropertySource; +import org.jboss.forge.roaster.model.util.Strings; +import org.sonatype.plexus.build.incremental.BuildContext; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import static org.apache.camel.maven.packaging.JSonSchemaHelper.getSafeValue; +import static org.apache.camel.maven.packaging.PackageHelper.loadText; + +/** + * Generate Spring Boot auto configuration files for Camel components. + * + * @goal prepare-spring-boot-auto-configuration + */ +public class SpringBootAutoConfigurationMojo extends AbstractMojo { + + /** + * The maven project. + * + * @parameter property="project" + * @required + * @readonly + */ + protected MavenProject project; + + /** + * The project build directory + * + * @parameter default-value="${project.build.directory}" + */ + protected File buildDir; + + /** + * The source directory + * + * @parameter default-value="${basedir}/src/main/java" + */ + protected File srcDir; + + /** + * The resources directory + * + * @parameter default-value="${basedir}/src/main/resources" + */ + protected File resourcesDir; + + /** + * build context to check changed files and mark them for refresh (used for + * m2e compatibility) + * + * @component + * @readonly + */ + private BuildContext buildContext; + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + // find the component names + List<String> componentNames = findComponentNames(); + + final Set<File> jsonFiles = new TreeSet<File>(); + PackageHelper.findJsonFiles(buildDir, jsonFiles, new PackageHelper.CamelComponentsModelFilter()); + + // create auto configuration for the components + if (!componentNames.isEmpty()) { + getLog().info("Found " + componentNames.size() + " components"); + for (String componentName : componentNames) { + String json = loadComponentJson(jsonFiles, componentName); + if (json != null) { + ComponentModel model = generateComponentModel(componentName, json); + + // only create source code if the component has options that can be used in auto configuration + if (!model.getComponentOptions().isEmpty()) { + + // use springboot as sub package name so the code is not in normal + // package so the Spring Boot JARs can be optional at runtime + int pos = model.getJavaType().lastIndexOf("."); + String pkg = model.getJavaType().substring(0, pos) + ".springboot"; + + createComponentConfigurationSource(pkg, model); + createComponentAutoConfigurationSource(pkg, model); + createSpringFactorySource(pkg, model); + } + } + } + } + } + + private void createComponentConfigurationSource(String packageName, ComponentModel model) throws MojoFailureException { + final JavaClassSource javaClass = Roaster.create(JavaClassSource.class); + + int pos = model.getJavaType().lastIndexOf("."); + String name = model.getJavaType().substring(pos + 1); + name = name.replace("Component", "ComponentConfiguration"); + javaClass.setPackage(packageName).setName(name); + + String doc = "Generated by camel-package-maven-plugin - do not edit this file!"; + if (!Strings.isBlank(model.getDescription())) { + doc = model.getDescription() + "\n\n" + doc; + } + javaClass.getJavaDoc().setFullText(doc); + + String prefix = "camel.component." + model.getScheme(); + javaClass.addAnnotation("org.springframework.boot.context.properties.ConfigurationProperties").setStringValue("prefix", prefix); + + for (ComponentOptionModel option : model.getComponentOptions()) { + // remove <?> as generic type as Roaster (Eclipse JDT) cannot use that + String type = option.getJavaType(); + type = type.replaceAll("\\<\\?\\>", ""); + PropertySource<JavaClassSource> prop = javaClass.addProperty(type, option.getName()); + if ("true".equals(option.getDeprecated())) { + prop.getField().addAnnotation(Deprecated.class); + } + if (!Strings.isBlank(option.getDescription())) { + prop.getField().getJavaDoc().setFullText(option.getDescription()); + } + } + + sortImports(javaClass); + + String fileName = packageName.replaceAll("\\.", "\\/") + "/" + name + ".java"; + File target = new File(srcDir, fileName); + + try { + InputStream is = getClass().getClassLoader().getResourceAsStream("license-header-java.txt"); + String header = loadText(is); + String code = sourceToString(javaClass); + code = header + code; + getLog().debug("Source code generated:\n" + code); + + if (target.exists()) { + String existing = FileUtils.readFileToString(target); + if (!code.equals(existing)) { + FileUtils.write(target, code, false); + getLog().info("Updated existing file: " + target); + } else { + getLog().info("No changes to existing file: " + target); + } + } else { + FileUtils.write(target, code); + getLog().info("Created file: " + target); + } + } catch (Exception e) { + throw new MojoFailureException("IOError with file " + target, e); + } + } + + private void createComponentAutoConfigurationSource(String packageName, ComponentModel model) throws MojoFailureException { + final JavaClassSource javaClass = Roaster.create(JavaClassSource.class); + + int pos = model.getJavaType().lastIndexOf("."); + String name = model.getJavaType().substring(pos + 1); + name = name.replace("Component", "ComponentAutoConfiguration"); + javaClass.setPackage(packageName).setName(name); + + String doc = "Generated by camel-package-maven-plugin - do not edit this file!"; + javaClass.getJavaDoc().setFullText(doc); + + javaClass.addAnnotation(Configuration.class); + + String configurationName = name.replace("ComponentAutoConfiguration", "ComponentConfiguration"); + AnnotationSource<JavaClassSource> ann = javaClass.addAnnotation(EnableConfigurationProperties.class); + ann.setLiteralValue("value", configurationName + ".class"); + + // add method for auto configure + + javaClass.addImport("java.util.HashMap"); + javaClass.addImport("java.util.Map"); + javaClass.addImport(model.getJavaType()); + javaClass.addImport("org.apache.camel.CamelContext"); + javaClass.addImport("org.apache.camel.util.IntrospectionSupport"); + + String body = createBody(model.getShortJavaType()); + + MethodSource<JavaClassSource> method = javaClass.addMethod() + .setName("configureComponent") + .setPublic() + .setBody(body) + .setReturnType(model.getShortJavaType()) + .addThrows(Exception.class); + + method.addParameter("CamelContext", "camelContext"); + method.addParameter(configurationName, "configuration"); + + method.addAnnotation(Bean.class); + method.addAnnotation(ConditionalOnClass.class).setLiteralValue("value", "CamelContext.class"); + method.addAnnotation(ConditionalOnMissingBean.class).setLiteralValue("value", model.getShortJavaType() + ".class"); + + sortImports(javaClass); + + String fileName = packageName.replaceAll("\\.", "\\/") + "/" + name + ".java"; + File target = new File(srcDir, fileName); + + try { + InputStream is = getClass().getClassLoader().getResourceAsStream("license-header-java.txt"); + String header = loadText(is); + String code = sourceToString(javaClass); + code = header + code; + getLog().debug("Source code generated:\n" + code); + + if (target.exists()) { + String existing = FileUtils.readFileToString(target); + if (!code.equals(existing)) { + FileUtils.write(target, code, false); + getLog().info("Updated existing file: " + target); + } else { + getLog().info("No changes to existing file: " + target); + } + } else { + FileUtils.write(target, code); + getLog().info("Created file: " + target); + } + } catch (Exception e) { + throw new MojoFailureException("IOError with file " + target, e); + } + } + + private void createSpringFactorySource(String packageName, ComponentModel model) throws MojoFailureException { + StringBuilder sb = new StringBuilder(); + sb.append("org.springframework.boot.autoconfigure.EnableAutoConfiguration=\\\n"); + + int pos = model.getJavaType().lastIndexOf("."); + String name = model.getJavaType().substring(pos + 1); + name = name.replace("Component", "ComponentAutoConfiguration"); + String lineToAdd = packageName + "." + name + "\n"; + sb.append(lineToAdd); + + String fileName = "META-INF/spring.factories"; + File target = new File(resourcesDir, fileName); + + if (target.exists()) { + try { + // is the auto configuration already in the file + boolean found = false; + List<String> lines = FileUtils.readLines(target); + for (String line : lines) { + if (line.contains(name)) { + found = true; + break; + } + } + + if (found) { + getLog().info("No changes to existing file: " + target); + } else { + // find last non empty line, so we can add our new line after that + int lastLine = 0; + for (int i = lines.size() - 1; i >= 0; i--) { + String line = lines.get(i); + if (!line.trim().isEmpty()) { + // adjust existing line so its being continued + line = line + ",\\"; + lines.set(i, line); + lastLine = i; + break; + } + } + lines.add(lastLine + 1, lineToAdd); + + StringBuilder code = new StringBuilder(); + for (String line : lines) { + code.append(line).append("\n"); + } + + // update + FileUtils.write(target, code.toString(), false); + getLog().info("Updated existing file: " + target); + } + } catch (Exception e) { + throw new MojoFailureException("IOError with file " + target, e); + } + } else { + // create new file + try { + InputStream is = getClass().getClassLoader().getResourceAsStream("license-header.txt"); + String header = loadText(is); + String code = sb.toString(); + // add empty new line after header + code = header + "\n" + code; + getLog().debug("Source code generated:\n" + code); + + FileUtils.write(target, code); + getLog().info("Created file: " + target); + } catch (Exception e) { + throw new MojoFailureException("IOError with file " + target, e); + } + } + } + + private static String createBody(String shortJavaType) { + StringBuilder sb = new StringBuilder(); + sb.append(shortJavaType).append(" component = new ").append(shortJavaType).append("();").append("\n"); + sb.append("component.setCamelContext(camelContext);\n"); + sb.append("\n"); + sb.append("Map<String, Object> parameters = new HashMap<>();\n"); + sb.append("IntrospectionSupport.getProperties(configuration, parameters, null);\n"); + sb.append("\n"); + sb.append("IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), component, parameters);\n"); + sb.append("\n"); + sb.append("return component;"); + return sb.toString(); + } + + private static void sortImports(JavaClassSource javaClass) { + // sort imports + List<Import> imports = javaClass.getImports(); + + // sort imports + List<String> names = new ArrayList<>(); + for (Import imp : imports) { + names.add(imp.getQualifiedName()); + } + // sort + Collections.sort(names, (s1, s2) -> { + // java comes first + if (s1.startsWith("java.")) { + s1 = "___" + s1; + } + if (s2.startsWith("java.")) { + s2 = "___" + s2; + } + // then javax comes next + if (s1.startsWith("javax.")) { + s1 = "__" + s1; + } + if (s2.startsWith("javax.")) { + s2 = "__" + s2; + } + // org.w3c is for some odd reason also before others + if (s1.startsWith("org.w3c.")) { + s1 = "_" + s1; + } + if (s2.startsWith("org.w3c.")) { + s2 = "_" + s2; + } + return s1.compareTo(s2); + }); + + // remove all imports first + for (String name : names) { + javaClass.removeImport(name); + } + // and add them back in correct order + for (String name : names) { + javaClass.addImport(name); + } + } + + private static String sourceToString(JavaClassSource javaClass) { + String code = javaClass.toString(); + // convert tabs to 4 spaces + code = code.replaceAll("\\t", " "); + return code; + } + + private static String loadComponentJson(Set<File> jsonFiles, String componentName) { + try { + for (File file : jsonFiles) { + if (file.getName().equals(componentName + ".json")) { + String json = loadText(new FileInputStream(file)); + boolean isComponent = json.contains("\"kind\": \"component\""); + if (isComponent) { + return json; + } + } + } + } catch (IOException e) { + // ignore + } + return null; + } + + private static ComponentModel generateComponentModel(String componentName, String json) { + List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("component", json, false); + + ComponentModel component = new ComponentModel(); + component.setScheme(getSafeValue("scheme", rows)); + component.setSyntax(getSafeValue("syntax", rows)); + component.setAlternativeSyntax(getSafeValue("alternativeSyntax", rows)); + component.setTitle(getSafeValue("title", rows)); + component.setDescription(getSafeValue("description", rows)); + component.setLabel(getSafeValue("label", rows)); + component.setDeprecated(getSafeValue("deprecated", rows)); + component.setConsumerOnly(getSafeValue("consumerOnly", rows)); + component.setProducerOnly(getSafeValue("producerOnly", rows)); + component.setJavaType(getSafeValue("javaType", rows)); + component.setGroupId(getSafeValue("groupId", rows)); + component.setArtifactId(getSafeValue("artifactId", rows)); + component.setVersion(getSafeValue("version", rows)); + + rows = JSonSchemaHelper.parseJsonSchema("componentProperties", json, true); + for (Map<String, String> row : rows) { + ComponentOptionModel option = new ComponentOptionModel(); + option.setName(getSafeValue("name", row)); + option.setKind(getSafeValue("kind", row)); + option.setType(getSafeValue("type", row)); + option.setJavaType(getSafeValue("javaType", row)); + option.setDeprecated(getSafeValue("deprecated", row)); + option.setDescription(getSafeValue("description", row)); + component.addComponentOption(option); + } + + rows = JSonSchemaHelper.parseJsonSchema("properties", json, true); + for (Map<String, String> row : rows) { + EndpointOptionModel option = new EndpointOptionModel(); + option.setName(getSafeValue("name", row)); + option.setKind(getSafeValue("kind", row)); + option.setGroup(getSafeValue("group", row)); + option.setRequired(getSafeValue("required", row)); + option.setType(getSafeValue("type", row)); + option.setJavaType(getSafeValue("javaType", row)); + option.setEnums(getSafeValue("enum", row)); + option.setPrefix(getSafeValue("prefix", row)); + option.setMultiValue(getSafeValue("multiValue", row)); + option.setDeprecated(getSafeValue("deprecated", row)); + option.setDefaultValue(getSafeValue("defaultValue", row)); + option.setDescription(getSafeValue("description", row)); + component.addEndpointOption(option); + } + + return component; + } + + private List<String> findComponentNames() { + List<String> componentNames = new ArrayList<String>(); + for (Resource r : project.getBuild().getResources()) { + File f = new File(r.getDirectory()); + if (!f.exists()) { + f = new File(project.getBasedir(), r.getDirectory()); + } + f = new File(f, "META-INF/services/org/apache/camel/component"); + + if (f.exists() && f.isDirectory()) { + File[] files = f.listFiles(); + if (files != null) { + for (File file : files) { + // skip directories as there may be a sub .resolver directory + if (file.isDirectory()) { + continue; + } + String name = file.getName(); + if (name.charAt(0) != '.') { + componentNames.add(name); + } + } + } + } + } + return componentNames; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/75251730/tooling/maven/camel-package-maven-plugin/src/main/resources/license-header-java.txt ---------------------------------------------------------------------- diff --git a/tooling/maven/camel-package-maven-plugin/src/main/resources/license-header-java.txt b/tooling/maven/camel-package-maven-plugin/src/main/resources/license-header-java.txt new file mode 100644 index 0000000..0f49ea9 --- /dev/null +++ b/tooling/maven/camel-package-maven-plugin/src/main/resources/license-header-java.txt @@ -0,0 +1,16 @@ +/** + * 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. + */ \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/75251730/tooling/maven/camel-package-maven-plugin/src/main/resources/license-header.txt ---------------------------------------------------------------------- diff --git a/tooling/maven/camel-package-maven-plugin/src/main/resources/license-header.txt b/tooling/maven/camel-package-maven-plugin/src/main/resources/license-header.txt new file mode 100644 index 0000000..12bdf0d --- /dev/null +++ b/tooling/maven/camel-package-maven-plugin/src/main/resources/license-header.txt @@ -0,0 +1,16 @@ +# +# 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. +#