0

I use xwiki Enterprise 7.4. The official way to install extensions is to use either Import feature or Extension Manager. Both ways require user interaction. I would like to automate extension installation process, so no user interactions for extension installation. Is it possible? I've automated spaces/pages creation via REST API. Maybe it's possible to use REST API to do it, I can't find it in documentation.

Why do I need it? It's simple: I've automated all the steps of deployment/migration process for my application and I would like to automate xwiki extension installation too.

engineer
  • 63
  • 9
  • Somewhat related: I have posted a script to update installed extensions via commandline: http://stackoverflow.com/questions/26155119 - this is not an answer to this problem, but maybe a starting point. – Clemens Klein-Robbenhaar Mar 16 '16 at 10:14
  • Where do you want to automate this installation from? From inside XWiki (i.e. using some script service) or from outside XWiki (using some REST API, as you`ve mentioned, or some configuration files/folders)? That is an important aspect missing from your question. – Eduard Moraru Mar 16 '16 at 14:54

3 Answers3

2

As indicated by Vincent, you can use the extension script service from inside XWiki. This script service is what the UI is using so everything the UI is doing can be done also by any script (as long as the script author has proper rights).

I just wrote a Velocity example on http://extensions.xwiki.org/xwiki/bin/view/Extension/Extension+Script+Module#HNon-interactiveandsynchronousinstall:

{{velocity}}
## 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()
{{/velocity}}
Thomas Mortagne
  • 397
  • 1
  • 7
  • Thanks, Thomas! I put jar file to my xwiki installation and the feature will be available. The only question I have: how to call the velocity script? Should it be REST call from my application (which is integrated with xwiki) or something else? My application has migrations and if it's possible I would prefer to call API from my application. – engineer Mar 17 '16 at 09:04
  • This kind of script is supposed to be executed as the content of a wiki page in XWiki (what I meant by "from inside XWiki."). Now you can use REST API to create a page with any script you want in it and then execute that page as Guillaume explained it in his answer. – Thomas Mortagne Mar 17 '16 at 13:57
1

The XWiki Core dev team is aware of this and it's in the roadmap but it's not done yet. For example you can see that it was planned for the 8.0 roadmap but it slipped (http://www.xwiki.org/xwiki/bin/view/Roadmaps/Archives8xCycle/).

Continue improving upgrade tools: Scriptable upgrades (priority 1), Simulation (priority 2)

It seems there's no issue created for this at the moment. Would be great if you could create a JIRA issue at http://xwiki.org in the XWiki Platform project.

Now regarding extensions, there's some Script Service that can be used to manipulate extensions, see http://extensions.xwiki.org/xwiki/bin/view/Extension/Extension+Script+Module

However this documentation is pretty terse. You could check the java code at https://github.com/xwiki/xwiki-platform/blob/95abd2951123431c1624c124b49ca7a88b41be00/xwiki-platform-core/xwiki-platform-extension/xwiki-platform-extension-script/src/main/java/org/xwiki/extension/script/ExtensionManagerScriptService.java#L84-L84

I've not personally used this script service so I can't give real examples of using this API

1

All you need is to put the Thomas' script in a page. You can use the REST API for that. See: http://platform.xwiki.org/xwiki/bin/view/Features/XWikiRESTfulAPI#HPageresources

Then you call the URL from your application.

Ex: you put the code in XWiki/AutoInstall with a REST call and then you can call this page with the following url:

http://localhost:8080/xwiki/bin/get/XWiki/AutoInstall

I suggest to use the "get" action from the URL to avoid unnecessary informations.

  • Thanks a lot, it works (as described, just need to add a velocity script and call the page with the script)! The only thing I worry about is get request, because usually get request doesn't change state of a server, but I suppose we can call velocity script only with get request. – engineer Mar 17 '16 at 16:01
  • Interesting, when I restart xwiki there are no the installed extension in the installed extensions list. The same thing happens when I install it via Extension Manager. What can be the source of the problem? – engineer Mar 17 '16 at 16:29
  • Maybe it's just some bug: extension is installed but not on the list of installed extensions. – engineer Mar 17 '16 at 19:03