You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Paulo Silveira <pa...@paulo.com.br> on 2003/05/29 19:29:36 UTC

maven-new interpolation aspect

Hello.

Jason and michal likes the idea of lazy interpolation, all done by the
aspect. So I ve added a new pointcut, to get around List
Project.getMavenRepoRemote().

    pointcut projectRepoteRepoGetter(Project p): call( List
Project.getMavenRepoRemote( .. ) )
                                        && target(p);

Then we interpolate _each_ remote repository string, creating a new
List. 

For maven.repo.local it gets more complicated, some classes do not
access it through project.getMavenRepoLocal(). Some classes even try
first to look it at System.getProperty(). You can take a look at
DefaultArtifactFactory as Jason said. Maybe another pointcut, but this
one would be to specific for the ArtifactFactory, I dont know if it is a
good idea. 

Take a look at the around code:

    List around(Project p): projectRepoteRepoGetter(p)
    {
        // Let's grab the value that would normally be returned.
        List remoteRepos = proceed(p);

        if ( remoteRepos == null )
        {
            return null;
        }
        
        // this one will be returned instead
        List interpolatedRemoteRepos = new ArrayList();
        
        // for each remote repository
        // interpolates it, and add to the new list
        for( Iterator i = remoteRepos.iterator(); i.hasNext(); ) 
        {
            String remoteRepo = (String) i.next();
            String interpolatedRepo = interpolate( remoteRepo, p );
            interpolatedRemoteRepos.add( interpolatedRepo );       
        }
        
        return interpolatedRemoteRepos;
    }


The interpolate method is an extract from what Jason wrote at first
time:

    private String interpolate(String s, Project project) {
        if ( s == null )
        {
            return null;
        }
        
        // Let's see if we need to do any value interpolation.
        if ( s.indexOf( "${pom" ) >= 0 )
        {
            // Find the method in the pom we're after, use reflection to
look
            // it up the method and execute it.
        }
        else if ( s.indexOf( "${" ) >= 0 )
        {
            return StringUtils.interpolate( s, project.getProperties()
);
        }

        return s;       
    }

(The patch is included)

thanks
------------------------
Paulo Silveira
http://www.paulo.com.br/
http://www.guj.com.br/