You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by be...@apache.org on 2021/01/08 12:24:15 UTC

[tapestry-5] branch 5.6.x updated (c2b64cf -> 81fd65b)

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

benw pushed a change to branch 5.6.x
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git.


    from c2b64cf  TAP5-2656: CSS URL rewriting still throws exceptions
     new 033b227  TAP5-2657: blacklist for manifest autoloaded modules
     new 81fd65b  TAP5-2658: tapestry-func Tuple custom hashCode on values

The 2 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:
 .../main/java/org/apache/tapestry5/func/Tuple.java |  14 +++
 .../java/org/apache/tapestry5/func/TupleTests.java |  12 +++
 .../org/apache/tapestry5/ioc/IOCUtilities.java     |  37 ++++++-
 .../groovy/ioc/specs/ManifestProcessingSpec.groovy | 115 +++++++++++++++++++++
 ...{ReloadAwareModule.java => ManifestModule.java} |  14 ++-
 tapestry-ioc/src/test/realjar/META-INF/MANIFEST.MF |   7 ++
 6 files changed, 192 insertions(+), 7 deletions(-)
 copy tapestry-ioc/src/test/java/com/example/{ReloadAwareModule.java => ManifestModule.java} (67%)
 create mode 100644 tapestry-ioc/src/test/realjar/META-INF/MANIFEST.MF


[tapestry-5] 02/02: TAP5-2658: tapestry-func Tuple custom hashCode on values

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

benw pushed a commit to branch 5.6.x
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git

commit 81fd65b4bd8be6f8eccfd4bfdbc2043f6813af0d
Author: Benjamin Weidig <be...@netzgut.net>
AuthorDate: Fri Jan 8 13:17:06 2021 +0100

    TAP5-2658: tapestry-func Tuple custom hashCode on values
---
 .../src/main/java/org/apache/tapestry5/func/Tuple.java     | 14 ++++++++++++++
 .../test/java/org/apache/tapestry5/func/TupleTests.java    | 12 ++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/tapestry-func/src/main/java/org/apache/tapestry5/func/Tuple.java b/tapestry-func/src/main/java/org/apache/tapestry5/func/Tuple.java
index 86625f3..ff19eea 100644
--- a/tapestry-func/src/main/java/org/apache/tapestry5/func/Tuple.java
+++ b/tapestry-func/src/main/java/org/apache/tapestry5/func/Tuple.java
@@ -14,6 +14,8 @@
 
 package org.apache.tapestry5.func;
 
