<commit_before>/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.extension.distribution.internal.job;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import org.apache.commons.lang3.ObjectUtils;
import org.xwiki.component.annotation.Component;
import org.xwiki.extension.ExtensionId;
import org.xwiki.extension.InstalledExtension;
import org.xwiki.extension.distribution.internal.DistributionManager;
import org.xwiki.extension.distribution.internal.job.DistributionStepStatus.UpdateState;
import org.xwiki.extension.repository.InstalledExtensionRepository;
import org.xwiki.job.AbstractJob;
import org.xwiki.job.internal.AbstractJobStatus;

/**
 * @version $Id$
 * @since 4.2M3
 */
@Component
@Named("distribution")
public class DistributionJob extends AbstractJob<DistributionRequest>
{
    /**
     * The component used to get information about the current distribution.
     */
    @Inject
    private DistributionManager distributionManager;

    @Inject
    private InstalledExtensionRepository installedRepository;

    @Override
    public String getType()
    {
        return "distribution";
    }

    @Override
    protected AbstractJobStatus<DistributionRequest> createNewStatus(DistributionRequest request)
    {
        // TODO: make steps components automatically discovered so that any module can add custom steps

        List<DistributionStepStatus> steps = new ArrayList<DistributionStepStatus>(3);

        ExtensionId extensionUI = this.distributionManager.getUIExtensionId();

        // Step 1: Install/upgrade main wiki UI

        DistributionStepStatus step1 = new DistributionStepStatus("extension.mainui");
        steps.add(step1);
        // Only if the UI is not already installed
        if (this.installedRepository.getInstalledExtension(extensionUI) != null) {
            step1.setUpdateState(UpdateState.COMPLETED);
        }

        // Step 2: Upgrade outdated extensions

        DistributionStepStatus step2 = new DistributionStepStatus("extension.outdatedextensions");
        steps.add(step2);
        step1.setUpdateState(UpdateState.COMPLETED);
        // Upgrade outdated extensions only when there is outdated extensions
        for (InstalledExtension extension : this.installedRepository.getInstalledExtensions()) {
            Collection<String> namespaces = extension.getNamespaces();
            if (namespaces == null) {
                if (!extension.isValid(null)) {
                    step2.setUpdateState(null);
                    break;
                }<commit_msg>XWIKI-8496: After installing from scratch XE with DW the status in the next restarts will be seen as PARTIAL<commit_after>/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.extension.distribution.internal.job;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import org.apache.commons.lang3.ObjectUtils;
import org.xwiki.component.annotation.Component;
import org.xwiki.extension.ExtensionId;
import org.xwiki.extension.InstalledExtension;
import org.xwiki.extension.distribution.internal.DistributionManager;
import org.xwiki.extension.distribution.internal.job.DistributionStepStatus.UpdateState;
import org.xwiki.extension.repository.InstalledExtensionRepository;
import org.xwiki.job.AbstractJob;
import org.xwiki.job.internal.AbstractJobStatus;

/**
 * @version $Id$
 * @since 4.2M3
 */
@Component
@Named("distribution")
public class DistributionJob extends AbstractJob<DistributionRequest>
{
    /**
     * The component used to get information about the current distribution.
     */
    @Inject
    private DistributionManager distributionManager;

    @Inject
    private InstalledExtensionRepository installedRepository;

    @Override
    public String getType()
    {
        return "distribution";
    }

    @Override
    protected AbstractJobStatus<DistributionRequest> createNewStatus(DistributionRequest request)
    {
        // TODO: make steps components automatically discovered so that any module can add custom steps

        List<DistributionStepStatus> steps = new ArrayList<DistributionStepStatus>(3);

        ExtensionId extensionUI = this.distributionManager.getUIExtensionId();

        // Step 1: Install/upgrade main wiki UI

        DistributionStepStatus step1 = new DistributionStepStatus("extension.mainui");
        steps.add(step1);
        // Only if the UI is not already installed
        if (this.installedRepository.getInstalledExtension(extensionUI) != null) {
            step1.setUpdateState(UpdateState.COMPLETED);
        }

        // Step 2: Upgrade outdated extensions

        DistributionStepStatus step2 = new DistributionStepStatus("extension.outdatedextensions");
        steps.add(step2);
        step2.setUpdateState(UpdateState.COMPLETED);
        // Upgrade outdated extensions only when there is outdated extensions
        for (InstalledExtension extension : this.installedRepository.getInstalledExtensions()) {
            Collection<String> namespaces = extension.getNamespaces();
            if (namespaces == null) {
                if (!extension.isValid(null)) {
                    step2.setUpdateState(null);
                    break;
                }
{'fraction_non_alphanumeric': 0.076868529286626, 'fraction_numerical': 0.008225783576797617, 'mean_word_length': 3.5792207792207793, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3757722', 'n_tokens_mistral': 1786, 'n_tokens_neox': 1699, 'n_words': 586}