Touch-ups to patchpanel app, including adding to Buck build.

Change-Id: I212a575d50f3a38dea83b9ebe0c004b6267b0cbf
diff --git a/apps/patchpanel/BUCK b/apps/patchpanel/BUCK
new file mode 100644
index 0000000..77f75b3
--- /dev/null
+++ b/apps/patchpanel/BUCK
@@ -0,0 +1,16 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//lib:org.apache.karaf.shell.console',
+    '//cli:onos-cli',
+]
+
+osgi_jar (
+    deps = COMPILE_DEPS,
+)
+
+onos_app (
+    title = 'Patch Panel',
+    category = 'Traffic Steering',
+    url = 'http://onosproject.org',
+    description = 'Creates patches between ports on a switch',
+)
diff --git a/apps/patchpanel/pom.xml b/apps/patchpanel/pom.xml
index 2666e72..382512c 100644
--- a/apps/patchpanel/pom.xml
+++ b/apps/patchpanel/pom.xml
@@ -14,7 +14,8 @@
   ~ 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/xsd/maven-4.0.0.xsd">
+<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">
     <parent>
         <artifactId>onos-apps</artifactId>
         <groupId>org.onosproject</groupId>
@@ -22,167 +23,35 @@
     </parent>
     <modelVersion>4.0.0</modelVersion>
 
-    <groupId>org.onosproject</groupId>
-    <artifactId>patchPanel</artifactId>
-    <version>1.0</version>
+    <artifactId>patchpanel</artifactId>
     <packaging>bundle</packaging>
 
-    <description>ONOS OSGi bundle archetype</description>
+    <description>ONOS patch panel application</description>
     <url>http://onosproject.org</url>
 
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-        <onos.version>1.7.0-SNAPSHOT</onos.version>
-        <onos.app.name>org.onosproject.patchPanel</onos.app.name>
+        <onos.app.name>org.onosproject.patchpanel</onos.app.name>
         <onos.app.title>Patch Panel</onos.app.title>
-        <onos.app.origin>Foo, Inc.</onos.app.origin>
-        <onos.app.category>default</onos.app.category>
+        <onos.app.origin>ON.Lab</onos.app.origin>
+        <onos.app.category>Traffic Steering</onos.app.category>
         <onos.app.url>http://onosproject.org</onos.app.url>
-        <onos.app.readme>ONOS OSGi bundle archetype.</onos.app.readme>
-       
+        <onos.app.readme>Creates patches between ports on a switch</onos.app.readme>
     </properties>
 
     <dependencies>
-        <dependency>
-            <groupId>org.onosproject</groupId>
-            <artifactId>onos-api</artifactId>
-            <version>1.7.0-SNAPSHOT</version>
-        </dependency>
 
         <dependency>
             <groupId>org.onosproject</groupId>
-            <artifactId>onlab-misc</artifactId>
-            <version>1.7.0-SNAPSHOT</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.onosproject</groupId>
-            <artifactId>onlab-osgi</artifactId>
-            <version>${onos.version}</version>
-        </dependency>
-
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <version>4.12</version>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.onosproject</groupId>
-            <artifactId>onos-api</artifactId>
-            <version>${onos.version}</version>
-            <scope>test</scope>
-            <classifier>tests</classifier>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.scr.annotations</artifactId>
-            <version>1.9.12</version>
-            <scope>provided</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.onosproject</groupId>
-            <artifactId>onos-incubator-api</artifactId>
-            <version>1.7.0-SNAPSHOT</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.onosproject</groupId>
-            <artifactId>onos-core-common</artifactId>
-            <version>1.7.0-SNAPSHOT</version>
-        </dependency>
-
-        <dependency>
-          <groupId>org.onosproject</groupId>
-          <artifactId>onos-cli</artifactId>
-          <version>1.7.0-SNAPSHOT</version>
-          <scope>provided</scope>
-        </dependency>
-
-        <dependency>
-          <groupId>org.osgi</groupId>
-          <artifactId>org.osgi.core</artifactId>
-          <version>5.0.0</version>
-          <scope>provided</scope>
+            <artifactId>onos-cli</artifactId>
+            <version>${project.version}</version>
         </dependency>
 
         <dependency>
           <groupId>org.apache.karaf.shell</groupId>
           <artifactId>org.apache.karaf.shell.console</artifactId>
