use of org.xwiki.extension.ExtensionId in project xwiki-platform by xwiki.
the class DiffXarJob method diff.
private void diff(InstalledExtension installedExtension, String namespace, Set<LocalDocumentReference> alreadydone) {
Collection<ExtensionId> excludedExtensions = getRequest().getExcludedExtensions();
if (XarExtensionHandler.TYPE.equals(installedExtension.getType()) && (excludedExtensions == null || !excludedExtensions.contains(installedExtension.getId()))) {
if (getRequest().isVerbose()) {
this.logger.info("Computing differences for [{}] on namespace [{}]", installedExtension.getId(), namespace);
}
try {
WikiReference wikiReference = new WikiReference(XarHandlerUtils.getWikiFromNamespace(namespace));
diff(new XarFile(new File(installedExtension.getFile().getAbsolutePath())), wikiReference, installedExtension.getId(), alreadydone);
} catch (UnsupportedNamespaceException e) {
this.logger.error("Failed to extract the wiki id from the namespace [{}].", namespace, e);
} catch (IOException e) {
this.logger.error("Failed to read the XAR file of the extension [{}].", installedExtension.getId(), e);
} catch (XarException e) {
this.logger.error("Failed to parse the XAR file of the extension [{}].", installedExtension.getId(), e);
}
}
}
use of org.xwiki.extension.ExtensionId 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);
}
}
use of org.xwiki.extension.ExtensionId in project xwiki-platform by xwiki.
the class XarExtensionScriptService method diff.
/**
* Computes the differences, in unified format, between the documents of an installed XAR extension and the document
* from the wiki.
*
* @param feature the identifier of a XAR extension (or one of its features)
* @param wiki the wiki where the XAR extension is installed
* @return the {@link Job} object which can be used to monitor the progress while the differences are being
* computed, or {@code null} in case of failure
* @since 7.0RC1
*/
public Job diff(String feature, String wiki) {
setError(null);
String namespace = getWikiNamespace(wiki);
InstallRequest installRequest = new InstallRequest();
installRequest.addExtension(new ExtensionId(feature, (Version) null));
if (namespace != null) {
installRequest.addNamespace(namespace);
}
installRequest.setId(getDiffJobId(feature, namespace));
try {
return this.jobExecutor.execute(DiffXarJob.JOB_TYPE, installRequest);
} catch (Exception e) {
setError(e);
return null;
}
}
use of org.xwiki.extension.ExtensionId in project xwiki-platform by xwiki.
the class XarExtensionScriptService method repairInstalledExtension.
/**
* Make sure the provided XAR extension properly is registered in the installed extensions index.
* <p>
* Start an asynchronous Job.
*
* @param id the extension identifier
* @param version the extension version
* @param wiki the wiki where the extension is installed
* @return the {@link Job} object which can be used to monitor the progress of the installation process, or
* {@code null} in case of failure
*/
public Job repairInstalledExtension(String id, String version, String wiki) {
setError(null);
if (!this.authorization.hasAccess(Right.PROGRAM)) {
setError(new JobException("Need programming right to repair a XAR"));
return null;
}
String namespace = getWikiNamespace(wiki);
InstallRequest installRequest = new InstallRequest();
installRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_ACTION_PREFIX, id, namespace));
DocumentReference currentUserReference = this.documentAccessBridge.getCurrentUserReference();
if (currentUserReference != null) {
installRequest.setProperty(PROPERTY_USER_REFERENCE, currentUserReference);
// We set the string value because the extension repository doesn't know how to serialize/parse an extension
// property whose value is a DocumentReference, and adding support for it requires considerable refactoring
// because ExtensionPropertySerializers are not components (they are currently hard-coded).
installRequest.setExtensionProperty(PROPERTY_USER_REFERENCE, currentUserReference.toString());
}
installRequest.addExtension(new ExtensionId(id, version));
if (StringUtils.isNotBlank(namespace)) {
installRequest.addNamespace(namespace);
}
Job job = null;
try {
job = this.jobExecutor.execute(RepairXarJob.JOBTYPE, installRequest);
} catch (Exception e) {
setError(e);
}
return job;
}
use of org.xwiki.extension.ExtensionId in project xwiki-platform by xwiki.
the class DocumentsDeletingListenerTest method test.
@Test
public void test() 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");
DocumentReference doc2 = new DocumentReference("a", "b", "c2");
DocumentReference doc3 = new DocumentReference("a", "b", "c3");
concernedEntities.put(doc1, new EntitySelection(doc1));
concernedEntities.put(doc2, new EntitySelection(doc2));
concernedEntities.put(doc3, new EntitySelection(doc3));
XarInstalledExtension ext1 = mock(XarInstalledExtension.class);
XarInstalledExtension ext2 = mock(XarInstalledExtension.class);
when(ext1.getId()).thenReturn(new ExtensionId("ext1"));
when(ext2.getId()).thenReturn(new ExtensionId("ext2"));
when(repository.getXarInstalledExtensions(doc1)).thenReturn(Arrays.asList(ext1, ext2));
when(repository.getXarInstalledExtensions(doc2)).thenReturn(Collections.emptyList());
when(repository.getXarInstalledExtensions(doc3)).thenReturn(Arrays.asList(ext2));
doAnswer(invocationOnMock -> {
ExtensionBreakingQuestion question = invocationOnMock.getArgument(0);
assertEquals(concernedEntities, question.getConcernedEntities());
// Ext 1
assertEquals(1, question.getExtension("ext1").getPages().size());
assertTrue(question.getExtension("ext1").getPages().contains(concernedEntities.get(doc1)));
// Ext 2
assertEquals(2, question.getExtension("ext2").getPages().size());
assertTrue(question.getExtension("ext2").getPages().contains(concernedEntities.get(doc1)));
assertTrue(question.getExtension("ext2").getPages().contains(concernedEntities.get(doc3)));
// Free pages
assertEquals(1, question.getFreePages().size());
assertTrue(question.getFreePages().contains(concernedEntities.get(doc2)));
// Assert nothing is select by default
for (EntitySelection selection : question.getConcernedEntities().values()) {
assertFalse(selection.isSelected());
}
return null;
}).when(status).ask(any(), anyLong(), any());
// Test
DocumentsDeletingEvent event = new DocumentsDeletingEvent();
mocker.getComponentUnderTest().onEvent(event, job, concernedEntities);
// Check
verify(status, times(1)).ask(any(), eq(5L), eq(TimeUnit.MINUTES));
}
Aggregations