use of org.xwiki.extension.ExtensionId in project xwiki-platform by xwiki.
the class ExtensionManagerScriptService method createInstallPlanRequest.
/**
* Create an {@link InstallRequest} instance based on given parameters, to be used to create the install plan.
*
* @param id the identifier of the extension to install
* @param version the version to install
* @param namespace the (optional) namespace where to install the extension; if {@code null} or empty, the extension
* will be installed in root namespace (globally)
* @return the {@link InstallRequest}
*/
public InstallRequest createInstallPlanRequest(String id, String version, String namespace) {
InstallRequest installRequest = new InstallRequest();
installRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_PLAN_PREFIX, id, namespace));
installRequest.setInteractive(true);
installRequest.addExtension(new ExtensionId(id, version));
if (StringUtils.isNotBlank(namespace)) {
installRequest.addNamespace(namespace);
}
XWikiContext xcontext = this.xcontextProvider.get();
// Indicate if it's allowed to do modification on root namespace
installRequest.setRootModificationsAllowed(namespace == null || xcontext.isMainWiki(toWikiId(namespace)));
// Allow overwritting a few things in extensions descriptors
installRequest.setRewriter(new ScriptExtensionRewriter());
contextualize(installRequest);
setRightsProperties(installRequest);
return installRequest;
}
use of org.xwiki.extension.ExtensionId in project xwiki-platform by xwiki.
the class XarInstalledExtensionRepository method getXarInstalledExtensions.
/**
* @param reference the reference of the document
* @return the extension owners of the passed document
* @since 8.1M2
*/
public Collection<XarInstalledExtension> getXarInstalledExtensions(DocumentReference reference) {
if (reference instanceof DocumentVersionReference) {
DocumentVersionReference versionReference = (DocumentVersionReference) reference;
if (versionReference.getVersion() instanceof ExtensionId) {
ExtensionId extensionId = (ExtensionId) versionReference.getVersion();
if (extensionId != null) {
return Arrays.asList((XarInstalledExtension) getInstalledExtension(extensionId));
}
}
}
Collection<XarInstalledExtension> wikiExtensions = this.documents.get(reference.getLocale() == null ? new DocumentReference(reference, Locale.ROOT) : reference);
Collection<XarInstalledExtension> rootExtensions = this.rootDocuments.get(reference.getLocalDocumentReference().getLocale() == null ? new LocalDocumentReference(reference.getLocalDocumentReference(), Locale.ROOT) : reference.getLocalDocumentReference());
List<XarInstalledExtension> allExtensions = new ArrayList<>();
if (wikiExtensions != null) {
allExtensions.addAll(wikiExtensions);
}
if (rootExtensions != null) {
allExtensions.addAll(rootExtensions);
}
return allExtensions;
}
use of org.xwiki.extension.ExtensionId in project xwiki-platform by xwiki.
the class DocumentsDeletingListenerTest method testCancel.
@Test
public void testCancel() throws Exception {
Request request = mock(Request.class);
Job job = mock(Job.class);
JobStatus status = mock(JobStatus.class);
when(job.getRequest()).thenReturn(request);
when(request.isInteractive()).thenReturn(true);
when(job.getStatus()).thenReturn(status);
Map<EntityReference, EntitySelection> concernedEntities = new HashMap<>();
DocumentReference doc1 = new DocumentReference("a", "b", "c1");
concernedEntities.put(doc1, new EntitySelection(doc1));
XarInstalledExtension ext1 = mock(XarInstalledExtension.class);
when(ext1.getId()).thenReturn(new ExtensionId("ext1"));
when(repository.getXarInstalledExtensions(doc1)).thenReturn(Arrays.asList(ext1));
InterruptedException e = new InterruptedException();
doThrow(e).when(status).ask(any(), anyLong(), any());
// Test
DocumentsDeletingEvent event = mock(DocumentsDeletingEvent.class);
mocker.getComponentUnderTest().onEvent(event, job, concernedEntities);
// Check
verify(status, times(1)).ask(any(), eq(5L), eq(TimeUnit.MINUTES));
verify(event).cancel(eq("Question has been interrupted."));
verify(mocker.getMockedLogger()).warn("Confirm question has been interrupted.");
}
use of org.xwiki.extension.ExtensionId in project xwiki-platform by xwiki.
the class FlavorSearchJob method findValidVersion.
private Extension findValidVersion(String flavorId, String namespace, List<Version> versionList) {
this.progressManager.pushLevelProgress(versionList.size(), flavorId);
try {
for (ListIterator<Version> it = versionList.listIterator(versionList.size()); it.hasPrevious(); ) {
this.progressManager.startStep(flavorId);
Version version = it.previous();
Extension extension = tryInstallExtension(new ExtensionId(flavorId, version), namespace);
this.progressManager.endStep(flavorId);
if (extension != null) {
return extension;
}
}
} finally {
this.progressManager.popLevelProgress(flavorId);
}
return null;
}
use of org.xwiki.extension.ExtensionId 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();
}
Aggregations