diff --git a/pom.xml b/pom.xml index 42d82d7..ca88640 100644 --- a/pom.xml +++ b/pom.xml @@ -48,7 +48,7 @@ ${project.basedir} 5.10.2 1.9.1 - 0.0.1 + 0.0.3 1.6.13 3.12.0 diff --git a/src/main/java/io/gatling/mojo/AbstractGatlingMojo.java b/src/main/java/io/gatling/mojo/AbstractGatlingMojo.java index f25ff68..63a3e5b 100644 --- a/src/main/java/io/gatling/mojo/AbstractGatlingMojo.java +++ b/src/main/java/io/gatling/mojo/AbstractGatlingMojo.java @@ -75,13 +75,6 @@ protected List buildTestClasspath() throws Exception { return testClasspathElements; } - protected void addArg(List args, String flag, Object value) { - if (value != null) { - args.add("-" + flag); - args.add(value.toString()); - } - } - protected PluginLogger newPluginLogger() { return new PluginLogger() { @Override diff --git a/src/main/java/io/gatling/mojo/GatlingMojo.java b/src/main/java/io/gatling/mojo/GatlingMojo.java index f9f52d0..dc8aa7a 100644 --- a/src/main/java/io/gatling/mojo/GatlingMojo.java +++ b/src/main/java/io/gatling/mojo/GatlingMojo.java @@ -367,21 +367,24 @@ private List simulations() throws MojoFailureException { } private List 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 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 = @@ -389,15 +392,15 @@ private List gatlingArgs(String simulationClass) throws Exception { 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; diff --git a/src/main/java/io/gatling/mojo/RecorderMojo.java b/src/main/java/io/gatling/mojo/RecorderMojo.java index 756466c..f7fcc65 100644 --- a/src/main/java/io/gatling/mojo/RecorderMojo.java +++ b/src/main/java/io/gatling/mojo/RecorderMojo.java @@ -131,18 +131,18 @@ public void execute() throws MojoExecutionException, MojoFailureException { private List recorderArgs( Path simulationsDirectory, String format, Path testResourcesDirectory) throws Exception { - List 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 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; } }