Ignore:
Timestamp:
2013-08-26T17:25:29+12:00 (11 years ago)
Author:
davidb
Message:

Introduction of 'verbosity' attribute to control the level of output generated by running this task

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/ant-tasks/src/org/greenstone/anttasks/RegexSearchReplace.java

    r21843 r28134  
    3737    private String pattern = null;
    3838    private String replacement = null;
     39    private int verbosity = 1;
    3940    private int fromLine = -1;
    4041    private int toLine = -1;
     
    107108
    108109        //output greeting
    109         System.out.println( "--------------------" );
    110         System.out.println( " RegexSearchReplace " );
    111         System.out.println( "--------------------" );
    112 
    113         //output replacement(s)
    114         System.out.println( "Replacements:" );
    115         if ( pattern != null ) {
     110        if (verbosity >= 3) {
     111            System.out.println( "--------------------" );
     112            System.out.println( " RegexSearchReplace " );
     113            System.out.println( "--------------------" );
     114
     115
     116            //output replacement(s)
     117            System.out.println( "Replacements:" );
     118
     119            if ( pattern != null ) {
    116120            System.out.println( " " + pattern + " -> " + replacement );
    117         } else {
     121            } else {
    118122            for ( int i=0; i<jobs.size(); i++ ) {
    119123                System.out.println( " " + ((RegexSearchReplaceJob)(jobs.get(i))).getPattern() + " -> " + ((RegexSearchReplaceJob)(jobs.get(i))).getReplacement() );
    120124            }
    121         }
    122         System.out.println();
    123 
    124         //output lines if necessary
    125         if ( this.fromLine != -1 || this.toLine != -1 ) {
     125            }
     126            System.out.println();
     127
     128
     129            //output lines if necessary
     130            if ( this.fromLine != -1 || this.toLine != -1 ) {
    126131            System.out.println( "Lines: " + (this.fromLine==-1?"Start":Integer.toString(this.fromLine)) + " ~ " + (this.toLine==-1?"End":Integer.toString(this.toLine)) );
    127132            System.out.println();
    128         }
    129 
    130         System.out.println( "Files: " );
     133            }
     134        }
     135
     136        if (verbosity == 1) {
     137            System.out.println( "Regex Search and Replace on File(s): " );
     138        }
     139        else if (verbosity > 1) {
     140            System.out.println( "File(s): " );
     141        }
     142
    131143        for ( int fileIndex=0; fileIndex<files.length; fileIndex++ ) {
    132144
     
    134146
    135147            File inputFile = files[fileIndex];
    136             System.out.println( " " + inputFile );
     148            if (verbosity >= 1) {
     149                System.out.println( " " + inputFile );
     150            }
    137151
    138152            //create the output stream
     
    250264
    251265       
    252             if ( noReplaces == 0 ) {
     266            if (verbosity >= 2) {
     267                if ( noReplaces == 0 ) {
    253268                System.out.println( " No Changes Made" );
    254             } else if ( noReplaces == 1 ) {
     269                } else if ( noReplaces == 1 ) {
    255270                System.out.println( " Successfully changed 1 line" );
    256             } else {
     271                } else {
    257272                System.out.println( " Successfully changed " + noReplaces + " lines" );
    258             }
    259             System.out.println();
     273                }
     274                System.out.println();
     275            }
    260276
    261277        }
     
    297313    }
    298314
     315    public void setVerbosity(String verbosity_str) {
     316
     317        //trim
     318        verbosity_str.replaceAll("\\s","");
     319
     320        if (verbosity_str == "" ) {
     321            throw new BuildException("Error - no value found in 'verbosity' attribute!");
     322        }
     323
     324        try {
     325            this.verbosity = Integer.parseInt(verbosity_str);
     326        } catch( NumberFormatException nfe ) {
     327            throw new BuildException("Error - invalid line numbers given in 'verbosity' attribute! '"
     328                         + verbosity_str + "'" );
     329        }
     330
     331    }
    299332
    300333    public void setPattern(String pattern) {
Note: See TracChangeset for help on using the changeset viewer.