@@ -38,6 +38,8 @@ | |||
| 38 | 38 | import org.scijava.module.ModuleService; | |
| 39 | 39 | import org.scijava.plugin.Parameter; | |
| 40 | 40 | import org.scijava.plugin.Plugin; | |
| 41 | + import org.scijava.script.ScriptLanguage; | ||
| 42 | + import org.scijava.script.ScriptService; | ||
| 41 | 43 | ||
| 42 | 44 | /** | |
| 43 | 45 | * A {@link ScriptProcessor} which parses the {@code #@script} directive. | |
@@ -97,7 +99,7 @@ | |||
| 97 | 99 | public class ScriptDirectiveScriptProcessor extends DirectiveScriptProcessor { | |
| 98 | 100 | ||
| 99 | 101 | public ScriptDirectiveScriptProcessor() { | |
| 100 | - super(directive -> "script".equals(directive)); | ||
| 102 | + super("script"::equals); | ||
| 101 | 103 | } | |
| 102 | 104 | ||
| 103 | 105 | @Parameter | |
@@ -106,6 +108,9 @@ public ScriptDirectiveScriptProcessor() { | |||
| 106 | 108 | @Parameter | |
| 107 | 109 | private ModuleService moduleService; | |
| 108 | 110 | ||
| 111 | + @Parameter | ||
| 112 | + private ScriptService scriptService; | ||
| 113 | + | ||
| 109 | 114 | // -- Internal DirectiveScriptProcessor methods -- | |
| 110 | 115 | ||
| 111 | 116 | @Override | |
@@ -125,6 +130,10 @@ private <T> void assignAttribute(final String k, final Object v) { | |||
| 125 | 130 | if (is(k, "name")) info().setName(as(v, String.class)); | |
| 126 | 131 | else if (is(k, "label")) info().setLabel(as(v, String.class)); | |
| 127 | 132 | else if (is(k, "description")) info().setDescription(as(v, String.class)); | |
| 133 | + else if (is(k, "language")) { | ||
| 134 | + ScriptLanguage lang = parseScriptLanguage(v.toString()); | ||
| 135 | + if (lang != null) info().setLanguage(lang); | ||
| 136 | + } | ||
| 128 | 137 | else if (is(k, "menuPath")) { | |
| 129 | 138 | info().setMenuPath(new MenuPath(as(v, String.class))); | |
| 130 | 139 | } | |
@@ -161,4 +170,12 @@ private Double priority(final Object p) { | |||
| 161 | 170 | if (lString.matches("last")) return Priority.LAST; | |
| 162 | 171 | return null; | |
| 163 | 172 | } | |
| 173 | + | ||
| 174 | + private ScriptLanguage parseScriptLanguage(final Object v) { | ||
| 175 | + final String langHint = v.toString(); | ||
| 176 | + ScriptLanguage lang = scriptService.getLanguageByName(langHint); | ||
| 177 | + if (lang == null) lang = scriptService.getLanguageByExtension(langHint); | ||
| 178 | + if (lang == null) log.warn("Unknown script language: " + langHint); | ||
| 179 | + return lang; | ||
| 180 | + } | ||
| 164 | 181 | } | |
0 commit comments