<commit_before>package com.wizzardo.http.framework;

import com.wizzardo.epoll.IOThread;
import com.wizzardo.epoll.SslConfig;
import com.wizzardo.http.filter.AuthFilter;
import com.wizzardo.http.filter.BasicAuthFilter;
import com.wizzardo.http.filter.TokenFilter;
import com.wizzardo.http.request.Request;
import com.wizzardo.http.response.RangeResponseHelper;
import com.wizzardo.http.response.Response;
import com.wizzardo.tools.collections.CollectionTools;
import com.wizzardo.tools.collections.flow.Flow;
import com.wizzardo.tools.evaluation.Config;
import com.wizzardo.http.*;
import com.wizzardo.http.framework.di.DependencyFactory;
import com.wizzardo.http.framework.di.SingletonDependency;
import com.wizzardo.http.framework.message.MessageBundle;
import com.wizzardo.http.framework.message.MessageSource;
import com.wizzardo.http.framework.template.*;
import com.wizzardo.http.mapping.UrlMapping;
import com.wizzardo.tools.evaluation.EvalTools;
import com.wizzardo.tools.interfaces.Consumer;
import com.wizzardo.tools.misc.TextTools;
import com.wizzardo.tools.misc.Unchecked;

import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.BlockingQueue;
import java.util.jar.Manifest;

/**
 * Created by wizzardo on 28.04.15.
 */
public class WebApplication extends HttpServer<HttpConnection> {

    protected Environment environment;
    protected Config config;
    protected Map<String, String> cliArgs = Collections.emptyMap();
    protected ResourceTools resourcesTools;
    protected Consumer<WebApplication> onSetup;
    protected Consumer<WebApplication> onLoadConfiguration;
    protected Set<String> profiles;

    public WebApplication() {
    }

    public WebApplication(String[] args) {
        Map<String, String> map = parseCliArgs(args);
        processArgs(map::get);
        cliArgs = map;
    }

    public WebApplication setEnvironment(Environment environment) {
        checkIfStarted();
        this.environment = environment;
        return this;
    }

    public Environment getEnvironment() {
        return environment;
    }

    public Set<String> getProfiles() {
        return profiles;
    }

    public WebApplication addProfile(String profile) {
        checkIfStarted();
        profiles.add(profile);
        return this;
    }

    public WebApplication onSetup(Consumer<WebApplication> onSetup) {
        this.onSetup = onSetup;
        return this;
    }

    public WebApplication onLoadConfiguration(Consumer<WebApplication> onLoadConfiguration) {
        this.onLoadConfiguration = onLoadConfiguration;
        return this;
    }

    protected void onStart() {
        resourcesTools = createResourceTools();
        List<Class> classes = resourcesTools.getClasses();
        DependencyFactory.get().setClasses(classes);

        DependencyFactory.get().register(ResourceTools.class, new SingletonDependency<>(resourcesTools));
        DependencyFactory.get().register(UrlMapping.class, new SingletonDependency<>(getUrlMapping()));
        DependencyFactory.get().register(ControllerUrlMapping.class, new SingletonDependency<>(getUrlMapping()));

        MessageBundle bundle = initMessageSource();
        DependencyFactory.get().register(MessageSource.class, new SingletonDependency<>(bundle));
        DependencyFactory.get().register(MessageBundle.class, new SingletonDependency<>(bundle));

        loadConfig("Config.groovy");
        processListener(onLoadConfiguration);

        loadEnvironmentVariables(config);
        loadSystemProperties(config);
        cliArgs.forEach((key, value) -> putInto(config, key, value));

        readProfiles(config);
        setupApplication();
        processListener(onSetup);

        TagLib.findTags(classes);
        DependencyFactory.get().register(DecoratorLib.class, new SingletonDependency<>(new DecoratorLib(classes)));

        super.onStart();
        System.out.println("application has started");
        System.out.println("environment: " + environment);
        System.out.println("profiles: " + profiles);
    }
<commit_msg>applying profiles before environment variables<commit_after>package com.wizzardo.http.framework;

import com.wizzardo.epoll.IOThread;
import com.wizzardo.epoll.SslConfig;
import com.wizzardo.http.filter.AuthFilter;
import com.wizzardo.http.filter.BasicAuthFilter;
import com.wizzardo.http.filter.TokenFilter;
import com.wizzardo.http.request.Request;
import com.wizzardo.http.response.RangeResponseHelper;
import com.wizzardo.http.response.Response;
import com.wizzardo.tools.collections.CollectionTools;
import com.wizzardo.tools.collections.flow.Flow;
import com.wizzardo.tools.evaluation.Config;
import com.wizzardo.http.*;
import com.wizzardo.http.framework.di.DependencyFactory;
import com.wizzardo.http.framework.di.SingletonDependency;
import com.wizzardo.http.framework.message.MessageBundle;
import com.wizzardo.http.framework.message.MessageSource;
import com.wizzardo.http.framework.template.*;
import com.wizzardo.http.mapping.UrlMapping;
import com.wizzardo.tools.evaluation.EvalTools;
import com.wizzardo.tools.interfaces.Consumer;
import com.wizzardo.tools.misc.TextTools;
import com.wizzardo.tools.misc.Unchecked;

import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.BlockingQueue;
import java.util.jar.Manifest;

/**
 * Created by wizzardo on 28.04.15.
 */
public class WebApplication extends HttpServer<HttpConnection> {

