Skip to content

Fix OsFamily detection and make it testable - #957

Merged
alexander-yevsyukov merged 13 commits into
masterfrom
os-family-enum
Oct 2, 2026
Merged

alexander-yevsyukov merged 13 commits into
masterfrom
os-family-enum

Conversation

@alexander-yevsyukov

@alexander-yevsyukov alexander-yevsyukov commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Reworks io.spine.environment.OsFamily so that it follows the detection rules of
org.apache.tools.ant.taskdefs.condition.Os, which it is based on, and so that
the rules can be tested regardless of the host the tests run on.

Detection

The previous implementation deviated from Ant in how it told a Unix:

Case Before After
Unix.isCurrent() on macOS false — the families were mutually exclusive true — a macOS host belongs to both macOS and Unix
SunOS, FreeBSD, and other Unix systems whose name does not end with x not a Unix, so detect() threw Unix
Missing os.name or path.separator property class initialization failed with IllegalStateException treated as an empty value

Unix is told by the : path separator, minus the two systems that use it
without being a Unix: OpenVMS and classic (pre-OS X) Mac OS.

As the families now overlap, code that relied on them being mutually exclusive
should use detect(). It returns the most specific family — macOS rather than
Unix on a Mac — relying on the more specific families being declared first.
When the OS belongs to none of the families, its exception now names the
os.name value.

Testability

The public methods keep their signatures: isCurrent() and detect(). The rules
move into two package-private, @VisibleForTesting methods,
matches(osName, pathSeparator) and detect(osName, pathSeparator), which the
public ones apply to the current system properties.

The properties are read into static final fields at class initialization, so
before this change a test could only observe the family of the host it ran on.
OsFamilySpec now drives each family and detect() through a table of real
os.name values (Windows, Mac OS X, Darwin, classic Mac OS, Linux, HP-UX,
SunOS, OpenVMS), covers the failure of detect(), and ties the seams back to
the public methods on the host. OsFamily is fully covered.

Documentation

Each constant is now documented, and the docs of the enum and detect() state
the overlap of the families and the exception detect() throws.

Housekeeping

Verification

./gradlew :base:build :environment:build :base:dokkaGenerate :environment:dokkaGenerate
passes on the head of the branch.

🤖 Generated with Claude Code

alexander-yevsyukov and others added 5 commits August 18, 2026 23:11
Extract the detection rules into a package-private `matches(osName,
pathSeparator)` seam so that they can be verified for any operating
system, not only for the one running the build. `isCurrent()` applies
the seam to the current `os.name` and `path.separator`.

Cover all three families with a table of real `os.name` values, and
document the constants, including the fact that a macOS host belongs
to the `Unix` family too.

Read the system properties with defaults to avoid an
`ExceptionInInitializerError` if a property is absent.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 18, 2026 22:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new io.spine.os package with an OsFamily enum (ported from Ant) to detect the host OS without requiring a ToolBase dependency, and updates version/dependency-report artifacts accordingly. The PR also includes a substantial generatePom rework (via config/built tooling updates) with additional tests.

Changes:

  • Introduce io.spine.os.OsFamily with isCurrent() and a test seam (matches(...)) plus unit tests covering multiple OS name variants.
  • Bump published snapshot version and regenerate dependency reports/POM to match.
  • Update build tooling around generatePom (lock-safe/deterministic behavior) and add Gradle TestKit coverage.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
