/** * Extracts the version information data from the <code>version.properties</code> file found in * the source directory. * * @return the version information from the <code>version.properties</code> file */ protected static VersionInfo createVersionInfo() { // We're not in a .jar file - try to find the build-res/version file and // read the version information from that. final VersionInfo versionInfo = new VersionInfo(); try { final ResourceBundle bundle = ResourceBundle.getBundle("version"); // $NON-NLS-1$ versionInfo.setFromManifest(false); versionInfo.setProductID(bundle.getString("impl.productID")); // $NON-NLS-1$ versionInfo.setTitle(bundle.getString("impl.title")); // $NON-NLS-1$ versionInfo.setVersionMajor(bundle.getString("release.major.number")); // $NON-NLS-1$ versionInfo.setVersionMinor(bundle.getString("release.minor.number")); // $NON-NLS-1$ versionInfo.setVersionBuild(bundle.getString("release.build.number")); // $NON-NLS-1$ // The release milestone number has both the release number and the milestone number final String releaseMilestoneNumber = bundle.getString("release.milestone.number"); // $NON-NLS-1$ if (releaseMilestoneNumber != null) { String[] parts = releaseMilestoneNumber.replace('-', '.').split("\\."); // $NON-NLS-1$ if (parts.length > 0) { versionInfo.setVersionRelease(parts[0]); if (parts.length > 1) { versionInfo.setVersionMilestone(parts[1]); } } } } catch (Exception e) { // TODO:log versionInfo.setVersion("No Version Information Available"); // $NON-NLS-1$ } return versionInfo; }
/** * Extracts the version information data from the manifest's attributes and puts them into a * VersionInfo instance. * * @param manifest the manifest information * @return the version information from the manifest */ protected static VersionInfo createVersionInfo(Manifest manifest) { final VersionInfo versionInfo = new VersionInfo(); final Attributes mainAttributes = manifest.getMainAttributes(); versionInfo.setFromManifest(true); versionInfo.setProductID(mainAttributes.getValue("Implementation-ProductID")); // $NON-NLS-1$ versionInfo.setTitle(mainAttributes.getValue("Implementation-Title")); // $NON-NLS-1$ versionInfo.setVersion(mainAttributes.getValue("Implementation-Version")); // $NON-NLS-1$ return versionInfo; }
@Test public void testToString() { versionInfo.setVersion(VERSION_NUMBER_ONE); versionInfo.setFromManifest(true); versionInfo.setTitle(TITLE); versionInfo.setProductID(PRODUCT_ID); assertThat(TO_STRING, equalTo(versionInfo.toString())); assertThat(true, equalTo(versionInfo.isFromManifest())); assertThat(TITLE, equalTo(versionInfo.getTitle())); assertThat(PRODUCT_ID, equalTo(versionInfo.getProductID())); }