1 | /*- | |
2 | * #%L | |
3 | * io.earcam.utilitarian.site.search.offline | |
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.search.offline; | |
20 | ||
21 | import static java.nio.charset.StandardCharsets.UTF_8; | |
22 | ||
23 | import java.net.URI; | |
24 | import java.nio.file.Path; | |
25 | import java.nio.file.Paths; | |
26 | import java.util.HashMap; | |
27 | import java.util.Map; | |
28 | ||
29 | import io.earcam.unexceptional.Exceptional; | |
30 | import io.earcam.utilitarian.site.search.offline.ConfigurationModel.Crawling; | |
31 | import io.earcam.utilitarian.site.search.offline.ConfigurationModel.Indexing; | |
32 | import io.earcam.utilitarian.site.search.offline.jsonb.JsonBind; | |
33 | ||
34 | public class Search { | |
35 | ||
36 | public static void main(String[] args) | |
37 | { | |
38 | System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "trace"); | |
39 |
2
1. main : changed conditional boundary → KILLED 2. main : negated conditional → KILLED |
if(args.length < 2) { |
40 | throw new IllegalArgumentException("Expected first arg to be json-output-dir, then at least a further argument of the form 'baseDir@baseUri'"); | |
41 | } | |
42 | ||
43 | final String jsonDir = args[0]; | |
44 | Indexer indexer = null; | |
45 |
3
1. main : changed conditional boundary → KILLED 2. main : Changed increment from 1 to -1 → KILLED 3. main : negated conditional → KILLED |
for(int i = 1; i < args.length; i++) { |
46 | int index = args[i].indexOf('@'); | |
47 |
1
1. main : negated conditional → KILLED |
if(index == -1) { |
48 | throw new IllegalArgumentException("Only arguments expected are 'baseDir@baseUri', recieved '" + args[i] + "' at index " + i); | |
49 | } | |
50 | Path baseDir = Paths.get(args[i].substring(0, index)); | |
51 |
1
1. main : Replaced integer addition with subtraction → KILLED |
URI baseUri = Exceptional.uri(args[i].substring(index + 1)); |
52 | Map<String, String> searchReplace = searchReplaceMap(jsonDir, baseDir, baseUri); | |
53 | ||
54 | String crawlerJson = Resources.getResource(Resources.DEFAULT_CRAWLER_JSON, UTF_8, searchReplace); | |
55 | Crawling crawler = JsonBind.readJson(crawlerJson, Crawling.class); | |
56 | ||
57 |
1
1. main : negated conditional → KILLED |
if(indexer == null) { |
58 | String indexerJson = Resources.getResource(Resources.DEFAULT_INDEXER_JSON, UTF_8, searchReplace); | |
59 | indexer = JsonBind.readJson(indexerJson, Indexing.class).build(); | |
60 | } | |
61 | indexer.add(crawler.build().documents()); | |
62 | } | |
63 | // @SuppressWarnings("squid:S2259") | |
64 |
1
1. main : removed call to io/earcam/utilitarian/site/search/offline/Indexer::writeJson → KILLED |
indexer.writeJson(); // NOSONAR false positive |
65 | } | |
66 | ||
67 | ||
68 | private static Map<String, String> searchReplaceMap(String jsonDir, Path baseDir, URI baseUri) | |
69 | { | |
70 | Map<String, String> searchReplace = new HashMap<>(); | |
71 | searchReplace.put("${outputCharset}", UTF_8.name()); | |
72 | searchReplace.put("${jsonDir}", jsonDir); | |
73 | searchReplace.put("${baseDir}", baseDir.toAbsolutePath().toString()); | |
74 | searchReplace.put("${baseUri}", baseUri.toString()); | |
75 |
1
1. searchReplaceMap : mutated return of Object value for io/earcam/utilitarian/site/search/offline/Search::searchReplaceMap to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return searchReplace; |
76 | } | |
77 | } | |
Mutations | ||
39 |
1.1 2.2 |
|
45 |
1.1 2.2 3.3 |
|
47 |
1.1 |
|
51 |
1.1 |
|
57 |
1.1 |
|
64 |
1.1 |
|
75 |
1.1 |