<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.environment;

import java.io.File;

import org.xwiki.component.embed.EmbeddableComponentManager;
import org.xwiki.component.manager.ComponentLookupException;
import org.xwiki.component.manager.ComponentManager;
import org.xwiki.environment.internal.StandardEnvironment;

/**
 * Helper class that can be used to easily initialize the full XWiki System (ie Component Manager and Environment).
 *
 * @version $Id$
 * @since 3.5M1
 */
public final class System
{
    /**
     * Helper static class, no public constructor.
     */
    private System()
    {
        // Prevent instantiation, this is a helper class.
    }

    /**
     * Initialize the full XWiki system (ie Component Manager and Environment), using the "java.io.tmpdir" System
     * property value as the temporary diretory location, without any resource directory set and without any permanent
     * directory set either.
     *
     * @param classLoader see {@link EmbeddableComponentManager#initialize(ClassLoader)}
     * @return the initialized Component Manager
     */
    public static ComponentManager initialize(ClassLoader classLoader)
    {
        return initialize(null, null, null, classLoader);
    }
    
    /**
     * Initialize the full XWiki system (ie Component Manager and Environment), using the class loader that loaded
     * this class, using the "java.io.tmpdir" System property value as the temporary diretory location, without
     * any resource directory set and without any permanent directory set either.
     *
     * @return the initialized Component Manager
     */
    public static ComponentManager initialize()
    {
        return initialize((File) null);
    }

    /**
     * Initialize the full XWiki system (ie Component Manager and Environment), using the class loader that loaded
     * this class, using the "java.io.tmpdir" System property value as the temporary diretory location and without
     * any resource directory set (the permanent directory will be used as the resource directory).
     *
     * @param permanentDirectory see {@link org.xwiki.environment.Environment#getPermanentDirectory()}
     * @return the initialized Component Manager
     */
    public static ComponentManager initialize(File permanentDirectory)
    {
        return initialize(permanentDirectory, null);
    }
    
    /**
     * Initialize the full XWiki system (ie Component Manager and Environment), using the class loader that loaded
     * this class and using the "java.io.tmpdir" System property value as the temporary diretory location.
     *
     * @param permanentDirectory see {@link org.xwiki.environment.Environment#getPermanentDirectory()}
     * @param resourceDirectory see {@link org.xwiki.environment.internal.StandardEnvironment#setResourceDirectory(java.io.File)}
     * @return the initialized Component Manager
     */
    public static ComponentManager initialize(File permanentDirectory, File resourceDirectory)
    {
        return initialize(permanentDirectory, resourceDirectory, null);
    }
    
    /**
     * Initialize the full XWiki system (ie Component Manager and Environment), using the class loader that loaded
     * this class.
     *
     * @param permanentDirectory see {@link org.xwiki.environment.Environment#getPermanentDirectory()}
     * @param resourceDirectory see {@link org.xwiki.environment.internal.StandardEnvironment#setResourceDirectory(java.io.File)}
     * @param temporaryDirectory see {@link org.xwiki.environment.Environment#getTemporaryDirectory()}
     * @return the initialized Component Manager
     */
    public static ComponentManager initialize(File permanentDirectory, File resourceDirectory, File temporaryDirectory)
    {
        return initialize(permanentDirectory, resourceDirectory, temporaryDirectory, null);
    }

    /**
     * Initialize the full XWiki system (ie Component Manager and Environment).
     * 
     * @param permanentDirectory see {@link org.xwiki.environment.Environment#getPermanentDirectory()}
     * @param resourceDirectory see {@link org.xwiki.environment.internal.StandardEnvironment#setResourceDirectory(java.io.File)}
     * @param temporaryDirectory see {@link org.xwiki.environment.Environment#getTemporaryDirectory()}
     * @param classLoader see {@link EmbeddableComponentManager#initialize(ClassLoader)}
     * @return the initialized Component Manager
     */
    public static ComponentManager initialize(File permanentDirectory, File resourceDirectory, File temporaryDirectory,
        ClassLoader classLoader)
    {
        // Step 1: Initialize Component system
        EmbeddableComponentManager ecm = new EmbeddableComponentManager();
        ecm.initialize(classLoader == null ? System.class.getClassLoader() : classLoader);

        // Step 2: Initialize Environment
        StandardEnvironment environment;
        try {
            environment = (StandardEnvironment) ecm.getInstance(Environment.class);
        } catch (ComponentLookupException e) {
            throw new RuntimeException("Failed to find Standard Environment", e);
        }
        environment.setPermanentDirectory(permanentDirectory);
        environment.setResourceDirectory(resourceDirectory);
        environment.setTemporaryDirectory(temporaryDirectory);

        return ecm;
    }
}
<commit_msg>[Misc] Removed unnecessary cast<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.environment;

import java.io.File;

