You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2013/05/29 19:49:39 UTC

[1/4] git commit: Prevent NPE after deserializing

Updated Branches:
  refs/heads/master 5647c47c9 -> 2f245e694


Prevent NPE after deserializing


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/37798513
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/37798513
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/37798513

Branch: refs/heads/master
Commit: 3779851328b96a73a0f6b8d2b758213f48150398
Parents: 5647c47
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Wed May 29 10:27:57 2013 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Wed May 29 10:27:57 2013 -0700

----------------------------------------------------------------------
 .../BaseOptimizedSessionPersistedObject.java       |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/37798513/tapestry-core/src/main/java/org/apache/tapestry5/BaseOptimizedSessionPersistedObject.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/BaseOptimizedSessionPersistedObject.java b/tapestry-core/src/main/java/org/apache/tapestry5/BaseOptimizedSessionPersistedObject.java
index 2070b39..402328e 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/BaseOptimizedSessionPersistedObject.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/BaseOptimizedSessionPersistedObject.java
@@ -14,6 +14,7 @@
 
 package org.apache.tapestry5;
 
+import java.io.IOException;
 import java.io.Serializable;
 import java.util.concurrent.atomic.AtomicBoolean;
 
@@ -34,6 +35,10 @@ public abstract class BaseOptimizedSessionPersistedObject implements OptimizedSe
 
     private transient AtomicBoolean dirty = new AtomicBoolean(false);
 
