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

yasserzamani pushed a commit to branch struts-2-5-x
in repository https://gitbox.apache.org/repos/asf/struts.git


The following commit(s) were added to refs/heads/struts-2-5-x by this push:
     new b0dd7c1  include ref in path as WW-5011 workaround (#353)
b0dd7c1 is described below

commit b0dd7c1c0dd099b9a43d735c9e5d54996920d281
Author: Yasser Zamani <yasserzam...@apache.org>
AuthorDate: Tue May 28 09:53:27 2019 +0430

    include ref in path as WW-5011 workaround (#353)
    
    * include ref in path for StrutsApplicationResource as WW-5011 workaround
    
    * add license to newly added xml files in previous commit
    
    * WW-5011 include ref in path via .toURI().getPath()
    
    * WW-5011 check protocol and not throw exception due to lazy file existence
    
    * decrease log file size to pass travis build
---
 .travis.yml                                        |  4 +--
 core/src/test/resources/log4j2.xml                 |  1 -
 .../struts2/tiles/StrutsApplicationResource.java   | 31 ++++++++++++++--
 .../tiles/StrutsApplicationResourceTest.java}      | 42 ++++++++--------------
 .../tiles/src/test/resources/emptyTiles###2.xml    | 14 +-------
 .../tiles/src/test/resources/emptyTiles.xml        | 14 +-------
 6 files changed, 48 insertions(+), 58 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 38e83f6..d07d990 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,12 +8,12 @@ jdk:
   - oraclejdk11
 
 install: true
-script: mvn test -DskipAssembly
+script: mvn test -DskipAssembly -B
 
 after_success:
   # TODO delete following if statement after fix of 
https://github.com/cobertura/cobertura/issues/271
   - if [ "$TRAVIS_JDK_VERSION" == "openjdk8" ] || [ "$TRAVIS_JDK_VERSION" == 
"oraclejdk8" ]; then
-      mvn cobertura:cobertura 
org.eluder.coveralls:coveralls-maven-plugin:report 
com.updateimpact:updateimpact-maven-plugin:submit 
-Ptravis-coveralls,update-impact -DskipAssembly;
+      mvn cobertura:cobertura 
org.eluder.coveralls:coveralls-maven-plugin:report 
com.updateimpact:updateimpact-maven-plugin:submit 
-Ptravis-coveralls,update-impact -DskipAssembly -B;
     else
       echo "Not reporting coverage for $TRAVIS_JDK_VERSION due to 
incompatibility or to save performance";
     fi;
diff --git a/core/src/test/resources/log4j2.xml 
b/core/src/test/resources/log4j2.xml
index 84e813a..4c4061d 100644
--- a/core/src/test/resources/log4j2.xml
+++ b/core/src/test/resources/log4j2.xml
@@ -29,6 +29,5 @@
         <Root level="info">
             <AppenderRef ref="STDOUT"/>
         </Root>
-        <Logger name="org.apache.struts2.views.xslt" level="debug"/>
     </Loggers>
 </Configuration>
\ No newline at end of file
diff --git 
a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsApplicationResource.java
 
b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsApplicationResource.java
index 1f636f9..1ad6ab9 100644
--- 
a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsApplicationResource.java
+++ 
b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsApplicationResource.java
@@ -19,19 +19,47 @@
 package org.apache.struts2.tiles;
 
 import org.apache.tiles.request.locale.PostfixedApplicationResource;
+import org.apache.tiles.request.locale.URLApplicationResource;
 
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URI;
 import java.net.URL;
 
 public class StrutsApplicationResource extends PostfixedApplicationResource {
 
     private final URL url;
+    private final File file;
+
+    /**
+     * fixes WW-5011
+     * @return file path for "file" protocol elsewhere url path as before to 
keep backward-compatibility
+     * @see URLApplicationResource#getFile(URL)
+     */
+    private static String getFilePath(URL url) {
+        String path = url.getPath();
+        if (!"file".equals(url.getProtocol())) {
+            return path;
+        }
+        try {
+            // fixes WW-5011 because includes ref in path - like 
URLApplicationResource#getFile(URL)
+            path = (new URI(url.toExternalForm())).getSchemeSpecificPart();
+        } catch (Exception e) {
+            // fallback solution
+            if (url.getRef() != null && !new File(path).exists()) {
+                // it's like WW-5011
+                path += "#" + url.getRef();
+            }
+        }
+
+        return path;
+    }
 
     public StrutsApplicationResource(URL url) {
-        super(url.getPath());
+        super(getFilePath(url));
         this.url = url;
+        this.file = new File(getFilePath(url));
     }
 
     @Override
@@ -41,7 +69,6 @@ public class StrutsApplicationResource extends 
PostfixedApplicationResource {
 
     @Override
     public long getLastModified() throws IOException {
-        File file = new File(url.getPath());
         if (file.exists()) {
             return file.lastModified();
         }
diff --git 
a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsApplicationResource.java
 
b/plugins/tiles/src/test/java/org/apache/struts2/tiles/StrutsApplicationResourceTest.java
similarity index 51%
copy from 
plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsApplicationResource.java
copy to 
plugins/tiles/src/test/java/org/apache/struts2/tiles/StrutsApplicationResourceTest.java
index 1f636f9..7b80c5b 100644
--- 
a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsApplicationResource.java
+++ 
b/plugins/tiles/src/test/java/org/apache/struts2/tiles/StrutsApplicationResourceTest.java
@@ -18,38 +18,26 @@
  */
 package org.apache.struts2.tiles;
 
-import org.apache.tiles.request.locale.PostfixedApplicationResource;
+import org.apache.tiles.request.ApplicationResource;
+import org.junit.Assert;
+import org.junit.Test;
 
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
 import java.net.URL;
 
-public class StrutsApplicationResource extends PostfixedApplicationResource {
+public class StrutsApplicationResourceTest {
 
-    private final URL url;
+    @Test
+    public void testWW5011fix() throws Exception {
+        URL resource = 
getClass().getClassLoader().getResource("emptyTiles.xml");
+        ApplicationResource ar = new StrutsApplicationResource(resource);
+        Assert.assertNotEquals(0, ar.getLastModified());
 
-    public StrutsApplicationResource(URL url) {
-        super(url.getPath());
-        this.url = url;
-    }
-
-    @Override
-    public InputStream getInputStream() throws IOException {
-        return url.openStream();
-    }
-
-    @Override
-    public long getLastModified() throws IOException {
-        File file = new File(url.getPath());
-        if (file.exists()) {
-            return file.lastModified();
-        }
-        return 0;
-    }
+        resource = 
getClass().getClassLoader().getResource("emptyTiles###2.xml");
+        ar = new StrutsApplicationResource(resource);
+        Assert.assertNotEquals(0, ar.getLastModified());
 
-    @Override
-    public String toString() {
-        return "Resource " + getLocalePath() + " at " + url.toString();
+        resource = getClass().getClassLoader().getResource("emptyTiles.xml");
+        ar = new StrutsApplicationResource(new URL(resource + "#ref1"));
+        Assert.assertNotEquals(0, ar.getLastModified());
     }
 }
diff --git a/core/src/test/resources/log4j2.xml 
b/plugins/tiles/src/test/resources/emptyTiles###2.xml
similarity index 68%
copy from core/src/test/resources/log4j2.xml
copy to plugins/tiles/src/test/resources/emptyTiles###2.xml
index 84e813a..cf2d8b3 100644
--- a/core/src/test/resources/log4j2.xml
+++ b/plugins/tiles/src/test/resources/emptyTiles###2.xml
@@ -19,16 +19,4 @@
  * under the License.
  */
 -->
-<Configuration>
-    <Appenders>
-        <Console name="STDOUT" target="SYSTEM_OUT">
-            <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
-        </Console>
-    </Appenders>
-    <Loggers>
-        <Root level="info">
-            <AppenderRef ref="STDOUT"/>
-        </Root>
-        <Logger name="org.apache.struts2.views.xslt" level="debug"/>
-    </Loggers>
-</Configuration>
\ No newline at end of file
+<tiles-definitions></tiles-definitions>
\ No newline at end of file
diff --git a/core/src/test/resources/log4j2.xml 
b/plugins/tiles/src/test/resources/emptyTiles.xml
similarity index 68%
copy from core/src/test/resources/log4j2.xml
copy to plugins/tiles/src/test/resources/emptyTiles.xml
index 84e813a..cf2d8b3 100644
--- a/core/src/test/resources/log4j2.xml
+++ b/plugins/tiles/src/test/resources/emptyTiles.xml
@@ -19,16 +19,4 @@
  * under the License.
  */
 -->
-<Configuration>
-    <Appenders>
-        <Console name="STDOUT" target="SYSTEM_OUT">
-            <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
-        </Console>
-    </Appenders>
-    <Loggers>
-        <Root level="info">
-            <AppenderRef ref="STDOUT"/>
-        </Root>
-        <Logger name="org.apache.struts2.views.xslt" level="debug"/>
-    </Loggers>
-</Configuration>
\ No newline at end of file
+<tiles-definitions></tiles-definitions>
\ No newline at end of file

Reply via email to