Skip to content
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: 1 addition & 1 deletion src/main/java/org/scijava/script/DefaultScriptService.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private HashMap<String, Class<?>> aliasMap() {
private synchronized void initScriptLanguageIndex() {
if (scriptLanguageIndex != null) return; // already initialized

final ScriptLanguageIndex index = new ScriptLanguageIndex();
final ScriptLanguageIndex index = new ScriptLanguageIndex(log);

// add ScriptLanguage plugins
for (final ScriptLanguage language : getInstances()) {
Expand Down
27 changes: 23 additions & 4 deletions src/main/java/org/scijava/script/ScriptLanguageIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

import javax.script.ScriptEngineFactory;

import org.scijava.log.LogService;
import org.scijava.util.FileUtils;

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

private final LogService log;

@Deprecated
public ScriptLanguageIndex() {
this(null);
}

/**
* Instantiates an index of the available script languages.
*
* @param logService the log service for errors and warnings
*/
public ScriptLanguageIndex(final LogService logService) {
log = logService;
}

public boolean add(final ScriptEngineFactory factory, final boolean gently) {
final String duplicateName = checkDuplicate(factory);
if (duplicateName != null) {
if (gently) return false;
throw new IllegalArgumentException("Duplicate scripting language '" +
duplicateName + "': existing=" +
byName.get(duplicateName).getClass().getName() + ", new=" +
factory.getClass().getName());
if (log != null) {
log.warn("Duplicate scripting language '" +
duplicateName + "': existing=" +
byName.get(duplicateName).getClass().getName() +
", new=" + factory.getClass().getName());
}
}

final ScriptLanguage language = wrap(factory);
Expand Down