Java Code Examples for groovy.lang.GroovyShell#DEFAULT_CODE_BASE

The following examples show how to use groovy.lang.GroovyShell#DEFAULT_CODE_BASE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BenchmarkGroovyExpressionEvaluation.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
@Setup
public void setup()
    throws IllegalAccessException, InstantiationException {
  _concatScriptText = "firstName + ' ' + lastName";
  _concatBinding = new Binding();
  _concatScript = new GroovyShell(_concatBinding).parse(_concatScriptText);
  _concatCodeSource = new GroovyCodeSource(_concatScriptText, Math.abs(_concatScriptText.hashCode()) + ".groovy",
      GroovyShell.DEFAULT_CODE_BASE);
  _concatGCLScript = (Script) _groovyClassLoader.parseClass(_concatCodeSource).newInstance();

  _maxScriptText = "longList.max{ it.toBigDecimal() }";
  _maxBinding = new Binding();
  _maxScript = new GroovyShell(_maxBinding).parse(_maxScriptText);
  _maxCodeSource = new GroovyCodeSource(_maxScriptText, Math.abs(_maxScriptText.hashCode()) + ".groovy",
      GroovyShell.DEFAULT_CODE_BASE);
  _maxGCLScript = (Script) _groovyClassLoader.parseClass(_maxCodeSource).newInstance();
}
 
Example 2
Source File: GroovyScripts.java    From powsybl-core with Mozilla Public License 2.0 5 votes vote down vote up
public static GroovyCodeSource load(Path path) {
    Objects.requireNonNull(path);
    try (Reader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
        return new GroovyCodeSource(reader, "script", GroovyShell.DEFAULT_CODE_BASE);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example 3
Source File: AbstractDslContingenciesProvider.java    From powsybl-core with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Creates a provider by reading the DSL from a UTF-8 encoded file.
 */
protected AbstractDslContingenciesProvider(final Path path) {
    Objects.requireNonNull(path);
    try (Reader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
        script = new GroovyCodeSource(reader, "script", GroovyShell.DEFAULT_CODE_BASE);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example 4
Source File: AbstractLoadFlowRulesEngineTest.java    From powsybl-core with Mozilla Public License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    network = createNetwork();
    LoadFlowActionSimulatorObserver observer = createObserver();
    GroovyCodeSource src = new GroovyCodeSource(new InputStreamReader(getClass().getResourceAsStream(getDslFile())), "test", GroovyShell.DEFAULT_CODE_BASE);
    actionDb = new ActionDslLoader(src).load(network);
    engine = new LoadFlowActionSimulator(network, computationManager, new LoadFlowActionSimulatorConfig("LoadFlowMock", 3, false, false),
            applyIfWorks(), new LoadFlowParameters(), observer);
}
 
Example 5
Source File: GroovyMain.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * Get a new GroovyCodeSource for a script which may be given as a location
 * (isScript is true) or as text (isScript is false).
 *
 * @param isScriptFile indicates whether the script parameter is a location or content
 * @param script       the location or context of the script
 * @return a new GroovyCodeSource for the given script
 * @throws IOException
 * @throws URISyntaxException
 * @since 2.3.0
 */
protected GroovyCodeSource getScriptSource(boolean isScriptFile, String script) throws IOException, URISyntaxException {
    //check the script is currently valid before starting a server against the script
    if (isScriptFile) {
        // search for the file and if it exists don't try to use URIs ...
        File scriptFile = huntForTheScriptFile(script);
        if (!scriptFile.exists() && URI_PATTERN.matcher(script).matches()) {
            return new GroovyCodeSource(new URI(script));
        }
        return new GroovyCodeSource(scriptFile);
    }
    return new GroovyCodeSource(script, "script_from_command_line", GroovyShell.DEFAULT_CODE_BASE);
}
 
Example 6
Source File: GroovyScripts.java    From powsybl-core with Mozilla Public License 2.0 4 votes vote down vote up
public static GroovyCodeSource load(InputStream inputStream) {
    Objects.requireNonNull(inputStream);
    return new GroovyCodeSource(new InputStreamReader(inputStream, StandardCharsets.UTF_8), "script", GroovyShell.DEFAULT_CODE_BASE);
}
 
Example 7
Source File: AbstractDslContingenciesProvider.java    From powsybl-core with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Creates a provider by reading the DSL content from a UTF-8 encoded input stream.
 */
protected AbstractDslContingenciesProvider(final InputStream input) {
    Objects.requireNonNull(input);
    script = new GroovyCodeSource(new InputStreamReader(input, StandardCharsets.UTF_8), "script", GroovyShell.DEFAULT_CODE_BASE);
}
 
Example 8
Source File: InvalidGroovyTest.java    From powsybl-core with Mozilla Public License 2.0 4 votes vote down vote up
private GroovyCodeSource getDslFile(String path) {
    return new GroovyCodeSource(new InputStreamReader(getClass().getResourceAsStream(path)), "test", GroovyShell.DEFAULT_CODE_BASE);
}