Skip to content

Package: AngusMailFeature

AngusMailFeature

nameinstructionbranchcomplexitylinemethod
AngusMailFeature()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
beforeAnalysis(Feature.BeforeAnalysisAccess)
M: 59 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
getOption(String, boolean)
M: 10 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
isInConfiguration(Feature.IsInConfigurationAccess)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$beforeAnalysis$0(Class)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$beforeAnalysis$1(Class)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$beforeAnalysis$2(Provider)
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
log(Supplier)
M: 8 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package org.eclipse.angus.mail.nativeimage;
18:
19: import jakarta.mail.Provider;
20: import jakarta.mail.Service;
21: import jakarta.mail.Session;
22: import jakarta.mail.URLName;
23: import org.graalvm.nativeimage.hosted.Feature;
24: import org.graalvm.nativeimage.hosted.RuntimeReflection;
25:
26: import java.text.MessageFormat;
27: import java.util.ServiceLoader;
28: import java.util.function.Supplier;
29:
30: public class AngusMailFeature implements Feature {
31:
32: private static final boolean ENABLED = getOption("angus.mail.native-image.enable", true);
33: private static final boolean DEBUG = getOption("angus.mail.native-image.trace", false);
34:
35: /**
36: * Default constructor.
37: */
38: public AngusMailFeature() {
39: }
40:
41: @Override
42: public boolean isInConfiguration(Feature.IsInConfigurationAccess access) {
43: return ENABLED;
44: }
45:
46: @Override
47: public void beforeAnalysis(BeforeAnalysisAccess access) {
48: final ServiceLoader<? extends Provider> providers = ServiceLoader.load(Provider.class);
49:• for (Provider p : providers) {
50: @SuppressWarnings({"unchecked"})
51: Class<? extends Service> pc = (Class<? extends Service>) access.findClassByName(p.getClassName());
52:• if (pc != null) {
53: log(() -> MessageFormat.format("Registering {0}", pc));
54: RuntimeReflection.register(pc);
55: try {
56: RuntimeReflection.register(pc.getConstructor(Session.class, URLName.class));
57: } catch (NoSuchMethodException e) {
58: log(() -> MessageFormat.format("\tno constructor for {0}", pc));
59: }
60: } else {
61: log(() -> MessageFormat.format("Class '{0}' for provider '{1}' not found", p.getClassName(), p.getClass().getName()));
62: }
63: }
64: }
65:
66: private static void log(Supplier<String> msg) {
67:• if (DEBUG) {
68: System.out.println(msg.get());
69: }
70: }
71:
72: private static boolean getOption(String name, boolean def) {
73: String prop = System.getProperty(name);
74:• if (prop == null) {
75: return def;
76: }
77: return Boolean.parseBoolean(name);
78: }
79:
80: }