diff --git a/.travis.yml b/.travis.yml
index 38e83f6dfd..d07d9909f5 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 84e813aba3..4c4061dbfa 100644
--- a/core/src/test/resources/log4j2.xml
+++ b/core/src/test/resources/log4j2.xml
@@ -29,6 +29,5 @@
-
\ 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 1f636f9ca5..1ad6ab95e6 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 InputStream getInputStream() throws IOException {
@Override
public long getLastModified() throws IOException {
- File file = new File(url.getPath());
if (file.exists()) {
return file.lastModified();
}
diff --git a/plugins/tiles/src/test/java/org/apache/struts2/tiles/StrutsApplicationResourceTest.java b/plugins/tiles/src/test/java/org/apache/struts2/tiles/StrutsApplicationResourceTest.java
new file mode 100644
index 0000000000..7b80c5bce3
--- /dev/null
+++ b/plugins/tiles/src/test/java/org/apache/struts2/tiles/StrutsApplicationResourceTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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.request.ApplicationResource;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.net.URL;
+
+public class StrutsApplicationResourceTest {
+
+ @Test
+ public void testWW5011fix() throws Exception {
+ URL resource = getClass().getClassLoader().getResource("emptyTiles.xml");
+ ApplicationResource ar = new StrutsApplicationResource(resource);
+ Assert.assertNotEquals(0, ar.getLastModified());
+
+ resource = getClass().getClassLoader().getResource("emptyTiles###2.xml");
+ ar = new StrutsApplicationResource(resource);
+ Assert.assertNotEquals(0, ar.getLastModified());
+
+ resource = getClass().getClassLoader().getResource("emptyTiles.xml");
+ ar = new StrutsApplicationResource(new URL(resource + "#ref1"));
+ Assert.assertNotEquals(0, ar.getLastModified());
+ }
+}
diff --git a/plugins/tiles/src/test/resources/emptyTiles###2.xml b/plugins/tiles/src/test/resources/emptyTiles###2.xml
new file mode 100644
index 0000000000..cf2d8b319d
--- /dev/null
+++ b/plugins/tiles/src/test/resources/emptyTiles###2.xml
@@ -0,0 +1,22 @@
+
+
+
\ No newline at end of file
diff --git a/plugins/tiles/src/test/resources/emptyTiles.xml b/plugins/tiles/src/test/resources/emptyTiles.xml
new file mode 100644
index 0000000000..cf2d8b319d
--- /dev/null
+++ b/plugins/tiles/src/test/resources/emptyTiles.xml
@@ -0,0 +1,22 @@
+
+
+
\ No newline at end of file