SitemapParameters.java

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.unexceptional.Exceptional.uri;
22
23
import java.io.Externalizable;
24
import java.io.IOException;
25
import java.io.InputStream;
26
import java.io.ObjectInput;
27
import java.io.ObjectInputStream;
28
import java.io.ObjectOutput;
29
import java.io.ObjectOutputStream;
30
import java.io.OutputStream;
31
import java.net.URI;
32
import java.nio.file.Path;
33
import java.nio.file.Paths;
34
import java.util.regex.Pattern;
35
36
import javax.annotation.ParametersAreNonnullByDefault;
37
import javax.annotation.WillClose;
38
39
import io.earcam.unexceptional.Closing;
40
import io.earcam.unexceptional.Exceptional;
41
42
//False positive, non-serializable fields on an Externalizable do not need to be made transient
43
@SuppressWarnings("squid:S1948")
44
@ParametersAreNonnullByDefault
45
public class SitemapParameters implements Externalizable {
46
47
	private static final long serialVersionUID = 337311296864382134L;
48
49
	public static final Pattern INCLUDE_ALL = Pattern.compile("^.*$");
50
51
	public static class SitemapOptions implements Externalizable {
52
53
		private static final long serialVersionUID = 8178383333097167552L;
54
55
		private boolean gzip;
56
		private Pattern include = INCLUDE_ALL;
57
58
59
		@Override
60
		public void writeExternal(ObjectOutput out) throws IOException
61
		{
62 1 1. writeExternal : removed call to java/io/ObjectOutput::writeBoolean → KILLED
			out.writeBoolean(gzip);
63 1 1. writeExternal : removed call to java/io/ObjectOutput::writeUTF → KILLED
			out.writeUTF(include.pattern());
64
		}
65
66
67
		@Override
68
		public void readExternal(ObjectInput in) throws IOException
69
		{
70
			gzip = in.readBoolean();
71
			include = Pattern.compile(in.readUTF());
72
		}
73
74
75
		public boolean gzipped()
76
		{
77 1 1. gzipped : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED
			return gzip;
78
		}
79
80
81
		public void setGzip(boolean gzip)
82
		{
83
			this.gzip = gzip;
84
		}
85
86
87
		public Pattern include()
88
		{
89 1 1. include : mutated return of Object value for io/earcam/utilitarian/site/sitemap/SitemapParameters$SitemapOptions::include to ( if (x != null) null else throw new RuntimeException ) → KILLED
			return include;
90
		}
91
92
93
		public void setInclude(Pattern include)
94
		{
95
			this.include = include;
96
		}
97
98
	}
99
100
	private SitemapOptions options = new SitemapOptions();
101
	URI base;
102
	Path sourceDir;
103
	Path targetDir;
104
105
106
	SitemapParameters()
107
	{}
108
109
110
	public SitemapParameters(URI base, Path sourcePath, Path targetPath)
111
	{
112
		this.base = ensureTrailingSlash(base);
113
		sourceDir = sourcePath;
114
		targetDir = targetPath;
115
		targetDir.toFile().mkdirs();
116
	}
117
118
119
	private static URI ensureTrailingSlash(URI uri)
120
	{
121
		String yuri = uri.toString();
122 3 1. ensureTrailingSlash : Replaced integer subtraction with addition → KILLED
2. ensureTrailingSlash : negated conditional → KILLED
3. ensureTrailingSlash : mutated return of Object value for io/earcam/utilitarian/site/sitemap/SitemapParameters::ensureTrailingSlash to ( if (x != null) null else throw new RuntimeException ) → KILLED
		return yuri.charAt(yuri.length() - 1) == '/' ? uri : Exceptional.uri(yuri + '/');
123
	}
124
125
126
	@Override
127
	public void writeExternal(ObjectOutput out) throws IOException
128
	{
129 1 1. writeExternal : removed call to io/earcam/utilitarian/site/sitemap/SitemapParameters$SitemapOptions::writeExternal → KILLED
		options.writeExternal(out);
130 1 1. writeExternal : removed call to java/io/ObjectOutput::writeUTF → KILLED
		out.writeUTF(base.toString());
131 1 1. writeExternal : removed call to java/io/ObjectOutput::writeUTF → KILLED
		out.writeUTF(sourceDir.toAbsolutePath().toString());
132 1 1. writeExternal : removed call to java/io/ObjectOutput::writeUTF → KILLED
		out.writeUTF(targetDir.toAbsolutePath().toString());
133
	}
134
135
136
	@Override
137
	public void readExternal(ObjectInput in) throws IOException
138
	{
139 1 1. readExternal : removed call to io/earcam/utilitarian/site/sitemap/SitemapParameters$SitemapOptions::readExternal → KILLED
		options.readExternal(in);
140
		base = uri(in.readUTF());
141
		sourceDir = Paths.get(in.readUTF());
142
		targetDir = Paths.get(in.readUTF());
143
	}
144
145
146
	public SitemapOptions options()
147
	{
148 1 1. options : mutated return of Object value for io/earcam/utilitarian/site/sitemap/SitemapParameters::options to ( if (x != null) null else throw new RuntimeException ) → KILLED
		return options;
149
	}
150
151
152
	public void serialize(@WillClose OutputStream out)
153
	{
154 1 1. serialize : removed call to io/earcam/unexceptional/Closing::closeAfterAccepting → KILLED
		Closing.closeAfterAccepting(ObjectOutputStream::new, out, this::writeExternal);
155
	}
156
157
158
	public SitemapParameters deserialize(@WillClose InputStream in)
159
	{
160 1 1. deserialize : removed call to io/earcam/unexceptional/Closing::closeAfterAccepting → KILLED
		Closing.closeAfterAccepting(ObjectInputStream::new, in, this::readExternal);
161 1 1. deserialize : mutated return of Object value for io/earcam/utilitarian/site/sitemap/SitemapParameters::deserialize to ( if (x != null) null else throw new RuntimeException ) → KILLED
		return this;
162
	}
163
}

