View | Details | Raw Unified | Return to bug 62700
Collapse All | Expand All

(-)a/bin/jmeter.properties (-3 / +7 lines)
Lines 916-930 beanshell.server.file=../extras/startup.bsh Link Here
916
# of Test and Thread Listeners.
916
# of Test and Thread Listeners.
917
917
918
#---------------------------------------------------------------------------
918
#---------------------------------------------------------------------------
919
# Groovy function
919
# JSR-223 function
920
#---------------------------------------------------------------------------
920
#---------------------------------------------------------------------------
921
921
922
# Path to Groovy file containing script to call on JMeter startup
922
# Path to JSR-223 file containing script to call on JMeter startup
923
# This script can use pre-defined variables:
923
# This script can use pre-defined variables:
924
# log : Logger to log any message
924
# log : Logger to log any message
925
# props : JMeter Property
925
# props : JMeter Property
926
# OUT : System.OUT
926
# OUT : System.OUT
927
#groovy.init.file=
927
#jsr223.init.file=
928
929
#---------------------------------------------------------------------------
930
# Groovy function
931
#---------------------------------------------------------------------------
928
932
929
#Path to Groovy file containing utility functions to make available to __groovy function
933
#Path to Groovy file containing utility functions to make available to __groovy function
930
#groovy.utilities=
934
#groovy.utilities=
(-)a/src/core/org/apache/jmeter/JMeter.java (-8 / +14 lines)
Lines 57-62 import org.apache.commons.cli.avalon.CLArgsParser; Link Here
57
import org.apache.commons.cli.avalon.CLOption;
57
import org.apache.commons.cli.avalon.CLOption;
58
import org.apache.commons.cli.avalon.CLOptionDescriptor;
58
import org.apache.commons.cli.avalon.CLOptionDescriptor;
59
import org.apache.commons.cli.avalon.CLUtil;
59
import org.apache.commons.cli.avalon.CLUtil;
60
import org.apache.commons.io.FilenameUtils;
60
import org.apache.commons.io.IOUtils;
61
import org.apache.commons.io.IOUtils;
61
import org.apache.jmeter.control.ReplaceableController;
62
import org.apache.jmeter.control.ReplaceableController;
62
import org.apache.jmeter.engine.ClientJMeterEngine;
63
import org.apache.jmeter.engine.ClientJMeterEngine;
Lines 673-690 public class JMeter implements JMeterPlugin { Link Here
673
                }
674
                }
674
            }
675
            }
675
        }
676
        }
676
        
677
677
        // Should we run a Groovy script on startup?
678
        // Should we run a JSR-223 script on startup?
678
        String jsr223Init = JMeterUtils.getProperty("groovy.init.file");// $NON-NLS-1$
679
        String jsr223Init = JMeterUtils.getProperty("jsr223.init.file");// $NON-NLS-1$
679
        if (jsr223Init != null){
680
        if (jsr223Init != null){
680
            log.info("Running Groovy init script in file: {}", jsr223Init);
681
            log.info("Running JSR-223 init script in file: {}", jsr223Init);
681
            File file = new File(jsr223Init);
682
            File file = new File(jsr223Init);
682
            if(file.exists() && file.canRead()) {
683
            if(file.exists() && file.canRead()) {
684
                String extension = FilenameUtils.getExtension(jsr223Init);
683
                try (FileReader reader = new FileReader(file)) {
685
                try (FileReader reader = new FileReader(file)) {
684
                    ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
686
                    ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
685
                    ScriptEngine engine = scriptEngineManager.getEngineByName("Groovy");
687
                    ScriptEngine engine = scriptEngineManager.getEngineByName(extension);
686
                    Bindings bindings = engine.createBindings();
688
                    Bindings bindings = engine.createBindings();
687
                    final Logger logger = LoggerFactory.getLogger("groovy.init.file");
689
                    final Logger logger = LoggerFactory.getLogger("jsr223.init.file");
688
                    bindings.put("log", logger); // $NON-NLS-1$ (this name is fixed)
690
                    bindings.put("log", logger); // $NON-NLS-1$ (this name is fixed)
689
                    Properties props = JMeterUtils.getJMeterProperties();
691
                    Properties props = JMeterUtils.getJMeterProperties();
690
                    bindings.put("props", props); // $NON-NLS-1$ (this name is fixed)
692
                    bindings.put("props", props); // $NON-NLS-1$ (this name is fixed)
Lines 692-701 public class JMeter implements JMeterPlugin { Link Here
692
                    bindings.put("OUT", System.out); // NOSONAR $NON-NLS-1$ (this name is fixed)
694
                    bindings.put("OUT", System.out); // NOSONAR $NON-NLS-1$ (this name is fixed)
693
                    engine.eval(reader, bindings);
695
                    engine.eval(reader, bindings);
694
                } catch (IOException | ScriptException ex) {
696
                } catch (IOException | ScriptException ex) {
695
                    log.error("Error running init script referenced by property {}", jsr223Init, ex);
697
                    log.error(
698
                            "Error running init script referenced by property {} with engine for {}",
699
                            jsr223Init, extension, ex);
696
                }
700
                }
697
            } else {
701
            } else {
698
                log.error("Script {} referenced by property {} is not readable or does not exists", file.getAbsolutePath(), jsr223Init);
702
                log.error(
703
                        "Script {} referenced by property {} is not readable or does not exists",
704
                        file.getAbsolutePath(), jsr223Init);
699
            }
705
            }
700
        }
706
        }
701
    }
707
    }
