Refactoring of karaf-boot
Project: http://git-wip-us.apache.org/repos/asf/karaf-boot/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf-boot/commit/87577122 Tree: http://git-wip-us.apache.org/repos/asf/karaf-boot/tree/87577122 Diff: http://git-wip-us.apache.org/repos/asf/karaf-boot/diff/87577122 Branch: refs/heads/master Commit: 875771223463745d13b96856b6b3fe2e9866af7c Parents: a0248b7 Author: Jean-Baptiste Onofré <[email protected]> Authored: Tue Sep 29 15:04:55 2015 +0200 Committer: Jean-Baptiste Onofré <[email protected]> Committed: Tue Sep 29 15:04:55 2015 +0200 ---------------------------------------------------------------------- .../sample.osgi.service.provider.Activator | 1 + karaf-boot-parent/pom.xml | 73 ------ karaf-boot-samples/README.md | 21 +- .../README.md | 33 +++ .../pom.xml | 52 +++++ .../ds/service/consumer/HelloServiceClient.java | 59 +++++ .../README.md | 28 +++ .../pom.xml | 52 +++++ .../sample/osgi/service/consumer/Activator.java | 48 ++++ .../README.md | 35 +++ .../pom.xml | 47 ++++ .../ds/service/provider/HelloService.java | 26 +++ .../ds/service/provider/HelloServiceImpl.java | 31 +++ .../README.md | 33 +++ .../pom.xml | 47 ++++ .../sample/osgi/service/provider/Activator.java | 41 ++++ .../osgi/service/provider/HelloService.java | 26 +++ .../osgi/service/provider/HelloServiceImpl.java | 28 +++ .../karaf-boot-sample-simple/pom.xml | 33 --- .../karaf/boot/sample/simple/SimpleBean.java | 14 -- karaf-boot-starter/README.md | 11 - karaf-boot-starter/pom.xml | 34 --- .../karaf-boot-starter-ds/pom.xml | 41 ++++ karaf-boot-starters/karaf-boot-starter/pom.xml | 46 ++++ karaf-boot-starters/pom.xml | 39 ++++ .../karaf-boot-maven-plugin/pom.xml | 100 +++++---- .../apache/karaf/boot/maven/GenerateMojo.java | 87 ++++++++ .../tools/maven/plugin/FilteredClassFinder.java | 60 ----- .../boot/tools/maven/plugin/GenerateMojo.java | 107 --------- .../boot/tools/maven/plugin/Generator.java | 223 ------------------- .../maven/plugin/OsgiServiceProviderWriter.java | 86 ------- .../boot/tools/maven/plugin/model/Bean.java | 152 ------------- .../boot/tools/maven/plugin/model/BeanRef.java | 69 ------ .../boot/tools/maven/plugin/model/Context.java | 121 ---------- .../plugin/model/JavaxTransactionFactory.java | 40 ---- .../boot/tools/maven/plugin/model/Matcher.java | 23 -- .../maven/plugin/model/OsgiServiceRef.java | 41 ---- .../tools/maven/plugin/model/ProducedBean.java | 13 -- .../boot/tools/maven/plugin/model/Property.java | 90 -------- .../maven/plugin/model/PropertyWriter.java | 23 -- .../plugin/model/SpringTransactionFactory.java | 40 ---- .../maven/plugin/model/TransactionalDef.java | 39 ---- .../resources/META-INF/plexus/components.xml | 61 +++++ .../boot/tools/maven/plugin/GeneratorTest.java | 99 -------- .../boot/tools/maven/plugin/Namespaces.java | 54 ----- .../boot/tools/maven/plugin/model/BeanTest.java | 92 -------- .../tools/maven/plugin/model/ContextTest.java | 84 ------- .../tools/maven/plugin/model/PropertyTest.java | 73 ------ .../maven/plugin/model/TestBeanForRef.java | 39 ---- .../boot/tools/maven/plugin/test/MyBean1.java | 52 ----- .../boot/tools/maven/plugin/test/MyBean3.java | 50 ----- .../boot/tools/maven/plugin/test/MyBean4.java | 13 -- .../tools/maven/plugin/test/MyFactoryBean.java | 17 -- .../tools/maven/plugin/test/MyProduced.java | 18 -- .../tools/maven/plugin/test/ParentBean.java | 33 --- .../boot/tools/maven/plugin/test/ServiceA.java | 23 -- .../tools/maven/plugin/test/ServiceAImpl1.java | 28 --- .../tools/maven/plugin/test/ServiceAImpl2.java | 34 --- .../boot/tools/maven/plugin/test/ServiceB.java | 23 -- .../maven/plugin/test/ServiceReferences.java | 33 --- karaf-boot/README.md | 5 - karaf-boot/pom.xml | 33 --- .../main/java/org/apache/karaf/boot/Arg.java | 53 ----- .../main/java/org/apache/karaf/boot/Bean.java | 79 ------- .../main/java/org/apache/karaf/boot/Bind.java | 31 --- .../java/org/apache/karaf/boot/Destroy.java | 31 --- .../java/org/apache/karaf/boot/Element.java | 43 ---- .../main/java/org/apache/karaf/boot/Init.java | 31 --- .../main/java/org/apache/karaf/boot/Inject.java | 32 --- .../main/java/org/apache/karaf/boot/List.java | 36 --- .../java/org/apache/karaf/boot/Reference.java | 69 ------ .../org/apache/karaf/boot/ReferenceList.java | 67 ------ .../apache/karaf/boot/ReferenceListener.java | 28 --- .../java/org/apache/karaf/boot/Register.java | 31 --- .../apache/karaf/boot/RegistrationListener.java | 29 --- .../java/org/apache/karaf/boot/Service.java | 56 ----- .../org/apache/karaf/boot/ServiceProperty.java | 36 --- .../main/java/org/apache/karaf/boot/Unbind.java | 31 --- .../java/org/apache/karaf/boot/Unregister.java | 31 --- pom.xml | 24 +- 80 files changed, 949 insertions(+), 2866 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/OSGI-INF/karaf-tracker/sample.osgi.service.provider.Activator ---------------------------------------------------------------------- diff --git a/OSGI-INF/karaf-tracker/sample.osgi.service.provider.Activator b/OSGI-INF/karaf-tracker/sample.osgi.service.provider.Activator new file mode 100644 index 0000000..12b26d7 --- /dev/null +++ b/OSGI-INF/karaf-tracker/sample.osgi.service.provider.Activator @@ -0,0 +1 @@ +#Thu Sep 24 22:02:56 CEST 2015 http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-parent/pom.xml ---------------------------------------------------------------------- diff --git a/karaf-boot-parent/pom.xml b/karaf-boot-parent/pom.xml deleted file mode 100644 index 9142128..0000000 --- a/karaf-boot-parent/pom.xml +++ /dev/null @@ -1,73 +0,0 @@ -<?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"> - - <modelVersion>4.0.0</modelVersion> - - <groupId>org.apache.karaf.boot</groupId> - <artifactId>karaf-boot-parent</artifactId> - <version>1.0.0-SNAPSHOT</version> - <packaging>pom</packaging> - - <dependencies> - <dependency> - <groupId>org.apache.karaf.boot</groupId> - <artifactId>karaf-boot</artifactId> - <version>1.0.0-SNAPSHOT</version> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.karaf.boot</groupId> - <artifactId>karaf-boot-maven-plugin</artifactId> - <version>1.0.0-SNAPSHOT</version> - <inherited>true</inherited> - <extensions>true</extensions> - <executions> - <execution> - <phase>generate-resources</phase> - <goals> - <goal>generate</goal> - </goals> - <configuration> - <scanPaths> - <scanPath>${project.build.sourceDirectory}</scanPath> - </scanPaths> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <version>2.5.4</version> - <inherited>true</inherited> - <extensions>true</extensions> - <configuration> - <supportedProjectTypes> - <supportedProjectType>jar</supportedProjectType> - <supportedProjectType>war</supportedProjectType> - </supportedProjectTypes> - </configuration> - <executions> - <execution> - <phase>package</phase> - <goals> - <goal>bundle</goal> - </goals> - <configuration> - <instructions> - <Import-Package> - org.apache.karaf.boot*;resolution:=optional, - * - </Import-Package> - </instructions> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - -</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-samples/README.md ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/README.md b/karaf-boot-samples/README.md index 31be07a..d65c349 100644 --- a/karaf-boot-samples/README.md +++ b/karaf-boot-samples/README.md @@ -1,9 +1,16 @@ -* karaf-boot-simple - Simple bean -* karaf-boot-service-provider - Service provider -* karaf-boot-service-consumer - Service consumer +* karaf-boot-sample-service-provider-osgi + Expose a service using the "native" Karaf OSGi layer (low level) +* karaf-boot-sample-service-consumer-osgi + Use a service using the "native" Karaf OSGi layer (low level) + +* karaf-boot-services-osgi + Simple services using OSGi +* karaf-boot-services-blueprint + Simple services using blueprint +* karaf-boot-services-ds + Simple services using DS/SCR +* karaf-boot-services-cdi + Simple services using CDI * karaf-boot-config-managed Managed by configuration (reload) * karaf-boot-servlet @@ -17,4 +24,4 @@ * karaf-boot-profile Build a profile based on karaf-boot definition * karaf-boot-starter - Package and configure Karaf as a ready to run artifact \ No newline at end of file + Package and configure Karaf as a ready to run artifact http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-samples/karaf-boot-sample-service-consumer-ds/README.md ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/karaf-boot-sample-service-consumer-ds/README.md b/karaf-boot-samples/karaf-boot-sample-service-consumer-ds/README.md new file mode 100644 index 0000000..93f69f7 --- /dev/null +++ b/karaf-boot-samples/karaf-boot-sample-service-consumer-ds/README.md @@ -0,0 +1,33 @@ +== karaf-boot-sample-service-provider-osgi == + +This sample exposes an OSGi service using the Karaf util classe and annotation. + += Design + +This artifact uses the hello service provided by another artifact (karaf-boot-sample-service-provider-ds for instance). + +It uses the DS annotations to create a bean with a reference (@Reference) to the hello service. +In the HelloServiceClient bean, we use the @Activate annotation to execute a specific method. + +You don't think anything else: karaf-boot will generate all the plumbing for you, and you will directly have a ready +to use artifact. + += 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-service-consumer-ds-1.0.jar) in the +Karaf deploy folder +* in the Karaf shell console, do: + + bundle:install -s mvn:karaf-boot-samples/karaf-boot-sample-service-consumer-ds/1.0 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-samples/karaf-boot-sample-service-consumer-ds/pom.xml ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/karaf-boot-sample-service-consumer-ds/pom.xml b/karaf-boot-samples/karaf-boot-sample-service-consumer-ds/pom.xml new file mode 100644 index 0000000..c6b85c0 --- /dev/null +++ b/karaf-boot-samples/karaf-boot-sample-service-consumer-ds/pom.xml @@ -0,0 +1,52 @@ +<?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-service-consumer-ds</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> + <dependency> + <groupId>org.apache.karaf.boot</groupId> + <artifactId>karaf-boot-sample-service-provider-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> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-samples/karaf-boot-sample-service-consumer-ds/src/main/java/sample/ds/service/consumer/HelloServiceClient.java ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/karaf-boot-sample-service-consumer-ds/src/main/java/sample/ds/service/consumer/HelloServiceClient.java b/karaf-boot-samples/karaf-boot-sample-service-consumer-ds/src/main/java/sample/ds/service/consumer/HelloServiceClient.java new file mode 100644 index 0000000..f70ebf7 --- /dev/null +++ b/karaf-boot-samples/karaf-boot-sample-service-consumer-ds/src/main/java/sample/ds/service/consumer/HelloServiceClient.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 sample.ds.service.consumer; + +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; +import sample.ds.service.provider.HelloService; + +@Component +public class HelloServiceClient implements Runnable { + + private HelloService helloService; + + private Thread thread; + + @Activate + public void start() { + thread = new Thread(this); + thread.start(); + } + + @Deactivate + public void stop() { + thread.interrupt(); + } + + public void run() { + while (true) { + System.out.println(helloService.hello("World")); + try { + Thread.sleep(5000); + } catch (Exception e) { + // nothing to do + } + } + } + + @Reference + public void setHelloService(HelloService helloService) { + this.helloService = helloService; + } + +} http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-samples/karaf-boot-sample-service-consumer-osgi/README.md ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/karaf-boot-sample-service-consumer-osgi/README.md b/karaf-boot-samples/karaf-boot-sample-service-consumer-osgi/README.md new file mode 100644 index 0000000..1684c81 --- /dev/null +++ b/karaf-boot-samples/karaf-boot-sample-service-consumer-osgi/README.md @@ -0,0 +1,28 @@ +== karaf-boot-sample-service-consumer-osgi == + +This sample uses an OSGi service using the Karaf util classe and annotation. + += Design + +The service "contract" is exposed by another artifact (the karaf-boot-sample-service-provider-osgi module). + +The hello service is retrieved in the Activator of this artifact, and uses it directly. + +This Activator overrides the doStart() method, where we retrieve the HelloService using the getTrackedService() method. Karaf +deals with all service lookup and tracking. + += Build + +To build, simply do: + + mvn clean install + += Deploy + +To deploy in Karaf: + +* you can drop the generated jar file (target/karaf-boot-sample-service-provider-osgi-1.0.jar) in the +Karaf deploy folder +* in the Karaf shell console, do: + + bundle:install -s mvn:karaf-boot-samples/karaf-boot-sample-service-consumer-osgi/1.0 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-samples/karaf-boot-sample-service-consumer-osgi/pom.xml ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/karaf-boot-sample-service-consumer-osgi/pom.xml b/karaf-boot-samples/karaf-boot-sample-service-consumer-osgi/pom.xml new file mode 100644 index 0000000..c26cfbf --- /dev/null +++ b/karaf-boot-samples/karaf-boot-sample-service-consumer-osgi/pom.xml @@ -0,0 +1,52 @@ +<?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-service-consumer-osgi</artifactId> + <version>1.0.0-SNAPSHOT</version> + + <dependencies> + <dependency> + <groupId>org.apache.karaf.boot</groupId> + <artifactId>karaf-boot-starter</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.karaf.boot</groupId> + <artifactId>karaf-boot-sample-service-provider-osgi</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> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-samples/karaf-boot-sample-service-consumer-osgi/src/main/java/sample/osgi/service/consumer/Activator.java ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/karaf-boot-sample-service-consumer-osgi/src/main/java/sample/osgi/service/consumer/Activator.java b/karaf-boot-samples/karaf-boot-sample-service-consumer-osgi/src/main/java/sample/osgi/service/consumer/Activator.java new file mode 100644 index 0000000..fffd850 --- /dev/null +++ b/karaf-boot-samples/karaf-boot-sample-service-consumer-osgi/src/main/java/sample/osgi/service/consumer/Activator.java @@ -0,0 +1,48 @@ +/** + * 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.osgi.service.consumer; + +import org.apache.karaf.util.tracker.BaseActivator; +import org.apache.karaf.util.tracker.annotation.RequireService; +import org.apache.karaf.util.tracker.annotation.Services; +import sample.osgi.service.provider.HelloService; + +/** + * Simple activator that retrieve the hello service and use it. + */ +@Services( + requires = { + @RequireService(HelloService.class) + } +) +public class Activator extends BaseActivator { + + @Override + public void doStart() throws Exception { + HelloService helloService = getTrackedService(HelloService.class); + + // basic usage, in real life, it could be injected and used in a bean or whatever + System.out.println("Hello " + helloService.hello("World")); + } + + @Override + public void doStop() { + super.doStop(); + } + + +} http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-samples/karaf-boot-sample-service-provider-ds/README.md ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/karaf-boot-sample-service-provider-ds/README.md b/karaf-boot-samples/karaf-boot-sample-service-provider-ds/README.md new file mode 100644 index 0000000..0206a7b --- /dev/null +++ b/karaf-boot-samples/karaf-boot-sample-service-provider-ds/README.md @@ -0,0 +1,35 @@ +== karaf-boot-sample-service-provider-ds == + +This sample exposes an OSGi service using the Karaf util classe and annotation. + += Design + +The service "contract" is describe by the Hello interface. It's a very simple service that expose one operation (hello). +The service client send a message (String) to the hello service and he gets a response. + +The HelloServiceImpl is very simple: it prefixes the message with "Hello". + +We use the @Component DS annotation on HelloServiceImpl implementation in order to expose the service. + +You don't think anything else: karaf-boot will generate all the plumbing for you, and you will directly have a ready +to use artifact. + += 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-service-provider-ds-1.0.jar) in the +Karaf deploy folder +* in the Karaf shell console, do: + + bundle:install -s mvn:karaf-boot-samples/karaf-boot-sample-service-provider-ds/1.0 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-samples/karaf-boot-sample-service-provider-ds/pom.xml ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/karaf-boot-sample-service-provider-ds/pom.xml b/karaf-boot-samples/karaf-boot-sample-service-provider-ds/pom.xml new file mode 100644 index 0000000..854a780 --- /dev/null +++ b/karaf-boot-samples/karaf-boot-sample-service-provider-ds/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-service-provider-ds</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> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-samples/karaf-boot-sample-service-provider-ds/src/main/java/sample/ds/service/provider/HelloService.java ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/karaf-boot-sample-service-provider-ds/src/main/java/sample/ds/service/provider/HelloService.java b/karaf-boot-samples/karaf-boot-sample-service-provider-ds/src/main/java/sample/ds/service/provider/HelloService.java new file mode 100644 index 0000000..50c2d30 --- /dev/null +++ b/karaf-boot-samples/karaf-boot-sample-service-provider-ds/src/main/java/sample/ds/service/provider/HelloService.java @@ -0,0 +1,26 @@ +/** + * 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.ds.service.provider; + +/** + * Simple hello service contract. + */ +public interface HelloService { + + public String hello(String message); + +} http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-samples/karaf-boot-sample-service-provider-ds/src/main/java/sample/ds/service/provider/HelloServiceImpl.java ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/karaf-boot-sample-service-provider-ds/src/main/java/sample/ds/service/provider/HelloServiceImpl.java b/karaf-boot-samples/karaf-boot-sample-service-provider-ds/src/main/java/sample/ds/service/provider/HelloServiceImpl.java new file mode 100644 index 0000000..5319a47 --- /dev/null +++ b/karaf-boot-samples/karaf-boot-sample-service-provider-ds/src/main/java/sample/ds/service/provider/HelloServiceImpl.java @@ -0,0 +1,31 @@ +/** + * 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.ds.service.provider; + +import org.osgi.service.component.annotations.Component; + +/** + * Simple implementation of the hello service.. + */ +@Component +public class HelloServiceImpl implements HelloService { + + public String hello(String message) { + return "Hello " + message + " !"; + } + +} http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-samples/karaf-boot-sample-service-provider-osgi/README.md ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/karaf-boot-sample-service-provider-osgi/README.md b/karaf-boot-samples/karaf-boot-sample-service-provider-osgi/README.md new file mode 100644 index 0000000..3cd81c6 --- /dev/null +++ b/karaf-boot-samples/karaf-boot-sample-service-provider-osgi/README.md @@ -0,0 +1,33 @@ +== karaf-boot-sample-service-provider-osgi == + +This sample exposes an OSGi service using the Karaf util classe and annotation. + += Design + +The service "contract" is describe by the Hello interface. It's a very simple service that expose one operation (hello). +The service client send a message (String) to the hello service and he gets a response. + +The HelloServiceImpl is very simple: it prefixes the message with "Hello". + +In order to expose this service, we create an Activator, extending Karaf util BaseActivator. +Our activator contains the @Services annotation describing the provided services (@ProvideService annotation). + +In this activator, we override the doStart() method, where we instantiate the HelloServiceImpl bean and register the +HelloService service using the register() method (provided by Karaf). The Karaf BaseActivator manages the service +registration, so you don't have to take care about the unregistration of the service, etc. + += Build + +To build, simply do: + + mvn clean install + += Deploy + +To deploy in Karaf: + +* you can drop the generated jar file (target/karaf-boot-sample-service-provider-osgi-1.0.jar) in the +Karaf deploy folder +* in the Karaf shell console, do: + + bundle:install -s mvn:karaf-boot-samples/karaf-boot-sample-service-provider-osgi/1.0 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-samples/karaf-boot-sample-service-provider-osgi/pom.xml ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/karaf-boot-sample-service-provider-osgi/pom.xml b/karaf-boot-samples/karaf-boot-sample-service-provider-osgi/pom.xml new file mode 100644 index 0000000..d1bb116 --- /dev/null +++ b/karaf-boot-samples/karaf-boot-sample-service-provider-osgi/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-service-provider-osgi</artifactId> + <version>1.0.0-SNAPSHOT</version> + + <dependencies> + <dependency> + <groupId>org.apache.karaf.boot</groupId> + <artifactId>karaf-boot-starter</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/87577122/karaf-boot-samples/karaf-boot-sample-service-provider-osgi/src/main/java/sample/osgi/service/provider/Activator.java ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/karaf-boot-sample-service-provider-osgi/src/main/java/sample/osgi/service/provider/Activator.java b/karaf-boot-samples/karaf-boot-sample-service-provider-osgi/src/main/java/sample/osgi/service/provider/Activator.java new file mode 100644 index 0000000..9bc9b20 --- /dev/null +++ b/karaf-boot-samples/karaf-boot-sample-service-provider-osgi/src/main/java/sample/osgi/service/provider/Activator.java @@ -0,0 +1,41 @@ +/** + * 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.osgi.service.provider; + +import org.apache.karaf.util.tracker.BaseActivator; +import org.apache.karaf.util.tracker.annotation.ProvideService; +import org.apache.karaf.util.tracker.annotation.Services; + +/** + * Simple activator registering the hello service. + */ +@Services( + provides = { + @ProvideService(HelloService.class) + } +) +public class Activator extends BaseActivator { + + @Override + public void doStart() throws Exception { + // create hello service bean + HelloServiceImpl bean = new HelloServiceImpl(); + // register the hello service + register(HelloService.class, bean); + } + +} http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-samples/karaf-boot-sample-service-provider-osgi/src/main/java/sample/osgi/service/provider/HelloService.java ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/karaf-boot-sample-service-provider-osgi/src/main/java/sample/osgi/service/provider/HelloService.java b/karaf-boot-samples/karaf-boot-sample-service-provider-osgi/src/main/java/sample/osgi/service/provider/HelloService.java new file mode 100644 index 0000000..fc0a357 --- /dev/null +++ b/karaf-boot-samples/karaf-boot-sample-service-provider-osgi/src/main/java/sample/osgi/service/provider/HelloService.java @@ -0,0 +1,26 @@ +/** + * 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.osgi.service.provider; + +/** + * Simple hello service contract. + */ +public interface HelloService { + + public String hello(String message); + +} http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-samples/karaf-boot-sample-service-provider-osgi/src/main/java/sample/osgi/service/provider/HelloServiceImpl.java ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/karaf-boot-sample-service-provider-osgi/src/main/java/sample/osgi/service/provider/HelloServiceImpl.java b/karaf-boot-samples/karaf-boot-sample-service-provider-osgi/src/main/java/sample/osgi/service/provider/HelloServiceImpl.java new file mode 100644 index 0000000..c212205 --- /dev/null +++ b/karaf-boot-samples/karaf-boot-sample-service-provider-osgi/src/main/java/sample/osgi/service/provider/HelloServiceImpl.java @@ -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. + */ +package sample.osgi.service.provider; + +/** + * Simple implementation of the hello service.. + */ +public class HelloServiceImpl implements HelloService { + + public String hello(String message) { + return "Hello " + message + " !"; + } + +} http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-samples/karaf-boot-sample-simple/pom.xml ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/karaf-boot-sample-simple/pom.xml b/karaf-boot-samples/karaf-boot-sample-simple/pom.xml deleted file mode 100644 index 538503d..0000000 --- a/karaf-boot-samples/karaf-boot-sample-simple/pom.xml +++ /dev/null @@ -1,33 +0,0 @@ -<?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> - - <parent> - <groupId>org.apache.karaf.boot</groupId> - <artifactId>karaf-boot-parent</artifactId> - <version>1.0.0-SNAPSHOT</version> - </parent> - - <artifactId>karaf-boot-sample-simple</artifactId> - <version>1.0.0-SNAPSHOT</version> - -</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-samples/karaf-boot-sample-simple/src/main/java/org/apache/karaf/boot/sample/simple/SimpleBean.java ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/karaf-boot-sample-simple/src/main/java/org/apache/karaf/boot/sample/simple/SimpleBean.java b/karaf-boot-samples/karaf-boot-sample-simple/src/main/java/org/apache/karaf/boot/sample/simple/SimpleBean.java deleted file mode 100644 index b89f733..0000000 --- a/karaf-boot-samples/karaf-boot-sample-simple/src/main/java/org/apache/karaf/boot/sample/simple/SimpleBean.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.apache.karaf.boot.sample.simple; - -import org.apache.karaf.boot.Bean; -import org.apache.karaf.boot.Init; - -@Bean(id = "simple-bean") -public class SimpleBean { - - @Init - public void simple() { - System.out.println("Hello world"); - } - -} http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-starter/README.md ---------------------------------------------------------------------- diff --git a/karaf-boot-starter/README.md b/karaf-boot-starter/README.md deleted file mode 100644 index 43dc8e3..0000000 --- a/karaf-boot-starter/README.md +++ /dev/null @@ -1,11 +0,0 @@ -Karaf Boot Starter ------------------- -Karaf Boot Starter provides a convenient way to create a ready to execute artifact, embedding Karaf. - -You just have to extend the KarafApplication class. In the config() method, you can define: -- the configuration -- the bundles -- the features -of your embedded Karaf instance. - -The Karaf Boot Starter Maven plugin will create the "key turn" jar that you can execute directly, on any machine. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-starter/pom.xml ---------------------------------------------------------------------- diff --git a/karaf-boot-starter/pom.xml b/karaf-boot-starter/pom.xml deleted file mode 100644 index 20fd28e..0000000 --- a/karaf-boot-starter/pom.xml +++ /dev/null @@ -1,34 +0,0 @@ -<?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> - - <parent> - <groupId>org.apache.karaf.boot</groupId> - <artifactId>karaf-boot-build</artifactId> - <version>1.0.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <artifactId>karaf-boot-starter</artifactId> - <packaging>pom</packaging> - -</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/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 new file mode 100644 index 0000000..9add66a --- /dev/null +++ b/karaf-boot-starters/karaf-boot-starter-ds/pom.xml @@ -0,0 +1,41 @@ +<?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> + + <parent> + <groupId>org.apache.karaf.boot</groupId> + <artifactId>karaf-boot-starters</artifactId> + <version>1.0.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>karaf-boot-starter-ds</artifactId> + + <dependencies> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.compendium</artifactId> + <version>5.0.0</version> + </dependency> + </dependencies> + +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-starters/karaf-boot-starter/pom.xml ---------------------------------------------------------------------- diff --git a/karaf-boot-starters/karaf-boot-starter/pom.xml b/karaf-boot-starters/karaf-boot-starter/pom.xml new file mode 100644 index 0000000..21c0d07 --- /dev/null +++ b/karaf-boot-starters/karaf-boot-starter/pom.xml @@ -0,0 +1,46 @@ +<?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> + + <parent> + <groupId>org.apache.karaf.boot</groupId> + <artifactId>karaf-boot-starters</artifactId> + <version>1.0.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>karaf-boot-starter</artifactId> + + <dependencies> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + <version>${osgi.version}</version> + </dependency> + <dependency> + <groupId>org.apache.karaf</groupId> + <artifactId>org.apache.karaf.util</artifactId> + <version>${karaf.version}</version> + </dependency> + </dependencies> + +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-starters/pom.xml ---------------------------------------------------------------------- diff --git a/karaf-boot-starters/pom.xml b/karaf-boot-starters/pom.xml new file mode 100644 index 0000000..04f6ff4 --- /dev/null +++ b/karaf-boot-starters/pom.xml @@ -0,0 +1,39 @@ +<?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> + + <parent> + <groupId>org.apache.karaf.boot</groupId> + <artifactId>karaf-boot-build</artifactId> + <version>1.0.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>karaf-boot-starters</artifactId> + <packaging>pom</packaging> + + <modules> + <module>karaf-boot-starter</module> + <module>karaf-boot-starter-ds</module> + </modules> + +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-tools/karaf-boot-maven-plugin/pom.xml ---------------------------------------------------------------------- diff --git a/karaf-boot-tools/karaf-boot-maven-plugin/pom.xml b/karaf-boot-tools/karaf-boot-maven-plugin/pom.xml index 19bb184..8897be1 100644 --- a/karaf-boot-tools/karaf-boot-maven-plugin/pom.xml +++ b/karaf-boot-tools/karaf-boot-maven-plugin/pom.xml @@ -1,6 +1,24 @@ <?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> <parent> @@ -15,63 +33,53 @@ <dependencies> <dependency> - <groupId>javax.inject</groupId> - <artifactId>javax.inject</artifactId> - <version>1</version> - </dependency> - <dependency> - <groupId>org.apache.xbean</groupId> - <artifactId>xbean-finder-shaded</artifactId> - <version>4.0</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context</artifactId> - <version>4.1.0.RELEASE</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-tx</artifactId> - <version>4.1.0.RELEASE</version> - </dependency> - <dependency> - <groupId>javax.persistence</groupId> - <artifactId>persistence-api</artifactId> - <version>1.0.2</version> - </dependency> - <dependency> - <groupId>javax.transaction</groupId> - <artifactId>javax.transaction-api</artifactId> - <version>1.2</version> - </dependency> - <dependency> - <groupId>org.ops4j.pax.cdi</groupId> - <artifactId>pax-cdi-api</artifactId> - <version>0.9.0</version> - </dependency> - <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-api</artifactId> <version>3.1.1</version> </dependency> <dependency> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-annotations</artifactId> + <version>3.3</version> + </dependency> + <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-core</artifactId> <version>3.1.1</version> </dependency> - - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.12</version> - <scope>test</scope> - </dependency> <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <version>2.4</version> - <scope>test</scope> + <groupId>org.apache.maven</groupId> + <artifactId>maven-model</artifactId> + <version>3.2.1</version> </dependency> </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-plugin-plugin</artifactId> + <version>3.3</version> + <configuration> + <goalPrefix>karaf-boot</goalPrefix> + <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> + </configuration> + <executions> + <execution> + <id>generate-descriptor</id> + <goals> + <goal>descriptor</goal> + </goals> + </execution> + <execution> + <id>generate-helpmojo</id> + <goals> + <goal>helpmojo</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/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 new file mode 100644 index 0000000..da9414d --- /dev/null +++ b/karaf-boot-tools/karaf-boot-maven-plugin/src/main/java/org/apache/karaf/boot/maven/GenerateMojo.java @@ -0,0 +1,87 @@ +package org.apache.karaf.boot.maven; + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Plugin; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.descriptor.*; +import org.apache.maven.plugins.annotations.*; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.codehaus.plexus.util.xml.Xpp3DomBuilder; + +import java.io.ByteArrayInputStream; + +@Mojo(name = "generate", threadSafe = true, defaultPhase = LifecyclePhase.PROCESS_CLASSES, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, inheritByDefault = false) +public class GenerateMojo extends AbstractMojo { + + @Parameter(defaultValue = "${project}", required = true, readonly = true) + private MavenProject mavenProject; + + @Parameter(defaultValue = "${session}", required = true, readonly = true) + private MavenSession mavenSession; + + @Component + private BuildPluginManager pluginManager; + + public void execute() throws MojoExecutionException { + try { + // invoke Karaf services plugin + getLog().info("Invoking karaf-services-maven-plugin"); + Plugin karafServicesPlugin = new Plugin(); + karafServicesPlugin.setGroupId("org.apache.karaf.tooling"); + karafServicesPlugin.setArtifactId("karaf-services-maven-plugin"); + karafServicesPlugin.setVersion("4.0.1"); + karafServicesPlugin.setInherited(false); + karafServicesPlugin.setExtensions(true); + Xpp3Dom configuration = Xpp3DomBuilder.build(new ByteArrayInputStream(("<configuration>" + + "<project>${project}</project>" + + "<activatorProperty>BNDExtension-Bundle-Activator</activatorProperty>" + + "<requirementsProperty>BNDExtension-Require-Capability</requirementsProperty>" + + "<capabilitiesProperty>BNDExtension-Provide-Capability</capabilitiesProperty>" + + "<outputDirectory>${project.build.directory}/generated/karaf-tracker</outputDirectory>" + + "<classLoader>project</classLoader>" + + "</configuration>").getBytes()), "UTF-8"); + PluginDescriptor karafServicesPluginDescriptor = pluginManager.loadPlugin(karafServicesPlugin, mavenProject.getRemotePluginRepositories(), mavenSession.getRepositorySession()); + MojoDescriptor karafServicesMojoDescriptor = karafServicesPluginDescriptor.getMojo("service-metadata-generate"); + MojoExecution execution = new MojoExecution(karafServicesMojoDescriptor, configuration); + pluginManager.executeMojo(mavenSession, execution); + + // invoke Felix bundle plugin + getLog().info("Invoking maven-bundle-plugin"); + Plugin felixBundlePlugin = new Plugin(); + felixBundlePlugin.setGroupId("org.apache.felix"); + felixBundlePlugin.setArtifactId("maven-bundle-plugin"); + felixBundlePlugin.setVersion("3.0.0"); + felixBundlePlugin.setInherited(true); + felixBundlePlugin.setExtensions(true); + // TODO if jpa-start is provided as persistence.xml location + configuration = Xpp3DomBuilder.build(new ByteArrayInputStream(("<configuration>" + + "<finalName>${project.build.finalName}</finalName>" + + "<outputDirectory>${project.build.outputDirectory}</outputDirectory>" + + "<m_mavenSession>${session}</m_mavenSession>" + + "<project>${project}</project>" + + "<buildDirectory>${project.build.directory}</buildDirectory>" + + "<supportedProjectTypes>" + + "<supportedProjectType>jar</supportedProjectType>" + + "<supportedProjectType>bundle</supportedProjectType>" + + "<supportedProjectType>war</supportedProjectType>" + + "</supportedProjectTypes>" + + "<instructions>" + + "<Private-Package>org.apache.karaf.util.tracker</Private-Package>" + + "<_dsannotations>*</_dsannotations>" + + "</instructions>" + + "</configuration>").getBytes()), "UTF-8"); + PluginDescriptor felixBundlePluginDescriptor = pluginManager.loadPlugin(felixBundlePlugin, mavenProject.getRemotePluginRepositories(), mavenSession.getRepositorySession()); + MojoDescriptor felixBundleMojoDescriptor = felixBundlePluginDescriptor.getMojo("bundle"); + execution = new MojoExecution(felixBundleMojoDescriptor, configuration); + pluginManager.executeMojo(mavenSession, execution); + } catch (Exception e) { + throw new MojoExecutionException("karaf-boot-maven-plugin failed", e); + } + } + +} http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-tools/karaf-boot-maven-plugin/src/main/java/org/apache/karaf/boot/tools/maven/plugin/FilteredClassFinder.java ---------------------------------------------------------------------- diff --git a/karaf-boot-tools/karaf-boot-maven-plugin/src/main/java/org/apache/karaf/boot/tools/maven/plugin/FilteredClassFinder.java b/karaf-boot-tools/karaf-boot-maven-plugin/src/main/java/org/apache/karaf/boot/tools/maven/plugin/FilteredClassFinder.java deleted file mode 100644 index 7ba607b..0000000 --- a/karaf-boot-tools/karaf-boot-maven-plugin/src/main/java/org/apache/karaf/boot/tools/maven/plugin/FilteredClassFinder.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * 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.karaf.boot.tools.maven.plugin; - -import java.lang.annotation.Annotation; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -import javax.inject.Singleton; - -import org.apache.xbean.finder.ClassFinder; -import org.springframework.stereotype.Component; - -public class FilteredClassFinder { - - @SuppressWarnings("unchecked") - public static Set<Class<?>> findClasses(ClassFinder finder, Collection<String> packageNames) { - return findClasses(finder, packageNames, new Class[]{Singleton.class, Component.class}); - } - - public static Set<Class<?>> findClasses(ClassFinder finder, Collection<String> packageNames, Class<? extends Annotation>[] annotations) { - Set<Class<?>> rawClasses = new HashSet<Class<?>>(); - for (Class<? extends Annotation> annotation : annotations) { - rawClasses.addAll(finder.findAnnotatedClasses(annotation)); - } - return filterByBasePackages(rawClasses, packageNames); - } - - private static Set<Class<?>> filterByBasePackages(Set<Class<?>> rawClasses, Collection<String> packageNames) { - Set<Class<?>> filteredClasses = new HashSet<Class<?>>(); - for (Class<?> clazz : rawClasses) { - for (String packageName : packageNames) { - if (clazz.getPackage().getName().startsWith(packageName)) { - filteredClasses.add(clazz); - continue; - } - } - } - //System.out.println("Raw: " + rawClasses); - //System.out.println("Filtered: " + beanClasses); - return filteredClasses; - } -} http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-tools/karaf-boot-maven-plugin/src/main/java/org/apache/karaf/boot/tools/maven/plugin/GenerateMojo.java ---------------------------------------------------------------------- diff --git a/karaf-boot-tools/karaf-boot-maven-plugin/src/main/java/org/apache/karaf/boot/tools/maven/plugin/GenerateMojo.java b/karaf-boot-tools/karaf-boot-maven-plugin/src/main/java/org/apache/karaf/boot/tools/maven/plugin/GenerateMojo.java deleted file mode 100644 index 72d5f28..0000000 --- a/karaf-boot-tools/karaf-boot-maven-plugin/src/main/java/org/apache/karaf/boot/tools/maven/plugin/GenerateMojo.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * 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.karaf.boot.tools.maven.plugin; - -import java.io.File; -import java.io.FileOutputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import org.apache.karaf.boot.tools.maven.plugin.model.Context; -import org.apache.maven.artifact.Artifact; -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.apache.xbean.finder.ClassFinder; - -/** - * Generates blueprint from spring annotations - * @goal generate - * @phase process-classes - * @requiresDependencyResolution compile - * @inheritByDefault false - * @description Generates artifact using karaf-boot annotations and supporting spring annotations @Component, @Autowire and @Value - */ -public class GenerateMojo extends AbstractMojo { - - /** - * The maven project. - * - * @parameter default-value="${project}" - * @required - */ - protected MavenProject project; - - /** - * @parameter - * @required - */ - protected List<String> scanPaths; - - /** - * true: Purely annotated mode (needs jpa 2.1.0 and transaction-blueprint 1.1.0) - * false: XML based mode for JPA 1.x and transaction-blueprint < 1.1.0 - * @parameter default-value="true" - * @required - */ - protected boolean persistenceAnnotated; - - public void execute() throws MojoExecutionException, MojoFailureException { - try { - String buildDir = project.getBuild().getDirectory(); - String generatedDir = buildDir + "/generated-resources"; - Resource resource = new Resource(); - resource.setDirectory(generatedDir); - project.addResource(resource); - ClassFinder finder = createProjectScopeFinder(); - - File file = new File(generatedDir, "OSGI-INF/blueprint/autowire.xml"); - file.getParentFile().mkdirs(); - System.out.println("Generating blueprint to " + file); - Set<Class<?>> classes = FilteredClassFinder.findClasses(finder, scanPaths); - Context context = new Context(classes); - context.resolve(); - new Generator(context, new FileOutputStream(file), persistenceAnnotated).generate(); - } catch (Exception e) { - throw new MojoExecutionException("Error building commands help", e); - } - } - - private ClassFinder createProjectScopeFinder() throws MalformedURLException { - List<URL> urls = new ArrayList<URL>(); - - urls.add( new File(project.getBuild().getOutputDirectory()).toURI().toURL() ); - for ( Object artifactO : project.getArtifacts() ) { - Artifact artifact = (Artifact)artifactO; - File file = artifact.getFile(); - if ( file != null ) { - urls.add( file.toURI().toURL() ); - } - } - ClassLoader loader = new URLClassLoader(urls.toArray(new URL[urls.size()]), getClass().getClassLoader()); - return new ClassFinder(loader, urls); - } - -} http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-tools/karaf-boot-maven-plugin/src/main/java/org/apache/karaf/boot/tools/maven/plugin/Generator.java ---------------------------------------------------------------------- diff --git a/karaf-boot-tools/karaf-boot-maven-plugin/src/main/java/org/apache/karaf/boot/tools/maven/plugin/Generator.java b/karaf-boot-tools/karaf-boot-maven-plugin/src/main/java/org/apache/karaf/boot/tools/maven/plugin/Generator.java deleted file mode 100644 index 8806d05..0000000 --- a/karaf-boot-tools/karaf-boot-maven-plugin/src/main/java/org/apache/karaf/boot/tools/maven/plugin/Generator.java +++ /dev/null @@ -1,223 +0,0 @@ -/** - * 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.karaf.boot.tools.maven.plugin; - -import java.io.OutputStream; -import java.lang.reflect.Field; - -import javax.persistence.PersistenceContext; -import javax.persistence.PersistenceUnit; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamWriter; - -import org.apache.karaf.boot.tools.maven.plugin.model.Bean; -import org.apache.karaf.boot.tools.maven.plugin.model.Context; -import org.apache.karaf.boot.tools.maven.plugin.model.OsgiServiceRef; -import org.apache.karaf.boot.tools.maven.plugin.model.ProducedBean; -import org.apache.karaf.boot.tools.maven.plugin.model.Property; -import org.apache.karaf.boot.tools.maven.plugin.model.PropertyWriter; -import org.apache.karaf.boot.tools.maven.plugin.model.TransactionalDef; - -public class Generator implements PropertyWriter { - private static final String NS_BLUEPRINT = "http://www.osgi.org/xmlns/blueprint/v1.0.0"; - private static final String NS_EXT = "http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"; - private static final String NS_JPA = "http://aries.apache.org/xmlns/jpa/v1.1.0"; - private static final String NS_JPA2 = "http://aries.apache.org/xmlns/jpan/v1.0.0"; - private static final String NS_TX = "http://aries.apache.org/xmlns/transactions/v1.2.0"; - - private Context context; - private XMLStreamWriter writer; - private boolean persistenceAnnotated; - - public Generator(Context context, OutputStream os, boolean persistenceAnnotated) throws XMLStreamException { - this.context = context; - this.persistenceAnnotated = persistenceAnnotated; - - XMLOutputFactory factory = XMLOutputFactory.newInstance(); - writer = factory.createXMLStreamWriter(os); - } - - public void generate() { - try { - writer.writeStartDocument(); - writer.writeCharacters("\n"); - writeBlueprint(); - - if (persistenceAnnotated) { - if (isJpaUsed()) { - writer.writeEmptyElement(NS_JPA2, "enable"); - writer.writeCharacters("\n"); - } - writer.writeEmptyElement(NS_TX, "enable-annotations"); - writer.writeCharacters("\n"); - //if (isJtaUsed()) { -// writer.writeEmptyElement(NS_TX, "enable-annotations"); - //} - } - for (Bean bean : context.getBeans()) { - writeBeanStart(bean); - bean.writeProperties(this); - writer.writeEndElement(); - writer.writeCharacters("\n"); - } - - writeServiceRefs(); - new OsgiServiceProviderWriter(writer).write(context.getBeans()); - - writer.writeEndElement(); - writer.writeCharacters("\n"); - writer.writeEndDocument(); - writer.writeCharacters("\n"); - writer.close(); - } catch (XMLStreamException e) { - throw new RuntimeException(e.getMessage(), e); - } - } - - private boolean isJpaUsed() { - boolean jpaUsed = false; - for (Bean bean : context.getBeans()) { - if (bean.persistenceFields.length > 0) { - jpaUsed = true; - } - } - return jpaUsed; - } - - private boolean isJtaUsed() { - boolean jtaUsed = false; - for (Bean bean : context.getBeans()) { - if (bean.transactionDef != null) { - jtaUsed = true; - } - - } - return jtaUsed; - } - - private void writeBlueprint() throws XMLStreamException { - writer.writeStartElement("blueprint"); - writer.writeDefaultNamespace(NS_BLUEPRINT); - writer.writeNamespace("ext", NS_EXT); - if (persistenceAnnotated) { - writer.writeNamespace("jpa", NS_JPA2); - } else { - writer.writeNamespace("jpa", NS_JPA); - } - writer.writeNamespace("tx", NS_TX); - } - - public void writeBeanStart(Bean bean) throws XMLStreamException { - writer.writeStartElement("bean"); - writer.writeAttribute("id", bean.id); - writer.writeAttribute("class", bean.clazz.getName()); - writer.writeAttribute("ext", NS_EXT, "field-injection", "true"); - if (bean instanceof ProducedBean) { - writeFactory((ProducedBean)bean); - } - if (bean.initMethod != null) { - writer.writeAttribute("init-method", bean.initMethod); - } - if (bean.destroyMethod != null) { - writer.writeAttribute("destroy-method", bean.destroyMethod); - } - writer.writeCharacters("\n"); - - if (!persistenceAnnotated) { - writeTransactional(bean.transactionDef); - writePersistenceFields(bean.persistenceFields); - } - } - - private void writeFactory(ProducedBean bean) throws XMLStreamException { - writer.writeAttribute("factory-ref", bean.factoryBeanId); - writer.writeAttribute("factory-method", bean.factoryMethod); - } - - private void writeTransactional(TransactionalDef transactionDef) - throws XMLStreamException { - if (transactionDef != null) { - writer.writeCharacters(" "); - writer.writeEmptyElement("tx", "transaction", NS_TX); - writer.writeAttribute("method", transactionDef.getMethod()); - writer.writeAttribute("value", transactionDef.getType()); - writer.writeCharacters("\n"); - } - } - - - private void writePersistenceFields(Field[] fields) throws XMLStreamException { - for (Field field : fields) { - writePersistenceField(field); - } - } - - private void writePersistenceField(Field field) throws XMLStreamException { - PersistenceContext persistenceContext = field.getAnnotation(PersistenceContext.class); - if (persistenceContext != null) { - writer.writeCharacters(" "); - writer.writeEmptyElement("jpa", "context", NS_JPA); - writer.writeAttribute("unitname", persistenceContext.unitName()); - writer.writeAttribute("property", field.getName()); - writer.writeCharacters("\n"); - } - PersistenceUnit persistenceUnit = field.getAnnotation(PersistenceUnit.class); - if (persistenceUnit != null) { - writer.writeCharacters(" "); - writer.writeEmptyElement("jpa", "unit", NS_JPA); - writer.writeAttribute("unitname", persistenceUnit.unitName()); - writer.writeAttribute("property", field.getName()); - writer.writeCharacters("\n"); - } - } - - private void writeServiceRefs() throws XMLStreamException { - for (OsgiServiceRef serviceBean : context.getServiceRefs()) { - writeServiceRef(serviceBean); - } - } - - private void writeServiceRef(OsgiServiceRef serviceBean) throws XMLStreamException { - writer.writeEmptyElement("reference"); - writer.writeAttribute("id", serviceBean.id); - writer.writeAttribute("interface", serviceBean.clazz.getName()); - if (serviceBean.filter != null && !"".equals(serviceBean.filter)) { - writer.writeAttribute("filter", serviceBean.filter); - } - writer.writeCharacters("\n"); - } - - public void writeProperty(Property property) { - try { - writer.writeCharacters(" "); - writer.writeEmptyElement("property"); - writer.writeAttribute("name", property.name); - if (property.ref != null) { - writer.writeAttribute("ref", property.ref); - } else if (property.value != null) { - writer.writeAttribute("value", property.value); - } - writer.writeCharacters("\n"); - } catch (XMLStreamException e) { - throw new RuntimeException(e.getMessage(), e); - } - } - -} http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/87577122/karaf-boot-tools/karaf-boot-maven-plugin/src/main/java/org/apache/karaf/boot/tools/maven/plugin/OsgiServiceProviderWriter.java ---------------------------------------------------------------------- diff --git a/karaf-boot-tools/karaf-boot-maven-plugin/src/main/java/org/apache/karaf/boot/tools/maven/plugin/OsgiServiceProviderWriter.java b/karaf-boot-tools/karaf-boot-maven-plugin/src/main/java/org/apache/karaf/boot/tools/maven/plugin/OsgiServiceProviderWriter.java deleted file mode 100644 index 95d57df..0000000 --- a/karaf-boot-tools/karaf-boot-maven-plugin/src/main/java/org/apache/karaf/boot/tools/maven/plugin/OsgiServiceProviderWriter.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * 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.karaf.boot.tools.maven.plugin; - -import java.util.Collection; - -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamWriter; - -import org.apache.karaf.boot.tools.maven.plugin.model.Bean; -import org.ops4j.pax.cdi.api.OsgiServiceProvider; -import org.ops4j.pax.cdi.api.Properties; -import org.ops4j.pax.cdi.api.Property; - -public class OsgiServiceProviderWriter { - private XMLStreamWriter writer; - - public OsgiServiceProviderWriter(XMLStreamWriter writer) { - this.writer = writer; - } - - public void write(Collection<Bean> beans) throws XMLStreamException { - for (Bean bean : beans) { - write(bean); - } - } - - public void write(Bean bean) throws XMLStreamException { - OsgiServiceProvider serviceProvider = bean.clazz.getAnnotation(OsgiServiceProvider.class); - if (serviceProvider == null) { - return; - } - if (serviceProvider.classes().length == 0) { - throw new IllegalArgumentException("Need to provide the interface class in the @OsgiServiceProvider(classes={...}) annotation on " + bean.clazz); - } - Properties properties = bean.clazz.getAnnotation(Properties.class); - if (properties == null) { - writer.writeEmptyElement("service"); - } else { - writer.writeStartElement("service"); - } - writer.writeAttribute("ref", bean.id); - Class<?> serviceIf = serviceProvider.classes()[0]; - writer.writeAttribute("interface", serviceIf.getName()); - writer.writeCharacters("\n"); - if (properties != null) { - writeProperties(properties); - writer.writeEndElement(); - writer.writeCharacters("\n"); - } - } - - private void writeProperties(Properties properties) throws XMLStreamException { - writer.writeCharacters(" "); - writer.writeStartElement("service-properties"); - writer.writeCharacters("\n"); - for (Property property : properties.value()) { - writer.writeCharacters(" "); - writer.writeEmptyElement("entry"); - writer.writeAttribute("key", property.name()); - writer.writeAttribute("value", property.value()); - writer.writeCharacters("\n"); - } - writer.writeCharacters(" "); - writer.writeEndElement(); - writer.writeCharacters("\n"); - } - - -}
