How to search for a string in files with Ant (make sure certain string isn't found in source files)

前端 未结 3 909
轻奢々
轻奢々 2020-12-03 17:55

I\'d like to search for a string within my source files with Ant. (I\'d like my build to fail in case certain string is found within my source files).

So, I should b

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 18:14

    You might consider using fileset selectors to do this. Selectors allow you to choose files based on content, size, editability and so on. You can combine selectors with name-based includes and excludes, or patternsets.

    Below is an example. The second fileset is derived from the first, with a selector that simply matches on file content. For more sophisticated matching there is the containsregexp selector. The result is a fileset containing only files matching the string. A fail task with a resourcecount condition is then used to fail the build, unless that fileset is empty.

    
    
    
    
        
            
        
    
    
    
        
        
    
    
    
        
            
        
    
    

    (Old answer): If adjusting or reusing filesets might be problematic, here's an illustration of a relatively simple alternative.

    The idea is to make a copy of the files, then replace the string you wish to search for with some flag value in the copied files. This will update the last modified time on any matching file. The uptodate task can then be used to look for affected files. Finally, unless no files matched, you can fail the build.

    
    
    
    
    
    
    
        
    
    
        
    
    
        
    
    
        
    
    
        
        
    
    
    

提交回复
热议问题