VersionInfopublic class VersionInfo extends Object Provides access to version information for HTTP components.
Instances of this class provide version information for a single module
or informal unit, as explained
here.
Static methods are used to extract version information from property
files that are automatically packaged with HTTP component release JARs.
All available version information is provided in strings, where
the string format is informal and subject to change without notice.
Version information is provided for debugging output and interpretation
by humans, not for automated processing in applications. |
Fields Summary |
---|
public static final String | UNAVAILABLEA string constant for unavailable information. | public static final String | VERSION_PROPERTY_FILEThe filename of the version information files. | public static final String | PROPERTY_MODULE | public static final String | PROPERTY_RELEASE | public static final String | PROPERTY_TIMESTAMP | private final String | infoPackageThe package that contains the version information. | private final String | infoModuleThe module from the version info. | private final String | infoReleaseThe release from the version info. | private final String | infoTimestampThe timestamp from the version info. | private final String | infoClassloaderThe classloader from which the version info was obtained. |
Constructors Summary |
---|
protected VersionInfo(String pckg, String module, String release, String time, String clsldr)Instantiates version information.
if (pckg == null) {
throw new IllegalArgumentException
("Package identifier must not be null.");
}
infoPackage = pckg;
infoModule = (module != null) ? module : UNAVAILABLE;
infoRelease = (release != null) ? release : UNAVAILABLE;
infoTimestamp = (time != null) ? time : UNAVAILABLE;
infoClassloader = (clsldr != null) ? clsldr : UNAVAILABLE;
|
Methods Summary |
---|
protected static final org.apache.http.util.VersionInfo | fromMap(java.lang.String pckg, java.util.Map info, java.lang.ClassLoader clsldr)Instantiates version information from properties.
if (pckg == null) {
throw new IllegalArgumentException
("Package identifier must not be null.");
}
String module = null;
String release = null;
String timestamp = null;
if (info != null) {
module = (String) info.get(PROPERTY_MODULE);
if ((module != null) && (module.length() < 1))
module = null;
release = (String) info.get(PROPERTY_RELEASE);
if ((release != null) && ((release.length() < 1) ||
(release.equals("${pom.version}"))))
release = null;
timestamp = (String) info.get(PROPERTY_TIMESTAMP);
if ((timestamp != null) &&
((timestamp.length() < 1) ||
(timestamp.equals("${mvn.timestamp}")))
)
timestamp = null;
} // if info
String clsldrstr = null;
if (clsldr != null)
clsldrstr = clsldr.toString();
return new VersionInfo(pckg, module, release, timestamp, clsldrstr);
| public final java.lang.String | getClassloader()Obtains the classloader used to read the version information.
This is just the toString output of the classloader,
since the version information should not keep a reference to
the classloader itself. That could prevent garbage collection.
return infoClassloader;
| public final java.lang.String | getModule()Obtains the name of the versioned module or informal unit.
This data is read from the version information for the package.
return infoModule;
| public final java.lang.String | getPackage()Obtains the package name.
The package name identifies the module or informal unit.
return infoPackage;
| public final java.lang.String | getRelease()Obtains the release of the versioned module or informal unit.
This data is read from the version information for the package.
return infoRelease;
| public final java.lang.String | getTimestamp()Obtains the timestamp of the versioned module or informal unit.
This data is read from the version information for the package.
return infoTimestamp;
| public static final org.apache.http.util.VersionInfo[] | loadVersionInfo(java.lang.String[] pckgs, java.lang.ClassLoader clsldr)Loads version information for a list of packages.
if (pckgs == null) {
throw new IllegalArgumentException
("Package identifier list must not be null.");
}
ArrayList vil = new ArrayList(pckgs.length);
for (int i=0; i<pckgs.length; i++) {
VersionInfo vi = loadVersionInfo(pckgs[i], clsldr);
if (vi != null)
vil.add(vi);
}
return (VersionInfo[]) vil.toArray(new VersionInfo[vil.size()]);
| public static final org.apache.http.util.VersionInfo | loadVersionInfo(java.lang.String pckg, java.lang.ClassLoader clsldr)Loads version information for a package.
if (pckg == null) {
throw new IllegalArgumentException
("Package identifier must not be null.");
}
if (clsldr == null)
clsldr = Thread.currentThread().getContextClassLoader();
Properties vip = null; // version info properties, if available
try {
// org.apache.http becomes
// org/apache/http/version.properties
InputStream is = clsldr.getResourceAsStream
(pckg.replace('.", '/") + "/" + VERSION_PROPERTY_FILE);
if (is != null) {
try {
Properties props = new Properties();
props.load(is);
vip = props;
} finally {
is.close();
}
}
} catch (IOException ex) {
// shamelessly munch this exception
}
VersionInfo result = null;
if (vip != null)
result = fromMap(pckg, vip, clsldr);
return result;
| public java.lang.String | toString()Provides the version information in human-readable format.
StringBuffer sb = new StringBuffer
(20 + infoPackage.length() + infoModule.length() +
infoRelease.length() + infoTimestamp.length() +
infoClassloader.length());
sb.append("VersionInfo(")
.append(infoPackage).append(':").append(infoModule);
// If version info is missing, a single "UNAVAILABLE" for the module
// is sufficient. Everything else just clutters the output.
if (!UNAVAILABLE.equals(infoRelease))
sb.append(':").append(infoRelease);
if (!UNAVAILABLE.equals(infoTimestamp))
sb.append(':").append(infoTimestamp);
sb.append(')");
if (!UNAVAILABLE.equals(infoClassloader))
sb.append('@").append(infoClassloader);
return sb.toString();
|
|