java.lang.Object
org.apache.derby.impl.tools.sysinfo.Main

public final class Main extends Object

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 Details

    • MESSAGE_FILE

      private static final String MESSAGE_FILE
      Name of file which contains messages for sysinfo.
      See Also:
    • LOCALIZED_RESOURCE

      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().
    • setPause

      private static boolean setPause
    • setLicense

      private static boolean setLicense
    • cptester

      private static boolean cptester
    • sep

      private static final String sep
      for use by the main () method
      See Also:
    • javaSep

      private static final String javaSep
    • jbmsSep

      private static final String jbmsSep
    • licSep

      private static final String licSep
    • locSep

      private static final String locSep
    • curLoc

      private static final String curLoc
    • EMBEDDED

      private static final String EMBEDDED
      See Also:
    • TOOLS

      private static final String TOOLS
      See Also:
    • NET

      private static final String NET
      See Also:
    • CLIENT

      private static final String CLIENT
      See Also:
    • MAINUSAGESTRING

      private static final String MAINUSAGESTRING
      See Also:
    • USAGESTRINGPARTA

      private static final String USAGESTRINGPARTA
      See Also:
    • USAGESTRINGPARTB

      private static final String USAGESTRINGPARTB
      See Also:
    • infoNames

      private static final String[] infoNames
    • jarNames

      private static final String[] jarNames
  • Constructor Details

    • Main

      public Main()
  • Method Details

    • main

      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.
    • getMainInfo

      public static void getMainInfo(PrintWriter aw, boolean pause)
    • parseArgs

      private static void parseArgs(String[] args)
    • pause

      private static void pause()
      For the benefit of DOS box users, this method waits for input before returning
    • reportDerby

      private static void reportDerby(PrintWriter localAW)
      prints out the jbms info to the specified AppStreamWriter.
      Parameters:
      localAW - the AppStreamWriter to use. If null, System.out is used
    • reportJavaInfo

      private static void reportJavaInfo(PrintWriter localAW)
      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

      private static void printPropertyIfNotNull(PrintWriter localAW, String property)
      Print property only if not null
      Parameters:
      localAW - This is PrintWriter to print to
      property - This is system property string
    • getJavaProperty

      private static String getJavaProperty(String whichProperty)
      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

      private static String getJavaProperty(String whichProperty, boolean nullUnavailable)
      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
      nullUnavailable - return nothing if no such java property and nullUnavailable is true
      Returns:
      the Java property value or a string capturing a security exception.
    • getCanonicalPath

      private static String getCanonicalPath(File f) throws IOException
      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

      private static void getClasspathInfo(String[] args, PrintWriter aw)
    • reportLocales

      private static void reportLocales(PrintWriter localAW)
      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

      private static void reportTesting(PrintWriter localAW)
      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

      static void useMe(String[] args, PrintWriter pw)
    • tryAllClasspaths

      private static void tryAllClasspaths(PrintWriter localPW) throws Throwable
      Throws:
      Throwable
    • trySomeClasspaths

      private static void trySomeClasspaths(String[] args, PrintWriter localPW) throws Throwable
      Throws:
      Throwable
    • tryCoreClasspath

      private static void tryCoreClasspath(StringBuffer successes, StringBuffer failures)
    • tryNetClasspath

      private static void tryNetClasspath(StringBuffer successes, StringBuffer failures)
    • tryClientClasspath

      private static void tryClientClasspath(StringBuffer successes, StringBuffer failures)
    • tryUtilsClasspath

      private static void tryUtilsClasspath(StringBuffer successes, StringBuffer failures)
    • tryTstingClasspath

      private static void tryTstingClasspath(StringBuffer successes, StringBuffer failures)
    • 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

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

      private static String notFound(String cn, String library)
    • crLf

      private static String crLf()
    • lookForMainArg

      private static String lookForMainArg(String[] args, PrintWriter localPW)
    • argumentsContain

      private static boolean argumentsContain(String[] args, String s)
    • argumentMatches

      private static String argumentMatches(String[] args, String ss)
    • getAllInfo

      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 - the classpath, or null if not accessible
      Returns:
      an array of ZipInfoProperties with the locations of the located resources
      See Also:
    • loadZipFromResource

      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:
      An array of ZipInfoProperties with the locations from which the info properties files were loaded.
      See Also:
    • parseClasspath

      private static String[] parseClasspath(String cp)
      Split the classpath into separate elements.
      Parameters:
      cp - the classpath, if accessible.
      Returns:
      a String array with the individual classpath elements.
    • checkForInfo

      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.
      Parameters:
      cpEntry - the classpath element
      Returns:
      a ZipInfoProperties if an info properties file is found.
    • checkDirectory

      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 - the directory to check as a String
      Returns:
      a ZipInfoProperties if a file is found, otherwise null.
    • checkFile

      private static ZipInfoProperties checkFile(String filename)
      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

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

      private static String getFileWhichLoadedClass(Class 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
    • mergeZips

      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 - the first array from loadZipWithResource
      zip2 - the second array from analyzing the classpath
      Returns:
      the merged array
    • formatURL

      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.