FileResolver.java

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
Location : getResource
Killed by : oghamcore.it.core.resource.resolver.FirstSupportingResolverTest.file(oghamcore.it.core.resource.resolver.FirstSupportingResolverTest)
negated conditional → KILLED

2.2
Location : getResource
Killed by : oghamall.it.email.ExternalFileTest.thymeleafHtmlFileFreemarkerTextFile(oghamall.it.email.ExternalFileTest)
negated conditional → KILLED

3.3
Location : getResource
Killed by : none
negated conditional → NO_COVERAGE

49

1.1
Location : getResource
Killed by : oghamall.it.email.ExternalFileTest.thymeleafHtmlFileFreemarkerTextFile(oghamall.it.email.ExternalFileTest)
replaced return value with null for fr/sii/ogham/core/resource/resolver/FileResolver::getResource → KILLED

2.2
Location : getResource
Killed by : oghamcore.it.core.resource.resolver.FirstSupportingResolverTest.file(oghamcore.it.core.resource.resolver.FirstSupportingResolverTest)
replaced return value with null for fr/sii/ogham/core/resource/resolver/FileResolver::getResource → KILLED

3.3
Location : getResource
Killed by : none
replaced return value with null for fr/sii/ogham/core/resource/resolver/FileResolver::getResource → NO_COVERAGE

56

1.1
Location : isAbsolute
Killed by : none
replaced boolean return with false for fr/sii/ogham/core/resource/resolver/FileResolver::isAbsolute → SURVIVED

2.2
Location : isAbsolute
Killed by : none
replaced boolean return with false for fr/sii/ogham/core/resource/resolver/FileResolver::isAbsolute → NO_COVERAGE

3.3
Location : isAbsolute
Killed by : oghamall.it.email.ExternalFileTest.thymeleafHtmlFileFreemarkerTextFile(oghamall.it.email.ExternalFileTest)
replaced boolean return with false for fr/sii/ogham/core/resource/resolver/FileResolver::isAbsolute → KILLED

4.4
Location : isAbsolute
Killed by : none
replaced boolean return with true for fr/sii/ogham/core/resource/resolver/FileResolver::isAbsolute → NO_COVERAGE

5.5
Location : isAbsolute
Killed by : oghamthymeleafv3.it.ExternalFileTest.fileUnreadable(oghamthymeleafv3.it.ExternalFileTest)
replaced boolean return with true for fr/sii/ogham/core/resource/resolver/FileResolver::isAbsolute → KILLED

6.6
Location : isAbsolute
Killed by : oghamall.it.email.ExternalFileTest.thymeleafHtmlFileFreemarkerTextFile(oghamall.it.email.ExternalFileTest)
replaced boolean return with true for fr/sii/ogham/core/resource/resolver/FileResolver::isAbsolute → KILLED

7.7
Location : isAbsolute
Killed by : oghamthymeleafv2.it.ExternalFileTest.fileUpdatedButUseThymeleafCache(oghamthymeleafv2.it.ExternalFileTest)
replaced boolean return with true for fr/sii/ogham/core/resource/resolver/FileResolver::isAbsolute → KILLED

63

1.1
Location : resolve
Killed by : none
replaced return value with null for fr/sii/ogham/core/resource/resolver/FileResolver::resolve → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT OGHAM