jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject svn commit: r1801864 - in /jmeter/trunk: src/core/org/apache/jmeter/gui/action/ActionRouter.java xdocs/changes.xml
Date Thu, 13 Jul 2017 18:55:59 GMT
Author: fschumacher
Date: Thu Jul 13 18:55:59 2017
New Revision: 1801864

URL: http://svn.apache.org/viewvc?rev=1801864&view=rev
Log:
When looking for classes in ActionRouter, fall back to location of the jar,
where ActionRouter is loaded from.

Provided by Emilian Bold (emi at apache.org)

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/gui/action/ActionRouter.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/action/ActionRouter.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/action/ActionRouter.java?rev=1801864&r1=1801863&r2=1801864&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/action/ActionRouter.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/action/ActionRouter.java Thu Jul 13 18:55:59
2017
@@ -21,10 +21,16 @@ package org.apache.jmeter.gui.action;
 import java.awt.HeadlessException;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.security.CodeSource;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Set;
 
 import javax.swing.SwingUtilities;
@@ -291,6 +297,35 @@ public final class ActionRouter implemen
         }
     }
 
+    private static List<String> findClassesThatExtend(String className, String excluding,
String[] searchPath) throws IOException, ClassNotFoundException {
+            List<String> listClasses = ClassFinder.findClassesThatExtend(
+                    searchPath, // strPathsOrJars - pathNames or jarfiles to search for classes
+                    new Class[] { Class.forName(className) },
+                    false, // innerClasses - should we include inner classes?
+                    null, // contains - className should contain this string
+                    // Ignore the classes which are specific to the reporting tool
+                    excluding, // notContains - className should not contain this string
+                    false); // annotations - true if classNames are annotations
+
+            return listClasses;
+    }
+
+    private static Optional<String[]> getCodeSourceSearchPath() {
+        CodeSource codeSource = ActionRouter.class.getProtectionDomain().getCodeSource();
+        if (codeSource != null) {
+            try {
+                URL ownLocation = codeSource.getLocation();
+                File ownPath = new File(ownLocation.toURI());
+                if (ownPath.exists()) {
+                    return Optional.of(new String[] { ownPath.getAbsolutePath() });
+                }
+            } catch (URISyntaxException ex) {
+                //ignore
+            }
+        }
+        return Optional.empty();
+    }
+
     /**
      * Only for use by the JMeter.startGui.
      * This method must not be called by getInstance() as was done previously.
@@ -301,15 +336,21 @@ public final class ActionRouter implemen
             return; // already done
         }
         try {
-            List<String> listClasses = ClassFinder.findClassesThatExtend(
-                    JMeterUtils.getSearchPaths(), // strPathsOrJars - pathNames or jarfiles
to search for classes
-                    // classNames - required parent class(es) or annotations
-                    new Class[] {Class.forName("org.apache.jmeter.gui.action.Command") },
// $NON-NLS-1$
-                    false, // innerClasses - should we include inner classes?
-                    null, // contains - className should contain this string
-                    // Ignore the classes which are specific to the reporting tool
-                    "org.apache.jmeter.report.gui", // $NON-NLS-1$ // notContains - className
should not contain this string
-                    false); // annotations - true if classNames are annotations
+            List<String> listClasses = findClassesThatExtend("org.apache.jmeter.gui.action.Command",
// $NON-NLS-1$
+                    "org.apache.jmeter.report.gui", // $NON-NLS-1$
+                    JMeterUtils.getSearchPaths());
+
+            if (listClasses.isEmpty()) {
+                //fallback
+                Optional<String[]> codeSourceSearchPath = getCodeSourceSearchPath();
+                if (codeSourceSearchPath.isPresent()) {
+                    log.info("Using fallback search path");
+                    listClasses = findClassesThatExtend("org.apache.jmeter.gui.action.Command",
// $NON-NLS-1$
+                            "org.apache.jmeter.report.gui", // $NON-NLS-1$
+                            codeSourceSearchPath.get());
+                }
+            }
+
             if (listClasses.isEmpty()) {
                 log.error("!!!!!Uh-oh, didn't find any action handlers!!!!!");
                 throw new JMeterError("No action handlers found - check JMeterHome and libraries");
@@ -344,3 +385,4 @@ public final class ActionRouter implemen
         return INSTANCE;
     }
 }
+

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1801864&r1=1801863&r2=1801864&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Thu Jul 13 18:55:59 2017
@@ -128,6 +128,8 @@ Summary
 
 <h3>General</h3>
 <ul>
+    <li>When looking for classes in <code>ActionRouter</code>, fall back
to location of the jar,
+       where <code>ActionRouter</code> is loaded from. Provided by Emilian Bold
(emi at apache.org)</li>
 </ul>
 
 <ch_section>Non-functional changes</ch_section>



Mime
View raw message