Changeset 17349 for other-projects


Ignore:
Timestamp:
2008-09-19T13:50:50+12:00 (16 years ago)
Author:
oranfry
Message:

fixed winpath option to rsr and made the test framwork better, plus merged test.xml and build.xml

Location:
other-projects/trunk/anttasks
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • other-projects/trunk/anttasks

    • Property svn:ignore
      •  

        old new  
        11classes
        22lib
         3test
        34
  • other-projects/trunk/anttasks/build.xml

    r17295 r17349  
    3333    </target>
    3434
     35    <target name="test-setup">
     36        <path id="test.classpath">
     37            <pathelement path="lib/anttasks.jar"/>
     38            <pathelement path="${crypt.jar}"/>
     39        </path>
     40        <typedef name="dcff" classname="org.greenstone.anttasks.DeleteChunkFromFile" classpathref="test.classpath"/>
     41        <typedef name="rsr" classname="org.greenstone.anttasks.RegexSearchReplace" classpathref="test.classpath"/>
     42        <mkdir dir="test"/>
     43    </target>
     44
     45    <target name="test" depends="test-setup">
     46        <antcall target="test-rsr"/>
     47    </target>
     48
     49    <target name="test-rsr" depends="test-setup">
     50
     51        <echo file="test/rsr1.txt">This is a test of the rsr task
     52To see if it can replace things with other things
     53Or if those things
     54Stay the same things
     55
     56Or not
     57
     58Replace with a path
     59@path@
     60
     61Replace with a path, with winPath on
     62@path-with-winpath@
     63
     64
     65</echo>
     66        <copy file="test/rsr1.txt" tofile="test/rsr2.txt"/>
     67        <copy file="test/rsr1.txt" tofile="test/rsr3.txt"/>
     68        <copy file="test/rsr1.txt" tofile="test/rsr4.txt"/>
     69
     70        <rsr file="test/rsr1.txt" pattern="things" replacement="strings"/>
     71
     72        <rsr file="test/rsr2.txt">
     73            <job pattern="things" replacement="objects"/>
     74            <job pattern="Or" replacement="And"/>
     75        </rsr>
     76
     77        <rsr file="test/rsr3.txt" pattern="@path@" replacement="C:\Program Files\Greenstone 2.80"/>
     78        <rsr file="test/rsr3.txt" pattern="@path-with-winpath@" replacement="C:\Program Files\Greenstone 2.80" winPath="true"/>
     79
     80        <rsr file="test/rsr4.txt">
     81            <job pattern="@path@" replacement="C:\Program Files\Greenstone 2.80"/>
     82            <job pattern="@path-with-winpath@" replacement="C:\Program Files\Greenstone 2.80" winPath="true"/>
     83        </rsr>
     84
     85    </target>
     86
     87    <target name="test-clean">
     88        <delete dir="test"/>
     89    </target>
     90
     91
     92
     93
    3594
    3695
  • other-projects/trunk/anttasks/src/org/greenstone/anttasks/RegexSearchReplace.java

    r17303 r17349  
    130130                String oldLine = line;
    131131                if ( pattern != null ) {
    132                     line = line.replaceAll((String)pattern, (String)replacement);
     132                    String rp = replacement;
     133                    if ( winPath ) {
     134                        rp = rp.replaceAll("\\\\","\\\\\\\\");
     135                    }
     136                    line = line.replaceAll((String)pattern, (String)rp);
    133137                } else {
    134138                    for ( int i=0; i<jobs.size(); i++ ) {
    135139                        String rp = ((RegexSearchReplaceJob)(jobs.get(i))).getReplacement();
    136                         if ( winPath ) {
     140                        if ( ((RegexSearchReplaceJob)(jobs.get(i))).getWinPath() ) {
    137141                            rp = rp.replaceAll("\\\\","\\\\\\\\");
    138142                        }
     
    211215    public void setReplacement(String replacement) {
    212216        replacement = replacement.replaceAll( "\\\\", "\\\\\\\\" );
    213         if ( winPath ) {
    214             replacement = replacement.replaceAll("\\\\","\\\\\\\\");
    215         }
    216217        this.replacement = replacement;
    217218    }
  • other-projects/trunk/anttasks/src/org/greenstone/anttasks/RegexSearchReplaceJob.java

    r17295 r17349  
    22public class RegexSearchReplaceJob extends org.apache.tools.ant.types.DataType {
    33
    4     public String pattern = null;
    5     public String replacement = null;
     4    String pattern = null;
     5    String replacement = null;
     6    boolean winPath = false;
    67
    78    public void setPattern(String pattern) {
     
    1415    }
    1516
     17    public void setWinPath( boolean winPath ) {
     18        this.winPath = winPath;
     19    }
     20
    1621    public String getPattern() {
    1722        return pattern;
     
    2025        return replacement;
    2126    }
     27    public boolean getWinPath() {
     28        return winPath;
     29    }
    2230
    2331}
Note: See TracChangeset for help on using the changeset viewer.