Adding packaging on onos*.zip file.
Modified Version.java to allow 3-segment version.
Changed onos-next to onos as default for ONOS_ROOT.

Change-Id: Ifbde9dfbc7af9a5891e9f41db6932859c0f59660
diff --git a/core/api/src/main/java/org/onosproject/core/Version.java b/core/api/src/main/java/org/onosproject/core/Version.java
index 5641a54..9196b5b 100644
--- a/core/api/src/main/java/org/onosproject/core/Version.java
+++ b/core/api/src/main/java/org/onosproject/core/Version.java
@@ -17,6 +17,8 @@
 
 import java.util.Objects;
 
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Strings.isNullOrEmpty;
 import static java.lang.Integer.parseInt;
 
 /**
@@ -24,22 +26,27 @@
  */
 public final class Version {
 
-    public static final String FORMAT = "%d.%d.%d.%s";
+    public static final String FORMAT = "%d.%d.%s.%s";
+    public static final String FORMAT_SHORT = "%d.%d.%s";
+
+    private static final String NEGATIVE = "Version segment cannot be negative";
 
     private final int major;
     private final int minor;
-    private final int patch;
+    private final String patch;
     private final String build;
 
     private final String format;
 
     // Creates a new version descriptor
-    private Version(int major, int minor, int patch, String build) {
+    private Version(int major, int minor, String patch, String build) {
         this.major = major;
         this.minor = minor;
         this.patch = patch;
         this.build = build;
-        this.format = String.format(FORMAT, major, minor, patch, build);
+        this.format = isNullOrEmpty(build) ?
+                String.format(FORMAT_SHORT, major, minor, patch) :
+                String.format(FORMAT, major, minor, patch, build);
     }
 
 
@@ -48,11 +55,13 @@
      *
      * @param major major version number
      * @param minor minod version number
-     * @param patch version patch number
-     * @param build build string
+     * @param patch version patch segment
+     * @param build optional build string
      * @return version descriptor
      */
-    public static Version version(int major, int minor, int patch, String build) {
+    public static Version version(int major, int minor, String patch, String build) {
+        checkArgument(major > 0, NEGATIVE);
+        checkArgument(minor > 0, NEGATIVE);
         return new Version(major, minor, patch, build);
     }
 
@@ -65,7 +74,7 @@
     public static Version version(String string) {
         String[] fields = string.split("[.-]");
         return new Version(parseInt(fields[0]), parseInt(fields[1]),
-                           parseInt(fields[2]), fields[3]);
+                           fields[2], fields.length == 4 ? fields[3] : null);
     }
 
     /**
@@ -87,11 +96,11 @@
     }
 
     /**
-     * Returns the version patch number.
+     * Returns the version patch segment.
      *
      * @return patch number
      */
-    public int patch() {
+    public String patch() {
         return patch;
     }
 
diff --git a/core/api/src/test/java/org/onosproject/VersionTest.java b/core/api/src/test/java/org/onosproject/VersionTest.java
index 61e44b7..44a319b 100644
--- a/core/api/src/test/java/org/onosproject/VersionTest.java
+++ b/core/api/src/test/java/org/onosproject/VersionTest.java
@@ -29,10 +29,10 @@
 
     @Test
     public void fromParts() {
-        Version v = version(1, 2, 3, "4321");
+        Version v = version(1, 2, "3", "4321");
         assertEquals("wrong major", 1, v.major());
         assertEquals("wrong minor", 2, v.minor());
-        assertEquals("wrong patch", 3, v.patch());
+        assertEquals("wrong patch", "3", v.patch());
         assertEquals("wrong build", "4321", v.build());
     }
 
@@ -41,7 +41,7 @@
         Version v = version("1.2.3.4321");
         assertEquals("wrong major", 1, v.major());
         assertEquals("wrong minor", 2, v.minor());
-        assertEquals("wrong patch", 3, v.patch());
+        assertEquals("wrong patch", "3", v.patch());
         assertEquals("wrong build", "4321", v.build());
     }
 
@@ -50,17 +50,26 @@
         Version v = version("1.2.3-SNAPSHOT");
         assertEquals("wrong major", 1, v.major());
         assertEquals("wrong minor", 2, v.minor());
-        assertEquals("wrong patch", 3, v.patch());
+        assertEquals("wrong patch", "3", v.patch());
         assertEquals("wrong build", "SNAPSHOT", v.build());
     }
 
     @Test
+    public void shortNumber() {
+        Version v = version("1.2.3");
+        assertEquals("wrong major", 1, v.major());
+        assertEquals("wrong minor", 2, v.minor());
+        assertEquals("wrong patch", "3", v.patch());
+        assertEquals("wrong build", null, v.build());
+    }
+
+    @Test
     public void testEquals() {
         new EqualsTester()
-                .addEqualityGroup(version("1.2.3.4321"), version(1, 2, 3, "4321"))
-                .addEqualityGroup(version("1.9.3.4321"), version(1, 9, 3, "4321"))
-                .addEqualityGroup(version("1.2.8.4321"), version(1, 2, 8, "4321"))
-                .addEqualityGroup(version("1.2.3.x"), version(1, 2, 3, "x"))
+                .addEqualityGroup(version("1.2.3.4321"), version(1, 2, "3", "4321"))
+                .addEqualityGroup(version("1.9.3.4321"), version(1, 9, "3", "4321"))
+                .addEqualityGroup(version("1.2.8.4321"), version(1, 2, "8", "4321"))
+                .addEqualityGroup(version("1.2.3.x"), version(1, 2, "3", "x"))
                 .testEquals();
     }
 }
