http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/154dac95/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleManagerImpl.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleManagerImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleManagerImpl.java index 4bf9597..95642ce 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleManagerImpl.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleManagerImpl.java @@ -28,7 +28,8 @@ import org.apache.tapestry5.json.JSONArray; import org.apache.tapestry5.json.JSONLiteral; import org.apache.tapestry5.json.JSONObject; import org.apache.tapestry5.services.AssetSource; -import org.apache.tapestry5.services.PathConstructor; +import org.apache.tapestry5.services.ResponseCompressionAnalyzer; +import org.apache.tapestry5.services.assets.AssetPathConstructor; import org.apache.tapestry5.services.assets.StreamableResourceSource; import org.apache.tapestry5.services.javascript.JavaScriptModuleConfiguration; import org.apache.tapestry5.services.javascript.ModuleManager; @@ -39,10 +40,13 @@ import java.util.Set; public class ModuleManagerImpl implements ModuleManager { - private final String requireConfig; + + private final ResponseCompressionAnalyzer compressionAnalyzer; private final Asset requireJS; + private final Map<String, JavaScriptModuleConfiguration> configuration; + private final Messages globalMessages; private final boolean compactJSON; @@ -56,7 +60,11 @@ public class ModuleManagerImpl implements ModuleManager // Note: ConcurrentHashMap does not support null as a value, alas. We use classpathRoot as a null. private final Map<String, Resource> cache = CollectionFactory.newConcurrentMap(); - public ModuleManagerImpl(PathConstructor constructor, + private final boolean devMode; + + private final AssetPathConstructor assetPathConstructor; + + public ModuleManagerImpl(ResponseCompressionAnalyzer compressionAnalyzer, AssetSource assetSource, @Path("${" + SymbolConstants.REQUIRE_JS + "}") Asset requireJS, @@ -66,23 +74,28 @@ public class ModuleManagerImpl implements ModuleManager @Symbol(SymbolConstants.COMPACT_JSON) boolean compactJSON, @Symbol(SymbolConstants.PRODUCTION_MODE) - boolean productionMode) + boolean productionMode, + AssetPathConstructor assetPathConstructor) { + this.compressionAnalyzer = compressionAnalyzer; this.requireJS = requireJS; + this.configuration = configuration; this.globalMessages = globalMessages; this.compactJSON = compactJSON; + this.assetPathConstructor = assetPathConstructor; - this.requireConfig = buildRequireJSConfig(constructor.constructClientPath("modules", ""), configuration, !productionMode); + this.devMode = !productionMode; classpathRoot = assetSource.resourceForPath(""); - extensions = CollectionFactory.newSet("js"); extensions.addAll(streamableResourceSource.fileExtensionsForContentType("text/javascript")); } - private String buildRequireJSConfig(String baseURL, Map<String, JavaScriptModuleConfiguration> configuration, boolean devMode) + private String buildRequireJSConfig() { + String baseURL = getBaseURL(); + JSONObject config = new JSONObject("baseUrl", baseURL); // In DevMode, wait up to five minutes for a script, as the developer may be using the debugger. @@ -110,6 +123,11 @@ public class ModuleManagerImpl implements ModuleManager return String.format("requirejs.config(%s);\n", config.toString(compactJSON)); } + private String getBaseURL() + { + return assetPathConstructor.constructAssetPath("module", compressionAnalyzer.isGZipSupported()); + } + private void addModuleToConfig(JSONObject config, String name, JavaScriptModuleConfiguration module) { JSONObject shimConfig = config.in("shim"); @@ -159,7 +177,10 @@ public class ModuleManagerImpl implements ModuleManager Element element = body.element("script", "type", "text/javascript"); - element.raw(requireConfig); + // Build it each time because we don't know if the client supports GZip or not, and + // (in development mode) URLs for some referenced assets could change (due to URLs + // containing a checksum on the resource content). + element.raw(buildRequireJSConfig()); StringBuilder content = new StringBuilder(1000); @@ -199,7 +220,6 @@ public class ModuleManagerImpl implements ModuleManager return resource; } - // Tack on a fake extension; otherwise modules whose name includes a '.' get mangled // by Resource.withExtension(). String baseName = String.format("/META-INF/modules/%s.EXT", moduleName);
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/154dac95/tapestry-core/src/main/java/org/apache/tapestry5/internal/util/VirtualResource.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/util/VirtualResource.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/util/VirtualResource.java index 0fc0738..bb1061f 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/util/VirtualResource.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/util/VirtualResource.java @@ -30,7 +30,7 @@ import java.util.Locale; * the contents of the virtual resource. * * @see org.apache.tapestry5.services.javascript.ModuleManager - * @see org.apache.tapestry5.internal.services.javascript.ModuleDispatcher + * @see org.apache.tapestry5.internal.services.javascript.ModuleAssetRequestHandler * @since 5.4 */ public abstract class VirtualResource implements Resource http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/154dac95/tapestry-core/src/main/java/org/apache/tapestry5/services/AssetAlias.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/AssetAlias.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/AssetAlias.java new file mode 100644 index 0000000..15ee1b7 --- /dev/null +++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/AssetAlias.java @@ -0,0 +1,32 @@ +// Copyright 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. +// 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.services; + +/** + * Identifies a virtual foldre and a path within that folder. + * + * @since 5.4 + * @deprecated Deprecated in 5.4 (see notes in {@link ClasspathAssetAliasManager}). + */ +public class AssetAlias +{ + public final String virtualFolder, path; + + public AssetAlias(String virtualFolder, String path) + { + this.virtualFolder = virtualFolder; + this.path = path; + } +} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/154dac95/tapestry-core/src/main/java/org/apache/tapestry5/services/ClasspathAssetAliasManager.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/ClasspathAssetAliasManager.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/ClasspathAssetAliasManager.java index e85234e..b540780 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/services/ClasspathAssetAliasManager.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/ClasspathAssetAliasManager.java @@ -41,22 +41,22 @@ import java.util.Map; * <p/> * Tapestry automatically contributes a number of mappings: for the application root package itself (as alias "app") and * for each library (via {@link ComponentClassResolver#getFolderToPackageMapping()}); + * + * @deprecated Deprecated in 5.4, with no replacement. This will no longer be used in Tapestry 5.5, as all classpath assets + * will need to be under the {@code META-INF/assets} folder (but may be maintained for compatibility reasons until 5.6). */ @UsesMappedConfiguration(String.class) public interface ClasspathAssetAliasManager { /** - * Takes a resource path to a classpath resource and adds the asset path prefix to the path. May also convert part - * of the path to an alias (based on the manager's configuration). - * <p/> - * Note: this method's signature changed incompatibly in Tapestry 5.4. + * Takes a classpath resource and determines the proper alias for it based on the mappings contributed to the service. * * @param resource * classpath resource * @return URL ready to send to the client */ - @IncompatibleChange(release = "5.4", details = "parameter changed from String to Resource") - String toClientURL(Resource resource); + @IncompatibleChange(release = "5.4", details = "parameter changed from String to Resource, renamed from toClientURL() to better identify purpose") + AssetAlias extractAssetAlias(Resource resource); /** * Returns the mappings used by the service: the keys are the folder aliases (i.e, "corelib") http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/154dac95/tapestry-core/src/main/java/org/apache/tapestry5/services/ResponseCompressionAnalyzer.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/ResponseCompressionAnalyzer.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/ResponseCompressionAnalyzer.java index ffe0239..d9a61b2 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/services/ResponseCompressionAnalyzer.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/ResponseCompressionAnalyzer.java @@ -1,4 +1,4 @@ -// Copyright 2009, 2011, 2012 The Apache Software Foundation +// Copyright 2009-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. @@ -17,9 +17,10 @@ package org.apache.tapestry5.services; import org.apache.tapestry5.services.assets.CompressionAnalyzer; /** - * Used to determine if the client supports GZIP compression of the response. + * Used to determine if the client supports GZip compression of the response. * * @see CompressionAnalyzer + * @see org.apache.tapestry5.SymbolConstants#GZIP_COMPRESSION_ENABLED * @since 5.1.0.0 */ public interface ResponseCompressionAnalyzer @@ -31,4 +32,14 @@ public interface ResponseCompressionAnalyzer * @return true if gzip is supported by client */ boolean isGZipSupported(); + + /** + * Uses {@link CompressionAnalyzer} to determine if the content is compressable, but only if the request + * indicates the client supports compression. + * + * @param contentType + * @return true if the content can be compressed for the current request + * @since 5.4 + */ + boolean isGZipEnabled(String contentType); } http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/154dac95/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetPathConstructor.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetPathConstructor.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetPathConstructor.java index 17fb2b7..ffb4d2c 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetPathConstructor.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetPathConstructor.java @@ -14,14 +14,13 @@ package org.apache.tapestry5.services.assets; -import org.apache.tapestry5.ioc.Resource; import org.apache.tapestry5.ioc.annotations.IncompatibleChange; import java.io.IOException; /** - * Encapsulates the logic or creating the path portion of an asset URL, including - * the application version. + * Encapsulates the logic or creating the path portion of an asset URL, including hooking the {@link org.apache.tapestry5.services.AssetPathConverter} + * into the generation. * * @see org.apache.tapestry5.services.PathConstructor * @since 5.2.0 @@ -30,31 +29,38 @@ public interface AssetPathConstructor { /** * Constructs an asset URL path from the virtual folder and path (within the virtual folder). + * After constructing the string (and honoring the {@link org.apache.tapestry5.SymbolConstants#ASSET_URL_FULL_QUALIFIED} + * symbol), the result is passed through the {@link org.apache.tapestry5.services.AssetPathConverter}. * * @param virtualFolder * corresponds to a {@link AssetRequestHandler} contributed to the AssetDispatcher service * @param path - * within the virtual folder (should <em>not</em> start with a slash). May be the empty string. - * When non-blank, separated from the rest of the path with a slash. + * a path that can be used to identify the underlying {@link org.apache.tapestry5.ioc.Resource} or + * or re-acquire the {@link StreamableResource}; this will be the final portion of the URL, after + * the appropriate prefix (based on whether the resource is compressed or not) and the checksum for the + * resource * @param resource - * underlying resource for the asset path, used to compute checksums (since 5.4) + * underlying resource for the asset path; the checksum portion of the URL is obtained from the resource * @return path portion of asset URL, which is everything needed by the {@link org.apache.tapestry5.internal.services.AssetDispatcher} * to find and stream the resource + * @see StreamableResourceSource */ - @IncompatibleChange(release = "5.4", details = "resource parameter added, IOException may not be thrown") - String constructAssetPath(String virtualFolder, String path, Resource resource) throws IOException; + @IncompatibleChange(release = "5.4", details = "resource parameter added, IOException may now be thrown") + String constructAssetPath(String virtualFolder, String path, StreamableResource resource) throws IOException; /** - * Constructs an asset path for a aggregated {@linkplain org.apache.tapestry5.services.javascript.JavaScriptStack stack}. + * Generates a base URL for a virtual folder (this exists mostly for {@link org.apache.tapestry5.services.javascript.ModuleManager} + * and {@link org.apache.tapestry5.internal.services.javascript.ModuleAssetRequestHandler}). Uses much of the same logic + * as {@link #constructAssetPath(String, String, StreamableResource)}, including + * {@link org.apache.tapestry5.SymbolConstants#ASSET_URL_FULL_QUALIFIED} and the {@link org.apache.tapestry5.services.AssetPathConverter}. * - * @param localeName - * name of the locale - * @param path - * based on the name of the core stack - * @param resource - * the aggregated stack (used when generating the checksum) - * @return path that identifies the checksum, locale, and path + * @param virtualFolder + * folder that will be used to select a {@link } + * @param compressed + * build a path that indicates GZip compression + * @return complete path * @since 5.4 */ - String constructStackAssetPath(String localeName, String path, StreamableResource resource) throws IOException; + String constructAssetPath(String virtualFolder, boolean compressed); + } http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/154dac95/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetRequestHandler.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetRequestHandler.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetRequestHandler.java index c0acce3..e1eb7ed 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetRequestHandler.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetRequestHandler.java @@ -49,6 +49,9 @@ public interface AssetRequestHandler * The handler should return true if it provided a response. If the handler returns false, this indicates that the * extra path did not identify a known asset (virtual or otherwise) and the AssetDispatcher service should send a * {@link HttpServletResponse#SC_NOT_FOUND} response. + * <p/> + * Starting in Tapestry 5.4, the handler is informed by the {@link org.apache.tapestry5.services.AssetRequestDispatcher} + * whether or not the content should be compressed (this is determined based on information in the URL). * * @param request * incoming asset request @@ -56,7 +59,8 @@ public interface AssetRequestHandler * used to send a response to client * @param extraPath * additional path to identify the specific asset - * @return true if request handler, false if asset not found + * @return true if request was handled (and response sent), false if asset not found + * @see org.apache.tapestry5.TapestryConstants#COMPRESS_CONTENT */ boolean handleAssetRequest(Request request, Response response, String extraPath) throws IOException; } http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/154dac95/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetsModule.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetsModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetsModule.java index 797e464..d727792 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetsModule.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetsModule.java @@ -75,7 +75,7 @@ public class AssetsModule configuration.add(SymbolConstants.COMBINE_SCRIPTS, SymbolConstants.PRODUCTION_MODE_VALUE); configuration.add(SymbolConstants.ASSET_URL_FULL_QUALIFIED, false); - configuration.add(SymbolConstants.ASSET_PATH_PREFIX, "assets"); + configuration.add(SymbolConstants.ASSET_PATH_PREFIX, "asset"); configuration.add(SymbolConstants.COMPRESSED_ASSET_PATH_PREFIX, "${tapestry.asset-path-prefix}.gz"); } @@ -86,10 +86,11 @@ public class AssetsModule public StreamableResourceSource enableCompression(StreamableResourceSource delegate, @Symbol(SymbolConstants.GZIP_COMPRESSION_ENABLED) boolean gzipEnabled, @Symbol(SymbolConstants.MIN_GZIP_SIZE) - int compressionCutoff) + int compressionCutoff, + AssetChecksumGenerator checksumGenerator) { return gzipEnabled - ? new SRSCompressingInterceptor(delegate, compressionCutoff) + ? new SRSCompressingInterceptor(delegate, compressionCutoff, checksumGenerator) : null; } @@ -189,12 +190,12 @@ public class AssetsModule @Marker(ContextProvider.class) public static AssetFactory buildContextAssetFactory(ApplicationGlobals globals, - AssetPathConstructor assetPathConstructor, - - AssetPathConverter converter) + ResponseCompressionAnalyzer compressionAnalyzer, + ResourceChangeTracker resourceChangeTracker, + StreamableResourceSource streamableResourceSource) { - return new ContextAssetFactory(assetPathConstructor, globals.getContext(), converter); + return new ContextAssetFactory(compressionAnalyzer, resourceChangeTracker, streamableResourceSource, assetPathConstructor, globals.getContext()); } @Contribute(ClasspathAssetAliasManager.class) @@ -222,8 +223,6 @@ public class AssetsModule @Autobuild StackAssetRequestHandler stackAssetRequestHandler, - AssetChecksumGenerator assetChecksumGenerator, - ClasspathAssetAliasManager classpathAssetAliasManager, ResourceStreamer streamer, AssetSource assetSource) @@ -234,11 +233,11 @@ public class AssetsModule { String path = mappings.get(folder); - configuration.add(folder, new ClasspathAssetRequestHandler(streamer, assetChecksumGenerator, assetSource, path)); + configuration.add(folder, new ClasspathAssetRequestHandler(streamer, assetSource, path)); } configuration.add(RequestConstants.CONTEXT_FOLDER, - new ContextAssetRequestHandler(streamer, assetChecksumGenerator, contextAssetFactory.getRootResource())); + new ContextAssetRequestHandler(streamer, contextAssetFactory.getRootResource())); configuration.add(RequestConstants.STACK_FOLDER, stackAssetRequestHandler); http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/154dac95/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/StreamableResource.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/StreamableResource.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/StreamableResource.java index 3edeff5..ab6cd16 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/StreamableResource.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/StreamableResource.java @@ -31,7 +31,7 @@ import java.io.OutputStream; public interface StreamableResource { /** - * Describes the underlying {@link Resource} (or resources} for this streamble resource; expressly used + * Describes the underlying {@link Resource} (or resources} for this streamable resource; expressly used * as part of the object's {@code toString()}. */ String getDescription(); http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/154dac95/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptModule.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptModule.java index cd19a5e..39417a3 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptModule.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptModule.java @@ -28,13 +28,13 @@ import org.apache.tapestry5.ioc.OrderedConfiguration; import org.apache.tapestry5.ioc.Resource; import org.apache.tapestry5.ioc.ServiceBinder; import org.apache.tapestry5.ioc.annotations.Contribute; -import org.apache.tapestry5.ioc.annotations.Primary; import org.apache.tapestry5.ioc.annotations.Symbol; import org.apache.tapestry5.ioc.services.FactoryDefaults; import org.apache.tapestry5.ioc.services.SymbolProvider; import org.apache.tapestry5.ioc.util.IdAllocator; import org.apache.tapestry5.json.JSONObject; import org.apache.tapestry5.services.*; +import org.apache.tapestry5.services.assets.AssetRequestHandler; import org.apache.tapestry5.services.compatibility.Compatibility; import org.apache.tapestry5.services.compatibility.Trait; import org.apache.tapestry5.services.messages.ComponentMessagesSource; @@ -130,6 +130,13 @@ public class JavaScriptModule return environmentalBuilder.build(JavaScriptSupport.class); } + @Contribute(Dispatcher.class) + @AssetRequestDispatcher + public static void provideModuleHandler(MappedConfiguration<String, AssetRequestHandler> configuration) + { + configuration.addInstance("module", ModuleAssetRequestHandler.class); + } + /** * Adds page render filters, each of which provides an {@link org.apache.tapestry5.annotations.Environmental} * service. Filters @@ -210,12 +217,6 @@ public class JavaScriptModule configuration.add("JavaScriptSupport", javascriptSupport, "after:DocumentLinker"); } - @Contribute(Dispatcher.class) - @Primary - public static void handleModuleRequests(OrderedConfiguration<Dispatcher> configuration) - { - configuration.addInstance("Module", ModuleDispatcher.class, "before:PageRender"); - } @Contribute(ModuleManager.class) public static void setupBaseModules(MappedConfiguration<String, Object> configuration, http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/154dac95/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/ResponseCompressionAnalyzerTest.groovy ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/ResponseCompressionAnalyzerTest.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/ResponseCompressionAnalyzerTest.groovy index 3b2f4c1..f702e2e 100644 --- a/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/ResponseCompressionAnalyzerTest.groovy +++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/ResponseCompressionAnalyzerTest.groovy @@ -17,7 +17,7 @@ class ResponseCompressionAnalyzerTest extends TestBase { replay() - ResponseCompressionAnalyzer rca = new ResponseCompressionAnalyzerImpl(request, true) + ResponseCompressionAnalyzer rca = new ResponseCompressionAnalyzerImpl(request, true, compressionAnalyzer) assert rca.isGZipSupported() == false http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/154dac95/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/assets/AssetPathConstructorImplTest.groovy ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/assets/AssetPathConstructorImplTest.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/assets/AssetPathConstructorImplTest.groovy index 7e41fbf..9065587 100644 --- a/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/assets/AssetPathConstructorImplTest.groovy +++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/assets/AssetPathConstructorImplTest.groovy @@ -31,7 +31,7 @@ class AssetPathConstructorImplTest extends TestBase { replay() - def apc = new AssetPathConstructorImpl(request, baseURLSource, false, "assets", pc, gen) + def apc = new AssetPathConstructorImpl(request, baseURLSource, false, "assets", null, pc, pathConverter) assert apc.constructAssetPath("virt", "extra.png", virtExtra) == "/assets/virt/abc/extra.png" @@ -58,7 +58,7 @@ class AssetPathConstructorImplTest extends TestBase { replay() - def apc = new AssetPathConstructorImpl(request, baseURLSource, true, "assets", pc, gen) + def apc = new AssetPathConstructorImpl(request, baseURLSource, true, "assets", null, pc, pathConverter) assert apc.constructAssetPath("virt", "icon.gif", r) == "http://localhost:8080/assets/virt/911/icon.gif" http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/154dac95/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleAssetRequestHandlerTest.groovy ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleAssetRequestHandlerTest.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleAssetRequestHandlerTest.groovy index 3c974b7..56635c3 100644 --- a/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleAssetRequestHandlerTest.groovy +++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleAssetRequestHandlerTest.groovy @@ -1,6 +1,6 @@ package org.apache.tapestry5.services.javascript -import org.apache.tapestry5.internal.services.javascript.ModuleDispatcher +import org.apache.tapestry5.internal.services.javascript.ModuleAssetRequestHandler import org.apache.tapestry5.ioc.internal.QuietOperationTracker import org.apache.tapestry5.ioc.test.TestBase import org.apache.tapestry5.services.PathConstructor @@ -25,7 +25,7 @@ class ModuleAssetRequestHandlerTest extends TestBase { replay() - def handler = new ModuleDispatcher(null, null, pc, new QuietOperationTracker()) + def handler = new ModuleAssetRequestHandler(null, null, new QuietOperationTracker()) assertEquals handler.dispatch(request, response), false @@ -61,7 +61,7 @@ class ModuleAssetRequestHandlerTest extends TestBase { replay() - def handler = new ModuleDispatcher(manager, null, pc, new QuietOperationTracker()) + def handler = new ModuleAssetRequestHandler(manager, null, new QuietOperationTracker()) assertEquals handler.dispatch(request, response), false http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/154dac95/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleDispatcherTests.groovy ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleDispatcherTests.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleDispatcherTests.groovy index 35b407a..ca72a21 100644 --- a/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleDispatcherTests.groovy +++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleDispatcherTests.groovy @@ -1,6 +1,6 @@ package org.apache.tapestry5.services.javascript -import org.apache.tapestry5.internal.services.javascript.ModuleDispatcher +import org.apache.tapestry5.internal.services.javascript.ModuleAssetRequestHandler import org.apache.tapestry5.ioc.internal.QuietOperationTracker import org.apache.tapestry5.ioc.test.TestBase import org.apache.tapestry5.services.PathConstructor @@ -22,7 +22,7 @@ class ModuleDispatcherTests extends TestBase { replay() - def handler = new ModuleDispatcher(null, null, pc, new QuietOperationTracker()) + def handler = new ModuleAssetRequestHandler(null, null, new QuietOperationTracker()) assertEquals handler.dispatch(request, null), false @@ -56,7 +56,7 @@ class ModuleDispatcherTests extends TestBase { replay() - def handler = new ModuleDispatcher(manager, null, pc, new QuietOperationTracker()) + def handler = new ModuleAssetRequestHandler(manager, null, new QuietOperationTracker()) assertEquals handler.dispatch(request, null), false http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/154dac95/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClasspathAssetAliasManagerImplTest.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClasspathAssetAliasManagerImplTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClasspathAssetAliasManagerImplTest.java index 776ad50..fcff983 100644 --- a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClasspathAssetAliasManagerImplTest.java +++ b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClasspathAssetAliasManagerImplTest.java @@ -14,17 +14,12 @@ package org.apache.tapestry5.internal.services; -import org.apache.tapestry5.internal.services.assets.AssetPathConstructorImpl; import org.apache.tapestry5.internal.test.InternalBaseTestCase; import org.apache.tapestry5.ioc.Resource; import org.apache.tapestry5.ioc.internal.util.CollectionFactory; import org.apache.tapestry5.ioc.util.UnknownValueException; -import org.apache.tapestry5.services.BaseURLSource; +import org.apache.tapestry5.services.AssetAlias; import org.apache.tapestry5.services.ClasspathAssetAliasManager; -import org.apache.tapestry5.services.PathConstructor; -import org.apache.tapestry5.services.Request; -import org.apache.tapestry5.services.assets.AssetChecksumGenerator; -import org.apache.tapestry5.services.assets.AssetPathConstructor; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -33,8 +28,6 @@ import java.util.Map; public class ClasspathAssetAliasManagerImplTest extends InternalBaseTestCase { - private static final String APP_VERSION = "1.2.3"; - public Map<String, String> configuration() { Map<String, String> configuration = CollectionFactory.newMap(); @@ -55,7 +48,7 @@ public class ClasspathAssetAliasManagerImplTest extends InternalBaseTestCase try { - new ClasspathAssetAliasManagerImpl(null, configuration); + new ClasspathAssetAliasManagerImpl(configuration); unreachable(); } catch (RuntimeException ex) { @@ -75,34 +68,26 @@ public class ClasspathAssetAliasManagerImplTest extends InternalBaseTestCase expected.put("tapestry-internal", "org/apache/tapestry5/internal"); expected.put("mylib", "com/example/mylib"); - ClasspathAssetAliasManager manager = new ClasspathAssetAliasManagerImpl(null, configuration()); + ClasspathAssetAliasManager manager = new ClasspathAssetAliasManagerImpl(configuration()); assertEquals(manager.getMappings(), expected); } @Test(dataProvider = "to_client_url_data") - public void to_client_url(String resourcePath, String expectedClientURL) throws IOException + public void to_client_url(String resourcePath, String expectedFolder, String expectedPath) throws IOException { - Request request = mockRequest(); Resource r = mockResource(); expect(r.getPath()).andReturn(resourcePath); - BaseURLSource baseURLSource = newMock(BaseURLSource.class); - PathConstructor pc = newMock(PathConstructor.class); - AssetChecksumGenerator acg = newMock(AssetChecksumGenerator.class); - - expect(pc.constructClientPath("assets", "")).andReturn("/ctx/assets/"); - expect(acg.generateChecksum(r)).andReturn("abcde"); - replay(); - ClasspathAssetAliasManager manager = new ClasspathAssetAliasManagerImpl( - new AssetPathConstructorImpl(request, - baseURLSource, false, "assets", pc, acg), configuration()); + ClasspathAssetAliasManager manager = new ClasspathAssetAliasManagerImpl(configuration()); + + AssetAlias alias = manager.extractAssetAlias(r); - String expectedPath = "/ctx/assets/" + expectedClientURL.replace("#", "abcde"); - assertEquals(manager.toClientURL(r), expectedPath); + assertEquals(alias.virtualFolder, expectedFolder); + assertEquals(alias.path, expectedPath); verify(); } @@ -110,8 +95,7 @@ public class ClasspathAssetAliasManagerImplTest extends InternalBaseTestCase @Test public void failure_if_path_not_in_mapped_alias_folder() { - AssetPathConstructor pc = newMock(AssetPathConstructor.class); - ClasspathAssetAliasManager manager = new ClasspathAssetAliasManagerImpl(pc, configuration()); + ClasspathAssetAliasManager manager = new ClasspathAssetAliasManagerImpl(configuration()); Resource resource = mockResource(); expect(resource.getPath()).andReturn("org/example/icons/flag.gif").atLeastOnce(); @@ -120,7 +104,7 @@ public class ClasspathAssetAliasManagerImplTest extends InternalBaseTestCase try { - manager.toClientURL(resource); + manager.extractAssetAlias(resource); unreachable(); } catch (UnknownValueException ex) { @@ -138,10 +122,11 @@ public class ClasspathAssetAliasManagerImplTest extends InternalBaseTestCase { return new Object[][] { - {"com/example/mylib/Foo.bar", "mylib/#/Foo.bar"}, - {"com/example/mylib/nested/Foo.bar", "mylib/#/nested/Foo.bar"}, - {"org/apache/tapestry5/internal/Foo.bar", "tapestry-internal/#/Foo.bar"}, - {"org/apache/tapestry5/Foo.bar", "tapestry/#/Foo.bar"},}; + {"com/example/mylib/Foo.bar", "mylib", "Foo.bar"}, + {"com/example/mylib/nested/Foo.bar", "mylib", "nested/Foo.bar"}, + {"org/apache/tapestry5/internal/Foo.bar", "tapestry-internal", "Foo.bar"}, + {"org/apache/tapestry5/Foo.bar", "tapestry", "Foo.bar"} + }; } } http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/154dac95/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClasspathAssetFactoryTest.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClasspathAssetFactoryTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClasspathAssetFactoryTest.java deleted file mode 100644 index bdddceb..0000000 --- a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClasspathAssetFactoryTest.java +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2006, 2007, 2008, 2009, 2011, 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. -// 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.internal.services; - -import org.apache.tapestry5.Asset; -import org.apache.tapestry5.internal.test.InternalBaseTestCase; -import org.apache.tapestry5.ioc.Resource; -import org.apache.tapestry5.ioc.internal.util.ClasspathResource; -import org.apache.tapestry5.services.AssetFactory; -import org.apache.tapestry5.services.ClasspathAssetAliasManager; -import org.testng.annotations.Test; - -public class ClasspathAssetFactoryTest extends InternalBaseTestCase -{ - private final IdentityAssetPathConverter converter = new IdentityAssetPathConverter(); - - @Test - public void asset_client_URL_is_cached() - { - Resource r = new ClasspathResource("foo/Bar.txt"); - - ClasspathAssetAliasManager aliasManager = mockClasspathAssetAliasManager(); - - String expectedClientURL = "/context/asset/foo/Bar.txt"; - - expect(aliasManager.toClientURL(r)).andReturn(expectedClientURL); - - replay(); - - ClasspathAssetFactory factory = new ClasspathAssetFactory(aliasManager, converter); - - Asset asset = factory.createAsset(r); - - assertEquals(asset.toClientURL(), expectedClientURL); - - // Now, to check the cache: - - assertEquals(asset.toClientURL(), expectedClientURL); - - verify(); - } - - @Test - public void simple_asset_client_URL() - { - ClasspathAssetAliasManager aliasManager = mockClasspathAssetAliasManager(); - - Resource r = new ClasspathResource("foo/Bar.txt"); - - String expectedClientURL = "/context/asset/foo/Bar.txt"; - - expect(aliasManager.toClientURL(r)).andReturn(expectedClientURL); - - replay(); - - AssetFactory factory = new ClasspathAssetFactory(aliasManager, new IdentityAssetPathConverter()); - - Asset asset = factory.createAsset(r); - - assertSame(asset.getResource(), r); - assertEquals(asset.toClientURL(), expectedClientURL); - assertEquals(asset.toString(), expectedClientURL); - - verify(); - } -} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/154dac95/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ContextAssetFactoryTest.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ContextAssetFactoryTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ContextAssetFactoryTest.java deleted file mode 100644 index cb0fa33..0000000 --- a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ContextAssetFactoryTest.java +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2006, 2007, 2009, 2012, 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. -// 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.internal.services; - -import org.apache.tapestry5.Asset; -import org.apache.tapestry5.internal.test.InternalBaseTestCase; -import org.apache.tapestry5.ioc.Resource; -import org.apache.tapestry5.services.AssetFactory; -import org.apache.tapestry5.services.Context; -import org.apache.tapestry5.services.assets.AssetPathConstructor; -import org.testng.annotations.Test; - -import java.io.IOException; - -public class ContextAssetFactoryTest extends InternalBaseTestCase -{ - private final IdentityAssetPathConverter converter = new IdentityAssetPathConverter(); - - @Test - public void root_resource() - { - Context context = mockContext(); - AssetPathConstructor apc = newMock(AssetPathConstructor.class); - - replay(); - - AssetFactory factory = new ContextAssetFactory(apc, context, converter); - - assertEquals(factory.getRootResource().toString(), "context:/"); - - verify(); - } - - @Test - public void asset_client_URL() throws IOException - { - Context context = mockContext(); - AssetPathConstructor apc = newMock(AssetPathConstructor.class); - - Resource r = new ContextResource(context, "foo/Bar.txt"); - - String expectedURL = "/expected-url"; - - expect(apc.constructAssetPath("ctx", "foo/Bar.txt", r)).andReturn(expectedURL).atLeastOnce(); - - replay(); - - AssetFactory factory = new ContextAssetFactory(apc, context, new IdentityAssetPathConverter()); - - Asset asset = factory.createAsset(r); - - assertSame(asset.getResource(), r); - - assertSame(asset.toClientURL(), expectedURL); - - // In real life, toString() is the same as toClientURL(), but we're testing - // that the optimize method is getting called, basically. - assertSame(asset.toString(), expectedURL); - - verify(); - } -} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/154dac95/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/assets/ContextAssetRequestHandlerTest.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/assets/ContextAssetRequestHandlerTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/assets/ContextAssetRequestHandlerTest.java index bdb745c..3836bff 100644 --- a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/assets/ContextAssetRequestHandlerTest.java +++ b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/assets/ContextAssetRequestHandlerTest.java @@ -42,7 +42,7 @@ public class ContextAssetRequestHandlerTest extends TestBase @Test(dataProvider = "invalid_paths") public void ensure_assets_are_rejected(String path) throws IOException { - ContextAssetRequestHandler handler = new ContextAssetRequestHandler(null, null, null); + ContextAssetRequestHandler handler = new ContextAssetRequestHandler(null, null); assertFalse(handler.handleAssetRequest(null, null, "fake-checksum/" + path), "Handler should return false for invalid path."); @@ -64,7 +64,7 @@ public class ContextAssetRequestHandlerTest extends TestBase replay(); - AssetRequestHandler h = new ContextAssetRequestHandler(streamer, gen, root); + AssetRequestHandler h = new ContextAssetRequestHandler(streamer, root); assertFalse(h.handleAssetRequest(req, res, "abc/folder/icon.png"));
