| 1 | package fr.sii.ogham.core.resource.resolver; | |
| 2 | ||
| 3 | import java.io.File; | |
| 4 | import java.util.List; | |
| 5 | ||
| 6 | import org.slf4j.Logger; | |
| 7 | import org.slf4j.LoggerFactory; | |
| 8 | ||
| 9 | import fr.sii.ogham.core.exception.resource.ResourceResolutionException; | |
| 10 | import fr.sii.ogham.core.resource.FileResource; | |
| 11 | import fr.sii.ogham.core.resource.Resource; | |
| 12 | import fr.sii.ogham.core.resource.path.ResolvedPath; | |
| 13 | import fr.sii.ogham.core.resource.path.ResolvedResourcePath; | |
| 14 | import fr.sii.ogham.core.resource.path.ResourcePath; | |
| 15 | ||
| 16 | /** | |
| 17 | * Resource resolver that searches for the resource on the file system. The | |
| 18 | * resource resolution can handle relative path but it depends on the runtime | |
| 19 | * environment. It is better to provide an absolute path. The generated resource | |
| 20 | * information will only contain a reference to the stream of the found | |
| 21 | * resource. If file pointed out by the path doesn't exist, then an | |
| 22 | * {@link ResourceResolutionException} is thrown to indicate that the resource | |
| 23 | * couldn't be found. | |
| 24 | * | |
| 25 | * @author Aurélien Baudet | |
| 26 | * @see FileResource | |
| 27 | */ | |
| 28 | public class FileResolver extends AbstractPrefixedLookupPathResolver implements RelativisableResourceResolver { | |
| 29 | private static final Logger LOG = LoggerFactory.getLogger(FileResolver.class); | |
| 30 | ||
| 31 | public FileResolver(List<String> lookups) { | |
| 32 | super(lookups); | |
| 33 | } | |
| 34 | ||
| 35 | public FileResolver(String... lookups) { | |
| 36 | super(lookups); | |
| 37 | } | |
| 38 | ||
| 39 | @Override | |
| 40 | protected Resource getResource(ResolvedPath resourcePath) throws ResourceResolutionException { | |
| 41 | LOG.debug("Loading resource {} from file system", resourcePath); | |
| 42 | String resolvedPath = resourcePath.getResolvedPath(); | |
| 43 | File file = new File(resolvedPath); | |
| 44 |
3
1. getResource : negated conditional → NO_COVERAGE 2. getResource : negated conditional → KILLED 3. getResource : negated conditional → KILLED |
if (!file.exists()) { |
| 45 | throw new ResourceResolutionException("Resource " + resolvedPath + " not found on file system", resourcePath); | |
| 46 | } | |
| 47 | Resource resource = new FileResource(file); | |
| 48 | LOG.debug("Resource {} found on the file system", resourcePath); | |
| 49 |
3
1. getResource : replaced return value with null for fr/sii/ogham/core/resource/resolver/FileResolver::getResource → NO_COVERAGE 2. getResource : replaced return value with null for fr/sii/ogham/core/resource/resolver/FileResolver::getResource → KILLED 3. getResource : replaced return value with null for fr/sii/ogham/core/resource/resolver/FileResolver::getResource → KILLED |
return resource; |
| 50 | } | |
| 51 | ||
| 52 | ||
| 53 | @Override | |
| 54 | public boolean isAbsolute(ResourcePath path) { | |
| 55 | ResolvedPath resourcePath = resolve(path); | |
| 56 |
7
1. isAbsolute : replaced boolean return with false for fr/sii/ogham/core/resource/resolver/FileResolver::isAbsolute → SURVIVED 2. isAbsolute : replaced boolean return with false for fr/sii/ogham/core/resource/resolver/FileResolver::isAbsolute → NO_COVERAGE 3. isAbsolute : replaced boolean return with true for fr/sii/ogham/core/resource/resolver/FileResolver::isAbsolute → NO_COVERAGE 4. isAbsolute : replaced boolean return with false for fr/sii/ogham/core/resource/resolver/FileResolver::isAbsolute → KILLED 5. isAbsolute : replaced boolean return with true for fr/sii/ogham/core/resource/resolver/FileResolver::isAbsolute → KILLED 6. isAbsolute : replaced boolean return with true for fr/sii/ogham/core/resource/resolver/FileResolver::isAbsolute → KILLED 7. isAbsolute : replaced boolean return with true for fr/sii/ogham/core/resource/resolver/FileResolver::isAbsolute → KILLED |
return new File(resourcePath.getResolvedPath()).isAbsolute(); |
| 57 | } | |
| 58 | ||
| 59 | @Override | |
| 60 | public ResolvedPath resolve(ResourcePath relativePath, String prefixPath, String suffixPath) { | |
| 61 | ResolvedPath resourcePath = resolve(relativePath); | |
| 62 | String lookup = getLookup(relativePath); | |
| 63 |
1
1. resolve : replaced return value with null for fr/sii/ogham/core/resource/resolver/FileResolver::resolve → NO_COVERAGE |
return new ResolvedResourcePath(relativePath, lookup, prefixPath + resourcePath.getResolvedPath() + suffixPath); |
| 64 | } | |
| 65 | } | |
Mutations | ||
| 44 |
1.1 2.2 3.3 |
|
| 49 |
1.1 2.2 3.3 |
|
| 56 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 |
|
| 63 |
1.1 |