# ExtensionLoader

`com.jsmacrosce.jsmacros.core.extensions.ExtensionLoader`

Discovers and initializes extensions associated with a core; queries other than `notLoaded()` trigger loading when completion has not been recorded. Returned extension sets are independent live backing sets; mutating one does not reconcile the others or registered libraries.  
 ```js
const Client = Java.type("com.jsmacrosce.jsmacros.client.JsMacrosClient");  
Chat.log(Client.clientCore.extensions.getAllLanguageExtensions().size());  
 ```

## Constructors

### new ExtensionLoader {#com.jsmacrosce.jsmacros.core.extensions.ExtensionLoader_constructor-Core-}

```js
new ExtensionLoader(Core<?, ?> core)
```

Stores the core and resolves its configured `Extensions` directory without loading extensions or creating that directory.

**Parameters:**
- `core`: associated core with initialized configuration

## Methods

### getAllExtensions {#com.jsmacrosce.jsmacros.core.extensions.ExtensionLoader_getAllExtensions-}

```js
getAllExtensions(): Set<Extension>
```

Loads extensions if needed and returns the live mutable backing set of all registered extensions.

**Returns:** the backing set of registered extensions

### getAllLanguageExtensions {#com.jsmacrosce.jsmacros.core.extensions.ExtensionLoader_getAllLanguageExtensions-}

```js
getAllLanguageExtensions(): Set<LanguageExtension>
```

Loads extensions if needed and returns the live mutable backing set of language extensions.

**Returns:** the backing set of language extensions

### getAllLibraryExtensions {#com.jsmacrosce.jsmacros.core.extensions.ExtensionLoader_getAllLibraryExtensions-}

```js
getAllLibraryExtensions(): Set<LibraryExtension>
```

Loads extensions if needed and returns the live mutable backing set of library extensions.

**Returns:** the backing set of library extensions

### getExtensionForFile {#com.jsmacrosce.jsmacros.core.extensions.ExtensionLoader_getExtensionForFile-File-}

```js
getExtensionForFile(File file): LanguageExtension
```

Loads extensions if needed and selects a language extension matching the file; when multiple matches include `MATCH_WITH_NAME`, only those named matches are considered.  
 Candidates are sorted by negated `int` priority, normally preferring higher priorities; `Integer.MIN_VALUE` overflows and sorts first. Equal priorities have no guaranteed selection.

**Parameters:**
- `file`: candidate file passed to language extensions for matching

**Returns:** the selected matching extension, or `null` if none match

### getExtensionForName {#com.jsmacrosce.jsmacros.core.extensions.ExtensionLoader_getExtensionForName-String-}

```js
getExtensionForName(String extName): Extension
```

Loads extensions if needed and returns the first registered extension with an exact name match; duplicate names have no guaranteed selection order.

**Parameters:**
- `extName`: exact registered extension name

**Returns:** a matching extension, or `null` if none matches

### getHighestPriorityExtension {#com.jsmacrosce.jsmacros.core.extensions.ExtensionLoader_getHighestPriorityExtension-}

```js
getHighestPriorityExtension(): LanguageExtension
```

Loads extensions if needed, then selects the language extension with the greatest priority while the cache is empty. Equal priorities have no guaranteed selection; a non-null cache is not invalidated by changes to the live language-extension set.

**Returns:** the cached or selected extension, or `null` if there are no language extensions

### isExtensionLoaded {#com.jsmacrosce.jsmacros.core.extensions.ExtensionLoader_isExtensionLoaded-String-}

```js
isExtensionLoaded(String name): boolean
```

Loads extensions if needed, then checks for an exact extension-name match in the registered set.

**Parameters:**
- `name`: exact extension name

**Returns:** whether a registered extension has that name

### isGuestObject {#com.jsmacrosce.jsmacros.core.extensions.ExtensionLoader_isGuestObject-Object-}

```js
isGuestObject(Object obj): boolean
```

Loads extensions if needed and asks the loaded language extensions whether they recognize the object.

**Parameters:**
- `obj`: object to inspect

**Returns:** `true` if any loaded language extension recognizes it; `false` otherwise

### loadExtensions {#com.jsmacrosce.jsmacros.core.extensions.ExtensionLoader_loadExtensions-}

```js
loadExtensions(): void
```

Attempts extension discovery, initialization, and library registration unless a class loader has already been assigned; in that case, logs a diagnostic and returns.  
 
 User archives are read from the `Extensions` directory. An archive that is itself an
 entry of another archive — an extension bundled in the mod jar, or a dependency nested in an
 extension jar — cannot be opened by [URLClassLoader](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/net/URLClassLoader.html) where it lies, so
 ExtensionArchiveCache copies it to a file under `Extensions/.cache` first. A
 nested jar entry is named from the source archive and entry metadata; a URL that provides no
 reliable metadata is named from a digest of its bytes. A cache file is reused when it is
 still a readable jar and its key still matches the source, and is removed at the end of the
 load if this load did not use it.  
 
 Discovery order is fixed: providers the parent class loader can see come first, then the
 archives named by the bundled manifest in the order it lists them, then the user's archives
 by file name. Within an archive, providers are visited in the order its service file lists
 them. An extension that shares its name with an already discovered one is ignored, and the
 first one found wins — so a user archive cannot replace a bundled extension of the same
 name. Dependencies are appended to the search path after the initial archives.  
 
 Each extension is handled on its own. A failure to load an extension's dependencies,  
 initialize it, or register its libraries is reported and skips that extension only; the
 remaining extensions still load. The same applies to a provider that cannot be
 instantiated. An extension's dependencies are all materialized and validated before any of
 them joins the search path, so a later invalid archive cannot publish the earlier ones.  
 Once registration is complete, registered extensions receive the post-load callback.  
 A callback failure is logged without unregistering the extension.  
 
 A failure that prevents the load from completing does not mark loading complete, so a
 later query can try again. Extensions registered before the failure are not rolled back, so
 a retry starts beside that partial state rather than from an empty loader. A query made
 while an extension is initializing returns the extensions registered so far; it does not
 start another discovery pass. The current thread's context class loader is set to the
 extension class loader before extensions initialize, because an extension may load classes
 of its own while initializing, and is left set on success. A failed load restores the
 caller's previous context class loader.

### notLoaded {#com.jsmacrosce.jsmacros.core.extensions.ExtensionLoader_notLoaded-}

```js
notLoaded(): boolean
```

Reports whether extension loading has not yet completed.

**Returns:** `true` until loading completion is recorded, including during a load attempt
