diff --git a/build.sbt b/build.sbt index 00ff45d..57026e2 100644 --- a/build.sbt +++ b/build.sbt @@ -9,7 +9,7 @@ githubPath := "gatling/gatling-sbt-plugin" libraryDependencies ++= Seq( "org.scalatest" %% "scalatest" % "3.2.19" % Test, - "io.gatling" % "gatling-enterprise-plugin-commons" % "1.9.6", + "io.gatling" % "gatling-enterprise-plugin-commons" % "1.9.7", "io.gatling" % "gatling-shared-cli" % "0.0.3" ) diff --git a/src/main/scala/io/gatling/sbt/GatlingKeys.scala b/src/main/scala/io/gatling/sbt/GatlingKeys.scala index 0b278d0..3d80e73 100644 --- a/src/main/scala/io/gatling/sbt/GatlingKeys.scala +++ b/src/main/scala/io/gatling/sbt/GatlingKeys.scala @@ -16,6 +16,7 @@ package io.gatling.sbt +import _root_.io.gatling.plugin.ConfigurationConstants import _root_.io.gatling.sbt.settings.BaseSettings import sbt._ @@ -41,19 +42,21 @@ object GatlingKeys { val enterpriseUrl = settingKey[URL]("URL of Gatling Enterprise.") val enterpriseApiToken = - settingKey[String](s"""API Token on Gatling Enterprise. - |Prefer configuration using `GATLING_ENTERPRISE_API_TOKEN` environment variable, or `gatling.enterprise.apiToken` system property. - |$documentationReference. - |""".stripMargin) + settingKey[String]( + s"""API Token on Gatling Enterprise. + |Prefer configuration using `${ConfigurationConstants.ApiToken.ENV_VAR}` environment variable, or `${ConfigurationConstants.ApiToken.SYS_PROP}` system property. + |$documentationReference. + |""".stripMargin + ) val enterprisePackageId = settingKey[String](s"""Package ID on Gatling Enterprise (used by `enterpriseUpload` task). - |${systemPropertyDescription("gatling.enterprise.packageId")}. + |${systemPropertyDescription(ConfigurationConstants.UploadOptions.PackageId.SYS_PROP)}. |$documentationReference. |""".stripMargin) val enterpriseSimulationId = settingKey[String](s"""Simulation ID on Gatling Enterprise. Used by `enterprisePackage` if `enterprisePackageId` isn't configured. - |${systemPropertyDescription("gatling.enterprise.simulationId")}. + |${systemPropertyDescription(ConfigurationConstants.UploadOptions.SimulationId.SYS_PROP)}. |$documentationReference. |""".stripMargin) @@ -66,7 +69,7 @@ object GatlingKeys { val waitForRunEnd = settingKey[Boolean]( s"""Wait for the result after starting the simulation on Gatling Enterprise, and complete with an error if the simulation ends with any error status. - |${systemPropertyDescription("gatling.enterprise.waitForRunEnd")}. + |${systemPropertyDescription(ConfigurationConstants.StartOptions.WaitForRunEnd.SYS_PROP)}. |$documentationReference. |""".stripMargin ) diff --git a/src/main/scala/io/gatling/sbt/settings/gatling/EnterprisePluginTask.scala b/src/main/scala/io/gatling/sbt/settings/gatling/EnterprisePluginTask.scala index a959c84..1ea3368 100644 --- a/src/main/scala/io/gatling/sbt/settings/gatling/EnterprisePluginTask.scala +++ b/src/main/scala/io/gatling/sbt/settings/gatling/EnterprisePluginTask.scala @@ -16,7 +16,7 @@ package io.gatling.sbt.settings.gatling -import io.gatling.plugin.{ BatchEnterprisePlugin, EnterprisePlugin, EnterprisePluginProvider, PluginConfiguration } +import io.gatling.plugin.{ BatchEnterprisePlugin, ConfigurationConstants, EnterprisePlugin, EnterprisePluginProvider, PluginConfiguration } import io.gatling.plugin.model.BuildTool import io.gatling.sbt.BuildInfo import io.gatling.sbt.GatlingKeys._ @@ -47,7 +47,7 @@ object EnterprisePluginTask { if (apiToken.isEmpty) { logger.error( s"""An API token is required to call the Gatling Enterprise server; see https://gatling.io/docs/enterprise/cloud/reference/admin/api_tokens/ and create a token with the role 'Configurer'. - |You can then set your API token's value in the environment variable GATLING_ENTERPRISE_API_TOKEN, pass it with -Dgatling.enterprise.apiToken=, or add the configuration to your SBT settings, e.g.: + |You can then set your API token's value in the environment variable ${ConfigurationConstants.ApiToken.ENV_VAR}, pass it with -D${ConfigurationConstants.ApiToken.SYS_PROP}=, or add the configuration to your SBT settings, e.g.: |${config.id} / enterpriseApiToken := MY_API_TOKEN_VALUE""".stripMargin ) throw ErrorAlreadyLoggedException diff --git a/src/main/scala/io/gatling/sbt/settings/gatling/EnterpriseSettings.scala b/src/main/scala/io/gatling/sbt/settings/gatling/EnterpriseSettings.scala index 5eda5ac..35e3038 100644 --- a/src/main/scala/io/gatling/sbt/settings/gatling/EnterpriseSettings.scala +++ b/src/main/scala/io/gatling/sbt/settings/gatling/EnterpriseSettings.scala @@ -16,9 +16,9 @@ package io.gatling.sbt.settings.gatling -import java.{ lang => jl } import java.net.URI +import io.gatling.plugin.ConfigurationConstants import io.gatling.sbt.GatlingKeys._ import sbt._ @@ -52,18 +52,17 @@ object EnterpriseSettings { val taskStart = new TaskEnterpriseStart(config, taskDeploy) Seq( - config / enterpriseUrl := URI.create("https://cloud.gatling.io").toURL, + config / enterpriseUrl := new URI(ConfigurationConstants.Url.value()).toURL, config / enterprisePackage := taskPackage.buildEnterprisePackage.value, config / enterpriseUpload := taskUpload.uploadEnterprisePackage.value, config / enterpriseDeploy := taskDeploy.enterpriseDeploy.evaluated, config / enterpriseStart := taskStart.enterpriseSimulationStart.evaluated, - config / enterprisePackageId := sys.props.get("gatling.enterprise.packageId").getOrElse(""), - config / enterpriseSimulationId := sys.props.get("gatling.enterprise.simulationId").getOrElse(""), - config / enterpriseControlPlaneUrl := sys.props - .get("gatling.enterprise.controlPlaneUrl") - .map(configString => URI.create(configString).toURL), - config / waitForRunEnd := jl.Boolean.getBoolean("gatling.enterprise.waitForRunEnd"), - config / enterpriseApiToken := sys.props.get("gatling.enterprise.apiToken").orElse(sys.env.get("GATLING_ENTERPRISE_API_TOKEN")).getOrElse(""), + config / enterprisePackageId := Option(ConfigurationConstants.UploadOptions.PackageId.value()).getOrElse(""), + config / enterpriseSimulationId := Option(ConfigurationConstants.UploadOptions.SimulationId.value()).getOrElse(""), + config / enterpriseControlPlaneUrl := Option(ConfigurationConstants.ControlPlaneUrl.value()) + .map(configString => new URI(configString).toURL), + config / waitForRunEnd := ConfigurationConstants.StartOptions.WaitForRunEnd.value(), + config / enterpriseApiToken := Option(ConfigurationConstants.ApiToken.value()).getOrElse(""), config / packageBin := (config / enterprisePackage).value // If we directly use config / enterprisePackage for publishing, classifiers (-tests or -it) are not correctly handled. ) } diff --git a/src/main/scala/io/gatling/sbt/settings/gatling/RecoverEnterprisePluginException.scala b/src/main/scala/io/gatling/sbt/settings/gatling/RecoverEnterprisePluginException.scala index 6618067..a3a8802 100644 --- a/src/main/scala/io/gatling/sbt/settings/gatling/RecoverEnterprisePluginException.scala +++ b/src/main/scala/io/gatling/sbt/settings/gatling/RecoverEnterprisePluginException.scala @@ -18,6 +18,7 @@ package io.gatling.sbt.settings.gatling import scala.util.{ Failure, Try } +import io.gatling.plugin.ConfigurationConstants import io.gatling.plugin.exceptions._ import sbt.Configuration @@ -44,7 +45,7 @@ class RecoverEnterprisePluginException(config: Configuration) { protected def logSimulationConfiguration(logger: ManagedLogger, waitForRunEndSetting: Boolean): Unit = if (!waitForRunEndSetting) { logger.info( - s"""To wait for the end of the run when starting a simulation on Gatling Enterprise, specify -Dgatling.enterprise.waitForRunEnd=true, or add the configuration to your SBT settings, e.g.: + s"""To wait for the end of the run when starting a simulation on Gatling Enterprise, specify -D${ConfigurationConstants.StartOptions.WaitForRunEnd.SYS_PROP}=true, or add the configuration to your SBT settings, e.g.: |${config.id} / waitForRunEnd := true |""".stripMargin ) diff --git a/src/main/scala/io/gatling/sbt/settings/gatling/TaskEnterpriseUpload.scala b/src/main/scala/io/gatling/sbt/settings/gatling/TaskEnterpriseUpload.scala index 3f3c15d..91299d3 100644 --- a/src/main/scala/io/gatling/sbt/settings/gatling/TaskEnterpriseUpload.scala +++ b/src/main/scala/io/gatling/sbt/settings/gatling/TaskEnterpriseUpload.scala @@ -20,6 +20,7 @@ import java.util.UUID import scala.util.Try +import io.gatling.plugin.ConfigurationConstants import io.gatling.sbt.GatlingKeys._ import io.gatling.sbt.settings.gatling.EnterpriseUtils._ @@ -38,7 +39,7 @@ class TaskEnterpriseUpload(config: Configuration, enterprisePackage: TaskEnterpr if (settingPackageId.isEmpty && settingSimulationId.isEmpty) { logger.error( s"""A package ID is required to upload a package on Gatling Enterprise; see https://gatling.io/docs/enterprise/cloud/reference/user/package_conf/ , create a package and copy its ID. - |You can then set your package ID value by passing it with -Dgatling.enterprise.packageId=, or add the configuration to your SBT settings, e.g.: + |You can then set your package ID value by passing it with -D${ConfigurationConstants.UploadOptions.PackageId.SYS_PROP}=, or add the configuration to your SBT settings, e.g.: |${config.id} / enterprisePackageId := MY_PACKAGE_ID | |Alternately, if you don't configure a packageId, you can configure the simulationId of an existing simulation on Gatling Enterprise: your code will be uploaded to the package used by that simulation.