This is an automated email from the ASF dual-hosted git repository. alien11689 pushed a commit to branch ARIES-2171-use-blueprint-maven-plugin-in-tutorials in repository https://gitbox.apache.org/repos/asf/aries.git
commit e9f59270c99a799855482f4244ab71aacc4fbe5d Author: Dominik Przybysz <[email protected]> AuthorDate: Sat Mar 15 08:06:57 2025 +0100 ARIES-2171: Use blueprint-maven-plugin in tutorials --- .../src/main/scripts/start_platform.bat | 2 +- .../src/main/scripts/start_platform.sh | 2 +- .../blueprint/tutorial-modules/greeter-api/pom.xml | 82 ++++++------- .../greeter/api/GreeterMessageService.java | 8 +- .../greeter-client-blueprint/pom.xml | 111 +++++++++-------- .../greeter/client/GreeterBlueprintClient.java | 38 +++--- .../resources/OSGI-INF/blueprint/blueprint.xml | 31 ----- .../tutorial-modules/greeter-client-osgi/pom.xml | 100 ++++++++-------- .../greeter/client/osgi/ClientBundleActivator.java | 12 +- .../greeter/client/osgi/GreeterTestClient.java | 132 +++++++++++---------- .../greeter-server-blueprint/pom.xml | 106 +++++++++-------- .../blueprint/GreeterMessageServiceImpl.java | 30 +++-- .../resources/OSGI-INF/blueprint/blueprint.xml | 27 ----- .../tutorial-modules/greeter-server-osgi/pom.xml | 96 ++++++++------- .../server/osgi/GreeterMessageServiceImpl.java | 23 ++-- .../server/osgi/ServiceRegisteringActivator.java | 27 +++-- tutorials/pom.xml | 43 +++++++ 17 files changed, 443 insertions(+), 427 deletions(-) diff --git a/tutorials/blueprint/tutorial-assembly/src/main/scripts/start_platform.bat b/tutorials/blueprint/tutorial-assembly/src/main/scripts/start_platform.bat index a0947cc71..6d82fb875 100644 --- a/tutorials/blueprint/tutorial-assembly/src/main/scripts/start_platform.bat +++ b/tutorials/blueprint/tutorial-assembly/src/main/scripts/start_platform.bat @@ -20,4 +20,4 @@ setlocal cd %~dp0 cd ..\platform -java -jar org.eclipse.osgi-3.22.0.jar -console -clean \ No newline at end of file +java -jar org.eclipse.osgi-3.23.0.jar -console -clean \ No newline at end of file diff --git a/tutorials/blueprint/tutorial-assembly/src/main/scripts/start_platform.sh b/tutorials/blueprint/tutorial-assembly/src/main/scripts/start_platform.sh index 8d1319056..e02623976 100644 --- a/tutorials/blueprint/tutorial-assembly/src/main/scripts/start_platform.sh +++ b/tutorials/blueprint/tutorial-assembly/src/main/scripts/start_platform.sh @@ -18,4 +18,4 @@ ################################################################################ scriptDir=`pwd`/`dirname $0` cd "${scriptDir}/../platform" -java -jar org.eclipse.osgi-3.22.0.jar -console -clean +java -jar org.eclipse.osgi-3.23.0.jar -console -clean diff --git a/tutorials/blueprint/tutorial-modules/greeter-api/pom.xml b/tutorials/blueprint/tutorial-modules/greeter-api/pom.xml index c589f8864..615acdd3d 100644 --- a/tutorials/blueprint/tutorial-modules/greeter-api/pom.xml +++ b/tutorials/blueprint/tutorial-modules/greeter-api/pom.xml @@ -1,21 +1,21 @@ <?xml version="1.0" encoding="UTF-8"?> - <!-- - 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 +<!-- + 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. - --> + 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. +--> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <parent> <groupId>org.apache.aries.tutorials.blueprint</groupId> @@ -24,33 +24,33 @@ <relativePath>../../pom.xml</relativePath> </parent> - <modelVersion>4.0.0</modelVersion> + <modelVersion>4.0.0</modelVersion> - <artifactId>org.apache.aries.tutorials.blueprint.greeter.api</artifactId> - <packaging>bundle</packaging> - <name>Greeter API</name> + <artifactId>org.apache.aries.tutorials.blueprint.greeter.api</artifactId> + <packaging>bundle</packaging> + <name>Greeter API</name> - <description> - This is the API for the greeter service. It has no parent because it - is built outside the tutorial. When the tutorial is assembled the source and binaries - from this project are included the the tutorial zip/tar.gz files. - The version is referenced in the tutorial documentation (tutorial-assembly/src/main/docs/instructions.html), - so changes to the version number here must be reflected in the documentation. - </description> + <description> + This is the API for the greeter service. It has no parent because it + is built outside the tutorial. When the tutorial is assembled the source and binaries + from this project are included the the tutorial zip/tar.gz files. + The version is referenced in the tutorial documentation (tutorial-assembly/src/main/docs/instructions.html), + so changes to the version number here must be reflected in the documentation. + </description> - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName> - <Export-Package>org.apache.aries.tutorials.blueprint.greeter.api</Export-Package> - </instructions> - </configuration> - </plugin> - </plugins> - </build> + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> + <Export-Package>org.apache.aries.tutorials.blueprint.greeter.api</Export-Package> + </instructions> + </configuration> + </plugin> + </plugins> + </build> </project> diff --git a/tutorials/blueprint/tutorial-modules/greeter-api/src/main/java/org/apache/aries/tutorials/blueprint/greeter/api/GreeterMessageService.java b/tutorials/blueprint/tutorial-modules/greeter-api/src/main/java/org/apache/aries/tutorials/blueprint/greeter/api/GreeterMessageService.java index 50cb80326..9b4f5d458 100644 --- a/tutorials/blueprint/tutorial-modules/greeter-api/src/main/java/org/apache/aries/tutorials/blueprint/greeter/api/GreeterMessageService.java +++ b/tutorials/blueprint/tutorial-modules/greeter-api/src/main/java/org/apache/aries/tutorials/blueprint/greeter/api/GreeterMessageService.java @@ -6,9 +6,9 @@ * 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 - * + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> * 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 @@ -19,5 +19,5 @@ package org.apache.aries.tutorials.blueprint.greeter.api; public interface GreeterMessageService { - public String getGreetingMessage(); + String getGreetingMessage(); } diff --git a/tutorials/blueprint/tutorial-modules/greeter-client-blueprint/pom.xml b/tutorials/blueprint/tutorial-modules/greeter-client-blueprint/pom.xml index dfba8c93b..390677262 100644 --- a/tutorials/blueprint/tutorial-modules/greeter-client-blueprint/pom.xml +++ b/tutorials/blueprint/tutorial-modules/greeter-client-blueprint/pom.xml @@ -1,21 +1,21 @@ <?xml version="1.0" encoding="UTF-8"?> - <!-- - 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 +<!-- + 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. - --> + 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. +--> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <parent> <groupId>org.apache.aries.tutorials.blueprint</groupId> @@ -23,52 +23,65 @@ <version>0.1-SNAPSHOT</version> <relativePath>../../pom.xml</relativePath> </parent> - <modelVersion>4.0.0</modelVersion> + <modelVersion>4.0.0</modelVersion> - <artifactId>org.apache.aries.tutorials.blueprint.greeter.client.blueprint</artifactId> - <packaging>bundle</packaging> - <name>Greeter Blueprint Client</name> + <artifactId>org.apache.aries.tutorials.blueprint.greeter.client.blueprint</artifactId> + <packaging>bundle</packaging> + <name>Greeter Blueprint Client</name> - <description> + <description> This is the final client for the greeter service. Students working through the tutorial should end up with the code in this project. It has no parent because it is built outside the tutorial. When the tutorial is assembled the source and binaries from this project are included the the tutorial zip/tar.gz files. The version is referenced in the tutorial documentation (tutorial-assembly/src/main/docs/instructions.html), so changes to the version number here must be reflected in the documentation. - </description> + </description> <properties> <aries.osgi.private.pkg>org.apache.aries.tutorials.blueprint.greeter.client</aries.osgi.private.pkg> </properties> - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin </artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName> - </instructions> - </configuration> - </plugin> - </plugins> - </build> - <dependencies> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi</artifactId> - <version>3.0.0</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.aries.tutorials.blueprint</groupId> - <artifactId>org.apache.aries.tutorials.blueprint.greeter.api</artifactId> - <version>${project.version}</version> - <scope>provided</scope> - </dependency> - </dependencies> + <extensions>true</extensions> + <configuration> + <instructions> + <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> + </instructions> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + + <dependencies> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi</artifactId> + </dependency> + <dependency> + <groupId>org.apache.aries.tutorials.blueprint</groupId> + <artifactId>org.apache.aries.tutorials.blueprint.greeter.api</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin-annotation</artifactId> + <optional>true</optional> + </dependency> + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + <optional>true</optional> + </dependency> + </dependencies> </project> diff --git a/tutorials/blueprint/tutorial-modules/greeter-client-blueprint/src/main/java/org/apache/aries/tutorials/blueprint/greeter/client/GreeterBlueprintClient.java b/tutorials/blueprint/tutorial-modules/greeter-client-blueprint/src/main/java/org/apache/aries/tutorials/blueprint/greeter/client/GreeterBlueprintClient.java index 0fd7cee29..a361ea43a 100644 --- a/tutorials/blueprint/tutorial-modules/greeter-client-blueprint/src/main/java/org/apache/aries/tutorials/blueprint/greeter/client/GreeterBlueprintClient.java +++ b/tutorials/blueprint/tutorial-modules/greeter-client-blueprint/src/main/java/org/apache/aries/tutorials/blueprint/greeter/client/GreeterBlueprintClient.java @@ -6,9 +6,9 @@ * 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 - * + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> * 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 @@ -18,29 +18,37 @@ */ package org.apache.aries.tutorials.blueprint.greeter.client; +import org.apache.aries.blueprint.annotation.bean.Bean; +import org.apache.aries.blueprint.annotation.config.ConfigProperty; +import org.apache.aries.blueprint.annotation.service.Reference; import org.apache.aries.tutorials.blueprint.greeter.api.GreeterMessageService; +import javax.inject.Inject; + +@Bean(initMethod = "doRequests") public class GreeterBlueprintClient { - GreeterMessageService greeterMessageService; - String clientID; - - public GreeterBlueprintClient(String clientID){ + private final String clientID; + private GreeterMessageService greeterMessageService; + + public GreeterBlueprintClient(@ConfigProperty("Blueprint Client") String clientID) { this.clientID = clientID; } - - public void setGreeterMessageService(GreeterMessageService gms){ + + @Inject + @Reference(timeout = 10000) + public void setGreeterMessageService(GreeterMessageService gms) { this.greeterMessageService = gms; } - - public void doRequests(){ + + public void doRequests() { System.out.println("Invoking injected service..."); printResult(greeterMessageService.getGreetingMessage()); } - - private void printResult(String response){ + + private void printResult(String response) { System.out.println("**********************************"); - System.out.println("*"+clientID); - System.out.println("*"+response); + System.out.println("*" + clientID); + System.out.println("*" + response); System.out.println("**********************************"); } } diff --git a/tutorials/blueprint/tutorial-modules/greeter-client-blueprint/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/tutorials/blueprint/tutorial-modules/greeter-client-blueprint/src/main/resources/OSGI-INF/blueprint/blueprint.xml deleted file mode 100644 index 8e731f612..000000000 --- a/tutorials/blueprint/tutorial-modules/greeter-client-blueprint/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ /dev/null @@ -1,31 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - <!-- - 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. - --> - -<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> - - <reference id="greeterService" - interface="org.apache.aries.tutorials.blueprint.greeter.api.GreeterMessageService" - timeout="10000" availability="mandatory" /> - - <bean id="clientBean" - class="org.apache.aries.tutorials.blueprint.greeter.client.GreeterBlueprintClient" - activation="eager" init-method="doRequests"> - <argument value="Blueprint Client" /> - <property name="greeterMessageService" ref="greeterService" /> - </bean> - -</blueprint> diff --git a/tutorials/blueprint/tutorial-modules/greeter-client-osgi/pom.xml b/tutorials/blueprint/tutorial-modules/greeter-client-osgi/pom.xml index 70fde0d9c..23c390e38 100644 --- a/tutorials/blueprint/tutorial-modules/greeter-client-osgi/pom.xml +++ b/tutorials/blueprint/tutorial-modules/greeter-client-osgi/pom.xml @@ -1,21 +1,21 @@ <?xml version="1.0" encoding="UTF-8"?> - <!-- - 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 +<!-- + 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. - --> + 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. +--> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <parent> <groupId>org.apache.aries.tutorials.blueprint</groupId> @@ -23,50 +23,48 @@ <version>0.1-SNAPSHOT</version> <relativePath>../../pom.xml</relativePath> </parent> - <modelVersion>4.0.0</modelVersion> + <modelVersion>4.0.0</modelVersion> - <artifactId>org.apache.aries.tutorials.blueprint.greeter.client.osgi</artifactId> - <packaging>bundle</packaging> - <name>Greeter OSGi Client</name> + <artifactId>org.apache.aries.tutorials.blueprint.greeter.client.osgi</artifactId> + <packaging>bundle</packaging> + <name>Greeter OSGi Client</name> - <description> + <description> This is the initial client for the greeter service. Students working through the tutorial - modify this client to turn it into a blueprint client. It has no parent because it - is built outside the tutorial. When the tutorial is assembled the source and binaries + modify this client to turn it into a blueprint client. It has no parent because it + is built outside the tutorial. When the tutorial is assembled the source and binaries from this project are included the the tutorial zip/tar.gz files. The version is referenced in the tutorial documentation (tutorial-assembly/src/main/docs/instructions.html), so changes to the version number here must be reflected in the documentation. - </description> + </description> - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin </artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName> - <Bundle-Activator>org.apache.aries.tutorials.blueprint.greeter.client.osgi.ClientBundleActivator</Bundle-Activator> - </instructions> - </configuration> - </plugin> - </plugins> - </build> - <dependencies> - <dependency> - <groupId>org.apache.aries.tutorials.blueprint</groupId> - <artifactId>org.apache.aries.tutorials.blueprint.greeter.api</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> + <Bundle-Activator>org.apache.aries.tutorials.blueprint.greeter.client.osgi.ClientBundleActivator</Bundle-Activator> + </instructions> + </configuration> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>org.apache.aries.tutorials.blueprint</groupId> + <artifactId>org.apache.aries.tutorials.blueprint.greeter.api</artifactId> <version>${project.version}</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi</artifactId> - <version>3.0.0</version> - <scope>provided</scope> - </dependency> - </dependencies> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi</artifactId> + </dependency> + </dependencies> </project> diff --git a/tutorials/blueprint/tutorial-modules/greeter-client-osgi/src/main/java/org/apache/aries/tutorials/blueprint/greeter/client/osgi/ClientBundleActivator.java b/tutorials/blueprint/tutorial-modules/greeter-client-osgi/src/main/java/org/apache/aries/tutorials/blueprint/greeter/client/osgi/ClientBundleActivator.java index c0f130a1b..6876487a7 100644 --- a/tutorials/blueprint/tutorial-modules/greeter-client-osgi/src/main/java/org/apache/aries/tutorials/blueprint/greeter/client/osgi/ClientBundleActivator.java +++ b/tutorials/blueprint/tutorial-modules/greeter-client-osgi/src/main/java/org/apache/aries/tutorials/blueprint/greeter/client/osgi/ClientBundleActivator.java @@ -6,9 +6,9 @@ * 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 - * + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> * 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 @@ -23,13 +23,15 @@ import org.osgi.framework.BundleContext; public class ClientBundleActivator implements BundleActivator { - public void start(BundleContext context) throws Exception { + @Override + public void start(BundleContext context) { //We use the 'start' notification to kick off our client. GreeterTestClient hwc = new GreeterTestClient(context, "OSGI-Client"); hwc.doRequests(); } - public void stop(BundleContext context) throws Exception { + @Override + public void stop(BundleContext context) { } } diff --git a/tutorials/blueprint/tutorial-modules/greeter-client-osgi/src/main/java/org/apache/aries/tutorials/blueprint/greeter/client/osgi/GreeterTestClient.java b/tutorials/blueprint/tutorial-modules/greeter-client-osgi/src/main/java/org/apache/aries/tutorials/blueprint/greeter/client/osgi/GreeterTestClient.java index b14679c10..0f828511d 100644 --- a/tutorials/blueprint/tutorial-modules/greeter-client-osgi/src/main/java/org/apache/aries/tutorials/blueprint/greeter/client/osgi/GreeterTestClient.java +++ b/tutorials/blueprint/tutorial-modules/greeter-client-osgi/src/main/java/org/apache/aries/tutorials/blueprint/greeter/client/osgi/GreeterTestClient.java @@ -6,9 +6,9 @@ * 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 - * + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> * 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 @@ -27,52 +27,54 @@ import org.osgi.util.tracker.ServiceTracker; * Example of various approaches to using an osgi service. */ public class GreeterTestClient { - String clientID = "<unset>"; - ServiceTracker tracker = null; - GreeterMessageService cachedService = null; - BundleContext owningContext; - - GreeterMessageService proxy = null; - + private final String clientID; + private final BundleContext owningContext; + private final ServiceTracker tracker; + private GreeterMessageService cachedService = null; + + private final GreeterMessageService proxy; + /** * A simple class to hide if a service is available to invoke. */ - class GreeterMessageServiceProxy implements GreeterMessageService{ - ServiceTracker greetingServiceTracker = null; - public GreeterMessageServiceProxy(BundleContext ctx){ + static class GreeterMessageServiceProxy implements GreeterMessageService { + private final ServiceTracker greetingServiceTracker; + + public GreeterMessageServiceProxy(BundleContext ctx) { greetingServiceTracker = new ServiceTracker(ctx, GreeterMessageService.class.getName(), null); greetingServiceTracker.open(); } - public String getGreetingMessage(){ - if(greetingServiceTracker.getTrackingCount()>0){ - return ((GreeterMessageService)greetingServiceTracker.getService()).getGreetingMessage(); - }else{ + + public String getGreetingMessage() { + if (greetingServiceTracker.getTrackingCount() > 0) { + return ((GreeterMessageService) greetingServiceTracker.getService()).getGreetingMessage(); + } else { return "<No Service Available>"; } - + } } - - public GreeterTestClient(BundleContext ctx, String clientID){ - this.clientID = clientID; - owningContext = ctx; - - //setup for proxied service usage. - proxy = new GreeterMessageServiceProxy(ctx); - - //setup for tracker usage. - tracker = new ServiceTracker(ctx, GreeterMessageService.class.getName(), null); - tracker.open(); - - //setup for super optimistic osgi service usage ;-) - try{ - cachedService = (GreeterMessageService)ctx.getService(ctx.getServiceReference(GreeterMessageService.class.getName())); - }catch(RuntimeException e){ - System.err.println("Unable to cache service at bundle start!"); - } + + public GreeterTestClient(BundleContext ctx, String clientID) { + this.clientID = clientID; + owningContext = ctx; + + //setup for proxied service usage. + proxy = new GreeterMessageServiceProxy(ctx); + + //setup for tracker usage. + tracker = new ServiceTracker(ctx, GreeterMessageService.class.getName(), null); + tracker.open(); + + //setup for super optimistic osgi service usage ;-) + try { + cachedService = (GreeterMessageService) ctx.getService(ctx.getServiceReference(GreeterMessageService.class.getName())); + } catch (RuntimeException e) { + System.err.println("Unable to cache service at bundle start!"); + } } - - public void doRequests(){ + + public void doRequests() { System.out.println("Proxy based..."); doRequestUsingProxy(); System.out.println("Tracker based..."); @@ -82,54 +84,54 @@ public class GreeterTestClient { System.out.println("Extremely hopeful..."); doRequestUsingCachedService(); } - - private void doRequestUsingImmediateLookup(BundleContext ctx){ + + private void doRequestUsingImmediateLookup(BundleContext ctx) { ServiceReference ref = ctx.getServiceReference(GreeterMessageService.class.getName()); - if(ref!=null){ - GreeterMessageService greetingService = (GreeterMessageService)ctx.getService(ref); - if(greetingService!=null){ + if (ref != null) { + GreeterMessageService greetingService = (GreeterMessageService) ctx.getService(ref); + if (greetingService != null) { String response = greetingService.getGreetingMessage(); printResult(response); - }else{ + } else { System.err.println("Immediate lookup gave null for getService"); } ctx.ungetService(ref); // dont forget this!! - }else{ + } else { System.err.println("Immediate lookup gave null service reference"); } } - - private void doRequestUsingTracker(){ - System.out.println("Tracker is tracking.. "+tracker.getTrackingCount()+" services"); - GreeterMessageService greetingService = (GreeterMessageService)tracker.getService(); - if(greetingService!=null){ + + private void doRequestUsingTracker() { + System.out.println("Tracker is tracking.. " + tracker.getTrackingCount() + " services"); + GreeterMessageService greetingService = (GreeterMessageService) tracker.getService(); + if (greetingService != null) { String response = greetingService.getGreetingMessage(); printResult(response); - }else{ + } else { System.err.println("Tracker gave null for service.."); } } - - private void doRequestUsingCachedService(){ - try{ + + private void doRequestUsingCachedService() { + try { printResult(cachedService.getGreetingMessage()); - }catch(RuntimeException e){ - System.err.println("Unable to use cached service. "+e); + } catch (RuntimeException e) { + System.err.println("Unable to use cached service. " + e); } } - - private void doRequestUsingProxy(){ - try{ + + private void doRequestUsingProxy() { + try { printResult(proxy.getGreetingMessage()); - }catch(RuntimeException e){ - System.err.println("Unable to use proxied service. "+e); + } catch (RuntimeException e) { + System.err.println("Unable to use proxied service. " + e); } } - - private void printResult(String response){ + + private void printResult(String response) { System.out.println("**********************************"); - System.out.println("*"+clientID); - System.out.println("*"+response); + System.out.println("*" + clientID); + System.out.println("*" + response); System.out.println("**********************************"); } diff --git a/tutorials/blueprint/tutorial-modules/greeter-server-blueprint/pom.xml b/tutorials/blueprint/tutorial-modules/greeter-server-blueprint/pom.xml index 36d6f3e8e..1510f2088 100644 --- a/tutorials/blueprint/tutorial-modules/greeter-server-blueprint/pom.xml +++ b/tutorials/blueprint/tutorial-modules/greeter-server-blueprint/pom.xml @@ -1,21 +1,21 @@ <?xml version="1.0" encoding="UTF-8"?> - <!-- - 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 +<!-- + 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. - --> + 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. +--> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <parent> <groupId>org.apache.aries.tutorials.blueprint</groupId> @@ -23,49 +23,55 @@ <version>0.1-SNAPSHOT</version> <relativePath>../../pom.xml</relativePath> </parent> - <modelVersion>4.0.0</modelVersion> + <modelVersion>4.0.0</modelVersion> + <artifactId>org.apache.aries.tutorials.blueprint.greeter.server.blueprint</artifactId> + <packaging>bundle</packaging> + <name>Greeter Blueprint Server</name> - <artifactId>org.apache.aries.tutorials.blueprint.greeter.server.blueprint</artifactId> - <packaging>bundle</packaging> - <name>Greeter Blueprint Server</name> - - <description> + <description> This is the final greeter service. Students working through the tutorial should end up with the code in this project. It has no parent because it is built outside the tutorial. When the tutorial is assembled the source and binaries from this project are included the the tutorial zip/tar.gz files. The version is referenced in the tutorial documentation (tutorial-assembly/src/main/docs/instructions.html), so changes to the version number here must be reflected in the documentation. - </description> + </description> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> + </instructions> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin</artifactId> + </plugin> + </plugins> + </build> - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin - </artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName> - </instructions> - </configuration> - </plugin> - </plugins> - </build> - <dependencies> - <dependency> - <groupId>org.apache.aries.tutorials.blueprint</groupId> - <artifactId>org.apache.aries.tutorials.blueprint.greeter.api</artifactId> + <dependencies> + <dependency> + <groupId>org.apache.aries.tutorials.blueprint</groupId> + <artifactId>org.apache.aries.tutorials.blueprint.greeter.api</artifactId> <version>${project.version}</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi</artifactId> - <version>3.0.0</version> - <scope>provided</scope> - </dependency> - </dependencies> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi</artifactId> + </dependency> + <dependency> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin-annotation</artifactId> + <optional>true</optional> + </dependency> + </dependencies> </project> diff --git a/tutorials/blueprint/tutorial-modules/greeter-server-blueprint/src/main/java/org/apache/aries/tutorials/blueprint/greeter/server/blueprint/GreeterMessageServiceImpl.java b/tutorials/blueprint/tutorial-modules/greeter-server-blueprint/src/main/java/org/apache/aries/tutorials/blueprint/greeter/server/blueprint/GreeterMessageServiceImpl.java index 7f509ef1b..ae9392424 100644 --- a/tutorials/blueprint/tutorial-modules/greeter-server-blueprint/src/main/java/org/apache/aries/tutorials/blueprint/greeter/server/blueprint/GreeterMessageServiceImpl.java +++ b/tutorials/blueprint/tutorial-modules/greeter-server-blueprint/src/main/java/org/apache/aries/tutorials/blueprint/greeter/server/blueprint/GreeterMessageServiceImpl.java @@ -6,9 +6,9 @@ * 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 - * + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> * 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 @@ -18,21 +18,25 @@ */ package org.apache.aries.tutorials.blueprint.greeter.server.blueprint; - +import org.apache.aries.blueprint.annotation.bean.Bean; +import org.apache.aries.blueprint.annotation.config.ConfigProperty; +import org.apache.aries.blueprint.annotation.service.Service; import org.apache.aries.tutorials.blueprint.greeter.api.GreeterMessageService; +@Service +@Bean +public class GreeterMessageServiceImpl implements GreeterMessageService { + private String sender = "<unset>"; -public class GreeterMessageServiceImpl implements GreeterMessageService{ - private String sender="<unset>"; - public String getGreetingMessage() { - return "Hello World! from : "+sender; + return "Hello World! from : " + sender; } - - public void setSender(String sender){ - this.sender=sender; - if(this.sender==null) - this.sender=""; + + @ConfigProperty("Blueprint Greeting Service") + public void setSender(String sender) { + this.sender = sender; + if (this.sender == null) + this.sender = ""; } } diff --git a/tutorials/blueprint/tutorial-modules/greeter-server-blueprint/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/tutorials/blueprint/tutorial-modules/greeter-server-blueprint/src/main/resources/OSGI-INF/blueprint/blueprint.xml deleted file mode 100644 index 9129a1b79..000000000 --- a/tutorials/blueprint/tutorial-modules/greeter-server-blueprint/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ /dev/null @@ -1,27 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - <!-- - 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. - --> -<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> - - <service id="greeterService" - interface="org.apache.aries.tutorials.blueprint.greeter.api.GreeterMessageService"> - <bean - class="org.apache.aries.tutorials.blueprint.greeter.server.blueprint.GreeterMessageServiceImpl"> - <property name="sender" value="Blueprint Greeting Service" /> - </bean> - </service> - -</blueprint> diff --git a/tutorials/blueprint/tutorial-modules/greeter-server-osgi/pom.xml b/tutorials/blueprint/tutorial-modules/greeter-server-osgi/pom.xml index 96166a594..728510a0c 100644 --- a/tutorials/blueprint/tutorial-modules/greeter-server-osgi/pom.xml +++ b/tutorials/blueprint/tutorial-modules/greeter-server-osgi/pom.xml @@ -1,21 +1,21 @@ <?xml version="1.0" encoding="UTF-8"?> - <!-- - 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 +<!-- + 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. - --> + 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. +--> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <parent> <groupId>org.apache.aries.tutorials.blueprint</groupId> @@ -23,50 +23,48 @@ <version>0.1-SNAPSHOT</version> <relativePath>../../pom.xml</relativePath> </parent> - <modelVersion>4.0.0</modelVersion> + <modelVersion>4.0.0</modelVersion> - <artifactId>org.apache.aries.tutorials.blueprint.greeter.server.osgi</artifactId> - <packaging>bundle</packaging> - <name>Greeter OSGi Server</name> + <artifactId>org.apache.aries.tutorials.blueprint.greeter.server.osgi</artifactId> + <packaging>bundle</packaging> + <name>Greeter OSGi Server</name> - <description> + <description> This is the initial greeter service project. Students working through the tutorial modify this server to turn it into a blueprint server. It has no parent because it is built outside the tutorial. When the tutorial is assembled the source and binaries from this project are included the the tutorial zip/tar.gz files. The version is referenced in the tutorial documentation (tutorial-assembly/src/main/docs/instructions.html), so changes to the version number here must be reflected in the documentation. - </description> + </description> - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin </artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName> - <Bundle-Activator>org.apache.aries.tutorials.blueprint.greeter.server.osgi.ServiceRegisteringActivator</Bundle-Activator> - </instructions> - </configuration> - </plugin> - </plugins> - </build> - <dependencies> - <dependency> - <groupId>org.apache.aries.tutorials.blueprint</groupId> - <artifactId>org.apache.aries.tutorials.blueprint.greeter.api</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> + <Bundle-Activator>org.apache.aries.tutorials.blueprint.greeter.server.osgi.ServiceRegisteringActivator</Bundle-Activator> + </instructions> + </configuration> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>org.apache.aries.tutorials.blueprint</groupId> + <artifactId>org.apache.aries.tutorials.blueprint.greeter.api</artifactId> <version>${project.version}</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi</artifactId> - <version>3.0.0</version> - <scope>provided</scope> - </dependency> - </dependencies> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi</artifactId> + </dependency> + </dependencies> </project> diff --git a/tutorials/blueprint/tutorial-modules/greeter-server-osgi/src/main/java/org/apache/aries/tutorials/blueprint/greeter/server/osgi/GreeterMessageServiceImpl.java b/tutorials/blueprint/tutorial-modules/greeter-server-osgi/src/main/java/org/apache/aries/tutorials/blueprint/greeter/server/osgi/GreeterMessageServiceImpl.java index 5e30ae172..a7627e38d 100644 --- a/tutorials/blueprint/tutorial-modules/greeter-server-osgi/src/main/java/org/apache/aries/tutorials/blueprint/greeter/server/osgi/GreeterMessageServiceImpl.java +++ b/tutorials/blueprint/tutorial-modules/greeter-server-osgi/src/main/java/org/apache/aries/tutorials/blueprint/greeter/server/osgi/GreeterMessageServiceImpl.java @@ -6,9 +6,9 @@ * 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 - * + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> * 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 @@ -20,18 +20,17 @@ package org.apache.aries.tutorials.blueprint.greeter.server.osgi; import org.apache.aries.tutorials.blueprint.greeter.api.GreeterMessageService; +public class GreeterMessageServiceImpl implements GreeterMessageService { + private String sender = "<unset>"; -public class GreeterMessageServiceImpl implements GreeterMessageService{ - private String sender="<unset>"; - public String getGreetingMessage() { - return "Hello World! from : "+sender; + return "Hello World! from : " + sender; } - - public void setSender(String sender){ - this.sender=sender; - if(this.sender==null) - this.sender=""; + + public void setSender(String sender) { + this.sender = sender; + if (this.sender == null) + this.sender = ""; } } diff --git a/tutorials/blueprint/tutorial-modules/greeter-server-osgi/src/main/java/org/apache/aries/tutorials/blueprint/greeter/server/osgi/ServiceRegisteringActivator.java b/tutorials/blueprint/tutorial-modules/greeter-server-osgi/src/main/java/org/apache/aries/tutorials/blueprint/greeter/server/osgi/ServiceRegisteringActivator.java index 836102743..a96013e2d 100644 --- a/tutorials/blueprint/tutorial-modules/greeter-server-osgi/src/main/java/org/apache/aries/tutorials/blueprint/greeter/server/osgi/ServiceRegisteringActivator.java +++ b/tutorials/blueprint/tutorial-modules/greeter-server-osgi/src/main/java/org/apache/aries/tutorials/blueprint/greeter/server/osgi/ServiceRegisteringActivator.java @@ -6,9 +6,9 @@ * 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 - * + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> * 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 @@ -18,31 +18,32 @@ */ package org.apache.aries.tutorials.blueprint.greeter.server.osgi; -import java.util.Properties; - import org.apache.aries.tutorials.blueprint.greeter.api.GreeterMessageService; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; +import java.util.Properties; + public class ServiceRegisteringActivator implements BundleActivator { - private ServiceRegistration greeterServiceRegistration=null; - - public void start(BundleContext context) throws Exception { + private ServiceRegistration greeterServiceRegistration = null; + + public void start(BundleContext context) { //create the class providing service, and initialise it GreeterMessageServiceImpl helloService = new GreeterMessageServiceImpl(); helloService.setSender("OSGI via BundleActivator"); - + //register the service - greeterServiceRegistration = - context.registerService(GreeterMessageService.class.getName(), helloService, new Properties()); + greeterServiceRegistration = + context.registerService(GreeterMessageService.class.getName(), helloService, new Properties()); } - public void stop(BundleContext context) throws Exception { + public void stop(BundleContext context) { //unregister the service - if(greeterServiceRegistration!=null) + if (greeterServiceRegistration != null) { greeterServiceRegistration.unregister(); + } } } diff --git a/tutorials/pom.xml b/tutorials/pom.xml index b6ac96f1a..950fde144 100644 --- a/tutorials/pom.xml +++ b/tutorials/pom.xml @@ -43,7 +43,10 @@ <properties> <aries.skip.version.check>true</aries.skip.version.check> + <blueprint-maven-plugin-annotation.version>1.3.0</blueprint-maven-plugin-annotation.version> + <blueprint-maven-plugin.version>1.10.0</blueprint-maven-plugin.version> <jansi.version>2.4.1</jansi.version> + <javax.inject.version>1</javax.inject.version> <jline.version>3.29.0</jline.version> <org.apache.aries.blueprint.api.version>1.0.1</org.apache.aries.blueprint.api.version> <org.apache.aries.blueprint.core.version>1.10.3</org.apache.aries.blueprint.core.version> @@ -57,6 +60,7 @@ <org.apache.felix.gogo.runtime.version>1.1.6</org.apache.felix.gogo.runtime.version> <org.eclipse.equinox.console.version>1.4.800</org.eclipse.equinox.console.version> <org.eclipse.osgi.version>3.23.0</org.eclipse.osgi.version> + <org.osgi.version>3.0.0</org.osgi.version> <pax-logging.version>1.11.17</pax-logging.version> </properties> @@ -143,9 +147,48 @@ <artifactId>org.apache.aries.quiesce.manager</artifactId> <version>${org.apache.aries.quiesce.manager.version}</version> </dependency> + <dependency> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin-annotation</artifactId> + <version>${blueprint-maven-plugin-annotation.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi</artifactId> + <version>${org.osgi.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + <version>${javax.inject.version}</version> + <scope>provided</scope> + </dependency> </dependencies> </dependencyManagement> + <build> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin</artifactId> + <version>${blueprint-maven-plugin.version}</version> + <executions> + <execution> + <phase>process-classes</phase> + <goals> + <goal>add-resource-dir</goal> + <goal>blueprint-generate</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </pluginManagement> + </build> + <modules> <module>blueprint</module> </modules>
