001    package org.shiftone.jrat.inject.ant;
002    
003    
004    import org.apache.tools.ant.BuildException;
005    import org.apache.tools.ant.Project;
006    import org.shiftone.jrat.core.criteria.IncludeExcludeMethodCriteria;
007    import org.shiftone.jrat.core.criteria.MatcherMethodCriteria;
008    import org.shiftone.jrat.inject.Injector;
009    
010    import java.io.File;
011    
012    
013    /**
014     * @author jeff@shiftone.org (Jeff Drost)
015     */
016    public class InjectTask extends AbstractFileTask {
017    
018        private Injector injector;
019        private IncludeExcludeMethodCriteria methodCriteria;
020    
021        public InjectTask() {
022    
023            injector = new Injector();
024            methodCriteria = new IncludeExcludeMethodCriteria();
025    
026            injector.setMethodCriteria(methodCriteria);
027        }
028    
029    
030        public MatcherMethodCriteria createInclude() {
031    
032            MatcherMethodCriteria newCriteria = new MatcherMethodCriteria();
033    
034            methodCriteria.addPositive(newCriteria);
035    
036            return newCriteria;
037        }
038    
039    
040        public MatcherMethodCriteria createExclude() {
041    
042            MatcherMethodCriteria newCriteria = new MatcherMethodCriteria();
043    
044            methodCriteria.addNegative(newCriteria);
045    
046            return newCriteria;
047        }
048    
049    
050        protected void processFile(File file) throws BuildException {
051    
052            log("processFile(" + file.getAbsolutePath() + ")", Project.MSG_VERBOSE);
053    
054            try {
055                injector.inject(file);
056            }
057            catch (Exception e) {
058                throw new BuildException(e);
059            }
060        }
061    
062    
063        protected void validateFile(File file) throws BuildException {
064    
065            if (file.exists() == false) {
066                throw new BuildException("File does not exist : " + file.getAbsolutePath());
067            }
068        }
069    }