View Javadoc
1   /*-
2    * #%L
3    * io.earcam.maven.plugin.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.maven.plugin.sitemap;
20  
21  import java.io.File;
22  import java.net.URI;
23  import java.util.regex.Pattern;
24  
25  import org.apache.maven.plugin.AbstractMojo;
26  import org.apache.maven.plugins.annotations.Parameter;
27  import org.apache.maven.project.MavenProject;
28  
29  import io.earcam.utilitarian.site.sitemap.SitemapParameters;
30  
31  public abstract class AbstractSitemapMojo extends AbstractMojo {
32  
33  	@Parameter(defaultValue = "${project}", readonly = true, required = true)
34  	protected MavenProject project;
35  
36  	/**
37  	 * Whether to GZIP the generated files
38  	 */
39  	@Parameter(property = "sitemap.gzip", defaultValue = "false")
40  	protected boolean gzip;
41  
42  	/**
43  	 * Regular expression determining which file names to include
44  	 */
45  	@Parameter(property = "sitemap.include.regex", defaultValue = ".*\\.html?$")
46  	protected String include;
47  
48  	/**
49  	 * The site's base URL, defaults to ${project.distributionManagement.site.url}
50  	 */
51  	@Parameter(property = "sitemap.url.base", defaultValue = "${project.distributionManagement.site.url}")
52  	protected URI baseUrl;
53  
54  	/**
55  	 * Location of files to index, defaults to ${project.reporting.outputDirectory}
56  	 */
57  	@Parameter(property = "sitemap.dir.source", defaultValue = "${project.reporting.outputDirectory}")
58  	protected File sourceDir;
59  
60  	/**
61  	 * Location of where the sitemap/index should be written, defaults to ${project.reporting.outputDirectory}
62  	 */
63  	@Parameter(property = "sitemap.dir.target", defaultValue = "${project.reporting.outputDirectory}")
64  	protected File targetDir;
65  
66  	/**
67  	 * Skip execution of this plugin
68  	 */
69  	@Parameter(property = "sitemap.skip", defaultValue = "false")
70  	protected boolean skip;
71  
72  
73  	protected SitemapParameters parameters()
74  	{
75  		SitemapParameters parameters = new SitemapParameters(baseUrl, sourceDir.toPath(), targetDir.toPath());
76  		parameters.options().setGzip(gzip);
77  		parameters.options().setInclude(Pattern.compile(include));
78  		return parameters;
79  	}
80  }