diff --git a/tools/build/envDefaults b/tools/build/envDefaults
index b4881a7..bef5223 100644
--- a/tools/build/envDefaults
+++ b/tools/build/envDefaults
@@ -1,7 +1,7 @@
 # Environmental defaults for ONOS build, package and test
 
 # Root of the ONOS source tree
-export ONOS_ROOT=${ONOS_ROOT:-~/onos-next}
+export ONOS_ROOT=${ONOS_ROOT:-~/onos}
 
 # M2 repository and Karaf gold bits
 export M2_REPO=${M2_REPO:-~/.m2/repository}
@@ -24,6 +24,7 @@
 export ONOS_STAGE_ROOT=${ONOS_STAGE_ROOT:-/tmp}
 export ONOS_STAGE=$ONOS_STAGE_ROOT/$ONOS_BITS
 export ONOS_TAR=$ONOS_STAGE.tar.gz
+export ONOS_ZIP=$ONOS_STAGE.zip
 
 # Defaults for ONOS testing using remote machines.
 # if [ -n "${ONOS_CELL}" -a -f $ONOS_ROOT/tools/test/cells/${ONOS_CELL} ]; then
diff --git a/tools/build/onos-package b/tools/build/onos-package
index 9bc8fd5..8bbb4b4 100755
--- a/tools/build/onos-package
+++ b/tools/build/onos-package
@@ -72,5 +72,6 @@
 # Now package up the ONOS tar file
 cd $ONOS_STAGE_ROOT
 COPYFILE_DISABLE=1 tar zcf $ONOS_TAR $ONOS_BITS
-ls -l $ONOS_TAR >&2
+which -s zip && zip -rq $ONOS_ZIP $ONOS_BITS
+ls -l $ONOS_TAR $ONOS_ZIP >&2
 rm -r $ONOS_STAGE
diff --git a/tools/dev/bash_profile b/tools/dev/bash_profile
index dbd65c4..2bb2059 100644
--- a/tools/dev/bash_profile
+++ b/tools/dev/bash_profile
@@ -3,7 +3,7 @@
 # Simply include in your own .bash_aliases or .bash_profile
 
 # Root of the ONOS source tree
-export ONOS_ROOT=${ONOS_ROOT:-~/onos-next}
+export ONOS_ROOT=${ONOS_ROOT:-~/onos}
 
 # Setup some environmental context for developers
 if [ -z "${JAVA_HOME}" ]; then
diff --git a/tools/package/bin/onos-service b/tools/package/bin/onos-service
index 7ce1b15..b9156ec 100755
--- a/tools/package/bin/onos-service
+++ b/tools/package/bin/onos-service
@@ -6,5 +6,7 @@
 #export JAVA_HOME=${JAVA_HOME:-/usr/lib/jvm/java-7-openjdk-amd64/}
 export JAVA_OPTS="${JAVA_OPTS:--Xms256m -Xmx2048m}"
 
-cd /opt/onos
-/opt/onos/apache-karaf-$KARAF_VERSION/bin/karaf "$@"
+ONOS_HOME=/opt/onos
+
+[ -d $ONOS_HOME ] && cd $ONOS_HOME || ONOS_HOME=$(dirname $0)/..
+${ONOS_HOME}/apache-karaf-$KARAF_VERSION/bin/karaf "$@"