MaxonT opened a new pull request, #3659:
URL: https://github.com/apache/maven-surefire/pull/3659

   Hi, this pull request replaces the Maven 3 deprecated API calls in Surefire 
that issue #3644 mentions, and I'm happy to change anything that doesn't fit 
your plans.
   
   ### Description
   
   `AbstractSurefireMojo.getProjectTestArtifacts()` returned 
`project.getTestArtifacts()`, which is deprecated since Maven 3. In maven-core 
3.9.16 (the `mavenVersion` this repo builds against) that method builds a list 
from `getArtifacts()` and keeps the artifacts whose 
`getArtifactHandler().isAddedToClasspath()` is true, in the iteration order of 
`getArtifacts()`; I read that from the bytecode with `javap`. This change does 
the same two steps inline: `project.getArtifacts().stream()`, the same 
`isAddedToClasspath()` filter, `Collectors.toList()`. A plain `getArtifacts()` 
would also hand `pom` type artifacts to `dependenciesToScan`, which is why the 
filter stays.
   
   The call site is `scanDependencies()`, which runs inside the surefire and 
failsafe goals. Both declare `requiresDependencyResolution = 
ResolutionScope.TEST`, so the artifacts are resolved when it runs, and the old 
and new code read the same `getArtifacts()` at the same moment. 
`getArtifacts()` returns an empty set when nothing is resolved, never null, so 
there is no new null case. Only this one method changes; no public signature, 
parameter or output changes.
   
   This covers only the `getTestArtifacts()` part of #3644. I left 
`DefaultJavaToolChain` in `AbstractSurefireMojo` and in 
`AbstractSurefireMojoToolchainsTest`, and the `ArtifactRepository` and 
`ArtifactRepositoryPolicy` uses in `SurefireReportMavenProjectStub`, for 
separate PRs. The toolchain code checks `instanceof` on that class, so I did 
not want to mix it into this change.
   
   ### Validation
   
   `mvn -B -pl maven-surefire-common -am verify 
-Dtest='!CommandChannelDecoderTest' -Dsurefire.failIfNoSpecifiedTests=false` on 
this head: exit 0, 933 tests run in `maven-surefire-common`, 0 failures, 0 
errors, 8 skipped. The same command on an unchanged copy of master gives the 
same result, exit 0 and the same counts. Spotless and Checkstyle ran in both 
builds and did not change the diff.
   
   Without the `-Dtest` exclusion, the build stops earlier in `surefire-booter` 
on both this head and unchanged master, with 
`CommandChannelDecoderTest.testBinaryCommandStream` failing at line 307. I did 
not look into why it fails on my machine, so `maven-surefire-common` is only 
reached with that one test excluded. The existing unit tests override 
`getProjectTestArtifacts()`, so none of them runs the new body, and I did not 
add a test for it. I did not run the integration tests (`-Prun-its`). The build 
ran with JDK 23.0.2 and Maven 3.9.9 on macOS.
   
   Part of #3644. Part of apache/maven#14157.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to