# 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 {#com.jsmacrosce.jsmacros.core.extensions.Extension_getDependencies-}

```js
getDependencies(): Set<URL>
```

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 {#com.jsmacrosce.jsmacros.core.extensions.Extension_getDependenciesInternal-Class-String-}

```js
static getDependenciesInternal(Class<?> clazz, String fname): Set<URL>
```

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 resources
- `fname`: descriptor path relative to the classpath root, without a leading slash

**Returns:** resolved dependency resource URLs, in descriptor order

### getExtensionName {#com.jsmacrosce.jsmacros.core.extensions.Extension_getExtensionName-}

```js
getExtensionName(): String
```

Returns the extension identifier used by the loader and default resource paths.

**Returns:** the extension identifier

### getTranslations {#com.jsmacrosce.jsmacros.core.extensions.Extension_getTranslations-String-}

```js
getTranslations(String lang): Map<String, String>
```

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 as `en_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 {#com.jsmacrosce.jsmacros.core.extensions.Extension_getTranslationsInternal-Class-String-}

```js
static getTranslationsInternal(Class<?> clazz, String fname): Map<String, String>
```

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 resource
- `fname`: 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

### init {#com.jsmacrosce.jsmacros.core.extensions.Extension_init-Core-}

```js
init(Core<?, ?> runner): void
```

Called by the loader after dependencies are loaded and before this extension's libraries are registered.

**Parameters:**
- `runner`: core instance supplied by the loader
