<commit_before>/**
 * Created by <NAME> on 14/02/16.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package org.openmole.core.workspace

import java.io.File

import org.openmole.tool.file._
import org.apache.commons.configuration2._
import org.apache.commons.configuration2.builder._
import org.apache.commons.configuration2.builder.fluent._
import org.openmole.core.tools.io.FromString

import scala.concurrent.duration._

object ConfigurationLocation {

  def apply[T](group: String, name: String, default: ⇒ Option[T], cyphered: Boolean = false) =
    new ConfigurationLocation[T](group, name, default, cyphered)

}

class ConfigurationLocation[T](val group: String, val name: String, _default: ⇒ Option[T], val cyphered: Boolean) {
  def default = _default
  override def equals(obj: Any) = (group, name).equals(obj)
  override def hashCode = (group, name).hashCode
  override def toString = s"$group.$name"
}

class ConfigurationFile(val file: File) {

  val config = {
    val params = new Parameters

    val builder =
      new ReloadingFileBasedConfigurationBuilder[FileBasedConfiguration](classOf[PropertiesConfiguration])
        .configure(params.fileBased()
          .setFile(file))

    builder.setAutoSave(true)
    builder.getConfiguration
  }

  def value(group: String, name: String): Option[String] =
    Option(config.getString(s"$group.$name"))

  def setValue(group: String, name: String, value: String) =
    config.setProperty(s"$group.$name", value)

  def setCommentedValue(group: String, name: String, value: String) =
    config.setProperty(s"#$group.$name", value)

  def clear() = {
    file.content = ""
  }

}

object ConfigurationString {

  implicit def stringConfigurationString: ConfigurationString[String] =
    new ConfigurationString[String] {
      def toString(t: String): String = t<commit_msg>[Core] fix: reload config on file change.<commit_after>/**
 * Created by <NAME> on 14/02/16.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package org.openmole.core.workspace

import java.io.File

import org.openmole.tool.file._
import org.apache.commons.configuration2._
import org.apache.commons.configuration2.builder._
import org.apache.commons.configuration2.builder.fluent._
import org.openmole.core.tools.io.FromString

import scala.concurrent.duration._

object ConfigurationLocation {

  def apply[T](group: String, name: String, default: ⇒ Option[T], cyphered: Boolean = false) =
    new ConfigurationLocation[T](group, name, default, cyphered)

}

class ConfigurationLocation[T](val group: String, val name: String, _default: ⇒ Option[T], val cyphered: Boolean) {
  def default = _default
  override def equals(obj: Any) = (group, name).equals(obj)
  override def hashCode = (group, name).hashCode
  override def toString = s"$group.$name"
}

class ConfigurationFile(val file: File) {

  @transient lazy val builder = {
    val params = new Parameters
    val builder =
      new ReloadingFileBasedConfigurationBuilder[FileBasedConfiguration](classOf[PropertiesConfiguration])
        .configure(params.fileBased()
          .setFile(file))
    builder.setAutoSave(true)
    builder
  }

  def config = builder.getConfiguration

  def value(group: String, name: String): Option[String] =
    Option(config.getString(s"$group.$name"))

  def setValue(group: String, name: String, value: String) =
    config.setProperty(s"$group.$name", value)

  def setCommentedValue(group: String, name: String, value: String) =
    config.setProperty(s"#$group.$name", value)

  def clear() = {
    file.content = ""
  }

}

object ConfigurationString {

  implicit def stringConfigurationString: ConfigurationString[String] =
    new ConfigurationString[String] {
      def toString(t: String): String = t
{'fraction_non_alphanumeric': 0.10215161874120249, 'fraction_numerical': 0.004021717273275689, 'mean_word_length': 4.208376963350785, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2149876', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1394, 'n_words': 470}