[
https://issues.apache.org/jira/browse/WW-5770?focusedWorklogId=1047364&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1047364
]
ASF GitHub Bot logged work on WW-5770:
--------------------------------------
Author: ASF GitHub Bot
Created on: 14/Oct/26 05:50
Start Date: 14/Oct/26 05:50
Worklog Time Spent: 10m
Work Description: lukaszlenart opened a new pull request, #2009:
URL: https://github.com/apache/struts/pull/2009
Fixes [WW-5770](https://issues.apache.org/jira/browse/WW-5770)
## Summary
A follow-up to package-scoped constants
([WW-3476](https://issues.apache.org/jira/browse/WW-3476)). A parent package
can now set the Convention result path for every action placed under it:
```xml
<package name="admin-base" extends="convention-default">
<scoped-constant name="struts.convention.result.path"
value="/WEB-INF/admin/"/>
</package>
```
Until now, the same effect needed `@ResultPath` on every action class or
Java package.
The result path of an action is taken from, in order:
1. `@ResultPath` on the action class or its Java package
2. the package's scoped `struts.convention.result.path`, including inherited
ones
3. the global `struts.convention.result.path`
## Why this needs a lookup by package
`ScopedConstantProvider.getValue(name)` resolves the package from the
current `ActionInvocation`, but Convention reads the result path in two places
that have none:
- **At startup**, `DefaultResultMapBuilder.build(...)` runs without an
invocation. It does receive the action's `PackageConfig`, and that config
already includes the parent's scoped constants.
- **At runtime**, `ConventionUnknownHandler` resolves results for
template-only requests, before any invocation of the requested action exists.
## Changes
- `ScopedConstantProvider` gets `default String getValue(String name,
PackageConfig packageConfig)`. It is a `default` method so the interface stays
functional; tests and custom providers keep using lambdas.
- `StrutsScopedConstantProvider` overrides it. A package that does not
declare the constant gives the global value, never the current invocation's
package. A nested request (`<s:action>`, a chain result) reaches
`handleUnknownAction` while the calling action's invocation is still bound, so
falling back to the current invocation would apply the caller's override there.
- Convention plugin:
- `ConventionScopableConstants` registers `struts.convention.result.path`
as scopable in `struts-plugin.xml`.
- `ConventionsService` gets two package-aware `default` overloads of
`determineResultPath`. Custom implementations that only implement the
one-argument methods keep their behaviour.
- `ConventionsServiceImpl` implements them. It keeps its constructor and
uses the constructor's global path when there is no package. The
`ScopedConstantProvider` arrives through an `@Inject` setter.
- `DefaultResultMapBuilder` passes the action's package.
- `ConventionUnknownHandler.determinePath(ActionConfig, PackageConfig,
String)` takes the package. `handleUnknownResult` passes the action's package.
`handleUnknownAction` has no action, so it passes the default parent package
(`struts.convention.default.parent.package`), the package it already uses for
result types.
## Compatibility
These need lines in the 7.5.0 migration notes:
- `ConventionUnknownHandler.determinePath` changed signature (it is
`protected`). A subclass that overrode the old two-argument form without
`@Override` keeps compiling, but its method is no longer called.
- Subclasses of `ConventionsServiceImpl` that override the one-argument
`determineResultPath` methods must override the two-argument forms, which the
framework now calls.
- `ScopedConstantProvider.getValue(String, PackageConfig)` is new; custom
providers may override it.
## Tests
- `StrutsScopedConstantProviderTest`: an explicit package resolves inherited
values, wins over the invocation's package, and ignores the invocation's
package when it has no override. An empty value is used as-is, a non-scopable
name throws, and a lambda provider gets the package lookup.
- New `ConventionsServiceImplTest`: class-level and package-level
`@ResultPath` win over the scoped value; the scoped value wins over the global
one; an empty value is used as-is; a null package gives the global path without
consulting the provider; a custom one-argument-only service keeps its behaviour.
- `DefaultResultMapBuilderTest`: a parent-package override moves results
found at startup, with and without a trailing slash, and `@ResultPath` still
wins.
- `ConventionUnknownHandlerTest` records the paths asked of the
`ServletContext`. An unknown action uses the default parent package's override,
or the global path when it has none; an unknown result uses the action
package's override.
- New `ConventionScopedResultPathTest` boots the real Convention
`struts-plugin.xml` with an XML parent package declaring the constant, and
renders the template from the scoped path.
Docs: apache/struts-site PR to follow (package-configuration
scoped-constants list and the Convention plugin page).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Issue Time Tracking
-------------------
Worklog Id: (was: 1047364)
Remaining Estimate: 0h
Time Spent: 10m
> Make struts.convention.result.path scopable per package
> -------------------------------------------------------
>
> Key: WW-5770
> URL: https://issues.apache.org/jira/browse/WW-5770
> Project: Struts 2
> Issue Type: Improvement
> Components: Plugin - Convention
> Reporter: Lukasz Lenart
> Priority: Major
> Fix For: 7.5.0
>
> Time Spent: 10m
> Remaining Estimate: 0h
>
> A follow-up to the package-scoped constants from
> [WW-3476|https://issues.apache.org/jira/browse/WW-3476], whose first adopter
> was [WW-5768|https://issues.apache.org/jira/browse/WW-5768]
> ({{struts.ui.theme}}, {{struts.ui.templateDir}}).
> h2. Goal
> Allow a parent package to set the Convention result path for the actions
> placed under it:
> {code:xml}<package name="admin-base" extends="convention-default">
> <scoped-constant name="struts.convention.result.path"
> value="/WEB-INF/admin/"/>
> </package>
> {code}
> Today the same effect needs {{@ResultPath}} on every action class or package.
> h2. Why it needs more than WW-5768
> {{ScopedConstantProvider.getValue(name)}} resolves the package from the
> current {{ActionInvocation}}. The Convention plugin reads the result path in
> two places:
> # *At startup*, in {{DefaultResultMapBuilder.build(...)}} via
> {{ConventionsService.determineResultPath(Class)}}. There is no invocation, so
> {{getValue(name)}} always returns the global value. However, {{build()}}
> receives the action's {{PackageConfig}}. {{PackageBasedActionConfigBuilder}}
> passes {{pkgCfg.build()}}, which was created with {{addParent(parentPkg)}},
> so {{getAllScopedConstants()}} already includes the parent's overrides.
> # *At runtime*, in {{ConventionUnknownHandler.determinePath(...)}} via
> {{determineResultPath(ActionConfig)}}, for action-less results.
> {{actionConfig}} may be {{null}} there.
> Both need a lookup by package rather than by invocation. One option is a
> {{getValue(String name, PackageConfig packageConfig)}} on
> {{ScopedConstantProvider}}, with {{getValue(name)}} delegating to it for the
> current invocation's package.
> h2. Proposed change
> * Register a {{ScopableConstants}} bean in the Convention plugin's
> {{struts-plugin.xml}} returning {{struts.convention.result.path}}.
> * Resolve the result path from the action's package in both places, keeping
> this precedence:
> ## {{@ResultPath}} on the action class or package
> ## the package's scoped constant (including inherited ones)
> ## the global {{struts.convention.result.path}}
> h2. Tests
> * A scoped override on the parent package changes the location of results
> built at startup.
> * {{@ResultPath}} still wins over the override.
> * An action-less result resolved by {{ConventionUnknownHandler}} uses the
> override.
> * With no override, the global path is used.
> h2. Docs
> On the struts-site, list the constant on the scoped-constants section of
> {{core-developers/package-configuration.md}}, and mention it on the
> Convention plugin page.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)