git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270704 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -23,7 +23,6 @@ import org.apache.myrmidon.api.TaskException; | |||||
| */ | */ | ||||
| public interface FileNameMapper | public interface FileNameMapper | ||||
| { | { | ||||
| /** | /** | ||||
| * Sets the from part of the transformation rule. | * Sets the from part of the transformation rule. | ||||
| * | * | ||||
| @@ -7,6 +7,8 @@ | |||||
| */ | */ | ||||
| package org.apache.tools.ant.util; | package org.apache.tools.ant.util; | ||||
| import java.io.File; | |||||
| /** | /** | ||||
| * Implementation of FileNameMapper that always returns the source file name | * Implementation of FileNameMapper that always returns the source file name | ||||
| * without any leading directory information. <p> | * 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> | * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | ||||
| */ | */ | ||||
| public class FlatFileNameMapper implements FileNameMapper | |||||
| public class FlatFileNameMapper | |||||
| implements FileNameMapper | |||||
| { | { | ||||
| /** | /** | ||||
| * Ignored. | * Ignored. | ||||
| * | |||||
| * @param from The new From value | |||||
| */ | */ | ||||
| public void setFrom( String from ) | |||||
| public void setFrom( final String from ) | |||||
| { | { | ||||
| } | } | ||||
| /** | /** | ||||
| * Ignored. | * 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 | * @param sourceFileName Description of Parameter | ||||
| * @return Description of the Returned Value | * @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()}; | |||||
| } | } | ||||
| } | } | ||||
| @@ -19,58 +19,59 @@ package org.apache.tools.ant.util; | |||||
| * | * | ||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | ||||
| */ | */ | ||||
| public class GlobPatternMapper implements FileNameMapper | |||||
| public class GlobPatternMapper | |||||
| implements FileNameMapper | |||||
| { | { | ||||
| /** | /** | ||||
| * Part of "from" pattern before the *. | * Part of "from" pattern before the *. | ||||
| */ | */ | ||||
| protected String fromPrefix = null; | |||||
| private String m_fromPrefix; | |||||
| /** | /** | ||||
| * Part of "from" pattern after the *. | * Part of "from" pattern after the *. | ||||
| */ | */ | ||||
| protected String fromPostfix = null; | |||||
| private String m_fromPostfix; | |||||
| /** | /** | ||||
| * Part of "to" pattern before the *. | * Part of "to" pattern before the *. | ||||
| */ | */ | ||||
| protected String toPrefix = null; | |||||
| private String m_toPrefix; | |||||
| /** | /** | ||||
| * Part of "to" pattern after the *. | * Part of "to" pattern after the *. | ||||
| */ | */ | ||||
| protected String toPostfix = null; | |||||
| private String m_toPostfix; | |||||
| /** | /** | ||||
| * Length of the postfix ("from" pattern). | * Length of the postfix ("from" pattern). | ||||
| */ | */ | ||||
| protected int postfixLength; | |||||
| private int m_postfixLength; | |||||
| /** | /** | ||||
| * Length of the prefix ("from" pattern). | * Length of the prefix ("from" pattern). | ||||
| */ | */ | ||||
| protected int prefixLength; | |||||
| private int m_prefixLength; | |||||
| /** | /** | ||||
| * Sets the "from" pattern. Required. | * Sets the "from" pattern. Required. | ||||
| * | * | ||||
| * @param from The new From value | * @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 ) | if( index == -1 ) | ||||
| { | { | ||||
| fromPrefix = from; | |||||
| fromPostfix = ""; | |||||
| m_fromPrefix = from; | |||||
| m_fromPostfix = ""; | |||||
| } | } | ||||
| else | 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 | * @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 ) | if( index == -1 ) | ||||
| { | { | ||||
| toPrefix = to; | |||||
| toPostfix = ""; | |||||
| m_toPrefix = to; | |||||
| m_toPostfix = ""; | |||||
| } | } | ||||
| else | 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 | * @param sourceFileName Description of Parameter | ||||
| * @return Description of the Returned Value | * @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 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 | * @param name Description of Parameter | ||||
| * @return Description of the Returned Value | * @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 ); | |||||
| } | } | ||||
| } | } | ||||
| @@ -15,15 +15,15 @@ package org.apache.tools.ant.util; | |||||
| * | * | ||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | ||||
| */ | */ | ||||
| public class IdentityMapper implements FileNameMapper | |||||
| public class IdentityMapper | |||||
| implements FileNameMapper | |||||
| { | { | ||||
| /** | /** | ||||
| * Ignored. | * Ignored. | ||||
| * | * | ||||
| * @param from The new From value | * @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 | * @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 | * @param sourceFileName Description of Parameter | ||||
| * @return Description of the Returned Value | * @return Description of the Returned Value | ||||
| */ | */ | ||||
| public String[] mapFileName( String sourceFileName ) | |||||
| public String[] mapFileName( final String sourceFileName ) | |||||
| { | { | ||||
| return new String[]{sourceFileName}; | return new String[]{sourceFileName}; | ||||
| } | } | ||||
| @@ -15,9 +15,10 @@ package org.apache.tools.ant.util; | |||||
| * | * | ||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @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. | * Ignored. | ||||
| @@ -35,7 +36,7 @@ public class MergingMapper implements FileNameMapper | |||||
| */ | */ | ||||
| public void setTo( String to ) | 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 | * @param sourceFileName Description of Parameter | ||||
| * @return Description of the Returned Value | * @return Description of the Returned Value | ||||
| */ | */ | ||||
| public String[] mapFileName( String sourceFileName ) | |||||
| public String[] mapFileName( final String sourceFileName ) | |||||
| { | { | ||||
| return mergedFile; | |||||
| return m_mergedFile; | |||||
| } | } | ||||
| } | } | ||||
| @@ -17,37 +17,34 @@ import org.apache.tools.ant.util.regexp.RegexpMatcherFactory; | |||||
| * | * | ||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @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() | public RegexpPatternMapper() | ||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| reg = ( new RegexpMatcherFactory() ).newRegexpMatcher(); | |||||
| m_matcher = ( new RegexpMatcherFactory() ).newRegexpMatcher(); | |||||
| } | } | ||||
| /** | /** | ||||
| * Sets the "from" pattern. Required. | * Sets the "from" 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 | throws TaskException | ||||
| { | { | ||||
| try | try | ||||
| { | { | ||||
| reg.setPattern( from ); | |||||
| m_matcher.setPattern( from ); | |||||
| } | } | ||||
| catch( NoClassDefFoundError e ) | catch( NoClassDefFoundError e ) | ||||
| { | { | ||||
| // depending on the implementation the actual RE won't | // depending on the implementation the actual RE won't | ||||
| // get instantiated in the constructor. | // 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 | * @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 | * @param sourceFileName Description of Parameter | ||||
| * @return Description of the Returned Value | * @return Description of the Returned Value | ||||
| */ | */ | ||||
| public String[] mapFileName( String sourceFileName ) | |||||
| public String[] mapFileName( final String sourceFileName ) | |||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| if( reg == null || to == null || !reg.matches( sourceFileName ) ) | |||||
| if( m_matcher == null || m_to == null || | |||||
| !m_matcher.matches( sourceFileName ) ) | |||||
| { | { | ||||
| return null; | 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 | * Replace all backreferences in the to pattern with the matched groups of | ||||
| * the source. | * 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 | 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 ) | if( value > -1 ) | ||||
| { | { | ||||
| result.append( (String)v.get( value ) ); | |||||
| m_result.append( (String)groups.get( value ) ); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| result.append( to[ i ] ); | |||||
| m_result.append( m_to[ i ] ); | |||||
| } | } | ||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| // XXX - should throw an exception instead? | // XXX - should throw an exception instead? | ||||
| result.append( '\\' ); | |||||
| m_result.append( '\\' ); | |||||
| } | } | ||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| result.append( to[ i ] ); | |||||
| m_result.append( m_to[ i ] ); | |||||
| } | } | ||||
| } | } | ||||
| return result.toString(); | |||||
| return m_result.toString(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -23,7 +23,6 @@ import org.apache.myrmidon.api.TaskException; | |||||
| */ | */ | ||||
| public interface FileNameMapper | public interface FileNameMapper | ||||
| { | { | ||||
| /** | /** | ||||
| * Sets the from part of the transformation rule. | * Sets the from part of the transformation rule. | ||||
| * | * | ||||
| @@ -7,6 +7,8 @@ | |||||
| */ | */ | ||||
| package org.apache.tools.ant.util; | package org.apache.tools.ant.util; | ||||
| import java.io.File; | |||||
| /** | /** | ||||
| * Implementation of FileNameMapper that always returns the source file name | * Implementation of FileNameMapper that always returns the source file name | ||||
| * without any leading directory information. <p> | * 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> | * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | ||||
| */ | */ | ||||
| public class FlatFileNameMapper implements FileNameMapper | |||||
| public class FlatFileNameMapper | |||||
| implements FileNameMapper | |||||
| { | { | ||||
| /** | /** | ||||
| * Ignored. | * Ignored. | ||||
| * | |||||
| * @param from The new From value | |||||
| */ | */ | ||||
| public void setFrom( String from ) | |||||
| public void setFrom( final String from ) | |||||
| { | { | ||||
| } | } | ||||
| /** | /** | ||||
| * Ignored. | * 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 | * @param sourceFileName Description of Parameter | ||||
| * @return Description of the Returned Value | * @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()}; | |||||
| } | } | ||||
| } | } | ||||
| @@ -19,58 +19,59 @@ package org.apache.tools.ant.util; | |||||
| * | * | ||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | ||||
| */ | */ | ||||
| public class GlobPatternMapper implements FileNameMapper | |||||
| public class GlobPatternMapper | |||||
| implements FileNameMapper | |||||
| { | { | ||||
| /** | /** | ||||
| * Part of "from" pattern before the *. | * Part of "from" pattern before the *. | ||||
| */ | */ | ||||
| protected String fromPrefix = null; | |||||
| private String m_fromPrefix; | |||||
| /** | /** | ||||
| * Part of "from" pattern after the *. | * Part of "from" pattern after the *. | ||||
| */ | */ | ||||
| protected String fromPostfix = null; | |||||
| private String m_fromPostfix; | |||||
| /** | /** | ||||
| * Part of "to" pattern before the *. | * Part of "to" pattern before the *. | ||||
| */ | */ | ||||
| protected String toPrefix = null; | |||||
| private String m_toPrefix; | |||||
| /** | /** | ||||
| * Part of "to" pattern after the *. | * Part of "to" pattern after the *. | ||||
| */ | */ | ||||
| protected String toPostfix = null; | |||||
| private String m_toPostfix; | |||||
| /** | /** | ||||
| * Length of the postfix ("from" pattern). | * Length of the postfix ("from" pattern). | ||||
| */ | */ | ||||
| protected int postfixLength; | |||||
| private int m_postfixLength; | |||||
| /** | /** | ||||
| * Length of the prefix ("from" pattern). | * Length of the prefix ("from" pattern). | ||||
| */ | */ | ||||
| protected int prefixLength; | |||||
| private int m_prefixLength; | |||||
| /** | /** | ||||
| * Sets the "from" pattern. Required. | * Sets the "from" pattern. Required. | ||||
| * | * | ||||
| * @param from The new From value | * @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 ) | if( index == -1 ) | ||||
| { | { | ||||
| fromPrefix = from; | |||||
| fromPostfix = ""; | |||||
| m_fromPrefix = from; | |||||
| m_fromPostfix = ""; | |||||
| } | } | ||||
| else | 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 | * @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 ) | if( index == -1 ) | ||||
| { | { | ||||
| toPrefix = to; | |||||
| toPostfix = ""; | |||||
| m_toPrefix = to; | |||||
| m_toPostfix = ""; | |||||
| } | } | ||||
| else | 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 | * @param sourceFileName Description of Parameter | ||||
| * @return Description of the Returned Value | * @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 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 | * @param name Description of Parameter | ||||
| * @return Description of the Returned Value | * @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 ); | |||||
| } | } | ||||
| } | } | ||||
| @@ -15,15 +15,15 @@ package org.apache.tools.ant.util; | |||||
| * | * | ||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | ||||
| */ | */ | ||||
| public class IdentityMapper implements FileNameMapper | |||||
| public class IdentityMapper | |||||
| implements FileNameMapper | |||||
| { | { | ||||
| /** | /** | ||||
| * Ignored. | * Ignored. | ||||
| * | * | ||||
| * @param from The new From value | * @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 | * @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 | * @param sourceFileName Description of Parameter | ||||
| * @return Description of the Returned Value | * @return Description of the Returned Value | ||||
| */ | */ | ||||
| public String[] mapFileName( String sourceFileName ) | |||||
| public String[] mapFileName( final String sourceFileName ) | |||||
| { | { | ||||
| return new String[]{sourceFileName}; | return new String[]{sourceFileName}; | ||||
| } | } | ||||
| @@ -15,9 +15,10 @@ package org.apache.tools.ant.util; | |||||
| * | * | ||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @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. | * Ignored. | ||||
| @@ -35,7 +36,7 @@ public class MergingMapper implements FileNameMapper | |||||
| */ | */ | ||||
| public void setTo( String to ) | 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 | * @param sourceFileName Description of Parameter | ||||
| * @return Description of the Returned Value | * @return Description of the Returned Value | ||||
| */ | */ | ||||
| public String[] mapFileName( String sourceFileName ) | |||||
| public String[] mapFileName( final String sourceFileName ) | |||||
| { | { | ||||
| return mergedFile; | |||||
| return m_mergedFile; | |||||
| } | } | ||||
| } | } | ||||
| @@ -17,37 +17,34 @@ import org.apache.tools.ant.util.regexp.RegexpMatcherFactory; | |||||
| * | * | ||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @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() | public RegexpPatternMapper() | ||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| reg = ( new RegexpMatcherFactory() ).newRegexpMatcher(); | |||||
| m_matcher = ( new RegexpMatcherFactory() ).newRegexpMatcher(); | |||||
| } | } | ||||
| /** | /** | ||||
| * Sets the "from" pattern. Required. | * Sets the "from" 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 | throws TaskException | ||||
| { | { | ||||
| try | try | ||||
| { | { | ||||
| reg.setPattern( from ); | |||||
| m_matcher.setPattern( from ); | |||||
| } | } | ||||
| catch( NoClassDefFoundError e ) | catch( NoClassDefFoundError e ) | ||||
| { | { | ||||
| // depending on the implementation the actual RE won't | // depending on the implementation the actual RE won't | ||||
| // get instantiated in the constructor. | // 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 | * @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 | * @param sourceFileName Description of Parameter | ||||
| * @return Description of the Returned Value | * @return Description of the Returned Value | ||||
| */ | */ | ||||
| public String[] mapFileName( String sourceFileName ) | |||||
| public String[] mapFileName( final String sourceFileName ) | |||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| if( reg == null || to == null || !reg.matches( sourceFileName ) ) | |||||
| if( m_matcher == null || m_to == null || | |||||
| !m_matcher.matches( sourceFileName ) ) | |||||
| { | { | ||||
| return null; | 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 | * Replace all backreferences in the to pattern with the matched groups of | ||||
| * the source. | * 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 | 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 ) | if( value > -1 ) | ||||
| { | { | ||||
| result.append( (String)v.get( value ) ); | |||||
| m_result.append( (String)groups.get( value ) ); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| result.append( to[ i ] ); | |||||
| m_result.append( m_to[ i ] ); | |||||
| } | } | ||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| // XXX - should throw an exception instead? | // XXX - should throw an exception instead? | ||||
| result.append( '\\' ); | |||||
| m_result.append( '\\' ); | |||||
| } | } | ||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| result.append( to[ i ] ); | |||||
| m_result.append( m_to[ i ] ); | |||||
| } | } | ||||
| } | } | ||||
| return result.toString(); | |||||
| return m_result.toString(); | |||||
| } | } | ||||
| } | } | ||||