-          <version>3.0.5</version>
-          <scope>provided</scope>
         </dependency>
 
     </dependencies>
 
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.felix</groupId>
-                <artifactId>maven-bundle-plugin</artifactId>
-                <version>3.0.1</version>
-                <extensions>true</extensions>
-            </plugin>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-compiler-plugin</artifactId>
-                <version>2.5.1</version>
-                <configuration>
-                    <source>1.8</source>
-                    <target>1.8</target>
-                </configuration>
-            </plugin>
-            <plugin>
-                <groupId>org.apache.felix</groupId>
-                <artifactId>maven-scr-plugin</artifactId>
-                <version>1.21.0</version>
-                <executions>
-                    <execution>
-                        <id>generate-scr-srcdescriptor</id>
-                        <goals>
-                            <goal>scr</goal>
-                        </goals>
-                    </execution>
-                </executions>
-                <configuration>
-                    <supportedProjectTypes>
-                        <supportedProjectType>bundle</supportedProjectType>
-                        <supportedProjectType>war</supportedProjectType>
-                    </supportedProjectTypes>
-                </configuration>
-            </plugin>
-            <plugin>
-                <groupId>org.onosproject</groupId>
-                <artifactId>onos-maven-plugin</artifactId>
-                <version>1.9</version>
-                <executions>
-                    <execution>
-                        <id>cfg</id>
-                        <phase>generate-resources</phase>
-                        <goals>
-                            <goal>cfg</goal>
-                        </goals>
-                    </execution>
-                    <execution>
-                        <id>swagger</id>
-                        <phase>generate-sources</phase>
-                        <goals>
-                            <goal>swagger</goal>
-                        </goals>
-                    </execution>
-                    <execution>
-                        <id>app</id>
-                        <phase>package</phase>
-                        <goals>
-                            <goal>app</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>
-        </plugins>
-    </build>
-
 </project>
diff --git a/apps/patchpanel/src/main/java/org/onosproject/patchpanel/cli/PatchPanelCommand.java b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/cli/PatchPanelCommand.java
index bac3221..5b6221a 100644
--- a/apps/patchpanel/src/main/java/org/onosproject/patchpanel/cli/PatchPanelCommand.java
+++ b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/cli/PatchPanelCommand.java
@@ -28,10 +28,11 @@
 import org.onosproject.net.DeviceId;
 import org.onosproject.patchpanel.impl.PatchPanelService;
 
-//name of command and description
+/**
+ * Command for adding a new patch.
+ */
 @Command(scope = "onos", name = "patch",
          description = "Gets the 2 ports of one ConnectPoint that will be patched")
