/**
  * @return The last build number for snapshot version. 0 if maven-metadata not found for the path.
  */
 private int getLastBuildNumber(RepoPath repoPath) {
   int buildNumber = 0;
   try {
     // get the parent path which should contains the maven-metadata
     RepoPath parentRepoPath = repoPath.getParent();
     RepositoryService repoService = ContextHelper.get().getRepositoryService();
     RepoPathImpl mavenMetadataPath =
         new RepoPathImpl(parentRepoPath, MavenNaming.MAVEN_METADATA_NAME);
     if (repoService.exists(mavenMetadataPath)) {
       String mavenMetadataStr = repoService.getStringContent(mavenMetadataPath);
       Metadata metadata = MavenModelUtils.toMavenMetadata(mavenMetadataStr);
       Versioning versioning = metadata.getVersioning();
       if (versioning != null) {
         Snapshot snapshot = versioning.getSnapshot();
         if (snapshot != null) {
           buildNumber = snapshot.getBuildNumber();
         }
       }
     } else {
       // ok probably not found. just log
       log.debug("No maven metadata found for {}.", repoPath);
     }
   } catch (Exception e) {
     log.error("Cannot obtain build number from metadata.", e);
   }
   return buildNumber;
 }
  private static int getBuildNumber(Metadata metadata) {
    int number = 0;

    Versioning versioning = metadata.getVersioning();
    if (versioning != null) {
      Snapshot snapshot = versioning.getSnapshot();
      if (snapshot != null && snapshot.getBuildNumber() > 0) {
        number = snapshot.getBuildNumber();
      }
    }

    return number;
  }