version.gradle.kts Bumps versionToPublish snapshot.
docs/dependencies/pom.xml Updates generated POM version to match snapshot.
docs/dependencies/dependencies.md Regenerates dependency license report content and timestamps.
buildSrc/build.gradle.kts Configures TestKit + passes buildSrc classpath to functional tests.
buildSrc/src/main/kotlin/io/spine/gradle/report/pom/DependencyWriter.kt Refactors dependency version sourcing to use collected resolved versions.
buildSrc/src/main/kotlin/io/spine/gradle/report/pom/PomGenerator.kt Makes generatePom depend on per-project resolved-version collectors.
buildSrc/src/main/kotlin/io/spine/gradle/report/pom/PomXmlWriter.kt Threads resolved-version source into XML generation.
buildSrc/src/main/kotlin/io/spine/gradle/report/pom/ResolvedVersions.kt Adds per-project collector task + resolution graph extraction.
buildSrc/src/test/kotlin/io/spine/gradle/report/pom/DependencyWriterSpec.kt Updates/extends unit coverage around resolved versions behavior.
buildSrc/src/test/kotlin/io/spine/gradle/report/pom/PomGeneratorIgTest.kt Adds TestKit integration test for generatePom determinism and conflict handling.
buildSrc/src/main/kotlin/io/spine/dependency/local/*.kt Bumps local Spine SDK dependency versions.
buildSrc/src/main/kotlin/io/spine/dependency/lib/Jackson.kt Minor refactor/clarification of Jackson module coordinates/docs.
buildSrc/src/main/kotlin/io/spine/dependency/lib/JacksonV2.kt Clarifies Jackson JSTEP-1 reference.
base/src/main/java/io/spine/os/package-info.java Introduces io.spine.os package with nullness/return-value annotations.
base/src/main/java/io/spine/os/OsFamily.java Adds OS-family detection API and matching rules.
base/src/test/kotlin/io/spine/os/OsFamilySpec.kt Adds parameterized tests for Windows/macOS/Unix matching and host-property consistency.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.00%. Comparing base (51cb428) to head (8abcd67).
⚠️ Report is 28 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #957      +/-   ##
==========================================
- Coverage   94.01%   94.00%   -0.02%     
==========================================
  Files         194      195       +1     
  Lines        4177     4201      +24     
  Branches      345      351       +6     
==========================================
+ Hits         3927     3949      +22     
  Misses        149      149              
- Partials      101      103       +2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

# Conflicts:
#	buildSrc/src/main/kotlin/io/spine/dependency/lib/Jackson.kt
#	buildSrc/src/main/kotlin/io/spine/dependency/local/Compiler.kt
#	buildSrc/src/main/kotlin/io/spine/dependency/local/CoreJvm.kt
#	buildSrc/src/main/kotlin/io/spine/dependency/local/CoreJvmCompiler.kt
#	buildSrc/src/main/kotlin/io/spine/dependency/local/ToolBase.kt
#	buildSrc/src/main/kotlin/io/spine/dependency/local/Validation.kt
#	buildSrc/src/main/kotlin/io/spine/gradle/report/pom/ResolvedVersions.kt
#	buildSrc/src/test/kotlin/io/spine/gradle/report/pom/PomGeneratorIgTest.kt
#	config
#	docs/dependencies/dependencies.md
#	docs/dependencies/pom.xml
#	version.gradle.kts
@alexander-yevsyukov alexander-yevsyukov moved this from 📋 Backlog to 🏗 In progress in v2.0 Oct 2, 2026
alexander-yevsyukov and others added 5 commits October 2, 2026 15:54
Rename `notMac` to `notClassicMac` in `Unix.matches()`, since the condition
admits macOS and excludes only the classic (pre-OS X) Mac OS. Correct the
`signature` Javadoc, which did not account for `macOS` passing its own value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Match the header used across the rest of the code after the merge of `master`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The `OsFamily` enum ported from ToolBase into `io.spine.os` duplicated
the existing `io.spine.environment.OsFamily`. Move it over the older enum
and drop the `io.spine.os` package.

The replacement follows Ant's rules: the families overlap, so a macOS host
is also a Unix, and Unix systems whose names do not end with `x`, such as
SunOS, are now detected. `detect()` is kept and returns the most specific
family; it gains the same `@VisibleForTesting` seam as `isCurrent()`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alexander-yevsyukov alexander-yevsyukov changed the title Add OsFamily enum to io.spine.os Replace environment.OsFamily with the ToolBase version Oct 2, 2026
@alexander-yevsyukov alexander-yevsyukov changed the title Replace environment.OsFamily with the ToolBase version Fix OsFamily detection and make it testable Oct 2, 2026
@alexander-yevsyukov
alexander-yevsyukov merged commit d1f2ffd into master Oct 2, 2026
8 checks passed
@alexander-yevsyukov
alexander-yevsyukov deleted the os-family-enum branch October 2, 2026 15:36
@github-project-automation github-project-automation Bot moved this from In Review to ✅ Done in v2.0 Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants