001/* 002 * SPDX-License-Identifier: Apache-2.0 003 * 004 * Copyright 2020-2024 Andres Almiray. 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * https://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.kordamp.maven.plugin.checker.mojos; 019 020import org.apache.maven.plugin.AbstractMojo; 021import org.apache.maven.plugin.MojoExecutionException; 022import org.apache.maven.plugin.MojoFailureException; 023import org.apache.maven.plugins.annotations.Mojo; 024import org.apache.maven.plugins.annotations.Parameter; 025import org.apache.maven.project.MavenProject; 026import org.kordamp.maven.checker.BomChecker; 027import org.kordamp.maven.checker.MavenLoggerAdapter; 028import org.kordamp.maven.checker.PomCheckException; 029 030/** 031 * Checks if a POM file is a minimal BOM file. 032 * Minimal BOM files contain the following elements: 033 * <ul> 034 * <li><groupId></li> 035 * <li><artifactId></li> 036 * <li><version></li> 037 * <li><dependencyManagement></li> 038 * </ul> 039 * 040 * @author Andres Almiray 041 * @since 1.0.0 042 */ 043@Mojo(name = "check-bom") 044public class CheckBomMojo extends AbstractMojo { 045 /** 046 * Fail the build on error. 047 */ 048 @Parameter(property = "checker.fail.on.error", defaultValue = "true") 049 private boolean failOnError; 050 051 /** 052 * The project whose model will be checked. 053 */ 054 @Parameter(defaultValue = "${project}", readonly = true, required = true) 055 private MavenProject project; 056 057 @Override 058 public void execute() throws MojoExecutionException, MojoFailureException { 059 try { 060 BomChecker.check(new MavenLoggerAdapter(getLog()), project, new BomChecker.Configuration() 061 .withFailOnError(failOnError)); 062 } catch (PomCheckException e) { 063 throw new MojoExecutionException("Bom check failed", e); 064 } 065 } 066}