This is an automated email from the ASF dual-hosted git repository. ebourg pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push: new 1fb000c Changed 'ant validate-eoln' to always check LF line endings regardless of the OS (by default Git checks out the files with LF EOL even on Windows) 1fb000c is described below commit 1fb000c3df34a0621f75050bbcb488d94d6124de Author: Emmanuel Bourg <ebo...@apache.org> AuthorDate: Wed May 8 23:25:47 2019 +0200 Changed 'ant validate-eoln' to always check LF line endings regardless of the OS (by default Git checks out the files with LF EOL even on Windows) --- BUILDING.txt | 9 ++--- build.xml | 3 +- java/org/apache/tomcat/buildutil/CheckEol.java | 48 +++++++++++++++++++------- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/BUILDING.txt b/BUILDING.txt index 1f618fb..f8695fb 100644 --- a/BUILDING.txt +++ b/BUILDING.txt @@ -545,15 +545,12 @@ The report file by default is written to You usually would not need to run this check. You can skip this section. Apache Tomcat project has convention that all of its textual source files, -stored in Subversion repository, are marked with Subversion property -"svn:eol-style" with value of "native". This convention makes the editing -of source code on different platforms easier. +stored in the Git repository, use Unix style LF line endings. This test is used by developers to check that the source code adheres to this convention. It verifies that the ends of lines in textual files are -appropriate for the operating system where it is run. The idea is to run -this check regularly on two different platforms and notify developers when -an inconsistency is detected. +appropriate. The idea is to run this check regularly and notify developers +when an inconsistency is detected. The command to run this test is: diff --git a/build.xml b/build.xml index f62cb76..ea87611 100644 --- a/build.xml +++ b/build.xml @@ -625,7 +625,6 @@ source="${compile.source}" target="${compile.target}" release="${compile.release}" - excludes="**/.svn/**" encoding="ISO-8859-1" includeAntRuntime="true" > <!-- Uncomment this to show unchecked warnings: @@ -638,7 +637,7 @@ classname="org.apache.tomcat.buildutil.CheckEol" classpath="${tomcat.classes}" /> - <checkeol> + <checkeol mode="LF"> <fileset dir="." > <patternset refid="text.files" /> <include name="**/*.bat"/> diff --git a/java/org/apache/tomcat/buildutil/CheckEol.java b/java/org/apache/tomcat/buildutil/CheckEol.java index 00633c7..2f32554 100644 --- a/java/org/apache/tomcat/buildutil/CheckEol.java +++ b/java/org/apache/tomcat/buildutil/CheckEol.java @@ -33,17 +33,21 @@ import org.apache.tools.ant.types.FileSet; /** * Ant task that checks that all the files in the given fileset have end-of-line - * delimiters that are appropriate for the current OS. + * delimiters that are appropriate. * * <p> - * 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. + * The goal is to check whether we have problems with Subversion's svn:eol-style + * property or Git's autocrlf setting when files are committed on one OS and then + * checked on another one. */ public class CheckEol extends Task { /** The files to be checked */ private final List<FileSet> filesets = new LinkedList<>(); + /** The line ending mode (either LF, CRLF, or null for OS specific) */ + private Mode mode; + /** * Sets the files to be checked * @@ -54,6 +58,29 @@ public class CheckEol extends Task { } /** + * Sets the line ending mode. + * + * @param mode + */ + public void setMode( String mode ) { + this.mode = Mode.valueOf( mode.toUpperCase() ); + } + + private Mode getMode() { + if ( mode != null ) { + return mode; + } else { + if ("\n".equals(System.lineSeparator())) { + return Mode.LF; + } else if ("\r\n".equals(System.lineSeparator())) { + return Mode.CRLF; + } + } + + return null; + } + + /** * Perform the check * * @throws BuildException if an error occurs during execution of @@ -62,14 +89,9 @@ public class CheckEol extends Task { @Override public void execute() throws BuildException { - Mode mode = null; - if ("\n".equals(System.lineSeparator())) { - mode = Mode.LF; - } else if ("\r\n".equals(System.lineSeparator())) { - mode = Mode.CRLF; - } else { - log("Line ends check skipped, because OS line ends setting is neither LF nor CRLF.", - Project.MSG_VERBOSE); + Mode mode = getMode(); + if ( mode == null ) { + log("Line ends check skipped, because OS line ends setting is neither LF nor CRLF.", Project.MSG_VERBOSE); return; } @@ -84,8 +106,8 @@ public class CheckEol extends Task { 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]); + for (String filename : files) { + File file = new File(basedir, filename); log("Checking file '" + file + "' for correct line ends", Project.MSG_DEBUG); try { --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org