Skip to content

Commit

Permalink
chore: upgrade gatling-shared-cli 0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
slandelle committed Apr 26, 2024
1 parent d5eac2f commit aa7ae7b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 41 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<header.basedir>${project.basedir}</header.basedir>
<junit.version>5.10.2</junit.version>
<gatling-enterprise-plugin-commons.version>1.9.1</gatling-enterprise-plugin-commons.version>
<gatling-shared-cli.version>0.0.1</gatling-shared-cli.version>
<gatling-shared-cli.version>0.0.3</gatling-shared-cli.version>

<nexus-staging-maven-plugin.version>1.6.13</nexus-staging-maven-plugin.version>
<maven-plugin-plugin.version>3.12.0</maven-plugin-plugin.version>
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/io/gatling/mojo/AbstractGatlingMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,6 @@ protected List<String> buildTestClasspath() throws Exception {
return testClasspathElements;
}

protected void addArg(List<String> args, String flag, Object value) {
if (value != null) {
args.add("-" + flag);
args.add(value.toString());
}
}

protected PluginLogger newPluginLogger() {
return new PluginLogger() {
@Override
Expand Down
43 changes: 23 additions & 20 deletions src/main/java/io/gatling/mojo/GatlingMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,37 +367,40 @@ private List<String> simulations() throws MojoFailureException {
}

private List<String> gatlingArgs(String simulationClass) throws Exception {
// encode runDescription in Base64 because it could contain characters that would break the
// command
String encodedRunDescription =
runDescription != null
? Base64.getEncoder().encodeToString(runDescription.getBytes(StandardCharsets.UTF_8))
: null;

List<String> args = new ArrayList<>();
addArg(args, GatlingCliOptions.Simulation.abbr, simulationClass);
addArg(args, GatlingCliOptions.ReportsOnly.abbr, reportsOnly);
addArg(args, GatlingCliOptions.ResultsFolder.abbr, resultsFolder.getCanonicalPath());
addArg(args, GatlingCliOptions.RunDescription.abbr, encodedRunDescription);

if (simulationClass != null) {
args.addAll(List.of(GatlingCliOptions.Simulation.shortOption(), simulationClass));
}
args.addAll(
List.of(GatlingCliOptions.ResultsFolder.shortOption(), resultsFolder.getCanonicalPath()));
if (reportsOnly != null) {
args.addAll(List.of(GatlingCliOptions.ReportsOnly.shortOption(), reportsOnly));
}
if (runDescription != null) {
// encode runDescription in Base64 because it could contain characters that would break the
// command
String encodedRunDescription =
Base64.getEncoder().encodeToString(runDescription.getBytes(StandardCharsets.UTF_8));
args.addAll(List.of(GatlingCliOptions.RunDescription.shortOption(), encodedRunDescription));
}
if (noReports) {
args.add("-" + GatlingCliOptions.NoReports);
args.add(GatlingCliOptions.NoReports.shortOption());
}

String[] gatlingVersion =
MojoUtils.findByGroupIdAndArtifactId(
mavenProject.getArtifacts(), GATLING_GROUP_ID, GATLING_MODULE_APP)
.getVersion()
.split("\\.");
int gatlingMajorVersion = Integer.valueOf(gatlingVersion[0]);
int gatlingMinorVersion = Integer.valueOf(gatlingVersion[1]);
int gatlingMajorVersion = Integer.parseInt(gatlingVersion[0]);
int gatlingMinorVersion = Integer.parseInt(gatlingVersion[1]);

if ((gatlingMajorVersion == 3 && gatlingMinorVersion >= 8) || gatlingMajorVersion > 4) {
addArg(args, GatlingCliOptions.Launcher.abbr, "maven");
addArg(
args,
GatlingCliOptions.BuildToolVersion.abbr,
MavenProject.class.getPackage().getImplementationVersion());
args.addAll(List.of(GatlingCliOptions.Launcher.shortOption(), "maven"));
args.addAll(
List.of(
GatlingCliOptions.BuildToolVersion.shortOption(),
MavenProject.class.getPackage().getImplementationVersion()));
}

return args;
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/io/gatling/mojo/RecorderMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,18 @@ public void execute() throws MojoExecutionException, MojoFailureException {

private List<String> recorderArgs(
Path simulationsDirectory, String format, Path testResourcesDirectory) throws Exception {
List<String> arguments = new ArrayList<>();
addArg(
arguments,
RecorderCliOptions.SimulationsFolder.abbr,
simulationsDirectory.toFile().getCanonicalPath());
addArg(arguments, RecorderCliOptions.Format.abbr, format);
addArg(
arguments,
RecorderCliOptions.ResourcesFolder.abbr,
testResourcesDirectory.toFile().getCanonicalPath());
addArg(arguments, RecorderCliOptions.Package.abbr, packageName);
addArg(arguments, RecorderCliOptions.ClassName.abbr, className);
return arguments;
List<String> args = new ArrayList<>();
args.addAll(
List.of(
RecorderCliOptions.SimulationsFolder.shortName,
simulationsDirectory.toFile().getCanonicalPath()));
args.addAll(List.of(RecorderCliOptions.Format.shortName, format));
args.addAll(
List.of(
RecorderCliOptions.ResourcesFolder.shortName,
testResourcesDirectory.toFile().getCanonicalPath()));
args.addAll(List.of(RecorderCliOptions.Package.shortName, packageName));
args.addAll(List.of(RecorderCliOptions.ClassName.shortName, className));
return args;
}
}

0 comments on commit aa7ae7b

Please sign in to comment.