Skip to content

Support excluding files matched by .gitignore across nohttp - #66

Draft
sbrannen wants to merge 1 commit into
spring-io:mainfrom
sbrannen:issues/gh-14-support-gitignore
Draft

Support excluding files matched by .gitignore across nohttp#66
sbrannen wants to merge 1 commit into
spring-io:mainfrom
sbrannen:issues/gh-14-support-gitignore

Conversation

@sbrannen

Copy link
Copy Markdown

Overview

This PR introduces a shared GitIgnoreFileFilter in the nohttp core module that parses a single root .gitignore file into regular-expression-based rules (supporting negation, directory-only patterns, anchored patterns, and the *, **, ?, and [...] wildcards) and exposes it as a Predicate<File>.

This is wired into all three consumers, enabled by default with a flag to disable it:

  • nohttp-cli: new -g flag on ReplaceFilesRunner, applied via DirScanner's existing excludeDirs()/excludeFiles() predicates.
  • nohttp-checkstyle: new useGitIgnore/baseDir properties on NoHttpCheck, consulted in processFiltered(). Since 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: new useGitIgnore NoHttpExtension property, which excludes a Spec<FileTreeElement> backed by the shared filter.

See the commit message for full details and rationale.

Related Issues

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
sbrannen force-pushed the issues/gh-14-support-gitignore branch from 0dbf7f8 to 5065215 Compare August 25, 2026 16:27
@sbrannen

Copy link
Copy Markdown
Author

An attempt to build the nohttp project currently fails as follows.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'nohttp-build'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not resolve io.spring.gradle:spring-build-conventions:0.0.38.
     Required by:
         project :
      > Could not resolve io.spring.gradle:spring-build-conventions:0.0.38.
         > Could not get resource 'https://repo.spring.io/plugins-release/io/spring/gradle/spring-build-conventions/0.0.38/spring-build-conventions-0.0.38.pom'.
            > Could not GET 'https://repo.spring.io/plugins-release/io/spring/gradle/spring-build-conventions/0.0.38/spring-build-conventions-0.0.38.pom'. Received status code 401 from server:

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
sbrannen marked this pull request as draft August 25, 2026 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant