Add support for webjars-locator-lite
This is a follow-up to spring-projects/spring-framework#27619 This commit adds support for "org.webjars:webjars-locator-lite" for enabling the statis resources chain. As of this commit, support for "org.webjars:webjars-locator-core" is deprecated for obvious performance reasons. Closes gh-40146
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-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,10 @@ import org.springframework.context.annotation.Conditional;
|
||||
/**
|
||||
* {@link Conditional @Conditional} that checks whether the Spring resource handling chain
|
||||
* is enabled. Matches if {@link WebProperties.Resources.Chain#getEnabled()} is
|
||||
* {@code true} or if {@code webjars-locator-core} is on the classpath.
|
||||
* {@code true} or if one of {@code "org.webjars:webjars-locator-core"},
|
||||
* {@code "org.webjars:webjars-locator-lite"} is on the classpath.
|
||||
* <p>
|
||||
* Note that support for {@code "org.webjars:webjars-locator-core"} is deprecated.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.3.0
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -32,12 +32,15 @@ import org.springframework.util.ClassUtils;
|
||||
* @author Stephane Nicoll
|
||||
* @author Phillip Webb
|
||||
* @author Madhura Bhave
|
||||
* @author Brian Clozel
|
||||
* @see ConditionalOnEnabledResourceChain
|
||||
*/
|
||||
class OnEnabledResourceChainCondition extends SpringBootCondition {
|
||||
|
||||
private static final String WEBJAR_ASSET_LOCATOR = "org.webjars.WebJarAssetLocator";
|
||||
|
||||
private static final String WEBJAR_VERSION_LOCATOR = "org.webjars.WebJarVersionLocator";
|
||||
|
||||
@Override
|
||||
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
||||
ConfigurableEnvironment environment = (ConfigurableEnvironment) context.getEnvironment();
|
||||
@@ -47,10 +50,13 @@ class OnEnabledResourceChainCondition extends SpringBootCondition {
|
||||
Boolean match = Chain.getEnabled(fixed, content, chain);
|
||||
ConditionMessage.Builder message = ConditionMessage.forCondition(ConditionalOnEnabledResourceChain.class);
|
||||
if (match == null) {
|
||||
if (ClassUtils.isPresent(WEBJAR_VERSION_LOCATOR, getClass().getClassLoader())) {
|
||||
return ConditionOutcome.match(message.found("class").items(WEBJAR_VERSION_LOCATOR));
|
||||
}
|
||||
if (ClassUtils.isPresent(WEBJAR_ASSET_LOCATOR, getClass().getClassLoader())) {
|
||||
return ConditionOutcome.match(message.found("class").items(WEBJAR_ASSET_LOCATOR));
|
||||
}
|
||||
return ConditionOutcome.noMatch(message.didNotFind("class").items(WEBJAR_ASSET_LOCATOR));
|
||||
return ConditionOutcome.noMatch(message.didNotFind("class").items(WEBJAR_VERSION_LOCATOR));
|
||||
}
|
||||
if (match) {
|
||||
return ConditionOutcome.match(message.because("enabled"));
|
||||
|
||||
Reference in New Issue
Block a user