Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9D63B2004C8 for ; Mon, 9 May 2016 16:48:24 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 9C7B116099C; Mon, 9 May 2016 14:48:24 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B3B30160A25 for ; Mon, 9 May 2016 16:48:22 +0200 (CEST) Received: (qmail 79893 invoked by uid 500); 9 May 2016 14:48:21 -0000 Mailing-List: contact commits-help@karaf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@karaf.apache.org Delivered-To: mailing list commits@karaf.apache.org Received: (qmail 79475 invoked by uid 99); 9 May 2016 14:48:21 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 May 2016 14:48:21 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A369CE0329; Mon, 9 May 2016 14:48:21 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: cschneider@apache.org To: commits@karaf.apache.org Date: Mon, 09 May 2016 14:48:41 -0000 Message-Id: In-Reply-To: <1e3eeb57e42d4f938950e5b22b1cb7f9@git.apache.org> References: <1e3eeb57e42d4f938950e5b22b1cb7f9@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [22/35] karaf-boot git commit: [blueprint] Add blueprint annotation support archived-at: Mon, 09 May 2016 14:48:24 -0000 [blueprint] Add blueprint annotation support Project: http://git-wip-us.apache.org/repos/asf/karaf-boot/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf-boot/commit/18a2cfab Tree: http://git-wip-us.apache.org/repos/asf/karaf-boot/tree/18a2cfab Diff: http://git-wip-us.apache.org/repos/asf/karaf-boot/diff/18a2cfab Branch: refs/heads/master Commit: 18a2cfab13be3acfbf72ce6fe014831d20173490 Parents: 52bc684 Author: Guillaume Nodet Authored: Fri Apr 15 20:48:32 2016 +0200 Committer: Guillaume Nodet Committed: Fri Apr 15 20:48:32 2016 +0200 ---------------------------------------------------------------------- .../README.md | 21 ++++++ .../pom.xml | 49 +++++++++++++ .../service/provider/HelloService.java | 25 +++++++ .../service/provider/HelloServiceImpl.java | 35 +++++++++ .../karaf-boot-starter-blueprint/pom.xml | 57 +++++++++++++++ .../boot/blueprint/impl/BlueprintProcessor.java | 76 ++++++++++++++++++++ .../javax.annotation.processing.Processor | 1 + karaf-boot-starters/pom.xml | 1 + pom.xml | 2 + 9 files changed, 267 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/18a2cfab/karaf-boot-samples/karaf-boot-sample-service-blueprint-annotation/README.md ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/karaf-boot-sample-service-blueprint-annotation/README.md b/karaf-boot-samples/karaf-boot-sample-service-blueprint-annotation/README.md new file mode 100644 index 0000000..02f255e --- /dev/null +++ b/karaf-boot-samples/karaf-boot-sample-service-blueprint-annotation/README.md @@ -0,0 +1,21 @@ +== karaf-boot-sample-service-blueprint-annotation == + +This sample exposes an OSGi service using blueprint annotations. + += Design + +TODO + += Build + +To build, simply do: + + mvn clean install + += Deploy + +* you can drop the generated jar file (target/karaf-boot-sample-service-blueprint-annotation-1.0.jar) in the +Karaf deploy folder +* in the Karaf shell console, do: + + bundle:install -s mvn:org.apache.karaf.boot/karaf-boot-sample-service-blueprint-annotation/1.0 http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/18a2cfab/karaf-boot-samples/karaf-boot-sample-service-blueprint-annotation/pom.xml ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/karaf-boot-sample-service-blueprint-annotation/pom.xml b/karaf-boot-samples/karaf-boot-sample-service-blueprint-annotation/pom.xml new file mode 100644 index 0000000..cc629dc --- /dev/null +++ b/karaf-boot-samples/karaf-boot-sample-service-blueprint-annotation/pom.xml @@ -0,0 +1,49 @@ + + + + + + 4.0.0 + + org.apache.karaf.boot + karaf-boot-sample-service-blueprint-annotation + 1.0.0-SNAPSHOT + + + + org.apache.karaf.boot + karaf-boot-starter-blueprint + ${project.version} + + + + + + + org.apache.karaf.boot + karaf-boot-maven-plugin + ${project.version} + true + + + + + http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/18a2cfab/karaf-boot-samples/karaf-boot-sample-service-blueprint-annotation/src/main/java/sample/blueprint/service/provider/HelloService.java ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/karaf-boot-sample-service-blueprint-annotation/src/main/java/sample/blueprint/service/provider/HelloService.java b/karaf-boot-samples/karaf-boot-sample-service-blueprint-annotation/src/main/java/sample/blueprint/service/provider/HelloService.java new file mode 100644 index 0000000..2555069 --- /dev/null +++ b/karaf-boot-samples/karaf-boot-sample-service-blueprint-annotation/src/main/java/sample/blueprint/service/provider/HelloService.java @@ -0,0 +1,25 @@ +/** + * 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.blueprint.service.provider; + +public interface HelloService { + + public String hello(String message); + + public void startUp(); + +} http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/18a2cfab/karaf-boot-samples/karaf-boot-sample-service-blueprint-annotation/src/main/java/sample/blueprint/service/provider/HelloServiceImpl.java ---------------------------------------------------------------------- diff --git a/karaf-boot-samples/karaf-boot-sample-service-blueprint-annotation/src/main/java/sample/blueprint/service/provider/HelloServiceImpl.java b/karaf-boot-samples/karaf-boot-sample-service-blueprint-annotation/src/main/java/sample/blueprint/service/provider/HelloServiceImpl.java new file mode 100644 index 0000000..f46b5da --- /dev/null +++ b/karaf-boot-samples/karaf-boot-sample-service-blueprint-annotation/src/main/java/sample/blueprint/service/provider/HelloServiceImpl.java @@ -0,0 +1,35 @@ +/** + * 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.blueprint.service.provider; + +import org.apache.aries.blueprint.annotation.Bean; +import org.apache.aries.blueprint.annotation.Service; + +@Bean(id = "HelloServiceImpl") +@Service(autoExport = "interfaces") +public class HelloServiceImpl implements HelloService{ + + public String hello(String message) { + return "Hello " + message + " !"; + } + + public void startUp() { + System.out.println("I'm starting up!"); + } + + +} http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/18a2cfab/karaf-boot-starters/karaf-boot-starter-blueprint/pom.xml ---------------------------------------------------------------------- diff --git a/karaf-boot-starters/karaf-boot-starter-blueprint/pom.xml b/karaf-boot-starters/karaf-boot-starter-blueprint/pom.xml new file mode 100644 index 0000000..9f48c60 --- /dev/null +++ b/karaf-boot-starters/karaf-boot-starter-blueprint/pom.xml @@ -0,0 +1,57 @@ + + + + + + 4.0.0 + + + org.apache.karaf.boot + karaf-boot-starters + 1.0.0-SNAPSHOT + ../pom.xml + + + karaf-boot-starter-blueprint + + + + org.apache.aries.blueprint + org.apache.aries.blueprint.api + 1.0.0 + + + org.apache.aries.blueprint + org.apache.aries.blueprint.annotation.api + 1.0.0 + + + + + + + maven-compiler-plugin + + -proc:none + + + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/18a2cfab/karaf-boot-starters/karaf-boot-starter-blueprint/src/main/java/org/apache/karaf/boot/blueprint/impl/BlueprintProcessor.java ---------------------------------------------------------------------- diff --git a/karaf-boot-starters/karaf-boot-starter-blueprint/src/main/java/org/apache/karaf/boot/blueprint/impl/BlueprintProcessor.java b/karaf-boot-starters/karaf-boot-starter-blueprint/src/main/java/org/apache/karaf/boot/blueprint/impl/BlueprintProcessor.java new file mode 100644 index 0000000..896a161 --- /dev/null +++ b/karaf-boot-starters/karaf-boot-starter-blueprint/src/main/java/org/apache/karaf/boot/blueprint/impl/BlueprintProcessor.java @@ -0,0 +1,76 @@ +package org.apache.karaf.boot.blueprint.impl; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.element.TypeElement; +import javax.tools.Diagnostic.Kind; +import javax.tools.FileObject; +import javax.tools.StandardLocation; +import java.io.ByteArrayOutputStream; +import java.io.CharArrayWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; +import java.io.Reader; +import java.io.Writer; +import java.util.HashSet; +import java.util.Set; + +import org.apache.aries.blueprint.annotation.Bean; + +public class BlueprintProcessor extends AbstractProcessor { + + boolean hasRun; + + public BlueprintProcessor() { + } + + @Override + public Set getSupportedAnnotationTypes() { + Set set = new HashSet(); + set.add(Bean.class.getName()); + return set; + } + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + if (!hasRun) { + hasRun = true; + // Add the blueprint requirement + try (PrintWriter w = appendResource("META-INF/org.apache.karaf.boot.bnd")) { + w.println("Bundle-Blueprint-Annotation: true"); + } catch (Exception e) { + processingEnv.getMessager().printMessage(Kind.ERROR, "Error: " + e.getMessage()); + } + } + return true; + } + + private PrintWriter appendResource(String resource) throws IOException { + try { + FileObject o = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", resource); + return new PrintWriter(o.openWriter()); + } catch (Exception e) { + try { + FileObject o = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", resource); + CharArrayWriter baos = new CharArrayWriter(); + try (Reader r = o.openReader(true)) { + char[] buf = new char[4096]; + int l; + while ((l = r.read(buf)) > 0) { + baos.write(buf, 0, l); + } + } + o.delete(); + o = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", resource); + Writer w = o.openWriter(); + w.write(baos.toCharArray()); + return new PrintWriter(w); + } catch (Exception e2) { + e2.addSuppressed(e); + e2.printStackTrace(); + throw e2; + } + } + } +} http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/18a2cfab/karaf-boot-starters/karaf-boot-starter-blueprint/src/main/resources/META-INF/services/javax.annotation.processing.Processor ---------------------------------------------------------------------- diff --git a/karaf-boot-starters/karaf-boot-starter-blueprint/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/karaf-boot-starters/karaf-boot-starter-blueprint/src/main/resources/META-INF/services/javax.annotation.processing.Processor new file mode 100644 index 0000000..fab44d1 --- /dev/null +++ b/karaf-boot-starters/karaf-boot-starter-blueprint/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1 @@ +org.apache.karaf.boot.blueprint.impl.BlueprintProcessor http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/18a2cfab/karaf-boot-starters/pom.xml ---------------------------------------------------------------------- diff --git a/karaf-boot-starters/pom.xml b/karaf-boot-starters/pom.xml index 127874e..57dbd39 100644 --- a/karaf-boot-starters/pom.xml +++ b/karaf-boot-starters/pom.xml @@ -39,6 +39,7 @@ karaf-boot-starter-web karaf-boot-starter-jpa karaf-boot-starter-cdi + karaf-boot-starter-blueprint \ No newline at end of file http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/18a2cfab/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index ca1f26e..eea3146 100644 --- a/pom.xml +++ b/pom.xml @@ -74,6 +74,8 @@ karaf-boot-samples/karaf-boot-sample-service-provider-blueprint karaf-boot-samples/karaf-boot-sample-service-consumer-blueprint + + karaf-boot-samples/karaf-boot-sample-service-blueprint-annotation karaf-boot-samples/karaf-boot-sample-cdi