• 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

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
  @Nullable
68
  public Integer getInteger(String className, String key) {
69
    return getInteger(className, key, null);
6✔
70
  }
71

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

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

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

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

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

138
  // static
139

140
  public static AutoConfigurationMetadata load(@Nullable ClassLoader classLoader) {
141
    return load(classLoader, PATH);
4✔
142
  }
143

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

160
  public static AutoConfigurationMetadata valueOf(Properties properties) {
161
    return new AutoConfigurationMetadata(properties);
5✔
162
  }
163

164
}
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