Skip to content

Commit 6c66218

Browse files
committed
Only warn about duplicate script engines
Once we have a Python script engine based on real Python (started in https://github.com/scijava/scripting-cpyton), we will want to avoid erroring out when there are *two* implementations for the same name, and instead let the implementation with the higher priority win. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 3a780f9 commit 6c66218

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/main/java/org/scijava/script/DefaultScriptService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ private HashMap<String, Class<?>> aliasMap() {
290290
private synchronized void initScriptLanguageIndex() {
291291
if (scriptLanguageIndex != null) return; // already initialized
292292

293-
final ScriptLanguageIndex index = new ScriptLanguageIndex();
293+
final ScriptLanguageIndex index = new ScriptLanguageIndex(log);
294294

295295
// add ScriptLanguage plugins
296296
for (final ScriptLanguage language : getInstances()) {

src/main/java/org/scijava/script/ScriptLanguageIndex.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
import javax.script.ScriptEngineFactory;
4141

42+
import org.scijava.log.LogService;
4243
import org.scijava.util.FileUtils;
4344

4445
/**
@@ -57,14 +58,32 @@ public class ScriptLanguageIndex extends HashSet<ScriptLanguage> {
5758
private final Map<String, ScriptLanguage> byName =
5859
new HashMap<String, ScriptLanguage>();
5960

61+
private final LogService log;
62+
63+
@Deprecated
64+
public ScriptLanguageIndex() {
65+
this(null);
66+
}
67+
68+
/**
69+
* Instantiates an index of the available script languages.
70+
*
71+
* @param logService the log service for errors and warnings
72+
*/
73+
public ScriptLanguageIndex(final LogService logService) {
74+
log = logService;
75+
}
76+
6077
public boolean add(final ScriptEngineFactory factory, final boolean gently) {
6178
final String duplicateName = checkDuplicate(factory);
6279
if (duplicateName != null) {
6380
if (gently) return false;
64-
throw new IllegalArgumentException("Duplicate scripting language '" +
65-
duplicateName + "': existing=" +
66-
byName.get(duplicateName).getClass().getName() + ", new=" +
67-
factory.getClass().getName());
81+
if (log != null) {
82+
log.warn("Duplicate scripting language '" +
83+
duplicateName + "': existing=" +
84+
byName.get(duplicateName).getClass().getName() +
85+
", new=" + factory.getClass().getName());
86+
}
6887
}
6988

7089
final ScriptLanguage language = wrap(factory);

0 commit comments

Comments
 (0)