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

mizosoft / methanol / #585

22 Aug 2025 05:42PM UTC coverage: 89.013% (-0.9%) from 89.944%
#585

push

github

web-flow
Properly setup coveralls (#132)

* Move buildSrc to gradle/src

* Setup coveralls with another Gradle plugin

 - Previously "com.github.kt3k.coveralls" was used which was removed in #130 due to issues with Gradle 9.0.0 (https://github.com/kt3k/coveralls-gradle-plugin/issues/119)

* Add CI job for coverallsJacoco

* Setup covered & test-contributing projects properly

2324 of 2796 branches covered (83.12%)

Branch coverage included in aggregate %.

7633 of 8390 relevant lines covered (90.98%)

0.91 hits per line

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

72.73
/methanol/src/main/java/com/github/mizosoft/methanol/internal/spi/BodyDecoderFactoryProviders.java
1
/*
2
 * Copyright (c) 2024 Moataz Hussein
3
 *
4
 * Permission is hereby granted, free of charge, to any person obtaining a copy
5
 * of this software and associated documentation files (the "Software"), to deal
6
 * in the Software without restriction, including without limitation the rights
7
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
 * copies of the Software, and to permit persons to whom the Software is
9
 * furnished to do so, subject to the following conditions:
10
 *
11
 * The above copyright notice and this permission notice shall be included in all
12
 * copies or substantial portions of the Software.
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
 * SOFTWARE.
21
 */
22

23
package com.github.mizosoft.methanol.internal.spi;
24

25
import com.github.mizosoft.methanol.BodyDecoder;
26
import com.github.mizosoft.methanol.internal.annotations.DefaultProvider;
27
import java.util.LinkedHashMap;
28
import java.util.List;
29
import java.util.Map;
30
import java.util.function.Function;
31
import java.util.stream.Collectors;
32
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
33

34
/** Utility class for finding decoder factories. */
35
public class BodyDecoderFactoryProviders {
36
  private static final ServiceProviders<BodyDecoder.Factory> factories =
1✔
37
      new ServiceProviders<>(BodyDecoder.Factory.class);
38

39
  @SuppressWarnings("NonFinalStaticField") // Lazily initialized.
40
  private static volatile @MonotonicNonNull Map<String, BodyDecoder.Factory> lazyBindings;
41

42
  private BodyDecoderFactoryProviders() {}
43

44
  public static List<BodyDecoder.Factory> factories() {
45
    return factories.get();
1✔
46
  }
47

48
  public static Map<String, BodyDecoder.Factory> bindings() {
49
    // Locking is not necessary as the cache itself is locked so the result never changes.
50
    var bindings = lazyBindings;
1✔
51
    if (bindings == null) {
1✔
52
      bindings = createBindings();
1✔
53
      lazyBindings = bindings;
1✔
54
    }
55
    return bindings;
1✔
56
  }
57

58
  private static Map<String, BodyDecoder.Factory> createBindings() {
59
    return factories().stream()
1✔
60
        .collect(
1✔
61
            Collectors.toMap(
1✔
62
                BodyDecoder.Factory::encoding,
63
                Function.identity(),
1✔
64
                (f1, f2) -> {
65
                  // Allow overriding default providers.
66
                  if (f1.getClass().isAnnotationPresent(DefaultProvider.class)) {
1!
67
                    return f2;
1✔
68
                  } else if (f2.getClass().isAnnotationPresent(DefaultProvider.class)) {
×
69
                    return f1;
×
70
                  } else {
71
                    return f2;
×
72
                  }
73
                },
74
                LinkedHashMap::new));
75
  }
76
}
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