001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2015 ForgeRock AS. 025 */ 026package org.forgerock.maven; 027 028import org.apache.maven.plugin.MojoExecutionException; 029import org.apache.maven.plugin.MojoFailureException; 030import org.apache.maven.plugins.annotations.LifecyclePhase; 031import org.apache.maven.plugins.annotations.Mojo; 032import org.apache.maven.plugins.annotations.Parameter; 033 034/** 035 * This be used to check that if a modified file contains a line that appears to 036 * be a comment and includes the word "copyright", then it should contain the 037 * current year. 038 */ 039@Mojo(name = "check-copyright", defaultPhase = LifecyclePhase.VALIDATE) 040public class CheckCopyrightMojo extends CopyrightAbstractMojo { 041 042 /** 043 * The property that may be used to prevent copyright date problems from 044 * failing the build. 045 */ 046 @Parameter(required = true, property = "ignoreCopyrightErrors", defaultValue = "false") 047 private boolean ignoreCopyrightErrors; 048 049 @Parameter(required = true, property = "skipCopyrightCheck", defaultValue = "false") 050 private boolean checkDisabled; 051 052 /** 053 * Uses maven-scm API to identify all modified files in the current 054 * workspace. For all source files, check if the copyright is up to date. 055 * 056 * @throws MojoFailureException 057 * if any 058 * @throws MojoExecutionException 059 * if any 060 */ 061 public void execute() throws MojoFailureException, MojoExecutionException { 062 if (checkDisabled) { 063 getLog().info("Copyright check is disabled"); 064 return; 065 } 066 067 checkCopyrights(); 068 if (!getIncorrectCopyrightFilePaths().isEmpty()) { 069 getLog().warn("Potential copyright year updates needed for the following files:"); 070 for (String filename : getIncorrectCopyrightFilePaths()) { 071 getLog().warn(" " + filename); 072 } 073 074 if (!ignoreCopyrightErrors) { 075 getLog().warn("Fix copyright date problems before proceeding, " 076 + "or use '-DignoreCopyrightErrors=true' to ignore copyright errors."); 077 getLog().warn("You can use update-copyrights maven profile " 078 + "(mvn validate -Pupdate-copyrights) to automatically update copyrights."); 079 throw new MojoExecutionException("Found files with potential copyright year updates needed"); 080 } 081 } else { 082 getLog().info("Copyrights are up to date"); 083 } 084 } 085}