Class Main
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();
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate 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
Resource for localizing the sysinfo messages.private static final String
private static final String
private static final String
Name of file which contains messages for sysinfo.private static final String
private static final String
for use by the main () methodprivate static boolean
private static boolean
private static final String
private static final String
private static final String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static String
argumentMatches
(String[] args, String ss) private static boolean
argumentsContain
(String[] args, String s) 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.private static ZipInfoProperties
Check inside a jar file for the presence of a Derby info properties file.private static ZipInfoProperties
checkForInfo
(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.private static String
crLf()
private static String
Strip a given URL down to the filename.private static String
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.private static String
wrapper for getCanonicalPath for sysinfo.private static void
getClasspathInfo
(String[] args, PrintWriter aw) private static String
Given a loaded class, this routine asks the class's class loader for information about where the class was loaded from.private static String
getJavaProperty
(String whichProperty) Return Java properties from java.lang.System.private static String
getJavaProperty
(String whichProperty, boolean nullUnavailable) Return Java properties from java.lang.System.static void
getMainInfo
(PrintWriter aw, boolean pause) static String
getTextMessage
(String msgId, Object... arguments) private static ZipInfoProperties[]
Attempt to load the info properties files specified in infoNames[i] using getResourceAsStream().private static String
lookForMainArg
(String[] args, PrintWriter localPW) static void
Application entry point for SysInfo.private static ZipInfoProperties[]
mergeZips
(ZipInfoProperties[] zip1, ZipInfoProperties[] zip2) Merge and flatten two arrays of ZipInfoProperties, removing any duplicates.private static String
private static void
private static String[]
parseClasspath
(String cp) Split the classpath into separate elements.private static void
pause()
For the benefit of DOS box users, this method waits for input before returningprivate static void
printPropertyIfNotNull
(PrintWriter localAW, String property) Print property only if not nullprivate static void
reportDerby
(PrintWriter localAW) prints out the jbms info to the specified AppStreamWriter.private static void
reportJavaInfo
(PrintWriter localAW) Writes out the relevant info about the Java environment to the specified AppStreamWriter.private static void
reportLocales
(PrintWriter localAW) Writes out information about the locales with the product.private static void
reportTesting
(PrintWriter localAW) Writes out information about the derbyTesting classes with the product.private static void
tryAllClasspaths
(PrintWriter localPW) private static void
tryAsResource
(String cn, String library, StringBuffer successes, StringBuffer failures) private static void
tryClientClasspath
(StringBuffer successes, StringBuffer failures) private static void
tryCoreClasspath
(StringBuffer successes, StringBuffer failures) private static void
tryMyClasspath
(String cn, String library, StringBuffer successes, StringBuffer failures) private static void
tryNetClasspath
(StringBuffer successes, StringBuffer failures) private static void
trySomeClasspaths
(String[] args, PrintWriter localPW) private static void
tryTstingClasspath
(StringBuffer successes, StringBuffer failures) private static void
tryUtilsClasspath
(StringBuffer successes, StringBuffer failures) (package private) static void
useMe
(String[] args, PrintWriter pw)
-
Field Details
-
MESSAGE_FILE
Name of file which contains messages for sysinfo.- See Also:
-
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 callmain()
. -
setPause
private static boolean setPause -
setLicense
private static boolean setLicense -
cptester
private static boolean cptester -
sep
for use by the main () method- See Also:
-
javaSep
-
jbmsSep
-
licSep
-
locSep
-
curLoc
-
EMBEDDED
- See Also:
-
TOOLS
- See Also:
-
NET
- See Also:
-
CLIENT
- See Also:
-
MAINUSAGESTRING
- See Also:
-
USAGESTRINGPARTA
- See Also:
-
USAGESTRINGPARTB
- See Also:
-
infoNames
-
jarNames
-
-
Constructor Details
-
Main
public Main()
-
-
Method Details
-
main
Application entry point for SysInfo. This will print out the Derby product information as well as a snapshot of the System properties. -
getMainInfo
-
parseArgs
-
pause
private static void pause()For the benefit of DOS box users, this method waits for input before returning -
reportDerby
prints out the jbms info to the specified AppStreamWriter.- Parameters:
localAW
- the AppStreamWriter to use. If null, System.out is used
-
reportJavaInfo
Writes out the relevant info about the Java environment to the specified AppStreamWriter.- Parameters:
localAW
- The AppStreamWriter to write info out to. If this is null, the info is written to System.out
-
printPropertyIfNotNull
Print property only if not null- Parameters:
localAW
- This is PrintWriter to print toproperty
- This is system property string
-
getJavaProperty
Return Java properties from java.lang.System. Will catch SecurityExceptions and note them for displaying information.- Parameters:
whichProperty
- This is the name of the property- Returns:
- getJavaProperty(whichProperty, false)
-
getJavaProperty
Return Java properties from java.lang.System. Will catch SecurityExceptions and note them for displaying information.- Parameters:
whichProperty
- This is the name of the propertynullUnavailable
- return nothing if no such java property and nullUnavailable is true- Returns:
- the Java property value or a string capturing a security exception.
-
getCanonicalPath
wrapper for getCanonicalPath for sysinfo. For sysinfo we just want to print the security exceptions, not throw them if we don't have permmission- Parameters:
f
- file on which to call getCanonicalPath- Returns:
- f.getCanonicalPath
- Throws:
IOException
-
getClasspathInfo
-
reportLocales
Writes out information about the locales with the product.- Parameters:
localAW
- the AppStreamWriter to which the info is written. If this value is null, the info is written to System.out
-
reportTesting
Writes out information about the derbyTesting classes with the product.- Parameters:
localAW
- the AppStreamWriter to which the info is written. If this value is null, the info is written to System.out
-
useMe
-
tryAllClasspaths
- Throws:
Throwable
-
trySomeClasspaths
- Throws:
Throwable
-
tryCoreClasspath
-
tryNetClasspath
-
tryClientClasspath
-
tryUtilsClasspath
-
tryTstingClasspath
-
tryMyClasspath
private static void tryMyClasspath(String cn, String library, StringBuffer successes, StringBuffer failures) -
tryAsResource
private static void tryAsResource(String cn, String library, StringBuffer successes, StringBuffer failures) -
found
-
notFound
-
crLf
-
lookForMainArg
-
argumentsContain
-
argumentMatches
-
getAllInfo
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
- the classpath, or null if not accessible- Returns:
- an array of ZipInfoProperties with the locations of the located resources
- See Also:
-
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:
- An array of ZipInfoProperties with the locations from which the info properties files were loaded.
- See Also:
-
parseClasspath
Split the classpath into separate elements.- Parameters:
cp
- the classpath, if accessible.- Returns:
- a String array with the individual classpath elements.
-
checkForInfo
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
- the classpath element- Returns:
- a ZipInfoProperties if an info properties file is found.
-
checkDirectory
Check a given directory for the presence of an info properties file in org/apache/derby/info inside the directory.- Parameters:
dirname
- the directory to check as a String- Returns:
- a ZipInfoProperties if a file is found, otherwise null.
-
checkFile
Check inside a jar file for the presence of a Derby info properties file.- Parameters:
filename
- the jar file to check- Returns:
- ZipInfoProperties with the jar file set as the location or null if not found.
-
getTextMessage
-
getFileWhichLoadedClass
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 -
mergeZips
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
- the first array from loadZipWithResourcezip2
- the second array from analyzing the classpath- Returns:
- the merged array
-
formatURL
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.
-