Extension
com.jsmacrosce.jsmacros.core.extensions.Extension
Provides an extension's identity, dependencies, initialization hook, and optional translations.
Extensions are discovered by the loader as service providers. Scripts can enumerate loaded extensions through context.getCtx().runner.extensions.getAllExtensions():
js
const extensions = context.getCtx().runner.extensions.getAllExtensions().iterator();
while (extensions.hasNext()) {
Chat.log(extensions.next().getExtensionName());
}Methods
getDependencies
Reads this extension's dependency descriptor,
jsmacrosce.ext.<name>.json. A missing descriptor means the extension declares no dependencies.Returns: resolved dependency resource URLs in the order the descriptor lists them; empty when the descriptor has no dependencies or none of them resolve
getDependenciesInternal
Resolves dependency URLs from a root-classpath JSON descriptor. The descriptor is a JSON object whose
dependencies value is an array of resource paths relative to the classpath root, for example {"dependencies": ["META-INF/jsmacroscedeps/graal-sdk.jar"]}. Each path names an archive inside the extension's own jar. Entries resolve in the order listed, which is the order the loader hands them to the class loader, so the first archive to contain a class wins. A missing descriptor and an absent dependencies member both mean "no dependencies". An unreadable, unparsable, or wrongly shaped descriptor throws, because a declaration that cannot be understood must not be mistaken for "no dependencies". A declared path that the classpath does not provide is reported and skipped instead of failing the extension. The descriptor lists archives that are embedded in the extension's own jar, and a development run or other flat classpath may supply the same classes without that archive existing at the declared path. The report names the descriptor and the path, so a dependency that really is missing can still be traced from the warning.Parameters:
clazz: class used to look up the descriptor and its dependency resourcesfname: descriptor path relative to the classpath root, without a leading slash
Returns: resolved dependency resource URLs, in descriptor order
getExtensionName
getTranslations
Reads this extension's language files from
assets/jsmacrosce/, for example assets/jsmacrosce/graal/lang/en_us.json for the graal extension. Files under the legacy assets/jsmacros/ namespace are ignored. If the requested language exists only at the legacy path, a warning names the file and its required destination. An extension that keeps its translations somewhere else overrides this method.Parameters:
lang: language-code filename component, such asen_us
Returns: translation values keyed by their JSON object keys; empty if no supported language file is present, if reading or parsing fails, or if the JSON root is not an object. Values that cannot be converted to strings can cause a runtime exception.
getTranslationsInternal
Reads a root-classpath JSON object as a map of string values. Read or parse failures and non-object roots produce an empty map.
Parameters:
clazz: class used to look up the resourcefname: resource path relative to the classpath root, without a leading slash
Returns: object entries converted to string values, or an empty map on read or parse failure or a non-object root; values that cannot be converted can cause a runtime exception