Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ SPDX-License-Identifier: MIT
```{eval-rst}
.. autofunction:: cjdk.list_vendors
.. versionadded:: 0.4.0
.. versionchanged:: 0.6.0
Now filters vendors by the given os/arch, which default to the current
platform.
```

```{eval-rst}
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ See also the section on [versioning](versioning-scheme).

## [Unreleased]

### Changed

- `list_vendors()` and `ls-vendors` now filter vendors by OS and architecture,
defaulting to the current platform.

## [0.5.0] - 2026-01-07

### Added
Expand Down
3 changes: 3 additions & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ successful, returns the exit code of the launched program.

```{eval-rst}
.. versionadded:: 0.4.0
.. versionchanged:: 0.6.0
Now filters vendors by the ``--os`` and ``--arch`` options, which default to
the current platform.
```

## Working with cached JDKs
Expand Down
12 changes: 8 additions & 4 deletions src/cjdk/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ def list_vendors(**kwargs: Unpack[ConfigKwargs]) -> list[str]:
"""
Return the list of available JDK vendors.

Parameters
----------
None

Other Parameters
----------------
cache_dir : pathlib.Path or str, optional
Override the root cache directory.
index_url : str, optional
Alternative URL for the JDK index.
os : str, optional
Operating system for the JDK (default: current operating system).
arch : str, optional
CPU architecture for the JDK (default: current architecture).

Returns
-------
Expand All @@ -71,6 +71,10 @@ def list_vendors(**kwargs: Unpack[ConfigKwargs]) -> list[str]:
If configuration is invalid.
InstallError
If fetching the index fails.

.. versionchanged:: 0.6.0
Now filters vendors by the given os/arch, which default to the current
platform.
"""
conf = _conf.configure(**kwargs)
return sorted(_jdk.available_vendors(conf))
Expand Down
13 changes: 7 additions & 6 deletions src/cjdk/_jdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,19 @@

def available_vendors(conf: Configuration) -> set[str]:
"""
Return the set of available JDK vendor names.
Return the set of available JDK vendor names for the configured OS and arch.

Arguments:
conf -- Configuration (currently unused, for future os/arch filtering)
conf -- Configuration (uses os and arch for filtering)
"""
_ = conf
index = _index.jdk_index(conf)
try:
vendors = index[conf.os][conf.arch]
except KeyError:
return set()
return {
vendor.removeprefix("jdk@")
for os in index
for arch in index[os]
for vendor in index[os][arch]
for vendor in vendors
if vendor.startswith("jdk@")
}

Expand Down
55 changes: 55 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,58 @@ def test_env_var_set():
with f("CJDK_TEST_ENV_VAR", "testvalue"):
assert os.environ["CJDK_TEST_ENV_VAR"] == "testvalue"
assert "CJDK_TEST_ENV_VAR" not in os.environ


def test_list_vendors(tmp_path):
with mock_server.start(
endpoint="/index.json",
data={
"linux": {
"amd64": {
"jdk@adoptium": {"17": "zip+http://example.com/a.zip"},
"jdk@zulu": {"17": "zip+http://example.com/z.zip"},
},
"arm64": {
"jdk@adoptium": {"17": "zip+http://example.com/a.zip"},
},
},
"darwin": {
"amd64": {
"jdk@graalvm": {"17": "zip+http://example.com/g.zip"},
},
},
},
) as server:
vendors_linux_amd64 = _api.list_vendors(
os="linux",
arch="amd64",
cache_dir=tmp_path / "cache",
index_url=server.url("/index.json"),
_allow_insecure_for_testing=True,
)
vendors_linux_arm64 = _api.list_vendors(
os="linux",
arch="arm64",
cache_dir=tmp_path / "cache",
index_url=server.url("/index.json"),
_allow_insecure_for_testing=True,
)
vendors_darwin_amd64 = _api.list_vendors(
os="darwin",
arch="amd64",
cache_dir=tmp_path / "cache",
index_url=server.url("/index.json"),
_allow_insecure_for_testing=True,
)
vendors_nonexistent = _api.list_vendors(
os="windows",
arch="amd64",
cache_dir=tmp_path / "cache",
index_url=server.url("/index.json"),
_allow_insecure_for_testing=True,
)

assert vendors_linux_amd64 == ["adoptium", "zulu"]
assert vendors_linux_arm64 == ["adoptium"]
assert vendors_darwin_amd64 == ["graalvm"]
assert vendors_nonexistent == []
2 changes: 1 addition & 1 deletion tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def test_list_vendors():
vendors = _api.list_vendors()
vendors = _api.list_vendors(os="linux", arch="amd64")
assert vendors is not None
assert "adoptium" in vendors
assert "corretto" in vendors
Expand Down