jvanzyl     2002/07/24 17:30:21

  Modified:    src/java/org/apache/maven/jelly/tags/project MavenTag.java
  Log:
  o modifying the maven tag to do the glob so that i can easily grab the
    set of projects that have been processed so that any arbitrary post
    processing can be performed. this will need to be cleaned up for
    long-lived reactors, as we don't want the list to grow indefinitely, but
    i'm not sure how to deal with this is the best way yet. it allows me
    to generate a navigation for the commons at any rate.
  
  Revision  Changes    Path
  1.3       +110 -42   
jakarta-turbine-maven/src/java/org/apache/maven/jelly/tags/project/MavenTag.java
  
  Index: MavenTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jelly/tags/project/MavenTag.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MavenTag.java     23 Jul 2002 03:13:50 -0000      1.2
  +++ MavenTag.java     25 Jul 2002 00:30:21 -0000      1.3
  @@ -55,11 +55,12 @@
    *
    * ====================================================================
    */
  -
   import java.io.File;
   
   import java.util.ArrayList;
  +import java.util.HashMap;
   
  +import org.apache.maven.MavenUtils;
   import org.apache.maven.app.Maven;
   
   import org.apache.commons.jelly.MissingAttributeException;
  @@ -68,99 +69,166 @@
   
   import java.util.StringTokenizer;
   
  +/**
  + * Maven tag that process a set of project descriptors.
  + *
  + * @author <a href="[EMAIL PROTECTED]">bob mcwhirter</a>
  + * @author <a href="[EMAIL PROTECTED]">Jason van Zyl</a>
  + * @version $Id$
  + */
   public class MavenTag
        extends TagSupport
   {
  -    private File descriptor;
       private File dir;
       private String goals;
  -
  +    private String glob;
  +    private String banner;
  +    private ArrayList reactorProjects = new ArrayList();
  +    
       private boolean ignore;
   
  +    /**
  +     * Description of the Method
  +     */
       public void doTag(XMLOutput output)
           throws Exception
       {
  -        if ( this.dir == null )
  +        if (this.dir == null)
           {
  -            throw new MissingAttributeException( "dir" );
  +            throw new MissingAttributeException("dir");
           }
  -        
  -        if ( this.descriptor == null )
  +
  +        if (this.glob == null)
           {
  -            throw new MissingAttributeException( "descriptor" );
  +            throw new MissingAttributeException("glob");
           }
  -        
  -        Maven parent = (Maven) getContext().getVariable( "maven.obj" );
  -        
  -        try
  -        {
  -            Maven maven = new Maven( parent.getMavenHome() );
  -        
  -            maven.setDir( getDir() );
  -            maven.setProjectFile( getDescriptor() );
  -            maven.setXMLOutput( output,
  -                                parent.isDebug() );
  -            maven.loadProperties();
   
  +        Maven parent = (Maven) Maven.getInstance().getVariable("maven.obj");
   
  -            if ( this.goals != null )
  +        String[] projects = MavenUtils.getFiles(getDir(), getGlob());
  +
  +        for (int i = 0; i < projects.length; i++)
  +        {
  +            try
               {
  -                StringTokenizer tokens = new StringTokenizer( this.goals,
  -                                                              "," );
  -            
  -                while ( tokens.hasMoreTokens() )
  +                File p = new File(projects[i]);
  +                
  +                System.out.println("+----------------------------------------");
  +                System.out.println("| " + getBanner() + " " + 
p.getParentFile().getName());
  +                System.out.println("+----------------------------------------");
  +
  +                Maven maven = new Maven(parent.getMavenHome());
  +                maven.setDir(p.getParentFile());
  +                maven.setProjectFile(new File(projects[i]));
  +                maven.setXMLOutput(output, parent.isDebug());
  +                maven.loadProperties();
  +
  +                if (this.goals != null)
                   {
  -                    maven.addGoalName( tokens.nextToken().trim() );
  +                    StringTokenizer tokens = new StringTokenizer(this.goals,
  +                        ",");
  +
  +                    while (tokens.hasMoreTokens())
  +                    {
  +                        maven.addGoalName(tokens.nextToken().trim());
  +                    }
                   }
  -            }
   
  -            maven.runtimeInitialization();
  -        
  -            maven.attainGoals();
  -        }
  -        catch (Exception e)
  -        {
  -            if ( ignore )
  -            {
  -                return;
  +                maven.runtimeInitialization();
  +                maven.attainGoals();
  +                
  +                // Collect the project objects so that we can use them
  +                // for any sort of post-processing.
  +                reactorProjects.add(maven.getProject());
               }
  +            catch (Exception e)
  +            {
  +                if (ignore)
  +                {
  +                    continue;
  +                }
   
  -            e.fillInStackTrace();
  +                e.fillInStackTrace();
   
  -            throw e;
  +                throw e;
  +            }
           }
  +    
  +        Maven.getInstance().setVariable("reactorProjects", reactorProjects);
       }
   
  -    public void setDescriptor(File descriptor)
  +    /**
  +     * Sets the glob attribute of the MavenTag object
  +     */
  +    public void setGlob(String glob)
       {
  -        this.descriptor = descriptor;
  +        this.glob = glob;
       }
   
  -    public File getDescriptor()
  +    /**
  +     * Gets the glob attribute of the MavenTag object
  +     */
  +    public String getGlob()
       {
  -        return this.descriptor;
  +        return this.glob;
  +    }
  +
  +    /**
  +     * Sets the banner attribute of the MavenTag object
  +     */
  +    public void setBanner(String banner)
  +    {
  +        this.banner = banner;
  +    }
  +
  +    /**
  +     * Gets the banner attribute of the MavenTag object
  +     */
  +    public String getBanner()
  +    {
  +        if (this.banner == null)
  +        {
  +            return "Processing";
  +        }
  +        
  +        return this.banner;
       }
   
  +    /**
  +     * Sets the dir attribute of the MavenTag object
  +     */
       public void setDir(File dir)
       {
           this.dir = dir;
       }
   
  +    /**
  +     * Gets the dir attribute of the MavenTag object
  +     */
       public File getDir()
       {
           return this.dir;
       }
   
  +    /**
  +     * Sets the goals attribute of the MavenTag object
  +     */
       public void setGoals(String goals)
       {
           this.goals = goals;
       }
   
  +    /**
  +     * Gets the goals attribute of the MavenTag object
  +     */
       public String getGoals()
       {
           return this.goals;
       }
   
  +    /**
  +     * Sets the ignoreFailures attribute of the MavenTag object
  +     */
       public void setIgnoreFailures(boolean ignore)
       {
           this.ignore = ignore;
  
  
  

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

Reply via email to