
io.earcam.maven.plugin.sitemap.SitemapIndexMavenLifecycleParticipant Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of io.earcam.maven.plugin.sitemap Show documentation
Show all versions of io.earcam.maven.plugin.sitemap Show documentation
sitemaps.org integration; scalable, specification compliant
The newest version!
/*-
* #%L
* io.earcam.maven.plugin.sitemap
* %%
* Copyright (C) 2017 earcam
* %%
* SPDX-License-Identifier: (BSD-3-Clause OR EPL-1.0 OR Apache-2.0 OR MIT)
*
* You must choose to accept, in full - any individual or combination of
* the following licenses:
*
* - BSD-3-Clause
* - EPL-1.0
* - Apache-2.0
* - MIT
*
* #L%
*/
package io.earcam.maven.plugin.sitemap;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;
import org.apache.maven.AbstractMavenLifecycleParticipant;
import org.apache.maven.MavenExecutionException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Model;
import org.apache.maven.model.Reporting;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.earcam.unexceptional.Exceptional;
import io.earcam.utilitarian.site.sitemap.Sitemaps;
@Component(role = AbstractMavenLifecycleParticipant.class, hint = SitemapIndexMavenLifecycleParticipant.NAME, instantiationStrategy = "singleton")
public class SitemapIndexMavenLifecycleParticipant extends AbstractMavenLifecycleParticipant {
private static final Logger LOG = LoggerFactory.getLogger(SitemapIndexMavenLifecycleParticipant.class);
static final String NAME = "sitemapindex";
private static final String CATEGORY = '[' + NAME + ']';
private static volatile boolean shouldRun = false;
@Override
public void afterSessionEnd(MavenSession session) throws MavenExecutionException
{
if(session.getResult().hasExceptions()) {
LOG.warn("{} extension: not running due to previous build errors", CATEGORY);
return;
}
LOG.debug("{} extension: configured to run: {}", CATEGORY, shouldRun);
if(shouldRun) {
MavenProject project = session.getTopLevelProject();
Stream targetDirs = project.getCollectedProjects().stream()
.map(MavenProject::getModel)
.map(Model::getReporting)
.map(Reporting::getOutputDirectory)
.map(Paths::get);
Path targetDir = Paths.get(project.getModel().getReporting().getOutputDirectory());
Path indexFile = Exceptional.apply(Sitemaps::index, targetDir, targetDirs);
Exceptional.apply(Files::lines, indexFile)
.forEach(f -> LOG.debug("{} Created {}", CATEGORY, f));
}
}
static void shouldRun()
{
shouldRun = true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy