This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch 
WW-3784-annotated-wildcard-specificity-ordering
in repository https://gitbox.apache.org/repos/asf/struts.git

commit da414ee25a87d918deec371c30d1dfd93e4acfa3
Author: Lukasz Lenart <[email protected]>
AuthorDate: Sun Jul 26 05:48:31 2026 +0200

    WW-3784 feat(core): add PackageConfig.Builder.reorderActionConfigs
    
    Co-Authored-By: Claude Opus 4.8 <[email protected]>
---
 .../struts2/config/entities/PackageConfig.java     | 12 ++++++
 .../entities/PackageConfigBuilderReorderTest.java  | 44 ++++++++++++++++++++++
 2 files changed, 56 insertions(+)

diff --git 
a/core/src/main/java/org/apache/struts2/config/entities/PackageConfig.java 
b/core/src/main/java/org/apache/struts2/config/entities/PackageConfig.java
index ccf2e756f..df9c7c8f1 100644
--- a/core/src/main/java/org/apache/struts2/config/entities/PackageConfig.java
+++ b/core/src/main/java/org/apache/struts2/config/entities/PackageConfig.java
@@ -24,6 +24,7 @@ import org.apache.struts2.util.location.Location;
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
@@ -517,6 +518,17 @@ public class PackageConfig extends Located implements 
Comparable<PackageConfig>,
             return this;
         }
 
+        public Builder reorderActionConfigs(Comparator<String> byActionName) {
+            List<Map.Entry<String, ActionConfig>> entries = new 
ArrayList<>(target.actionConfigs.entrySet());
+            entries.sort(Map.Entry.comparingByKey(byActionName));
+            Map<String, ActionConfig> reordered = new LinkedHashMap<>();
+            for (Map.Entry<String, ActionConfig> entry : entries) {
+                reordered.put(entry.getKey(), entry.getValue());
+            }
+            target.actionConfigs = reordered;
+            return this;
+        }
+
         public Builder addParents(List<PackageConfig> parents) {
             for (PackageConfig config : parents) {
                 addParent(config);
diff --git 
a/core/src/test/java/org/apache/struts2/config/entities/PackageConfigBuilderReorderTest.java
 
b/core/src/test/java/org/apache/struts2/config/entities/PackageConfigBuilderReorderTest.java
new file mode 100644
index 000000000..71769df62
--- /dev/null
+++ 
b/core/src/test/java/org/apache/struts2/config/entities/PackageConfigBuilderReorderTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.entities;
+
+import junit.framework.TestCase;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+
+public class PackageConfigBuilderReorderTest extends TestCase {
+
+    public void testReorderActionConfigsAppliesComparator() {
+        PackageConfig.Builder builder = new PackageConfig.Builder("test");
+        builder.addActionConfig("some/*", action("some/*"));
+        builder.addActionConfig("some/usefull/*", action("some/usefull/*"));
+
+        // reverse-alphabetical proves the map is genuinely reordered, not 
left as-inserted
+        builder.reorderActionConfigs(Comparator.reverseOrder());
+
+        List<String> keys = new 
ArrayList<>(builder.build().getActionConfigs().keySet());
+        assertEquals(List.of("some/usefull/*", "some/*"), keys);
+    }
+
+    private ActionConfig action(String name) {
+        return new ActionConfig.Builder("test", name, 
"com.example.Action").build();
+    }
+}

Reply via email to