Top Description Inners Fields Constructors Methods
org.apache.derby.impl.tools.sysinfo

public final Class Main

extends Object
Class Inheritance
Imports
java.util.Arrays, .Comparator, .List, .Locale, .Properties, .Locale, .MissingResourceException, .StringTokenizer, .Vector, java.io.IOException, .UnsupportedEncodingException, .InputStream, .BufferedReader, .InputStreamReader, .File, .IOException, .FileInputStream, .InputStream, java.util.zip.ZipFile, .ZipEntry, java.lang.reflect.Method, java.net.URI, .URL, .URLDecoder, java.security.ProtectionDomain, .CodeSource, org.apache.derby.shared.common.info.JVMInfo, .PropertyNames, .ProductVersionHolder, .ProductGenusNames, org.apache.derby.shared.common.reference.ModuleUtil, org.apache.derby.iapi.tools.i18n.*

Sysinfo reports values relevant to the current Derby configuration.

Sysinfo looks for properties files in org.apache.derby.info named after the genus names in org.apache.derby.tools.sysinfo, and gets their location using getResource. It also searches the classpath and attempts to load the info properties files from the directory or jar locations on the classpath, and eliminates any duplicated information. If no files are found, or some other exception occurs, the value returned will be "".

This class can be used to print out system information at the command line by issuing the command:

  java org.apache.derby.tools.sysinfo
Alternatively, you can use SysInfo within your program to display Derby information; a Derby version string is returned by this Java code:
  new Main().toString();

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private static final String
private static boolean
private static final String
private static final String
private static final String[]
private static final String[]
private static final String
private static final String
private static final String
private static final LocalizedResource
LOCALIZED_RESOURCE

Resource for localizing the sysinfo messages.

private static final String
private static final String
private static final String
private static final String
sep

for use by the main () method

private static boolean
private static boolean
private static final String
private static final String
private static final String
private static final String

Constructor Summary

AccessConstructor and Description
public
Main()

Method Summary

Modifier and TypeMethod and Description
private static String
private static boolean
private static ZipInfoProperties

Returns:

a ZipInfoProperties if a file is found, otherwise null.
checkDirectory
(String
the directory to check as a String
dirname
)

Check a given directory for the presence of an info properties file in org/apache/derby/info inside the directory.

private static ZipInfoProperties

Returns:

ZipInfoProperties with the jar file set as the location or null if not found.
checkFile
(String
the jar file to check
filename
)

Check inside a jar file for the presence of a Derby info properties file.

private static ZipInfoProperties

Returns:

a ZipInfoProperties if an info properties file is found.
checkForInfo
(final String
the classpath element
cpEntry
)

Given an individual element of the element of the classpath, call checkDirectory() if the element is a directory or checkFile() if the element is a file.

private static String
crLf()

private static String
formatURL(URL loc)

Strip a given URL down to the filename.

private static String
found(String cn, String library, String loc)

public static ZipInfoProperties[]

Returns:

an array of ZipInfoProperties with the locations of the located resources
getAllInfo
(String
the classpath, or null if not accessible
classpath
)

Get all the info we can obtain from the local execution context as to the availability of the Derby classes by attempting to load the info files with loadZipFromResource() and checking classpath locations with checkForInfo if the classpath is accessible.

private static String

Returns:

f.getCanonicalPath
getCanonicalPath
(final File
file on which to call getCanonicalPath
f
)

wrapper for getCanonicalPath for sysinfo.

private static void
private static String
getFileWhichLoadedClass(final Class<T> cls)

Given a loaded class, this routine asks the class's class loader for information about where the class was loaded from.

private static String

Returns:

getJavaProperty(whichProperty, false)
getJavaProperty
(final String
This is the name of the property
whichProperty
)

Return Java properties from java.lang.System.

private static String

Returns:

the Java property value or a string capturing a security exception.
getJavaProperty
(final String
This is the name of the property
whichProperty
,
boolean
return nothing if no such java property and nullUnavailable is true
nullUnavailable
)

