You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by th...@apache.org on 2020/12/16 01:12:32 UTC

[tapestry-5] branch master updated: TAP5-2654: Remove Asset2 by merging it into Asset

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

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


The following commit(s) were added to refs/heads/master by this push:
     new e464b01  TAP5-2654: Remove Asset2 by merging it into Asset
e464b01 is described below

commit e464b015f1a776acafe372f66cc128f6b42d1a9c
Author: Thiago H. de Paula Figueiredo <th...@arsmachina.com.br>
AuthorDate: Tue Dec 15 22:12:11 2020 -0300

    TAP5-2654: Remove Asset2 by merging it into Asset
---
 .../src/main/java/org/apache/tapestry5/Asset.java  | 17 ++++++++++
 .../src/main/java/org/apache/tapestry5/Asset2.java | 38 ----------------------
 .../tapestry5/internal/TapestryInternalUtils.java  | 37 ---------------------
 .../tapestry5/internal/bindings/AssetBinding.java  | 10 +++---
 .../tapestry5/internal/services/AbstractAsset.java |  4 +--
 .../apache/tapestry5/test/TapestryTestCase.java    |  5 ---
 .../internal/TapestryInternalUtilsTest.java        | 36 --------------------
 7 files changed, 23 insertions(+), 124 deletions(-)

diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/Asset.java b/tapestry-core/src/main/java/org/apache/tapestry5/Asset.java
index 4108a7d..7036b9f 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/Asset.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/Asset.java
@@ -23,6 +23,8 @@ import org.apache.tapestry5.commons.Resource;
  *
  * Release 5.1.0.0 introduced {@link org.apache.tapestry5.Asset2}, which extends this interface with an additional
  * method.
+ * 
+ * Release 5.7.0 merged Asset2 into Asset and Asset2 got removed.
  *
  * @see org.apache.tapestry5.services.AssetPathConverter
  */
@@ -53,4 +55,19 @@ public interface Asset
      */
     Resource getResource();
 
+    /**
+     * Returns true if the Asset is invariant (meaning that it returns the same value from {@link Asset#toClientURL()}
+     * at all times). Most Assets are invariant. Assets that are used as binding values will be cached more aggressively by Tapestry if they are
+     * invariant. This default implementation returns <code>false</code>
+     *
+     * @return true if invariant
+     * @see org.apache.tapestry5.services.AssetPathConverter#isInvariant()
+     * @see Binding#isInvariant()
+     * @since 5.1.0.0 (in Asset2), 5.7.0 (in Asset).
+     */
+    default boolean isInvariant() 
+    {
+        return false;
+    }
+
 }
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/Asset2.java b/tapestry-core/src/main/java/org/apache/tapestry5/Asset2.java
deleted file mode 100644
index f2e715d..0000000
--- a/tapestry-core/src/main/java/org/apache/tapestry5/Asset2.java
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2009 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 org.apache.tapestry5;
-
-/**
- * Extension to {@link org.apache.tapestry5.Asset} that adds a method to determine if the asset is invariant or not.
- * {@link org.apache.tapestry5.services.AssetFactory} instances should ideally return Asset2 objects, not Asset. This is
- * only of primary interest to the {@link org.apache.tapestry5.internal.bindings.AssetBindingFactory}, as it determines
- * the invariance of the binding from the asset (and assumes variant unless the asset object implements this
- * interface).
- *
- * @since 5.1.0.0
- */
-public interface Asset2 extends Asset
-{
-    /**
-     * Returns true if the Asset is invariant (meaning that it returns the same value from {@link Asset#toClientURL()}
-     * at all times). Most Assets are invariant. Assets that are used as binding values will be cached more aggressively by Tapestry if they are
-     * invariant.
-     *
-     * @return true if invariant
-     * @see org.apache.tapestry5.services.AssetPathConverter#isInvariant()
-     * @see Binding#isInvariant()
-     */
-    boolean isInvariant();
-}
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java
index e1fd13f..7744216 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java
@@ -389,43 +389,6 @@ public class TapestryInternalUtils
         return true;
     }
 
