• 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

90.91
today-context/src/main/java/infra/context/condition/OnJavaCondition.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.condition;
19

20
import java.util.Map;
21

22
import infra.context.annotation.Condition;
23
import infra.context.annotation.ConditionContext;
24
import infra.core.JavaVersion;
25
import infra.core.Ordered;
26
import infra.core.annotation.Order;
27
import infra.core.type.AnnotatedTypeMetadata;
28

29
/**
30
 * {@link Condition} that checks for a required version of Java.
31
 *
32
 * @author Oliver Gierke
33
 * @author Phillip Webb
34
 * @author <a href="https://github.com/TAKETODAY">Harry Yang</a>
35
 * @see ConditionalOnJava
36
 * @since 4.0 2022/4/4 12:23
37
 */
38
@Order(Ordered.HIGHEST_PRECEDENCE + 20)
39
class OnJavaCondition extends InfraCondition {
3✔
40

41
  private static final JavaVersion JVM_VERSION = JavaVersion.getJavaVersion();
3✔
42

43
  @Override
44
  @SuppressWarnings("NullAway")
45
  public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
46
    Map<String, Object> attributes = metadata.getAnnotationAttributes(ConditionalOnJava.class);
4✔
47
    ConditionalOnJava.Range range = (ConditionalOnJava.Range) attributes.get("range");
5✔
48
    JavaVersion version = (JavaVersion) attributes.get("value");
5✔
49
    return getMatchOutcome(range, JVM_VERSION, version);
6✔
50
  }
51

52
  protected ConditionOutcome getMatchOutcome(ConditionalOnJava.Range range, JavaVersion runningVersion, JavaVersion version) {
53
    boolean match = isWithin(runningVersion, range, version);
6✔
54
    String expected = String.format((range != ConditionalOnJava.Range.EQUAL_OR_NEWER) ? "(older than %s)" : "(%s or newer)", version);
14✔
55
    ConditionMessage message = ConditionMessage.forCondition(ConditionalOnJava.class, expected)
9✔
56
            .foundExactly(runningVersion);
2✔
57
    return new ConditionOutcome(match, message);
6✔
58
  }
59

60
  /**
61
   * Determines if the {@code runningVersion} is within the specified range of versions.
62
   *
63
   * @param runningVersion the current version.
64
   * @param range the range
65
   * @param version the bounds of the range
66
   * @return if this version is within the specified range
67
   */
68
  private boolean isWithin(JavaVersion runningVersion, ConditionalOnJava.Range range, JavaVersion version) {
69
    if (range == ConditionalOnJava.Range.EQUAL_OR_NEWER) {
3✔
70
      return runningVersion.isEqualOrNewerThan(version);
4✔
71
    }
72
    if (range == ConditionalOnJava.Range.OLDER_THAN) {
3!
73
      return runningVersion.isOlderThan(version);
4✔
74
    }
75
    throw new IllegalStateException("Unknown range " + range);
×
76
  }
77

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