Search in sources :

Example 1 with FlavorQuery

use of org.xwiki.platform.flavor.FlavorQuery in project xwiki-platform by xwiki.

the class FlavorSearchJob method runInternal.

@Override
protected void runInternal() throws Exception {
    // Get known flavors
    Collection<ExtensionId> knownFlavors = this.flavorManager.getKnownFlavors();
    Collection<String> knownInvalidFlavors = this.flavorManager.getKnownInvalidFlavors();
    // Get remote flavors
    IterableResult<Extension> flavors = this.flavorManager.searchFlavors(new FlavorQuery());
    this.progressManager.pushLevelProgress(knownFlavors.size() + flavors.getSize(), this);
    try {
        // Remember which flavors already been (in)validated
        Set<String> doneFlavors = new HashSet<>();
        // Add the know invalid flavors to the list of already done flavors
        doneFlavors.addAll(knownInvalidFlavors);
        String namespace = getRequest().getNamespaces().iterator().next();
        // Add known flavors
        for (ExtensionId flavorId : knownFlavors) {
            this.progressManager.startStep(this);
            // Validate and add the flavor
            validateKnownFlavor(flavorId, namespace);
            // Remember we took care of this flavor
            doneFlavors.add(flavorId.getId());
            this.progressManager.endStep(this);
        }
        // Add remote flavors
        for (Extension flavor : flavors) {
            this.progressManager.startStep(this);
            // Search only unknown flavors
            if (!doneFlavors.contains(flavor.getId().getId())) {
                Extension validExtension = findValidVersion(flavor.getId().getId(), namespace);
                if (validExtension != null) {
                    this.foundFlavors.add(validExtension);
                }
            }
            this.progressManager.endStep(this);
        }
    } finally {
        this.progressManager.popLevelProgress(this);
    }
}
Also used : Extension(org.xwiki.extension.Extension) ExtensionId(org.xwiki.extension.ExtensionId) FlavorQuery(org.xwiki.platform.flavor.FlavorQuery) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 Extension (org.xwiki.extension.Extension)1 ExtensionId (org.xwiki.extension.ExtensionId)1 FlavorQuery (org.xwiki.platform.flavor.FlavorQuery)1