harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From regi...@apache.org
Subject svn commit: r959877 - in /harmony/enhanced/java/branches/java6/classlib/modules/instrument/src: main/java/org/apache/harmony/instrument/internal/ test/java/org/apache/harmony/tests/java/lang/instrument/ test/java/org/apache/harmony/tests/java/lang/inst...
Date Fri, 02 Jul 2010 06:54:01 GMT
Author: regisxu
Date: Fri Jul  2 06:54:01 2010
New Revision: 959877

URL: http://svn.apache.org/viewvc?rev=959877&view=rev
Log:
Apply patch for HARMONY-6565: [java6][classlib][instrument]NoSuchMethodException throws when
Agent only implements premain(String) method

Added:
    harmony/enhanced/java/branches/java6/classlib/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/HelloWorldOneArgTest.java
  (with props)
    harmony/enhanced/java/branches/java6/classlib/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/agents/HelloWorldOneArgAgent.java
  (with props)
Modified:
    harmony/enhanced/java/branches/java6/classlib/modules/instrument/src/main/java/org/apache/harmony/instrument/internal/InstrumentationImpl.java

Modified: harmony/enhanced/java/branches/java6/classlib/modules/instrument/src/main/java/org/apache/harmony/instrument/internal/InstrumentationImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/instrument/src/main/java/org/apache/harmony/instrument/internal/InstrumentationImpl.java?rev=959877&r1=959876&r2=959877&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/instrument/src/main/java/org/apache/harmony/instrument/internal/InstrumentationImpl.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/instrument/src/main/java/org/apache/harmony/instrument/internal/InstrumentationImpl.java
Fri Jul  2 06:54:01 2010
@@ -37,9 +37,12 @@ public class InstrumentationImpl impleme
      * ----------------------------------------------------------------------------
      */
 
-    private static final Class[] PREMAIN_SIGNATURE = new Class[] {
+    private static final Class[] PREMAIN_AGENTMAIN_2_ARGS_SIGNATURE = new Class[] {
             String.class, Instrumentation.class };
 
+    private static final Class[] PREMAIN_AGENTMAIN_1_ARG_SIGNATURE = new Class[] {
+            String.class };
+
     /*
      * ----------------------------------------------------------------------------
      * Variables
@@ -209,9 +212,21 @@ public class InstrumentationImpl impleme
         try {
             ClassLoader loader = ClassLoader.getSystemClassLoader();
             Class c = loader.loadClass(utf8BytesToString(className));
-            Method method = c.getMethod("premain", PREMAIN_SIGNATURE); //$NON-NLS-1$
-            method.invoke(null, new Object[] {
-                    null == options ? null : utf8BytesToString(options), this });
+            String optionsStr = null == options ? null : utf8BytesToString(options);
+            Method method;
+            /*
+             * Refer to spec, first attempts to invoke:
+             *     public static void premain(String agentArgs, Instrumentation inst);
+             * If the agent class does not implement this method then the JVM will attempt
to invoke:
+             *     public static void premain(String agentArgs);
+             */
+            try {
+                method = c.getMethod("premain", PREMAIN_AGENTMAIN_2_ARGS_SIGNATURE); //$NON-NLS-1$
+                method.invoke(null, new Object[] { optionsStr, this });
+            } catch (NoSuchMethodException e) {
+                method = c.getMethod("premain", PREMAIN_AGENTMAIN_1_ARG_SIGNATURE);
+                method.invoke(null, new Object[] { optionsStr });
+            }
         } catch (Exception e) {
             e.printStackTrace();
             System.err

Added: harmony/enhanced/java/branches/java6/classlib/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/HelloWorldOneArgTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/HelloWorldOneArgTest.java?rev=959877&view=auto
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/HelloWorldOneArgTest.java
(added)
+++ harmony/enhanced/java/branches/java6/classlib/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/HelloWorldOneArgTest.java
Fri Jul  2 06:54:01 2010
@@ -0,0 +1,67 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.tests.java.lang.instrument;
+
+import static org.apache.harmony.tests.java.lang.instrument.InstrumentTestHelper.LINE_SEPARATOR;
+import static org.apache.harmony.tests.java.lang.instrument.InstrumentTestHelper.PREMAIN_CLASS;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.tests.java.lang.instrument.agents.HelloWorldOneArgAgent;
+
+public class HelloWorldOneArgTest extends TestCase {
+    private InstrumentTestHelper helper = null;
+
+    private static String JAR_PREFIX = "HelloWorldOneArgTest";
+
+    @Override
+    public void setUp() {
+        helper = new InstrumentTestHelper();
+    }
+
+    @Override
+    public void tearDown() {
+        helper.clean();
+    }
+
+    public void testHelloWorld() throws Exception {
+        helper.addManifestAttributes(PREMAIN_CLASS, HelloWorldOneArgAgent.class
+                .getName());
+        helper.setJarName(JAR_PREFIX + ".testHelloWorld.jar");
+        helper.setMainClass(TestMain.class);
+        List<Class> classes = new ArrayList<Class>();
+        classes.add(HelloWorldOneArgAgent.class);
+        helper.addClasses(classes);
+
+        helper.run();
+
+        if (helper.getExitCode() != 0) {
+            System.out.println("std err:");
+            System.out.println(helper.getStdErr());
+            System.out.println("std out:");
+            System.out.println(helper.getStdOut());
+            fail("helper exit code was non-zero");
+        }
+        assertEquals("Hello World With One Arg" + LINE_SEPARATOR, helper.getStdOut());
+        assertEquals("", helper.getStdErr());
+    }
+
+}

Propchange: harmony/enhanced/java/branches/java6/classlib/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/HelloWorldOneArgTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/java/branches/java6/classlib/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/agents/HelloWorldOneArgAgent.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/agents/HelloWorldOneArgAgent.java?rev=959877&view=auto
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/agents/HelloWorldOneArgAgent.java
(added)
+++ harmony/enhanced/java/branches/java6/classlib/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/agents/HelloWorldOneArgAgent.java
Fri Jul  2 06:54:01 2010
@@ -0,0 +1,24 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.tests.java.lang.instrument.agents;
+
+public class HelloWorldOneArgAgent {
+    public static void premain(String agentArgs) {
+        System.out.println("Hello World With One Arg");
+    }
+}

Propchange: harmony/enhanced/java/branches/java6/classlib/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/agents/HelloWorldOneArgAgent.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message