public class Which
extends java.lang.Object
Which is the command line interface to the org.apache.env package. Simply put, it provides a simplistic check of a user's actual environment for debugging and product support purposes by detecting the specific versions of commonly installed classes in the environment.
Which and related service classes provide a framework for looking for version information and passing it around in hashtables. Users can plug in their own implementations of WhichProject classes to get custom version info about any product.
One important usage note: you must call Which (or subclasses) in the environment that you wish to check. I.e. if you have a problem with a command line tool, then call Which from the same command line environment. If you have a problem with a servlet, you must call Which.blah() from your servlet as it's installed in an actual container.
Usage - command line:
java org.apache.env.Which [project;WhichProject] [-options]
Usage - from program:
int status = org.apache.env.Which.which(hash, projects, options);
Usage - from XSLT stylesheet in Xalan-J:
(add which.jar to your classpath and run the following stylesheet)
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xalan" exclude-result-prefixes="xalan"> <xsl:output indent="yes"/> <xsl:template match="/"> <xsl:copy-of select="xalan:checkEnvironment()"/> </xsl:template> </xsl:stylesheet>
Original credit to org.apache.xalan.xslt.EnvironmentCheck
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_PROJECTS
Default set of projects to use if none provided.
|
protected java.lang.StringBuffer |
optionsBuf
optionsBuf.
|
protected java.io.PrintWriter |
outWriter
outWriter.
|
protected java.lang.StringBuffer |
projectsBuf
projectsBuf.
|
static java.lang.String |
SEPARATOR
Generic ';' separator for various items.
|
Constructor and Description |
---|
Which() |
Modifier and Type | Method and Description |
---|---|
void |
doMain(java.lang.String[] args)
Instance worker method to handle main().
|
static void |
getGeneralInfo(java.util.Hashtable hash,
java.lang.String options)
Grab a couple of generally useful items, like classpath,
java version, version of this file, etc..
|
static int |
getProjectsInfo(java.util.Hashtable hash,
java.lang.String projects,
java.lang.String options)
Get information from various project's WhichProject impls.
|
static java.lang.String |
getVersion()
Get simple version info about org.apache.env.Which and
related classes.
|
static void |
main(java.lang.String[] args)
Command line runnability.
|
protected boolean |
parseArgs(java.lang.String[] args)
Parse commandline args, return false if help asked for.
|
protected void |
reportHashtable(java.util.Hashtable hash,
java.lang.String name,
java.io.PrintWriter out)
Print information from a hashtable into the PrintWriter.
|
void |
reportProjectsInfo(java.util.Hashtable hash,
java.lang.String options,
int status,
java.io.PrintWriter out)
Print information from which() into the PrintWriter.
|
protected java.lang.String |
usage()
Return our usage statement.
|
static int |
which(java.util.Hashtable hash,
java.lang.String projects,
java.lang.String options)
Which - get all info.
|
public static final java.lang.String SEPARATOR
public static final java.lang.String DEFAULT_PROJECTS
protected java.lang.StringBuffer optionsBuf
protected java.lang.StringBuffer projectsBuf
protected java.io.PrintWriter outWriter
public static void main(java.lang.String[] args)
args
- command line argspublic void doMain(java.lang.String[] args)
args
- command line argspublic static int which(java.util.Hashtable hash, java.lang.String projects, java.lang.String options)
hash
- to put information inprojects
- to get information aboutoptions
- to apply like strict or verbosepublic static void getGeneralInfo(java.util.Hashtable hash, java.lang.String options)
hash
- to put information inprojects
- to get information aboutpublic static int getProjectsInfo(java.util.Hashtable hash, java.lang.String projects, java.lang.String options)
Each project's info is put into a subhash. Note: if projects is null, we use DEFAULT_PROJECTS.
hash
- to put information inprojects
- to get information aboutoptions
- to apply like strict or verbosepublic void reportProjectsInfo(java.util.Hashtable hash, java.lang.String options, int status, java.io.PrintWriter out)
Simplistic implementation to report to a writer.
hash
- to get info from (may have subhashtables)options
- to apply like strict or verbosestatus
- from finding version infoout
- PrintWriter to send Properties.list()-like
output toprotected void reportHashtable(java.util.Hashtable hash, java.lang.String name, java.io.PrintWriter out)
Provides a pre-order traversal where the parent hash has it's output dumped before recursing to any child sub hashes. Sorta looks like Properties.list() output.
hash
- to get info from (may have subhashtables)name
- to print as header for this hashout
- PrintWriter to send Properties.list()-like
output toprotected java.lang.String usage()
protected boolean parseArgs(java.lang.String[] args)
args
- array of commandline argspublic static java.lang.String getVersion()
Copyright ? 2001 Apache Software Foundation. All Rights Reserved.