diff --git a/tools/checkstyle/checkstyle.py b/tools/checkstyle/checkstyle.py index 2f4270cd3..00cd2d661 100755 --- a/tools/checkstyle/checkstyle.py +++ b/tools/checkstyle/checkstyle.py @@ -28,6 +28,30 @@ import tempfile import xml.dom.minidom import gitlint.git as git +def _FindFoldersContaining(root, wanted): + """Searches recursively from root to find directories that has a file with + the given name. + + Args: + root: Root folder to start the search from. + wanted: The filename that we are looking for. + + Returns: + List of folders that has a file with the given name + """ + + if os.path.islink(root): + return [] + result = [] + for fileName in os.listdir(root): + filePath = os.path.join(root, fileName) + if os.path.isdir(filePath): + subResult = _FindFoldersContaining(filePath, wanted) + result.extend(subResult) + else: + if fileName == wanted: + result.append(root) + return result MAIN_DIRECTORY = os.path.normpath(os.path.dirname(__file__)) CHECKSTYLE_JAR = os.path.join(MAIN_DIRECTORY, 'checkstyle.jar') @@ -37,7 +61,8 @@ FORCED_RULES = ['com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck SKIPPED_RULES_FOR_TEST_FILES = ['com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck', 'com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck'] SUBPATH_FOR_TEST_FILES = ['/tests/', '/test/'] -SUBPATH_FOR_TEST_DATA_FILES = ['src/tests/test-data/'] +SUBPATH_FOR_TEST_DATA_FILES = _FindFoldersContaining(os.path.dirname(os.getcwd()), + "IGNORE_CHECKSTYLE") ERROR_UNCOMMITTED = 'You need to commit all modified files before running Checkstyle\n' ERROR_UNTRACKED = 'You have untracked java files that are not being checked:\n'