Bug 55202 - Add syntax color for scripts elements (BeanShell, BSF, and JSR223) and JDBC elements with RSyntaxTextArea
Add syntax color for scripts elements (BeanShell, BSF, and JSR223) and JDBC e...
Status: RESOLVED FIXED
Product: JMeter
Classification: Unclassified
Component: Main
2.9
All All
: P2 enhancement (vote)
: ---
Assigned To: JMeter issues mailing list
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2013-07-05 17:54 UTC by Marko
Modified: 2013-09-26 19:42 UTC (History)
1 user (show)



Attachments
Patch for BeanShellAssertionGui (1.85 KB, patch)
2013-07-05 17:54 UTC, Marko
Details | Diff
Patch for BeanShellSamplerGui.java (1.83 KB, patch)
2013-07-05 17:56 UTC, Marko
Details | Diff
Patch for GenericTestBeanCusomizer.java (3.51 KB, patch)
2013-07-05 17:58 UTC, Marko
Details | Diff
Patch for TextAreaEditor.java (2.92 KB, patch)
2013-07-05 17:58 UTC, Marko
Details | Diff
Patch for WrapperEditor.java (551 bytes, patch)
2013-07-05 17:59 UTC, Marko
Details | Diff
build.properties file that includes rsyntaxtextarea.jar (15.90 KB, text/plain)
2013-07-05 18:00 UTC, Marko
Details
Mapping between ComboBox elements and Syntaxes (710 bytes, text/plain)
2013-07-05 18:02 UTC, Marko
Details
Patch for ant build file to include rsysntaxtextarea.jar (758 bytes, patch)
2013-07-05 18:04 UTC, Marko
Details | Diff
ScreenShot of Syntax Highlight in jmeter (169.07 KB, image/png)
2013-07-05 18:07 UTC, Marko
Details
RSyntaxTextArea.patch contains the full patch of all java files (10.61 KB, patch)
2013-07-05 19:10 UTC, Marko
Details | Diff
Adding mapping between languages and available syntaxes (1.46 KB, text/plain)
2013-07-05 19:35 UTC, Marko
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marko 2013-07-05 17:54:31 UTC
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
Comment 1 Marko 2013-07-05 17:56:44 UTC
Created attachment 30541 [details]
Patch for BeanShellSamplerGui.java
Comment 2 Marko 2013-07-05 17:58:12 UTC
Created attachment 30542 [details]
Patch for GenericTestBeanCusomizer.java
Comment 3 Marko 2013-07-05 17:58:49 UTC
Created attachment 30543 [details]
Patch for TextAreaEditor.java
Comment 4 Marko 2013-07-05 17:59:31 UTC
Created attachment 30544 [details]
Patch for WrapperEditor.java
Comment 5 Marko 2013-07-05 18:00:31 UTC
Created attachment 30545 [details]
build.properties file that includes rsyntaxtextarea.jar
Comment 6 Marko 2013-07-05 18:02:16 UTC
Created attachment 30546 [details]
Mapping between ComboBox elements and Syntaxes
Comment 7 Marko 2013-07-05 18:04:15 UTC
Created attachment 30547 [details]
Patch for ant build file to include rsysntaxtextarea.jar
Comment 8 Marko 2013-07-05 18:07:17 UTC
Created attachment 30548 [details]
ScreenShot of Syntax Highlight in jmeter
Comment 9 Marko 2013-07-05 19:10:56 UTC
Created attachment 30549 [details]
RSyntaxTextArea.patch contains the full patch of all java files
Comment 10 Milamber 2013-07-05 19:13:57 UTC
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)
Comment 11 Sebb 2013-07-05 19:25:53 UTC
(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.
Comment 12 Marko 2013-07-05 19:27:13 UTC
I will add the header to the file. No problem.
Do you require unit test too? Documentation updates?
Comment 13 Marko 2013-07-05 19:35:04 UTC
Created attachment 30550 [details]
Adding mapping between languages and available syntaxes
Comment 14 Milamber 2013-07-05 19:35:50 UTC
(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.
Comment 15 Milamber 2013-07-05 19:39:49 UTC
(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 :-)
Comment 16 Sebb 2013-07-05 19:56:03 UTC
(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.
Comment 17 Milamber 2013-07-05 20:48:47 UTC

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
Comment 18 Milamber 2013-07-07 09:19:30 UTC
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
Comment 19 Milamber 2013-07-07 11:32:54 UTC
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
Comment 20 Milamber 2013-07-07 11:36:50 UTC
Seems everything is ok. I close it.
Comment 21 Philippe Mouawad 2013-07-07 13:21:42 UTC
Thanks. Great feature.
There is still a little one, in JDBC Sampler syntax highlight is done on Java not SQL.
Comment 22 Sebb 2013-07-09 14:51:23 UTC
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
Comment 23 Philippe Mouawad 2013-09-26 06:47:19 UTC
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
Comment 24 Philippe Mouawad 2013-09-26 19:42:46 UTC
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