Return-Path: X-Original-To: apmail-tomcat-dev-archive@www.apache.org Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E27E19BC3 for ; Wed, 15 Feb 2012 01:40:20 +0000 (UTC) Received: (qmail 79254 invoked by uid 500); 15 Feb 2012 01:40:20 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 79173 invoked by uid 500); 15 Feb 2012 01:40:20 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 79163 invoked by uid 99); 15 Feb 2012 01:40:20 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Feb 2012 01:40:20 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Feb 2012 01:40:16 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D55E023888D2 for ; Wed, 15 Feb 2012 01:39:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1244302 - in /tomcat/trunk: build.xml java/org/apache/tomcat/buildutil/CheckEol.java Date: Wed, 15 Feb 2012 01:39:55 -0000 To: dev@tomcat.apache.org From: kkolinko@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120215013955.D55E023888D2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kkolinko Date: Wed Feb 15 01:39:55 2012 New Revision: 1244302 URL: http://svn.apache.org/viewvc?rev=1244302&view=rev Log: Implement check for correct end-of-line characters in the source files. I plan to add it as a separate task in Gump. Running it on Windows currently shows 11 problem files. Added: tomcat/trunk/java/org/apache/tomcat/buildutil/CheckEol.java (with props) Modified: tomcat/trunk/build.xml Modified: tomcat/trunk/build.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/build.xml?rev=1244302&r1=1244301&r2=1244302&view=diff ============================================================================== --- tomcat/trunk/build.xml (original) +++ tomcat/trunk/build.xml Wed Feb 15 01:39:55 2012 @@ -482,6 +482,30 @@ + + + + + + + + + + + + + + + + + + + + + + * The goal is to check whether we have problems with svn:eol-style property + * when files are committed on one OS and then checked on another one. + */ +public class CheckEol extends Task { + + private static final String eoln = System.getProperty("line.separator"); + + /** The files to be checked */ + private final List filesets = new LinkedList(); + + /** + * Sets the files to be checked + * + * @param fs The fileset to be checked. + */ + public void addFileset( FileSet fs ) { + filesets.add( fs ); + } + + /** + * Perform the check + * + * @throws BuildException if an error occurs during execution of + * this task. + */ + @Override + public void execute() throws BuildException { + + Mode mode = null; + if ("\n".equals(eoln)) { + mode = Mode.LF; + } else if ("\r\n".equals(eoln)) { + mode = Mode.CRLF; + } else { + log("Line ends check skipped, because OS line ends setting is neither LF nor CRLF.", + Project.MSG_VERBOSE); + return; + } + + int count = 0; + + List errors = new ArrayList(); + + // Step through each file and check. + for (FileSet fs : filesets) { + DirectoryScanner ds = fs.getDirectoryScanner(getProject()); + File basedir = ds.getBasedir(); + String[] files = ds.getIncludedFiles(); + if (files.length > 0) { + log("Checking line ends in " + files.length + " file(s)"); + for (int i = 0; i < files.length; i++) { + File file = new File(basedir, files[i]); + log("Checking file '" + file + "' for correct line ends", + Project.MSG_DEBUG); + try { + check(file, errors, mode); + } catch (IOException e) { + throw new BuildException("Could not check file '" + + file.getAbsolutePath() + "'", e); + } + count++; + } + } + } + if (count > 0) { + log("Done line ends check in " + count + " file(s), " + + errors.size() + " error(s) found."); + } + if (errors.size() > 0) { + String message = "The following files have wrong line ends: " + + errors; + // We need to explicitly write the message to the log, because + // long BuildException messages may be trimmed. E.g. I observed + // this problem with Eclipse IDE 3.7. + log(message, Project.MSG_ERR); + throw new BuildException(message); + } + } + + private static enum Mode { + LF, CRLF + } + + private static class CheckFailure { + private final File file; + private final int line; + private final String value; + + public CheckFailure(File file, int line, String value) { + this.file = file; + this.line = line; + this.value = value; + } + + @Override + public String toString() { + return eoln + file + ": uses " + value + " on line " + line; + } + } + + private void check(File file, List errors, Mode mode) + throws IOException { + BufferedInputStream is = new BufferedInputStream(new FileInputStream( + file)); + try { + int line = 1; + int prev = -1; + int ch; + while ((ch = is.read()) != -1) { + if (ch == '\n') { + if (mode == Mode.LF && prev == '\r') { + errors.add(new CheckFailure(file, line, "CRLF")); + return; + } else if (mode == Mode.CRLF && prev != '\r') { + errors.add(new CheckFailure(file, line, "LF")); + return; + } + line++; + } else if (prev == '\r') { + errors.add(new CheckFailure(file, line, "CR")); + return; + } + prev = ch; + } + } finally { + is.close(); + } + } +} Propchange: tomcat/trunk/java/org/apache/tomcat/buildutil/CheckEol.java ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org