You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by od...@apache.org on 2010/06/02 12:44:52 UTC

svn commit: r950482 - in /harmony/enhanced/java/trunk/classlib/modules/instrument/src: main/native/instrument/shared/ test/java/org/apache/harmony/tests/java/lang/instrument/ test/resources/jars/org/apache/harmony/tests/instrument/

Author: odeakin
Date: Wed Jun  2 10:44:52 2010
New Revision: 950482

URL: http://svn.apache.org/viewvc?rev=950482&view=rev
Log:
The spec says that if the Boot-Class-Path entry in a java agent manifest specifies a relative path, that path should be taken relative to the location of the agent jar. Also adding a regression test case for this fix.

Added:
    harmony/enhanced/java/trunk/classlib/modules/instrument/src/test/resources/jars/org/apache/harmony/tests/instrument/BCP.jar   (with props)
    harmony/enhanced/java/trunk/classlib/modules/instrument/src/test/resources/jars/org/apache/harmony/tests/instrument/BCPTest.jar   (with props)
Modified:
    harmony/enhanced/java/trunk/classlib/modules/instrument/src/main/native/instrument/shared/inst_agt.c
    harmony/enhanced/java/trunk/classlib/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/InstrumentTest.java

Modified: harmony/enhanced/java/trunk/classlib/modules/instrument/src/main/native/instrument/shared/inst_agt.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/instrument/src/main/native/instrument/shared/inst_agt.c?rev=950482&r1=950481&r2=950482&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/instrument/src/main/native/instrument/shared/inst_agt.c (original)
+++ harmony/enhanced/java/trunk/classlib/modules/instrument/src/main/native/instrument/shared/inst_agt.c Wed Jun  2 10:44:52 2010
@@ -380,10 +380,35 @@ jint Parse_Options(JavaVM *vm, JNIEnv *e
     //add bootclasspath
 
     bootclasspath = read_attribute(vm, manifest, lwrmanifest,"boot-class-path");
-    if(NULL != bootclasspath){
+    if (NULL != bootclasspath){
+        
+#if defined(WIN32) || defined(WIN64)
+        // On Windows the agent jar path can have a mixture of forward and back slashes.
+        // For ease, convert forward slashes to back slashes
+        char *currentSlash = strchr(jar_name, '/');
+        while (currentSlash) {
+            *currentSlash = '\\';
+            currentSlash = strchr(currentSlash, '/');
+        }
+#endif
+
         bootclasspath_item = strtok(bootclasspath, " ");
         while(NULL != bootclasspath_item){
-            check_jvmti_error(env, (*jvmti)->AddToBootstrapClassLoaderSearch(jvmti, bootclasspath_item),"Failed to add bootstrap classpath.");
+            if ((bootclasspath_item[0] != DIR_SEPARATOR) && (strrchr(jar_name, DIR_SEPARATOR))) {
+                // This is not an absolute path, so add this relative path to the path of the agent library
+                int lastSeparatorOff = strrchr(jar_name, DIR_SEPARATOR) - jar_name + 1;
+                int size = lastSeparatorOff + strlen(bootclasspath_item) + 1;
+                char *jarPath = (char *)hymem_allocate_memory(size);
+                
+                memcpy(jarPath, jar_name, lastSeparatorOff);
+                strcpy(jarPath + lastSeparatorOff, bootclasspath_item);
+                check_jvmti_error(env, (*jvmti)->AddToBootstrapClassLoaderSearch(jvmti, jarPath),"Failed to add bootstrap classpath.");
+                hymem_free_memory(jarPath);
+            } else {
+                // This is either an absolute path of jar_name has not path before the filename
+                check_jvmti_error(env, (*jvmti)->AddToBootstrapClassLoaderSearch(jvmti, bootclasspath_item),"Failed to add bootstrap classpath.");
+            }           
+
             bootclasspath_item = strtok(NULL, " ");
         }
         hymem_free_memory(bootclasspath);

Modified: harmony/enhanced/java/trunk/classlib/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/InstrumentTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/InstrumentTest.java?rev=950482&r1=950481&r2=950482&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/InstrumentTest.java (original)
+++ harmony/enhanced/java/trunk/classlib/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/InstrumentTest.java Wed Jun  2 10:44:52 2010
@@ -205,4 +205,16 @@ public class InstrumentTest extends Test
         String result = Support_Exec.execJava(arg, path, true);
         assertEquals("", result);
     }
+
+    /**
+     * @tests test manifest Boot-Class-Path property is treated 
+     *        correctly
+     */
+    public void test_boot_class_path() throws Exception {
+        String[] arg = new String[2];
+        arg[0] = "-javaagent:resources/jars/org/apache/harmony/tests/instrument/BCPTest.jar";
+        arg[1] = "org/apache/harmony/tests/java/lang/instrument/TestMain";
+        String result = Support_Exec.execJava(arg, null, true);
+        assertEquals("Hello World", result.trim());
+    }
 }

Added: harmony/enhanced/java/trunk/classlib/modules/instrument/src/test/resources/jars/org/apache/harmony/tests/instrument/BCP.jar
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/instrument/src/test/resources/jars/org/apache/harmony/tests/instrument/BCP.jar?rev=950482&view=auto
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/java/trunk/classlib/modules/instrument/src/test/resources/jars/org/apache/harmony/tests/instrument/BCP.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: harmony/enhanced/java/trunk/classlib/modules/instrument/src/test/resources/jars/org/apache/harmony/tests/instrument/BCPTest.jar
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/instrument/src/test/resources/jars/org/apache/harmony/tests/instrument/BCPTest.jar?rev=950482&view=auto
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/java/trunk/classlib/modules/instrument/src/test/resources/jars/org/apache/harmony/tests/instrument/BCPTest.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream