diff --git a/src/main/java/io/gatling/mojo/EnterprisePackageMojo.java b/src/main/java/io/gatling/mojo/EnterprisePackageMojo.java index 36b59d2..ec75e71 100644 --- a/src/main/java/io/gatling/mojo/EnterprisePackageMojo.java +++ b/src/main/java/io/gatling/mojo/EnterprisePackageMojo.java @@ -75,13 +75,12 @@ public class EnterprisePackageMojo extends AbstractEnterpriseMojo { @Parameter(property = "gatling.excludes") private String[] excludes; - private Set nonGatlingDependencies(Artifact artifact) { - if (artifact == null) { - return Collections.emptySet(); - } - - return resolveTransitively(artifact).stream() - .filter(art -> !GATLING_GROUP_IDS.contains(art.getGroupId())) + private Set nonGatlingDependencies(List artifacts) { + return artifacts.stream() + .flatMap( + artifact -> + resolveTransitively(artifact).stream() + .filter(art -> !GATLING_GROUP_IDS.contains(art.getGroupId()))) .collect(Collectors.toSet()); } @@ -91,24 +90,28 @@ public void execute() throws MojoExecutionException, MojoFailureException { Set allDeps = mavenProject.getArtifacts(); - Artifact gatlingApp = - MojoUtils.findByGroupIdAndArtifactId(allDeps, GATLING_GROUP_ID, GATLING_MODULE_APP); - Artifact gatlingChartsHighcharts = - MojoUtils.findByGroupIdAndArtifactId( - allDeps, GATLING_HIGHCHARTS_GROUP_ID, GATLING_MODULE_HIGHCHARTS); - Artifact frontlineProbe = - MojoUtils.findByGroupIdAndArtifactId( - allDeps, GATLING_FRONTLINE_GROUP_ID, GATLING_FRONTLINE_MODULE_PROBE); + List depsWithFrontLineGroupId = + MojoUtils.findByGroupId(allDeps, GATLING_FRONTLINE_GROUP_ID); + if (!depsWithFrontLineGroupId.isEmpty()) { + throw new MojoExecutionException( + "Found a dependency with group id " + + GATLING_FRONTLINE_GROUP_ID + + " in projects dependencies"); + } - if (gatlingApp == null) { + List depsWithGatlingGroupId = MojoUtils.findByGroupId(allDeps, GATLING_GROUP_ID); + List depsWithGatlingHighchartsGroupId = + MojoUtils.findByGroupId(allDeps, GATLING_HIGHCHARTS_GROUP_ID); + if (depsWithGatlingGroupId.isEmpty()) { throw new MojoExecutionException( - "Couldn't find io.gatling:gatling-app in project dependencies"); + "Couldn't find any dependencies with group id " + + GATLING_GROUP_ID + + " in project dependencies"); } Set gatlingDependencies = new HashSet<>(); - gatlingDependencies.addAll(nonGatlingDependencies(gatlingApp)); - gatlingDependencies.addAll(nonGatlingDependencies(gatlingChartsHighcharts)); - gatlingDependencies.addAll(nonGatlingDependencies(frontlineProbe)); + gatlingDependencies.addAll(nonGatlingDependencies(depsWithGatlingGroupId)); + gatlingDependencies.addAll(nonGatlingDependencies(depsWithGatlingHighchartsGroupId)); Set filteredDeps = allDeps.stream() @@ -207,13 +210,17 @@ public void execute() throws MojoExecutionException, MojoFailureException { // generate fake manifest File manifest = new File(metaInfDir, "MANIFEST.MF"); + String gatlingVersion = + MojoUtils.findByGroupIdAndArtifactId(allDeps, GATLING_GROUP_ID, GATLING_MODULE_APP) + .getVersion(); + try (FileWriter fw = new FileWriter(manifest)) { fw.write("Manifest-Version: 1.0\n"); fw.write("Implementation-Title: " + mavenProject.getArtifactId() + "\n"); fw.write("Implementation-Version: " + mavenProject.getVersion() + "\n"); fw.write("Implementation-Vendor: " + mavenProject.getGroupId() + "\n"); fw.write("Specification-Vendor: GatlingCorp\n"); - fw.write("Gatling-Version: " + gatlingApp.getVersion() + "\n"); + fw.write("Gatling-Version: " + gatlingVersion + "\n"); fw.write("Gatling-Packager: maven" + "\n"); } catch (IOException e) { throw new MojoExecutionException("Failed to generate manifest", e); diff --git a/src/main/java/io/gatling/mojo/MojoConstants.java b/src/main/java/io/gatling/mojo/MojoConstants.java index e777fd7..25de90d 100644 --- a/src/main/java/io/gatling/mojo/MojoConstants.java +++ b/src/main/java/io/gatling/mojo/MojoConstants.java @@ -30,9 +30,7 @@ private MojoConstants() {} static final String GATLING_GROUP_ID = "io.gatling"; static final String GATLING_MODULE_APP = "gatling-app"; static final String GATLING_HIGHCHARTS_GROUP_ID = "io.gatling.highcharts"; - static final String GATLING_MODULE_HIGHCHARTS = "gatling-charts-highcharts"; static final String GATLING_FRONTLINE_GROUP_ID = "io.gatling.frontline"; - static final String GATLING_FRONTLINE_MODULE_PROBE = "frontline-probe"; static final Set GATLING_GROUP_IDS; static { diff --git a/src/main/java/io/gatling/mojo/MojoUtils.java b/src/main/java/io/gatling/mojo/MojoUtils.java index 3894788..57e14a4 100644 --- a/src/main/java/io/gatling/mojo/MojoUtils.java +++ b/src/main/java/io/gatling/mojo/MojoUtils.java @@ -32,6 +32,7 @@ import java.util.jar.Manifest; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; import org.apache.maven.artifact.Artifact; public final class MojoUtils { @@ -129,4 +130,10 @@ static Artifact findByGroupIdAndArtifactId( } return null; } + + static List findByGroupId(Set artifacts, String groupId) { + return artifacts.stream() + .filter(artifact -> artifact.getGroupId().equals(groupId)) + .collect(Collectors.toList()); + } }