+import java.util.Objects;
+
 /**
  * A Tuple holds two values of two different types.
  * 
@@ -89,6 +91,18 @@ public class Tuple<A, B>
     }
 
     /**
+     * Returns a hash code value for the tuple, based on its values.
+     *
+     * @return a hash code value for this tuple.
+     * @since 5.6.2
+     */
+    @Override
+    public int hashCode()
+    {
+        return Objects.hash(this.first, this.second);
+    }
+
+    /**
      * The heart of {@link #equals(Object)}; the other object is the same class as this object.
      * 
      * @param other
diff --git a/tapestry-func/src/test/java/org/apache/tapestry5/func/TupleTests.java b/tapestry-func/src/test/java/org/apache/tapestry5/func/TupleTests.java
index 283387b..3eadf37 100644
--- a/tapestry-func/src/test/java/org/apache/tapestry5/func/TupleTests.java
+++ b/tapestry-func/src/test/java/org/apache/tapestry5/func/TupleTests.java
@@ -55,4 +55,16 @@ public class TupleTests extends BaseFuncTest
     {
         assertTrue(t.equals(Tuple.create("tapestry", 5)));
     }
+
+    @Test
+    public void equivalent_tuples_have_equal_hashcode()
+    {
+        assertTrue(t.hashCode() == Tuple.create("tapestry", 5).hashCode());
+    }
+
+    @Test
+    public void unequal_values_have_different_hashcode()
+    {
+        assertFalse(t.hashCode() == Tuple.create("tapestry", 4).hashCode());
+    }
 }


[tapestry-5] 01/02: TAP5-2657: blacklist for manifest autoloaded modules

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

benw pushed a commit to branch 5.6.x
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git

commit 033b227ee277ec6777de0ea2c5d0a20420ba457f
Author: Benjamin Weidig <be...@netzgut.net>
AuthorDate: Thu Jan 7 15:54:17 2021 +0100

    TAP5-2657: blacklist for manifest autoloaded modules
---
 .../org/apache/tapestry5/ioc/IOCUtilities.java     |  37 ++++++-
 .../groovy/ioc/specs/ManifestProcessingSpec.groovy | 115 +++++++++++++++++++++
 .../src/test/java/com/example/ManifestModule.java  |  29 ++++++
 tapestry-ioc/src/test/realjar/META-INF/MANIFEST.MF |   7 ++
 4 files changed, 184 insertions(+), 4 deletions(-)

diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/IOCUtilities.java b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/IOCUtilities.java
index 27892ef..639d890 100644
--- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/IOCUtilities.java
+++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/IOCUtilities.java
@@ -18,7 +18,10 @@ import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.util.Collections;
 import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
 import java.util.jar.Manifest;
 
 import static org.apache.tapestry5.ioc.IOCConstants.MODULE_BUILDER_MANIFEST_ENTRY_NAME;
@@ -57,6 +60,8 @@ public final class IOCUtilities
      * Scans the classpath for JAR Manifests that contain the Tapestry-Module-Classes attribute and adds each
      * corresponding class to the RegistryBuilder. In addition, looks for a system property named "tapestry.modules" and
      * adds all of those modules as well. The tapestry.modules approach is intended for development.
+     * To prevent auto-loading of Manifest-defined modules the system property named "tapestry.manifest-modules-blacklist"
+     * can be used.
      *
      * @param builder
      *         the builder to which modules will be added
@@ -65,6 +70,19 @@ public final class IOCUtilities
      */
     public static void addDefaultModules(RegistryBuilder builder)
     {
+        Set<String> blacklistedManifestModules = new HashSet<>();
+        String modulesBlacklist = System.getProperty("tapestry.manifest-modules-blacklist");
+        if (modulesBlacklist != null)
+        {
+            String[] blacklistedClassnames = modulesBlacklist.split(",");
+
+            
+            for (String classname : blacklistedClassnames)
+            {
+                blacklistedManifestModules.add(classname.trim());
+            }
+        }
+
         try
         {
             Enumeration<URL> urls = builder.getClassLoader().getResources("META-INF/MANIFEST.MF");
@@ -73,7 +91,7 @@ public final class IOCUtilities
             {
                 URL url = urls.nextElement();
 
-                addModulesInManifest(builder, url);
+                addModulesInManifest(builder, url, blacklistedManifestModules);
             }
 
             addModulesInList(builder, System.getProperty("tapestry.modules"));
@@ -84,7 +102,7 @@ public final class IOCUtilities
         }
     }
 
