You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2024/03/25 06:30:16 UTC

(struts) branch feature/WW-5402-autoload-classptah updated (a8a9e6d73 -> fcde5a25a)

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

lukaszlenart pushed a change to branch feature/WW-5402-autoload-classptah
in repository https://gitbox.apache.org/repos/asf/struts.git


 discard a8a9e6d73 WW-5402 Auto loads Tiles definitions from classpath
     new fcde5a25a WW-5402 Auto loads Tiles definitions from classpath

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (a8a9e6d73)
            \
             N -- N -- N   refs/heads/feature/WW-5402-autoload-classptah (fcde5a25a)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/struts2/tiles/StrutsTilesContainerFactoryTest.java  | 7 +++++++
 1 file changed, 7 insertions(+)


(struts) 01/01: WW-5402 Auto loads Tiles definitions from classpath

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch feature/WW-5402-autoload-classptah
in repository https://gitbox.apache.org/repos/asf/struts.git

commit fcde5a25a82caf937cc505d06fc33641bc68b177
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sun Mar 24 11:29:12 2024 +0100

    WW-5402 Auto loads Tiles definitions from classpath
---
 plugins/tiles/pom.xml                              |   3 -
 .../struts2/tiles/StrutsTilesContainerFactory.java |  25 ++--
 .../tiles/StrutsTilesContainerFactoryTest.java     | 134 +++++++++++++++++++++
 3 files changed, 152 insertions(+), 10 deletions(-)

diff --git a/plugins/tiles/pom.xml b/plugins/tiles/pom.xml
index 440f6ee79..1a6caf2c1 100644
--- a/plugins/tiles/pom.xml
+++ b/plugins/tiles/pom.xml
@@ -35,9 +35,6 @@
     <profiles>
         <profile>
             <id>build-autotags</id>
-            <activation>
-                <activeByDefault>true</activeByDefault>
-            </activation>
             <build>
                 <plugins>
                     <plugin>
diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java
index 205476467..aba4e5985 100644
--- a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java
+++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java
@@ -25,11 +25,6 @@ import ognl.PropertyAccessor;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.tiles.api.TilesContainer;
-import org.apache.tiles.request.ApplicationContext;
-import org.apache.tiles.request.ApplicationResource;
-import org.apache.tiles.request.Request;
-import org.apache.tiles.request.render.BasicRendererFactory;
-import org.apache.tiles.request.render.ChainedDelegateRenderer;
 import org.apache.tiles.core.definition.DefinitionsFactory;
 import org.apache.tiles.core.definition.pattern.DefinitionPatternMatcherFactory;
 import org.apache.tiles.core.definition.pattern.PatternDefinitionResolver;
@@ -57,6 +52,11 @@ import org.apache.tiles.ognl.PropertyAccessorDelegateFactory;
 import org.apache.tiles.ognl.ScopePropertyAccessor;
 import org.apache.tiles.ognl.TilesApplicationContextNestedObjectExtractor;
 import org.apache.tiles.ognl.TilesContextPropertyAccessorDelegateFactory;
+import org.apache.tiles.request.ApplicationContext;
+import org.apache.tiles.request.ApplicationResource;
+import org.apache.tiles.request.Request;
+import org.apache.tiles.request.render.BasicRendererFactory;
+import org.apache.tiles.request.render.ChainedDelegateRenderer;
 import org.apache.tiles.request.render.Renderer;
 
 import javax.el.ArrayELResolver;
