/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2008 Sun Microsystems, Inc.
* Portions copyright 2012 ForgeRock AS.
*/
/**
* This class provides an implementation of an Ant task that may be used to
* perform various checks to deteermine whether a file is suitable to be
* committed. This includes:
* <UL>
* <LI>Make sure that the file has the correct "svn:eol-style" property
* value.</LI>
* <LI>If a file contains a line that appears to be a comment and includes the
* word "copyright", then it should contain the current year.</LI>
* </UL>
*/
public class CheckPrecommit
extends Task
implements ISVNStatusHandler
{
/**
* The name of the system property that may be used to prevent copyright date
* problems from failing the build.
*/
"org.opends.server.IgnoreCopyrightDateErrors";
/**
* The name of the system property that may be used to prevent svn eol-style
* problems from failing the build.
*/
"org.opends.server.IgnoreEOLStyleErrors";
/**
*
*/
static
{
}
// The path to the directory that is the base of the workspace.
// The set of files that appear to have problems with the EOL style.
// The set of files that appear to have problems with the copyright date.
// The path to the root of the Subversion workspace to check.
// The string representation of the current year.
// The overall SVN Client Manager. required with svnkit 1.2.x
// The property client used to look at file properties.
/**
* Specifies the path to the root of the Subversion workspace for which to
* retrieve the revision number.
*
* @param workspace The path to the root of the Subversion workspace for
* which to retrieve the revision number.
*/
{
}
/**
* Performs the appropriate processing needed for this task. In this case,
* it uses SVNKit to identify all modified files in the current workspace.
* For all source files, look for comment lines containing the word
* "copyright" and make sure at least one of them contains the current year.
*/
@Override()
public void execute()
{
{
}
else
{
}
// Get the year to use in the determination.
// Process the base directory and all of its subdirectories.
try
{
}
catch (Exception e)
{
e.printStackTrace();
"Subversion status: " + e);
return;
}
boolean fail = false;
if (! eolStyleProblemFiles.isEmpty())
{
"for the following files:");
{
}
{
fail = true;
"use '-D" + IGNORE_EOLSTYLE_ERRORS_PROPERTY +
"=true' to ignore svn eol-style warnings.");
}
}
if (! copyrightProblemFiles.isEmpty())
{
"for the following files:");
{
}
{
fail = true;
"or use '-D" + IGNORE_COPYRIGHT_ERRORS_PROPERTY +
"=true' to ignore copyright warnings.");
}
}
if (fail)
{
throw new BuildException();
}
}
/**
* Examines the provided status item to determine whether the associated file
* is acceptable.
*
* @param status The SVN status information for the file of interest.
*/
{
{
// The file doesn't exist (which probably means it's been deleted) or
// isn't a regular file, so we'll ignore it.
return;
}
if (lastPeriodPos > 0)
{
{
// The file doesn't have an extension that we care about, so skip it.
return;
}
}
else
{
// The file doesn't have an extension. We'll still want to check it if
if ((parentDirectory == null) ||
{
return;
}
if ((parentDirectory == null) ||
{
return;
}
}
{
}
// Check to make sure that the file has the correct EOL style.
try
{
if ((propertyData == null) ||
{
}
}
catch (SVNException se)
{
// This could happen if the file isn't under version control. If so, then
// we can't check the eol-style but we should at least be able to check
// the copyright dates, so keep going.
}
// Check to see whether the file has a comment line containing a copyright
// without the current year.
try
{
boolean copyrightFound = false;
boolean correctYearFound = false;
{
if (isCommentLine(lowerLine))
{
if (copyrightPos > 0)
{
copyrightFound = true;
{
correctYearFound = true;
break;
}
}
}
}
if (copyrightFound && (! correctYearFound))
{
}
}
catch (IOException ioe)
{
" to check copyright date.");
"performed.");
throw new RuntimeException();
}
finally
{
try
{
{
}
} catch (Exception e) {}
}
}
/**
* Indicates whether the provided line appears to be a comment line. It will
* check for a number of common comment indicators in Java source files,
* shell scripts, XML files, and LDIF files.
*
* @param lowerLine The line to be checked. It should have been coverted to
* all lowercase characters and any leading spaces
* removed.
*
* @return {@code true} if it appears that the line is a comment line, or
* {@code false} if not.
*/
{
{
return true;
}
else
{
return false;
}
}
}