コード例 #1
0
  /**
   * Loads the versioning information for the given project-information structure using the project
   * information's internal name as lookup key.
   *
   * @param projectInformation the project we load information for.
   */
  public VersionHelper(final ProjectInformation projectInformation) {
    if (projectInformation == null) {
      throw new NullPointerException();
    }

    this.projectInformation = projectInformation;

    Manifest manifest = manifestCache.get(projectInformation.getInternalName());
    if (manifest == null) {
      final ClassLoader loader = projectInformation.getClass().getClassLoader();
      try {
        final Enumeration resources = loader.getResources("META-INF/MANIFEST.MF");
        while (resources.hasMoreElements()) {
          final URL url = (URL) resources.nextElement();
          final String urlAsText = url.toURI().toString();
          Manifest maybeManifest = manifestCache.getByURL(urlAsText);
          if (maybeManifest == null) {
            final InputStream inputStream = url.openStream();
            try {
              maybeManifest = new Manifest(new BufferedInputStream(inputStream));
            } finally {
              inputStream.close();
            }
          }

          final Attributes attr =
              getAttributes(maybeManifest, projectInformation.getInternalName());
          final String maybeTitle = getValue(attr, "Implementation-ProductID", null);
          if (maybeTitle != null) {
            manifestCache.set(maybeTitle, urlAsText, maybeManifest);
            if (maybeTitle.equals(projectInformation.getInternalName())) {
              manifest = maybeManifest;
              break;
            }
          } else {
            manifestCache.set(maybeTitle, urlAsText, maybeManifest);
          }
        }

      } catch (Exception e) {
        // Ignore; Maybe log.
        e.printStackTrace();
      }
    }
    if (manifest != null) {
      init(manifest);
    } else {
      DebugLog.log(
          "Failed to create version information for " + projectInformation.getInternalName());
      version = "TRUNK.development";
      title = projectInformation.getInternalName();
      productId = projectInformation.getInternalName();
      releaseMajor = "0";
      releaseMinor = "0";
      releaseMilestone = "0";
      releaseCandidateToken = "snapshot";
      releaseBuildNumber = "0";
      releaseNumber = createReleaseVersion();
    }
  }