コード例 #1
0
  /**
   * Parse a version String and add the components to a properties object.
   *
   * @param version the version to parse
   */
  public void parseVersion(String version) {
    ArtifactVersion artifactVersion = new DefaultArtifactVersion(version);

    ArtifactVersion releaseVersion = artifactVersion;
    if (ArtifactUtils.isSnapshot(version)) {
      // work around for MBUILDHELPER-69
      releaseVersion =
          new DefaultArtifactVersion(
              StringUtils.substring(
                  version, 0, version.length() - Artifact.SNAPSHOT_VERSION.length() - 1));
    }

    if (version.equals(artifactVersion.getQualifier())) {
      // This means the version parsing failed, so try osgi format.
      getLog().debug("The version is not in the regular format, will try OSGi format instead");
      artifactVersion = new OsgiArtifactVersion(version);
    }

    defineVersionProperty("majorVersion", artifactVersion.getMajorVersion());
    defineVersionProperty("minorVersion", artifactVersion.getMinorVersion());
    defineVersionProperty("incrementalVersion", artifactVersion.getIncrementalVersion());
    defineVersionProperty("nextMajorVersion", artifactVersion.getMajorVersion() + 1);
    defineVersionProperty("nextMinorVersion", artifactVersion.getMinorVersion() + 1);
    defineVersionProperty("nextIncrementalVersion", artifactVersion.getIncrementalVersion() + 1);

    String qualifier = artifactVersion.getQualifier();
    if (qualifier == null) {
      qualifier = "";
    }
    defineVersionProperty("qualifier", qualifier);

    defineVersionProperty("buildNumber", releaseVersion.getBuildNumber()); // see MBUILDHELPER-69

    // Replace the first instance of "-" to create an osgi compatible version string.
    String osgiVersion = getOsgiVersion(artifactVersion);
    defineVersionProperty("osgiVersion", osgiVersion);
  }
コード例 #2
0
  /**
   * Make an osgi compatible version String from an ArtifactVersion
   *
   * @param version The artifact version.
   * @return The OSGi version as string.
   */
  public String getOsgiVersion(ArtifactVersion version) {
    if (version.toString().equals(version.getQualifier())) {
      return version.toString();
    }

    StringBuffer osgiVersion = new StringBuffer();
    osgiVersion.append(version.getMajorVersion());
    osgiVersion.append("." + version.getMinorVersion());
    osgiVersion.append("." + version.getIncrementalVersion());

    if (version.getQualifier() != null || version.getBuildNumber() != 0) {
      osgiVersion.append(".");

      if (version.getQualifier() != null) {
        osgiVersion.append(version.getQualifier());
      }
      if (version.getBuildNumber() != 0) {
        osgiVersion.append(version.getBuildNumber());
      }
    }

    return osgiVersion.toString();
  }