Add karaf-boot-sample-config sample
Project: http://git-wip-us.apache.org/repos/asf/karaf-boot/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf-boot/commit/1ea096cd Tree: http://git-wip-us.apache.org/repos/asf/karaf-boot/tree/1ea096cd Diff: http://git-wip-us.apache.org/repos/asf/karaf-boot/diff/1ea096cd Branch: refs/heads/master Commit: 1ea096cd69df985efc1c5b596ea4a0846c78cdd3 Parents: 1683f3c Author: Jean-Baptiste Onofré <[email protected]> Authored: Wed Oct 14 16:07:22 2015 +0200 Committer: Jean-Baptiste Onofré <[email protected]> Committed: Wed Oct 14 16:07:22 2015 +0200 ---------------------------------------------------------------------- .../karaf-boot-sample-config/README.md | 31 +++++++++++++ .../karaf-boot-sample-config/pom.xml | 47 ++++++++++++++++++++ .../java/sample/config/ConfigComponent.java | 43 ++++++++++++++++++ .../karaf-boot-starter-ds/pom.xml | 4 +- .../apache/karaf/boot/maven/GenerateMojo.java | 1 + pom.xml | 10 ++++- 6 files changed, 133 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/1ea096cd/karaf-boot-samples/karaf-boot-sample-config/README.md ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/karaf-boot-sample-config/README.md b/karaf-boot-samples/karaf-boot-sample-config/README.md new file mode 100644 index 0000000..6f571d5 --- /dev/null +++ b/karaf-boot-samples/karaf-boot-sample-config/README.md @@ -0,0 +1,31 @@ +== karaf-boot-sample-config == + +This sample shows how to use a configuration provided in the etc folder of Karaf, and directly use the +properties values in your code. + += Design + +The ConfigComponent use a SampleConfig configuration. The SampleConfig configuration is "injected" at activation +time of the component. + +The component just displays the values of the properties. + += Build + +To build, simply do: + + mvn clean install + += Deploy + +To deploy in Karaf, you have to enable the DS support first. For that, you have to install the scr feature: + + feature:install scr + +Once scr feature installed: + +* you can drop the generated jar file (target/karaf-boot-sample-config-1.0.jar) in the +Karaf deploy folder +* in the Karaf shell console, do: + + bundle:install -s mvn:karaf-boot-samples/karaf-boot-sample-config/1.0 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/1ea096cd/karaf-boot-samples/karaf-boot-sample-config/pom.xml ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/karaf-boot-sample-config/pom.xml b/karaf-boot-samples/karaf-boot-sample-config/pom.xml new file mode 100644 index 0000000..688150b --- /dev/null +++ b/karaf-boot-samples/karaf-boot-sample-config/pom.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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/xsd/maven-4.0.0.xsd"> + + <!-- + + 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. + --> + + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.karaf.boot</groupId> + <artifactId>karaf-boot-sample-config</artifactId> + <version>1.0.0-SNAPSHOT</version> + + <dependencies> + <dependency> + <groupId>org.apache.karaf.boot</groupId> + <artifactId>karaf-boot-starter-ds</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.karaf.boot</groupId> + <artifactId>karaf-boot-maven-plugin</artifactId> + <version>${project.version}</version> + <extensions>true</extensions> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/1ea096cd/karaf-boot-samples/karaf-boot-sample-config/src/main/java/sample/config/ConfigComponent.java ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/karaf-boot-sample-config/src/main/java/sample/config/ConfigComponent.java b/karaf-boot-samples/karaf-boot-sample-config/src/main/java/sample/config/ConfigComponent.java new file mode 100644 index 0000000..52cf369 --- /dev/null +++ b/karaf-boot-samples/karaf-boot-sample-config/src/main/java/sample/config/ConfigComponent.java @@ -0,0 +1,43 @@ +/** + * 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 sample.config; + +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.metatype.annotations.Designate; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; + +@ObjectClassDefinition(name = "Sample Configuration", pid = "org.apache.karaf.boot.sample.config") +@interface SampleConfig { + String stringProperty() default "default"; + int intProperty() default 0; + boolean booleanProperty() default false; +} + +@Component +@Designate(ocd = SampleConfig.class) +public class ConfigComponent { + + @Activate + public void activate(SampleConfig sampleConfig) { + System.out.println("We use the property there"); + System.out.println("stringProperty:" + sampleConfig.stringProperty()); + System.out.println("intProperty: " + sampleConfig.intProperty()); + System.out.println("booleanProperty: " + sampleConfig.booleanProperty()); + } + +} http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/1ea096cd/karaf-boot-starters/karaf-boot-starter-ds/pom.xml ---------------------------------------------------------------------- diff --git a/karaf-boot-starters/karaf-boot-starter-ds/pom.xml b/karaf-boot-starters/karaf-boot-starter-ds/pom.xml index 9add66a..09eb983 100644 --- a/karaf-boot-starters/karaf-boot-starter-ds/pom.xml +++ b/karaf-boot-starters/karaf-boot-starter-ds/pom.xml @@ -33,8 +33,8 @@ <dependencies> <dependency> <groupId>org.osgi</groupId> - <artifactId>org.osgi.compendium</artifactId> - <version>5.0.0</version> + <artifactId>osgi.cmpn</artifactId> + <version>${osgi.version}</version> </dependency> </dependencies> http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/1ea096cd/karaf-boot-tools/karaf-boot-maven-plugin/src/main/java/org/apache/karaf/boot/maven/GenerateMojo.java ---------------------------------------------------------------------- diff --git a/karaf-boot-tools/karaf-boot-maven-plugin/src/main/java/org/apache/karaf/boot/maven/GenerateMojo.java b/karaf-boot-tools/karaf-boot-maven-plugin/src/main/java/org/apache/karaf/boot/maven/GenerateMojo.java index da9414d..f15dad3 100644 --- a/karaf-boot-tools/karaf-boot-maven-plugin/src/main/java/org/apache/karaf/boot/maven/GenerateMojo.java +++ b/karaf-boot-tools/karaf-boot-maven-plugin/src/main/java/org/apache/karaf/boot/maven/GenerateMojo.java @@ -58,6 +58,7 @@ public class GenerateMojo extends AbstractMojo { felixBundlePlugin.setVersion("3.0.0"); felixBundlePlugin.setInherited(true); felixBundlePlugin.setExtensions(true); + // TODO check if a osgi.bnd file is present in the project base directory // TODO if jpa-start is provided as persistence.xml location configuration = Xpp3DomBuilder.build(new ByteArrayInputStream(("<configuration>" + "<finalName>${project.build.finalName}</finalName>" + http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/1ea096cd/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index cb5e826..b1bab33 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ </description> <properties> - <karaf.version>4.0.1</karaf.version> + <karaf.version>4.0.2</karaf.version> <osgi.version>6.0.0</osgi.version> </properties> @@ -40,7 +40,10 @@ <!-- TODO reuse @Services & @Reference shell annotations for generic use cases --> + <!-- Archetypes --> + <!-- Samples --> + <!-- services --> <module>karaf-boot-samples/karaf-boot-sample-service-provider-osgi</module> <module>karaf-boot-samples/karaf-boot-sample-service-consumer-osgi</module> <module>karaf-boot-samples/karaf-boot-sample-service-provider-ds</module> @@ -50,11 +53,16 @@ <!-- shell --> <module>karaf-boot-samples/karaf-boot-sample-shell</module> <!-- config --> + <module>karaf-boot-samples/karaf-boot-sample-config</module> <!-- jpa --> <!-- servlet --> + <!-- webui / angular --> <!-- test --> <!-- rest & soap --> <!-- camel --> + + <!-- Demos --> + <!-- complete library demos --> </modules> </project>
