How to use ant to check for tags (TODO: etc) in java source

ぃ、小莉子 提交于 2019-12-05 09:23:35

Maybe you can use Checkstyle. I think there is a check for TODO comments and checkstyle can be run as an Ant task so you might achieve what you want.

You can use ant conditions for these checks:

<condition property="isSourceFileOK">
    <not>
        <isfileselected file="${source}">
            <contains text="TODO" casesensitive="yes"/>
        </isfileselected>
    </not>
</condition>
<fail unless="isSourceFileOK" message="Source contains TODO!" />

As for the Perforce variant, you will likely want to write a trigger for that. See the perforce docu about triggers for more information. In your case, you'd write a 'change-content' trigger in order to see the file-content on the Perforce server before file-commit.

Within the trigger you can use p4 files //depot/...@4711 to get a list of files of the change (in this case 4711, but is handed over on the command line to the trigger. For each of the files you'd use p4 print -q //depot/path/to/file@4711 to get the content of the file and scan this for your keywords (TODO/XXX). You could print a warning on stdout in case of TODO and exit with code 0, so that the commit succeeds and exit with code 1 in the case of XXX so that the commit fails.

joel.neely

First, jassuncao is correct; Checkstyle does what you are asking, according to the docs here. At the risk of incurring "don't reinvent the wheel" wrath, I might also suggest that what you are wanting to accomplish is a nice problem for someone who wants to learn how to write Ant tasks.

You could also use the Ant TODO task.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!