Skip to content

Commit

Permalink
chore(engine,parent): Bump GraalVM to 21.3.12
Browse files Browse the repository at this point in the history
Notes

- Bumps icu:icu4j to version 71.1

Introduces:

CustomScriptEngineManager - Class that allows to parameterise behaviour needed for a given JS engine: a) After the engines are detected from the classpath b) Before the engines are created

GraalVM Warnings

The commit sets the System property to disable the respective warnings introduced by bumping GraalVM to version 21.3.10.

- The system property is always set when a GraalJS script engine is found on the classpath
- The above applies by default to all distros

Related-to: #4299
  • Loading branch information
psavidis authored Dec 10, 2024
1 parent 52c33ee commit 14a704b
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import javax.naming.InitialContext;
import javax.script.ScriptEngineManager;
import javax.sql.DataSource;
import org.apache.ibatis.builder.xml.XMLConfigBuilder;
import org.apache.ibatis.datasource.pooled.PooledDataSource;
Expand Down Expand Up @@ -339,6 +338,7 @@
import org.camunda.bpm.engine.impl.runtime.DefaultDeserializationTypeValidator;
import org.camunda.bpm.engine.impl.scripting.ScriptFactory;
import org.camunda.bpm.engine.impl.scripting.engine.BeansResolverFactory;
import org.camunda.bpm.engine.impl.scripting.engine.CamundaScriptEngineManager;
import org.camunda.bpm.engine.impl.scripting.engine.DefaultScriptEngineResolver;
import org.camunda.bpm.engine.impl.scripting.engine.ResolverFactory;
import org.camunda.bpm.engine.impl.scripting.engine.ScriptBindingsFactory;
Expand Down Expand Up @@ -2642,7 +2642,7 @@ protected void initScripting() {
resolverFactories.add(new BeansResolverFactory());
}
if (scriptEngineResolver == null) {
scriptEngineResolver = new DefaultScriptEngineResolver(new ScriptEngineManager());
scriptEngineResolver = new DefaultScriptEngineResolver(new CamundaScriptEngineManager());
}
if (scriptingEngines == null) {
scriptingEngines = new ScriptingEngines(new ScriptBindingsFactory(resolverFactories), scriptEngineResolver);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.camunda.bpm.engine.impl.scripting.engine;

import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static org.camunda.bpm.engine.impl.scripting.engine.ScriptingEngines.GRAAL_JS_SCRIPT_ENGINE_NAME;

/**
* Custom Script Engine Manager that can execute custom logic:
* <p>
* a) after the discovery of the engines on the classpath; the respective engine factories are created
* b) before the engines are created.
*
* If custom logic is needed for a specific engine after the classpath detection, before the engine creation,
* it can be added to the classes map.
*/
public class CamundaScriptEngineManager extends ScriptEngineManager {

protected final Map<String, Runnable> engineNameToInitLogicMappings = Map.of(
GRAAL_JS_SCRIPT_ENGINE_NAME, this::disableGraalVMInterpreterOnlyModeWarnings
);

public CamundaScriptEngineManager() {
super(); // creates engine factories after classpath discovery
applyConfigOnEnginesAfterClasspathDiscovery();
}

protected void applyConfigOnEnginesAfterClasspathDiscovery() {
var engineNames = getEngineNamesFoundInClasspath();

for (var engineName : engineNames) {
executeConfigurationBeforeEngineCreation(engineName);
}
}

protected List<String> getEngineNamesFoundInClasspath() {
var engineFactories = getEngineFactories();

return engineFactories.stream()
.map(ScriptEngineFactory::getEngineName)
.collect(Collectors.toList());

}

/**
* Fetches the config logic of a given engine from the mappings and executes it in case it exists.
*
* @param engineName the given engine name
*/
protected void executeConfigurationBeforeEngineCreation(String engineName) {
var config = engineNameToInitLogicMappings.get(engineName);
if (config != null) {
config.run();
}
}

protected void disableGraalVMInterpreterOnlyModeWarnings() {
System.setProperty("polyglot.engine.WarnInterpreterOnly", "false");
}

}
4 changes: 2 additions & 2 deletions parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
<!-- use minimum version of resteasy and jersey -->
<version.jaxrs.api>2.0.1.Final</version.jaxrs.api>
<version.groovy>4.0.22</version.groovy>
<version.graal.js>21.1.0</version.graal.js>
<version.icu.icu4j>68.2</version.icu.icu4j>
<version.graal.js>21.3.12</version.graal.js>
<version.icu.icu4j>71.1</version.icu.icu4j>
<!-- json-smart and accessors-smart are runtime dependencies of json-path -->
<version.json-path>2.9.0</version.json-path>
<version.json-smart>2.5.0</version.json-smart>
Expand Down

0 comments on commit 14a704b

Please sign in to comment.