import org.xwiki.component.embed.EmbeddableComponentManager;
import org.xwiki.component.manager.ComponentLookupException;
import org.xwiki.component.manager.ComponentManager;
import org.xwiki.environment.internal.StandardEnvironment;

/**
 * Helper class that can be used to easily initialize the full XWiki System (ie Component Manager and Environment).
 *
 * @version $Id$
 * @since 3.5M1
 */
public final class System
{
    /**
     * Helper static class, no public constructor.
     */
    private System()
    {
        // Prevent instantiation, this is a helper class.
    }

    /**
     * Initialize the full XWiki system (ie Component Manager and Environment), using the "java.io.tmpdir" System
     * property value as the temporary diretory location, without any resource directory set and without any permanent
     * directory set either.
     *
     * @param classLoader see {@link EmbeddableComponentManager#initialize(ClassLoader)}
     * @return the initialized Component Manager
     */
    public static ComponentManager initialize(ClassLoader classLoader)
    {
        return initialize(null, null, null, classLoader);
    }
    
    /**
     * Initialize the full XWiki system (ie Component Manager and Environment), using the class loader that loaded
     * this class, using the "java.io.tmpdir" System property value as the temporary diretory location, without
     * any resource directory set and without any permanent directory set either.
     *
     * @return the initialized Component Manager
     */
    public static ComponentManager initialize()
    {
        return initialize((File) null);
    }

    /**
     * Initialize the full XWiki system (ie Component Manager and Environment), using the class loader that loaded
     * this class, using the "java.io.tmpdir" System property value as the temporary diretory location and without
     * any resource directory set (the permanent directory will be used as the resource directory).
     *
     * @param permanentDirectory see {@link org.xwiki.environment.Environment#getPermanentDirectory()}
     * @return the initialized Component Manager
     */
    public static ComponentManager initialize(File permanentDirectory)
    {
        return initialize(permanentDirectory, null);
    }
    
    /**
     * Initialize the full XWiki system (ie Component Manager and Environment), using the class loader that loaded
     * this class and using the "java.io.tmpdir" System property value as the temporary diretory location.
     *
     * @param permanentDirectory see {@link org.xwiki.environment.Environment#getPermanentDirectory()}
     * @param resourceDirectory see {@link org.xwiki.environment.internal.StandardEnvironment#setResourceDirectory(java.io.File)}
     * @return the initialized Component Manager
     */
    public static ComponentManager initialize(File permanentDirectory, File resourceDirectory)
    {
        return initialize(permanentDirectory, resourceDirectory, null);
    }
    
    /**
     * Initialize the full XWiki system (ie Component Manager and Environment), using the class loader that loaded
     * this class.
     *
     * @param permanentDirectory see {@link org.xwiki.environment.Environment#getPermanentDirectory()}
     * @param resourceDirectory see {@link org.xwiki.environment.internal.StandardEnvironment#setResourceDirectory(java.io.File)}
     * @param temporaryDirectory see {@link org.xwiki.environment.Environment#getTemporaryDirectory()}
     * @return the initialized Component Manager
     */
    public static ComponentManager initialize(File permanentDirectory, File resourceDirectory, File temporaryDirectory)
    {
        return initialize(permanentDirectory, resourceDirectory, temporaryDirectory, null);
    }

    /**
     * Initialize the full XWiki system (ie Component Manager and Environment).
     * 
     * @param permanentDirectory see {@link org.xwiki.environment.Environment#getPermanentDirectory()}
     * @param resourceDirectory see {@link org.xwiki.environment.internal.StandardEnvironment#setResourceDirectory(java.io.File)}
     * @param temporaryDirectory see {@link org.xwiki.environment.Environment#getTemporaryDirectory()}
     * @param classLoader see {@link EmbeddableComponentManager#initialize(ClassLoader)}
     * @return the initialized Component Manager
     */
    public static ComponentManager initialize(File permanentDirectory, File resourceDirectory, File temporaryDirectory,
        ClassLoader classLoader)
    {
        // Step 1: Initialize Component system
        EmbeddableComponentManager ecm = new EmbeddableComponentManager();
        ecm.initialize(classLoader == null ? System.class.getClassLoader() : classLoader);

        // Step 2: Initialize Environment
        StandardEnvironment environment;
        try {
            environment = ecm.getInstance(Environment.class);
        } catch (ComponentLookupException e) {
            throw new RuntimeException("Failed to find Standard Environment", e);
        }
        environment.setPermanentDirectory(permanentDirectory);
        environment.setResourceDirectory(resourceDirectory);
        environment.setTemporaryDirectory(temporaryDirectory);

        return ecm;
    }
}

{'fraction_non_alphanumeric': 0.07366897217307383, 'fraction_numerical': 0.002895287115972334, 'mean_word_length': 3.6555597154623736, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3443137', 'n_tokens_mistral': 2938, 'n_tokens_neox': 2896, 'n_words': 1104}