Return Java properties from java.lang.System.

public static void
getMainInfo(PrintWriter aw, boolean pause)

public static String
getTextMessage(String msgId, Object... arguments)

private static ZipInfoProperties[]

Returns:

An array of ZipInfoProperties with the locations from which the info properties files were loaded.
loadZipFromResource
()

Attempt to load the info properties files specified in infoNames[i] using getResourceAsStream().

private static String
public static void
main(String[] args)

Application entry point for SysInfo.

private static ZipInfoProperties[]

Returns:

the merged array
mergeZips
(ZipInfoProperties[]
the first array from loadZipWithResource
zip1
,
ZipInfoProperties[]
the second array from analyzing the classpath
zip2
)

Merge and flatten two arrays of ZipInfoProperties, removing any duplicates.

private static String
notFound(String cn, String library)

private static void
parseArgs(String[] args)

private static String[]

Returns:

a String array with the individual classpath elements.
parseClasspath
(String
the classpath, if accessible.
cp
)

Split the classpath into separate elements.

private static void
pause()

For the benefit of DOS box users, this method waits for input before returning

private static void
printPropertyIfNotNull(PrintWriter
This is PrintWriter to print to
localAW
,
String
This is system property string
property
)

Print property only if not null

private static void
reportDerby(PrintWriter
the AppStreamWriter to use. If null, System.out is used
localAW
)

prints out the jbms info to the specified AppStreamWriter.

private static void
reportJavaInfo(PrintWriter
The AppStreamWriter to write info out to. If this is null, the info is written to System.out
localAW
)

Writes out the relevant info about the Java environment to the specified AppStreamWriter.

private static void
reportLocales(PrintWriter
the AppStreamWriter to which the info is written. If this value is null, the info is written to System.out
localAW
)

Writes out information about the locales with the product.

private static void
reportTesting(PrintWriter
the AppStreamWriter to which the info is written. If this value is null, the info is written to System.out
localAW
)

Writes out information about the derbyTesting classes with the product.

private static void
private static void
tryAsResource(String cn, String library, StringBuffer successes, StringBuffer failures)

private static void
private static void
private static void
tryMyClasspath(String cn, String library, StringBuffer successes, StringBuffer failures)

private static void
private static void
private static void
private static void
pack-priv static void
useMe(String[] args, PrintWriter pw)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CLIENTback to summary
private static final String CLIENT
cptesterback to summary
private static boolean cptester
curLocback to summary
private static final String curLoc
EMBEDDEDback to summary
private static final String EMBEDDED
infoNamesback to summary
private static final String[] infoNames
jarNamesback to summary
private static final String[] jarNames
javaSepback to summary
private static final String javaSep
jbmsSepback to summary
private static final String jbmsSep
licSepback to summary
private static final String licSep
LOCALIZED_RESOURCEback to summary
private static final LocalizedResource LOCALIZED_RESOURCE

Resource for localizing the sysinfo messages. The default LocalizedResource reads messages from the toolsmessages bundle. Create this instance to read messages from sysinfoMessages. Use the locale and codeset specified by derby.ui.locale and derby.ui.codeset if they are set. Note that this variable must be initialized when the class is loaded in order to work correctly for the API methods that don't call main().

locSepback to summary
private static final String locSep
MAINUSAGESTRINGback to summary
private static final String MAINUSAGESTRING
NETback to summary
private static final String NET
sepback to summary
private static final String sep

for use by the main () method

setLicenseback to summary
private static boolean setLicense
setPauseback to summary
private static boolean setPause
TEST_CLASS_NAMEback to summary
private static final String TEST_CLASS_NAME
TOOLSback to summary
private static final String TOOLS
USAGESTRINGPARTAback to summary
private static final String USAGESTRINGPARTA
USAGESTRINGPARTBback to summary
private static final String USAGESTRINGPARTB

Constructor Detail

Mainback to summary
public Main()

Method Detail