-
 public class PatchPanelCommand extends AbstractShellCommand {
     //the 2 arguments, both connect points
     @Argument(index = 0, name = "switch/portNumber", description = "ConnectPoint and first port number",
diff --git a/apps/patchpanel/src/main/java/org/onosproject/patchpanel/cli/package-info.java b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/cli/package-info.java
index 85a7842..f4e7c9e 100644
--- a/apps/patchpanel/src/main/java/org/onosproject/patchpanel/cli/package-info.java
+++ b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/cli/package-info.java
@@ -15,7 +15,7 @@
  */
 
 /**
- * patch panel-related CLI commands(in cli folder).
+ * Patch panel-related CLI commands(in cli folder).
  */
 package org.onosproject.patchpanel.cli;
 
diff --git a/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/PatchPanel.java b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/PatchPanel.java
index 068ae00..b08be7e 100644
--- a/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/PatchPanel.java
+++ b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/PatchPanel.java
@@ -14,15 +14,6 @@
  * limitations under the License.
  */
 
-/**
- * This class acts as a software patch panel application.
- * The user specifies 2 connectpoint on the same device that he/she would like to patch.
- * Using a flow rule, the 2 connectpoints are patched.
- *
- * @author Parvahti Meyyappan
- * @version %I%, %G%
- */
-
 package org.onosproject.patchpanel.impl;
 
 import org.apache.felix.scr.annotations.Component;
@@ -31,6 +22,7 @@
 import org.apache.felix.scr.annotations.ReferenceCardinality;
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Deactivate;
+import org.onosproject.cli.net.ConnectPointCompleter;
 import org.onosproject.core.ApplicationId;
 import org.onosproject.core.CoreService;
 import org.onosproject.net.PortNumber;
@@ -46,11 +38,19 @@
 import java.util.ArrayList;
 import java.util.List;
 
-
+/**
+ * This class acts as a software patch panel application.
+ * The user specifies 2 connectpoint on the same device that he/she would like to patch.
+ * Using a flow rule, the 2 connectpoints are patched.
+ */
 @Component(immediate = true)
 @Service
 public class PatchPanel implements PatchPanelService {
 
+    // OSGI: help bundle plugin discover runtime package dependency.
+    @SuppressWarnings("unused")
+    private ConnectPointCompleter connectPointCompleter;
+
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected FlowRuleService flowRuleService;
 
@@ -65,12 +65,8 @@
 
     @Activate
     protected void activate() throws NullPointerException {
+        appId = coreService.registerApplication("org.onosproject.patchpanel");
         log.info("Started");
-        try {
-            appId = coreService.getAppId("org.onosproject.patchPanel");
-        } catch (NullPointerException e) {
-            throw new NullPointerException("ERROR:App Id is null");
-        }
     }
 
     @Deactivate
@@ -101,10 +97,18 @@
                 .withSelector(DefaultTrafficSelector.builder().matchInPort(inPort).build())
                 .withTreatment(DefaultTrafficTreatment.builder().setOutput(outPort).build())
                 .withPriority(PacketPriority.REACTIVE.priorityValue())
-                .makeTemporary(5)
+                .makePermanent()
                 .fromApp(appId).build();
 
-        flowRuleService.applyFlowRules(fr);
+        FlowRule fr2 = DefaultFlowRule.builder()
+                .forDevice(cp1.deviceId())
+                .withSelector(DefaultTrafficSelector.builder().matchInPort(outPort).build())
+                .withTreatment(DefaultTrafficTreatment.builder().setOutput(inPort).build())
+                .withPriority(PacketPriority.REACTIVE.priorityValue())
+                .makePermanent()
+                .fromApp(appId).build();
+
+        flowRuleService.applyFlowRules(fr, fr2);
 
     }
 
diff --git a/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/PatchPanelService.java b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/PatchPanelService.java
index 64754c0..f37df1d 100644
--- a/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/PatchPanelService.java
+++ b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/PatchPanelService.java
@@ -18,17 +18,15 @@
 import org.onosproject.net.ConnectPoint;
 
 /**
- * A service for the patch panel application to
- * export and use with the cli .
+ * A service for the patch panel application to export and use with the cli.
  */
 public interface PatchPanelService {
 
     /**
-     * Get the connectPoints that need to be patched.
+     * Adds a new patch between two connect points.
+     *
      * @param cp    the first connect point
      * @param cp2   the second connect point
-     * @return void
      */
-    public boolean addPatch(ConnectPoint cp, ConnectPoint cp2);
-
-}
\ No newline at end of file
+    boolean addPatch(ConnectPoint cp, ConnectPoint cp2);
+}
diff --git a/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/AppUiComponent.java b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/PatchPanelUiComponent.java
similarity index 95%
rename from apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/AppUiComponent.java
rename to apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/PatchPanelUiComponent.java
index 8402cb1..ea2f085 100644
--- a/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/AppUiComponent.java
+++ b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/PatchPanelUiComponent.java
@@ -34,7 +34,7 @@
  *  ONOS UI Custom-View application component for the Patch Panel Application.
  */
 @Component(immediate = true)
-public class AppUiComponent {
+public class PatchPanelUiComponent {
 
     private static final String VIEW_ID = "sampleCustom";
     private static final String VIEW_TEXT = "Patch Panel Application";
@@ -51,7 +51,7 @@
 
     // Factory for UI message handlers
     private final UiMessageHandlerFactory messageHandlerFactory =
-            () -> ImmutableList.of(new AppUiMessageHandler());
+            () -> ImmutableList.of(new PatchPanelUiMessageHandler());
 
     // Application UI extension
     protected UiExtension extension =
diff --git a/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/AppUiMessageHandler.java b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/PatchPanelUiMessageHandler.java
similarity index 98%
rename from apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/AppUiMessageHandler.java
rename to apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/PatchPanelUiMessageHandler.java
index 431f4d0..b03bb02 100644
--- a/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/AppUiMessageHandler.java
+++ b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/PatchPanelUiMessageHandler.java
@@ -40,7 +40,7 @@
  *  to each event. In this particular implementation the second message
  *  handler creates the patch and the first message handler loads the data
  */
-public class AppUiMessageHandler extends UiMessageHandler {
+public class PatchPanelUiMessageHandler extends UiMessageHandler {
 
     private static final String SAMPLE_CUSTOM_DATA_REQ = "sampleCustomDataRequest";
     private static final String SAMPLE_CUSTOM_DATA_RESP = "sampleCustomDataResponse";
@@ -136,4 +136,4 @@
             sendMessage(SAMPLE_CUSTOM_DATA_RESP3, sid, payload);
         }
     }
-}
\ No newline at end of file
+}
diff --git a/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/package-info.java b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/package-info.java
index 6bee0e2..7c109d2 100644
--- a/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/package-info.java
+++ b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/package-info.java
@@ -16,6 +16,6 @@
  */
 
 /**
- * patch panel-related CLI commands(in implementation folder).
+ * Patch panel-related CLI commands(in implementation folder).
  */
 package org.onosproject.patchpanel.impl;
diff --git a/modules.defs b/modules.defs
index 22b7adf..4fca095 100644
--- a/modules.defs
+++ b/modules.defs
@@ -150,6 +150,7 @@
     '//apps/cpman/app:onos-apps-cpman-app-oar',
     '//apps/xosclient:onos-apps-xosclient-oar',
     '//apps/scalablegateway:onos-apps-scalablegateway-oar',
+    '//apps/patchpanel:onos-apps-patchpanel-oar',
 ]
 
 APP_JARS = [