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.MavenCentralChecker; 027import org.kordamp.maven.checker.MavenLoggerAdapter; 028import org.kordamp.maven.checker.PomCheckException; 029 030/** 031 * Checks if a POM complies with the rules for uploading to Maven Central. 032 * 033 * @author Andres Almiray 034 * @since 1.0.0 035 */ 036@Mojo(name = "check-maven-central") 037public class CheckMavenCentralMojo extends AbstractMojo { 038 /** 039 * The project whose model will be checked. 040 */ 041 @Parameter(defaultValue = "${project}", readonly = true, required = true) 042 private MavenProject project; 043 044 /** 045 * Fail the build on error. 046 */ 047 @Parameter(property = "checker.fail.on.error", defaultValue = "true") 048 private boolean failOnError; 049 050 /** 051 * Fail the build on warning. 052 */ 053 @Parameter(property = "checker.fail.on.warning") 054 private boolean failOnWarning; 055 056 /** 057 * Checks if version is -SNAPSHOT. 058 */ 059 @Parameter(property = "checker.release", defaultValue = "true") 060 private boolean release; 061 062 /** 063 * Checks if <repositories> and <pluginRepositories> are present. 064 */ 065 @Parameter(property = "checker.strict", defaultValue = "true") 066 private boolean strict; 067 068 @Override 069 public void execute() throws MojoExecutionException, MojoFailureException { 070 try { 071 MavenCentralChecker.check(new MavenLoggerAdapter(getLog()), project, new MavenCentralChecker.Configuration() 072 .withRelease(release) 073 .withStrict(strict) 074 .withFailOnError(failOnError) 075 .withFailOnWarning(failOnWarning)); 076 } catch (PomCheckException e) { 077 throw new MojoExecutionException("MavenCentral check failed", e); 078 } 079 } 080}