Skip to content

#2589: Inject an application-level IdeContext into NlsService from th… - #2648

Open
krystynaShatkovska wants to merge 7 commits into
devonfw:mainfrom
krystynaShatkovska:feature/2589-nls-service-context-injection
Open

krystynaShatkovska wants to merge 7 commits into
devonfw:mainfrom
krystynaShatkovska:feature/2589-nls-service-context-injection

Conversation

@krystynaShatkovska

@krystynaShatkovska krystynaShatkovska commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

This PR fixes #2589

In PR #2548, NlsService was made to accept an injected IdeContext so its tests could run in an isolated environment, but the GUI kept using the old no-context path and NlsService retained a fallback that lazily created an IdeContextConsole when no context was present. This finishes the refactor so the context is always supplied through dependency injection:

Implemented changes:

  • Change 1
    NlsService no longer creates a fallback IdeContext. It now has a single NlsService(IdeContext, Locale) constructor that requires a non-null IdeContext. The NlsService(Locale) constructor, which left the context null and forced the fallback to a fresh IdeContextConsole, is removed.

  • Change 2
    The GUI supplies the context. GuiStateManager now constructs an application-level IdeContextConsole bound to the app start context and injects it into NlsService. Binding it to the start context also keeps the GUI logging context, which the old no-arg IdeContextConsole() discarded.

  • Change 3
    Behavior is preserved. Locale persistence still writes IDE_OPTIONS = -Duser.language= to the user-scope ~/.ide/ide.properties, and the IDE_OPTIONS isolation behavior introduced in #2533: isolate NlsServiceTest and stop IDE_OPTIONS env var from pollu… #2548 is unchanged.

  • Change 4
    NlsServiceTest is updated to inject the isolated test context instead of the removed constructor.


