<commit_before>package org.openmole.core

import org.openmole.core.authentication._
import org.openmole.core.db._
import org.openmole.core.event._
import org.openmole.core.fileservice._
import org.openmole.core.preference._
import org.openmole.core.replication._
import org.openmole.core.serializer._
import org.openmole.core.threadprovider._
import org.openmole.core.workspace._
import org.openmole.tool.crypto._
import org.openmole.tool.random._
import org.openmole.tool.file._

package object services {

  object Services {

    def withServices[T](workspace: File, password: String)(f: Services ⇒ T) = {
      val services = Services(workspace, password)
      try f(services)
      finally dispose(services)
    }

    def preference(workspace: Workspace) = Preference(workspace.persistentDir)
    def authenticationStore(workspace: Workspace) = AuthenticationStore(workspace.persistentDir)

    def apply(workspace: File, password: String) = {
      implicit val ws = Workspace(workspace)
      implicit val cypher = Cypher(password)
      implicit val preference = Services.preference(ws)
      implicit val newFile = NewFile(workspace)
      implicit val seeder = Seeder()
      implicit val serializerService = SerializerService()
      implicit val threadProvider = ThreadProvider()
      implicit val replicaCatalog = ReplicaCatalog(ws)
      implicit val authenticationStore = Services.authenticationStore(ws)
      implicit val fileService = FileService()
      implicit val randomProvider = RandomProvider(seeder.newRNG)
      implicit val eventDispatcher = EventDispatcher()
      new ServicesContainer()
    }

    def dispose(services: Services) = {
      util.Try(services.workspace.tmpDir.recursiveDelete)
      util.Try(services.threadProvider.stop())
    }

    def resetPassword(implicit authenticationStore: AuthenticationStore, preference: Preference) = {
      authenticationStore.delete()
      preference.clear()
    }

  }
<commit_msg>[Core] enh: add copy method for services.<commit_after>package org.openmole.core

import org.openmole.core.authentication._
import org.openmole.core.db._
import org.openmole.core.event._
import org.openmole.core.fileservice._
import org.openmole.core.preference._
import org.openmole.core.replication._
import org.openmole.core.serializer._
import org.openmole.core.threadprovider._
import org.openmole.core.workspace._
import org.openmole.tool.crypto._
import org.openmole.tool.random._
import org.openmole.tool.file._

package object services {

  object Services {

    def withServices[T](workspace: File, password: String)(f: Services ⇒ T) = {
      val services = Services(workspace, password)
      try f(services)
      finally dispose(services)
    }

    def preference(workspace: Workspace) = Preference(workspace.persistentDir)
    def authenticationStore(workspace: Workspace) = AuthenticationStore(workspace.persistentDir)

    def apply(workspace: File, password: String) = {
      implicit val ws = Workspace(workspace)
      implicit val cypher = Cypher(password)
      implicit val preference = Services.preference(ws)
      implicit val newFile = NewFile(workspace)
      implicit val seeder = Seeder()
      implicit val serializerService = SerializerService()
      implicit val threadProvider = ThreadProvider()
      implicit val replicaCatalog = ReplicaCatalog(ws)
      implicit val authenticationStore = Services.authenticationStore(ws)
      implicit val fileService = FileService()
      implicit val randomProvider = RandomProvider(seeder.newRNG)
      implicit val eventDispatcher = EventDispatcher()
      new ServicesContainer()
    }

    def dispose(services: Services) = {
      util.Try(services.workspace.tmpDir.recursiveDelete)
      util.Try(services.threadProvider.stop())
    }

    def resetPassword(implicit authenticationStore: AuthenticationStore, preference: Preference) = {
      authenticationStore.delete()
      preference.clear()
    }

    def copy(services: Services)(
      workspace:           Workspace           = services.workspace,
      preference:          Preference          = services.preference,
      cypher:              Cypher              = services.cypher,
      threadProvider:      ThreadProvider      = services.threadProvider,
      seeder:              Seeder              = services.seeder,
      replicaCatalog:      ReplicaCatalog      = services.replicaCatalog,
      newFile:             NewFile             = services.newFile,
      authenticationStore: AuthenticationStore = services.authenticationStore,
      serializerService:   SerializerService   = services.serializerService,
      fileService:         FileService         = services.fileService,
      randomProvider:      RandomProvider      = services.randomProvider,
      eventDispatcher:     EventDispatcher     = services.eventDispatcher
    ) =
      new ServicesContainer()(
        workspace = workspace,
        preference = preference,
        cypher = cypher,
        threadProvider = threadProvider,
        seeder = seeder,
        replicaCatalog = replicaCatalog,
        newFile = newFile,
        authenticationStore = authenticationStore,
        serializerService = serializerService,
        fileService = fileService,
        randomProvider = randomProvider,
        eventDispatcher = eventDispatcher
      )

  }

{'fraction_non_alphanumeric': 0.08092918696140877, 'fraction_numerical': 0.0, 'mean_word_length': 3.2609736632083, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6894344', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1439, 'n_words': 317}