argumentMatchesback to summary
private static String argumentMatches(String[] args, String ss)
argumentsContainback to summary
private static boolean argumentsContain(String[] args, String s)
checkDirectoryback to summary
private static ZipInfoProperties checkDirectory(String dirname)

Check a given directory for the presence of an info properties file in org/apache/derby/info inside the directory.

Parameters
dirname:String

the directory to check as a String

Returns:ZipInfoProperties

a ZipInfoProperties if a file is found, otherwise null.

checkFileback to summary
private static ZipInfoProperties checkFile(String filename)

Check inside a jar file for the presence of a Derby info properties file.

Parameters
filename:String

the jar file to check

Returns:ZipInfoProperties

ZipInfoProperties with the jar file set as the location or null if not found.

checkForInfoback to summary
private static ZipInfoProperties checkForInfo(final String cpEntry)

Given an individual element of the element of the classpath, call checkDirectory() if the element is a directory or checkFile() if the element is a file.

Parameters
cpEntry:String

the classpath element

Returns:ZipInfoProperties

a ZipInfoProperties if an info properties file is found.

crLfback to summary
private static String crLf()
formatURLback to summary
private static String formatURL(URL loc)

Strip a given URL down to the filename. The URL will be a jarfile or directory containing a Derby info properties file. Return the canonical path for the filename, with the path separators normalized.

foundback to summary
private static String found(String cn, String library, String loc)
getAllInfoback to summary
public static ZipInfoProperties[] getAllInfo(String classpath)

Get all the info we can obtain from the local execution context as to the availability of the Derby classes by attempting to load the info files with loadZipFromResource() and checking classpath locations with checkForInfo if the classpath is accessible.

Parameters
classpath:String

the classpath, or null if not accessible

Returns:ZipInfoProperties[]

an array of ZipInfoProperties with the locations of the located resources

See Also
loadZipFromResource(), checkForInfo(String)
getCanonicalPathback to summary
private static String getCanonicalPath(final File f) throws IOException

wrapper for getCanonicalPath for sysinfo. When we installed a SecurityManager (see DERBY-7138), we wanted to print the security exceptions for sysinfo, not throw them if we didn't have permmission

Parameters
f:File

file on which to call getCanonicalPath

Returns:String

f.getCanonicalPath

getClasspathInfoback to summary
private static void getClasspathInfo(String[] args, PrintWriter aw)
getFileWhichLoadedClassback to summary
private static String getFileWhichLoadedClass(final Class<T> cls)

Given a loaded class, this routine asks the class's class loader for information about where the class was loaded from. Typically, this is a file, which might be either a class file or a jar file. The routine figures that out, and returns the name of the file. If it can't figure it out, it returns null

getJavaPropertyback to summary
private static String getJavaProperty(final String whichProperty)

Return Java properties from java.lang.System.

Parameters
whichProperty:String

This is the name of the property

Returns:String

getJavaProperty(whichProperty, false)

getJavaPropertyback to summary
private static String getJavaProperty(final String whichProperty, boolean nullUnavailable)

Return Java properties from java.lang.System.

Parameters
whichProperty:String

This is the name of the property

nullUnavailable:boolean

return nothing if no such java property and nullUnavailable is true

Returns:String

the Java property value or a string capturing a security exception.

getMainInfoback to summary
public static void getMainInfo(PrintWriter aw, boolean pause)
getTextMessageback to summary
public static String getTextMessage(String msgId, Object... arguments)
loadZipFromResourceback to summary
private static ZipInfoProperties[] loadZipFromResource()

Attempt to load the info properties files specified in infoNames[i] using getResourceAsStream(). If none are able to be loaded, return a null array.

Returns:ZipInfoProperties[]

An array of ZipInfoProperties with the locations from which the info properties files were loaded.

See Also
infoNames
lookForMainArgback to summary
private static String lookForMainArg(String[] args, PrintWriter localPW)
mainback to summary
public static void main(String[] args)

Application entry point for SysInfo. This will print out the Derby product information as well as a snapshot of the System properties.

