Support excluding files matched by .gitignore across nohttp - #66
Draft
sbrannen wants to merge 1 commit into
Draft
Conversation
Prior to this commit, the only way to exclude files matched by a project's .gitignore from nohttp was the approach introduced in Spring Framework's buildSrc CheckstyleConventions plugin (spring-projects/spring-framework@0acdf80): translating .gitignore lines into Ant-glob patterns on the Gradle plugin's `source` FileTree. That approach is Gradle-specific, cannot express negated patterns, and would have to be reimplemented from scratch for nohttp-cli and nohttp-checkstyle. Furthermore, there is no dedicated nohttp Maven plugin: Maven users configure `maven-checkstyle-plugin` directly against `NoHttpCheck` and are left hand-listing exclusions (see samples/nohttp-maven-sample/pom.xml). To address that, this commit introduces a GitIgnoreFileFilter in the nohttp core module, which parses a single root .gitignore file into a set of regular-expression-based rules -- rather than Ant-glob strings -- and exposes a Predicate<File> that matches paths against those rules. This supports git semantics that the Ant-glob translation could not, in particular that later lines -- including negated patterns -- take precedence over earlier ones, and that a directory-only pattern (trailing `/`) only ever matches an actual directory rather than a same-named file. Note, however, that nested .gitignore files in subdirectories are not supported. This filter is then wired into all three consumers, enabled by default with a flag to disable it: - nohttp-cli: a new `-g` flag on ReplaceFilesRunner, applied via DirScanner's existing excludeDirs()/excludeFiles() predicates. - nohttp-checkstyle: new useGitIgnore/baseDir properties on NoHttpCheck, consulted at the top of processFiltered(). Since NoHttpCheck is a plain Checkstyle AbstractFileSetCheck with no per-fileset filtering hook, matched files are still read by Checkstyle but no longer reported as violations. Because there is no dedicated nohttp Maven plugin, this alone gives Maven (and Ant) users of NoHttpCheck the same .gitignore exclusion behavior with no additional configuration. - nohttp-gradle: a new useGitIgnore NoHttpExtension property which excludes a Spec<FileTreeElement> backed by the shared filter. Tests have been added for GitIgnoreFileFilter (covering wildcards, anchoring, negation, and directory-only matching), for NoHttpCheck (covering the new properties and processFiltered() behavior), for ReplaceFilesRunner, and for NoHttpCheckstylePluginTest/ITest. See spring-projects/spring-framework#37164 Closes spring-iogh-14 Signed-off-by: Sam Brannen <104798+sbrannen@users.noreply.github.com>
sbrannen
force-pushed
the
issues/gh-14-support-gitignore
branch
from
August 25, 2026 16:27
0dbf7f8 to
5065215
Compare
Author
|
An attempt to build the Thus, the code, tests, and documentation in this PR have not been officially "tested". Once the build issues have been sorted out, please let me know so that I can test everything. In the interim, I will transition this to a "draft" PR. |
sbrannen
marked this pull request as draft
August 25, 2026 16:33
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.
Overview
This PR introduces a shared
GitIgnoreFileFilterin thenohttpcore module that parses a single root.gitignorefile into regular-expression-based rules (supporting negation, directory-only patterns, anchored patterns, and the*,**,?, and[...]wildcards) and exposes it as aPredicate<File>.This is wired into all three consumers, enabled by default with a flag to disable it:
-gflag onReplaceFilesRunner, applied viaDirScanner's existingexcludeDirs()/excludeFiles()predicates.useGitIgnore/baseDirproperties onNoHttpCheck, consulted inprocessFiltered(). Since there is no dedicated nohttp Maven plugin, this alone gives Maven (and Ant) users ofNoHttpCheckthe same.gitignoreexclusion behavior with no additional configuration.useGitIgnoreNoHttpExtensionproperty, which excludes aSpec<FileTreeElement>backed by the shared filter.See the commit message for full details and rationale.
Related Issues
nohttpexcludes automatically from.gitignorespring-projects/spring-framework#37164