org.apache.camel.maven.packaging.XRefCheckMojo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of camel-package-maven-plugin Show documentation
Show all versions of camel-package-maven-plugin Show documentation
Maven plugin to help package Camel components and plugins
The newest version!
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.maven.packaging;
import java.io.IOError;
import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.camel.tooling.util.PackageHelper;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.snakeyaml.engine.v2.api.Load;
import org.snakeyaml.engine.v2.api.LoadSettings;
@Mojo(name = "xref-check", threadSafe = true)
public class XRefCheckMojo extends AbstractMojo {
public static final java.lang.String PLAYBOOK = "antora-playbook-local-xref-check.yml";
/**
* The maven project.
*/
@Parameter(property = "project", required = true, readonly = true)
protected MavenProject project;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
try {
List unresolved = checkXRef(project.getBasedir().toPath());
if (!unresolved.isEmpty()) {
getLog().error("Unresolved xrefs:");
for (String ref : unresolved) {
getLog().error(" " + ref);
}
throw new MojoFailureException("Unresolved xrefs");
}
} catch (IOException e) {
throw new MojoFailureException("Error checking xref", e);
}
}
public List checkXRef(Path path) throws IOException {
List unresolved = new ArrayList<>();
Load yaml = new Load(LoadSettings.builder().build());
Map site;
try (Reader r = Files.newBufferedReader(path.resolve(PLAYBOOK))) {
site = (Map) yaml.loadFromReader(r);
}
Map attributes = (Map) ((Map) site.get("asciidoc")).get("attributes");
if (attributes != null) {
attributes = attributes.entrySet().stream()
.collect(Collectors.toMap(e -> "{" + e.getKey() + "}", Map.Entry::getValue));
}
Map> componentPaths = new HashMap<>();
Map> componentNavs = new HashMap<>();
Map pages = new TreeMap<>();
for (Map source : (List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy