arturobernalg opened a new pull request, #1055:
URL: https://github.com/apache/maven-archetype/pull/1055

   When a module's own directory name contains a fileSet's `directory` value as 
a substring (e.g. a module `dir="openapi"` with a nested fileSet 
`directory="api"`), `DefaultFilesetArchetypeGenerator.getOutputFile()` corrupts 
the generated file's output path, or throws `StringIndexOutOfBoundsException` 
once the mismatch is large enough.
   
   The method strips the fileSet directory from the template path with 
`StringUtils.replaceOnce(template, directory, "")` -- a plain first-occurrence 
substring replace, not anchored to a path segment. For 
`template="openapi/api/index.ts"`, `directory="api"`, that finds and removes 
the `api` that's actually part of `openapi` (the module name) instead of the 
real `/api/` segment, then the subsequent 
`templateName.substring(moduleOffset.length())` either over-strips the path or 
throws once the corrupted string is shorter than `moduleOffset`.
   
   The fix computes the exact known prefix (`moduleOffset + "/" + directory`, 
the same basedir `ArchetypeFilesResolver.filterFiles()` already scans resources 
against) and strips that, instead of searching for `directory` as a bare 
substring anywhere in the path. `processTemplates()` also calls this method 
with `template == moduleOffset` (no file suffix at all) purely to pre-create an 
empty fileSet directory -- that case is handled explicitly too.
   
   Added a new `openapi` module to the existing `fileset-1.0` test archetype, 
with a nested fileSet `directory="api"`, and a new assertion in 
`testGenerateFileSetArchetype`. Confirmed fail-before: without the fix, 
generation throws `StringIndexOutOfBoundsException` at `getOutputFile` for this 
exact structure. Full `archetype-common` suite (30 tests), checkstyle and 
spotless pass locally with the fix.
   
   ---
   
   To make clear that you license your contribution under
   the [Apache License Version 2.0, January 
2004](https://www.apache.org/licenses/LICENSE-2.0)
   check one of the following:
   
   - [x] I hereby declare this contribution to be licensed under the [Apache 
License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
   - [x] I hereby declare that I have filed an [Apache Individual Contributor 
License Agreement](https://www.apache.org/licenses/icla.pdf).


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