• 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

37.5
/src/main/java/org/commonwl/cwlsdk/cwl1_2/utils/Uris.java
1
package org.commonwl.cwlsdk.cwl1_2.utils;
2

3
import java.io.UnsupportedEncodingException;
4
import java.net.URI;
5
import java.net.URISyntaxException;
6
import java.nio.charset.StandardCharsets;
7

NEW
8
public class Uris {
×
9

10
        // Emulate Python's urlsplit.
11
        public static class UriSplit {
12
                String scheme;
13
                String netloc;
14
                String path;
15
                String query;
16
                String fragment;
17

18
                public UriSplit(String scheme, String netloc, String path, String query, String fragment) {
1✔
19
                        this.scheme = scheme;
1✔
20
                        this.netloc = netloc;
1✔
21
                        this.path = path;
1✔
22
                        this.query = query;
1✔
23
                        this.fragment = fragment;
1✔
24
                }
1✔
25

26
                public String toString() {
NEW
27
                        return String.format("UriSplit[%s,%s,%s,%s,%s]", this.scheme, this.netloc, this.path, this.query,
×
28
                                        this.fragment);
29
                }
30

31
        }
32

33
        public static String fileUri(final String path) {
NEW
34
                return fileUri(path, false);
×
35
        }
36

37
        public static String fileUri(final String path, final boolean splitFrag) {
NEW
38
                if (path.equals("file://")) {
×
NEW
39
                        return path;
×
40
                }
41
                String frag;
42
                String urlPath;
NEW
43
                if (splitFrag) {
×
NEW
44
                        final String[] pathsp = path.split("#", 2);
×
45
                        // is quoting this?
NEW
46
                        urlPath = Uris.quote(pathsp[0]);
×
NEW
47
                        if (pathsp.length == 2) {
×
NEW
48
                                frag = "#" + Uris.quote(pathsp[1]);
×
49
                        } else {
NEW
50
                                frag = "";
×
NEW
51
                                urlPath = Uris.quote(path);
×
52
                        }
NEW
53
                } else {
×
NEW
54
                        urlPath = Uris.quote(path);
×
NEW
55
                        frag = "";
×
56
                }
NEW
57
                if (urlPath.startsWith("//")) {
×
NEW
58
                        return "file:" + urlPath + frag;
×
59
                } else {
NEW
60
                        return "file://" + urlPath + frag;
×
61
                }
62
        }
63

64
        public static UriSplit split(final String uriString) {
65
                try {
66
                        final URI uri = new URI(uriString);
1✔
67
                        return new Uris.UriSplit(uri.getScheme(), uri.getAuthority(), uri.getPath(), uri.getQuery(),
1✔
68
                                        uri.getFragment());
1✔
69
                } catch (URISyntaxException e) {
1✔
70
                        return new Uris.UriSplit(null, null, uriString, null, null);
1✔
71
                }
72
        }
73

74
        public static String unsplit(final String scheme, final String netloc, final String path, final String query,
75
                        final String fragment) {
76
                try {
77
                        return new URI(scheme, netloc, path, query, fragment).toString();
1✔
NEW
78
                } catch (URISyntaxException e) {
×
NEW
79
                        if (scheme == null && path.startsWith("_:")) {
×
NEW
80
                                String uri = path;
×
NEW
81
                                if (fragment != null && fragment.length() > 0) {
×
NEW
82
                                        uri += "#" + fragment;
×
83
                                }
NEW
84
                                return fragment;
×
85
                        }
NEW
86
                        throw new RuntimeException(e);
×
87
                }
88
        }
89

90
        public static URI toUri(final String url) {
91
                try {
92
                        return new URI(url);
1✔
NEW
93
                } catch (URISyntaxException e) {
×
NEW
94
                        throw new RuntimeException(e);
×
95
                }
96
        }
97

98
        public static String quote(final String uri) {
99
                try {
NEW
100
                        return java.net.URLDecoder.decode(uri, StandardCharsets.UTF_8.name());
×
NEW
101
                } catch (UnsupportedEncodingException e) {
×
NEW
102
                        throw new RuntimeException(e);
×
103
                }
104
        }
105

106
        public static String unquote(final String uri) {
107
                try {
NEW
108
                        return java.net.URLEncoder.encode(uri, StandardCharsets.UTF_8.name());
×
NEW
109
                } catch (UnsupportedEncodingException e) {
×
NEW
110
                        throw new RuntimeException(e);
×
111
                }
112
        }
113

114
        public static String shortname(final String input_id) {
115
                try {
116
                        final URI uri = new URI(input_id);
1✔
117
                        final String fragment = uri.getFragment();
1✔
118
                        if (fragment != null) {
1✔
119
                                String[] fragment_elements = fragment.split("/");
1✔
120
                                return fragment_elements[fragment_elements.length - 1];
1✔
121
                        } else {
122
                                String[] path_elements = uri.getPath().split("/");
1✔
123
                                return path_elements[path_elements.length - 1];
1✔
124
                        }
NEW
125
                } catch (URISyntaxException e) {
×
NEW
126
                        return input_id;
×
127
                }
128
        }
129
}
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