<commit_before>/*
 * Copyright (C) 2016 University of Freiburg.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package rdfanalyzer.spark;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map.Entry;
import java.util.Properties;

import org.apache.spark.SparkConf;

/**
 * This class is used to (1) read configuration files and (2) set up the Spark
 * Configuration.
 */
public class Configuration {
	/**
	 * Private inner class which not gets initialized before it is called by the
	 * outer class.
	 */
	private static final class ConfigHolder {
		/*
		 * Initialization of class variables will only happen once. In addition
		 * the ClassLoader will implicitly synchronize this initialization.
		 */
		static final Properties PROPERTIES = getProperties();
		static final SparkConf SPARK_CONF = getSparkConf();

		/**
		 * Reads the config files and stores the properties.
		 * 
		 * @return
		 */
		static final Properties getProperties() {
			Properties properties = new Properties();

			try {
				ClassLoader classloader = Thread.currentThread().getContextClassLoader();
				InputStream is = classloader.getResourceAsStream("app.properties");

				properties.load(is);
			} catch (IOException e) {
				// TODO: This was removed on Cluster!
				e.printStackTrace();
			}

			return properties;
		}

		/**
		 * Sets up the new Spark Configuration.
		 * 
		 * @return new SparkConf
		 */
		static final SparkConf getSparkConf() {
			SparkConf sparkConf = new SparkConf();

			for (Entry<Object, Object> prop : PROPERTIES.entrySet()) {
				String key = (String) prop.getKey();
				String val = (String) prop.getValue();

				// Set all spark properties to the configuration.
				if (key.startsWith("spark")) {
					System.out.println(">>> Key='" + key + "' => Val='" + val + "'");
					sparkConf.set(key, val);
				}
			}

			return sparkConf;
		}
	}

	private Configuration() {
		// Block initialization of this class from other methods.
	}

	/**
	 * @return Properties object
	 */
	private static Properties props() {
		return ConfigHolder.PROPERTIES;<commit_msg>Logs reading of properties.<commit_after>/*
 * Copyright (C) 2016 University of Freiburg.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package rdfanalyzer.spark;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map.Entry;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.apache.spark.SparkConf;

/**
 * This class is used to (1) read configuration files and (2) set up the Spark
 * Configuration.
 */
public class Configuration {
	private final static Logger logger = Logger.getLogger(DeploymentListener.class);

	/**
	 * Private inner class which not gets initialized before it is called by the
	 * outer class.
	 */
	private static final class ConfigHolder {
		/*
		 * Initialization of class variables will only happen once. In addition
		 * the ClassLoader will implicitly synchronize this initialization.
		 */
		static final Properties PROPERTIES = getProperties();
		static final SparkConf SPARK_CONF = getSparkConf();

		/**
		 * Reads the config files and stores the properties.
		 * 
		 * @return
		 */
		static final Properties getProperties() {
			Properties properties = new Properties();

			try {
				ClassLoader classloader = Thread.currentThread().getContextClassLoader();
				InputStream is = classloader.getResourceAsStream("app.properties");

				properties.load(is);
			} catch (IOException e) {
				// TODO: This was removed on Cluster!
				e.printStackTrace();
			}

			return properties;
		}

		/**
		 * Sets up the new Spark Configuration.
		 * 
		 * @return new SparkConf
		 */
		static final SparkConf getSparkConf() {
			SparkConf sparkConf = new SparkConf();

			logger.info("Reading properties ...");
			for (Entry<Object, Object> prop : PROPERTIES.entrySet()) {
				String key = (String) prop.getKey();
				String val = (String) prop.getValue();

				// Set all spark properties to the configuration.
				if (key.startsWith("spark")) {
					logger.info("[" + key + "] => '" + val + "'");
					sparkConf.set(key, val);
				}
			}

			return sparkConf;
		}
	}

	private Configuration() {
		// Block initialization of this class from other methods.
	}

	/**
	 * @return Properties object
	 */
	private static Properties props() {
		return ConfigHolder.PROPERTIES;
{'fraction_non_alphanumeric': 0.10119492158327109, 'fraction_numerical': 0.00392083644510829, 'mean_word_length': 3.416323165704864, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '670408', 'n_tokens_mistral': 1653, 'n_tokens_neox': 1409, 'n_words': 544}