Manifest validation script, updates to bootstrap script, added onos-app-samples to manifest

Change-Id: I5598206748285fce044246745fd49e768e48ed26
diff --git a/default.xml b/default.xml
index 18d1e00..952dccc 100644
--- a/default.xml
+++ b/default.xml
@@ -10,6 +10,7 @@
            sync-j="4" />
 
   <project path="onos" name="onos" groups="onos" />
+  <project path="onos-app-samples" name="onos-app-samples" groups="samples" />
 
 </manifest>
 
diff --git a/manifest.dtd b/manifest.dtd
new file mode 100644
index 0000000..7b2c66c
--- /dev/null
+++ b/manifest.dtd
@@ -0,0 +1,61 @@
+<!ELEMENT manifest (notice?,
+                    remote*,
+                    default?,
+                    manifest-server?,
+                    remove-project*,
+                    project*,
+                    extend-project*,
+                    repo-hooks?)>
+<!ELEMENT notice (#PCDATA)>
+<!ELEMENT remote EMPTY>
+<!ATTLIST remote name         ID    #REQUIRED>
+<!ATTLIST remote alias        CDATA #IMPLIED>
+<!ATTLIST remote fetch        CDATA #REQUIRED>
+<!ATTLIST remote pushurl      CDATA #IMPLIED>
+<!ATTLIST remote review       CDATA #IMPLIED>
+<!ATTLIST remote revision     CDATA #IMPLIED>
+<!ELEMENT default EMPTY>
+<!ATTLIST default remote      IDREF #IMPLIED>
+<!ATTLIST default revision    CDATA #IMPLIED>
+<!ATTLIST default dest-branch CDATA #IMPLIED>
+<!ATTLIST default sync-j      CDATA #IMPLIED>
+<!ATTLIST default sync-c      CDATA #IMPLIED>
+<!ATTLIST default sync-s      CDATA #IMPLIED>
+<!ELEMENT manifest-server EMPTY>
+<!ATTLIST manifest-server url CDATA #REQUIRED>
+<!ELEMENT project (annotation*,
+                   project*,
+                   copyfile*,
+                   linkfile*)>
+<!ATTLIST project name        CDATA #REQUIRED>
+<!ATTLIST project path        CDATA #IMPLIED>
+<!ATTLIST project remote      IDREF #IMPLIED>
+<!ATTLIST project revision    CDATA #IMPLIED>
+<!ATTLIST project dest-branch CDATA #IMPLIED>
+<!ATTLIST project groups      CDATA #IMPLIED>
+<!ATTLIST project sync-c      CDATA #IMPLIED>
+<!ATTLIST project sync-s      CDATA #IMPLIED>
+<!ATTLIST project upstream CDATA #IMPLIED>
+<!ATTLIST project clone-depth CDATA #IMPLIED>
+<!ATTLIST project force-path CDATA #IMPLIED>
+<!ELEMENT annotation EMPTY>
+<!ATTLIST annotation name  CDATA #REQUIRED>
+<!ATTLIST annotation value CDATA #REQUIRED>
+<!ATTLIST annotation keep  CDATA "true">
+<!ELEMENT copyfile EMPTY>
+<!ATTLIST copyfile src  CDATA #REQUIRED>
+<!ATTLIST copyfile dest CDATA #REQUIRED>
+<!ELEMENT linkfile EMPTY>
+<!ATTLIST linkfile src CDATA #REQUIRED>
+<!ATTLIST linkfile dest CDATA #REQUIRED>
+<!ELEMENT extend-project EMPTY>
+<!ATTLIST extend-project name CDATA #REQUIRED>
+<!ATTLIST extend-project path CDATA #IMPLIED>
+<!ATTLIST extend-project groups CDATA #IMPLIED>
+<!ELEMENT remove-project EMPTY>
+<!ATTLIST remove-project name  CDATA #REQUIRED>
+<!ELEMENT repo-hooks EMPTY>
+<!ATTLIST repo-hooks in-project CDATA #REQUIRED>
+<!ATTLIST repo-hooks enabled-list CDATA #REQUIRED>
+<!ELEMENT include EMPTY>
+<!ATTLIST include name CDATA #REQUIRED>
diff --git a/onos-boostrap.sh b/onos-boostrap.sh
new file mode 100644
index 0000000..93c1e11
--- /dev/null
+++ b/onos-boostrap.sh
@@ -0,0 +1,93 @@
+#!/usr/bin/env bash
+#
+# Copyright 2017-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.
+#
+# onos-bootstrap.sh
+# Bootstraps repo for ONOS, downloads source
+
+set -e -u -o pipefail
+
+# Use master as default version
+REPO_BRANCH=${REPO_BRANCH:-'master'}
+
+ONOS_REPO_DIR="${CORDDIR:-${HOME}/onosrepo}"
+
+function install_repo() {
+  if [ ! -x "/usr/local/bin/repo" ]
+  then
+    echo "Installing repo..."
+    # v1.23, per https://source.android.com/source/downloading
+    REPO_SHA256SUM="e147f0392686c40cfd7d5e6f332c6ee74c4eab4d24e2694b3b0a0c037bf51dc5"
+    curl -o /tmp/repo https://storage.googleapis.com/git-repo-downloads/repo
+    echo "$REPO_SHA256SUM  /tmp/repo" | sha256sum -c -
+    sudo mv /tmp/repo /usr/local/bin/repo
+    sudo chmod a+x /usr/local/bin/repo
+  fi
+}
+
+function checkout_onos() {
+
+  if [ ! -d "$ONOS_REPO_DIR" ]
+  then
+
+    # Create default git config if unconfigured
+    if [ ! -e "${HOME}/.gitconfig" ]
+    then
+      echo "No ${HOME}/.gitconfig, setting testing defaults"
+      git config --global user.name 'Test User'
+      git config --global user.email 'test@null.com'
+      git config --global color.ui false
+    fi
+
+    echo "Checking out ONOS using repo..."
+
+    mkdir -p $ONOS_REPO_DIR && cd $ONOS_REPO_DIR
+    repo init -u https://gerrit.onosproject.org/manifest -b $REPO_BRANCH
+    repo sync
+
+    # check out gerrit branches using repo
+    if [[ ! -z ${GERRIT_PATCHES[@]-} ]]
+    then
+      for gerrit_patch in "${GERRIT_PATCHES[@]-}"
+      do
+        echo "Checking out gerrit changeset: '$gerrit_patch'"
+        repo download ${gerrit_patch/:/ }
+      done
+    fi
+  fi
+}
+
+# Parse options
+GERRIT_PATCHES=()
+
+while getopts "p:h" opt; do
+  case ${opt} in
+    h ) echo "Usage:"
+      echo "    $0                download ONOS using repo [default]"
+      echo "    $0 -p <project:changeset/revision>  checkout patchsetsfrom gerrit. Can"
+      echo "                      be used multiple times."
+      echo "    $0 -h             display this help message"
+      ;;
+    p ) GERRIT_PATCHES+=("$OPTARG")
+      ;;
+    \? ) echo "Invalid option: -$OPTARG"
+      exit 1
+      ;;
+  esac
+done
+
+install_repo
+checkout_onos
+
diff --git a/repo_bootstrap.sh b/repo_bootstrap.sh
deleted file mode 100644
index f123fbd..0000000
--- a/repo_bootstrap.sh
+++ /dev/null
@@ -1,58 +0,0 @@
-#!/usr/bin/env bash
-# repo_bootstrap.sh
-
-# Use master as default version
-REPO_BRANCH=${REPO_BRANCH:-'master'}
-ONOS_REPO_DIR=${ONOS_REPO_DIR:-'~/onos_repo'}
-
-function install_repo_tool() {
-  if [ ! -x "/usr/local/bin/repo" ]
-  then
-    echo "Installing repo..."
-    REPO_SHA256SUM="e147f0392686c40cfd7d5e6f332c6ee74c4eab4d24e2694b3b0a0c037bf51dc5" # not versioned...
-    curl -o /tmp/repo https://storage.googleapis.com/git-repo-downloads/repo
-    echo "$REPO_SHA256SUM  /tmp/repo" | sha256sum -c -
-    sudo mv /tmp/repo /usr/local/bin/repo
-    sudo chmod a+x /usr/local/bin/repo
-  fi
-}
-
-function checkout_onos_with_repo() {
-
-  if [ ! -d "$ONOS_REPO_DIR" ]
-  then
-    echo "Checking out ONOS using repo..."
-
-    mkdir $ONOS_REPO_DIR && cd $ONOS_REPO_DIR
-    repo init -u https://gerrit.onosproject.org/manifest -b $REPO_BRANCH -g onos
-    repo sync
-
-    # check out gerrit branches using repo
-    for gerrit_branch in ${GERRIT_BRANCHES[@]}; do
-      echo "Checking out opencord gerrit branch: $gerrit_branch"
-      repo download ${gerrit_branch/:/ }
-    done
-  fi
-}
-
-# Parse options
-GERRIT_BRANCHES=
-
-while getopts "b:chsv" opt; do
-  case ${opt} in
-    b ) GERRIT_BRANCHES+=("$OPTARG")
-      ;;
-    h ) echo "Usage:"
-      echo "    $0                download ONOS using repo [default]"
-      echo "    $0 -b <project:changeset/revision>  checkout changesets from gerrit. Can"
-      echo "                      be used multiple times."
-      echo "    $0 -h             display this help message"
-     \? ) echo "Invalid option: -$OPTARG"
-      exit 1
-      ;;
-  esac
-done
-
-install_repo_tool()
-checkout_onos_with_repo()
-
diff --git a/validate_manifest.sh b/validate_manifest.sh
new file mode 100755
index 0000000..77d3211
--- /dev/null
+++ b/validate_manifest.sh
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+# validate_manifest.sh
+#
+# Copyright 2017-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.
+#
+# Validates the repo manifest, per the DTD format given here:
+# https://gerrit.googlesource.com/git-repo/+/master/docs/manifest-format.txt
+
+echo "Verifying default.xml using manifest.dtd"
+
+# check that xmllint is available
+if ! [ -x "$(command -v xmllint)" ]
+then
+  echo "Please install 'xmllint' to use this script"
+  exit 1
+fi
+
+# run the verification
+xmllint --noout --dtdvalid manifest.dtd default.xml
+status=$?
+
+if [ $status -ne 0 ]
+then
+  echo "FAILURE: default.xml isn't valid - exit status: $status"
+  exit $status
+else
+  echo "SUCCESS: default.xml validated correctly"
+  exit 0
+fi