use of org.xwiki.extension.job.InstallRequest in project xwiki-platform by xwiki.
the class ExtensionInstallerTest method installExtension.
@Test
public void installExtension() throws Exception {
// Mocks
InstallJob installJob = mock(InstallJob.class);
mocker.registerComponent(Job.class, InstallJob.JOBTYPE, installJob);
final InstallRequest[] installRequest = { null };
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
installRequest[0] = (InstallRequest) invocation.getArguments()[0];
return null;
}
}).when(installJob).initialize(any(Request.class));
// Test
mocker.getComponentUnderTest().installExtension("wikiId", new ExtensionId("extensionId", "version"));
// Verify
assertNotNull(installRequest[0]);
assertEquals(Arrays.asList("wiki:wikiId"), installRequest[0].getNamespaces());
assertEquals(Arrays.asList("wikicreation", "install", "wikiId"), installRequest[0].getId());
assertEquals(Arrays.asList(new ExtensionId("extensionId", "version")), installRequest[0].getExtensions());
assertEquals(new DocumentReference("xwiki", "XWiki", "superadmin"), installRequest[0].getProperty("user.reference"));
verify(installJob).run();
}
use of org.xwiki.extension.job.InstallRequest in project xwiki-platform by xwiki.
the class DataMojo method executeInternal.
@Override
public void executeInternal() throws MojoExecutionException {
InstallRequest installRequest = new InstallRequest();
// Allow modifying root namespace
installRequest.setRootModificationsAllowed(true);
// Make sure jars are installed on root
// TODO: use a less script oriented class
ScriptExtensionRewriter rewriter = new ScriptExtensionRewriter();
rewriter.installExtensionTypeOnRootNamespace("jar");
rewriter.installExtensionTypeOnRootNamespace("webjar");
installRequest.setRewriter(rewriter);
// Use superadmin as pages author
installRequest.setProperty(AbstractExtensionValidator.PROPERTY_USERREFERENCE, new DocumentReference("xwiki", "XWiki", XWikiRightService.SUPERADMIN_USER));
this.extensionHelper.install(this.includes, installRequest, "wiki:xwiki", null);
}
use of org.xwiki.extension.job.InstallRequest in project xwiki-platform by xwiki.
the class ExtensionInstaller method installExtension.
/**
* Install an extension on a wiki.
*
* @param wikiId id of the wiki
* @param extensionId id of the extension to install
* @throws org.xwiki.platform.wiki.creationjob.WikiCreationException if problem occurs
*/
public void installExtension(String wikiId, ExtensionId extensionId) throws WikiCreationException {
try {
// Create the install request
InstallRequest installRequest = new InstallRequest();
installRequest.setId(Arrays.asList(WikiCreationJob.JOB_ID_PREFIX, "install", wikiId));
installRequest.addExtension(extensionId);
installRequest.addNamespace("wiki:" + wikiId);
// To avoid problem with Programming Rights, we install everything with superadmin
installRequest.setProperty(PROPERTY_USERREFERENCE, SUPERADMIN_REFERENCE);
InstallJob job = componentManager.getInstance(Job.class, InstallJob.JOBTYPE);
job.initialize(installRequest);
job.run();
} catch (ComponentLookupException e) {
throw new WikiCreationException(String.format("Failed to install the extension [%s] on the wiki [%s].", extensionId.toString(), wikiId), e);
}
}
use of org.xwiki.extension.job.InstallRequest in project xwiki-platform by xwiki.
the class XarExtensionHandlerTest method installOnNamespace.
private XarInstalledExtension installOnNamespace(ExtensionId extensionId, String namespace, DocumentReference user) throws Throwable {
InstallRequest installRequest = new InstallRequest();
if (user != null) {
installRequest.setProperty("user.reference", getXWikiContext().getUserReference());
installRequest.setProperty("checkrights", true);
}
installRequest.addExtension(extensionId);
if (namespace != null) {
installRequest.addNamespace(namespace);
}
Job installJob = this.jobExecutor.execute(InstallJob.JOBTYPE, installRequest);
installJob.join();
List<LogEvent> errors = installJob.getStatus().getLog().getLogsFrom(LogLevel.WARN);
if (!errors.isEmpty()) {
if (errors.get(0).getThrowable() != null) {
throw errors.get(0).getThrowable();
} else {
throw new Exception(errors.get(0).getFormattedMessage());
}
}
return (XarInstalledExtension) this.xarExtensionRepository.resolve(extensionId);
}
use of org.xwiki.extension.job.InstallRequest in project xwiki-platform by xwiki.
the class DiffXarJob method runInternal.
@Override
protected void runInternal() throws Exception {
InstallRequest request = getRequest();
// There must be only one namespace specified because we compute the differences for only one wiki.
if (!request.hasNamespaces() || request.getNamespaces().size() != 1) {
return;
}
String namespace = request.getNamespaces().iterator().next();
Collection<ExtensionId> extensionIds = request.getExtensions();
this.progressManager.pushLevelProgress(extensionIds.size(), this);
try {
for (ExtensionId extensionId : extensionIds) {
this.progressManager.startStep(this);
InstalledExtension installedExtension = getInstalledExtension(extensionId, namespace);
// Make sure the specified extension is installed on the specified namespace.
if (installedExtension != null && installedExtension.isInstalled(namespace)) {
diff(extensionId.getId(), namespace, new HashSet<>());
}
this.progressManager.endStep(this);
}
} finally {
this.progressManager.popLevelProgress(this);
}
}
Aggregations