Class FeatureIndexer

java.lang.Object
com.arc_e_tect.gradle.gherkin.indexing.FeatureIndexer

public class FeatureIndexer extends Object
Numbers Feature/Scenario titles directly in the source .feature files according to a configured IndexingMode.

A line whose existing number already matches the format mode would itself produce - a single integer for a Feature, or for a Scenario/Scenario Outline either a single integer (IndexingMode.SCENARIO) or <featureNumber>.<n> (IndexingMode.ALL, matched against that line's own feature's resolved number) - is left completely untouched: its number is "pinned". Every other numbered line (wrong format, or a leftover from a different mode, or IndexingMode.OFF itself never expecting a number at all) is stripped and, if mode numbers lines of that kind, assigned a fresh number one past the highest pinned number seen so far (or from 1, if none are pinned yet) - so a newly added file that happens to sort alphabetically before already-numbered files never bumps their numbers, and fresh numbers always read as a continuation of the existing sequence rather than backfilling a gap earlier in it. Passing forceRewrite = true instead ignores existing numbers entirely and renumbers everything from scratch, exactly as if every file were being numbered for the first time.

Never called with IndexingMode.CI: the caller skips invoking this class entirely for that mode, since CI means the feature files must be left completely untouched, not even to strip prior numbering the way IndexingMode.OFF does.

  • Constructor Details

    • FeatureIndexer

      public FeatureIndexer()
      Creates a new FeatureIndexer.
  • Method Details

    • reindex

      public void reindex(List<File> featureFiles, IndexingMode mode, boolean forceRewrite)
      Rewrites every file in featureFiles in place per mode and forceRewrite - see the class documentation for exactly what changes and what's left alone. Files are numbered in the order they appear in featureFiles - the caller is responsible for ordering that list the way numbers should be assigned. A file is only rewritten on disk when its content actually changes.
      Parameters:
      featureFiles - the feature files collected for this run, in the order to number them in
      mode - the indexing mode to apply
      forceRewrite - when true, ignores existing numbers and renumbers everything from scratch; when false, leaves already-correctly-numbered lines alone