1
|
|
package fr.sii.ogham.core.resource.resolver; |
2
|
|
|
3
|
|
import java.io.File; |
4
|
|
import java.io.IOException; |
5
|
|
import java.io.InputStream; |
6
|
|
import java.util.List; |
7
|
|
|
8
|
|
import org.slf4j.Logger; |
9
|
|
import org.slf4j.LoggerFactory; |
10
|
|
|
11
|
|
import fr.sii.ogham.core.exception.resource.ResourceResolutionException; |
12
|
|
import fr.sii.ogham.core.resource.ByteResource; |
13
|
|
import fr.sii.ogham.core.resource.Resource; |
14
|
|
import fr.sii.ogham.core.resource.path.ResolvedPath; |
15
|
|
import fr.sii.ogham.core.resource.path.ResolvedResourcePath; |
16
|
|
import fr.sii.ogham.core.resource.path.ResourcePath; |
17
|
|
|
18
|
|
/** |
19
|
|
* Resource resolver that searches for the resource into the classpath. This |
20
|
|
* implementation is able to manage path starting or not with '/'. The resource |
21
|
|
* resolution needs an absolute class path. The generated resource information |
22
|
|
* will only contain a reference to the stream of the found resource. If the |
23
|
|
* path points nowhere, an {@link ResourceResolutionException} is thrown to |
24
|
|
* indicate that the resource couldn't be found. |
25
|
|
* |
26
|
|
* @author Aurélien Baudet |
27
|
|
* @see ByteResource |
28
|
|
*/ |
29
|
|
public class ClassPathResolver extends AbstractPrefixedLookupPathResolver implements RelativisableResourceResolver { |
30
|
|
|
31
|
|
private static final Logger LOG = LoggerFactory.getLogger(ClassPathResolver.class); |
32
|
|
|
33
|
|
public ClassPathResolver(List<String> lookups) { |
34
|
|
super(lookups); |
35
|
|
} |
36
|
|
|
37
|
|
public ClassPathResolver(String... lookups) { |
38
|
|
super(lookups); |
39
|
|
} |
40
|
|
|
41
|
|
@Override |
42
|
|
public Resource getResource(ResourcePath path) throws ResourceResolutionException { |
43
|
|
ResolvedPath resourcePath = resolve(path); |
44
|
6
1. getResource : replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::getResource → NO_COVERAGE
2. getResource : replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::getResource → TIMED_OUT
3. getResource : replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::getResource → KILLED
4. getResource : replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::getResource → KILLED
5. getResource : replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::getResource → KILLED
6. getResource : replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::getResource → KILLED
|
return getResource(resourcePath); |
45
|
|
} |
46
|
|
|
47
|
|
@Override |
48
|
|
protected Resource getResource(ResolvedPath resourcePath) throws ResourceResolutionException { |
49
|
|
try { |
50
|
|
LOG.debug("Loading resource {} from classpath...", resourcePath); |
51
|
|
String resolvedPath = resourcePath.getResolvedPath(); |
52
|
6
1. getResource : negated conditional → NO_COVERAGE
2. getResource : negated conditional → TIMED_OUT
3. getResource : negated conditional → KILLED
4. getResource : negated conditional → KILLED
5. getResource : negated conditional → KILLED
6. getResource : negated conditional → KILLED
|
InputStream stream = getClass().getClassLoader().getResourceAsStream(resolvedPath.startsWith("/") ? resolvedPath.substring(1) : resolvedPath); |
53
|
6
1. getResource : negated conditional → NO_COVERAGE
2. getResource : negated conditional → TIMED_OUT
3. getResource : negated conditional → KILLED
4. getResource : negated conditional → KILLED
5. getResource : negated conditional → KILLED
6. getResource : negated conditional → KILLED
|
if (stream == null) { |
54
|
|
throw new ResourceResolutionException("Resource " + resolvedPath + " not found in the classpath", resourcePath); |
55
|
|
} |
56
|
|
LOG.debug("Resource {} available in the classpath...", resourcePath); |
57
|
6
1. getResource : replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::getResource → NO_COVERAGE
2. getResource : replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::getResource → TIMED_OUT
3. getResource : replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::getResource → KILLED
4. getResource : replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::getResource → KILLED
5. getResource : replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::getResource → KILLED
6. getResource : replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::getResource → KILLED
|
return new ByteResource(extractName(resolvedPath), stream); |
58
|
|
} catch (IOException e) { |
59
|
|
throw new ResourceResolutionException("The resource " + resourcePath.getOriginalPath() + " is not readable", resourcePath, e); |
60
|
|
} |
61
|
|
} |
62
|
|
|
63
|
|
private static String extractName(String path) { |
64
|
4
1. extractName : replaced return value with "" for fr/sii/ogham/core/resource/resolver/ClassPathResolver::extractName → SURVIVED
2. extractName : replaced return value with "" for fr/sii/ogham/core/resource/resolver/ClassPathResolver::extractName → NO_COVERAGE
3. extractName : replaced return value with "" for fr/sii/ogham/core/resource/resolver/ClassPathResolver::extractName → TIMED_OUT
4. extractName : replaced return value with "" for fr/sii/ogham/core/resource/resolver/ClassPathResolver::extractName → KILLED
|
return new File(path).getName(); |
65
|
|
} |
66
|
|
|
67
|
|
|
68
|
|
@Override |
69
|
|
public boolean isAbsolute(ResourcePath path) { |
70
|
|
ResolvedPath resourcePath = resolve(path); |
71
|
14
1. isAbsolute : replaced boolean return with false for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → NO_COVERAGE
2. isAbsolute : replaced boolean return with false for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → SURVIVED
3. isAbsolute : replaced boolean return with true for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → NO_COVERAGE
4. isAbsolute : replaced boolean return with false for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → TIMED_OUT
5. isAbsolute : replaced boolean return with true for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → TIMED_OUT
6. isAbsolute : replaced boolean return with false for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → KILLED
7. isAbsolute : replaced boolean return with false for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → KILLED
8. isAbsolute : replaced boolean return with false for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → KILLED
9. isAbsolute : replaced boolean return with false for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → KILLED
10. isAbsolute : replaced boolean return with true for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → KILLED
11. isAbsolute : replaced boolean return with true for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → KILLED
12. isAbsolute : replaced boolean return with true for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → KILLED
13. isAbsolute : replaced boolean return with true for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → KILLED
14. isAbsolute : replaced boolean return with true for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → KILLED
|
return resourcePath.getResolvedPath().startsWith("/"); |
72
|
|
} |
73
|
|
|
74
|
|
@Override |
75
|
|
public ResolvedPath resolve(ResourcePath relativePath, String prefixPath, String suffixPath) { |
76
|
|
ResolvedPath resourcePath = resolve(relativePath); |
77
|
|
String lookup = getLookup(relativePath); |
78
|
5
1. resolve : replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::resolve → NO_COVERAGE
2. resolve : replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::resolve → KILLED
3. resolve : replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::resolve → KILLED
4. resolve : replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::resolve → KILLED
5. resolve : replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::resolve → KILLED
|
return new ResolvedResourcePath(relativePath, lookup, prefixPath + resourcePath.getResolvedPath() + suffixPath); |
79
|
|
} |
80
|
|
} |
| | Mutations |
44 |
|
1.1 Location : getResource Killed by : oghamthymeleafv3.it.ThymeleafDetectorTest.foundButEmpty(oghamthymeleafv3.it.ThymeleafDetectorTest) replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::getResource → KILLED 2.2 Location : getResource Killed by : oghamthymeleafv2.it.ThymeleafDetectorTest.foundButEmpty(oghamthymeleafv2.it.ThymeleafDetectorTest) replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::getResource → KILLED 3.3 Location : getResource Killed by : none replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::getResource → TIMED_OUT 4.4 Location : getResource Killed by : none replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::getResource → NO_COVERAGE 5.5 Location : getResource Killed by : oghamall.it.html.translator.JsoupInlineCssTranslatorTest.externalStyles(oghamall.it.html.translator.JsoupInlineCssTranslatorTest) replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::getResource → KILLED 6.6 Location : getResource Killed by : oghamcore.it.core.resource.resolver.FirstSupportingResolverTest.none(oghamcore.it.core.resource.resolver.FirstSupportingResolverTest) replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::getResource → KILLED
|
52 |
|
1.1 Location : getResource Killed by : oghamcore.it.core.resource.resolver.FirstSupportingResolverTest.none(oghamcore.it.core.resource.resolver.FirstSupportingResolverTest) negated conditional → KILLED 2.2 Location : getResource Killed by : oghamthymeleafv2.it.ThymeleafDetectorTest.foundButEmpty(oghamthymeleafv2.it.ThymeleafDetectorTest) negated conditional → KILLED 3.3 Location : getResource Killed by : oghamthymeleafv3.it.ThymeleafDetectorTest.foundButEmpty(oghamthymeleafv3.it.ThymeleafDetectorTest) negated conditional → KILLED 4.4 Location : getResource Killed by : none negated conditional → NO_COVERAGE 5.5 Location : getResource Killed by : none negated conditional → TIMED_OUT 6.6 Location : getResource Killed by : oghamall.it.html.translator.JsoupInlineCssTranslatorTest.externalStyles(oghamall.it.html.translator.JsoupInlineCssTranslatorTest) negated conditional → KILLED
|
53 |
|
1.1 Location : getResource Killed by : none negated conditional → TIMED_OUT 2.2 Location : getResource Killed by : none negated conditional → NO_COVERAGE 3.3 Location : getResource Killed by : oghamthymeleafv3.it.ThymeleafDetectorTest.notFound(oghamthymeleafv3.it.ThymeleafDetectorTest) negated conditional → KILLED 4.4 Location : getResource Killed by : oghamcore.it.core.resource.resolver.FirstSupportingResolverTest.none(oghamcore.it.core.resource.resolver.FirstSupportingResolverTest) negated conditional → KILLED 5.5 Location : getResource Killed by : oghamthymeleafv2.it.ThymeleafDetectorTest.notFound(oghamthymeleafv2.it.ThymeleafDetectorTest) negated conditional → KILLED 6.6 Location : getResource Killed by : oghamall.it.html.translator.JsoupInlineCssTranslatorTest.unreadableCss(oghamall.it.html.translator.JsoupInlineCssTranslatorTest) negated conditional → KILLED
|
57 |
|
1.1 Location : getResource Killed by : oghamthymeleafv3.it.ThymeleafDetectorTest.foundButEmpty(oghamthymeleafv3.it.ThymeleafDetectorTest) replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::getResource → KILLED 2.2 Location : getResource Killed by : oghamall.it.html.translator.JsoupInlineCssTranslatorTest.externalStyles(oghamall.it.html.translator.JsoupInlineCssTranslatorTest) replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::getResource → KILLED 3.3 Location : getResource Killed by : oghamthymeleafv2.it.ThymeleafDetectorTest.foundButEmpty(oghamthymeleafv2.it.ThymeleafDetectorTest) replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::getResource → KILLED 4.4 Location : getResource Killed by : none replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::getResource → TIMED_OUT 5.5 Location : getResource Killed by : none replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::getResource → NO_COVERAGE 6.6 Location : getResource Killed by : oghamcore.it.core.resource.resolver.FirstSupportingResolverTest.none(oghamcore.it.core.resource.resolver.FirstSupportingResolverTest) replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::getResource → KILLED
|
64 |
|
1.1 Location : extractName Killed by : none replaced return value with "" for fr/sii/ogham/core/resource/resolver/ClassPathResolver::extractName → SURVIVED 2.2 Location : extractName Killed by : oghamall.it.email.EmailSMTPDefaultsTest.attachmentLookup(oghamall.it.email.EmailSMTPDefaultsTest) replaced return value with "" for fr/sii/ogham/core/resource/resolver/ClassPathResolver::extractName → KILLED 3.3 Location : extractName Killed by : none replaced return value with "" for fr/sii/ogham/core/resource/resolver/ClassPathResolver::extractName → NO_COVERAGE 4.4 Location : extractName Killed by : none replaced return value with "" for fr/sii/ogham/core/resource/resolver/ClassPathResolver::extractName → TIMED_OUT
|
71 |
|
1.1 Location : isAbsolute Killed by : oghamall.it.email.EmailMultiTemplateTest.withThymeleafOneVariantWithParsingError(oghamall.it.email.EmailMultiTemplateTest) replaced boolean return with false for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → KILLED 2.2 Location : isAbsolute Killed by : none replaced boolean return with false for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → TIMED_OUT 3.3 Location : isAbsolute Killed by : none replaced boolean return with false for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → NO_COVERAGE 4.4 Location : isAbsolute Killed by : none replaced boolean return with false for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → SURVIVED 5.5 Location : isAbsolute Killed by : oghamthymeleafv2.it.ThymeleafDetectorTest.foundButEmpty(oghamthymeleafv2.it.ThymeleafDetectorTest) replaced boolean return with false for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → KILLED 6.6 Location : isAbsolute Killed by : oghamthymeleafv3.it.ThymeleafDetectorTest.foundButEmpty(oghamthymeleafv3.it.ThymeleafDetectorTest) replaced boolean return with false for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → KILLED 7.7 Location : isAbsolute Killed by : oghamcore.it.html.translator.InlineImageTranslatorTest.absoluteUrlsShouldBeAutomaticallySkipped(oghamcore.it.html.translator.InlineImageTranslatorTest) replaced boolean return with false for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → KILLED 8.8 Location : isAbsolute Killed by : oghamfremarker.it.FreeMarkerParserTest.nested(oghamfremarker.it.FreeMarkerParserTest) replaced boolean return with true for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → KILLED 9.9 Location : isAbsolute Killed by : oghamthymeleafv2.it.ThymeleafDetectorTest.found(oghamthymeleafv2.it.ThymeleafDetectorTest) replaced boolean return with true for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → KILLED 10.10 Location : isAbsolute Killed by : oghamcore.it.html.translator.InlineImageTranslatorTest.oghamAttributesShoulBeRemoved(oghamcore.it.html.translator.InlineImageTranslatorTest) replaced boolean return with true for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → KILLED 11.11 Location : isAbsolute Killed by : none replaced boolean return with true for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → NO_COVERAGE 12.12 Location : isAbsolute Killed by : oghamthymeleafv3.it.ThymeleafDetectorTest.foundWithoutNamespace(oghamthymeleafv3.it.ThymeleafDetectorTest) replaced boolean return with true for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → KILLED 13.13 Location : isAbsolute Killed by : none replaced boolean return with true for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → TIMED_OUT 14.14 Location : isAbsolute Killed by : oghamall.it.html.translator.JsoupInlineCssTranslatorTest.externalStyles(oghamall.it.html.translator.JsoupInlineCssTranslatorTest) replaced boolean return with true for fr/sii/ogham/core/resource/resolver/ClassPathResolver::isAbsolute → KILLED
|
78 |
|
1.1 Location : resolve Killed by : none replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::resolve → NO_COVERAGE 2.2 Location : resolve Killed by : oghamall.it.html.translator.JsoupInlineCssTranslatorTest.unreadableCss(oghamall.it.html.translator.JsoupInlineCssTranslatorTest) replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::resolve → KILLED 3.3 Location : resolve Killed by : oghamthymeleafv2.it.ThymeleafDetectorTest.notFound(oghamthymeleafv2.it.ThymeleafDetectorTest) replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::resolve → KILLED 4.4 Location : resolve Killed by : oghamcore.it.html.translator.InlineImageTranslatorTest.oghamAttributesShoulBeRemoved(oghamcore.it.html.translator.InlineImageTranslatorTest) replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::resolve → KILLED 5.5 Location : resolve Killed by : oghamthymeleafv3.it.ThymeleafDetectorTest.notFound(oghamthymeleafv3.it.ThymeleafDetectorTest) replaced return value with null for fr/sii/ogham/core/resource/resolver/ClassPathResolver::resolve → KILLED
|