• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

TAKETODAY / today-infrastructure / 18154768944

01 Oct 2025 07:26AM UTC coverage: 81.882% (-0.005%) from 81.887%
18154768944

push

github

web-flow
Merge pull request #290 from TAKETODAY/dev/jspecify

jspecify

59788 of 78013 branches covered (76.64%)

Branch coverage included in aggregate %.

141239 of 167496 relevant lines covered (84.32%)

3.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.87
today-context/src/main/java/infra/scripting/bsh/BshScriptEvaluator.java
1
/*
2
 * Copyright 2017 - 2025 the original author or authors.
3
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see [https://www.gnu.org/licenses/]
16
 */
17

18
package infra.scripting.bsh;
19

20
import org.jspecify.annotations.Nullable;
21

22
import java.io.IOException;
23
import java.io.StringReader;
24
import java.util.Map;
25

26
import bsh.EvalError;
27
import bsh.Interpreter;
28
import infra.beans.factory.BeanClassLoaderAware;
29
import infra.scripting.ScriptCompilationException;
30
import infra.scripting.ScriptEvaluator;
31
import infra.scripting.ScriptSource;
32

33
/**
34
 * BeanShell-based implementation of Framework's {@link ScriptEvaluator} strategy interface.
35
 *
36
 * @author Juergen Hoeller
37
 * @author <a href="https://github.com/TAKETODAY">海子 Yang</a>
38
 * @see Interpreter#eval(String)
39
 * @since 4.0
40
 */
41
public class BshScriptEvaluator implements ScriptEvaluator, BeanClassLoaderAware {
42

43
  @Nullable
44
  private ClassLoader classLoader;
45

46
  /**
47
   * Construct a new BshScriptEvaluator.
48
   */
49
  public BshScriptEvaluator() {
2✔
50

51
  }
1✔
52

53
  /**
54
   * Construct a new BshScriptEvaluator.
55
   *
56
   * @param classLoader the ClassLoader to use for the {@link Interpreter}
57
   */
58
  public BshScriptEvaluator(ClassLoader classLoader) {
×
59
    this.classLoader = classLoader;
×
60
  }
×
61

62
  @Override
63
  public void setBeanClassLoader(ClassLoader classLoader) {
64
    this.classLoader = classLoader;
×
65
  }
×
66

67
  @Override
68
  @Nullable
69
  public Object evaluate(ScriptSource script) {
70
    return evaluate(script, null);
5✔
71
  }
72

73
  @Override
74
  @Nullable
75
  public Object evaluate(ScriptSource script, @Nullable Map<String, Object> arguments) {
76
    try {
77
      Interpreter interpreter = new Interpreter();
4✔
78
      interpreter.setClassLoader(this.classLoader);
4✔
79
      if (arguments != null) {
2✔
80
        for (Map.Entry<String, Object> entry : arguments.entrySet()) {
11✔
81
          interpreter.set(entry.getKey(), entry.getValue());
7✔
82
        }
1✔
83
      }
84
      return interpreter.eval(new StringReader(script.getScriptAsString()));
8✔
85
    }
86
    catch (IOException ex) {
×
87
      throw new ScriptCompilationException(script, "Cannot access BeanShell script", ex);
×
88
    }
89
    catch (EvalError ex) {
×
90
      throw new ScriptCompilationException(script, ex);
×
91
    }
92
  }
93

94
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc