Class Lockfile
java.lang.Object
com.arc_e_tect.gradle.apionly.subscriber.Lockfile
apionly.lock -- what this project is actually building against.
Committed, and recording per target the resolved version, the channel it came
from, and the SHA-256 of every fetched file. That is the verbatim guarantee:
`verifyApiSpec` re-hashes and fails when anything drifted, whether because a
generated file was hand-edited or because a tag was moved under the build's
feet. Run it in CI and contract drift becomes a build failure rather than a
production surprise.
The format is deliberately a small, sorted, line-oriented text file rather
than JSON: it is read by people in review far more often than by machines, and
a one-line diff should mean one thing changed.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordWhat is locked for one target. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe format this class reads and writes. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionThe entry for one target.voidput(Lockfile.Entry entry) Adds or replaces the entry for a target.static LockfileReads a lockfile, or returns an empty one if it does not exist.static StringThe SHA-256 of a file, lowercase hexadecimal.targets()Every target with an entry, in sorted order.voidWrites the lockfile, with targets and their files in sorted order.
-
Field Details
-
FORMAT_VERSION
public static final int FORMAT_VERSIONThe format this class reads and writes. Bumped only when the format changes.- See Also:
-
-
Constructor Details
-
Lockfile
public Lockfile()Creates an empty lockfile.
-
-
Method Details
-
read
Reads a lockfile, or returns an empty one if it does not exist.A missing file is an ordinary first-run state, not an error: a project that has never fetched anything has nothing locked yet.
- Parameters:
file- the lockfile to read- Returns:
- the parsed lockfile, empty if the file is absent
- Throws:
UncheckedIOException- if the file exists but cannot be read
-
write
Writes the lockfile, with targets and their files in sorted order.The ordering matters: this file is read in review far more often than by a machine, and a one-line diff should mean one thing changed rather than a reordering.
- Parameters:
file- where to write- Throws:
UncheckedIOException- if it cannot be written
-
get
The entry for one target.- Parameters:
target- the contract to look up- Returns:
- its entry, or
nullif nothing is locked for it
-
put
Adds or replaces the entry for a target.- Parameters:
entry- what to record
-
targets
Every target with an entry, in sorted order.- Returns:
- the locked target names
-
sha256
The SHA-256 of a file, lowercase hexadecimal.- Parameters:
file- the file to hash- Returns:
- its digest as 64 hexadecimal characters
- Throws:
UncheckedIOException- if the file cannot be read
-