<commit_before>/**
 * Copyright 2011-2012 eBusiness Information, Groupe Excilys (www.excilys.com)
 *
 * 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 com.excilys.ebi.gatling.app
import java.io.{ StringWriter, PrintWriter }
import java.lang.System.currentTimeMillis

import scala.tools.nsc.interpreter.AbstractFileClassLoader
import scala.tools.nsc.io.Path.{ string2path, jfile2path }
import scala.tools.nsc.io.{ PlainFile, Path, File, Directory }
import scala.tools.nsc.reporters.ConsoleReporter
import scala.tools.nsc.{ Settings, Global }

import org.joda.time.DateTime.now

import com.excilys.ebi.gatling.app.UserSelection.DEFAULT_RUN_ID
import com.excilys.ebi.gatling.charts.config.ChartsFiles.activeSessionsFile
import com.excilys.ebi.gatling.charts.report.ReportsGenerator
import com.excilys.ebi.gatling.core.config.{ GatlingFiles, GatlingConfiguration }
import com.excilys.ebi.gatling.core.result.message.RunRecord
import com.excilys.ebi.gatling.core.runner.Runner
import com.excilys.ebi.gatling.core.scenario.configuration.Simulation
import com.excilys.ebi.gatling.core.util.IOHelper.use
import com.twitter.io.TempDirectory

import grizzled.slf4j.Logging
import scopt.OptionParser

/**
 * Object containing entry point of application
 */
object Gatling extends Logging {

	/**
	 * Entry point of Application
	 *
	 * @param args Arguments of the main method
	 */
	def main(args: Array[String]) {

		val options: Options = Options()

		val cliOptsParser = new OptionParser("gatling") {
			opt("nr", "no-reports", "Runs simulation but does not generate reports", { options.noReports = true })
			opt("ro", "reports-only", "<folderName>", "Generates the reports for the simulation in <folderName>", { v: String => options.reportsOnlyFolder = Some(v) })
			opt("cf", "config-file", "<fileName>", "Uses <fileName> as the configuration file", { v: String => options.configFileName = Some(v) })
			opt("df", "data-folder", "<folderName>", "Uses <folderName> as the folder where feeders are stored", { v: String => options.dataFolder = Some(v) })
			opt("rf", "results-folder", "<folderName>", "Uses <folderName> as the folder where results are stored", { v: String => options.resultsFolder = Some(v) })
			opt("bf", "request-bodies-folder", "<folderName>", "Uses <folderName> as the folder where request bodies are stored", { v: String => options.requestBodiesFolder = Some(v) })
			opt("sf", "simulations-folder", "<folderName>", "Uses <folderName> to discover simulations that could be run", { v: String => options.simulationSourcesFolder = Some(v) })
			opt("s", "simulations", "<simulationNames>", "Runs the <simulationNames> sequentially", { v: String => options.simulations = Some(v.split(",").toList) })
		}

		if (cliOptsParser.parse(args))
			start(options)

		// if arguments are incorrect, usage message is displayed
	}

	def start(options: Options) = new Gatling(options: Options).launch
}

class Gatling(options: Options) extends Logging {

	lazy val tempDir = Directory(TempDirectory.create(true))

	// Initializes configuration
	GatlingConfiguration.setUp(options.configFileName, options.dataFolder, options.requestBodiesFolder, options.resultsFolder, options.simulationSourcesFolder)

