You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by bp...@apache.org on 2006/03/21 19:36:51 UTC

svn commit: r387599 - in /db/derby/code/trunk/java: testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/master/DerbyNet/ testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/ tools/org/apac...

Author: bpendleton
Date: Tue Mar 21 10:36:49 2006
New Revision: 387599

URL: http://svn.apache.org/viewcvs?rev=387599&view=rev
Log:
DERBY-668: SysInfo does not print the right info in class loader scenarios

This change modifies the sysinfo tool to print additional information about
the classes and jars that it examines. For each class that sysinfo examines,
it now calls getProtectionDomain().getCodeSource() to retrieve information
about the source of that file, which might be: an entry in the application
classpath, an entry in a class loader location list, a jar fetched due to
being listed in the manifest entry of another jar, a standard extension
in the JRE's extensions directory, a jar installed into the application
server, or any of various other possibilities.

The additional information about the class's origin is displayed in the
sysinfo output.

Note that when sysinfo runs under a Java security manager, it may need
special permissions to access this additional information, including the
permission to read the java.class.path property, and the permission to
call getProtectionDomain on a class. If sysinfo is not granted these
permissions, it will display an error message about the security problem
in place of displaying the class origin information.


Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/sysinfo.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/sysinfo.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/RunClassPathTester.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/sysinfo_withproperties.out
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/sysinfo/Main.java
    db/derby/code/trunk/java/tools/org/apache/derby/loc/sysinfoMessages.properties

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/sysinfo.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/sysinfo.out?rev=387599&r1=387598&r2=387599&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/sysinfo.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/sysinfo.out Tue Mar 21 10:36:49 2006
@@ -12,6 +12,7 @@
 derby.drda.host=xxxFILTERED_HOSTNAMExxx
 derby.drda.traceAll=false
 ----- Derby Information --------
+Unable to analyze class path: access denied (java.util.PropertyPermission java.class.path read)
 -----
 ----- Locale Information -----------------
 Current Locale :  [English/United States [en_US]]
@@ -39,6 +40,7 @@
 derby.drda.host=xxxFILTERED_HOSTNAMExxx
 derby.drda.traceAll=false
 ----- Derby Information --------
+Unable to analyze class path: access denied (java.util.PropertyPermission java.class.path read)
 -----
 ----- Locale Information -----------------
 Current Locale :  [English/United States [en_US]]
@@ -67,6 +69,7 @@
 derby.drda.host=xxxFILTERED_HOSTNAMExxx
 derby.drda.traceAll=false
 ----- Derby Information --------
+Unable to analyze class path: access denied (java.util.PropertyPermission java.class.path read)
 -----
 ----- Locale Information -----------------
 Current Locale :  [English/United States [en_US]]

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/sysinfo.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/sysinfo.out?rev=387599&r1=387598&r2=387599&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/sysinfo.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/sysinfo.out Tue Mar 21 10:36:49 2006
@@ -12,6 +12,7 @@
 derby.drda.host=xxxFILTERED_HOSTNAMExxx
 derby.drda.traceAll=false
 ----- Derby Information --------
+Unable to analyze class path: access denied (java.util.PropertyPermission java.class.path read)
 -----
 ----- Locale Information -----------------
 Current Locale :  [English/United States [en_US]]
@@ -39,6 +40,7 @@
 derby.drda.host=xxxFILTERED_HOSTNAMExxx
 derby.drda.traceAll=false
 ----- Derby Information --------
+Unable to analyze class path: access denied (java.util.PropertyPermission java.class.path read)
 -----
 ----- Locale Information -----------------
 Current Locale :  [English/United States [en_US]]
@@ -67,6 +69,7 @@
 derby.drda.host=xxxFILTERED_HOSTNAMExxx
 derby.drda.traceAll=false
 ----- Derby Information --------
+Unable to analyze class path: access denied (java.util.PropertyPermission java.class.path read)
 -----
 ----- Locale Information -----------------
 Current Locale :  [English/United States [en_US]]

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/RunClassPathTester.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/RunClassPathTester.out?rev=387599&r1=387598&r2=387599&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/RunClassPathTester.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/RunClassPathTester.out Tue Mar 21 10:36:49 2006
@@ -1,4 +1,6 @@
 FOUND IN CLASS PATH:
    Derby embedded engine library (derby.jar)
+   Unable to access Protection Domain or Code Source for class interface org.apache.derby.database.Database: access denied (java.lang.RuntimePermission getProtectionDomain)
    user-specified class (SimpleApp)
+   Unable to access Protection Domain or Code Source for class class SimpleApp: access denied (java.lang.RuntimePermission getProtectionDomain)
 SUCCESS: All Derby related classes found in class path.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/sysinfo_withproperties.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/sysinfo_withproperties.out?rev=387599&r1=387598&r2=387599&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/sysinfo_withproperties.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/sysinfo_withproperties.out Tue Mar 21 10:36:49 2006
@@ -13,6 +13,7 @@
 derby.drda.host=xxxFILTERED_HOSTNAMExxx
 derby.drda.traceAll=false
 ----- Derby Information --------
+Unable to analyze class path: access denied (java.util.PropertyPermission java.class.path read)
 -----
 ----- Locale Information -----------------
 Current Locale :  [English/United States [en_US]]
@@ -41,6 +42,7 @@
 derby.drda.host=xxxFILTERED_HOSTNAMExxx
 derby.drda.traceAll=false
 ----- Derby Information --------
