slachiewicz commented on PR #268:
URL: 
https://github.com/apache/maven-source-plugin/pull/268#issuecomment-5183277815

   Both of these are on the closed #315 branch, still pushed at 
`slachiewicz:maven-4.0.0-rc-6` in case it is easier to cherry-pick than to 
retype. The hunks:
   
   **1. Test harness imports.** In `SourceJarMojoTest`, `TestSourceJarMojoTest` 
and `AbstractSourcePluginTestCase`:
   
   ```diff
   -import org.apache.maven.api.plugin.testing.Basedir;
   -import org.apache.maven.api.plugin.testing.InjectMojo;
   -import org.apache.maven.api.plugin.testing.MojoParameter;
   -import org.apache.maven.api.plugin.testing.MojoTest;
   -import org.apache.maven.api.plugin.testing.stubs.SessionMock;
   -import org.apache.maven.internal.impl.InternalSession;
   -import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir;
   +import org.apache.maven.testing.plugin.Basedir;
   +import org.apache.maven.testing.plugin.InjectMojo;
   +import org.apache.maven.testing.plugin.MojoParameter;
   +import org.apache.maven.testing.plugin.MojoTest;
   +import org.apache.maven.testing.plugin.stubs.SessionMock;
   +import org.apache.maven.impl.InternalSession;
   +import static org.apache.maven.testing.plugin.MojoExtension.getBasedir;
   ```
   
   Note `InternalSession` moved too — `org.apache.maven.internal.impl` → 
`org.apache.maven.impl`.
   
   This is worth doing exactly as @ascheman says. Before relocating, the tests 
ran and reported green while `@Basedir` and `@MojoParameter` were being 
ignored, and the run produced `target/null-sources.jar`. It fails silently, not 
loudly.
   
   **2. Resources through `ProjectManager`.** In `SourceJarNoForkMojo` and 
`TestSourceJarNoForkMojo` (`ProjectScope.TEST` in the latter):
   
   ```diff
   -    protected List<Resource> getResources(Project p) {
   -        return projectManager.getResources(p, ProjectScope.MAIN);
   +    protected List<SourceRoot> getResources(Project p) {
   +        return projectManager
   +                .getEnabledSourceRoots(p, ProjectScope.MAIN, 
Language.RESOURCES)
   +                .toList();
   ```
   
   with `getSources` alongside it:
   
   ```diff
   -        return projectManager.getCompileSourceRoots(p, ProjectScope.MAIN);
   +        return projectManager
   +                .getEnabledSourceRoots(p, ProjectScope.MAIN, 
Language.JAVA_FAMILY)
   +                .map(SourceRoot::directory)
   +                .toList();
   ```
   
   That changes the abstract `getResources` return type to `List<SourceRoot>`, 
so `AbstractSourceJarMojo.archiveProjectContent` maps `resource.getDirectory()` 
→ `directory()`, `getIncludes()` → `includes()`, `getExcludes()` → 
`excludes()`, and `getTargetPath()` → 
`targetPath().map(Path::toString).orElse(null)`.
   
   Three things found while doing it that are easy to trip over:
   
   - `SourceRoot.stringFiltering()` exists, but the beta-3 code never read 
`Resource.getFiltering()`. Wiring it up now would change which file contents 
land in the jar, so I deliberately left it alone.
   - `getEnabledSourceRoots` filters on `enabled()` and requires a `Language`, 
neither of which the old call did. `JAVA_FAMILY` matches what 
maven-compiler-plugin uses.
   - `createArchiver()` finds `maven-shared-archive-resources` through 
`project.getBuild().getResources()`, which has the same deprecation. Moving it 
to the `ProjectManager` view also picks up roots registered at runtime by 
maven-remote-resources-plugin — the very plugin that produces those resources. 
No test covers that path either way.
   
   Also worth folding in while these files are open: `src/site/site.xml` still 
carries a `<skin>` workaround whose own comment says it is only needed on 
beta-3 and is redundant from rc-5 onwards.
   


-- 
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