kratos0718 opened a new pull request, #317:
URL: https://github.com/apache/maven-source-plugin/pull/317
Fixes #307
### Problem
`AbstractSourceJarMojo.createArchiver()` identified the shared archive
resources directory by calling `String.endsWith` on the entire path:
```java
if (r.getDirectory().endsWith("maven-shared-archive-resources")) {
```
Because that tests the whole path string rather than the final segment, any
resource directory whose path merely *ends with* those characters also matches
— for example `/var/lib/tmp-maven-shared-archive-resources-extra`, or a
directory a user happens to name `my-maven-shared-archive-resources`. Its
contents would then be added to the source archive as though it were the
directory produced by maven-remote-resources-plugin.
### Fix
Compare the last path segment instead, using `Path.getFileName()`, and reuse
the already-resolved `Path` for `addDirectory` rather than parsing the same
string a second time. `getFileName()` returns `null` for a root path, so that
case is guarded.
The literal is lifted into a named constant with a short comment recording
that it is matched against the last segment, so the next reader does not have
to infer the intent.
### Testing
`mvn test` — 10 tests across `SourceJarMojoTest` and
`TestSourceJarMojoTest`, all passing. No behaviour change for correctly-named
directories; the difference only shows on paths that previously matched by
suffix.
- [x] I hereby declare this contribution to be licenced under the [Apache
License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
--
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]