+Unable to analyze class path: access denied (java.util.PropertyPermission java.class.path read)
 -----
 ----- Locale Information -----------------
 Current Locale :  [English/United States [en_US]]
@@ -70,6 +72,7 @@
 derby.drda.host=xxxFILTERED_HOSTNAMExxx
 derby.drda.traceAll=false
 ----- Derby Information --------
+Unable to analyze class path: access denied (java.util.PropertyPermission java.class.path read)
 -----
 ----- Locale Information -----------------
 Current Locale :  [English/United States [en_US]]

Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/sysinfo/Main.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/sysinfo/Main.java?rev=387599&r1=387598&r2=387599&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/sysinfo/Main.java (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/sysinfo/Main.java Tue Mar 21 10:36:49 2006
@@ -39,6 +39,11 @@
 import java.util.Vector;
 import java.io.InputStream;
 import java.lang.reflect.Method;
+import java.net.URL;
+import java.security.ProtectionDomain;
+import java.security.CodeSource;
+import java.security.PrivilegedAction;
+import java.security.AccessController;
 
 import org.apache.derby.iapi.services.info.PropertyNames;
 import org.apache.derby.iapi.services.info.ProductVersionHolder;
@@ -195,6 +200,8 @@
 		  classpath = System.getProperty("java.class.path");
 	  }
 	  catch (SecurityException se) {
+          localAW.println(
+              Main.getTextMessage ("SIF01.U", se.getMessage()));
 		  classpath = null;
 	  }
 
@@ -573,8 +580,9 @@
 	private static void tryMyClasspath(String cn, String library, StringBuffer successes, StringBuffer failures) {
 
 		try {
-			Class.forName(cn);
-			successes.append(found(cn, library));
+			Class c = Class.forName(cn);
+                        String loc = getFileWhichLoadedClass(c);
+                        successes.append(found(cn, library, loc));
 		}
 
 		catch (Throwable t) {
@@ -591,7 +599,8 @@
 		try {
 			java.io.InputStream in = cn.getClass().getResourceAsStream(cn);
 			in.close();
-			successes.append(found(cn, library));
+                        String loc = getFileWhichLoadedClass(cn.getClass());
+			successes.append(found(cn, library, loc));
 		}
 
 		catch (Throwable t) {
@@ -601,10 +610,12 @@
 
 	}
 
-	private static String found(String cn, String library) {
+	private static String found(String cn, String library, String loc) {
 		StringBuffer temp = new StringBuffer(crLf());
 		temp.append("   " + library);
 		temp.append(crLf());
+                if (loc != null)
+                    temp.append("   ").append(loc).append(crLf());
 		temp.append(crLf());
 		return temp.toString();
 	}
@@ -885,6 +896,16 @@
 
 		ZipInfoProperties zip = new ZipInfoProperties(jccVersion);
 
+                String loc = getFileWhichLoadedClass(c);
+                // For db2jcc.jar, report the actual file from which DB2Driver
+                // was loaded, if we can determine it. For db2jcc_license_c,
+                // report the filename from the classpath, and the version 
+                // info from the DB2Driver that we loaded. This is slightly
+                // misleading, since db2jcc_license_c.jar doesn't really have
+                // a "version", but the two jars are usually linked.
+                if (loc != null && filename.indexOf("license_c") < 0)
+                    zip.setLocation(loc);
+                else
         zip.setLocation(new File(filename).getCanonicalPath().replace('/', File.separatorChar));
 		return zip;
             } catch (Exception e) { return null; }
@@ -965,5 +986,53 @@
 		// we have a base file (sysinfoMessages.properties) so don't give us a last chance.
 		return org.apache.derby.iapi.services.i18n.MessageService.formatMessage(getBundle(), msgId, arguments, false);
 	}
+
+    /**
+     * 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
+     */
+    private static String getFileWhichLoadedClass(final Class cls)
+    {
+         return (String)AccessController.doPrivileged( new PrivilegedAction()
+        {
+            public Object run()
+            {
+                CodeSource cs = null;
+                try {
+                    cs = cls.getProtectionDomain().getCodeSource ();
+                }
+                catch (SecurityException se) {
+                    return Main.getTextMessage("SIF01.V", cls, se.getMessage());
+                }
+ 
+                if ( cs == null )
+                    return null;        
+     
+                URL result = cs.getLocation ();
+     
+                String loc;
+
+                // If the class is found directly as a class file, loc has the
+                // filename of that classfile. If the class is found in a jar,
+                // loc has the format: 
+                //   file:[jarName]!className
+                // In that case, we fetch the jarName and return it.
+                if ("file".equals(result.getProtocol()))
+                {
+                    loc = result.getPath();
+                    if (loc.indexOf("!") > 0)
+                        loc = loc.substring(0, loc.indexOf("!"));
+                }
+                else
+                {
+                    loc = result.toString();
+                }
+                return loc;
+            }
+        });
+    }
 } // end of class Main
 

Modified: db/derby/code/trunk/java/tools/org/apache/derby/loc/sysinfoMessages.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/tools/org/apache/derby/loc/sysinfoMessages.properties?rev=387599&r1=387598&r2=387599&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/loc/sysinfoMessages.properties (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/loc/sysinfoMessages.properties Tue Mar 21 10:36:49 2006
@@ -20,6 +20,8 @@
 SIF01.R=Found support for locale: [{0}]
 SIF01.S=\t version: {0}
 SIF01.T=Current Locale :
+SIF01.U=Unable to analyze class path: {0}
+SIF01.V=Unable to access Protection Domain or Code Source for class {0}: {1}
 
 
 # VM environment properties.