-    /**
-     * Converts an Asset to an Asset2 if necessary. When actually wrapping an Asset as an Asset2, the asset is assumed
-     * to be variant (i.e., not cacheable).
-     *
-     * @since 5.1.0.0
-     */
-    public static Asset2 toAsset2(final Asset asset)
-    {
-        if (asset instanceof Asset2)
-            return (Asset2) asset;
-
-        return new Asset2()
-        {
-            /** Returns false. */
-            public boolean isInvariant()
-            {
-                return false;
-            }
-
-            public Resource getResource()
-            {
-                return asset.getResource();
-            }
-
-            public String toClientURL()
-            {
-                return asset.toClientURL();
-            }
-
-            @Override
-            public String toString()
-            {
-                return asset.toString();
-            }
-        };
-    }
-
     public static InternalPropertyConduit toInternalPropertyConduit(final PropertyConduit conduit)
     {
         if (conduit instanceof InternalPropertyConduit)
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/bindings/AssetBinding.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/bindings/AssetBinding.java
index 0ec556d..fb99fc8 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/bindings/AssetBinding.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/bindings/AssetBinding.java
@@ -1,4 +1,4 @@
-// Copyright 2009 The Apache Software Foundation
+// Copyright 2009, 2020 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.
@@ -15,28 +15,26 @@
 package org.apache.tapestry5.internal.bindings;
 
 import org.apache.tapestry5.Asset;
-import org.apache.tapestry5.Asset2;
 import org.apache.tapestry5.commons.Location;
-import org.apache.tapestry5.internal.TapestryInternalUtils;
 
 public class AssetBinding extends AbstractBinding
 {
     private final String description;
 
-    private final Asset2 asset;
+    private final Asset asset;
 
     public AssetBinding(Location location, String description, Asset asset)
     {
         super(location);
 
         this.description = description;
-        this.asset = TapestryInternalUtils.toAsset2(asset);
+        this.asset = asset;
     }
 
     @Override
     public Class getBindingType()
     {
-        return Asset2.class;
+        return Asset.class;
     }
 
     public Object get()
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AbstractAsset.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AbstractAsset.java
index 813e215..20e88ac 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AbstractAsset.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AbstractAsset.java
@@ -14,14 +14,14 @@
 
 package org.apache.tapestry5.internal.services;
 
-import org.apache.tapestry5.Asset2;
+import org.apache.tapestry5.Asset;
 
 /**
  * Base class for assets.
  *
  * @since 5.1.0.0
  */
-public abstract class AbstractAsset implements Asset2
+public abstract class AbstractAsset implements Asset
 {
     private final boolean invariant;
 
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java b/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java
index 3b000c9..cb53579 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java
@@ -1041,11 +1041,6 @@ public abstract class TapestryTestCase extends IOCTestCase
         return newMock(ComponentRequestHandler.class);
     }
 
-    protected final Asset2 mockAsset2()
-    {
-        return newMock(Asset2.class);
-    }
-
     /**
      * @since 5.2.0
      */
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/internal/TapestryInternalUtilsTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/internal/TapestryInternalUtilsTest.java
index 258ccdf..8f70ab5 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/internal/TapestryInternalUtilsTest.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/internal/TapestryInternalUtilsTest.java
@@ -383,42 +383,6 @@ public class TapestryInternalUtilsTest extends InternalBaseTestCase
     }
 
     @Test
-    public void to_asset2_no_wrapper_needed()
-    {
-        Asset2 asset2 = mockAsset2();
-
-        replay();
-
-        assertSame(TapestryInternalUtils.toAsset2(asset2), asset2);
-
-        verify();
-    }
-
-    @Test
-    public void asset_to_asset2_wrapper()
-    {
-        Asset asset = mockAsset();
-        Resource resource = mockResource();
-        String clientURL = "clientURL";
-
-        train_toClientURL(asset, clientURL);
-
-        expect(asset.getResource()).andReturn(resource);
-
-        replay();
-
-        Asset2 asset2 = TapestryInternalUtils.toAsset2(asset);
-
-        assertFalse(asset2.isInvariant());
-
-        assertSame(asset2.toClientURL(), clientURL);
-        assertSame(asset2.toString(), asset.toString());
-        assertSame(asset2.getResource(), resource);
-
-        verify();
-    }
-
-    @Test
     public void to_internal_property_conduit_no_wrapper_needed()
     {
         InternalPropertyConduit conduit2 = newMock(InternalPropertyConduit.class);