use of org.xwiki.extension.job.UninstallRequest in project xwiki-platform by xwiki.
the class ExtensionManagerScriptService method createUninstallPlanRequest.
/**
* Create an {@link UninstallRequest} instance based on passed parameters.
*
* @param extensionId the identifier of the extension to uninstall
* @param namespace the (optional) namespace from where to uninstall the extension; if {@code null} or empty, the
* extension will be uninstalled globally
* @return the {@link UninstallRequest}
*/
private UninstallRequest createUninstallPlanRequest(ExtensionId extensionId, String namespace) {
UninstallRequest uninstallRequest = new UninstallRequest();
uninstallRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_PLAN_PREFIX, extensionId.getId(), namespace));
uninstallRequest.setInteractive(true);
uninstallRequest.addExtension(extensionId);
if (StringUtils.isNotBlank(namespace)) {
uninstallRequest.addNamespace(namespace);
}
// Indicate if it's allowed to do modification on root namespace
uninstallRequest.setRootModificationsAllowed(namespace == null || this.xcontextProvider.get().isMainWiki(toWikiId(namespace)));
contextualize(uninstallRequest);
setRightsProperties(uninstallRequest);
return uninstallRequest;
}
use of org.xwiki.extension.job.UninstallRequest in project xwiki-platform by xwiki.
the class ExtensionManagerScriptService method createUninstallRequest.
private UninstallRequest createUninstallRequest(ExtensionId extensionId, String namespace) {
UninstallRequest uninstallRequest = createUninstallPlanRequest(extensionId, namespace);
uninstallRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_ACTION_PREFIX, extensionId.getId(), namespace));
return uninstallRequest;
}
use of org.xwiki.extension.job.UninstallRequest in project xwiki-platform by xwiki.
the class ExtensionHistoryScriptServiceTest method getRecords.
@Test
public void getRecords() throws Exception {
InstallRequest devInstallReq = new InstallRequest();
devInstallReq.addNamespace("wiki:dev");
ExtensionJobHistoryRecord devInstall = new ExtensionJobHistoryRecord("install", devInstallReq, null, null, null);
UninstallRequest devUninstallReq = new UninstallRequest();
devUninstallReq.addNamespace("wiki:dev");
ExtensionJobHistoryRecord devUninstall = new ExtensionJobHistoryRecord("uninstall", devUninstallReq, null, null, null);
ExtensionJobHistoryRecord globalInstall = new ExtensionJobHistoryRecord("install", new InstallRequest(), null, null, null);
ExtensionJobHistoryRecord globalUninstall = new ExtensionJobHistoryRecord("uninstall", new UninstallRequest(), null, null, null);
InstallRequest draftsInstallReq = new InstallRequest();
draftsInstallReq.addNamespace("wiki:drafts");
ExtensionJobHistoryRecord draftsInstall = new ExtensionJobHistoryRecord("install", draftsInstallReq, null, null, null);
List<ExtensionJobHistoryRecord> records = Arrays.asList(devInstall, globalInstall);
ExtensionJobHistory history = this.mocker.getInstance(ExtensionJobHistory.class);
ArgumentCaptor<Predicate<ExtensionJobHistoryRecord>> predicateCaptor = ArgumentCaptor.forClass((Class) Predicate.class);
when(history.getRecords(predicateCaptor.capture(), eq("offsetRecordId"), eq(5))).thenReturn(records);
when(this.xcontext.getWikiId()).thenReturn("dev");
assertEquals(records, this.mocker.getComponentUnderTest().getRecords().fromThisWiki().ofType(Arrays.asList("install")).list("offsetRecordId", 5));
Predicate<ExtensionJobHistoryRecord> predicate = predicateCaptor.getValue();
assertTrue(predicate.evaluate(devInstall));
assertTrue(predicate.evaluate(globalInstall));
assertFalse(predicate.evaluate(devUninstall));
assertFalse(predicate.evaluate(globalUninstall));
assertFalse(predicate.evaluate(draftsInstall));
}
use of org.xwiki.extension.job.UninstallRequest in project xwiki-platform by xwiki.
the class XarExtensionHandlerTest method uninstall.
private void uninstall(ExtensionId extensionId, String wiki) throws Throwable {
UninstallRequest uninstallRequest = new UninstallRequest();
uninstallRequest.setProperty("user.reference", getXWikiContext().getUserReference());
uninstallRequest.setProperty("checkrights", true);
uninstallRequest.addExtension(extensionId);
if (wiki != null) {
uninstallRequest.addNamespace("wiki:" + wiki);
}
Job uninstallJob = this.jobExecutor.execute(UninstallJob.JOBTYPE, uninstallRequest);
uninstallJob.join();
List<LogEvent> errors = uninstallJob.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());
}
}
}
use of org.xwiki.extension.job.UninstallRequest in project xwiki-platform by xwiki.
the class InstalledExtensionIndexTest method testInstallExtensionOnRoot.
@Test
public void testInstallExtensionOnRoot() throws Exception {
// Use superadmin
getUtil().setDefaultCredentials(TestUtils.SUPER_ADMIN_CREDENTIALS);
ExtensionId extensionId = new ExtensionId("maven:jar", "1.0");
// ///////////////////////////////////////////
// Make sure it's not yet installed on node 0 and node 1
getUtil().switchExecutor(0);
assertTrue("The extension is already installed on node0", !getExtensionTestUtils().isInstalled(extensionId, Namespace.ROOT));
getUtil().switchExecutor(1);
assertTrue("The extension is already installed on node1", !getExtensionTestUtils().isInstalled(extensionId, Namespace.ROOT));
// ///////////////////////////////////////////
// Install extension on node 0
getUtil().switchExecutor(0);
InstallRequest installRequest = new InstallRequest();
installRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_PLAN_PREFIX, extensionId.getId(), null));
installRequest.setInteractive(false);
installRequest.addExtension(extensionId);
executeJob("install", installRequest);
// ///////////////////////////////////////////
// Make sure it has been installed on node 0
assertTrue("The extension was not installed on node0", getExtensionTestUtils().isInstalled(extensionId, Namespace.ROOT));
// ///////////////////////////////////////////
// Make sure it has been installed on node 1
getUtil().switchExecutor(1);
long t1 = System.currentTimeMillis();
while (!getExtensionTestUtils().isInstalled(extensionId, Namespace.ROOT)) {
if (System.currentTimeMillis() - t1 > 10000L) {
fail("The extension was not installed on node1");
}
Thread.sleep(100);
}
// ///////////////////////////////////////////
// Uninstall extension from node 1
getUtil().switchExecutor(1);
UninstallRequest uninstallRequest = new UninstallRequest();
uninstallRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_PLAN_PREFIX, extensionId.getId(), null));
uninstallRequest.setInteractive(false);
uninstallRequest.addExtension(extensionId);
executeJob("uninstall", uninstallRequest);
// ///////////////////////////////////////////
// Make sure it has been uninstalled from node 1
assertTrue("The extension is still installed on node1", !getExtensionTestUtils().isInstalled(extensionId, Namespace.ROOT));
// ///////////////////////////////////////////
// Make sure it has been uninstalled from node 0
getUtil().switchExecutor(1);
t1 = System.currentTimeMillis();
while (getExtensionTestUtils().isInstalled(extensionId, Namespace.ROOT)) {
if (System.currentTimeMillis() - t1 > 10000L) {
fail("The extension is still installed on node0");
}
Thread.sleep(100);
}
}
Aggregations