| 1 | /*- | |
| 2 |  * #%L | |
| 3 |  * io.earcam.utilitarian.site.sitemap | |
| 4 |  * %% | |
| 5 |  * Copyright (C) 2017 earcam | |
| 6 |  * %% | |
| 7 |  * SPDX-License-Identifier: (BSD-3-Clause OR EPL-1.0 OR Apache-2.0 OR MIT) | |
| 8 |  * | |
| 9 |  * You <b>must</b> choose to accept, in full - any individual or combination of | |
| 10 |  * the following licenses: | |
| 11 |  * <ul> | |
| 12 |  * 	<li><a href="https://opensource.org/licenses/BSD-3-Clause">BSD-3-Clause</a></li> | |
| 13 |  * 	<li><a href="https://www.eclipse.org/legal/epl-v10.html">EPL-1.0</a></li> | |
| 14 |  * 	<li><a href="https://www.apache.org/licenses/LICENSE-2.0">Apache-2.0</a></li> | |
| 15 |  * 	<li><a href="https://opensource.org/licenses/MIT">MIT</a></li> | |
| 16 |  * </ul> | |
| 17 |  * #L% | |
| 18 |  */ | |
| 19 | package io.earcam.utilitarian.site.sitemap; | |
| 20 | ||
| 21 | import static io.earcam.utilitarian.site.sitemap.SitemapParameters.INCLUDE_ALL; | |
| 22 | ||
| 23 | import java.io.IOException; | |
| 24 | import java.net.URI; | |
| 25 | import java.nio.file.Files; | |
| 26 | import java.nio.file.Path; | |
| 27 | import java.util.function.Consumer; | |
| 28 | import java.util.function.Predicate; | |
| 29 | import java.util.stream.Stream; | |
| 30 | ||
| 31 | import javax.annotation.concurrent.NotThreadSafe; | |
| 32 | ||
| 33 | @NotThreadSafe | |
| 34 | public class Sitemap extends AbstractSitemap { | |
| 35 | ||
| 36 | 	public static final String NAME_SITEMAP = "sitemap"; | |
| 37 | ||
| 38 | 	private static final String TAG_URL = "url"; | |
| 39 | ||
| 40 | 	private static final String HEAD = "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">"; | |
| 41 | ||
| 42 | 	private static final String TAIL = "</urlset>"; | |
| 43 | ||
| 44 | 	URI sourceUri; | |
| 45 | ||
| 46 | ||
| 47 | 	public Sitemap(SitemapParameters parameters, Consumer<Path> generatedFileRecorder) | |
| 48 | 	{ | |
| 49 | 		super(parameters, HEAD, TAG_URL, TAIL, generatedFileRecorder); | |
| 50 | 		sourceUri = parameters.sourceDir.toUri(); | |
| 51 | 	} | |
| 52 | ||
| 53 | ||
| 54 | 	public void run() throws IOException | |
| 55 | 	{ | |
| 56 | 		Stream<Path> files = Files.walk(parameters.sourceDir) | |
| 57 | 
1
1. lambda$run$0 : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED | 
				.filter(Files::isRegularFile); | 
| 58 | 		files = filter(files); | |
| 59 | 
1
1. run : removed call to io/earcam/utilitarian/site/sitemap/Sitemap::process → KILLED | 
		process(files.sequential()); | 
| 60 | 	} | |
| 61 | ||
| 62 | ||
| 63 | 	private Stream<Path> filter(Stream<Path> files) | |
| 64 | 	{ | |
| 65 | 
1
1. filter : negated conditional → KILLED | 
		if(!INCLUDE_ALL.equals(parameters.options().include())) { | 
| 66 | 			Predicate<String> filter = parameters.options().include().asPredicate(); | |
| 67 | 
2
1. filter : mutated return of Object value for io/earcam/utilitarian/site/sitemap/Sitemap::filter to ( if (x != null) null else throw new RuntimeException ) → KILLED 2. lambda$filter$1 : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED  | 
			return files.filter(f -> filter.test(f.toAbsolutePath().toString())); | 
| 68 | 		} | |
| 69 | 
1
1. filter : mutated return of Object value for io/earcam/utilitarian/site/sitemap/Sitemap::filter to ( if (x != null) null else throw new RuntimeException ) → KILLED | 
		return files; | 
| 70 | 	} | |
| 71 | ||
| 72 | ||
| 73 | 	@Override | |
| 74 | 	protected Path filename() | |
| 75 | 	{ | |
| 76 | 
2
1. filename : Replaced integer addition with subtraction → KILLED 2. filename : mutated return of Object value for io/earcam/utilitarian/site/sitemap/Sitemap::filename to ( if (x != null) null else throw new RuntimeException ) → KILLED  | 
		return filename(parameters, NAME_SITEMAP + (++indexFileSuffix)); | 
| 77 | 	} | |
| 78 | ||
| 79 | ||
| 80 | 	/* | |
| 81 | 	 * Relativize the local dir as URI then apply as resolve to base URL | |
| 82 | 	 */ | |
| 83 | 	@Override | |
| 84 | 	protected String createUrl(Path siteResourceFile) throws IOException | |
| 85 | 	{ | |
| 86 | 		URI uri = sourceUri.relativize(siteResourceFile.toUri()); | |
| 87 | 
1
1. createUrl : mutated return of Object value for io/earcam/utilitarian/site/sitemap/Sitemap::createUrl to ( if (x != null) null else throw new RuntimeException ) → KILLED | 
		return parameters.base.resolve(uri).toString(); | 
| 88 | 	} | |
| 89 | } | |
Mutations | ||
| 57 | 
 
 1.1  | 
|
| 59 | 
 
 1.1  | 
|
| 65 | 
 
 1.1  | 
|
| 67 | 
 
 1.1 2.2  | 
|
| 69 | 
 
 1.1  | 
|
| 76 | 
 
 1.1 2.2  | 
|
| 87 | 
 
 1.1  |