(-)a/xdocs/changes.xml (-1 / +1 lines)
Lines 160-166 this behaviour, set <code>httpclient.reset_state_on_thread_group_iteration=false Link Here
160
  <li><bug>62470</bug>CSV Output : Enable logging of sub results when <code>jmeter.save.saveservice.subresults=true</code>. Contributed by Ubik Load Pack (support at ubikloadpack.com)</li>
160
  <li><bug>62470</bug>CSV Output : Enable logging of sub results when <code>jmeter.save.saveservice.subresults=true</code>. Contributed by Ubik Load Pack (support at ubikloadpack.com)</li>
161
  <li><bug>62473</bug>Setting "<code>saveservice_properties</code>" has counter intuitive behaviour</li>
161
  <li><bug>62473</bug>Setting "<code>saveservice_properties</code>" has counter intuitive behaviour</li>
162
  <li><bug>62354</bug>Correct calculation and usage of units for second per user (reported by jffagot05 at gmail.com)</li>
162
  <li><bug>62354</bug>Correct calculation and usage of units for second per user (reported by jffagot05 at gmail.com)</li>
163
  <li><bug>62700</bug>Introduce groovy.init.file to allow calling a groovy script on JMeter startup</li>
163
  <li><bug>62700</bug>Introduce <code>jsr223.init.file</code> to allow calling a JSR-223 script on JMeter startup</li>
164
  <li><bug>62128</bug>Try to guess <code>JMETER_HOME</code> correctly, when <code>jmeter.bat</code> is called from a batch file in another directory. Contributed by logox01 (logox01 at gmx.at)</li>
164
  <li><bug>62128</bug>Try to guess <code>JMETER_HOME</code> correctly, when <code>jmeter.bat</code> is called from a batch file in another directory. Contributed by logox01 (logox01 at gmx.at)</li>
165
  <li><pr>386</pr>Add parameter support for RMI keystore creation scripts. Contributed by Logan Mauzaize (t524467 at airfrance.fr)</li>
165
  <li><pr>386</pr>Add parameter support for RMI keystore creation scripts. Contributed by Logan Mauzaize (t524467 at airfrance.fr)</li>
166
  <li><bug>62065</bug>Use Maven artifact for JAF Module instead of embedded module</li>
166
  <li><bug>62065</bug>Use Maven artifact for JAF Module instead of embedded module</li>
(-)a/xdocs/usermanual/properties_reference.xml (-12 / +18 lines)
Lines 1496-1506 JMETER-SERVER</source> Link Here
1496
    confirmation dialogue.<br/>
1496
    confirmation dialogue.<br/>
1497
    Defaults to: <code>false</code>
1497
    Defaults to: <code>false</code>
1498
</property>
1498
</property>
1499
<property name="jsr223.compiled_scripts_cache_size">
1500
    Used by JSR223 elements.<br/>
1501
    Size of compiled scripts cache.<br/>
1502
    Defaults to: <code>100</code></property>
1503
</properties>
1504
</section>
1499
</section>
1505
<section name="&sect-num;.36 Classpath configuration" anchor="classpath">
1500
<section name="&sect-num;.36 Classpath configuration" anchor="classpath">
1506
<properties>
1501
<properties>
Lines 1875-1895 JMETER-SERVER</source> Link Here
1875
</section>
1870
</section>
1876
1871
1877
<section name="&sect-num;.43 Advanced Groovy Scripting configuration" anchor="groovy">
1872
<section name="&sect-num;.43 Advanced Groovy Scripting configuration" anchor="groovy">
1878
<description>Advanced properties for configuration of scripting in Grooyv</description>
1873
<description>Advanced properties for configuration of scripting in Groovy</description>
1879
<properties>
1874
<properties>
1880
    <property name="groovy.init.file">
1875
    <property name="groovy.utilities">
1881
    Path to Groovy file containing script to call on JMeter startup. <br/>
1876
    Path to Groovy file containing utility functions to make available to <funclink name="__groovy"/> function.<br/>
1877
    Defaults to <code>bin/utility.groovy</code>
1878
    </property>
1879
</properties>
1880
</section>
1881
1882
<section name="&sect-num;.43 Advanced JSR-223 Scripting configuration" anchor="jsr223">
1883
<description>Advanced properties for configuration of scripting in JSR-223</description>
1884
<properties>
1885
    <property name="jsr223.init.file">
1886
    Path to JSR-223 file containing script to call on JMeter startup.<br/>
1882
    This script can use pre-defined variables:
1887
    This script can use pre-defined variables:
1883
    <ul>
1888
    <ul>
1884
        <li><code>log</code>: Logger to log any message, uses SLF4J library</li>
1889
        <li><code>log</code>: Logger to log any message, uses SLF4J library</li>
1885
        <li><code>props</code>: JMeter Properties</li>
1890
        <li><code>props</code>: JMeter Properties</li>
1886
        <li><code>OUT</code>: System.OUT, useful to write in the console</li>
1891
        <li><code>OUT</code>: System.OUT, useful to write in the console</li>
1887
    </ul>
1892
    </ul>
1888
    No script is defined by default. 
1893
    No script is defined by default.
1889
    </property>
1894
    </property>
1890
    <property name="groovy.utilities">
1895
    <property name="jsr223.compiled_scripts_cache_size">
1891
    Path to Groovy file containing utility functions to make available to __groovy function. <br/>
1896
    Used by JSR223 elements.<br/>
1892
    Defaults to <code>bin/utility.groovy</code> 
1897
    Size of compiled scripts cache.<br/>
1898
    Defaults to: <code>100</code>
1893
    </property>
1899
    </property>
1894
</properties>
1900
</properties>
1895
</section>
1901
</section>

Return to bug 62700