@@ -69,6 +69,7 @@ import javax.el.ResourceBundleELResolver;
 import javax.servlet.jsp.JspFactory;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -100,10 +101,20 @@ public class StrutsTilesContainerFactory extends BasicTilesContainerFactory {
     public static final String PATTERN_WILDCARD = "WILDCARD";
     public static final String PATTERN_REGEXP = "REGEXP";
 
+    /**
+     * Default pattern to be used to collect Tiles definitions if user didn't configure any
+     * @deprecated use {@link #TILES_DEFAULT_PATTERNS} instead
+     */
+    @Deprecated
+    public static final String TILES_DEFAULT_PATTERN = "/WEB-INF/**/tiles*.xml,classpath*:META-INF/**/tiles*.xml";
+
     /**
      * Default pattern to be used to collect Tiles definitions if user didn't configure any
      */
-    public static final String TILES_DEFAULT_PATTERN = "tiles*.xml";
+    public static final Set<String> TILES_DEFAULT_PATTERNS = new HashSet<String>() {{
+        add("/WEB-INF/**/tiles*.xml");
+        add("classpath*:META-INF/**/tiles*.xml");
+    }};
 
     /**
      * Supported expression languages
@@ -213,7 +224,7 @@ public class StrutsTilesContainerFactory extends BasicTilesContainerFactory {
         if (params.containsKey(DefinitionsFactory.DEFINITIONS_CONFIG)) {
             return TextParseUtil.commaDelimitedStringToSet(params.get(DefinitionsFactory.DEFINITIONS_CONFIG));
         }
-        return TextParseUtil.commaDelimitedStringToSet(TILES_DEFAULT_PATTERN);
+        return TILES_DEFAULT_PATTERNS;
     }
 
     protected ELAttributeEvaluator createELEvaluator(ApplicationContext applicationContext) {
diff --git a/plugins/tiles/src/test/java/org/apache/struts2/tiles/StrutsTilesContainerFactoryTest.java b/plugins/tiles/src/test/java/org/apache/struts2/tiles/StrutsTilesContainerFactoryTest.java
new file mode 100644
index 000000000..890403e8a
--- /dev/null
+++ b/plugins/tiles/src/test/java/org/apache/struts2/tiles/StrutsTilesContainerFactoryTest.java
@@ -0,0 +1,134 @@
+/*
+ * 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.tiles;
+
+import org.apache.tiles.api.TilesContainer;
+import org.apache.tiles.core.evaluator.AttributeEvaluatorFactory;
+import org.apache.tiles.core.evaluator.impl.DirectAttributeEvaluator;
+import org.apache.tiles.core.locale.LocaleResolver;
+import org.apache.tiles.core.prepare.factory.BasicPreparerFactory;
+import org.apache.tiles.core.prepare.factory.PreparerFactory;
+import org.apache.tiles.ognl.OGNLAttributeEvaluator;
+import org.apache.tiles.request.ApplicationContext;
+import org.apache.tiles.request.ApplicationResource;
+import org.apache.tiles.request.locale.URLApplicationResource;
+import org.apache.tiles.request.render.BasicRendererFactory;
+import org.apache.tiles.request.render.ChainedDelegateRenderer;
+import org.apache.tiles.request.render.Renderer;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.servlet.ServletContext;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class StrutsTilesContainerFactoryTest {
+
+    private StrutsTilesContainerFactory factory;
+    private ApplicationContext applicationContext;
+
+    @Before
+    public void setUp() throws Exception {
+        applicationContext = createMock(ApplicationContext.class);
+        factory = new StrutsTilesContainerFactory();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        reset(applicationContext);
+    }
+
+    @Test
+    public void getSources() {
+        ApplicationResource pathResource = new URLApplicationResource(
+                "/org/apache/tiles/core/config/tiles-defs.xml",
+                Objects.requireNonNull(getClass().getResource("/org/apache/tiles/core/config/tiles-defs.xml"))
+        );
+        ApplicationResource classpathResource = new URLApplicationResource(
+                "/org/apache/tiles/core/config/defs1.xml",
+                Objects.requireNonNull(getClass().getResource("/org/apache/tiles/core/config/defs1.xml"))
+        );
+        expect(applicationContext.getInitParams()).andReturn(Collections.emptyMap());
+        expect(applicationContext.getResources("/WEB-INF/**/tiles*.xml")).andReturn(Collections.singleton(pathResource));
+        expect(applicationContext.getResources("classpath*:META-INF/**/tiles*.xml")).andReturn(Collections.singleton(classpathResource));
+        replay(applicationContext);
+
+        List<ApplicationResource> resources = factory.getSources(applicationContext);
+        assertEquals("The urls list is not two-sized", 2, resources.size());
+        assertEquals("The URL is not correct", pathResource, resources.get(0));
+        assertEquals("The URL is not correct", classpathResource, resources.get(1));
+    }
+
+    @Test
+    public void createAttributeEvaluatorFactory() {
+        ServletContext servletContext = createMock(ServletContext.class);
+        expect(applicationContext.getContext()).andReturn(servletContext).anyTimes();
+        replay(applicationContext);
+
+        LocaleResolver resolver = factory.createLocaleResolver(applicationContext);
+        AttributeEvaluatorFactory attributeEvaluatorFactory = factory.createAttributeEvaluatorFactory(
+                applicationContext, resolver);
+        assertTrue("The class of the evaluator is not correct",
+                attributeEvaluatorFactory.getAttributeEvaluator((String) null) instanceof DirectAttributeEvaluator);
+        assertTrue("The class of the evaluator is not correct",
+                attributeEvaluatorFactory.getAttributeEvaluator("S2") instanceof StrutsAttributeEvaluator);
+        assertTrue("The class of the evaluator is not correct",
+                attributeEvaluatorFactory.getAttributeEvaluator("OGNL") instanceof OGNLAttributeEvaluator);
+        assertTrue("The class of the evaluator is not correct",
+                attributeEvaluatorFactory.getAttributeEvaluator("I18N") instanceof I18NAttributeEvaluator);
+    }
+
+    @Test
+    public void createPreparerFactory() {
+        PreparerFactory preparerFactory = factory.createPreparerFactory(applicationContext);
+        assertTrue("The class of the preparer factory is not correct", preparerFactory instanceof BasicPreparerFactory);
+    }
+
+    @Test
+    public void testCreateDefaultAttributeRenderer() {
+        TilesContainer container = createMock(TilesContainer.class);
+        AttributeEvaluatorFactory attributeEvaluatorFactory = createMock(AttributeEvaluatorFactory.class);
+        BasicRendererFactory rendererFactory = createMock(BasicRendererFactory.class);
+        Renderer stringRenderer = createMock(Renderer.class);
+        Renderer templateRenderer = createMock(Renderer.class);
+        Renderer definitionRenderer = createMock(Renderer.class);
+
+        expect(rendererFactory.getRenderer("string")).andReturn(stringRenderer);
+        expect(rendererFactory.getRenderer("template")).andReturn(templateRenderer);
+        expect(rendererFactory.getRenderer("definition")).andReturn(definitionRenderer);
+        expect(rendererFactory.getRenderer("freemarker")).andReturn(definitionRenderer);
+
+        replay(container, attributeEvaluatorFactory, rendererFactory);
+        Renderer renderer = factory.createDefaultAttributeRenderer(rendererFactory, applicationContext, container,
+                attributeEvaluatorFactory);
+        assertTrue("The default renderer class is not correct", renderer instanceof ChainedDelegateRenderer);
+        verify(container, attributeEvaluatorFactory, rendererFactory);
+    }
+
+}
\ No newline at end of file