Search in sources :

Example 1 with XarEntry

use of org.xwiki.xar.XarEntry in project xwiki-platform by xwiki.

the class XarExtensionHandler method uninstall.

@Override
public void uninstall(InstalledExtension installedExtension, String namespace, Request request) throws UninstallException {
    try {
        initializePagesIndex(request);
        initJobPackageConfiguration(request, false);
    } catch (Exception e) {
        throw new UninstallException("Failed to initialize extension plan index", e);
    }
    // probably not be in an expected state)
    if (!request.isRemote()) {
        Job currentJob;
        try {
            currentJob = this.componentManager.<JobContext>getInstance(JobContext.class).getCurrentJob();
        } catch (ComponentLookupException e) {
            currentJob = null;
        }
        if (currentJob == null) {
            String wiki;
            try {
                wiki = XarHandlerUtils.getWikiFromNamespace(namespace);
            } catch (UnsupportedNamespaceException e) {
                throw new UninstallException("Failed to extract wiki id from namespace", e);
            }
            PackageConfiguration configuration = createPackageConfiguration(null, request, wiki);
            try {
                XarInstalledExtension xarLocalExtension = (XarInstalledExtension) this.xarRepository.resolve(installedExtension.getId());
                Collection<XarEntry> pages = xarLocalExtension.getXarPackage().getEntries();
                this.packager.unimportPages(pages, configuration);
            } catch (Exception e) {
                // Not supposed to be possible
                throw new UninstallException("Failed to get xar extension [" + installedExtension.getId() + "] from xar repository", e);
            }
        } else {
        // The actual delete of pages is done in XarExtensionJobFinishedListener
        }
    }
}
Also used : XarInstalledExtension(org.xwiki.extension.xar.internal.repository.XarInstalledExtension) XarEntry(org.xwiki.xar.XarEntry) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) JobContext(org.xwiki.job.JobContext) Job(org.xwiki.job.Job) AbstractExtensionJob(org.xwiki.extension.job.internal.AbstractExtensionJob) PackageConfiguration(org.xwiki.extension.xar.internal.handler.packager.PackageConfiguration) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ExtensionException(org.xwiki.extension.ExtensionException) IOException(java.io.IOException) UninstallException(org.xwiki.extension.UninstallException) InstallException(org.xwiki.extension.InstallException) XarException(org.xwiki.xar.XarException) UninstallException(org.xwiki.extension.UninstallException)

Example 2 with XarEntry

use of org.xwiki.xar.XarEntry in project xwiki-platform by xwiki.

the class XarExtensionPlan method getPreviousXarExtensionPlanEntry.

public XarExtensionPlanEntry getPreviousXarExtensionPlanEntry(String wiki, LocalDocumentReference localDocumentReference) {
    XarEntry xarEntry = new XarEntry(localDocumentReference);
    XarExtensionPlanEntry planEntry = null;
    Map<XarEntry, XarExtensionPlanEntry> wikiEntry = this.previousXAREntries.get(wiki);
    if (wikiEntry != null) {
        planEntry = wikiEntry.get(xarEntry);
    }
    if (planEntry == null) {
        wikiEntry = this.previousXAREntries.get(null);
        if (wikiEntry != null) {
            planEntry = wikiEntry.get(xarEntry);
        }
    }
    return planEntry;
}
Also used : XarEntry(org.xwiki.xar.XarEntry)

Example 3 with XarEntry

use of org.xwiki.xar.XarEntry in project xwiki-platform by xwiki.

the class DocumentMergeImporter method merge.

