Thomas Vachuska
Committed by Gerrit Code Review

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
......@@ -17,6 +17,8 @@ package org.onosproject.core;
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 @@ import static java.lang.Integer.parseInt;
*/
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 @@ public final class Version {
*
* @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 final class Version {
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 @@ public final class Version {
}
/**
* Returns the version patch number.
* Returns the version patch segment.
*
* @return patch number
*/
public int patch() {
public String patch() {
return patch;
}
......
......@@ -29,10 +29,10 @@ public class VersionTest {
@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 @@ public class VersionTest {
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 @@ public class VersionTest {
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();
}
}
......
# 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_BITS=onos-${ONOS_VERSION%~*}
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
......
......@@ -72,5 +72,6 @@ echo $ONOS_VERSION > $ONOS_STAGE/VERSION
# 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
......
......@@ -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
......
......@@ -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 "$@"
......