Perform the check @throws BuildException if an error occurs during execution of this task.
()
| 88 | * @throws BuildException if an error occurs during execution of this task. |
| 89 | */ |
| 90 | @Override |
| 91 | public void execute() throws BuildException { |
| 92 | |
| 93 | Mode mode = getMode(); |
| 94 | if (mode == null) { |
| 95 | log("Line ends check skipped, because OS line ends setting is neither LF nor CRLF.", Project.MSG_VERBOSE); |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | int count = 0; |
| 100 | |
| 101 | List<CheckFailure> errors = new ArrayList<>(); |
| 102 | |
| 103 | // Step through each file and check. |
| 104 | for (FileSet fs : filesets) { |
| 105 | DirectoryScanner ds = fs.getDirectoryScanner(getProject()); |
| 106 | File basedir = ds.getBasedir(); |
| 107 | String[] files = ds.getIncludedFiles(); |
| 108 | if (files.length > 0) { |
| 109 | log("Checking line ends in " + files.length + " file(s)"); |
| 110 | for (String filename : files) { |
| 111 | File file = new File(basedir, filename); |
| 112 | log("Checking file '" + file + "' for correct line ends", Project.MSG_DEBUG); |
| 113 | try { |
| 114 | check(file, errors, mode); |
| 115 | } catch (IOException ioe) { |
| 116 | throw new BuildException("Could not check file '" + file.getAbsolutePath() + "'", ioe); |
| 117 | } |
| 118 | count++; |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | if (count > 0) { |
| 123 | log("Done line ends check in " + count + " file(s), " + errors.size() + " error(s) found."); |
| 124 | } |
| 125 | if (!errors.isEmpty()) { |
| 126 | String message = "The following files have wrong line ends: " + errors; |
| 127 | // We need to explicitly write the message to the log, because |
| 128 | // long BuildException messages may be trimmed. E.g. I observed |
| 129 | // this problem with Eclipse IDE 3.7. |
| 130 | log(message, Project.MSG_ERR); |
| 131 | throw new BuildException(message); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | private enum Mode { |
| 136 | LF, |
nothing calls this directly
no test coverage detected