-    private static void addModulesInManifest(RegistryBuilder builder, URL url)
+    private static void addModulesInManifest(RegistryBuilder builder, URL url, Set<String> blacklist)
     {
         InputStream in = null;
 
@@ -102,7 +120,7 @@ public final class IOCUtilities
 
             String list = mf.getMainAttributes().getValue(MODULE_BUILDER_MANIFEST_ENTRY_NAME);
 
-            addModulesInList(builder, list);
+            addModulesInList(builder, list, blacklist);
         } catch (RuntimeException ex)
         {
             fail = ex;
@@ -123,13 +141,24 @@ public final class IOCUtilities
 
     static void addModulesInList(RegistryBuilder builder, String list)
     {
+        addModulesInList(builder, list, Collections.emptySet());
+    }
+
+    static void addModulesInList(RegistryBuilder builder, String list, Set<String> blacklist)
+    {
         if (list == null) return;
 
         String[] classnames = list.split(",");
 
         for (String classname : classnames)
         {
-            builder.add(classname.trim());
+            String trimmedClassname = classname.trim();
+            if (blacklist != null && blacklist.contains(trimmedClassname))
+            {
+                continue;
+            }
+
+            builder.add(trimmedClassname);
         }
     }
 
diff --git a/tapestry-ioc/src/test/groovy/ioc/specs/ManifestProcessingSpec.groovy b/tapestry-ioc/src/test/groovy/ioc/specs/ManifestProcessingSpec.groovy
index 8c13398..ac76bc5 100644
--- a/tapestry-ioc/src/test/groovy/ioc/specs/ManifestProcessingSpec.groovy
+++ b/tapestry-ioc/src/test/groovy/ioc/specs/ManifestProcessingSpec.groovy
@@ -1,7 +1,10 @@
 package ioc.specs
 
+import com.example.ManifestModule
+
 import org.apache.tapestry5.ioc.IOCUtilities
 import org.apache.tapestry5.ioc.RegistryBuilder
+
 import spock.lang.Specification
 
 class ManifestProcessingSpec extends Specification {
@@ -31,7 +34,119 @@ class ManifestProcessingSpec extends Specification {
 
     e.message.contains "Exception loading module(s) from manifest"
     e.message.contains "Failure loading Tapestry IoC module class does.not.exist.Module"
+  }
+
+  def "valid class in manifest"() {
+
+    given:
+
+    File jar = new File("src/test/realjar")
+
+    expect:
+
+    // This is more to verify the module execution environment
+    jar.exists()
+    jar.isDirectory()
+
+    when:
+
+    URL url = jar.toURL()
+    URLClassLoader loader = new URLClassLoader([url] as URL[], Thread.currentThread().contextClassLoader)
+
+    RegistryBuilder builder = new RegistryBuilder(loader)
+
+    IOCUtilities.addDefaultModules(builder)
+
+    def reg = builder.build()
+    reg.performRegistryStartup()
+
+    then:
+
+    noExceptionThrown()
+
+    ManifestModule.startupCalled == true
+
+    cleanup:
+
+    ManifestModule.startupCalled = false
+  }
+
+  def "blacklisted manifest module not loaded"() {
+
+    given:
+
+    File jar = new File("src/test/realjar")
+
+    def props = System.getProperties()
+    props.setProperty("tapestry.manifest-modules-blacklist", "does.not.ExistModule,com.example.ManifestModule")
+
+    expect:
+
+    // This is more to verify the module execution environment
+    jar.exists()
+    jar.isDirectory()
+
+    when:
 
+    URL url = jar.toURL()
+    URLClassLoader loader = new URLClassLoader([url] as URL[], Thread.currentThread().contextClassLoader)
+
+    RegistryBuilder builder = new RegistryBuilder(loader)
+
+    IOCUtilities.addDefaultModules(builder)
+
+    def reg = builder.build()
+    reg.performRegistryStartup()
+
+    then:
+
+    noExceptionThrown()
+
+    ManifestModule.startupCalled == false
+
+    cleanup:
+
+    props.remove("tapestry.manifest-modules-blacklist")
+    ManifestModule.startupCalled = false
+  }
+
+  def "blacklisted manifest module empty"() {
+
+    given:
+
+    File jar = new File("src/test/realjar")
+
+    def props = System.getProperties()
+    props.setProperty("tapestry.manifest-modules-blacklist", "")
+
+    expect:
+
+    // This is more to verify the module execution environment
+    jar.exists()
+    jar.isDirectory()
+
+    when:
+
+    URL url = jar.toURL()
+    URLClassLoader loader = new URLClassLoader([url] as URL[], Thread.currentThread().contextClassLoader)
+
+    RegistryBuilder builder = new RegistryBuilder(loader)
 
+    IOCUtilities.addDefaultModules(builder)
+
+    def reg = builder.build()
+    reg.performRegistryStartup()
+
+    then:
+
+    noExceptionThrown()
+
+    ManifestModule.startupCalled == true
+
+    cleanup:
+
+    props.remove("tapestry.manifest-modules-blacklist")
+    ManifestModule.startupCalled = false
   }
+
 }
diff --git a/tapestry-ioc/src/test/java/com/example/ManifestModule.java b/tapestry-ioc/src/test/java/com/example/ManifestModule.java
new file mode 100644
index 0000000..b09eec3
--- /dev/null
+++ b/tapestry-ioc/src/test/java/com/example/ManifestModule.java
@@ -0,0 +1,29 @@
+// Copyright 2021 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.
+// 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 com.example;
+
+import org.apache.tapestry5.ioc.annotations.Startup;
+
+public class ManifestModule
+{
+    public static boolean startupCalled = false;
+
+    @Startup
+    public void doStartup()
+    {
+        ManifestModule.startupCalled = true;
+    }
+
+}
diff --git a/tapestry-ioc/src/test/realjar/META-INF/MANIFEST.MF b/tapestry-ioc/src/test/realjar/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..bfcd412
--- /dev/null
+++ b/tapestry-ioc/src/test/realjar/META-INF/MANIFEST.MF
@@ -0,0 +1,7 @@
+Manifest-Version: 1.0
+Archiver-Version: Plexus Archiver
+Created-By: Apache Maven
+Built-By: Ben
+Build-Jdk: 1.8.0_271
+Tapestry-Module-Classes: com.example.ManifestModule
+