Apply the computed include patterns when finding other resources - #1023
Open
adityaanikam wants to merge 1 commit into
Open
Apply the computed include patterns when finding other resources#1023adityaanikam wants to merge 1 commit into
adityaanikam wants to merge 1 commit into
Conversation
findOtherResources(int, List, List, String) builds a list of include patterns from the directories of the given sources files and then never hands it to the scanner. ListScanner treats a missing include set as "**", so the scan returned every file the language excludes did not remove, regardless of the directories the caller scoped it to. Pass the patterns to the scanner, as the sibling overloads already do. ListScanner has a List<String> overload of setIncludes, so the list is used as built. An empty sources list still leaves the include set unset and so keeps the previous behaviour. The caller removes the returned files from the list it is still working through, so the level three pass was consuming files that belong to the level two and root passes, and those files were then grouped by a level that does not match their depth.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The four-argument
DefaultArchetypeFilesResolver.findOtherResources(int level, List<String> files, List<String> sourcesFiles, String languages)builds a list of include patterns from the directories of the given sources files, and then never applies it:ListScanner.scantreats a missing include set as"**":So the scan returns every file that the language excludes do not remove, and
sourcesFileshas no effect on the result. Both sibling methods that build include patterns, the three-argumentfindOtherResourcesandfindOtherSources, do callsetIncludes.The fix passes the list to the scanner.
ListScanneralready has asetIncludes(List<String>)overload, so no joining is needed. An empty sources list produces an empty pattern array, which leaves the include field unset and preserves today's behaviour, so the change is inert in that case.Additional context and related issues
Fixes #1020.
On the effect:
FilesetArchetypeCreator.createArchetypecalls this once, and removes the returned files from the list it is still working through. The level three pass therefore consumed everything left, starving the laterfindOtherResources(2, ...)andfindOtherResources(0, ...)passes. Files such aspom.xmlwere handed tocreateFileSets(..., 3, ...)and grouped by a level that does not match their depth, instead of falling to the root pass.No files are dropped by the change: whatever the level three pass no longer claims is still matched by the root pass, whose include pattern is
**.Testing
Added
testFindOtherResourcesIsRestrictedToTheSourcesDirectoriesto the existingTestDefaultArchetypeFilesResolver. With a sources file ofsrc/main/java/App.javaat level 3, the derived directory issrc/main, sosrc/test/resources/AppTest.propertiesandpom.xmlmust not be returned.Verified with a negative control: reverting only
DefaultArchetypeFilesResolver.javaand keeping the test makes it fail with all three files returned, which is the abandoned-includes behaviour:mvn verify -pl archetype-common -ampasses with 30 tests. The integration tests pass as well, 32 builds with no failures, which includes thecreate-from-projectprojects and both roundtrips that exercise this code path.Your pull request should address just one issue, without pulling in other changes.
Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
Each commit in the pull request should have a meaningful subject line and body.
Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
Run
mvn verifyto make sure basic checks pass.You have run the integration tests successfully (
mvn -Prun-its verify).I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004