private XarEntryMergeResult merge(String comment, XWikiDocument currentDocument, XWikiDocument previousDocument, XWikiDocument nextDocument, PackageConfiguration configuration) throws Exception {
    XWikiContext xcontext = this.xcontextProvider.get();
    // 3 ways merge
    XWikiDocument mergedDocument = currentDocument.clone();
    MergeConfiguration mergeConfiguration = new MergeConfiguration();
    mergeConfiguration.setProvidedVersionsModifiables(true);
    MergeResult documentMergeResult;
    try {
        documentMergeResult = mergedDocument.merge(previousDocument, nextDocument, mergeConfiguration, xcontext);
    } catch (Exception e) {
        // Unexpected error, lets behave as if there was a conflict
        documentMergeResult = new MergeResult();
        documentMergeResult.getLog().error("Unexpected exception thrown. Usually means there is a bug in the merge.", e);
        documentMergeResult.setModified(true);
    }
    documentMergeResult.getLog().log(this.logger);
    XWikiDocument documentToSave;
    if (documentMergeResult.isModified() || !documentMergeResult.getLog().getLogsFrom(LogLevel.ERROR).isEmpty()) {
        documentToSave = askDocumentToSave(currentDocument, previousDocument, nextDocument, mergedDocument, configuration, documentMergeResult);
        if (documentToSave != currentDocument) {
            saveDocument(documentToSave, comment, false, configuration);
        }
    }
    return new XarEntryMergeResult(new XarEntry(new LocalDocumentReference(mergedDocument.getDocumentReferenceWithLocale())), documentMergeResult);
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XarEntry(org.xwiki.xar.XarEntry) MergeResult(com.xpn.xwiki.doc.merge.MergeResult) XWikiContext(com.xpn.xwiki.XWikiContext) MergeConfiguration(com.xpn.xwiki.doc.merge.MergeConfiguration)

Example 4 with XarEntry

use of org.xwiki.xar.XarEntry in project xwiki-platform by xwiki.

the class XarInstalledExtensionRepository method pagesUpdated.

private void pagesUpdated(XarInstalledExtension installedExtension, String namespace, boolean add) throws UnsupportedNamespaceException {
    if (installedExtension != null) {
        for (XarEntry xarEntry : installedExtension.getXarPackage().getEntries()) {
            if (namespace != null) {
                DocumentReference reference = new DocumentReference(xarEntry, new WikiReference(XarHandlerUtils.getWikiFromNamespace(namespace)));
                synchronized (this.documents) {
                    Collection<XarInstalledExtension> referenceExtensions = this.documents.get(reference);
                    if (referenceExtensions != null || add) {
                        Set<XarInstalledExtension> newSet = referenceExtensions != null ? new LinkedHashSet<>(referenceExtensions) : new LinkedHashSet<>();
                        if (add) {
                            newSet.add(installedExtension);
                        } else {
                            newSet.remove(installedExtension);
                        }
                        this.documents.put(reference, newSet);
                    }
                }
            } else {
                synchronized (this.rootDocuments) {
                    Collection<XarInstalledExtension> referenceExtensions = this.rootDocuments.get(xarEntry);
                    if (referenceExtensions != null || add) {
                        Set<XarInstalledExtension> newSet = referenceExtensions != null ? new LinkedHashSet<>(referenceExtensions) : new LinkedHashSet<>();
                        if (add) {
                            newSet.add(installedExtension);
                        } else {
                            newSet.remove(installedExtension);
                        }
                        this.rootDocuments.put(xarEntry, newSet);
                    }
                }
            }
        }
    }
}
Also used : XarEntry(org.xwiki.xar.XarEntry) WikiReference(org.xwiki.model.reference.WikiReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 5 with XarEntry

use of org.xwiki.xar.XarEntry in project xwiki-platform by xwiki.

the class HTTPPerformanceTest method addXarFiles.

private static void addXarFiles(List<HTTPSampler> samplers) throws UnsupportedEncodingException, XarException, IOException {
    String path = System.getProperty("pathToDocuments");
    String patternFilter = System.getProperty("documentsToTest");
    Pattern pattern = patternFilter == null ? null : Pattern.compile(patternFilter);
    for (XarEntry xarEntry : XarPackage.getEntries(new File(path))) {
        if (pattern == null || pattern.matcher(SERIALIZER.serialize(xarEntry)).matches()) {
            samplers.add(createSample(xarEntry, "get"));
            samplers.add(createSample(xarEntry, "view"));
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) XarEntry(org.xwiki.xar.XarEntry) File(java.io.File)

Aggregations

XarEntry (org.xwiki.xar.XarEntry)11 DocumentReference (org.xwiki.model.reference.DocumentReference)5 File (java.io.File)3 IOException (java.io.IOException)3 LocalExtension (org.xwiki.extension.LocalExtension)3 PackageConfiguration (org.xwiki.extension.xar.internal.handler.packager.PackageConfiguration)3 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)3 WikiReference (org.xwiki.model.reference.WikiReference)3 XWikiContext (com.xpn.xwiki.XWikiContext)2 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Pattern (java.util.regex.Pattern)2 ExecutionContext (org.xwiki.context.ExecutionContext)2 XarException (org.xwiki.xar.XarException)2 XWikiException (com.xpn.xwiki.XWikiException)1 MergeConfiguration (com.xpn.xwiki.doc.merge.MergeConfiguration)1 MergeResult (com.xpn.xwiki.doc.merge.MergeResult)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1