mergeZipsback to summary
private static ZipInfoProperties[] mergeZips(ZipInfoProperties[] zip1, ZipInfoProperties[] zip2)

Merge and flatten two arrays of ZipInfoProperties, removing any duplicates. There may be duplicates in the arrays because loadZipFromResource may find all the properties files in the same location, such as when loading from compiled source instead of packaged jars. Also, a poorly constructed classpath may contain duplicate entries that each contain the Derby classes, and we need only report the first of each such instances found.

The second array may be null if the classpath was empty, in which case we still remove the duplicates from the first array and return the shortened array.

Parameters
zip1:ZipInfoProperties[]

the first array from loadZipWithResource

zip2:ZipInfoProperties[]

the second array from analyzing the classpath

Returns:ZipInfoProperties[]

the merged array

notFoundback to summary
private static String notFound(String cn, String library)
parseArgsback to summary
private static void parseArgs(String[] args)
parseClasspathback to summary
private static String[] parseClasspath(String cp)

Split the classpath into separate elements.

Parameters
cp:String

the classpath, if accessible.

Returns:String[]

a String array with the individual classpath elements.

pauseback to summary
private static void pause()

For the benefit of DOS box users, this method waits for input before returning

printPropertyIfNotNullback to summary
private static void printPropertyIfNotNull(PrintWriter localAW, String property)

Print property only if not null

Parameters
localAW:PrintWriter

This is PrintWriter to print to

property:String

This is system property string

reportDerbyback to summary
private static void reportDerby(PrintWriter localAW)

prints out the jbms info to the specified AppStreamWriter.

Parameters
localAW:PrintWriter

the AppStreamWriter to use. If null, System.out is used

reportJavaInfoback to summary
private static void reportJavaInfo(PrintWriter localAW)

Writes out the relevant info about the Java environment to the specified AppStreamWriter.

Parameters
localAW:PrintWriter

The AppStreamWriter to write info out to. If this is null, the info is written to System.out

reportLocalesback to summary
private static void reportLocales(PrintWriter localAW)

Writes out information about the locales with the product.

Parameters
localAW:PrintWriter

the AppStreamWriter to which the info is written. If this value is null, the info is written to System.out

reportTestingback to summary
private static void reportTesting(PrintWriter localAW)

Writes out information about the derbyTesting classes with the product.

Parameters
localAW:PrintWriter

the AppStreamWriter to which the info is written. If this value is null, the info is written to System.out

tryAllClasspathsback to summary
private static void tryAllClasspaths(PrintWriter localPW) throws Throwable
tryAsResourceback to summary
private static void tryAsResource(String cn, String library, StringBuffer successes, StringBuffer failures)
tryClientClasspathback to summary
private static void tryClientClasspath(StringBuffer successes, StringBuffer failures)
tryCoreClasspathback to summary
private static void tryCoreClasspath(StringBuffer successes, StringBuffer failures)
tryMyClasspathback to summary
private static void tryMyClasspath(String cn, String library, StringBuffer successes, StringBuffer failures)
tryNetClasspathback to summary
private static void tryNetClasspath(StringBuffer successes, StringBuffer failures)
trySomeClasspathsback to summary
private static void trySomeClasspaths(String[] args, PrintWriter localPW) throws Throwable
tryTstingClasspathback to summary
private static void tryTstingClasspath(StringBuffer successes, StringBuffer failures)
tryUtilsClasspathback to summary
private static void tryUtilsClasspath(StringBuffer successes, StringBuffer failures)
useMeback to summary
pack-priv static void useMe(String[] args, PrintWriter pw)
org.apache.derby.impl.tools.sysinfo back to summary

public Class Main.LocaleSorter

extends Object
implements Comparator<Locale>
Class Inheritance
All Implemented Interfaces
java.util.Comparator

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int
compare(Locale
the first object to be compared.
left
,
Locale
the second object to be compared.
right
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

LocaleSorterback to summary
public LocaleSorter()

Method Detail

compareback to summary
public int compare(Locale left, Locale right)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
left:Locale

the first object to be compared.

right:Locale

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.