• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

TAKETODAY / today-infrastructure / 18154768944

01 Oct 2025 07:26AM UTC coverage: 81.882% (-0.005%) from 81.887%
18154768944

push

github

web-flow
Merge pull request #290 from TAKETODAY/dev/jspecify

jspecify

59788 of 78013 branches covered (76.64%)

Branch coverage included in aggregate %.

141239 of 167496 relevant lines covered (84.32%)

3.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.43
today-context/src/main/java/infra/context/annotation/LoadTimeWeavingConfiguration.java
1
/*
2
 * Copyright 2017 - 2025 the original author or authors.
3
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see [https://www.gnu.org/licenses/]
16
 */
17

18
package infra.context.annotation;
19

20
import org.jspecify.annotations.Nullable;
21

22
import infra.beans.factory.BeanClassLoaderAware;
23
import infra.beans.factory.annotation.Autowired;
24
import infra.beans.factory.config.BeanDefinition;
25
import infra.context.ConfigurableApplicationContext;
26
import infra.context.annotation.EnableLoadTimeWeaving.AspectJWeaving;
27
import infra.context.weaving.AspectJWeavingEnabler;
28
import infra.context.weaving.DefaultContextLoadTimeWeaver;
29
import infra.core.annotation.MergedAnnotation;
30
import infra.core.type.AnnotationMetadata;
31
import infra.instrument.classloading.LoadTimeWeaver;
32
import infra.lang.Assert;
33
import infra.stereotype.Component;
34

35
/**
36
 * {@code @Configuration} class that registers a {@link LoadTimeWeaver} bean.
37
 *
38
 * <p>This configuration class is automatically imported when using the
39
 * {@link EnableLoadTimeWeaving} annotation. See {@code @EnableLoadTimeWeaving}
40
 * javadoc for complete usage details.
41
 *
42
 * @author Chris Beams
43
 * @author <a href="https://github.com/TAKETODAY">Harry Yang</a>
44
 * @see LoadTimeWeavingConfigurer
45
 * @see ConfigurableApplicationContext#LOAD_TIME_WEAVER_BEAN_NAME
46
 * @since 4.0
47
 */
48
@Configuration(proxyBeanMethods = false)
49
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
50
public class LoadTimeWeavingConfiguration implements ImportAware, BeanClassLoaderAware {
3✔
51

52
  @Nullable
53
  private MergedAnnotation<EnableLoadTimeWeaving> enableLTW;
54

55
  @Nullable
56
  private LoadTimeWeavingConfigurer ltwConfigurer;
57

58
  @Nullable
59
  private ClassLoader beanClassLoader;
60

61
  @Override
62
  public void setImportMetadata(AnnotationMetadata importMetadata) {
63
    this.enableLTW = importMetadata.getAnnotation(EnableLoadTimeWeaving.class);
5✔
64
    if (!enableLTW.isPresent()) {
4!
65
      throw new IllegalArgumentException(
×
66
              "@EnableLoadTimeWeaving is not present on importing class " + importMetadata.getClassName());
×
67
    }
68
  }
1✔
69

70
  @Autowired(required = false)
71
  public void setLoadTimeWeavingConfigurer(LoadTimeWeavingConfigurer ltwConfigurer) {
72
    this.ltwConfigurer = ltwConfigurer;
3✔
73
  }
1✔
74

75
  @Override
76
  public void setBeanClassLoader(@Nullable ClassLoader beanClassLoader) {
77
    this.beanClassLoader = beanClassLoader;
3✔
78
  }
1✔
79

80
  @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
81
  @Component(ConfigurableApplicationContext.LOAD_TIME_WEAVER_BEAN_NAME)
82
  public LoadTimeWeaver loadTimeWeaver() {
83
    Assert.state(this.beanClassLoader != null, "No ClassLoader set");
7!
84
    LoadTimeWeaver loadTimeWeaver = null;
2✔
85

86
    if (this.ltwConfigurer != null) {
3!
87
      // The user has provided a custom LoadTimeWeaver instance
88
      loadTimeWeaver = this.ltwConfigurer.getLoadTimeWeaver();
4✔
89
    }
90

91
    if (loadTimeWeaver == null) {
2!
92
      // No custom LoadTimeWeaver provided -> fall back to the default
93
      loadTimeWeaver = new DefaultContextLoadTimeWeaver(this.beanClassLoader);
×
94
    }
95

96
    if (this.enableLTW != null) {
3!
97
      AspectJWeaving aspectJWeaving = this.enableLTW.getEnum("aspectjWeaving", AspectJWeaving.class);
7✔
98
      switch (aspectJWeaving) {
5!
99
        case DISABLED:
100
          // AJ weaving is disabled -> do nothing
101
          break;
1✔
102
        case AUTODETECT:
103
          if (this.beanClassLoader.getResource(AspectJWeavingEnabler.ASPECTJ_AOP_XML_RESOURCE) == null) {
5!
104
            // No aop.xml present on the classpath -> treat as 'disabled'
105
            break;
1✔
106
          }
107
          // aop.xml is present on the classpath -> enable
108
          AspectJWeavingEnabler.enableAspectJWeaving(loadTimeWeaver, this.beanClassLoader);
×
109
          break;
×
110
        case ENABLED:
111
          AspectJWeavingEnabler.enableAspectJWeaving(loadTimeWeaver, this.beanClassLoader);
4✔
112
          break;
113
      }
114
    }
115

116
    return loadTimeWeaver;
2✔
117
  }
118

119
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc