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

common-workflow-language / cwljava / #394

31 Oct 2025 04:10PM UTC coverage: 57.972% (-1.6%) from 59.538%
#394

push

github

mr-c
rename package to a namespace that we control

7575 of 12994 new or added lines in 261 files covered. (58.3%)

7752 of 13372 relevant lines covered (57.97%)

0.58 hits per line

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

92.42
/src/main/java/org/commonwl/cwlsdk/cwl1_2/utils/Loader.java
1
package org.commonwl.cwlsdk.cwl1_2.utils;
2

3
import java.util.HashMap;
4
import java.util.List;
5
import java.util.Map;
6

7
public interface Loader<T> {
8

9
  T load(
10
      final Object doc,
11
      final String baseUri,
12
      final LoadingOptions loadingOptions,
13
      final String docRoot);
14

15
  default T load(final Object doc, final String baseUri, final LoadingOptions loadingOptions) {
16
    return load(doc, baseUri, loadingOptions, null);
1✔
17
  }
18

19
  default T documentLoad(
20
      final String doc, final String baseUri, final LoadingOptions loadingOptions) {
NEW
21
    return load(doc, baseUri, loadingOptions);
×
22
  }
23

24
  default T documentLoad(
25
      final Map<String, Object> doc_, final String baseUri_, final LoadingOptions loadingOptions_) {
26
    Map<String, Object> doc = doc_;
1✔
27
    LoadingOptions loadingOptions = loadingOptions_;
1✔
28
    if (doc.containsKey("$namespaces")) {
1✔
29
      final Map<String, String> namespaces = (Map<String, String>) doc.get("$namespaces");
1✔
30
      loadingOptions =
1✔
31
          new LoadingOptionsBuilder().copiedFrom(loadingOptions).setNamespaces(namespaces).build();
1✔
32
      doc = copyWithoutKey(doc, "$namespaces");
1✔
33
    }
34
    String baseUri = baseUri_;
1✔
35
    if (doc.containsKey("$base")) {
1✔
NEW
36
      baseUri = (String) doc.get("$base");
×
37
    }
38
    if (doc.containsKey("$graph")) {
1✔
39
      return load(doc.get("$graph"), baseUri, loadingOptions);
1✔
40
    } else {
41
      return load(doc, baseUri, loadingOptions, baseUri);
1✔
42
    }
43
  }
44

45
  default T documentLoad(
46
      final List<Object> doc, final String baseUri, final LoadingOptions loadingOptions) {
47
    return load(doc, baseUri, loadingOptions);
1✔
48
  }
49

50
  default T documentLoadByUrl(final String url, final LoadingOptions loadingOptions) {
51
    if (loadingOptions.idx.containsKey(url)) {
1✔
52
      Object result = loadingOptions.idx.get(url);
1✔
53
      if (result instanceof String) {
1✔
NEW
54
        return documentLoad((String) result, url, loadingOptions);
×
55
      } else if (result instanceof Map) {
1✔
56
        return documentLoad((Map<String, Object>) result, url, loadingOptions);
1✔
57
      }
58
      return load(result, url, loadingOptions);
1✔
59
    }
60

61
    final String text = loadingOptions.fetcher.fetchText(url);
1✔
62
    try {
63
      Map<String, Object> resultMap = YamlUtils.mapFromString(text);
1✔
64
      loadingOptions.idx.put(url, resultMap);
1✔
65
      final LoadingOptionsBuilder urlLoadingOptions =
1✔
66
          new LoadingOptionsBuilder().copiedFrom(loadingOptions).setFileUri(url);
1✔
67
      return documentLoad(resultMap, url, urlLoadingOptions.build());
1✔
68
    } catch (ClassCastException e) {
1✔
69
      List<Object> resultList = YamlUtils.listFromString(text);
1✔
70
      loadingOptions.idx.put(url, resultList);
1✔
71
      final LoadingOptionsBuilder urlLoadingOptions =
1✔
72
          new LoadingOptionsBuilder().copiedFrom(loadingOptions).setFileUri(url);
1✔
73
      return documentLoad(resultList, url, urlLoadingOptions.build());
1✔
74
    }
75
  }
76

77
  default T loadField(
78
      final Object val_, final String baseUri, final LoadingOptions loadingOptions) {
79
    Object val = val_;
1✔
80
    if (val instanceof Map) {
1✔
81
      Map<String, Object> valMap = (Map<String, Object>) val;
1✔
82
      if (valMap.containsKey("$import")) {
1✔
83
        if (loadingOptions.fileUri == null) {
1✔
NEW
84
          throw new ValidationException("Cannot load $import without fileuri");
×
85
        }
86
        return documentLoadByUrl(
1✔
87
            loadingOptions.fetcher.urlJoin(loadingOptions.fileUri, (String) valMap.get("$import")),
1✔
88
            loadingOptions);
89
      } else if (valMap.containsKey("$include")) {
1✔
90
        if (loadingOptions.fileUri == null) {
1✔
NEW
91
          throw new ValidationException("Cannot load $import without fileuri");
×
92
        }
93
        val =
1✔
94
            loadingOptions.fetcher.fetchText(
1✔
95
                loadingOptions.fetcher.urlJoin(
1✔
96
                    loadingOptions.fileUri, (String) valMap.get("$include")));
1✔
97
      }
98
    }
99
    return load(val, baseUri, loadingOptions);
1✔
100
  }
101

102
  default Map<String, Object> copyWithoutKey(final Map<String, Object> doc, final String key) {
103
    final Map<String, Object> result = new HashMap();
1✔
104
    for (final Map.Entry<String, Object> entry : doc.entrySet()) {
1✔
105
      if (!entry.getKey().equals(key)) {
1✔
106
        result.put(entry.getKey(), entry.getValue());
1✔
107
      }
108
    }
1✔
109
    return result;
1✔
110
  }
111

112
  static <T> T validateOfJavaType(final Class<T> clazz, final Object doc) {
113
    if (!clazz.isInstance(doc)) {
1✔
114
      String className = "null";
1✔
115
      if (doc != null) {
1✔
116
        className = doc.getClass().getName();
1✔
117
      }
118
      final String message =
1✔
119
          String.format(
1✔
120
              "Expected object with Java type of %s but got %s", clazz.getName(), className);
1✔
121
      throw new ValidationException(message);
1✔
122
    }
123
    return (T) doc;
1✔
124
  }
125
}
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