org.apache.env

Class Which


public class Which
extends java.lang.Object

General environment checking and version finding service.

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);

Original credit to org.apache.xalan.xslt.EnvironmentCheck

Version:
$Id: Which.java,v 1.2 2001/12/21 22:59:05 curcuru Exp $
Author:
shane_curcuru@us.ibm.com

Field Summary

static String
DEFAULT_PROJECTS
Default set of projects to use if none provided.
static String
SEPARATOR
Generic ';' separator for various items.
protected StringBuffer
optionsBuf
optionsBuf.
protected PrintWriter
outWriter
outWriter.
protected StringBuffer
projectsBuf
projectsBuf.

Method Summary

void
doMain(String[] args)
Instance worker method to handle main().
static void
getGeneralInfo(Hashtable hash, String options)
Grab a couple of generally useful items, like classpath, java version, version of this file, etc..
static int
getProjectsInfo(Hashtable hash, String projects, String options)
Get information from various project's WhichProject impls.
static String
getVersion()
Get simple version info about org.apache.env.Which and related classes.
static void
main(String[] args)
Command line runnability.
protected boolean
parseArgs(String[] args)
Parse commandline args, return false if help asked for.
protected void
reportHashtable(Hashtable hash, String name, PrintWriter out)
Print information from a hashtable into the PrintWriter.
void
reportProjectsInfo(Hashtable hash, String options, int status, PrintWriter out)
Print information from which() into the PrintWriter.
protected String
usage()
Return our usage statement.
static int
which(Hashtable hash, String projects, String options)
Which - get all info.

Field Details

DEFAULT_PROJECTS

public static final String DEFAULT_PROJECTS
Default set of projects to use if none provided.

SEPARATOR

public static final String SEPARATOR
Generic ';' separator for various items.

optionsBuf

protected StringBuffer optionsBuf
optionsBuf.

outWriter

protected PrintWriter outWriter
outWriter.

projectsBuf

protected StringBuffer projectsBuf
projectsBuf.

Method Details

doMain

public void doMain(String[] args)
Instance worker method to handle main().
Parameters:
args - command line args

getGeneralInfo

public static void getGeneralInfo(Hashtable hash,
                                  String options)
Grab a couple of generally useful items, like classpath, java version, version of this file, etc..
Parameters:
hash - to put information in

getProjectsInfo

public static int getProjectsInfo(Hashtable hash,
                                  String projects,
                                  String options)
Get information from various project's WhichProject impls.

Each project's info is put into a subhash. Note: if projects is null, we use DEFAULT_PROJECTS.

Parameters:
hash - to put information in
projects - to get information about
options - to apply like strict or verbose
Returns:
status information from WhichConstant

getVersion

public static String getVersion()
Get simple version info about org.apache.env.Which and related classes.
Returns:
String of our file version

main

public static void main(String[] args)
Command line runnability.
Parameters:
args - command line args

parseArgs

protected boolean parseArgs(String[] args)
Parse commandline args, return false if help asked for.
Parameters:
args - array of commandline args
Returns:
true if OK, false if error/usage/help needed

reportHashtable

protected void reportHashtable(Hashtable hash,
                               String name,
                               PrintWriter out)
Print information from a hashtable into the PrintWriter.

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.

Parameters:
hash - to get info from (may have subhashtables)
name - to print as header for this hash
out - PrintWriter to send Properties.list()-like output to

reportProjectsInfo

public void reportProjectsInfo(Hashtable hash,
                               String options,
                               int status,
                               PrintWriter out)
Print information from which() into the PrintWriter.

Simplistic implementation to report to a writer.

Parameters:
hash - to get info from (may have subhashtables)
options - to apply like strict or verbose
status - from finding version info
out - PrintWriter to send Properties.list()-like output to

usage

protected String usage()
Return our usage statement.
Returns:
String of our usage

which

public static int which(Hashtable hash,
                        String projects,
                        String options)
Which - get all info. Worker method called from doMain or suitable for calling from other programs.
Parameters:
hash - to put information in
projects - to get information about
options - to apply like strict or verbose
Returns:
status information from WhichConstant

Copyright B) 2001 Apache. All Rights Reserved.