<commit_before>package org.ambraproject.wombat.config;

import com.google.common.base.Strings;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
import org.ambraproject.rhombat.cache.Cache;
import org.ambraproject.rhombat.cache.MemcacheClient;
import org.ambraproject.rhombat.cache.NullCache;
import org.ambraproject.rhombat.gson.Iso8601DateAdapter;
import org.ambraproject.wombat.service.remote.ArticleApi;
import org.ambraproject.wombat.service.remote.ArticleApiImpl;
import org.ambraproject.wombat.service.remote.CachedRemoteService;
import org.ambraproject.wombat.service.remote.JsonService;
import org.ambraproject.wombat.service.remote.ReaderService;
import org.ambraproject.wombat.service.remote.SolrSearchApi;
import org.ambraproject.wombat.service.remote.SolrSearchApiImpl;
import org.ambraproject.wombat.service.remote.StreamService;
import org.ambraproject.wombat.service.remote.UserApi;
import org.ambraproject.wombat.service.remote.UserApiImpl;
import org.ambraproject.wombat.util.JodaTimeLocalDateAdapter;
import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.yaml.snakeyaml.Yaml;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.util.Date;

@Configuration
public class RootConfiguration {

  @Bean
  public Yaml yaml() {
    return new Yaml();
  }

  private static final String CONFIG_DIR_PROPERTY_NAME = "wombat.configDir";
  private static final String CONFIG_DIR_ENVIRONMENT_NAME = "WOMBAT_CONFIG_DIR";

  private static File getConfigDirectory(ApplicationContext applicationContext) {
    String property = System.getProperty(CONFIG_DIR_PROPERTY_NAME);
    if (!Strings.isNullOrEmpty(property)) {
      return new File(property);
    }

    String environmentVar = System.getenv(CONFIG_DIR_ENVIRONMENT_NAME);
    if (!Strings.isNullOrEmpty(environmentVar)) {
      return new File(environmentVar);
    }

    String applicationName = applicationContext.getApplicationName();
    if (!Strings.isNullOrEmpty(applicationName)) {
      return new File("/etc", applicationName);
    }

    throw new RuntimeException("Config directory not found. " +
        "(If application name is empty, " + CONFIG_DIR_PROPERTY_NAME + " or "
        + CONFIG_DIR_ENVIRONMENT_NAME + " must be defined.)");
  }

  @Bean
  public RuntimeConfiguration runtimeConfiguration(ApplicationContext applicationContext,
                                                   Yaml yaml)
      throws IOException {
    File configDirectory = getConfigDirectory(applicationContext);
    File configPath = new File(configDirectory, "wombat.yaml");
    if (!configPath.exists()) {
      throw new RuntimeConfigurationException(configPath.getPath() + " not found");
    }<commit_msg>DPRO-2792: Always require config directory by system property<commit_after>package org.ambraproject.wombat.config;

import com.google.common.base.Strings;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
import org.ambraproject.rhombat.cache.Cache;
import org.ambraproject.rhombat.cache.MemcacheClient;
import org.ambraproject.rhombat.cache.NullCache;
import org.ambraproject.rhombat.gson.Iso8601DateAdapter;
import org.ambraproject.wombat.service.remote.ArticleApi;
import org.ambraproject.wombat.service.remote.ArticleApiImpl;
import org.ambraproject.wombat.service.remote.CachedRemoteService;
import org.ambraproject.wombat.service.remote.JsonService;
import org.ambraproject.wombat.service.remote.ReaderService;
import org.ambraproject.wombat.service.remote.SolrSearchApi;
import org.ambraproject.wombat.service.remote.SolrSearchApiImpl;
import org.ambraproject.wombat.service.remote.StreamService;
import org.ambraproject.wombat.service.remote.UserApi;
import org.ambraproject.wombat.service.remote.UserApiImpl;
import org.ambraproject.wombat.util.JodaTimeLocalDateAdapter;
import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.yaml.snakeyaml.Yaml;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.util.Date;

@Configuration
public class RootConfiguration {

  @Bean
  public Yaml yaml() {
    return new Yaml();
  }

  private static final String CONFIG_DIR_PROPERTY_NAME = "wombat.configDir";

  private static File getConfigDirectory() {
    String property = System.getProperty(CONFIG_DIR_PROPERTY_NAME);
    if (!Strings.isNullOrEmpty(property)) {
      return new File(property);
    } else {
      throw new RuntimeException("Config directory not found. " + CONFIG_DIR_PROPERTY_NAME + " must be defined.");
    }
  }

  @Bean
  public RuntimeConfiguration runtimeConfiguration(Yaml yaml)
      throws IOException {
    File configDirectory = getConfigDirectory();
    File configPath = new File(configDirectory, "wombat.yaml");
    if (!configPath.exists()) {
      throw new RuntimeConfigurationException(configPath.getPath() + " not found");
    }
{'fraction_non_alphanumeric': 0.09524670160853063, 'fraction_numerical': 0.0021688053497198627, 'mean_word_length': 5.288636363636364, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7250264', 'n_tokens_mistral': 1679, 'n_tokens_neox': 1624, 'n_words': 293}