2222import org .apache .maven .project .MavenProject ;
2323import org .codehaus .plexus .util .xml .Xpp3Dom ;
2424import org .eclipse .aether .artifact .DefaultArtifact ;
25+ import org .eclipse .aether .graph .DefaultDependencyNode ;
2526import org .eclipse .aether .resolution .ArtifactRequest ;
2627import org .eclipse .aether .resolution .ArtifactResolutionException ;
2728import org .eclipse .aether .resolution .ArtifactResult ;
29+ import org .eclipse .aether .resolution .DependencyRequest ;
30+ import org .eclipse .aether .resolution .DependencyResolutionException ;
31+ import org .eclipse .aether .resolution .DependencyResult ;
2832import org .pitest .classinfo .ClassName ;
2933import org .pitest .classpath .DirectoryClassPathRoot ;
3034import org .pitest .functional .FCollection ;
@@ -86,7 +90,9 @@ public ReportOptions convert() {
8690
8791 classPath .addAll (this .mojo .getAdditionalClasspathElements ());
8892
89- autoAddJUnitPlatform (classPath );
93+ autoAddJUnitPlatformLauncher (classPath );
94+ autoAddJUnitPlatformEngine (classPath );
95+ autoAddJupiterEngine (classPath );
9096 removeExcludedDependencies (classPath );
9197
9298 addCrossModuleDirsToClasspath (classPath );
@@ -125,13 +131,22 @@ private void addCrossModuleDirsToClasspath(List<String> classPath) {
125131 *
126132 * @param classPath classpath to modify
127133 */
128- private void autoAddJUnitPlatform (List <String > classPath ) {
134+ private void autoAddJUnitPlatformLauncher (List <String > classPath ) {
135+ autoAddJUnitPlatformArtifact (classPath , "junit-platform-launcher" );
136+ }
137+
138+ private void autoAddJUnitPlatformEngine (List <String > classPath ) {
139+ autoAddJUnitPlatformArtifact (classPath , "junit-platform-engine" );
140+ }
141+
142+
143+ private void autoAddJUnitPlatformArtifact (List <String > classPath , String artifactId ) {
129144 List <Artifact > junitDependencies = this .mojo .getProject ().getArtifacts ().stream ()
130145 .filter (a -> a .getGroupId ().equals ("org.junit.platform" ))
131146 .collect (Collectors .toList ());
132147
133- // If the launcher has been manually added to the dependencies, there is nothing to do
134- if (junitDependencies .stream ().anyMatch (a -> a .getArtifactId ().equals ("junit-platform-launcher" ))) {
148+ // If the artifact has been manually added to the dependencies, there is nothing to do
149+ if (junitDependencies .stream ().anyMatch (a -> a .getArtifactId ().equals (artifactId ))) {
135150 return ;
136151 }
137152
@@ -144,24 +159,67 @@ private void autoAddJUnitPlatform(List<String> classPath) {
144159 // Look for platform engine or platform commons on classpath
145160 Artifact toMatch = maybeJUnitPlatform .get ();
146161
147- // Assume that platform launcher has been released with same version number as engine and commons
148- DefaultArtifact platformLauncher = new DefaultArtifact (toMatch .getGroupId (), "junit-platform-launcher" , "jar" ,
162+ // Assume that artifact has been released with same version number as engine and commons
163+ DefaultArtifact platformLauncher = new DefaultArtifact (toMatch .getGroupId (), artifactId , "jar" ,
149164 toMatch .getVersion ());
150165
166+ addArtifact (classPath , platformLauncher );
167+ }
168+
169+ private void autoAddJupiterEngine (List <String > classPath ) {
170+ List <Artifact > junitDependencies = this .mojo .getProject ().getArtifacts ().stream ()
171+ .filter (a -> a .getGroupId ().equals ("org.junit.jupiter" ))
172+ .collect (Collectors .toList ());
173+
174+ // If the engine has been manually added to the dependencies, there is nothing to do
175+ if (junitDependencies .stream ().anyMatch (a -> a .getArtifactId ().equals ("junit-jupiter-engine" ))) {
176+ return ;
177+ }
178+
179+ Optional <Artifact > maybeApi = this .mojo .getProject ().getArtifacts ().stream ()
180+ .filter (a -> a .getArtifactId ().equals ("junit-jupiter-api" ))
181+ .findFirst ();
182+
183+ if (maybeApi .isEmpty ()) {
184+ return ;
185+ }
186+
187+ // Look for platform engine or platform commons on classpath
188+ Artifact toMatch = maybeApi .get ();
189+
190+ // Assume that engine has been released with same version number as api
191+ DefaultArtifact platformLauncher = new DefaultArtifact (toMatch .getGroupId (), "junit-jupiter-engine" , "jar" ,
192+ toMatch .getVersion ());
193+
194+ addArtifact (classPath , platformLauncher );
195+
196+ }
197+
198+ private void addArtifact (List <String > classPath , DefaultArtifact platformLauncher ) {
151199 try {
200+
152201 ArtifactRequest r = new ArtifactRequest ();
153202 r .setArtifact (platformLauncher );
154-
203+
155204 r .setRepositories (this .mojo .getProject ().getRemotePluginRepositories ());
156205 ArtifactResult resolved = this .mojo .repositorySystem ().resolveArtifact (mojo .session ().getRepositorySession (), r );
157206
158207 this .log .info ("Auto adding " + resolved + " to classpath." );
159208 classPath .add (resolved .getArtifact ().getFile ().getAbsolutePath ());
160- } catch (ArtifactResolutionException e ) {
209+
210+ // get any transitive dependencies,
211+ // although this doesn't seem to be neccesary for current releases of junit
212+ DependencyRequest dependencyRequest = new DependencyRequest (new DefaultDependencyNode (platformLauncher ), null );
213+ DependencyResult transitive = this .mojo .repositorySystem ().resolveDependencies (mojo .session ().getRepositorySession (), dependencyRequest );
214+ for (ArtifactResult result : transitive .getArtifactResults ()) {
215+ this .log .info ("Auto adding " + result + " to classpath." );
216+ classPath .add (result .getArtifact ().getFile ().getAbsolutePath ());
217+ }
218+
219+ } catch (DependencyResolutionException | ArtifactResolutionException e ) {
161220 this .log .error ("Could not resolve " + platformLauncher );
162221 throw new RuntimeException (e );
163222 }
164-
165223 }
166224
167225 private static Optional <Artifact > findJUnitArtifact (List <Artifact > junitDependencies ) {
@@ -460,8 +518,9 @@ private Collection<String> findOccupiedTestPackages() {
460518 }
461519
462520 private Collection <Artifact > filteredDependencies () {
463- return FCollection .filter (this .mojo .getPluginArtifactMap ().values (),
464- this .dependencyFilter );
521+ return this .mojo .getPluginArtifactMap ().values ().stream ()
522+ .filter (this .dependencyFilter )
523+ .collect (Collectors .toList ());
465524 }
466525
467526 private Collection <String > determineMutators () {
0 commit comments