1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package io.earcam.maven.plugin.sitemap;
20
21 import java.io.File;
22 import java.net.URI;
23 import java.util.List;
24
25 import org.apache.maven.AbstractMavenLifecycleParticipant;
26 import org.apache.maven.MavenExecutionException;
27 import org.apache.maven.execution.MavenSession;
28 import org.codehaus.plexus.component.annotations.Component;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 import io.earcam.utilitarian.site.sitemap.Sitemaps;
33
34 @Component(role = AbstractMavenLifecycleParticipant.class, hint = SitemapSubmissionMavenLifecycleParticipant.NAME, instantiationStrategy = "singleton")
35 public class SitemapSubmissionMavenLifecycleParticipant extends AbstractMavenLifecycleParticipant {
36
37 private static final Logger LOG = LoggerFactory.getLogger(SitemapIndexMavenLifecycleParticipant.class);
38 static final String NAME = "sitemapsubmission";
39 private static final String CATEGORY = '[' + NAME + ']';
40
41 static volatile boolean run = false;
42 static URI baseUrl;
43 static File targetDir;
44 static List<String> hosts;
45
46
47 @Override
48 public void afterSessionEnd(MavenSession session) throws MavenExecutionException
49 {
50 if(session.getResult().hasExceptions()) {
51 LOG.warn("{} extension: not running due to previous build errors", CATEGORY);
52 return;
53 }
54 LOG.debug("{} extension: configured to run: {}", CATEGORY, run);
55 if(run) {
56 String responses = Sitemaps.submit(targetDir.toPath(), baseUrl, hosts);
57 LOG.info("{} extension ran, responses: {}", CATEGORY, responses);
58 }
59 }
60
61
62 static void shouldRun(URI baseUrl, File targetDir, List<String> hosts)
63 {
64 run = true;
65 SitemapSubmissionMavenLifecycleParticipant.baseUrl = baseUrl;
66 SitemapSubmissionMavenLifecycleParticipant.targetDir = targetDir;
67 SitemapSubmissionMavenLifecycleParticipant.hosts = hosts;
68 }
69 }