jvanzyl     2004/02/07 08:26:51

  Modified:    maven-mboot/src/main Bootstrapper.java
  Log:
  o add functionality to interpolate <extend/> element.
  
  Revision  Changes    Path
  1.15      +53 -3     maven-components/maven-mboot/src/main/Bootstrapper.java
  
  Index: Bootstrapper.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-mboot/src/main/Bootstrapper.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Bootstrapper.java 7 Feb 2004 16:17:49 -0000       1.14
  +++ Bootstrapper.java 7 Feb 2004 16:26:51 -0000       1.15
  @@ -15,6 +15,7 @@
   import java.util.ArrayList;
   import java.util.Iterator;
   import java.util.List;
  +import java.util.Map;
   import java.util.Properties;
   
   public class Bootstrapper
  @@ -285,8 +286,57 @@
           return properties;
       }
   
  +    private String interpolate( String text, Map namespace )
  +    {
  +        Iterator keys = namespace.keySet().iterator();
  +
  +        while ( keys.hasNext() )
  +        {
  +            String key = keys.next().toString();
  +
  +            Object obj = namespace.get( key );
  +
  +            String value = obj.toString();
  +
  +            text = replace( text, "${" + key + "}", value );
  +
  +            if ( key.indexOf( " " ) == -1 )
  +            {
  +                text = replace( text, "$" + key, value );
  +            }
  +        }
  +        return text;
  +    }
  +
  +    private String replace( String text, String repl, String with )
  +    {
  +        return replace( text, repl, with, -1 );
  +    }
  +
  +    private String replace( String text, String repl, String with, int max )
  +    {
  +        if ( text == null || repl == null || with == null || repl.length() == 0 )
  +        {
  +            return text;
  +        }
  +
  +        StringBuffer buf = new StringBuffer( text.length() );
  +        int start = 0, end = 0;
  +        while ( ( end = text.indexOf( repl, start ) ) != -1 )
  +        {
  +            buf.append( text.substring( start, end ) ).append( with );
  +            start = end + repl.length();
  +
  +            if ( --max == 0 )
  +            {
  +                break;
  +            }
  +        }
  +        buf.append( text.substring( start ) );
  +        return buf.toString();
  +    }
   
  -    static class BootstrapPomParser
  +    class BootstrapPomParser
           extends DefaultHandler
       {
           private List dependencies = new ArrayList();
  @@ -299,7 +349,7 @@
   
           private Resource currentResource;
   
  -        private static SAXParserFactory saxFactory;
  +        private SAXParserFactory saxFactory;
   
           private boolean insideDependency = false;
   
  @@ -382,7 +432,7 @@
           {
               if ( rawName.equals( "extend" ) )
               {
  -                String extend = getBodyText();
  +                String extend = interpolate( getBodyText(), properties ) ;
   
                   File f = new File( file.getParentFile(), extend );
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to