	def launch {
		val runUuids = options.reportsOnlyFolder match {
			case Some(reportsOnlyFolder) => List(reportsOnlyFolder)
			case None =>
				val classes = options.simulationBinariesFolder match {

					case Some(simulationBinariesFolder) =>
						// expect simulations to have been pre-compiled (ex: IDE)
						val classNames = getClassNamesFromBinariesDirectory(Directory(simulationBinariesFolder))
						loadSimulationClasses(classNames)

					case None =>
						val scalaFiles = collectFiles(GatlingFiles.simulationsFolder, "scala")
						val classloader = compile(scalaFiles)
						val classNames = getClassNamesFromBinariesDirectory(tempDir)
						loadSimulationClasses(classNames, classloader)
				}

				val userSelection = options.simulations match {<commit_msg>Rename Gatling.launch back into apply<commit_after>/**
 * Copyright 2011-2012 eBusiness Information, Groupe Excilys (www.excilys.com)
 *
 * 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 com.excilys.ebi.gatling.app
import java.io.{ StringWriter, PrintWriter }
import java.lang.System.currentTimeMillis

import scala.tools.nsc.interpreter.AbstractFileClassLoader
import scala.tools.nsc.io.Path.{ string2path, jfile2path }
import scala.tools.nsc.io.{ PlainFile, Path, File, Directory }
import scala.tools.nsc.reporters.ConsoleReporter
import scala.tools.nsc.{ Settings, Global }

import org.joda.time.DateTime.now

import com.excilys.ebi.gatling.app.UserSelection.DEFAULT_RUN_ID
import com.excilys.ebi.gatling.charts.config.ChartsFiles.activeSessionsFile
import com.excilys.ebi.gatling.charts.report.ReportsGenerator
import com.excilys.ebi.gatling.core.config.{ GatlingFiles, GatlingConfiguration }
import com.excilys.ebi.gatling.core.result.message.RunRecord
import com.excilys.ebi.gatling.core.runner.Runner
import com.excilys.ebi.gatling.core.scenario.configuration.Simulation
import com.excilys.ebi.gatling.core.util.IOHelper.use
import com.twitter.io.TempDirectory

import grizzled.slf4j.Logging
import scopt.OptionParser

/**
 * Object containing entry point of application
 */
object Gatling extends Logging {

	/**
	 * Entry point of Application
	 *
	 * @param args Arguments of the main method
	 */
	def main(args: Array[String]) {

		val options: Options = Options()

		val cliOptsParser = new OptionParser("gatling") {
			opt("nr", "no-reports", "Runs simulation but does not generate reports", { options.noReports = true })
			opt("ro", "reports-only", "<folderName>", "Generates the reports for the simulation in <folderName>", { v: String => options.reportsOnlyFolder = Some(v) })
			opt("cf", "config-file", "<fileName>", "Uses <fileName> as the configuration file", { v: String => options.configFileName = Some(v) })
			opt("df", "data-folder", "<folderName>", "Uses <folderName> as the folder where feeders are stored", { v: String => options.dataFolder = Some(v) })
			opt("rf", "results-folder", "<folderName>", "Uses <folderName> as the folder where results are stored", { v: String => options.resultsFolder = Some(v) })
			opt("bf", "request-bodies-folder", "<folderName>", "Uses <folderName> as the folder where request bodies are stored", { v: String => options.requestBodiesFolder = Some(v) })
			opt("sf", "simulations-folder", "<folderName>", "Uses <folderName> to discover simulations that could be run", { v: String => options.simulationSourcesFolder = Some(v) })
			opt("s", "simulations", "<simulationNames>", "Runs the <simulationNames> sequentially", { v: String => options.simulations = Some(v.split(",").toList) })
		}

		if (cliOptsParser.parse(args))
			start(options)

		// if arguments are incorrect, usage message is displayed
	}

	def start(options: Options) = new Gatling(options: Options)
}

class Gatling(options: Options) extends Logging {

	lazy val tempDir = Directory(TempDirectory.create(true))

	// Initializes configuration
	GatlingConfiguration.setUp(options.configFileName, options.dataFolder, options.requestBodiesFolder, options.resultsFolder, options.simulationSourcesFolder)

	def apply {
		val runUuids = options.reportsOnlyFolder match {
			case Some(reportsOnlyFolder) => List(reportsOnlyFolder)
			case None =>
				val classes = options.simulationBinariesFolder match {

					case Some(simulationBinariesFolder) =>
						// expect simulations to have been pre-compiled (ex: IDE)
						val classNames = getClassNamesFromBinariesDirectory(Directory(simulationBinariesFolder))
						loadSimulationClasses(classNames)

					case None =>
						val scalaFiles = collectFiles(GatlingFiles.simulationsFolder, "scala")
						val classloader = compile(scalaFiles)
						val classNames = getClassNamesFromBinariesDirectory(tempDir)
						loadSimulationClasses(classNames, classloader)
				}

				val userSelection = options.simulations match {
{'fraction_non_alphanumeric': 0.11318656882366022, 'fraction_numerical': 0.00333555703802535, 'mean_word_length': 4.875244937949053, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '6272854', 'n_tokens_mistral': 2881, 'n_tokens_neox': 2640, 'n_words': 734}