+    private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
+        dirty = new AtomicBoolean(false);
+    }
+
     public final boolean checkAndResetDirtyMarker()
     {
         return dirty.getAndSet(false);


[4/4] git commit: Advance version number to 5.4-alpha-6

Posted by hl...@apache.org.
Advance version number to 5.4-alpha-6


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/2f245e69
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/2f245e69
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/2f245e69

Branch: refs/heads/master
Commit: 2f245e694507482829dbd0ab219d152c30656330
Parents: 98e7d96
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Wed May 29 10:39:04 2013 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Wed May 29 10:39:04 2013 -0700

----------------------------------------------------------------------
 build.gradle |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/2f245e69/build.gradle
----------------------------------------------------------------------
diff --git a/build.gradle b/build.gradle
index 15fd545..295906a 100755
--- a/build.gradle
+++ b/build.gradle
@@ -34,7 +34,7 @@ project.version = tapestryVersion()
 def tapestryVersion() {
 
     def major = "5.4"
-    def minor = "-alpha-5"
+    def minor = "-alpha-6"
 
     // When building on the CI server, make sure -SNAPSHOT is appended, as it is a nightly build.
     // When building normally, or for a release, no suffix is desired.


[3/4] git commit: TAP5-2120: Handle relative URLs through root of resource domain

Posted by hl...@apache.org.
TAP5-2120: Handle relative URLs through root of resource domain

Normalize all paths to NOT start with a leading slash


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/98e7d96c
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/98e7d96c
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/98e7d96c

Branch: refs/heads/master
Commit: 98e7d96c44dcd6f8142d158ffb096af67f6bcc24
Parents: 5a42ffe
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Wed May 29 10:30:13 2013 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Wed May 29 10:30:13 2013 -0700

----------------------------------------------------------------------
 .../apache/tapestry5/modules/TapestryModule.java   |    2 +-
 .../ioc/internal/util/AbstractResource.java        |   46 ++-
 .../groovy/ioc/specs/ClasspathResourceSpec.groovy  |  270 ++++++++-------
 3 files changed, 171 insertions(+), 147 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/98e7d96c/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
index 68454d8..833e84f 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
@@ -2007,7 +2007,7 @@ public final class TapestryModule
         // files deleted between scriptaculous releases to be accidentally left lying around).
         // There's also a ClasspathAliasManager contribution based on the path.
 
-        configuration.add("tapestry.asset.root", "classpath:/META-INF/assets/tapestry5");
+        configuration.add("tapestry.asset.root", "classpath:META-INF/assets/tapestry5");
 
         configuration.add(SymbolConstants.SCRIPTACULOUS, "${tapestry.asset.root}/scriptaculous_1_9_0");
 

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/98e7d96c/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/AbstractResource.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/AbstractResource.java b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/AbstractResource.java
index d382ba2..feed8cf 100644
--- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/AbstractResource.java
+++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/AbstractResource.java
@@ -1,4 +1,4 @@
-// Copyright 2006, 2008, 2010, 2011, 2012 The Apache Software Foundation
+// Copyright 2006-2013 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ import java.io.BufferedInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.util.List;
 import java.util.Locale;
 
 /**
@@ -56,7 +57,9 @@ public abstract class AbstractResource extends LockSupport implements Resource
     protected AbstractResource(String path)
     {
         assert path != null;
-        this.path = path;
+
+        // Normalize paths to NOT start with a leading slash
+        this.path = path.startsWith("/") ? path.substring(1) : path;
     }
 
     public final String getPath()
@@ -81,27 +84,32 @@ public abstract class AbstractResource extends LockSupport implements Resource
     public final Resource forFile(String relativePath)
     {
         assert relativePath != null;
-        StringBuilder builder = new StringBuilder(getFolder());
+
+        List<String> terms = CollectionFactory.newList();
+
+        for (String term : getFolder().split("/"))
+        {
+            terms.add(term);
+        }
 
         for (String term : relativePath.split("/"))
         {
             // This will occur if the relative path contains sequential slashes
 
-            if (term.equals(""))
-                continue;
-
-            if (term.equals("."))
+            if (term.equals("") || term.equals("."))
+            {
                 continue;
+            }
 
             if (term.equals(".."))
             {
-                int slashx = builder.lastIndexOf("/");
-
-                // TODO: slashx < 0 (i.e., no slash)
+                if (terms.isEmpty())
+                {
+                    throw new IllegalStateException(String.format("Relative path '%s' for %s would go above root.", relativePath, this));
+                }
 
-                // Trim path to content before the slash
+                terms.remove(terms.size() - 1);
 
-                builder.setLength(slashx);
                 continue;
             }
 
@@ -110,13 +118,19 @@ public abstract class AbstractResource extends LockSupport implements Resource
             // name of a folder, since a Resource should be a file within
             // a folder.
 
-            if (builder.length() > 0)
-                builder.append("/");
+            terms.add(term);
+        }
+
+        StringBuilder path = new StringBuilder(100);
+        String sep = "";
 
-            builder.append(term);
+        for (String term : terms)
+        {
+            path.append(sep).append(term);
+            sep = "/";
         }
 
-        return createResource(builder.toString());
+        return createResource(path.toString());
     }
 
     public final Resource forLocale(Locale locale)

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/98e7d96c/tapestry-ioc/src/test/groovy/ioc/specs/ClasspathResourceSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/ioc/specs/ClasspathResourceSpec.groovy b/tapestry-ioc/src/test/groovy/ioc/specs/ClasspathResourceSpec.groovy
index fc96e0e..2442bf3 100644
--- a/tapestry-ioc/src/test/groovy/ioc/specs/ClasspathResourceSpec.groovy
+++ b/tapestry-ioc/src/test/groovy/ioc/specs/ClasspathResourceSpec.groovy
@@ -5,222 +5,232 @@ import spock.lang.Specification
 
 class ClasspathResourceSpec extends Specification {
 
-  static final String RESOURCE_TXT_CONTENT = "content from resource.txt";
+    static final String RESOURCE_TXT_CONTENT = "content from resource.txt";
 
-  static final String FOLDER = "org/apache/tapestry5/ioc/internal/util";
+    static final String FOLDER = "org/apache/tapestry5/ioc/internal/util";
 
-  static final String PATH = FOLDER + "/resource.txt";
-  public static final String SAME_FOLDER_RESOURCE_CONTENT = "content from same-folder resource"
+    static final String PATH = FOLDER + "/resource.txt";
+    public static final String SAME_FOLDER_RESOURCE_CONTENT = "content from same-folder resource"
 
-  def content(resource) {
-    resource.toURL().text.trim()
-  }
+    def content(resource) {
+        resource.toURL().text.trim()
+    }
 
-  def "get URL of resource"() {
-    def r = new ClasspathResource(PATH)
+    def "get URL of resource"() {
+        def r = new ClasspathResource(PATH)
 
-    expect:
+        expect:
 
-    content(r) == RESOURCE_TXT_CONTENT
-  }
+        content(r) == RESOURCE_TXT_CONTENT
+    }
 
-  def "expend path from root resource yields same URL as full path"() {
-    def r = new ClasspathResource("").forFile(PATH)
+    def "expand path from root resource yields same URL as full path"() {
+        def r = new ClasspathResource("").forFile(PATH)
 
-    expect:
+        expect:
 
-    content(r) == RESOURCE_TXT_CONTENT
-  }
+        content(r) == RESOURCE_TXT_CONTENT
+    }
 
-  def "a leading slash is ignored for the root resource"() {
-    def r = new ClasspathResource("/").forFile(PATH)
+    def "a leading slash is ignored for the root resource"() {
+        def r = new ClasspathResource("/").forFile(PATH)
 
-    expect:
+        expect:
 
-    content(r) == RESOURCE_TXT_CONTENT
-  }
+        content(r) == RESOURCE_TXT_CONTENT
+    }
 
-  def "a leading slash is ignored for the path from the root resource"() {
-    def r = new ClasspathResource("/").forFile("/" + PATH)
+    def "a leading slash is ignored for the path from the root resource"() {
+        def r = new ClasspathResource("/").forFile("/" + PATH)
 
-    expect:
+        expect:
 
-    content(r) == RESOURCE_TXT_CONTENT
-  }
+        content(r) == RESOURCE_TXT_CONTENT
+    }
 
-  def "path and file for resource are available"() {
-    when:
+    def "path and file for resource are available"() {
+        when:
 
-    def r = new ClasspathResource(PATH)
+        def r = new ClasspathResource(PATH)
 
-    then:
+        then:
 
-    r.folder == FOLDER
-    r.file == "resource.txt"
-  }
+        r.folder == FOLDER
+        r.file == "resource.txt"
+    }
 
-  def "access a file in the same folder"() {
-    when:
+    def "access a file in the same folder"() {
+        when:
 
-    def r = new ClasspathResource(PATH)
-    def n = r.forFile("same-folder.txt")
+        def r = new ClasspathResource(PATH)
+        def n = r.forFile("same-folder.txt")
 
-    then:
+        then:
 
-    content(n) == SAME_FOLDER_RESOURCE_CONTENT
-  }
+        content(n) == SAME_FOLDER_RESOURCE_CONTENT
+    }
 
-  def "access a file in same folder using using ./ relative path"() {
-    when:
+    def "access a file in same folder using using ./ relative path"() {
+        when:
 
-    def r = new ClasspathResource(PATH)
-    def n = r.forFile("./same-folder.txt")
+        def r = new ClasspathResource(PATH)
+        def n = r.forFile("./same-folder.txt")
 
-    then:
+        then:
 
-    content(n) == SAME_FOLDER_RESOURCE_CONTENT
+        content(n) == SAME_FOLDER_RESOURCE_CONTENT
 
-  }
+    }
 
-  def "multiple slashes treated as a single slash"() {
-    when:
+    def "multiple slashes treated as a single slash"() {
+        when:
 
-    def r = new ClasspathResource(PATH)
-    def n = r.forFile("././/.///same-folder.txt")
+        def r = new ClasspathResource(PATH)
+        def n = r.forFile("././/.///same-folder.txt")
 
-    then:
+        then:
 
-    content(n) == SAME_FOLDER_RESOURCE_CONTENT
+        content(n) == SAME_FOLDER_RESOURCE_CONTENT
 
-  }
+    }
 
-  def "file in subfolder"() {
-    when:
+    def "file in subfolder"() {
+        when:
 
-    def r = new ClasspathResource(PATH)
-    def n = r.forFile("sub/sub-folder.txt")
+        def r = new ClasspathResource(PATH)
+        def n = r.forFile("sub/sub-folder.txt")
 
-    then:
+        then:
 
-    content(n) == "content from sub-folder resource"
+        content(n) == "content from sub-folder resource"
 
-  }
+    }
 
-  def "reference same resource yields same instance"() {
-    when:
+    def "reference same resource yields same instance"() {
+        when:
 
-    def r = new ClasspathResource(PATH)
+        def r = new ClasspathResource(PATH)
 
 
-    then:
+        then:
 
-    r.forFile("../util/resource.txt").is(r)
-  }
+        r.forFile("../util/resource.txt").is(r)
+    }
 
-  def "access file in parent folder"() {
-    def r = new ClasspathResource(PATH)
+    def "access file in parent folder"() {
+        def r = new ClasspathResource(PATH)
 
-    when:
+        when:
 
-    def n = r.forFile("../parent-folder.txt")
+        def n = r.forFile("../parent-folder.txt")
 
-    then:
+        then:
 
-    content(n) == "content from parent-folder resource"
-  }
+        content(n) == "content from parent-folder resource"
+    }
 
-  def "toString() is meaningful"() {
-    expect:
+    def "toString() is meaningful"() {
+        expect:
 
-    new ClasspathResource(PATH).toString() == "classpath:$PATH"
-  }
+        new ClasspathResource(PATH).toString() == "classpath:$PATH"
+    }
 
-  def "URL for a missing resource is null"() {
-    when:
+    def "URL for a missing resource is null"() {
+        when:
 
-    def r = new ClasspathResource("$FOLDER/missing-resource.txt")
+        def r = new ClasspathResource("$FOLDER/missing-resource.txt")
 
-    then:
+        then:
 
-    r.toURL() == null
-  }
+        r.toURL() == null
+    }
 
-  def "localization of a resource"() {
+    def "localization of a resource"() {
 
-    def r = new ClasspathResource(PATH)
+        def r = new ClasspathResource(PATH)
 
-    when:
+        when:
 
-    def l = r.forLocale(Locale.FRENCH)
+        def l = r.forLocale(Locale.FRENCH)
 
-    then:
+        then:
 
-    content(l) == "french content"
-  }
+        content(l) == "french content"
+    }
 
-  def "localization finds closest match"() {
-    def r = new ClasspathResource(PATH)
+    def "localization finds closest match"() {
+        def r = new ClasspathResource(PATH)
 
-    when:
+        when:
 
-    def l = r.forLocale(Locale.CANADA_FRENCH)
+        def l = r.forLocale(Locale.CANADA_FRENCH)
 
-    then:
+        then:
 
-    content(l) == "french content"
-  }
+        content(l) == "french content"
+    }
 
-  def "localization to base resource"() {
-    def r = new ClasspathResource(PATH)
+    def "localization to base resource"() {
+        def r = new ClasspathResource(PATH)
 
-    when:
+        when:
 
-    def l = r.forLocale(Locale.JAPANESE)
+        def l = r.forLocale(Locale.JAPANESE)
 
-    then:
+        then:
 
-    l.is(r)
-  }
+        l.is(r)
+    }
 
-  def "localization of missing resource is null"() {
-    def r = new ClasspathResource("$FOLDER/missing-resource.txt")
+    def "localization of missing resource is null"() {
+        def r = new ClasspathResource("$FOLDER/missing-resource.txt")
 
-    expect:
+        expect:
 
-    r.forLocale(Locale.KOREAN) == null
+        r.forLocale(Locale.KOREAN) == null
 
-  }
+    }
 
-  def "extending to new extension that matches old extension yields same Resource"() {
-    def r = new ClasspathResource(PATH)
+    def "extending to new extension that matches old extension yields same Resource"() {
+        def r = new ClasspathResource(PATH)
 
-    when:
+        when:
 
-    def n = r.withExtension("txt")
+        def n = r.withExtension("txt")
 
-    then:
+        then:
 
-    n.is(r)
-  }
+        n.is(r)
+    }
 
-  def "extending with a new extension"() {
-    def r = new ClasspathResource(PATH)
+    def "extending with a new extension"() {
+        def r = new ClasspathResource(PATH)
 
-    when:
+        when:
 
-    def n = r.withExtension("ext")
+        def n = r.withExtension("ext")
 
-    then:
+        then:
 
-    content(n) == "ext content"
-  }
+        content(n) == "ext content"
+    }
 
-  def "a new extension that does not exist is a null URL"() {
-    def r = new ClasspathResource(PATH)
+    def "a new extension that does not exist is a null URL"() {
+        def r = new ClasspathResource(PATH)
 
 
-    expect:
+        expect:
+
+        r.withExtension("does-not-exist").toURL() == null
+    }
+
+    def "up dir from root folder resolves correctly"() {
+
+        def r = new ClasspathResource("root/a-file")
+
+        expect:
+
+        r.forFile("../foo/bar").toString() == "classpath:foo/bar"
+    }
 
-    r.withExtension("does-not-exist").toURL() == null
-  }
 }


[2/4] git commit: Disable tests that break build (due to timing concerns)

Posted by hl...@apache.org.
Disable tests that break build (due to timing concerns)


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/5a42ffe9
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/5a42ffe9
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/5a42ffe9

Branch: refs/heads/master
Commit: 5a42ffe98e0f98ef0795fc49540a1c5f50f80d2d
Parents: 3779851
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Wed May 29 10:28:42 2013 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Wed May 29 10:28:42 2013 -0700

----------------------------------------------------------------------
 .../integration/app1/ZoneRefreshTest.java          |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/5a42ffe9/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneRefreshTest.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneRefreshTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneRefreshTest.java
index 7980475..fa8e91b 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneRefreshTest.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneRefreshTest.java
@@ -15,13 +15,13 @@
 package org.apache.tapestry5.integration.app1;
 
 import org.apache.tapestry5.integration.TapestryCoreTestCase;
-import org.apache.tapestry5.test.SeleniumTestCase;
 import org.testng.annotations.Test;
 
+// Disabled these tests because they are time sensitive and cause build failures.
 public class ZoneRefreshTest extends TapestryCoreTestCase
 {
 
-    @Test
+    @Test(enabled = false)
     public void test_if_zone_with_event_handler_returning_void_works() throws Exception
     {
         openBaseURL();
@@ -35,7 +35,7 @@ public class ZoneRefreshTest extends TapestryCoreTestCase
         checkZoneValues("zone", 3);
     }
 
-    @Test
+    @Test(enabled = false)
     public void test_if_zone_with_event_handler_returning_zone_works() throws Exception
     {
         openBaseURL();


[4/4] git commit: Advance version number to 5.4-alpha-6

Posted by hl...@apache.org.
Advance version number to 5.4-alpha-6


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/2f245e69
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/2f245e69
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/2f245e69

Branch: refs/heads/master
Commit: 2f245e694507482829dbd0ab219d152c30656330
Parents: 98e7d96
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Wed May 29 10:39:04 2013 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Wed May 29 10:39:04 2013 -0700

----------------------------------------------------------------------
 build.gradle |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/2f245e69/build.gradle
----------------------------------------------------------------------
diff --git a/build.gradle b/build.gradle
index 15fd545..295906a 100755
--- a/build.gradle
+++ b/build.gradle
@@ -34,7 +34,7 @@ project.version = tapestryVersion()
 def tapestryVersion() {
 
     def major = "5.4"
-    def minor = "-alpha-5"
+    def minor = "-alpha-6"
 
     // When building on the CI server, make sure -SNAPSHOT is appended, as it is a nightly build.
     // When building normally, or for a release, no suffix is desired.


[3/4] git commit: TAP5-2120: Handle relative URLs through root of resource domain

Posted by hl...@apache.org.
TAP5-2120: Handle relative URLs through root of resource domain

Normalize all paths to NOT start with a leading slash


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/98e7d96c
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/98e7d96c
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/98e7d96c

Branch: refs/heads/master
Commit: 98e7d96c44dcd6f8142d158ffb096af67f6bcc24
Parents: 5a42ffe
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Wed May 29 10:30:13 2013 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Wed May 29 10:30:13 2013 -0700

----------------------------------------------------------------------
 .../apache/tapestry5/modules/TapestryModule.java   |    2 +-
 .../ioc/internal/util/AbstractResource.java        |   46 ++-
 .../groovy/ioc/specs/ClasspathResourceSpec.groovy  |  270 ++++++++-------
 3 files changed, 171 insertions(+), 147 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/98e7d96c/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
index 68454d8..833e84f 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
@@ -2007,7 +2007,7 @@ public final class TapestryModule
         // files deleted between scriptaculous releases to be accidentally left lying around).
         // There's also a ClasspathAliasManager contribution based on the path.
 
-        configuration.add("tapestry.asset.root", "classpath:/META-INF/assets/tapestry5");
+        configuration.add("tapestry.asset.root", "classpath:META-INF/assets/tapestry5");
 
         configuration.add(SymbolConstants.SCRIPTACULOUS, "${tapestry.asset.root}/scriptaculous_1_9_0");
 

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/98e7d96c/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/AbstractResource.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/AbstractResource.java b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/AbstractResource.java
index d382ba2..feed8cf 100644
--- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/AbstractResource.java
+++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/AbstractResource.java
@@ -1,4 +1,4 @@
-// Copyright 2006, 2008, 2010, 2011, 2012 The Apache Software Foundation
+// Copyright 2006-2013 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ import java.io.BufferedInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.util.List;
 import java.util.Locale;
 
 /**
@@ -56,7 +57,9 @@ public abstract class AbstractResource extends LockSupport implements Resource
     protected AbstractResource(String path)
     {
         assert path != null;
-        this.path = path;
+
+        // Normalize paths to NOT start with a leading slash
+        this.path = path.startsWith("/") ? path.substring(1) : path;
     }
 
     public final String getPath()
@@ -81,27 +84,32 @@ public abstract class AbstractResource extends LockSupport implements Resource
     public final Resource forFile(String relativePath)
     {
         assert relativePath != null;
-        StringBuilder builder = new StringBuilder(getFolder());
+
+        List<String> terms = CollectionFactory.newList();
+
+        for (String term : getFolder().split("/"))
+        {
+            terms.add(term);
+        }
 
         for (String term : relativePath.split("/"))
         {
             // This will occur if the relative path contains sequential slashes
 
-            if (term.equals(""))
-                continue;
-
-            if (term.equals("."))
+            if (term.equals("") || term.equals("."))
+            {
                 continue;
+            }
 
             if (term.equals(".."))
             {
-                int slashx = builder.lastIndexOf("/");
-
-                // TODO: slashx < 0 (i.e., no slash)
+                if (terms.isEmpty())
+                {
+                    throw new IllegalStateException(String.format("Relative path '%s' for %s would go above root.", relativePath, this));
+                }
 
-                // Trim path to content before the slash
+                terms.remove(terms.size() - 1);
 
-                builder.setLength(slashx);
                 continue;
             }
 
@@ -110,13 +118,19 @@ public abstract class AbstractResource extends LockSupport implements Resource
             // name of a folder, since a Resource should be a file within
             // a folder.
 
-            if (builder.length() > 0)
-                builder.append("/");
+            terms.add(term);
+        }
+
+        StringBuilder path = new StringBuilder(100);
+        String sep = "";
 
-            builder.append(term);
+        for (String term : terms)
+        {
+            path.append(sep).append(term);
+            sep = "/";
         }
 
-        return createResource(builder.toString());
+        return createResource(path.toString());
     }
 
     public final Resource forLocale(Locale locale)

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/98e7d96c/tapestry-ioc/src/test/groovy/ioc/specs/ClasspathResourceSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/ioc/specs/ClasspathResourceSpec.groovy b/tapestry-ioc/src/test/groovy/ioc/specs/ClasspathResourceSpec.groovy
index fc96e0e..2442bf3 100644
--- a/tapestry-ioc/src/test/groovy/ioc/specs/ClasspathResourceSpec.groovy
+++ b/tapestry-ioc/src/test/groovy/ioc/specs/ClasspathResourceSpec.groovy
@@ -5,222 +5,232 @@ import spock.lang.Specification
 
 class ClasspathResourceSpec extends Specification {
 
-  static final String RESOURCE_TXT_CONTENT = "content from resource.txt";
+    static final String RESOURCE_TXT_CONTENT = "content from resource.txt";
 
-  static final String FOLDER = "org/apache/tapestry5/ioc/internal/util";
+    static final String FOLDER = "org/apache/tapestry5/ioc/internal/util";
 
-  static final String PATH = FOLDER + "/resource.txt";
-  public static final String SAME_FOLDER_RESOURCE_CONTENT = "content from same-folder resource"
+    static final String PATH = FOLDER + "/resource.txt";
+    public static final String SAME_FOLDER_RESOURCE_CONTENT = "content from same-folder resource"
 
-  def content(resource) {
-    resource.toURL().text.trim()
-  }
+    def content(resource) {
+        resource.toURL().text.trim()
+    }
 
-  def "get URL of resource"() {
-    def r = new ClasspathResource(PATH)
+    def "get URL of resource"() {
+        def r = new ClasspathResource(PATH)
 
-    expect:
+        expect:
 
-    content(r) == RESOURCE_TXT_CONTENT
-  }
+        content(r) == RESOURCE_TXT_CONTENT
+    }
 
-  def "expend path from root resource yields same URL as full path"() {
-    def r = new ClasspathResource("").forFile(PATH)
+    def "expand path from root resource yields same URL as full path"() {
+        def r = new ClasspathResource("").forFile(PATH)
 
-    expect:
+        expect:
 
-    content(r) == RESOURCE_TXT_CONTENT
-  }
+        content(r) == RESOURCE_TXT_CONTENT
+    }
 
-  def "a leading slash is ignored for the root resource"() {
-    def r = new ClasspathResource("/").forFile(PATH)
+    def "a leading slash is ignored for the root resource"() {
+        def r = new ClasspathResource("/").forFile(PATH)
 
-    expect:
+        expect:
 
-    content(r) == RESOURCE_TXT_CONTENT
-  }
+        content(r) == RESOURCE_TXT_CONTENT
+    }
 
-  def "a leading slash is ignored for the path from the root resource"() {
-    def r = new ClasspathResource("/").forFile("/" + PATH)
+    def "a leading slash is ignored for the path from the root resource"() {
+        def r = new ClasspathResource("/").forFile("/" + PATH)
 
-    expect:
+        expect:
 
-    content(r) == RESOURCE_TXT_CONTENT
-  }
+        content(r) == RESOURCE_TXT_CONTENT
+    }
 
-  def "path and file for resource are available"() {
-    when:
+    def "path and file for resource are available"() {
+        when:
 
-    def r = new ClasspathResource(PATH)
+        def r = new ClasspathResource(PATH)
 
-    then:
+        then:
 
-    r.folder == FOLDER
-    r.file == "resource.txt"
-  }
+        r.folder == FOLDER
+        r.file == "resource.txt"
+    }
 
-  def "access a file in the same folder"() {
-    when:
+    def "access a file in the same folder"() {
+        when:
 
-    def r = new ClasspathResource(PATH)
-    def n = r.forFile("same-folder.txt")
+        def r = new ClasspathResource(PATH)
+        def n = r.forFile("same-folder.txt")
 
-    then:
+        then:
 
-    content(n) == SAME_FOLDER_RESOURCE_CONTENT
-  }
+        content(n) == SAME_FOLDER_RESOURCE_CONTENT
+    }
 
-  def "access a file in same folder using using ./ relative path"() {
-    when:
+    def "access a file in same folder using using ./ relative path"() {
+        when:
 
-    def r = new ClasspathResource(PATH)
-    def n = r.forFile("./same-folder.txt")
+        def r = new ClasspathResource(PATH)
+        def n = r.forFile("./same-folder.txt")
 
-    then:
+        then:
 
-    content(n) == SAME_FOLDER_RESOURCE_CONTENT
+        content(n) == SAME_FOLDER_RESOURCE_CONTENT
 
-  }
+    }
 
-  def "multiple slashes treated as a single slash"() {
-    when:
+    def "multiple slashes treated as a single slash"() {
+        when:
 
-    def r = new ClasspathResource(PATH)
-    def n = r.forFile("././/.///same-folder.txt")
+        def r = new ClasspathResource(PATH)
+        def n = r.forFile("././/.///same-folder.txt")
 
-    then:
+        then:
 
-    content(n) == SAME_FOLDER_RESOURCE_CONTENT
+        content(n) == SAME_FOLDER_RESOURCE_CONTENT
 
-  }
+    }
 
-  def "file in subfolder"() {
-    when:
+    def "file in subfolder"() {
+        when:
 
-    def r = new ClasspathResource(PATH)
-    def n = r.forFile("sub/sub-folder.txt")
+        def r = new ClasspathResource(PATH)
+        def n = r.forFile("sub/sub-folder.txt")
 
-    then:
+        then:
 
-    content(n) == "content from sub-folder resource"
+        content(n) == "content from sub-folder resource"
 
-  }
+    }
 
-  def "reference same resource yields same instance"() {
-    when:
+    def "reference same resource yields same instance"() {
+        when:
 
-    def r = new ClasspathResource(PATH)
+        def r = new ClasspathResource(PATH)
 
 
-    then:
+        then:
 
-    r.forFile("../util/resource.txt").is(r)
-  }
+        r.forFile("../util/resource.txt").is(r)
+    }
 
-  def "access file in parent folder"() {
-    def r = new ClasspathResource(PATH)
+    def "access file in parent folder"() {
+        def r = new ClasspathResource(PATH)
 
-    when:
+        when:
 
-    def n = r.forFile("../parent-folder.txt")
+        def n = r.forFile("../parent-folder.txt")
 
-    then:
+        then:
 
-    content(n) == "content from parent-folder resource"
-  }
+        content(n) == "content from parent-folder resource"
+    }
 
-  def "toString() is meaningful"() {
-    expect:
+    def "toString() is meaningful"() {
+        expect:
 
-    new ClasspathResource(PATH).toString() == "classpath:$PATH"
-  }
+        new ClasspathResource(PATH).toString() == "classpath:$PATH"
+    }
 
-  def "URL for a missing resource is null"() {
-    when:
+    def "URL for a missing resource is null"() {
+        when:
 
-    def r = new ClasspathResource("$FOLDER/missing-resource.txt")
+        def r = new ClasspathResource("$FOLDER/missing-resource.txt")
 
-    then:
+        then:
 
-    r.toURL() == null
-  }
+        r.toURL() == null
+    }
 
-  def "localization of a resource"() {
+    def "localization of a resource"() {
 
-    def r = new ClasspathResource(PATH)
+        def r = new ClasspathResource(PATH)
 
-    when:
+        when:
 
-    def l = r.forLocale(Locale.FRENCH)
+        def l = r.forLocale(Locale.FRENCH)
 
-    then:
+        then:
 
-    content(l) == "french content"
-  }
+        content(l) == "french content"
+    }
 
-  def "localization finds closest match"() {
-    def r = new ClasspathResource(PATH)
+    def "localization finds closest match"() {
+        def r = new ClasspathResource(PATH)
 
-    when:
+        when:
 
-    def l = r.forLocale(Locale.CANADA_FRENCH)
+        def l = r.forLocale(Locale.CANADA_FRENCH)
 
-    then:
+        then:
 
-    content(l) == "french content"
-  }
+        content(l) == "french content"
+    }
 
-  def "localization to base resource"() {
-    def r = new ClasspathResource(PATH)
+    def "localization to base resource"() {
+        def r = new ClasspathResource(PATH)
 
-    when:
+        when:
 
-    def l = r.forLocale(Locale.JAPANESE)
+        def l = r.forLocale(Locale.JAPANESE)
 
-    then:
+        then:
 
-    l.is(r)
-  }
+        l.is(r)
+    }
 
-  def "localization of missing resource is null"() {
-    def r = new ClasspathResource("$FOLDER/missing-resource.txt")
+    def "localization of missing resource is null"() {
+        def r = new ClasspathResource("$FOLDER/missing-resource.txt")
 
-    expect:
+        expect:
 
-    r.forLocale(Locale.KOREAN) == null
+        r.forLocale(Locale.KOREAN) == null
 
-  }
+    }
 
-  def "extending to new extension that matches old extension yields same Resource"() {
-    def r = new ClasspathResource(PATH)
+    def "extending to new extension that matches old extension yields same Resource"() {
+        def r = new ClasspathResource(PATH)
 
-    when:
+        when:
 
-    def n = r.withExtension("txt")
+        def n = r.withExtension("txt")
 
-    then:
+        then:
 
-    n.is(r)
-  }
+        n.is(r)
+    }
 
-  def "extending with a new extension"() {
-    def r = new ClasspathResource(PATH)
+    def "extending with a new extension"() {
+        def r = new ClasspathResource(PATH)
 
-    when:
+        when:
 
-    def n = r.withExtension("ext")
+        def n = r.withExtension("ext")
 
-    then:
+        then:
 
-    content(n) == "ext content"
-  }
+        content(n) == "ext content"
+    }
 
-  def "a new extension that does not exist is a null URL"() {
-    def r = new ClasspathResource(PATH)
+    def "a new extension that does not exist is a null URL"() {
+        def r = new ClasspathResource(PATH)
 
 
-    expect:
+        expect:
+
+        r.withExtension("does-not-exist").toURL() == null
+    }
+
+    def "up dir from root folder resolves correctly"() {
+
+        def r = new ClasspathResource("root/a-file")
+
+        expect:
+
+        r.forFile("../foo/bar").toString() == "classpath:foo/bar"
+    }
 
-    r.withExtension("does-not-exist").toURL() == null
-  }
 }


[2/4] git commit: Disable tests that break build (due to timing concerns)

Posted by hl...@apache.org.
Disable tests that break build (due to timing concerns)


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/5a42ffe9
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/5a42ffe9
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/5a42ffe9

Branch: refs/heads/master
Commit: 5a42ffe98e0f98ef0795fc49540a1c5f50f80d2d
Parents: 3779851
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Wed May 29 10:28:42 2013 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Wed May 29 10:28:42 2013 -0700

----------------------------------------------------------------------
 .../integration/app1/ZoneRefreshTest.java          |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/5a42ffe9/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneRefreshTest.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneRefreshTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneRefreshTest.java
index 7980475..fa8e91b 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneRefreshTest.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneRefreshTest.java
@@ -15,13 +15,13 @@
 package org.apache.tapestry5.integration.app1;
 
 import org.apache.tapestry5.integration.TapestryCoreTestCase;
-import org.apache.tapestry5.test.SeleniumTestCase;
 import org.testng.annotations.Test;
 
+// Disabled these tests because they are time sensitive and cause build failures.
 public class ZoneRefreshTest extends TapestryCoreTestCase
 {
 
-    @Test
+    @Test(enabled = false)
     public void test_if_zone_with_event_handler_returning_void_works() throws Exception
     {
         openBaseURL();
@@ -35,7 +35,7 @@ public class ZoneRefreshTest extends TapestryCoreTestCase
         checkZoneValues("zone", 3);
     }
 
-    @Test
+    @Test(enabled = false)
     public void test_if_zone_with_event_handler_returning_zone_works() throws Exception
     {
         openBaseURL();