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

aspectran / aspectran / #3986

15 Jan 2025 04:27AM CUT coverage: 35.056% (+0.05%) from 35.004%
#3986

push

github

topframe
Update

7 of 40 new or added lines in 6 files covered. (17.5%)

2 existing lines in 2 files now uncovered.

14194 of 40489 relevant lines covered (35.06%)

0.35 hits per line

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

10.53
/core/src/main/java/com/aspectran/core/context/resource/ResourceEntries.java
1
/*
2
 * Copyright (c) 2008-2025 The Aspectran Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.aspectran.core.context.resource;
17

18
import com.aspectran.utils.StringUtils;
19
import com.aspectran.utils.annotation.jsr305.NonNull;
20

21
import java.io.File;
22
import java.io.Serial;
23
import java.net.MalformedURLException;
24
import java.net.URI;
25
import java.net.URISyntaxException;
26
import java.net.URL;
27
import java.util.LinkedHashMap;
28
import java.util.jar.JarEntry;
29

30
import static com.aspectran.utils.PathUtils.REGULAR_FILE_SEPARATOR_CHAR;
31
import static com.aspectran.utils.ResourceUtils.JAR_URL_PREFIX;
32
import static com.aspectran.utils.ResourceUtils.JAR_URL_SEPARATOR;
33

34
/**
35
 * The Class ResourceEntries.
36
 *
37
 * <p>Created: 2014. 12. 24 PM 4:54:13</p>
38
 */
39
public class ResourceEntries extends LinkedHashMap<String, URL> {
40

41
    @Serial
42
    private static final long serialVersionUID = -6936820061673430782L;
43

44
    ResourceEntries() {
45
        super();
1✔
46
    }
1✔
47

48
    public void putResource(String name, @NonNull File file) throws InvalidResourceException {
49
        URL url;
50
        try {
51
            url = file.toURI().toURL();
×
52
        } catch (MalformedURLException e) {
×
53
            throw new InvalidResourceException("Invalid resource: " + file, e);
×
54
        }
×
NEW
55
        put(name, url);
×
56
    }
×
57

58
    public void putResource(@NonNull File file, @NonNull JarEntry entry) throws InvalidResourceException {
59
        String resourceName = entry.getName();
×
60
        URL url;
61
        try {
62
            // "jar:file:///C:/proj/parser/jar/parser.jar!/test.xml"
63
            url = new URI(JAR_URL_PREFIX + file.toURI() + JAR_URL_SEPARATOR + resourceName).toURL();
×
64
        } catch (URISyntaxException | MalformedURLException e) {
×
65
            throw new InvalidResourceException("Invalid resource: " + file, e);
×
66
        }
×
67
        put(resourceName, url);
×
68
    }
×
69

70
    @Override
71
    public URL put(String name, URL url) {
NEW
72
        name = name.replace(File.separatorChar, REGULAR_FILE_SEPARATOR_CHAR);
×
NEW
73
        if (StringUtils.endsWith(name, REGULAR_FILE_SEPARATOR_CHAR)) {
×
NEW
74
            name = name.substring(0, name.length() - 1);
×
75
        }
NEW
76
        return super.put(name, url);
×
77
    }
78

79
}
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

© 2025 Coveralls, Inc