Skip to content

Support SDKMAN! Package Count#2033

Open
iskandergaba wants to merge 6 commits into
fastfetch-cli:devfrom
iskandergaba:dev
Open

Support SDKMAN! Package Count#2033
iskandergaba wants to merge 6 commits into
fastfetch-cli:devfrom
iskandergaba:dev

Conversation

@iskandergaba
Copy link
Copy Markdown

@iskandergaba iskandergaba commented Oct 29, 2025

This Pull Request fulfills #2027.

Disclaimer: I have used generative AI to help me implement this feature. I have, however, had to thoroughly review, optimize, and fix the code myself.

Below is a screenshot of the result. Note that some data has been redacted from the screenshot.

screenshot

Let me know if anything is missing.

@CarterLi
Copy link
Copy Markdown
Member

Does SDKMAN supports java SDKs only? We don't plan to add support for language specific package managers.

@iskandergaba
Copy link
Copy Markdown
Author

iskandergaba commented Oct 29, 2025

From their website, I quote:

Install Software Development Kits for the JVM such as Java, Scala, Kotlin, and Groovy. Ant, Gradle, Grails, Maven, SBT, Spark, Spring Boot, Vert.x and many others also supported.

So, technically no. It is not only Java Development Kits (JDKs), but rather SDKs for Java Virtual Machine (JVM) and then some more. For example:

  1. Apache Spark, for example, is built using Scala (a JVM functional programming language). While the engine itself is written in Scala, it offers high-level APIs in multiple programming languages, including Java, Python (via PySpark), R, and Scala, allowing developers to write applications in their preferred language.
  2. Apache ActiveMQ is primarily written in Java and is a Java-based message broker developed by the Apache Software Foundation. While the core broker is Java-based, Active's supports clients written in a wide range of programming languages, including JavaScript, C, C++, Python, .NET, Ruby, PHP, and others.

We don't plan to add support for language specific package managers.

The Java equivalent for npm is not SDKMAN!. It would be rather maven and gradle, which happen to be installable via apt as well as SDKMAN!.

My point is: This is not to install Java project libraries like npm or pip.

I laid my case. It is up to the maintainers and the community from here.

@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

Copy link
Copy Markdown

@codacy-production codacy-production Bot left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

The implementation correctly identifies SDKMAN! candidates by looking for the 'current' directory and integrates the 'sdk' count into the output modules. However, the PR is currently missing logic to add these detected packages to the global package total (result->all), which will lead to inaccurate reporting.

While Codacy analysis is up to standards, the detection logic relies strictly on the SDKMAN_CANDIDATES_DIR environment variable. This should be improved with a fallback to the default installation path to support non-interactive shells. Additionally, the use of manual path construction should be replaced with the project's internal string buffer utilities for safety and consistency.

About this PR

  • No unit or integration tests were provided to verify the SDKMAN! detection logic or handle edge cases such as missing environment variables or specific directory structures.

Test suggestions

  • Detection returns 0 if the SDKMAN_CANDIDATES_DIR environment variable is not set.
  • Detection correctly counts candidates that contain a 'current' directory and ignores those that do not.
  • Hidden files or directories within the candidates path are ignored during the count.
  • The detected 'sdk' count is included in the total packages count ('all') in the final output.
  • Detection falls back to $HOME/.sdkman/candidates when the environment variable is missing.
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Detection returns 0 if the `SDKMAN_CANDIDATES_DIR` environment variable is not set.
2. Detection correctly counts candidates that contain a 'current' directory and ignores those that do not.
3. Hidden files or directories within the candidates path are ignored during the count.
4. The detected 'sdk' count is included in the total packages count ('all') in the final output.
5. Detection falls back to `$HOME/.sdkman/candidates` when the environment variable is missing.

TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback

Comment on lines +290 to +316
static uint32_t getSDKMAN(void) {
const char* candidatesDir = getenv("SDKMAN_CANDIDATES_DIR");
if (!ffStrSet(candidatesDir))
return 0;

FF_AUTO_CLOSE_DIR DIR* dir = opendir(candidatesDir);
if (!dir)
return 0;

uint32_t count = 0;
char path[PATH_MAX];
struct dirent *entry;
while ((entry = readdir(dir)) != NULL)
{
if (entry->d_name[0] == '.')
continue;

if (entry->d_type == DT_DIR || entry->d_type == DT_UNKNOWN)
{
snprintf(path, sizeof(path), "%s/%s/current", candidatesDir, entry->d_name);
if (ffPathExists(path, FF_PATHTYPE_DIRECTORY))
++count;
}
}

return count;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 MEDIUM RISK

Suggestion: Refactor the getSDKMAN function to improve robustness and consistency:

  1. Add a fallback check for the default path ~/.sdkman/candidates (using instance.state.platform.homeDir) if SDKMAN_CANDIDATES_DIR is not set.
  2. Use ffStrbuf or FF_STRBUF_AUTO_DESTROY instead of manual char[PATH_MAX] and snprintf to avoid potential truncation and match the project's idiomatic style.

{ "Number of rpm packages", "rpm" },
{ "Number of scoop-global packages", "scoop-global" },
{ "Number of scoop-user packages", "scoop-user" },
{"Number of SDKMAN! packages", "sdk"},
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚪ LOW RISK

Nitpick: Add spaces inside the braces for consistency with the rest of the array: { "Number of SDKMAN! packages", "sdk" }.

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.

2 participants