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 / +19 lines)
Lines 57-63 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;
62
import org.apache.commons.lang3.StringUtils;
61
import org.apache.jmeter.control.ReplaceableController;
63
import org.apache.jmeter.control.ReplaceableController;
62
import org.apache.jmeter.engine.ClientJMeterEngine;
64
import org.apache.jmeter.engine.ClientJMeterEngine;
63
import org.apache.jmeter.engine.DistributedRunner;
65
import org.apache.jmeter.engine.DistributedRunner;
Lines 673-690 public class JMeter implements JMeterPlugin { Link Here
673
                }
675
                }
674
            }
676
            }
675
        }
677
        }
676
        
678
677
        // Should we run a Groovy script on startup?
679
        // Should we run a JSR-223 script on startup?
678
        String jsr223Init = JMeterUtils.getProperty("groovy.init.file");// $NON-NLS-1$
680
        String jsr223Init = JMeterUtils.getProperty("jsr223.init.file");// $NON-NLS-1$
679
        if (jsr223Init != null){
681
        if (jsr223Init != null){
680
            log.info("Running Groovy init script in file: {}", jsr223Init);
682
            log.info("Running JSR-223 init script in file: {}", jsr223Init);
681
            File file = new File(jsr223Init);
683
            File file = new File(jsr223Init);
682
            if(file.exists() && file.canRead()) {
684
            if(file.exists() && file.canRead()) {
685
                String extension = FilenameUtils.getExtension(jsr223Init);
683
                try (FileReader reader = new FileReader(file)) {
686
                try (FileReader reader = new FileReader(file)) {
684
                    ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
687
                    ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
685
                    ScriptEngine engine = scriptEngineManager.getEngineByName("Groovy");
688
                    ScriptEngine engine = scriptEngineManager.getEngineByName(
689
                            StringUtils.defaultString(extension, "groovy"));
690
                    if (engine == null) {
691
                        engine = scriptEngineManager.getEngineByName("groovy");
692
                    }
686
                    Bindings bindings = engine.createBindings();
693
                    Bindings bindings = engine.createBindings();
687
                    final Logger logger = LoggerFactory.getLogger("groovy.init.file");
694
                    final Logger logger = LoggerFactory.getLogger("jsr223.init.file");
688
                    bindings.put("log", logger); // $NON-NLS-1$ (this name is fixed)
695
                    bindings.put("log", logger); // $NON-NLS-1$ (this name is fixed)
689
                    Properties props = JMeterUtils.getJMeterProperties();
696
                    Properties props = JMeterUtils.getJMeterProperties();
690
                    bindings.put("props", props); // $NON-NLS-1$ (this name is fixed)
697
                    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)
699
                    bindings.put("OUT", System.out); // NOSONAR $NON-NLS-1$ (this name is fixed)
693
                    engine.eval(reader, bindings);
700
                    engine.eval(reader, bindings);
694
                } catch (IOException | ScriptException ex) {
701
                } catch (IOException | ScriptException ex) {
695
                    log.error("Error running init script referenced by property {}", jsr223Init, ex);
702
                    log.error(
703
                            "Error running init script referenced by property {} with engine for {}",
704
                            jsr223Init, extension, ex);
696
                }
705
                }
697
            } else {
706
            } else {
698
                log.error("Script {} referenced by property {} is not readable or does not exists", file.getAbsolutePath(), jsr223Init);
707
                log.error(
708
                        "Script {} referenced by property {} is not readable or does not exists",
709
                        file.getAbsolutePath(), jsr223Init);
699
            }
710
            }
700
        }
711
        }
701
    }
712
    }
(-)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 / +22 lines)
Lines 1496-1505 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>
1499
</properties>
1504
</section>
1500
</section>
1505
<section name="&sect-num;.36 Classpath configuration" anchor="classpath">
1501
<section name="&sect-num;.36 Classpath configuration" anchor="classpath">
Lines 1875-1895 JMETER-SERVER</source> Link Here
1875
</section>
1871
</section>
1876
1872
1877
<section name="&sect-num;.43 Advanced Groovy Scripting configuration" anchor="groovy">
1873
<section name="&sect-num;.43 Advanced Groovy Scripting configuration" anchor="groovy">
1878
<description>Advanced properties for configuration of scripting in Grooyv</description>
1874
<description>Advanced properties for configuration of scripting in Groovy</description>
1875
<properties>
1876
    <property name="groovy.utilities">
1877
    Path to Groovy file containing utility functions to make available to <funclink name="__groovy"/> function.<br/>
1878
    Defaults to <code>bin/utility.groovy</code>
1879
    </property>
1880
</properties>
1881
</section>
1882
1883
<section name="&sect-num;.43 Advanced JSR-223 Scripting configuration" anchor="jsr223">
1884
<description>Advanced properties for configuration of scripting in JSR-223</description>
1879
<properties>
1885
<properties>
1880
    <property name="groovy.init.file">
1886
    <property name="jsr223.init.file">
1881
    Path to Groovy file containing script to call on JMeter startup. <br/>
1887
    <p>Path to JSR-223 file containing script to call on JMeter startup.</p>
1882
    This script can use pre-defined variables:
1888
    <p>The actual scripting engine to use will be determined by the extension
1889
    of the init file name. If the file name has no extension, or no scripting
1890
    engine could be found for that extension, Groovy will be used.</p>
1891
    <p>This script can use pre-defined variables:</p>
1883
    <ul>
1892
    <ul>
1884
        <li><code>log</code>: Logger to log any message, uses SLF4J library</li>
1893
        <li><code>log</code>: Logger to log any message, uses SLF4J library</li>
1885
        <li><code>props</code>: JMeter Properties</li>
1894
        <li><code>props</code>: JMeter Properties</li>
1886
        <li><code>OUT</code>: System.OUT, useful to write in the console</li>
1895
        <li><code>OUT</code>: System.OUT, useful to write in the console</li>
1887
    </ul>
1896
    </ul>
1888
    No script is defined by default. 
1897
    No script is defined by default.
1889
    </property>
1898
    </property>
1890
    <property name="groovy.utilities">
1899
    <property name="jsr223.compiled_scripts_cache_size">
1891
    Path to Groovy file containing utility functions to make available to __groovy function. <br/>
1900
    Used by JSR223 elements.<br/>
1892
    Defaults to <code>bin/utility.groovy</code> 
1901
    Size of compiled scripts cache.<br/>
1902
    Defaults to: <code>100</code>
1893
    </property>
1903
    </property>
1894
</properties>
1904
</properties>
1895
</section>
1905
</section>

Return to bug 62700