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 static org.apache.maven.plugins.annotations.LifecyclePhase.SITE;
22  
23  import java.nio.file.Files;
24  import java.nio.file.Path;
25  
26  import org.apache.maven.plugin.MojoExecutionException;
27  import org.apache.maven.plugin.MojoFailureException;
28  import org.apache.maven.plugins.annotations.Mojo;
29  import org.slf4j.Logger;
30  import org.slf4j.LoggerFactory;
31  
32  import io.earcam.unexceptional.Exceptional;
33  import io.earcam.utilitarian.site.sitemap.Sitemaps;
34  
35  /**
36   * Mojo for generating sitemaps
37   */
38  @Mojo(name = SitemapMojo.NAME, requiresProject = true, threadSafe = true, inheritByDefault = true, defaultPhase = SITE, aggregator = false, requiresOnline = false)
39  public class SitemapMojo extends AbstractSitemapMojo {
40  
41  	private static final Logger LOG = LoggerFactory.getLogger(SitemapMojo.class);
42  	static final String NAME = "sitemap";
43  	private static final String CATEGORY = '[' + NAME + ']';
44  
45  
46  	@Override
47  	public void execute() throws MojoExecutionException, MojoFailureException
48  	{
49  		if(skip) {
50  			LOG.debug("{} skip == true, skipping execution", CATEGORY);
51  			return;
52  		}
53  
54  		LOG.debug("{} start", CATEGORY);
55  
56  		Path file = Exceptional.apply(Sitemaps::create, parameters());
57  
58  		Exceptional.apply(Files::lines, file)
59  				.forEach(f -> LOG.debug("{} Created {}", CATEGORY, f));
60  
61  		LOG.debug("{} end", CATEGORY);
62  	}
63  }