From ba9496de6c1e9532588a3d8abbdd849410ee3db7 Mon Sep 17 00:00:00 2001 From: Vedran Pavic Date: Thu, 5 Sep 2024 21:51:11 +0200 Subject: [PATCH] Simplify WebJars support --- .../annotation/ResourceChainRegistration.java | 10 +- .../resource/LiteWebJarsResourceResolver.java | 112 -------------- .../resource/WebJarsResourceResolver.java | 32 ++-- .../ResourceHandlerRegistryTests.java | 10 +- .../LiteWebJarsResourceResolverTests.java | 138 ------------------ .../WebJarsResourceResolverTests.java | 66 +++++---- 6 files changed, 68 insertions(+), 300 deletions(-) delete mode 100644 spring-webmvc/src/main/java/org/springframework/web/servlet/resource/LiteWebJarsResourceResolver.java delete mode 100644 spring-webmvc/src/test/java/org/springframework/web/servlet/resource/LiteWebJarsResourceResolverTests.java diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceChainRegistration.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceChainRegistration.java index 51fcf349486c..9c2a73fafd6e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceChainRegistration.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceChainRegistration.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,6 @@ import org.springframework.web.servlet.resource.CachingResourceResolver; import org.springframework.web.servlet.resource.CachingResourceTransformer; import org.springframework.web.servlet.resource.CssLinkResourceTransformer; -import org.springframework.web.servlet.resource.LiteWebJarsResourceResolver; import org.springframework.web.servlet.resource.PathResourceResolver; import org.springframework.web.servlet.resource.ResourceResolver; import org.springframework.web.servlet.resource.ResourceTransformer; @@ -83,7 +82,6 @@ public ResourceChainRegistration(boolean cacheResources, @Nullable Cache cache) * @param resolver the resolver to add * @return the current instance for chained method invocation */ - @SuppressWarnings("removal") public ResourceChainRegistration addResolver(ResourceResolver resolver) { Assert.notNull(resolver, "The provided ResourceResolver should not be null"); this.resolvers.add(resolver); @@ -93,7 +91,7 @@ public ResourceChainRegistration addResolver(ResourceResolver resolver) { else if (resolver instanceof PathResourceResolver) { this.hasPathResolver = true; } - else if (resolver instanceof WebJarsResourceResolver || resolver instanceof LiteWebJarsResourceResolver) { + else if (resolver instanceof WebJarsResourceResolver) { this.hasWebjarsResolver = true; } return this; @@ -118,10 +116,10 @@ protected List getResourceResolvers() { if (!this.hasPathResolver) { List result = new ArrayList<>(this.resolvers); if (isWebJarVersionLocatorPresent && !this.hasWebjarsResolver) { - result.add(new LiteWebJarsResourceResolver()); + result.add(new WebJarsResourceResolver()); } else if (isWebJarAssetLocatorPresent && !this.hasWebjarsResolver) { - result.add(new WebJarsResourceResolver()); + result.add(new WebJarsResourceResolver(new org.webjars.WebJarAssetLocator())); } result.add(new PathResourceResolver()); return result; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/LiteWebJarsResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/LiteWebJarsResourceResolver.java deleted file mode 100644 index 99af509a440e..000000000000 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/LiteWebJarsResourceResolver.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2002-2024 the original author or authors. - * - * 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 - * - * https://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.springframework.web.servlet.resource; - -import java.util.List; - -import jakarta.servlet.http.HttpServletRequest; -import org.webjars.WebJarVersionLocator; - -import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; - -/** - * A {@code ResourceResolver} that delegates to the chain to locate a resource and then - * attempts to find a matching versioned resource contained in a WebJar JAR file. - * - *

This allows WebJars.org users to write version agnostic paths in their templates, - * like {@code