Created attachment 30540 [details] Patch for BeanShellAssertionGui Problem Statement: In my daily work i used BeanShell elements extensively and i find them to be very powerful giving the edge to jmeter over the other test frameworks. However, writing Java or Python code in JTextArea is really painful and error prone (and it can hurt the eyes too). Proposal: I would like to propose to Jmeter Dev Community to include rsyntaxtextarea-2.0.7.jar library that can do syntax highlighting, code folding, undo typing, and redo typing. The library is published under BSD license and more details can be found here: http://fifesoft.com/rsyntaxtextarea/ The jar file needs to be compiled from source (It is very easy to do. Took me only 5 minutes to compile and add it to jmeter project in eclipse) Implementation change Proposal: The following is the list of files that i changed to make Syntax Highlighting work: M src/protocol/java/org/apache/jmeter/protocol/java/control/gui/BeanShellSamplerGui.java M src/components/org/apache/jmeter/assertions/gui/BeanShellAssertionGui.java ? src/core/org/apache/jmeter/testbeans/gui/textarea.properties M src/core/org/apache/jmeter/testbeans/gui/TextAreaEditor.java M src/core/org/apache/jmeter/testbeans/gui/WrapperEditor.java M src/core/org/apache/jmeter/testbeans/gui/GenericTestBeanCustomizer.java I also had to add the following in build.properties rsyntaxtextarea.version = 2.0.7 rsyntaxtextarea.jar = rsyntaxtextarea-${rsyntaxtextarea.version}.jar rsyntaxtextarea.md5 = a4bdaabc88ff5464002a43c654bbf856 the following in .classpath <classpathentry kind="lib" path="lib/rsyntaxtextarea-2.0.7.jar"/> And the following in build.xml <include name="${lib.dir}/${rsyntaxtextarea.jar}"/> </patternset> ... <pathelement location="${lib.dir}/${xstream.jar}"/> <pathelement location="${lib.dir}/${rsyntaxtextarea.jar}"/> ... Implementation Details TextAreaEditor.java and textarea.properties: Instead of JTextArea, textUI uses RSyntaxTextArea. In order to have numbers for lines i also changes the scroller to RTextScrollPane. To support different languages from BSF and JSR elements new private field languageProperties is added. This field keeps mapping between different languages and syntaxes available in SyntaxConstants interface. Mappings are defined in textarea.properties file Also the TextAreaEditor implements PropertyChangeListener so that propertyChange events can be captured. In summary: public class TextAreaEditor extends PropertyEditorSupport implements FocusListener, PropertyChangeListener { private RSyntaxTextArea textUI; private RTextScrollPane scroller; private Properties languageProperties; ... private final void init() {// called from ctor, so must not be overridable textUI = new RSyntaxTextArea(20,20); textUI.discardAllEdits(); textUI.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA); textUI.setCodeFoldingEnabled(true); textUI.setAntiAliasingEnabled(true); textUI.addFocusListener(this); textUI.setWrapStyleWord(true); textUI.setLineWrap(true); scroller = new RTextScrollPane(textUI); scroller.setFoldIndicatorEnabled(true); languageProperties = JMeterUtils.loadProperties("org/apache/jmeter/testbeans/gui/textarea.properties"); } ... @Override public void propertyChange(PropertyChangeEvent evt){ Object source = evt.getSource(); if (source instanceof ComboStringEditor && source !=null){ ComboStringEditor cse = (ComboStringEditor)source; String lang = cse.getAsText().toLowerCase(); if (languageProperties.containsKey(lang)){ textUI.setSyntaxEditingStyle(languageProperties.getProperty(lang)); } else{ textUI.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE); } } } Implementation Details BeanShellAssertionGui.java and BeanShellSamplerGui.java This is not a java bean element so direct change was applied: private RSyntaxTextArea scriptField;// script area ... private JPanel createScriptPanel() { scriptField = new RSyntaxTextArea(20,20); scriptField.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA); scriptField.setCodeFoldingEnabled(true); scriptField.setAntiAliasingEnabled(true); scriptField.setLineWrap(true); scriptField.setWrapStyleWord(true); ... JPanel panel = new JPanel(new BorderLayout()); panel.add(label, BorderLayout.NORTH); panel.add(new RTextScrollPane(scriptField), BorderLayout.CENTER); Implementation Details GenericTestBeanCustomizer.java Changes made here were necessary to enable Syntax Highlighting changes when different language is selected in ComboBox in BSF and JSR elements. GenericTestBeanCustomizer(BeanInfo beanInfo) { super(); ... // Added in the "for" loop for descriptors //Find the index of textAreaEditor if (propertyEditor instanceof TextAreaEditor) { textAreaEditorIndex = i; } //Figure out the index of scriptLanguage ComboBOx if (name.equals("scriptLanguage")){ scriptLanguageIndex=i; } ... // This is after the for loop. In case of BSF and JSR elements i want to add textAreaEditor as // a listener to scriptLanguage ComboBox. String beanName = this.beanInfo.getBeanDescriptor().getName(); if (beanName.startsWith("BSF") || beanName.startsWith("JSR223")){ WrapperEditor we = (WrapperEditor) editors[scriptLanguageIndex]; TextAreaEditor tae = (TextAreaEditor) editors[textAreaEditorIndex]; we.addChangeListener(tae); } ... Implementation Details WrapperEditor.java In the GenericTestBeanCustomizer constructor i used e.addChangeListener(tae) to add listener to comboBox. Consequently, WrapperEditor class had to be modified, thus addChangeListener method is added that will do actual listener adding on the guiEditor public void addChangeListener(PropertyChangeListener listener){ guiEditor.addPropertyChangeListener(listener); } Conclusion I found Syntax Highlighting to significantly improve look and feel of Scripting elements in Jmeter. Especially revording was to find that RSyntaxTextArea has integrated undo/redo. It is available by simply right clicking in the TextArea. Nevertheless, all the changes proposed are cosmetic and up to you to decide if it would be worth changing in Jmeter. Best Regards
Created attachment 30541 [details] Patch for BeanShellSamplerGui.java
Created attachment 30542 [details] Patch for GenericTestBeanCusomizer.java
Created attachment 30543 [details] Patch for TextAreaEditor.java
Created attachment 30544 [details] Patch for WrapperEditor.java
Created attachment 30545 [details] build.properties file that includes rsyntaxtextarea.jar
Created attachment 30546 [details] Mapping between ComboBox elements and Syntaxes
Created attachment 30547 [details] Patch for ant build file to include rsysntaxtextarea.jar
Created attachment 30548 [details] ScreenShot of Syntax Highlight in jmeter
Created attachment 30549 [details] RSyntaxTextArea.patch contains the full patch of all java files
Thanks for your contribution, seems to be a very cool improvement. Can you confirm than the file textarea.properties is under Apache License 2 or upload a new version with the AL2 Header, please. @Sebb, the component RSyntaxTextArea is distributed under a "modified BSD license." See: http://fifesoft.com/rsyntaxtextarea/RSyntaxTextArea.License.txt It's seems be compliant with the AL2, I think. The only change (compare to BSD license) is : * Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. For memory, the license compliant with AL2 (BSD is included) http://www.apache.org/legal/resolved.html#category-a == The LICENSE and NOTICE files must modify to include the mention of RSyntaxTextArea's license. (I can do this)
(In reply to Milamber from comment #10) > @Sebb, the component RSyntaxTextArea is distributed under a "modified BSD > license." > See: http://fifesoft.com/rsyntaxtextarea/RSyntaxTextArea.License.txt > It's seems be compliant with the AL2, I think. > > The only change (compare to BSD license) is : > * Neither the name of the author nor the names of its contributors may > be used to endorse or promote products derived from this software > without specific prior written permission. > > > For memory, the license compliant with AL2 (BSD is included) > http://www.apache.org/legal/resolved.html#category-a That seems OK, but IANAL. > == > The LICENSE and NOTICE files must modify to include the mention of > RSyntaxTextArea's license. (I can do this) Obviously the new license needs including in LICENSE (or as a separate file linked from it). Are you sure that the NOTICE file needs updating? It's important not to add anything to NOTICE that is not strictly required. This may need asking on the legal-discuss list.
I will add the header to the file. No problem. Do you require unit test too? Documentation updates?
Created attachment 30550 [details] Adding mapping between languages and available syntaxes
(In reply to Sebb from comment #11) > (In reply to Milamber from comment #10) > > > == > > The LICENSE and NOTICE files must modify to include the mention of > > RSyntaxTextArea's license. (I can do this) > > Obviously the new license needs including in LICENSE (or as a separate file > linked from it). > > Are you sure that the NOTICE file needs updating? I prefer, because in Mvnrepository site, the indicated license is LGPL, but perhaps it's a doc's bug. In official site, the license is clearly indicated. http://mvnrepository.com/artifact/com.fifesoft/rsyntaxtextarea/2.0.7 > It's important not to add anything to NOTICE that is not strictly required. > This may need asking on the legal-discuss list.
(In reply to Marko from comment #12) > I will add the header to the file. No problem. > Do you require unit test too? Documentation updates? Test unit doesn't seems needed because this is only an visual improvement. In the docs, some screenshots must be update, but I can do this too. Now It's time for me to test your patch :-)
(In reply to Milamber from comment #14) > (In reply to Sebb from comment #11) > > (In reply to Milamber from comment #10) > > > > > Are you sure that the NOTICE file needs updating? > > I prefer, because in Mvnrepository site, the indicated license is LGPL, but > perhaps it's a doc's bug. In official site, the license is clearly indicated. That's not sufficient reason to add anything to the NOTICE file. It looks like the code is built using Ant, not Maven, so maybe it was uploaded by a 3rd party who got the pom wrong. But clearly we cannot depend on the jar from Maven Central. > http://mvnrepository.com/artifact/com.fifesoft/rsyntaxtextarea/2.0.7 > > > It's important not to add anything to NOTICE that is not strictly required. > > This may need asking on the legal-discuss list.
Thanks. Committed in last trunk. (some changes in your patch: de-tabulation: prefer spaces for indentation, alphabetical order in jars listing, remove unused imports, formatting code) Docs screenshots to do (tomorrow) URL: http://svn.apache.org/r1500124 Log: Bug 55202 - Proposal to add RSyntaxTextArea for BeanShell, BSF, and JSR223 elements Bugzilla Id: 55202 Added: jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/textarea.properties (with props) Modified: jmeter/trunk/LICENSE jmeter/trunk/build.properties jmeter/trunk/build.xml jmeter/trunk/eclipse.classpath jmeter/trunk/res/maven/ApacheJMeter_parent.pom jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/BeanShellAssertionGui.java jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/GenericTestBeanCustomizer.java jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/TextAreaEditor.java jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/WrapperEditor.java jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/control/gui/BeanShellSamplerGui.java jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/r1500390 Log: Get rsyntaxtextarea jar file from official binary zip Bugzilla Id: 55202 Modified: jmeter/trunk/build.properties jmeter/trunk/build.xml
URL: http://svn.apache.org/r1500408 Log: Update docs with new screenshots Bugzilla Id: 55202 Added: jmeter/trunk/docs/images/screenshots/beanshell_assertion.png (with props) jmeter/trunk/xdocs/images/screenshots/beanshell_assertion.png (with props) Modified: jmeter/trunk/docs/images/screenshots/beanshell_listener.png jmeter/trunk/docs/images/screenshots/beanshell_postprocessor.png jmeter/trunk/docs/images/screenshots/beanshell_preprocessor.png jmeter/trunk/docs/images/screenshots/beanshellsampler.png jmeter/trunk/docs/images/screenshots/bsf_assertion.png jmeter/trunk/docs/images/screenshots/bsf_listener.png jmeter/trunk/docs/images/screenshots/bsf_postprocessor.png jmeter/trunk/docs/images/screenshots/bsf_preprocessor.png jmeter/trunk/docs/images/screenshots/bsfsampler.png jmeter/trunk/docs/images/screenshots/bsh_assertion.png jmeter/trunk/docs/images/screenshots/jsr223-sampler.png jmeter/trunk/docs/images/screenshots/mongodb-script.png jmeter/trunk/docs/images/screenshots/timers/beanshell_timer.png jmeter/trunk/docs/images/screenshots/timers/bsf_timer.png jmeter/trunk/xdocs/images/screenshots/beanshell_listener.png jmeter/trunk/xdocs/images/screenshots/beanshell_postprocessor.png jmeter/trunk/xdocs/images/screenshots/beanshell_preprocessor.png jmeter/trunk/xdocs/images/screenshots/beanshellsampler.png jmeter/trunk/xdocs/images/screenshots/bsf_assertion.png jmeter/trunk/xdocs/images/screenshots/bsf_listener.png jmeter/trunk/xdocs/images/screenshots/bsf_postprocessor.png jmeter/trunk/xdocs/images/screenshots/bsf_preprocessor.png jmeter/trunk/xdocs/images/screenshots/bsfsampler.png jmeter/trunk/xdocs/images/screenshots/bsh_assertion.png jmeter/trunk/xdocs/images/screenshots/jsr223-sampler.png jmeter/trunk/xdocs/images/screenshots/mongodb-script.png jmeter/trunk/xdocs/images/screenshots/timers/beanshell_timer.png jmeter/trunk/xdocs/images/screenshots/timers/bsf_timer.png jmeter/trunk/xdocs/usermanual/component_reference.xml
Seems everything is ok. I close it.
Thanks. Great feature. There is still a little one, in JDBC Sampler syntax highlight is done on Java not SQL.
URL: http://svn.apache.org/r1501306 Log: Add syntax color for scripts elements (BeanShell, BSF, and JSR223) with RSyntaxTextArea JDBC now uses SQL language format Bugzilla Id: 55202 Modified: jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/TextAreaEditor.java jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/JDBCTestElementBeanInfoSupport.java
Date: Thu Sep 26 06:44:29 2013 New Revision: 1526398 URL: http://svn.apache.org/r1526398 Log: Bug 55202 - Add syntax color for scripts elements (BeanShell, BSF, and JSR223) and JDBC elements with RSyntaxTextArea Add missing configuration properties in jmeter.properties Bugzilla Id: 55202 Modified: jmeter/trunk/bin/jmeter.properties Date: Thu Sep 26 06:46:36 2013 New Revision: 1526400 URL: http://svn.apache.org/r1526400 Log: Bug 55202 - Add syntax color for scripts elements (BeanShell, BSF, and JSR223) and JDBC elements with RSyntaxTextArea Add a way to disable undo feature in JSyntaxtTextArea, thanks Robert Futrell Bugzilla Id: 55202 Modified: jmeter/trunk/bin/jmeter.properties jmeter/trunk/src/core/org/apache/jmeter/gui/util/JSyntaxTextArea.java
Date: Thu Sep 26 19:39:31 2013 New Revision: 1526656 URL: http://svn.apache.org/r1526656 Log: Bug 55202 - Add syntax color for scripts elements (BeanShell, BSF, and JSR223) and JDBC elements with RSyntaxTextArea Fixed bad configuration Bugzilla Id: 55202 Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/util/JSyntaxTextArea.java
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/3157