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/
Index: PomInterpolationAspect.java
===================================================================
RCS file:
/home/cvspublic/maven-new/core/src/aspect/org/apache/maven/PomInterpolationAspect.java,v
retrieving revision 1.3
diff -u -r1.3 PomInterpolationAspect.java
--- PomInterpolationAspect.java 23 May 2003 02:10:29 -0000 1.3
+++ PomInterpolationAspect.java 29 May 2003 17:28:51 -0000
@@ -2,6 +2,9 @@
import org.apache.maven.project.Project;
import org.apache.plexus.util.StringUtils;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Iterator;
/** An aspect that intercepts all public getters in the project
* and interpolates values into the result before being return
@@ -23,6 +26,9 @@
pointcut projectGetters(Project p): call( String Project.get*( .. ) )
&& target(p);
+ pointcut projectRepoteRepoGetter(Project p): call( List
Project.getMavenRepoRemote( .. ) )
+ && target(p);
+
String around(Project p): projectGetters(p)
{
// Let's grab the value that would normally be returned.
@@ -33,6 +39,41 @@
return null;
}
+ return interpolate( s, p );
+ }
+
+
+ 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;
+ }
+
+ 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 )
{
@@ -41,9 +82,9 @@
}
else if ( s.indexOf( "${" ) >= 0 )
{
- return StringUtils.interpolate( s, p.getProperties() );
+ return StringUtils.interpolate( s, project.getProperties() );
}
- return s;
+ return s;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]