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

hazendaz / scriptable-dataset / #124

04 Mar 2024 01:31AM UTC coverage: 89.683% (-0.2%) from 89.922%
#124

push

github

hazendaz
[ci] Modernize the code

23 of 26 branches covered (88.46%)

Branch coverage included in aggregate %.

14 of 14 new or added lines in 2 files covered. (100.0%)

7 existing lines in 3 files now uncovered.

90 of 100 relevant lines covered (90.0%)

0.9 hits per line

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

76.92
/src/main/java/de/gmorling/scriptabledataset/handlers/StandardHandlerConfig.java
1
/*
2
 * scriptable-dataset (https://github.com/hazendaz/scriptable-dataset)
3
 *
4
 * Copyright 2011-2024 Hazendaz.
5
 *
6
 * All rights reserved. This program and the accompanying materials
7
 * are made available under the terms of The Apache Software License,
8
 * Version 2.0 which accompanies this distribution, and is available at
9
 * https://www.apache.org/licenses/LICENSE-2.0.txt
10
 *
11
 * Contributors:
12
 *     Gunnar Morling
13
 *     Hazendaz (Jeremy Landis).
14
 */
15
package de.gmorling.scriptabledataset.handlers;
16

17
import java.util.ArrayList;
18
import java.util.Collections;
19
import java.util.HashMap;
20
import java.util.List;
21
import java.util.Map;
22
import java.util.ServiceConfigurationError;
23
import java.util.ServiceLoader;
24

25
import org.slf4j.Logger;
26
import org.slf4j.LoggerFactory;
27

28
/**
29
 * Manages handlers, that shall always executed for scripts in a given language. These standard handlers will be called
30
 * <b>before</b> any custom handlers in the pre invocation and <b>after</b> any custom handlers in the post invocation.
31
 */
32
public class StandardHandlerConfig {
33

34
    /** The standard handlers. */
35
    private static Map<String, List<ScriptInvocationHandler>> standardHandlers;
36

37
    /**
38
     * Instantiates a new standard handler config.
39
     */
40
    private StandardHandlerConfig() {
41
        // Prevent Instantiation
42
    }
43

44
    static {
45

46
        standardHandlers = new HashMap<>();
1✔
47

48
        ServiceLoader<ScriptInvocationHandler> serviceLoader = ServiceLoader.load(ScriptInvocationHandler.class);
1✔
49
        try {
50
            for (ScriptInvocationHandler scriptInvocationHandler : serviceLoader) {
1✔
51

52
                List<ScriptInvocationHandler> handlersForLanguage = standardHandlers
1✔
53
                        .get(scriptInvocationHandler.getLanguageName());
1✔
54

55
                if (handlersForLanguage == null) {
1!
56
                    handlersForLanguage = new ArrayList<>();
1✔
57
                    standardHandlers.put(scriptInvocationHandler.getLanguageName(), handlersForLanguage);
1✔
58
                }
59

60
                handlersForLanguage.add(scriptInvocationHandler);
1✔
61
            }
1✔
UNCOV
62
        } catch (ServiceConfigurationError error) {
×
UNCOV
63
            Logger logger = LoggerFactory.getLogger(StandardHandlerConfig.class);
×
64
            logger.error(
×
65
                    "Loading of standard script invocation handlers failed, most likely due to an unknown handler implementation given in META-INF/services {}",
66
                    ScriptInvocationHandler.class.getName());
×
UNCOV
67
            standardHandlers = Collections.emptyMap();
×
68
        }
1✔
69
    }
1✔
70

71
    /**
72
     * Gets the standard handlers by language.
73
     *
74
     * @param language
75
     *            the language
76
     *
77
     * @return the standard handlers by language
78
     */
79
    public static List<ScriptInvocationHandler> getStandardHandlersByLanguage(String language) {
80
        if (standardHandlers.containsKey(language)) {
1✔
81
            return Collections.unmodifiableList(standardHandlers.get(language));
1✔
82
        }
83
        return Collections.emptyList();
1✔
84
    }
85
}
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