예제 #1
0
  /**
   * Parses a new Version object from a String.
   *
   * @param toParse The String object to parse.
   * @return a new Version object.
   * @throws IllegalArgumentException When there is an error parsing the String.
   */
  public static Version parse(final String toParse) throws IllegalArgumentException {
    if (toParse == null) {
      throw new IllegalArgumentException("Error parsing version from null String");
    }

    final Matcher m = STD_VERSION_PATT.matcher(toParse);
    if (!m.find()) {
      throw new IllegalArgumentException(String.format("Error parsing version from '%s'", toParse));
    }

    Version v = new Version();
    v.rawVersion = toParse;
    v.prefix = m.group(1);

    final String major = m.group(2);
    if (major != null && !major.equals("")) {
      v.setMajor(major);
    }

    final String minor = m.group(3);
    if (minor != null && !minor.equals("")) {
      v.setMinor(minor);
    }

    final String build = m.group(4);
    if (build != null && !build.equals("")) {
      v.setBuild(build);
    }

    final String revision = m.group(5);
    if (revision != null && !revision.equals("")) {
      v.setRevision(m.group(5));
    }

    v.suffix = m.group(6);

    return v;
  }
예제 #2
0
 /**
  * Sets the version's BUILD component.
  *
  * @param toSet The version's BUILD component.
  */
 public void setBuild(final int toSet) {
   setBuild(String.valueOf(toSet));
 }