    protected Environment environment;
    protected Config config;
    protected Map<String, String> cliArgs = Collections.emptyMap();
    protected ResourceTools resourcesTools;
    protected Consumer<WebApplication> onSetup;
    protected Consumer<WebApplication> onLoadConfiguration;
    protected Set<String> profiles;

    public WebApplication() {
    }

    public WebApplication(String[] args) {
        Map<String, String> map = parseCliArgs(args);
        processArgs(map::get);
        cliArgs = map;
    }

    public WebApplication setEnvironment(Environment environment) {
        checkIfStarted();
        this.environment = environment;
        return this;
    }

    public Environment getEnvironment() {
        return environment;
    }

    public Set<String> getProfiles() {
        return profiles;
    }

    public WebApplication addProfile(String profile) {
        checkIfStarted();
        profiles.add(profile);
        return this;
    }

    public WebApplication onSetup(Consumer<WebApplication> onSetup) {
        this.onSetup = onSetup;
        return this;
    }

    public WebApplication onLoadConfiguration(Consumer<WebApplication> onLoadConfiguration) {
        this.onLoadConfiguration = onLoadConfiguration;
        return this;
    }

    protected void onStart() {
        resourcesTools = createResourceTools();
        List<Class> classes = resourcesTools.getClasses();
        DependencyFactory.get().setClasses(classes);

        DependencyFactory.get().register(ResourceTools.class, new SingletonDependency<>(resourcesTools));
        DependencyFactory.get().register(UrlMapping.class, new SingletonDependency<>(getUrlMapping()));
        DependencyFactory.get().register(ControllerUrlMapping.class, new SingletonDependency<>(getUrlMapping()));

        MessageBundle bundle = initMessageSource();
        DependencyFactory.get().register(MessageSource.class, new SingletonDependency<>(bundle));
        DependencyFactory.get().register(MessageBundle.class, new SingletonDependency<>(bundle));

        loadConfig("Config.groovy");
        processListener(onLoadConfiguration);
        readProfiles(config);

        loadEnvironmentVariables(config);
        loadSystemProperties(config);
        cliArgs.forEach((key, value) -> putInto(config, key, value));

        setupApplication();
        processListener(onSetup);

        TagLib.findTags(classes);
        DependencyFactory.get().register(DecoratorLib.class, new SingletonDependency<>(new DecoratorLib(classes)));

        super.onStart();
        System.out.println("application has started");
        System.out.println("environment: " + environment);
        System.out.println("profiles: " + profiles);
    }

{'fraction_non_alphanumeric': 0.10539185719525615, 'fraction_numerical': 0.0014671720259200392, 'mean_word_length': 4.058750773036487, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 37, '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': '14075', 'n_tokens_mistral': 2234, 'n_tokens_neox': 2163, 'n_words': 396}