/* * The contents of this file are subject to the terms of the Common Development and * Distribution License (the License). You may not use this file except in compliance with the * License. * * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the * specific language governing permission and limitations under the License. * * When distributing Covered Software, include this CDDL Header Notice in each file and include * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL * Header, with the fields enclosed by brackets [] replaced by your own identifying * information: "Portions Copyright [year] [name of copyright owner]". * * Copyright 2015-2016 ForgeRock AS. */ package org.forgerock.maven; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.LinkedList; import java.util.List; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.apache.maven.scm.ScmException; import org.apache.maven.scm.ScmFile; import org.apache.maven.scm.ScmFileSet; import org.apache.maven.scm.ScmFileStatus; import org.apache.maven.scm.ScmResult; import org.apache.maven.scm.ScmVersion; import org.apache.maven.scm.command.diff.DiffScmResult; import org.apache.maven.scm.command.status.StatusScmResult; import org.apache.maven.scm.log.ScmLogDispatcher; import org.apache.maven.scm.log.ScmLogger; import org.apache.maven.scm.manager.BasicScmManager; import org.apache.maven.scm.manager.NoSuchScmProviderException; import org.apache.maven.scm.manager.ScmManager; import org.apache.maven.scm.provider.ScmProviderRepository; import org.apache.maven.scm.provider.git.command.GitCommand; import org.apache.maven.scm.provider.git.command.diff.GitDiffConsumer; import org.apache.maven.scm.provider.git.gitexe.GitExeScmProvider; import org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils; import org.apache.maven.scm.provider.git.gitexe.command.diff.GitDiffCommand; import org.apache.maven.scm.repository.ScmRepository; import org.apache.maven.scm.repository.ScmRepositoryException; import org.codehaus.plexus.util.cli.CommandLineUtils; import org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer; import org.codehaus.plexus.util.cli.Commandline; /** * Abstract class which is used for both copyright checks and updates. */ public abstract class CopyrightAbstractMojo extends AbstractMojo { static final String DIFF_REFERENCE_BRANCH_NAME_PROPERTY = "checkCopyrightDiffReferenceBranchName"; /** The Maven Project. */ @Parameter(required = true, property = "project", readonly = true) private MavenProject project; /** * Copyright owner. * This string token must be present on the same line with 'copyright' keyword and the current year. */ @Parameter(required = true, defaultValue = "ForgeRock AS") private String copyrightOwnerToken; /** The path to the root of the scm local workspace to check. */ @Parameter(required = true, defaultValue = "${basedir}") private String baseDir; @Parameter(required = true, defaultValue = "${project.scm.connection}") private String scmRepositoryUrl; /** The Git master branch name of the repository. **/ @Parameter(required = true, property = DIFF_REFERENCE_BRANCH_NAME_PROPERTY, defaultValue = "origin/master") private String gitMasterBranchName; /** * List of file patterns for which copyright check and/or update will be skipped. * Pattern can contain the following wildcards (*, ?, **{@literal /}). */ @Parameter(required = false) private List disabledFiles; /** The file extensions to test. */ public static final List CHECKED_EXTENSIONS = Arrays.asList( "bat", "c", "h", "html", "java", "ldif", "Makefile", "mc", "properties", "sh", "txt", "xml", "xsd", "xsl"); private static final List EXCLUDED_END_COMMENT_BLOCK_TOKEN = Arrays.asList("*/", "-->"); private static final List SUPPORTED_COMMENT_MIDDLE_BLOCK_TOKEN = Arrays.asList("*", "#", "rem", "!"); private static final List SUPPORTED_START_BLOCK_COMMENT_TOKEN = Arrays.asList("/*", "