/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
*/ package org.apache.tomcat.buildutil;
/** * Ant task that checks that all the files in the given fileset have end-of-line * delimiters that are appropriate. * * <p> * 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.
*/ publicclass CheckEol extends Task {
/** The files to be checked */ privatefinal List<FileSet> filesets = new ArrayList<>();
/** The line ending mode (either LF, CRLF, or null for OS specific) */ private Mode mode;
/** * Sets the files to be checked * * @param fs The fileset to be checked.
*/ publicvoid addFileset( FileSet fs ) {
filesets.add( fs );
}
/** * Sets the line ending mode. * * @param mode The line ending mode (either LF or CRLF)
*/ publicvoid setMode( String mode ) { this.mode = Mode.valueOf( mode.toUpperCase() );
}
/** * Perform the check * * @throws BuildException if an error occurs during execution of * this task.
*/
@Override publicvoid execute() throws BuildException {
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;
}
int count = 0;
List<CheckFailure> 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 (String filename : files) {
File file = new File(basedir, filename);
log("Checking file '" + file + "' for correct line ends",
Project.MSG_DEBUG); try {
check(file, errors, mode);
} catch (IOException e) { thrownew 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); thrownew BuildException(message);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.