Browse Source

Made all the mappers consistent

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270704 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 24 years ago
parent
commit
3512883717
12 changed files with 168 additions and 172 deletions
  1. +0
    -1
      proposal/myrmidon/src/main/org/apache/tools/ant/util/FileNameMapper.java
  2. +8
    -10
      proposal/myrmidon/src/main/org/apache/tools/ant/util/FlatFileNameMapper.java
  3. +35
    -31
      proposal/myrmidon/src/main/org/apache/tools/ant/util/GlobPatternMapper.java
  4. +5
    -5
      proposal/myrmidon/src/main/org/apache/tools/ant/util/IdentityMapper.java
  5. +6
    -6
      proposal/myrmidon/src/main/org/apache/tools/ant/util/MergingMapper.java
  6. +30
    -33
      proposal/myrmidon/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java
  7. +0
    -1
      proposal/myrmidon/src/todo/org/apache/tools/ant/util/FileNameMapper.java
  8. +8
    -10
      proposal/myrmidon/src/todo/org/apache/tools/ant/util/FlatFileNameMapper.java
  9. +35
    -31
      proposal/myrmidon/src/todo/org/apache/tools/ant/util/GlobPatternMapper.java
  10. +5
    -5
      proposal/myrmidon/src/todo/org/apache/tools/ant/util/IdentityMapper.java
  11. +6
    -6
      proposal/myrmidon/src/todo/org/apache/tools/ant/util/MergingMapper.java
  12. +30
    -33
      proposal/myrmidon/src/todo/org/apache/tools/ant/util/RegexpPatternMapper.java

+ 0
- 1
proposal/myrmidon/src/main/org/apache/tools/ant/util/FileNameMapper.java View File

@@ -23,7 +23,6 @@ import org.apache.myrmidon.api.TaskException;
*/
public interface FileNameMapper
{

/**
* Sets the from part of the transformation rule.
*


+ 8
- 10
proposal/myrmidon/src/main/org/apache/tools/ant/util/FlatFileNameMapper.java View File

@@ -7,6 +7,8 @@
*/
package org.apache.tools.ant.util;

import java.io.File;

/**
* Implementation of FileNameMapper that always returns the source file name
* without any leading directory information. <p>
@@ -16,24 +18,20 @@ package org.apache.tools.ant.util;
*
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
public class FlatFileNameMapper implements FileNameMapper
public class FlatFileNameMapper
implements FileNameMapper
{

/**
* Ignored.
*
* @param from The new From value
*/
public void setFrom( String from )
public void setFrom( final String from )
{
}

/**
* Ignored.
*
* @param to The new To value
*/
public void setTo( String to )
public void setTo( final String to )
{
}

@@ -44,8 +42,8 @@ public class FlatFileNameMapper implements FileNameMapper
* @param sourceFileName Description of Parameter
* @return Description of the Returned Value
*/
public String[] mapFileName( String sourceFileName )
public String[] mapFileName( final String sourceFileName )
{
return new String[]{new java.io.File( sourceFileName ).getName()};
return new String[]{new File( sourceFileName ).getName()};
}
}

+ 35
- 31
proposal/myrmidon/src/main/org/apache/tools/ant/util/GlobPatternMapper.java View File

