Extension Script Module

Last modified by Thomas Mortagne on 2024/08/30 09:57

connectProvide script oriented APIs to manipulate extensions
TypeJAR
CategoryAPI
Developed by

XWiki Development Team

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1
Bundled With

XWiki Standard

Description

The Extension module provide various script oriented APIs. It's also possible to extend it by registering a org.xwiki.script.service.ScriptService component with a hint prefixed with "extension.".

Following are the default set of extension related APIs:

  • extension: $services.extension The entry point of this module is the script service with the identifier extension which then provide several "sub-script services".
    • core: $services.extension.core This script service is dedicated to code extensions. Core extension being the unmodificable extension included in the WAR or coming from the application server.
    • local: $services.extension.local This script service is dedicated to local extensions. Local extension being all the extension installed or not that have been downloaded at some point.
    • installed: $services.extension.installed This script service is dedicated to installed extensions.
    • rating: $services.extension.rating This script service is dedicated to rating informations.
    • history: $services.extension.history Provides access to the Extension Job History and offers APIs to serialize (export), deserialize (import) and replay history records.

Examples

Non-interactive and synchronous install

Install some extension on current wiki in a non-interactive and synchronous fashion.

## Create install request for extension with id org.xwiki.contrib:extension-tweak and version 1.3 on current wiki
#set($installRequest = $services.extension.createInstallRequest('org.xwiki.contrib:extension-tweak', '1.3', "wiki:${xcontext.database}"))

## Disable interactive mode
$installRequest.setInteractive(false)

## Start install
#set($installJob = $services.extension.install($installRequest))

## Wait until install is done
$installJob.join()

Search

Search remote extension

Since 7.1RC1 an advanced search API is provided with filtering, sorting, etc.

#set($query = $services.extension.newQuery('toto'))

## Sort by name
$query.addSort('name', 'DESC')

## Get only the flavors
$query.addFilter('category', 'flavor', 'EQUAL')

## Only the first 10 results
$query.setLimit(10)

## Execute search
#set($result = $services.extension.search($query))

## Display found extensions
#foreach ($extension in $result)
  * $extension
#end

Search installed extension

#set($query = $services.extension.newQuery('toto'))

## Sort by name
$query.addSort('name', 'DESC')

## Get only the flavors
$query.addFilter('category', 'flavor', 'EQUAL')

## Only the first 10 results
$query.setLimit(10)

## Search in extensions installed in wiki "mywiki"
#set($result = $services.extension.installed.repository.searchInstalledExtensions('wiki:mywiki', $query))

## [since 8.1] Search in all installed extensions
#set($result = $services.extension.installed.repository.searchInstalledExtensions($query))

## Display found extensions
#foreach ($extension in $result)
  * $extension
#end

Get Connected