APIdia Launch Partner
Top Description Fields Constructors Methods
net.ucanaccess.util

public final Class VersionInfo

extends Object
Class Inheritance
Imports
org.w3c.dom.Document, org.xml.sax.SAXException, java.io.IOException, .InputStream, java.lang.System.Logger, .System.Logger.Level, java.nio.file.Files, .Path, .Paths, java.util.Map, .Objects, java.util.concurrent.ConcurrentHashMap, java.util.jar.Attributes, .Manifest, java.util.regex.Matcher, .Pattern, java.util.stream.Stream, javax.xml.XMLConstants, javax.xml.parsers.DocumentBuilderFactory, .ParserConfigurationException, javax.xml.xpath.XPathConstants, .XPathExpressionException, .XPathFactory

The purpose of this class is to find the project's version information by all means possible,

First this class attempts to read version information from key Attributes.Name.IMPLEMENTATION_VERSION in the Java manifest by using the Java api.

Should this operation fail, it looks for a MANIFEST.MF in the file system in order to read version information from the first file found.

In case this also fails, it looks for the project's Maven POM file to extract version information from the xml structure.

Author
Markus Spann
Since
v5.1.2

Field Summary

Modifier and TypeField and Description
private static final Map<Class<?>, VersionInfo>
CACHE

Cache of version information by class.

private static final System.Logger
private int
private int
private String

Constructor Summary

AccessConstructor and Description
pack-priv
VersionInfo()

Default constructor.

Method Summary

Modifier and TypeMethod and Description
pack-priv static void
clearCache()

Clears the internal cache of version information.

public static VersionInfo

Returns:

The VersionInfo instance for the given class.
find
(Class<?>
The class to find the version for. Cannot be null.
clazz
)

Finds and returns the version information for a given class.

pack-priv VersionInfo

Returns:

This VersionInfo instance with the version details populated.
findVersion
(Package
The package of the class to find the version for.
p
)

Finds the version information by checking the package, manifest, or Maven POM file.

public int

Returns:

The major version number, or 0 if not found or unparsable.
getMajorVersion
()

Returns the major version number.

public int

Returns:

The minor version number, or 0 if not found or unparsable.
getMinorVersion
()

Returns the minor version number.

public String

Returns:

The version string, or null if not found.
getVersion
()

Returns the full version string.

pack-priv String

Returns:

The version string, or null if not found.
readFromManifest
()

Reads the version information from a MANIFEST.MF file in the file system.

pack-priv String

Returns:

The version string, or null if not found.
readFromMavenPom
()

Reads the version information from a pom.xml file in the file system.

public String

Returns:

A formatted string with version, major, and minor numbers.
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of the version info.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

CACHEback to summary
private static final Map<Class<?>, VersionInfo> CACHE

Cache of version information by class.

LOGGERback to summary
private static final System.Logger LOGGER
majorVersionback to summary
private int majorVersion
minorVersionback to summary
private int minorVersion
versionback to summary
private String version

Constructor Detail

VersionInfoback to summary
pack-priv VersionInfo()

Default constructor.

Method Detail

clearCacheback to summary
pack-priv static void clearCache()

Clears the internal cache of version information. This is primarily for testing purposes.

findback to summary
public static VersionInfo find(Class<?> clazz)

Finds and returns the version information for a given class. The method uses a cache to avoid redundant lookups.

Parameters
clazz:Class<?>

The class to find the version for. Cannot be null.

Returns:VersionInfo

The VersionInfo instance for the given class.

Exceptions
NullPointerException:
if class is null.
findVersionback to summary
pack-priv VersionInfo findVersion(Package p)

Finds the version information by checking the package, manifest, or Maven POM file.

Parameters
p:Package

The package of the class to find the version for.

Returns:VersionInfo

This VersionInfo instance with the version details populated.

getMajorVersionback to summary
public int getMajorVersion()

Returns the major version number.

Returns:int

The major version number, or 0 if not found or unparsable.

getMinorVersionback to summary
public int getMinorVersion()

Returns the minor version number.

Returns:int

The minor version number, or 0 if not found or unparsable.

getVersionback to summary
public String getVersion()

Returns the full version string.

Returns:String

The version string, or null if not found.

readFromManifestback to summary
pack-priv String readFromManifest()

Reads the version information from a MANIFEST.MF file in the file system.

Returns:String

The version string, or null if not found.

readFromMavenPomback to summary
pack-priv String readFromMavenPom()

Reads the version information from a pom.xml file in the file system.

Returns:String

The version string, or null if not found.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of the version info.

Returns:String

A formatted string with version, major, and minor numbers.

Annotations
@Override