Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load ScriptEngine plugins based on Nashorn.class #3

Merged
merged 2 commits into from
Feb 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# JScriptBox releases

## [Unreleased]
### Fixed
- Nashorn script engine is now searched for using the Nashorn classloader rather than the current thread context classloader ([#3](https://github.com/diffplug/jscriptbox/pull/3) to help fix [spotless#803](https://github.com/diffplug/spotless/issues/803)).

## [3.0.0] - 2015-09-21
- First stable release.
10 changes: 4 additions & 6 deletions src/main/java/com/diffplug/jscriptbox/javascript/Nashorn.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2015 DiffPlug
* Copyright (C) 2015-2023 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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
* https://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,
Expand All @@ -15,16 +15,14 @@
*/
package com.diffplug.jscriptbox.javascript;

import com.diffplug.jscriptbox.Language;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

import com.diffplug.jscriptbox.Language;

public class Nashorn {
/**
* Language implementation for javascript using the nashorn engine.
Expand All @@ -39,7 +37,7 @@ public static Language language() {
/** Language implementation for javascript using the given policy for resolving any potential conflicts with reserved keywords. */
public static Language language(OnReservedKeyword policy) {
return map -> {
ScriptEngine jsEngine = new ScriptEngineManager().getEngineByName("nashorn");
ScriptEngine jsEngine = new ScriptEngineManager(Nashorn.class.getClassLoader()).getEngineByName("nashorn");
ScriptContext context = jsEngine.getContext();

String mapName = "nashornScriptBoxMap";
Expand Down