<commit_before>package <%=packageName%>.config.reload;

import org.apache.commons.io.filefilter.SuffixFileFilter;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springsource.loaded.ReloadableType;
import org.springsource.loaded.TypeRegistry;
import org.springsource.loaded.Utils;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static java.nio.file.LinkOption.NOFOLLOW_LINKS;
import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;

/**
 * A watcher for the target class folder.
 * 
 * The watcher will monitor all folders and sub-folders to check if a new class
 * is created. If so, the new class will be loaded and managed by Spring-Loaded.
 */
public class JHipsterFileSystemWatcher implements Runnable {

    private static Logger log = LoggerFactory.getLogger(JHipsterFileSystemWatcher.class);

    private static boolean isStarted;
    private final WatchService watcher;
    private final Map<WatchKey, Path> keys = new HashMap<>();
    private ClassLoader parentClassLoader;
    private Map<String, URLClassLoader> urlClassLoaderMap = new HashMap<>();

    public JHipsterFileSystemWatcher(List<String> watchFolders, ClassLoader classLoader) throws Exception {
        this.parentClassLoader = classLoader;

        watcher = FileSystems.getDefault().newWatchService();

        // Register all folders
        for (String watchFolder : watchFolders) {
            URLClassLoader urlClassLoader = new URLClassLoader(new URL[] {new File(watchFolder).toURI().toURL()}, classLoader);
            urlClassLoaderMap.put(watchFolder, urlClassLoader);

            final Path classesFolderPath = FileSystems.getDefault().getPath(watchFolder);
            registerAll(classesFolderPath);
        }

        isStarted = true;
    }

    /**
     * Register the classLoader and start a thread that will be used to monitor folders where classes can be created.
     *
     * @param classLoader the classLoader of the application
     * @param watchFolders the list of folders to watch
     */
    public static void register(ClassLoader classLoader, List<String> watchFolders) {
        try {
            if (watchFolders.size() == 0) {
                log.warn("SpringLoaded - No watch folders have been defined in the application-{profile}.yml. " +
                        "We will use the default target/classes");
                watchFolders.add("target/classes");
            }

            final Thread thread = new Thread(new JHipsterFileSystemWatcher(watchFolders, classLoader));
            thread.setDaemon(true);
            thread.start();

            Runtime.getRuntime().addShutdownHook(new Thread() {
                public void run() {
                    JHipsterFileSystemWatcher.isStarted = false;
                    try {
                        thread.join();
                    } catch (InterruptedException e) {
                        log.error("Failed during the JVM shutdown", e);
                    }
                }
            });
        } catch (Exception e) {
            log.error("Failed to start the watcher. New class will not be loaded.", e);
        }<commit_msg>Wording<commit_after>package <%=packageName%>.config.reload;

import org.apache.commons.io.filefilter.SuffixFileFilter;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springsource.loaded.ReloadableType;
import org.springsource.loaded.TypeRegistry;
import org.springsource.loaded.Utils;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static java.nio.file.LinkOption.NOFOLLOW_LINKS;
import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;

/**
 * A watcher for the target class folder.
 * 
 * The watcher will monitor all folders and sub-folders to check if a new class
 * is created. If so, the new class will be loaded and managed by Spring-Loaded.
 */
public class JHipsterFileSystemWatcher implements Runnable {

    private static Logger log = LoggerFactory.getLogger(JHipsterFileSystemWatcher.class);

    private static boolean isStarted;
    private final WatchService watcher;
    private final Map<WatchKey, Path> keys = new HashMap<>();
    private ClassLoader parentClassLoader;
    private Map<String, URLClassLoader> urlClassLoaderMap = new HashMap<>();

    public JHipsterFileSystemWatcher(List<String> watchFolders, ClassLoader classLoader) throws Exception {
        this.parentClassLoader = classLoader;

        watcher = FileSystems.getDefault().newWatchService();

        // Register all folders
        for (String watchFolder : watchFolders) {
            URLClassLoader urlClassLoader = new URLClassLoader(new URL[] {new File(watchFolder).toURI().toURL()}, classLoader);
            urlClassLoaderMap.put(watchFolder, urlClassLoader);

            final Path classesFolderPath = FileSystems.getDefault().getPath(watchFolder);
            registerAll(classesFolderPath);
        }

        isStarted = true;
    }

    /**
     * Register the classLoader and start a thread that will be used to monitor folders where classes can be created.
     *
     * @param classLoader the classLoader of the application
     * @param watchFolders the list of folders to watch
     */
    public static void register(ClassLoader classLoader, List<String> watchFolders) {
        try {
            if (watchFolders.size() == 0) {
                log.warn("SpringLoaded - No watched folders have been defined in the application-{profile}.yml. " +
                        "We will use the default target/classes");
                watchFolders.add("target/classes");
            }

            final Thread thread = new Thread(new JHipsterFileSystemWatcher(watchFolders, classLoader));
            thread.setDaemon(true);
            thread.start();

            Runtime.getRuntime().addShutdownHook(new Thread() {
                public void run() {
                    JHipsterFileSystemWatcher.isStarted = false;
                    try {
                        thread.join();
                    } catch (InterruptedException e) {
                        log.error("Failed during the JVM shutdown", e);
                    }
                }
            });
        } catch (Exception e) {
            log.error("Failed to start the watcher. New class will not be loaded.", e);
        }
{'fraction_non_alphanumeric': 0.08840749414519906, 'fraction_numerical': 0.0008782201405152225, 'mean_word_length': 2.752333882482153, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2500837', 'n_tokens_mistral': 1840, 'n_tokens_neox': 1782, 'n_words': 500}