Search code examples
javaeclipseanttodo

How to mark some code that must be removed before production?


Sometimes for testing/developing purposes we make some changes in the code that must be removed in a production build. I wonder if there is an easy way of marking such blocks so that production build would fail as long as they are present or at least it will warn you during the build somehow.

Simple "//TODO:" doesn't really work because it is ofter forgotten and mixed with tons of other todos. Is there anything stronger?

Or maybe even if I can create some external txt file and put there instructions on what to do before production, and that ant would check if that file is present then cancel build.

We are using Eclipse/Ant (and java + Spring).

Update: I don't mean that there are big chunks of code that are different in local and production. In fact all code is the same and should be the same. Just lets say I comment out some line of code to save lot of time during development and forget to uncomment it or something along those lines. I just want to be able to flag the project somehow that something needs an attention and that production build would fail or show a warning.


Solution

  • You could also just define stronger task comment markers: FIXME (high priority) and XXX (normal priority) are standard in Eclipse, and you could define more task tags (Eclipse Properties -> Java -> Compiler -> Task Tags)

    If you want to fail your build, you could use the Ant (1.7) contains file selector to look for files containing specified text:

    <target name="fixmeCheck">
      <fail message="Fixmes found">
        <condition>
          <not>
            <resourcecount count="0">
              <fileset dir="${pom.build.sourceDirectory}"
                       includes="**/*.java">
                 <contains text="FIXME" casesensitive="yes"/>
              </fileset>
            </resourcecount>
          </not>
        </condition>
      </fail>
    </target>
    
    <target name="compile" depends="fixmeCheck">
    

    Obviously, change ${pom.build.sourceDirectory} to your source directory, and FIXME to the comment that you want to search for.

    Does anyone know a nice way to print out the files found in this fileset in the build file (other than just looking in Eclipse again)?