Enhancing base bundle archetype to include component config property as an example.

Change-Id: Ia0dfeb989944029b67cdfe750d127e8a2bfa8dd4
diff --git a/tools/package/archetypes/bundle/src/main/resources/archetype-resources/pom.xml b/tools/package/archetypes/bundle/src/main/resources/archetype-resources/pom.xml
index 0ac416c..b3a4365 100644
--- a/tools/package/archetypes/bundle/src/main/resources/archetype-resources/pom.xml
+++ b/tools/package/archetypes/bundle/src/main/resources/archetype-resources/pom.xml
@@ -100,11 +100,17 @@
 
         <dependency>
             <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.service.component.annotations</artifactId>
+            <artifactId>org.osgi.service.component</artifactId>
             <version>1.4.0</version>
             <scope>provided</scope>
         </dependency>
-    </dependencies>
+
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.component.annotations</artifactId>
+            <version>1.4.0</version>
+            <scope>provided</scope>
+        </dependency>    </dependencies>
 
     <build>
         <plugins>
@@ -137,7 +143,7 @@
             <plugin>
                 <groupId>org.onosproject</groupId>
                 <artifactId>onos-maven-plugin</artifactId>
-                <version>2.0</version>
+                <version>2.1</version>
                 <executions>
                     <execution>
                         <id>cfg</id>
diff --git a/tools/package/archetypes/bundle/src/main/resources/archetype-resources/src/main/java/AppComponent.java b/tools/package/archetypes/bundle/src/main/resources/archetype-resources/src/main/java/AppComponent.java
index 9fdf0fb..c2fc6428 100644
--- a/tools/package/archetypes/bundle/src/main/resources/archetype-resources/src/main/java/AppComponent.java
+++ b/tools/package/archetypes/bundle/src/main/resources/archetype-resources/src/main/java/AppComponent.java
@@ -18,28 +18,65 @@
  */
 package ${package};
 
+import com.google.common.collect.ImmutableSet;
+import org.onosproject.cfg.ComponentConfigService;
+import org.osgi.service.component.ComponentContext;
 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.Modified;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.Dictionary;
+import java.util.Properties;
+
+import static org.onlab.util.Tools.get;
+
 /**
  * Skeletal ONOS application component.
  */
-@Component(immediate = true)
-public class AppComponent {
+@Component(immediate = true,
+           service = {SomeInterface.class},
+           property = {
+               "someProperty=Some Default String Value",
+           })
+public class AppComponent implements SomeInterface {
 
     private final Logger log = LoggerFactory.getLogger(getClass());
 
+    /** Some configurable property. */
+    private String someProperty;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY)
+    protected ComponentConfigService cfgService;
+
     @Activate
     protected void activate() {
+        cfgService.registerProperties(getClass());
         log.info("Started");
     }
 
     @Deactivate
     protected void deactivate() {
+        cfgService.unregisterProperties(getClass(), false);
         log.info("Stopped");
     }
 
+    @Modified
+    public void modified(ComponentContext context) {
+        Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties();
+        if (context != null) {
+            someProperty = get(properties, "someProperty");
+        }
+        log.info("Reconfigured");
+    }
+
+    @Override
+    public void someMethod() {
+        log.info("Invoked");
+    }
+
 }
diff --git a/tools/package/archetypes/bundle/src/main/resources/archetype-resources/src/main/java/SomeInterface.java b/tools/package/archetypes/bundle/src/main/resources/archetype-resources/src/main/java/SomeInterface.java
new file mode 100644
index 0000000..93f5f79
--- /dev/null
+++ b/tools/package/archetypes/bundle/src/main/resources/archetype-resources/src/main/java/SomeInterface.java
@@ -0,0 +1,25 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/*
+ * Copyright ${year}-present Open Networking Foundation
+ *
+ * Licensed 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 ${package};
+
+public interface SomeInterface {
+
+    void someMethod();
+
+}
\ No newline at end of file
diff --git a/tools/package/archetypes/bundle/src/main/resources/archetype-resources/src/test/java/AppComponentTest.java b/tools/package/archetypes/bundle/src/main/resources/archetype-resources/src/test/java/AppComponentTest.java
index dd51ad5..0267613 100644
--- a/tools/package/archetypes/bundle/src/main/resources/archetype-resources/src/test/java/AppComponentTest.java
+++ b/tools/package/archetypes/bundle/src/main/resources/archetype-resources/src/test/java/AppComponentTest.java
@@ -21,6 +21,10 @@
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.onosproject.cfg.ComponentConfigService;
+import org.onosproject.cfg.ConfigProperty;
+
+import java.util.Set;
 
 /**
  * Set of tests of the ONOS application component.
@@ -32,8 +36,8 @@
     @Before
     public void setUp() {
         component = new AppComponent();
+        component.cfgService = new TestComponentConfigService();
         component.activate();
-
     }
 
     @After
@@ -46,4 +50,46 @@
 
     }
 
+    private class TestComponentConfigService implements ComponentConfigService {
+        @Override
+        public Set<String> getComponentNames() {
+            return null;
+        }
+
+        @Override
+        public void registerProperties(Class<?> componentClass) {
+
+        }
+
+        @Override
+        public void unregisterProperties(Class<?> componentClass, boolean clear) {
+
+        }
+
+        @Override
+        public Set<ConfigProperty> getProperties(String componentName) {
+            return null;
+        }
+
+        @Override
+        public void setProperty(String componentName, String name, String value) {
+
+        }
+
+        @Override
+        public void preSetProperty(String componentName, String name, String value) {
+
+        }
+
+        @Override
+        public void unsetProperty(String componentName, String name) {
+
+        }
+
+        @Override
+        public ConfigProperty getProperty(String componentName, String attribute) {
+            return null;
+        }
+    }
+
 }