Mutations

62

1.1
Location : writeExternal
Killed by : io.earcam.utilitarian.site.sitemap.SitemapParametersTest.serialization()
removed call to java/io/ObjectOutput::writeBoolean → KILLED

63

1.1
Location : writeExternal
Killed by : io.earcam.utilitarian.site.sitemap.SitemapParametersTest.serialization()
removed call to java/io/ObjectOutput::writeUTF → KILLED

77

1.1
Location : gzipped
Killed by : io.earcam.utilitarian.site.sitemap.SitemapsTest.createSitemap()
replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED

89

1.1
Location : include
Killed by : io.earcam.utilitarian.site.sitemap.SitemapsTest.createSitemap()
mutated return of Object value for io/earcam/utilitarian/site/sitemap/SitemapParameters$SitemapOptions::include to ( if (x != null) null else throw new RuntimeException ) → KILLED

122

1.1
Location : ensureTrailingSlash
Killed by : io.earcam.utilitarian.site.sitemap.SitemapParametersTest.serialization()
Replaced integer subtraction with addition → KILLED

2.2
Location : ensureTrailingSlash
Killed by : io.earcam.utilitarian.site.sitemap.SitemapTest.simpleSitemap()
negated conditional → KILLED

3.3
Location : ensureTrailingSlash
Killed by : io.earcam.utilitarian.site.sitemap.SitemapParametersTest.serialization()
mutated return of Object value for io/earcam/utilitarian/site/sitemap/SitemapParameters::ensureTrailingSlash to ( if (x != null) null else throw new RuntimeException ) → KILLED

129

1.1
Location : writeExternal
Killed by : io.earcam.utilitarian.site.sitemap.SitemapParametersTest.serialization()
removed call to io/earcam/utilitarian/site/sitemap/SitemapParameters$SitemapOptions::writeExternal → KILLED

130

1.1
Location : writeExternal
Killed by : io.earcam.utilitarian.site.sitemap.SitemapParametersTest.serialization()
removed call to java/io/ObjectOutput::writeUTF → KILLED

131

1.1
Location : writeExternal
Killed by : io.earcam.utilitarian.site.sitemap.SitemapParametersTest.serialization()
removed call to java/io/ObjectOutput::writeUTF → KILLED

132

1.1
Location : writeExternal
Killed by : io.earcam.utilitarian.site.sitemap.SitemapParametersTest.serialization()
removed call to java/io/ObjectOutput::writeUTF → KILLED

139

1.1
Location : readExternal
Killed by : io.earcam.utilitarian.site.sitemap.SitemapParametersTest.serialization()
removed call to io/earcam/utilitarian/site/sitemap/SitemapParameters$SitemapOptions::readExternal → KILLED

148

1.1
Location : options
Killed by : io.earcam.utilitarian.site.sitemap.SitemapParametersTest.serialization()
mutated return of Object value for io/earcam/utilitarian/site/sitemap/SitemapParameters::options to ( if (x != null) null else throw new RuntimeException ) → KILLED

154

1.1
Location : serialize
Killed by : io.earcam.utilitarian.site.sitemap.SitemapParametersTest.serialization()
removed call to io/earcam/unexceptional/Closing::closeAfterAccepting → KILLED

160

1.1
Location : deserialize
Killed by : io.earcam.utilitarian.site.sitemap.SitemapsTest.robotsTxt()
removed call to io/earcam/unexceptional/Closing::closeAfterAccepting → KILLED

161

1.1
Location : deserialize
Killed by : io.earcam.utilitarian.site.sitemap.SitemapsTest.robotsTxt()
mutated return of Object value for io/earcam/utilitarian/site/sitemap/SitemapParameters::deserialize to ( if (x != null) null else throw new RuntimeException ) → KILLED

Active mutators

Tests examined


Report generated by PIT 1.4.3