@@ -19,58 +19,59 @@ package org.apache.tools.ant.util;
*
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
public class GlobPatternMapper implements FileNameMapper
public class GlobPatternMapper
implements FileNameMapper
{
/**
* Part of &quot;from&quot; pattern before the *.
*/
protected String fromPrefix = null;
private String m_fromPrefix;

/**
* Part of &quot;from&quot; pattern after the *.
*/
protected String fromPostfix = null;
private String m_fromPostfix;

/**
* Part of &quot;to&quot; pattern before the *.
*/
protected String toPrefix = null;
private String m_toPrefix;

/**
* Part of &quot;to&quot; pattern after the *.
*/
protected String toPostfix = null;
private String m_toPostfix;

/**
* Length of the postfix (&quot;from&quot; pattern).
*/
protected int postfixLength;
private int m_postfixLength;

/**
* Length of the prefix (&quot;from&quot; pattern).
*/
protected int prefixLength;
private int m_prefixLength;

/**
* Sets the &quot;from&quot; pattern. Required.
*
* @param from The new From value
*/
public void setFrom( String from )
public void setFrom( final String from )
{
int index = from.lastIndexOf( "*" );
final int index = from.lastIndexOf( "*" );
if( index == -1 )
{
fromPrefix = from;
fromPostfix = "";
m_fromPrefix = from;
m_fromPostfix = "";
}
else
{
fromPrefix = from.substring( 0, index );
fromPostfix = from.substring( index + 1 );
m_fromPrefix = from.substring( 0, index );
m_fromPostfix = from.substring( index + 1 );
}
prefixLength = fromPrefix.length();
postfixLength = fromPostfix.length();
m_prefixLength = m_fromPrefix.length();
m_postfixLength = m_fromPostfix.length();
}

/**
@@ -78,18 +79,18 @@ public class GlobPatternMapper implements FileNameMapper
*
* @param to The new To value
*/
public void setTo( String to )
public void setTo( final String to )
{
int index = to.lastIndexOf( "*" );
final int index = to.lastIndexOf( "*" );
if( index == -1 )
{
toPrefix = to;
toPostfix = "";
m_toPrefix = to;
m_toPostfix = "";
}
else
{
toPrefix = to.substring( 0, index );
toPostfix = to.substring( index + 1 );
m_toPrefix = to.substring( 0, index );
m_toPostfix = to.substring( index + 1 );
}
}

@@ -100,17 +101,20 @@ public class GlobPatternMapper implements FileNameMapper
* @param sourceFileName Description of Parameter
* @return Description of the Returned Value
*/
public String[] mapFileName( String sourceFileName )
public String[] mapFileName( final String sourceFileName )
{
if( fromPrefix == null
|| !sourceFileName.startsWith( fromPrefix )
|| !sourceFileName.endsWith( fromPostfix ) )
if( m_fromPrefix == null ||
!sourceFileName.startsWith( m_fromPrefix ) ||
!sourceFileName.endsWith( m_fromPostfix ) )
{
return null;
}
return new String[]{toPrefix
+ extractVariablePart( sourceFileName )
+ toPostfix};
else
{
final String result = m_toPrefix +
extractVariablePart( sourceFileName ) + m_toPostfix;
return new String[]{result};
}
}

/**
@@ -120,9 +124,9 @@ public class GlobPatternMapper implements FileNameMapper
* @param name Description of Parameter
* @return Description of the Returned Value
*/
protected String extractVariablePart( String name )
protected String extractVariablePart( final String name )
{
return name.substring( prefixLength,
name.length() - postfixLength );
return name.substring( m_prefixLength,
name.length() - m_postfixLength );
}
}

+ 5
- 5
proposal/myrmidon/src/main/org/apache/tools/ant/util/IdentityMapper.java View File

