Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor options #113

Merged
merged 5 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
38 changes: 0 additions & 38 deletions src/main/groovy/io/gatling/gradle/CommonLogMessage.groovy

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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=<PACKAGE_ID>') " +
"or gatling.enterprise.simulation (or pass it with '-Dgatling.enterprise.simulationId=<SIMULATION_ID>') 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}=<PACKAGE_ID>') " +
"or gatling.enterprise.simulationId (or pass it with '-D${ConfigurationConstants.UploadOptions.SimulationId.SYS_PROP}=<SIMULATION_ID>') 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.")
}
}
}
Expand Down
91 changes: 48 additions & 43 deletions src/main/groovy/io/gatling/gradle/GatlingPluginExtension.groovy
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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) {
Expand All @@ -52,24 +42,32 @@ 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) {
setSimulationId(simulationId)
}

def setSimulationName(String simulationName) {
this.simulationId = UUID.fromString(simulationName)
this.simulationName = simulationName
}

def simulationName(String simulationName) {
Expand All @@ -93,7 +91,7 @@ class GatlingPluginExtension {
}

def setPackageId(String packageId) {
this.packageId = UUID.fromString(packageId)
this.packageId = packageId
}

def packageId(String packageId) {
Expand All @@ -117,7 +115,7 @@ class GatlingPluginExtension {
}

def setControlPlaneUrl(String controlPlaneUrl) {
this.controlPlaneUrl = new URL(controlPlaneUrl)
this.controlPlaneUrl = controlPlaneUrl
}

def controlPlaneUrl(String controlPlaneUrl) {
Expand All @@ -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) {
Expand All @@ -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=<API_TOKEN>' 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}=<API_TOKEN>' 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
Expand Down
Loading