[ 
https://issues.apache.org/jira/browse/WW-3476?focusedWorklogId=1046799&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1046799
 ]

ASF GitHub Bot logged work on WW-3476:
--------------------------------------

                Author: ASF GitHub Bot
            Created on: 10/Oct/26 16:44
            Start Date: 10/Oct/26 16:44
    Worklog Time Spent: 10m 
      Work Description: lukaszlenart commented on code in PR #2005:
URL: https://github.com/apache/struts/pull/2005#discussion_r4238388180


##########
core/src/main/java/org/apache/struts2/config/entities/PackageConfig.java:
##########
@@ -90,6 +94,8 @@ protected PackageConfig(PackageConfig orig) {
         this.parents = new ArrayList<>(orig.parents);
         this.location = orig.location;
         this.strictMethodInvocation = orig.strictMethodInvocation;
+        this.scopedConstants = new LinkedHashMap<>(orig.scopedConstants);
+        this.allScopedConstants = orig.allScopedConstants;

Review Comment:
   This one is already unmodifiable. It copies the reference to the map 
`build()` produced with `Collections.unmodifiableMap(...)`, or 
`Collections.emptyMap()` before the first build, so nothing can write through 
it.



##########
core/src/main/java/org/apache/struts2/config/entities/PackageConfig.java:
##########
@@ -90,6 +94,8 @@ protected PackageConfig(PackageConfig orig) {
         this.parents = new ArrayList<>(orig.parents);
         this.location = orig.location;
         this.strictMethodInvocation = orig.strictMethodInvocation;
+        this.scopedConstants = new LinkedHashMap<>(orig.scopedConstants);

Review Comment:
   Not here. The copy constructor builds the Builder's working copy: `build()` 
does `target = new PackageConfig(result)`, and `new Builder(existing)` goes 
through it too. `addScopedConstant` then writes into that map, so an 
unmodifiable copy would break `new Builder(existing).addScopedConstant(...)`. 
Every other collection in this constructor is mutable for the same reason. The 
instance callers get is read-only: `build()` wraps the map with 
`Collections.unmodifiableMap`, and 
`PackageConfigTest#testScopedConstantsAreUnmodifiableAfterBuild` pins that.



##########
core/src/main/java/org/apache/struts2/config/StrutsScopedConstantProvider.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.struts2.config;
+
+import org.apache.struts2.ActionContext;
+import org.apache.struts2.ActionInvocation;
+import org.apache.struts2.ActionProxy;
+import org.apache.struts2.config.entities.PackageConfig;
+import org.apache.struts2.inject.Container;
+import org.apache.struts2.inject.Inject;
+
+import java.util.Optional;
+import java.util.Set;
+
+/**
+ * @since 7.5.0
+ */
+public class StrutsScopedConstantProvider implements ScopedConstantProvider {
+
+    private Container container;
+    private Configuration configuration;
+    private volatile Set<String> scopableNames;
+
+    @Inject
+    public void setContainer(Container container) {
+        this.container = container;
+    }
+
+    @Inject
+    public void setConfiguration(Configuration configuration) {
+        this.configuration = configuration;
+    }

Review Comment:
   Agreed. In dc4305acd it now injects only `Container` and gets 
`Configuration` from it. The scopable names are computed in the same setter 
too, which also removed the `volatile` lazy cache Sonar flagged.



##########
core/src/main/java/org/apache/struts2/StrutsConstants.java:
##########
@@ -628,6 +628,13 @@ public final class StrutsConstants {
      */
     public static final String STRUTS_PARAMETER_ALLOWLISTER = 
"struts.parameterAllowlister";
 
+    /**
+     * The {@link org.apache.struts2.config.ScopedConstantProvider} 
implementation class.
+     *
+     * @since 7.5.0
+     */
+    public static final String STRUTS_SCOPED_CONSTANT_PROVIDER = 
"struts.scopedConstantProvider";

Review Comment:
   Right, it names a bean. In 8a8125046 the Javadoc now says it is the name of 
the Struts bean implementing `ScopedConstantProvider`, selected by 
`StrutsBeanSelectionProvider`. The same commit lists it in the extension-point 
table, adds `struts.scopedConstantProvider=struts` to `default.properties`, and 
adds a test that the constant selects a custom bean.





Issue Time Tracking
-------------------

    Worklog Id:     (was: 1046799)
    Time Spent: 1h 20m  (was: 1h 10m)

> Allow overwriting of constants for each package
> -----------------------------------------------
>
>                 Key: WW-3476
>                 URL: https://issues.apache.org/jira/browse/WW-3476
>             Project: Struts 2
>          Issue Type: New Feature
>          Components: XML Configuration
>    Affects Versions: 2.2.1
>            Reporter: Johannes Geppert
>            Assignee: Lukasz Lenart
>            Priority: Major
>             Fix For: 7.5.0
>
>          Time Spent: 1h 20m
>  Remaining Estimate: 0h
>
> Allow to overwriting of constants for each package.
> So I can specify as example for each package an other ActionMapper, Local or 
> other location for the JSP Files.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to