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

TAKETODAY / today-infrastructure / 20298495350

17 Dec 2025 09:45AM UTC coverage: 84.405% (+0.007%) from 84.398%
20298495350

push

github

TAKETODAY
:zap: 优化注解数据处理逻辑

- 将 Nullable 注解放置在返回值类型之前以符合新的语法规范
- 使用 MergedAnnotation 替代 Map 来获取注解属性,提升类型安全性
- 简化条件判断逻辑,通过 isPresent() 方法检查注解是否存在
- 更新注解属性访问方式,使用 getEnum() 等类型安全的方法
- 统一注解元数据处理接口的实现方式

61877 of 78357 branches covered (78.97%)

Branch coverage included in aggregate %.

145923 of 167837 relevant lines covered (86.94%)

3.71 hits per line

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

94.12
today-context/src/main/java/infra/context/annotation/config/AutoConfigurationMetadata.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.config;
19

20
import org.jspecify.annotations.Nullable;
21

22
import java.io.IOException;
23
import java.net.URL;
24
import java.util.Enumeration;
25
import java.util.Properties;
26
import java.util.Set;
27

28
import infra.core.io.PropertiesUtils;
29
import infra.core.io.UrlResource;
30
import infra.util.StringUtils;
31

32
/**
33
 * Provides access to meta-data written by the auto-configure annotation processor.
34
 *
35
 * @author Phillip Webb
36
 * @author <a href="https://github.com/TAKETODAY">Harry Yang</a>
37
 * @since 4.0 2022/2/1 02:48
38
 */
39
public class AutoConfigurationMetadata {
40

41
  protected static final String PATH = "META-INF/infra-autoconfigure-metadata.properties";
42

43
  private final Properties properties;
44

45
  AutoConfigurationMetadata(Properties properties) {
2✔
46
    this.properties = properties;
3✔
47
  }
1✔
48

49
  /**
50
   * Return {@code true} if the specified class name was processed by the annotation
51
   * processor.
52
   *
53
   * @param className the source class
54
   * @return if the class was processed
55
   */
56
  public boolean wasProcessed(String className) {
57
    return this.properties.containsKey(className);
5✔
58
  }
59

60
  /**
61
   * Get an {@link Integer} value from the meta-data.
62
   *
63
   * @param className the source class
64
   * @param key the meta-data key
65
   * @return the meta-data value or {@code null}
66
   */
67
  public @Nullable Integer getInteger(String className, String key) {
68
    return getInteger(className, key, null);
6✔
69
  }
70

71
  /**
72
   * Get an {@link Integer} value from the meta-data.
73
   *
74
   * @param className the source class
75
   * @param key the meta-data key
76
   * @param defaultValue the default value
77
   * @return the meta-data value or {@code defaultValue}
78
   */
79
  public @Nullable Integer getInteger(String className, String key, @Nullable Integer defaultValue) {
80
    String value = get(className, key);
5✔
81
    return value != null ? Integer.valueOf(value) : defaultValue;
7✔
82
  }
83

84
  /**
85
   * Get a {@link Set} value from the meta-data.
86
   *
87
   * @param className the source class
88
   * @param key the meta-data key
89
   * @return the meta-data value or {@code null}
90
   */
91
  public @Nullable Set<String> getSet(String className, String key) {
92
    return getSet(className, key, null);
6✔
93
  }
94

95
  /**
96
   * Get a {@link Set} value from the meta-data.
97
   *
98
   * @param className the source class
99
   * @param key the meta-data key
100
   * @param defaultValue the default value
101
   * @return the meta-data value or {@code defaultValue}
102
   */
103
  public @Nullable Set<String> getSet(String className, String key, @Nullable Set<String> defaultValue) {
104
    String value = get(className, key);
5✔
105
    return value != null ? StringUtils.commaDelimitedListToSet(value) : defaultValue;
7✔
106
  }
107

108
  /**
109
   * Get an {@link String} value from the meta-data.
110
   *
111
   * @param className the source class
112
   * @param key the meta-data key
113
   * @return the meta-data value or {@code null}
114
   */
115
  public @Nullable String get(String className, String key) {
116
    return get(className, key, null);
6✔
117
  }
118

119
  /**
120
   * Get an {@link String} value from the meta-data.
121
   *
122
   * @param className the source class
123
   * @param key the meta-data key
124
   * @param defaultValue the default value
125
   * @return the meta-data value or {@code defaultValue}
126
   */
127
  public @Nullable String get(String className, String key, @Nullable String defaultValue) {
128
    String value = this.properties.getProperty(className + "." + key);
7✔
129
    return value != null ? value : defaultValue;
6✔
130
  }
131

132
  // static
133

134
  public static AutoConfigurationMetadata load(@Nullable ClassLoader classLoader) {
135
    return load(classLoader, PATH);
4✔
136
  }
137

138
  public static AutoConfigurationMetadata load(@Nullable ClassLoader classLoader, String path) {
139
    try {
140
      Enumeration<URL> urls = classLoader != null
2✔
141
              ? classLoader.getResources(path)
4✔
142
              : ClassLoader.getSystemResources(path);
3✔
143
      Properties properties = new Properties();
4✔
144
      while (urls.hasMoreElements()) {
3✔
145
        properties.putAll(PropertiesUtils.loadProperties(new UrlResource(urls.nextElement())));
10✔
146
      }
147
      return valueOf(properties);
3✔
148
    }
149
    catch (IOException ex) {
×
150
      throw new IllegalArgumentException("Unable to load @ConditionalOnClass location [%s]".formatted(path), ex);
×
151
    }
152
  }
153

154
  public static AutoConfigurationMetadata valueOf(Properties properties) {
155
    return new AutoConfigurationMetadata(properties);
5✔
156
  }
157

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

© 2026 Coveralls, Inc