diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 2cd4dd8..3f7acc7 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -11,7 +11,7 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up JDK21 + - name: Set up JDK11 uses: actions/setup-java@v4 with: distribution: 'zulu' diff --git a/README.md b/README.md index d739f8b..695ad96 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![Gatling Community](https://img.shields.io/badge/Community-Gatling-e28961?style=for-the-badge&logo=discourse)](https://community.gatling.io) > [!WARNING] -> The documentation now lives on the Gatling website and can be found [here](https://gatling.io/docs/current/extensions/gradle_plugin/). +> The documentation now lives on the Gatling website and can be found [here](https://docs.gatling.io/reference/integrations/build-tools/gradle-plugin/). ## Dev testing diff --git a/build.gradle b/build.gradle index 4c59ea2..ea02b4d 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ repositories { } dependencies { - implementation "io.gatling:gatling-enterprise-plugin-commons:1.9.6" + implementation "io.gatling:gatling-enterprise-plugin-commons:1.9.7" implementation "io.gatling:gatling-shared-cli:0.0.3" constraints { implementation('com.fasterxml.jackson.core:jackson-databind') { diff --git a/src/main/groovy/io/gatling/gradle/CommonLogMessage.groovy b/src/main/groovy/io/gatling/gradle/CommonLogMessage.groovy deleted file mode 100644 index 9d303c7..0000000 --- a/src/main/groovy/io/gatling/gradle/CommonLogMessage.groovy +++ /dev/null @@ -1,38 +0,0 @@ -package io.gatling.gradle - -import io.gatling.plugin.model.Simulation -import org.gradle.api.logging.Logger - - -final class CommonLogMessage { - - static void logSimulationCreated(Simulation simulation, Logger logger) { - logger.lifecycle("Created simulation named ${simulation.name} with ID '${simulation.id}'") - } - - static void logSimulationConfiguration(Logger logger, Simulation simulation, UUID simulationIdSetting, boolean waitForRunEndSetting) { - if (simulationIdSetting == null || !waitForRunEndSetting) { - StringBuilder builder = new StringBuilder("\n") - if (simulationIdSetting == null) { - builder.append( - """To start directly the same simulation, add the following Gradle configuration: - |gatling.enterprise.simulationId "${simulation.id}" - |gatling.enterprise.packageId "${simulation.pkgId}" - |Or specify -Dgatling.enterprissimulationId=${simulation.id} -Dgatling.enterprispackageId=${simulation.pkgId} - | - |""".stripMargin() - ) - } - if (!waitForRunEndSetting) { - builder.append( - """To wait for the end of the run when starting a simulation on Gatling Enterprise, add the following configuration: - |gatling.enterprise.waitForRunEnd true - |Or specify -Dgatling.enterprise.waitForRunEnd=true - | - |""".stripMargin()) - } - builder.append("See https://gatling.io/docs/gatling/reference/current/extensions/gradle_plugin/#working-with-gatling-enterprise-cloud for more information.\n") - logger.lifecycle(builder.toString()) - } - } -} diff --git a/src/main/groovy/io/gatling/gradle/GatlingEnterpriseStartTask.groovy b/src/main/groovy/io/gatling/gradle/GatlingEnterpriseStartTask.groovy index b3963ee..2df60b3 100644 --- a/src/main/groovy/io/gatling/gradle/GatlingEnterpriseStartTask.groovy +++ b/src/main/groovy/io/gatling/gradle/GatlingEnterpriseStartTask.groovy @@ -22,7 +22,7 @@ class GatlingEnterpriseStartTask extends GatlingEnterpriseDeployTask { final RunSummary runSummary = enterprisePlugin.startSimulation(gatling.enterprise.simulationName, deploymentInfo, runComment) logger.lifecycle(""" |Simulation successfully started. - |Reports are available at: ${gatling.enterprise.url.toExternalForm() + runSummary.reportsPath} + |Reports are available at: ${gatling.enterprise.webAppUrl.toExternalForm() + runSummary.reportsPath} |""".stripMargin()) if (waitForRunEnd) { SimulationEndResult finishedRun = enterprisePlugin.waitForRunEnd(runSummary) diff --git a/src/main/groovy/io/gatling/gradle/GatlingEnterpriseUploadTask.groovy b/src/main/groovy/io/gatling/gradle/GatlingEnterpriseUploadTask.groovy index 7f6b591..b6d7309 100644 --- a/src/main/groovy/io/gatling/gradle/GatlingEnterpriseUploadTask.groovy +++ b/src/main/groovy/io/gatling/gradle/GatlingEnterpriseUploadTask.groovy @@ -1,6 +1,7 @@ package io.gatling.gradle import io.gatling.plugin.BatchEnterprisePlugin +import io.gatling.plugin.ConfigurationConstants import org.gradle.api.DefaultTask import org.gradle.api.InvalidUserDataException import org.gradle.api.tasks.CacheableTask @@ -23,9 +24,9 @@ class GatlingEnterpriseUploadTask extends DefaultTask { logger.lifecycle("Uploading package belonging to the simulation " + gatling.enterprise.simulationId) enterprisePlugin.uploadPackageWithSimulationId(gatling.enterprise.simulationId, inputs.files.singleFile) } else { - throw new InvalidUserDataException("You need to either configure gatling.enterprise.packageId (or pass it with '-Dgatling.enterprise.packageId=') " + - "or gatling.enterprise.simulation (or pass it with '-Dgatling.enterprise.simulationId=') to upload a package." + - "Please see https://gatling.io/docs/gatling/reference/current/extensions/gradle_plugin/#working-with-gatling-enterprise-cloud for more information.") + throw new InvalidUserDataException("You need to either configure gatling.enterprise.packageId (or pass it with '-D${ConfigurationConstants.UploadOptions.PackageId.SYS_PROP}=') " + + "or gatling.enterprise.simulationId (or pass it with '-D${ConfigurationConstants.UploadOptions.SimulationId.SYS_PROP}=') to upload a package." + + "Please see https://docs.gatling.io/reference/integrations/build-tools/gradle-plugin/#running-your-simulations-on-gatling-enterprise-cloud for more information.") } } } diff --git a/src/main/groovy/io/gatling/gradle/GatlingPluginExtension.groovy b/src/main/groovy/io/gatling/gradle/GatlingPluginExtension.groovy index 394e726..f2e10b7 100644 --- a/src/main/groovy/io/gatling/gradle/GatlingPluginExtension.groovy +++ b/src/main/groovy/io/gatling/gradle/GatlingPluginExtension.groovy @@ -1,6 +1,7 @@ package io.gatling.gradle import io.gatling.plugin.BatchEnterprisePlugin +import io.gatling.plugin.ConfigurationConstants import io.gatling.plugin.EnterprisePlugin import io.gatling.plugin.EnterprisePluginProvider import io.gatling.plugin.GatlingConstants @@ -18,30 +19,19 @@ import org.gradle.api.tasks.Optional class GatlingPluginExtension { static final Map DEFAULT_SYSTEM_PROPS = [:] - private static final String API_TOKEN_PROPERTY = "gatling.enterprise.apiToken" - private static final String API_TOKEN_ENV = "GATLING_ENTERPRISE_API_TOKEN" - private static final String SIMULATION_ID_PROPERTY = "gatling.enterprise.simulationId" - private static final String SIMULATION_NAME_PROPERTY = "gatling.enterprise.simulationName" - private static final String RUN_TITLE_PROPERTY = "gatling.enterprise.runTitle" - private static final String RUN_DESCRIPTION_PROPERTY = "gatling.enterprise.runDescription" - private static final String PACKAGE_ID_PROPERTY = "gatling.enterprise.packageId" - private static final String BATCH_MODE_PROPERTY = "gatling.enterprise.batchMode" - private static final String WAIT_FOR_RUN_END_PROPERTY = "gatling.enterprise.waitForRunEnd" - private static final String CONTROL_PLANE_URL = "gatling.enterprise.controlPlaneUrl" - private static final String PACKAGE_DESCRIPTOR_FILENAME_PROPERTY = "gatling.enterprise.packageDescriptorFilename" - private static final String PLUGIN_NAME = "gatling-gradle-plugin" final static class Enterprise { private String apiToken - private UUID simulationId + private String simulationId private String simulationName private String runTitle private String runDescription - private UUID packageId - private URL url = URI.create("https://cloud.gatling.io").toURL() + private String packageId + private String apiUrl + private String webAppUrl private boolean batchMode private boolean waitForRunEnd - private URL controlPlaneUrl + private String controlPlaneUrl private String packageDescriptorFilename def setBatchMode(boolean batchMode) { @@ -52,16 +42,24 @@ class GatlingPluginExtension { setBatchMode(batchMode) } - def setUrl(String url) { - this.url = URI.create(url).toURL() + def setApiUrl(String apiUrl) { + this.apiUrl = apiUrl } - def url(String url) { - setUrl(url) + def apiUrl(String apiUrl) { + setApiUrl(apiUrl) + } + + def setWebAppUrl(String webAppUrl) { + this.webAppUrl = webAppUrl + } + + def webAppUrl(String webAppUrl) { + setWebAppUrl(webAppUrl) } def setSimulationId(String simulationId) { - this.simulationId = UUID.fromString(simulationId) + this.simulationId = simulationId } def simulationId(String simulationId) { @@ -69,7 +67,7 @@ class GatlingPluginExtension { } def setSimulationName(String simulationName) { - this.simulationId = UUID.fromString(simulationName) + this.simulationName = simulationName } def simulationName(String simulationName) { @@ -93,7 +91,7 @@ class GatlingPluginExtension { } def setPackageId(String packageId) { - this.packageId = UUID.fromString(packageId) + this.packageId = packageId } def packageId(String packageId) { @@ -117,7 +115,7 @@ class GatlingPluginExtension { } def setControlPlaneUrl(String controlPlaneUrl) { - this.controlPlaneUrl = new URL(controlPlaneUrl) + this.controlPlaneUrl = controlPlaneUrl } def controlPlaneUrl(String controlPlaneUrl) { @@ -135,68 +133,74 @@ class GatlingPluginExtension { @Input @Optional UUID getSimulationId() { - def sysProp = System.getProperty(SIMULATION_ID_PROPERTY) - return simulationId ?: (sysProp ? UUID.fromString(sysProp) : null) + var str = ConfigurationConstants.UploadOptions.SimulationId.valueOf(simulationId) + str ? UUID.fromString(str) : null } @Input @Optional String getSimulationName() { - simulationName ?: System.getProperty(SIMULATION_NAME_PROPERTY) ?: null + ConfigurationConstants.StartOptions.SimulationName.valueOf(simulationName) } @Input @Optional String getRunTitle() { - runTitle ?: System.getProperty(RUN_TITLE_PROPERTY) ?: null + ConfigurationConstants.StartOptions.RunTitle.valueOf(runTitle) } String getRunDescription() { - runDescription ?: System.getProperty(RUN_DESCRIPTION_PROPERTY) ?: null + ConfigurationConstants.StartOptions.RunTitle.valueOf(runDescription) } @Input @Optional String getApiToken() { - apiToken ?: System.getProperty(API_TOKEN_PROPERTY, System.getenv(API_TOKEN_ENV)) + ConfigurationConstants.ApiToken.valueOf(apiToken) } @Input @Optional UUID getPackageId() { - def sysProp = System.getProperty(PACKAGE_ID_PROPERTY) - return packageId ?: (sysProp ? UUID.fromString(sysProp) : null) + var str = ConfigurationConstants.UploadOptions.PackageId.valueOf(packageId) + str ? UUID.fromString(str) : null + } + + @Input + @Optional + URL getApiUrl() { + new URI(ConfigurationConstants.ApiUrl.valueOf(apiUrl)).toURL() } @Input @Optional - URL getUrl() { - return url + URL getWebAppUrl() { + new URI(ConfigurationConstants.WebAppUrl.valueOf(webAppUrl)).toURL() } @Input @Optional boolean getBatchMode() { - return batchMode || Boolean.getBoolean(BATCH_MODE_PROPERTY) + ConfigurationConstants.BatchMode.valueOf(batchMode) } @Input @Optional boolean getWaitForRunEnd() { - return waitForRunEnd || Boolean.getBoolean(WAIT_FOR_RUN_END_PROPERTY) + ConfigurationConstants.StartOptions.WaitForRunEnd.valueOf(waitForRunEnd) } @Input @Optional URL getControlPlaneUrl() { - def sysProp = System.getProperty(CONTROL_PLANE_URL) - return controlPlaneUrl ?: (sysProp ? new URL(sysProp) : null) + var str = ConfigurationConstants.ControlPlaneUrl.valueOf(controlPlaneUrl) + str ? new URI(str).toURL() : null } @Input @Optional String getPackageDescriptorFilename() { - packageDescriptorFilename ?: System.getProperty(PACKAGE_DESCRIPTOR_FILENAME_PROPERTY) ?: null + ConfigurationConstants.DeployOptions.PackageDescriptionFilename.valueOf(packageDescriptorFilename) } BatchEnterprisePlugin initBatchEnterprisePlugin(Logger logger) { @@ -220,19 +224,20 @@ class GatlingPluginExtension { } private PluginConfiguration getPluginConfiguration(Logger logger, boolean forceBatchMode) { - final apiToken = getApiToken() + final apiToken = ConfigurationConstants.ApiToken.value() if (!apiToken) { throw new InvalidUserDataException(""" |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 wil the role 'Configure'. - |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 Gradle settings, e.g.: + |See https://docs.gatling.io/reference/execute/cloud/admin/api-tokens/ and create a token wil the role 'Configure'. + |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 Gradle settings, e.g.: |gatling.enterprise.apiToken \"MY_API_TOKEN_VALUE\" """.stripMargin() ) } return new PluginConfiguration( - getUrl(), + getApiUrl(), + getWebAppUrl(), apiToken, getControlPlaneUrl(), BuildTool.GRADLE, diff --git a/src/main/groovy/io/gatling/gradle/UnsupportedClientPluginException.java b/src/main/groovy/io/gatling/gradle/UnsupportedClientPluginException.java index 542780b..7d15448 100644 --- a/src/main/groovy/io/gatling/gradle/UnsupportedClientPluginException.java +++ b/src/main/groovy/io/gatling/gradle/UnsupportedClientPluginException.java @@ -3,7 +3,7 @@ public final class UnsupportedClientPluginException extends Exception { public UnsupportedClientPluginException(Exception cause) { super( - "Please update the Gatling Gradle plugin to the latest version for compatibility with Gatling Enterprise. See https://gatling.io/docs/gatling/reference/current/extensions/gradle_plugin/ for more information about this plugin.", + "Please update the Gatling Gradle plugin to the latest version for compatibility with Gatling Enterprise. See https://docs.gatling.io/reference/integrations/build-tools/gradle-plugin/ for more information about this plugin.", cause ); }