decouple buck yang plugin from buck main archive

- prep to allow bumping yang tool versin without releasing whole
  onos-buck archive

- with this patch,
  reverting back from locally patched state
  (= undo `patch-yang-libs`)
  will be:
   $ git checkout -- lib/BUCK tools/build/onos-buck

Change-Id: I06bfccdcfd6b22e2252b5c9dc145cece26058841
diff --git a/lib/deps.json b/lib/deps.json
index 6233aac..cb9300c 100644
--- a/lib/deps.json
+++ b/lib/deps.json
@@ -247,7 +247,7 @@
     "aries-util": "mvn:org.apache.aries:org.apache.aries.util:1.1.1",
     "guava20": "mvn:com.google.guava:guava:20.0",
 
-    // Note: update BVER in tools/dev/bin/patch-yang-libs
+    // Note update BVER in tools/dev/bin/patch-yang-libs and YANG_VER in tools/build/onos-buck
     "onos-yang-model":"mvn:org.onosproject:onos-yang-model:2.4",
     "onos-yang-compiler-api":"mvn:org.onosproject:onos-yang-compiler-api:2.4",
     "onos-yang-runtime":"mvn:org.onosproject:onos-yang-runtime:2.4",
diff --git a/tools/build/onos-buck b/tools/build/onos-buck
index 9ebed5d..9f5a704 100755
--- a/tools/build/onos-buck
+++ b/tools/build/onos-buck
@@ -8,6 +8,9 @@
 BUCK_URL="http://repo1.maven.org/maven2/org/onosproject/onos-buck/v2018.02.09.01/buck-v2018.02.09.01.zip"
 BUCK_SHA="45d8bd28f441991257babf89f7a317edb3a2b536"
 
+# onos-yang-tools buck plugin version
+YANG_VER="2.4"
+
 [  "-U" = "$1" ] && shift && FORCE_UPDATE=True
 
 ROOT_DIR=${ONOS_ROOT:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )"}
@@ -39,6 +42,45 @@
     rm -rf $ROOT_DIR/buck-out
     printf "Successfully updated Buck in $ROOT_DIR/bin/buck to $BUCK_FILE\n\n"
 fi
+
+# Fetch & install onos yang tools buck plugin
+YANG_PLUGIN_CACHE="cache/onos-yang-compiler-buck-plugin-$YANG_VER.jar"
+if hash mvn 2>/dev/null; then
+  if [[ $YANG_VER = *"-SNAPSHOT" ]] || [ ! -f "$YANG_PLUGIN_CACHE" ]; then
+    ARTIFACT="org.onosproject:onos-yang-compiler-buck-plugin:$YANG_VER"
+    mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.2:copy \
+        -Dartifact=$ARTIFACT \
+        -Dtransitive=false -Dmdep.overWriteSnapshots=true \
+        -DoutputDirectory=cache > /dev/null
+  fi
+else
+  if [ ! -f "$YANG_PLUGIN_CACHE" ]; then
+    if [[ $YANG_VER = *"-SNAPSHOT" ]]; then
+      echo "mvn command must be installed to handle SNAPSHOT version"
+      exit 1
+    fi
+
+    curl -o "$YANG_PLUGIN_CACHE" \
+      -L https://repo1.maven.org/maven2/org/onosproject/onos-yang-compiler-buck-plugin/$YANG_VER/onos-yang-compiler-buck-plugin-$YANG_VER.jar
+  fi
+
+  if [[ $YANG_VER != *"-SNAPSHOT" ]] && hash shasum 2>/dev/null; then
+    SHA=$(shasum $YANG_PLUGIN_CACHE | cut -d' ' -f1)
+    if [ ! -f "$YANG_PLUGIN_CACHE".sha1 ]; then
+      curl -o "$YANG_PLUGIN_CACHE".sha1 \
+        -L https://repo1.maven.org/maven2/org/onosproject/onos-yang-compiler-buck-plugin/$YANG_VER/onos-yang-compiler-buck-plugin-$YANG_VER.jar.sha1
+    fi
+    YANG_PLUGIN_SHA=$(cat "$YANG_PLUGIN_CACHE".sha1)
+    if [ "$SHA" != "$YANG_PLUGIN_SHA" ]; then
+       echo "ERROR: Downloaded SHA ($SHA) did not match expected SHA ($YANG_PLUGIN_SHA)" &&
+       rm -f $YANG_PLUGIN_CACHE $YANG_PLUGIN_CACHE.sha1 && exit 1
+     fi
+  else
+    echo "SHA verification skipped"
+  fi
+fi
+install -Cv "$YANG_PLUGIN_CACHE" plugins/yang.jar
+
 popd > /dev/null
 
 BUCK=$ROOT_DIR/bin/buck
diff --git a/tools/dev/bin/patch-yang-libs b/tools/dev/bin/patch-yang-libs
index 3e269fe..2686836 100755
--- a/tools/dev/bin/patch-yang-libs
+++ b/tools/dev/bin/patch-yang-libs
@@ -45,6 +45,12 @@
 if [ ! -f "$YANG_PLUGIN_SRC" ]; then
     mvn -f $YANG_TOOLS_ROOT/pom.xml -am -pl :onos-yang-compiler-buck-plugin install -DskipTests -Dcheckstyle.skip
 fi
-# Patch the YANG BUCK plugin
-cp -p $YANG_PLUGIN_SRC \
-        $ONOS_ROOT/bin/plugins/yang.jar
+# populate buck plugin cache with SNAPSHOT version
+ARTIFACT="org.onosproject:onos-yang-compiler-buck-plugin:$SVER"
+mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.2:copy \
+    -Dartifact=$ARTIFACT \
+    -Dtransitive=false -Dmdep.overWriteSnapshots=true \
+    -DoutputDirectory=$ONOS_ROOT/bin/cache > /dev/null
+
+# Patch the YANG BUCK plugin version specified
+sed -i.bak "s/YANG_VER=\"$BVER\"/YANG_VER=\"$SVER\"/" $ONOS_ROOT/tools/build/onos-buck