Testing instructions

  1. Run the affected GUI tests:
    mvn -pl gui -am test -Dsurefire.failIfNoSpecifiedTests=false -Dtest='NlsServiceTest,AppBaseTest' -> NlsServiceTest (29) and AppBaseTest (10) pass. A full mvn verify also passes.
  2. Launch the GUI and change the locale; the preference persists to ~/.ide/ide.properties as IDE_OPTIONS=-Duser.language=... and is picked up on the next start — including the startup path with no workspace yet selected (covered by AppBaseTest).
  3. Confirm a machine-wide IDE_OPTIONS environment variable does not override the persisted locale (the isolation introduced in NlsServiceTest not properly isolated and fails if IDE_OPTIONS is set #2533 / PR #2533: isolate NlsServiceTest and stop IDE_OPTIONS env var from pollu… #2548 is intact).

Checklist for this PR

Make sure everything is checked before merging this PR. For further info please also see
our DoD.

  • When running mvn clean test locally all tests pass and build is successful
  • PR title is of the form #«issue-id»: «brief summary» (e.g. #921: fixed setup.bat and not feature/921 fixed setup.bat).
    If no issue ID exists, title only.
  • PR top-level comment summarizes what has been done and contains link to addressed issue(s)
  • PR and issue(s) have suitable labels
  • Issue is set to In Progress and assigned to you or there is no issue (might happen for very small PRs)
  • You followed all coding conventions
  • You have added the issue implemented by your PR in CHANGELOG.adoc unless issue is labelled
    with internal
  • You have not changed any dependency in pom.xml files or otherwise if runtime dependencies changed,
    you have updated our LICENSE.adoc
  • You have formulated clear instructions on how to test your contribution under "Testing instructions"

…from the GUI

The GUI previously constructed NlsService with a null context, which made
NlsService fall back to lazily creating its own IdeContextConsole at
persistence time -- a service reaching into the environment to build its own
dependency.

Inject an application-level IdeContextConsole bound to the GUI's start
context from GuiStateManager, and remove the now-unused NlsService(Locale)
constructor and the fallback creation. NlsService now always receives its
context via dependency injection. This also fixes a latent issue: the old
fallback built its own start context and discarded the GUI logging context.

Locale handling and IDE_OPTIONS isolation behavior are unchanged.
@github-project-automation github-project-automation Bot moved this to 🆕 New in IDEasy board Oct 13, 2026
@krystynaShatkovska krystynaShatkovska self-assigned this Oct 13, 2026
@krystynaShatkovska krystynaShatkovska added enhancement New feature or request GUI Graphical User Interface of IDEasy (aka dashboard) build with JavaFx internal Nothing to be added to CHANGELOG, only internal story nls native language support (i18n, l10n) labels Oct 13, 2026
@coveralls

coveralls commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 38900158726

Coverage decreased (-0.002%) to 74.753%

Details

  • Coverage decreased (-0.002%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • 29 coverage regressions across 3 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

29 previously-covered lines in 3 files lost coverage.

File Lines Losing Coverage Coverage
com/devonfw/ide/gui/core/service/NlsService.java 19 82.01%
com/devonfw/ide/gui/core/context/GuiStateManager.java 9 83.05%
com/devonfw/tools/ide/version/VersionSegment.java 1 90.81%

Coverage Stats

Coverage Status
Relevant Lines: 19641
Covered Lines: 15336
Line Coverage: 78.08%
Relevant Branches: 8723
Covered Branches: 5867
Branch Coverage: 67.26%
Branches in Coverage %: Yes
Coverage Strength: 3.35 hits per line

💛 - Coveralls

@laim2003 laim2003 self-assigned this Oct 14, 2026
@laim2003
laim2003 self-requested a review October 14, 2026 08:22
@krystynaShatkovska krystynaShatkovska moved this from 🆕 New to Team Review in IDEasy board Oct 14, 2026
@krystynaShatkovska krystynaShatkovska moved this from Team Review to 👀 In review in IDEasy board Oct 14, 2026
@krystynaShatkovska krystynaShatkovska moved this from 👀 In review to Team Review in IDEasy board Oct 14, 2026

@laim2003 laim2003 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.

Thank you @krystynaShatkovska. The implementation is now much better and less hacky. However, the persistence does not yet work and also does not seem to be implemented in the code currently, but at the same time that is also not the scope of this PR. I'll check if we already have a PR that fixes this issue and if not I will create one. Regardless in my opinion this PR is ready to merge.

@laim2003 laim2003 moved this from Team Review to 👀 In review in IDEasy board Oct 14, 2026
@laim2003 laim2003 added this to the release:2026.10.001 milestone Oct 14, 2026
@quando632 quando632 self-assigned this Oct 14, 2026

@quando632 quando632 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.

Thanks for finishing this refactoring. NlsService now has a single constructor with Objects.requireNonNull, so it no longer creates a context behind the scenes. Moving the IdeStartContextImpl creation up and binding the console context to it keeps the GUI log listener, which is a good detail. The updated Javadoc also explains clearly how production code and tests supply the context.

Comment thread gui/src/main/java/com/devonfw/ide/gui/core/context/GuiStateManager.java Outdated
@quando632

Copy link
Copy Markdown
Contributor

The description says fixes #2548, which is the earlier PR, so GitHub does not link #2589 and will not close it on merge. Please change it to fixes #2589.

Address review feedback: GuiStateManager now offers an (ideRoot, IdeContext)
overload; the single-arg constructor delegates and derives the context from the
GUI start context. AppBaseTest injects an isolated IdeTestContext (stub System,
throw-away user home) so persisting the locale no longer rewrites the developer's
real ~/.ide/ide.properties.
Resolve conflicts from upstream's GUI rework (devonfw#2480 Rework GUI tests, devonfw#2400 Rework console) against the devonfw#2589 NlsService context injection:
- NlsService keeps the single (IdeContext, Locale) constructor; the lazy IdeContextConsole fallback is removed.
- GuiStateManager keeps the (ideRoot, IdeContext) overload and the startContext-first ordering, dropping the now-removed ConsoleController.
- AppBaseTest now extends UIBasedApplicationTest and injects an isolated NlsService context (throw-away @tempdir user home) so setLocale never rewrites the real ~/.ide/ide.properties.
- ConsolePanelTest (new in the console rework) is migrated off the removed single-arg NlsService constructor to the injected-context form.

@quando632 quando632 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.

Thanks for the quick follow-up. The new GuiStateManager(String, IdeContext) overload keeps the production default intact, and AppBaseTest no longer writes to the real ~/.ide/ide.properties. Looks ready to merge from my side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request GUI Graphical User Interface of IDEasy (aka dashboard) build with JavaFx internal Nothing to be added to CHANGELOG, only internal story nls native language support (i18n, l10n)

Projects

Status: 👀 In review

Development

Successfully merging this pull request may close these issues.

Cleanup GUI context injection for NlsService

4 participants