@@ -15,15 +15,15 @@ package org.apache.tools.ant.util;
*
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
public class IdentityMapper implements FileNameMapper
public class IdentityMapper
implements FileNameMapper
{

/**
* Ignored.
*
* @param from The new From value
*/
public void setFrom( String from )
public void setFrom( final String from )
{
}

@@ -32,7 +32,7 @@ public class IdentityMapper implements FileNameMapper
*
* @param to The new To value
*/
public void setTo( String to )
public void setTo( final String to )
{
}

@@ -42,7 +42,7 @@ public class IdentityMapper implements FileNameMapper
* @param sourceFileName Description of Parameter
* @return Description of the Returned Value
*/
public String[] mapFileName( String sourceFileName )
public String[] mapFileName( final String sourceFileName )
{
return new String[]{sourceFileName};
}


+ 6
- 6
proposal/myrmidon/src/main/org/apache/tools/ant/util/MergingMapper.java View File

@@ -15,9 +15,10 @@ package org.apache.tools.ant.util;
*
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
public class MergingMapper implements FileNameMapper
public class MergingMapper
implements FileNameMapper
{
protected String[] mergedFile = null;
private String[] m_mergedFile;

/**
* Ignored.
@@ -35,7 +36,7 @@ public class MergingMapper implements FileNameMapper
*/
public void setTo( String to )
{
mergedFile = new String[]{to};
m_mergedFile = new String[]{to};
}

/**
@@ -44,9 +45,8 @@ public class MergingMapper implements FileNameMapper
* @param sourceFileName Description of Parameter
* @return Description of the Returned Value
*/
public String[] mapFileName( String sourceFileName )
public String[] mapFileName( final String sourceFileName )
{
return mergedFile;
return m_mergedFile;
}

}

+ 30
- 33
proposal/myrmidon/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java View File

@@ -17,37 +17,34 @@ import org.apache.tools.ant.util.regexp.RegexpMatcherFactory;
*
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
public class RegexpPatternMapper implements FileNameMapper
public class RegexpPatternMapper
implements FileNameMapper
{
protected RegexpMatcher reg = null;
protected char[] to = null;
protected StringBuffer result = new StringBuffer();
private RegexpMatcher m_matcher;
private char[] m_to;
private StringBuffer m_result = new StringBuffer();

public RegexpPatternMapper()
throws TaskException
{
reg = ( new RegexpMatcherFactory() ).newRegexpMatcher();
m_matcher = ( new RegexpMatcherFactory() ).newRegexpMatcher();
}

/**
* Sets the &quot;from&quot; pattern. Required.
*
* @param from The new From value
* @exception TaskException Description of Exception
*/
public void setFrom( String from )
public void setFrom( final String from )
throws TaskException
{
try
{
reg.setPattern( from );
m_matcher.setPattern( from );
}
catch( NoClassDefFoundError e )
{
// depending on the implementation the actual RE won't
// get instantiated in the constructor.
throw new TaskException( "Cannot load regular expression matcher",
e );
throw new TaskException( "Cannot load regular expression matcher", e );
}
}

@@ -56,9 +53,9 @@ public class RegexpPatternMapper implements FileNameMapper
*
* @param to The new To value
*/
public void setTo( String to )
public void setTo( final String to )
{
this.to = to.toCharArray();
m_to = to.toCharArray();
}

/**
@@ -68,57 +65,57 @@ public class RegexpPatternMapper implements FileNameMapper
* @param sourceFileName Description of Parameter
* @return Description of the Returned Value
*/
public String[] mapFileName( String sourceFileName )
public String[] mapFileName( final String sourceFileName )
throws TaskException
{
if( reg == null || to == null || !reg.matches( sourceFileName ) )
if( m_matcher == null || m_to == null ||
!m_matcher.matches( sourceFileName ) )
{
return null;
}
return new String[]{replaceReferences( sourceFileName )};
else
{
return new String[]{replaceReferences( sourceFileName )};
}
}

/**
* Replace all backreferences in the to pattern with the matched groups of
* the source.
*
* @param source Description of Parameter
* @return Description of the Returned Value
*/
protected String replaceReferences( String source )
private String replaceReferences( final String source )
throws TaskException
{
ArrayList v = reg.getGroups( source );
final ArrayList groups = m_matcher.getGroups( source );

result.setLength( 0 );
for( int i = 0; i < to.length; i++ )
m_result.setLength( 0 );
for( int i = 0; i < m_to.length; i++ )
{
if( to[ i ] == '\\' )
if( m_to[ i ] == '\\' )
{
if( ++i < to.length )
if( ++i < m_to.length )
{
int value = Character.digit( to[ i ], 10 );
final int value = Character.digit( m_to[ i ], 10 );
if( value > -1 )
{
result.append( (String)v.get( value ) );
m_result.append( (String)groups.get( value ) );
}
else
{
result.append( to[ i ] );
m_result.append( m_to[ i ] );
}
}
else
{
// XXX - should throw an exception instead?
result.append( '\\' );
m_result.append( '\\' );
}
}
else
{
result.append( to[ i ] );
m_result.append( m_to[ i ] );
}
}
return result.toString();
return m_result.toString();
}

}

+ 0
- 1
proposal/myrmidon/src/todo/org/apache/tools/ant/util/FileNameMapper.java View File

@@ -23,7 +23,6 @@ import org.apache.myrmidon.api.TaskException;
*/
public interface FileNameMapper
{

/**
* Sets the from part of the transformation rule.
*


+ 8
- 10
proposal/myrmidon/src/todo/org/apache/tools/ant/util/FlatFileNameMapper.java View File

@@ -7,6 +7,8 @@
*/
package org.apache.tools.ant.util;

import java.io.File;

/**
* Implementation of FileNameMapper that always returns the source file name
* without any leading directory information. <p>
@@ -16,24 +18,20 @@ package org.apache.tools.ant.util;
*
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
public class FlatFileNameMapper implements FileNameMapper
public class FlatFileNameMapper
implements FileNameMapper
{

/**
* Ignored.
*
* @param from The new From value
*/
public void setFrom( String from )
public void setFrom( final String from )
{
}

/**
* Ignored.
*
* @param to The new To value
*/
public void setTo( String to )
public void setTo( final String to )
{
}

@@ -44,8 +42,8 @@ public class FlatFileNameMapper implements FileNameMapper
* @param sourceFileName Description of Parameter
* @return Description of the Returned Value
*/
public String[] mapFileName( String sourceFileName )
public String[] mapFileName( final String sourceFileName )
{
return new String[]{new java.io.File( sourceFileName ).getName()};
return new String[]{new File( sourceFileName ).getName()};
}
}

+ 35
- 31
proposal/myrmidon/src/todo/org/apache/tools/ant/util/GlobPatternMapper.java View File

@@ -19,58 +19,59 @@ package org.apache.tools.ant.util;
*
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
public class GlobPatternMapper implements FileNameMapper
public class GlobPatternMapper
implements FileNameMapper
{
/**
* Part of &quot;from&quot; pattern before the *.
*/
protected String fromPrefix = null;
private String m_fromPrefix;

/**
* Part of &quot;from&quot; pattern after the *.
*/
protected String fromPostfix = null;
private String m_fromPostfix;

/**
* Part of &quot;to&quot; pattern before the *.
*/
protected String toPrefix = null;
private String m_toPrefix;

/**
* Part of &quot;to&quot; pattern after the *.
*/
protected String toPostfix = null;
private String m_toPostfix;

/**
* Length of the postfix (&quot;from&quot; pattern).
*/
protected int postfixLength;
private int m_postfixLength;

/**
* Length of the prefix (&quot;from&quot; pattern).
*/
protected int prefixLength;
private int m_prefixLength;

/**
* Sets the &quot;from&quot; pattern. Required.
*
* @param from The new From value
*/
public void setFrom( String from )
public void setFrom( final String from )
{
int index = from.lastIndexOf( "*" );
final int index = from.lastIndexOf( "*" );
if( index == -1 )
{
fromPrefix = from;
fromPostfix = "";
m_fromPrefix = from;
m_fromPostfix = "";
}
else
{
fromPrefix = from.substring( 0, index );
fromPostfix = from.substring( index + 1 );
m_fromPrefix = from.substring( 0, index );
m_fromPostfix = from.substring( index + 1 );
}
prefixLength = fromPrefix.length();
postfixLength = fromPostfix.length();
m_prefixLength = m_fromPrefix.length();
m_postfixLength = m_fromPostfix.length();
}

/**
@@ -78,18 +79,18 @@ public class GlobPatternMapper implements FileNameMapper
*
* @param to The new To value
*/
public void setTo( String to )
public void setTo( final String to )
{
int index = to.lastIndexOf( "*" );
final int index = to.lastIndexOf( "*" );
if( index == -1 )
{
toPrefix = to;
toPostfix = "";
m_toPrefix = to;
m_toPostfix = "";
}
else
{
toPrefix = to.substring( 0, index );
toPostfix = to.substring( index + 1 );
m_toPrefix = to.substring( 0, index );
m_toPostfix = to.substring( index + 1 );
}
}

@@ -100,17 +101,20 @@ public class GlobPatternMapper implements FileNameMapper
* @param sourceFileName Description of Parameter
* @return Description of the Returned Value
*/
public String[] mapFileName( String sourceFileName )
public String[] mapFileName( final String sourceFileName )
{
if( fromPrefix == null
|| !sourceFileName.startsWith( fromPrefix )
|| !sourceFileName.endsWith( fromPostfix ) )
if( m_fromPrefix == null ||
!sourceFileName.startsWith( m_fromPrefix ) ||
!sourceFileName.endsWith( m_fromPostfix ) )
{
return null;
}
return new String[]{toPrefix
+ extractVariablePart( sourceFileName )
+ toPostfix};
else
{
final String result = m_toPrefix +
extractVariablePart( sourceFileName ) + m_toPostfix;
return new String[]{result};
}
}

/**
@@ -120,9 +124,9 @@ public class GlobPatternMapper implements FileNameMapper
* @param name Description of Parameter
* @return Description of the Returned Value
*/
protected String extractVariablePart( String name )
protected String extractVariablePart( final String name )
{
return name.substring( prefixLength,
name.length() - postfixLength );
return name.substring( m_prefixLength,
name.length() - m_postfixLength );
}
}

+ 5
- 5
proposal/myrmidon/src/todo/org/apache/tools/ant/util/IdentityMapper.java View File

@@ -15,15 +15,15 @@ package org.apache.tools.ant.util;
*
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
public class IdentityMapper implements FileNameMapper
public class IdentityMapper
implements FileNameMapper
{

/**
* Ignored.
*
* @param from The new From value
*/
public void setFrom( String from )
public void setFrom( final String from )
{
}

@@ -32,7 +32,7 @@ public class IdentityMapper implements FileNameMapper
*
* @param to The new To value
*/
public void setTo( String to )
public void setTo( final String to )
{
}

@@ -42,7 +42,7 @@ public class IdentityMapper implements FileNameMapper
* @param sourceFileName Description of Parameter
* @return Description of the Returned Value
*/
public String[] mapFileName( String sourceFileName )
public String[] mapFileName( final String sourceFileName )
{
return new String[]{sourceFileName};
}


+ 6
- 6
proposal/myrmidon/src/todo/org/apache/tools/ant/util/MergingMapper.java View File

@@ -15,9 +15,10 @@ package org.apache.tools.ant.util;
*
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
public class MergingMapper implements FileNameMapper
public class MergingMapper
implements FileNameMapper
{
protected String[] mergedFile = null;
private String[] m_mergedFile;

/**
* Ignored.
@@ -35,7 +36,7 @@ public class MergingMapper implements FileNameMapper
*/
public void setTo( String to )
{
mergedFile = new String[]{to};
m_mergedFile = new String[]{to};
}

/**
@@ -44,9 +45,8 @@ public class MergingMapper implements FileNameMapper
* @param sourceFileName Description of Parameter
* @return Description of the Returned Value
*/
public String[] mapFileName( String sourceFileName )
public String[] mapFileName( final String sourceFileName )
{
return mergedFile;
return m_mergedFile;
}

}

+ 30
- 33
proposal/myrmidon/src/todo/org/apache/tools/ant/util/RegexpPatternMapper.java View File

@@ -17,37 +17,34 @@ import org.apache.tools.ant.util.regexp.RegexpMatcherFactory;
*
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
public class RegexpPatternMapper implements FileNameMapper
public class RegexpPatternMapper
implements FileNameMapper
{
protected RegexpMatcher reg = null;
protected char[] to = null;
protected StringBuffer result = new StringBuffer();
private RegexpMatcher m_matcher;
private char[] m_to;
private StringBuffer m_result = new StringBuffer();

public RegexpPatternMapper()
throws TaskException
{
reg = ( new RegexpMatcherFactory() ).newRegexpMatcher();
m_matcher = ( new RegexpMatcherFactory() ).newRegexpMatcher();
}

/**
* Sets the &quot;from&quot; pattern. Required.
*
* @param from The new From value
* @exception TaskException Description of Exception
*/
public void setFrom( String from )
public void setFrom( final String from )
throws TaskException
{
try
{
reg.setPattern( from );
m_matcher.setPattern( from );
}
catch( NoClassDefFoundError e )
{
// depending on the implementation the actual RE won't
// get instantiated in the constructor.
throw new TaskException( "Cannot load regular expression matcher",
e );
throw new TaskException( "Cannot load regular expression matcher", e );
}
}

@@ -56,9 +53,9 @@ public class RegexpPatternMapper implements FileNameMapper
*
* @param to The new To value
*/
public void setTo( String to )
public void setTo( final String to )
{
this.to = to.toCharArray();
m_to = to.toCharArray();
}

/**
@@ -68,57 +65,57 @@ public class RegexpPatternMapper implements FileNameMapper
* @param sourceFileName Description of Parameter
* @return Description of the Returned Value
*/
public String[] mapFileName( String sourceFileName )
public String[] mapFileName( final String sourceFileName )
throws TaskException
{
if( reg == null || to == null || !reg.matches( sourceFileName ) )
if( m_matcher == null || m_to == null ||
!m_matcher.matches( sourceFileName ) )
{
return null;
}
return new String[]{replaceReferences( sourceFileName )};
else
{
return new String[]{replaceReferences( sourceFileName )};
}
}

/**
* Replace all backreferences in the to pattern with the matched groups of
* the source.
*
* @param source Description of Parameter
* @return Description of the Returned Value
*/
protected String replaceReferences( String source )
private String replaceReferences( final String source )
throws TaskException
{
ArrayList v = reg.getGroups( source );
final ArrayList groups = m_matcher.getGroups( source );

result.setLength( 0 );
for( int i = 0; i < to.length; i++ )
m_result.setLength( 0 );
for( int i = 0; i < m_to.length; i++ )
{
if( to[ i ] == '\\' )
if( m_to[ i ] == '\\' )
{
if( ++i < to.length )
if( ++i < m_to.length )
{
int value = Character.digit( to[ i ], 10 );
final int value = Character.digit( m_to[ i ], 10 );
if( value > -1 )
{
result.append( (String)v.get( value ) );
m_result.append( (String)groups.get( value ) );
}
else
{
result.append( to[ i ] );
m_result.append( m_to[ i ] );
}
}
else
{
// XXX - should throw an exception instead?
result.append( '\\' );
m_result.append( '\\' );
}
}
else
{
result.append( to[ i ] );
m_result.append( m_to[ i ] );
}
}
return result.toString();
return m_result.toString();
}

}

Loading…
Cancel
Save