maven-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jvan...@apache.org
Subject cvs commit: jakarta-turbine-maven/src/java/org/apache/maven/jelly/tags/maven ReactorTag.java
Date Tue, 31 Dec 2002 07:01:20 GMT
jvanzyl     2002/12/30 23:01:20

  Added:       src/java/org/apache/maven/jelly/tags/maven ReactorTag.java
  Log:
  refactoring. update to follow
  
  Revision  Changes    Path
  1.1                  jakarta-turbine-maven/src/java/org/apache/maven/jelly/tags/maven/ReactorTag.java
  
  Index: ReactorTag.java
  ===================================================================
  package org.apache.maven.jelly.tags.maven;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache MavenSession" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache MavenSession", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  import org.apache.commons.jelly.MissingAttributeException;
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.maven.MavenUtils;
  import org.apache.maven.MavenSession;
  import org.apache.maven.project.Project;
  import org.apache.maven.jelly.MavenJellyContext;
  
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  /**
   * Reactor tag that processes a set of project descriptors taking into
   * consideration the inter-project dependencies.
   *
   * @author <a href="bob@werken.com">bob mcwhirter</a>
   * @author <a href="jason@zenplex.com">Jason van Zyl</a>
   * @author <a href="mailto:evenisse@ifrance.com">Emmanuel Venisse</a>
   * @version $Id: ReactorTag.java,v 1.1 2002/12/31 07:01:20 jvanzyl Exp $
   */
  
  /*
  
  We use the basedir for the glob, but we need to set the descriptor.
  
  */
  
  /**
   * Used for building a set of projects in the correct order to satisfy any
   * dependencies among the projects being processed.
   *
   * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
   *
   * @version $Id: ReactorTag.java,v 1.1 2002/12/31 07:01:20 jvanzyl Exp $
   */
  public class ReactorTag
      extends MavenTag
  {
      /** The glob used to select projects within the base directory. */
      private String glob;
  
      /** Projects to include. */
      private String includes;
  
      /** Projects to exclude. */
      private String excludes;
  
      /** Banner to display when each project is processed. */
      private String banner;
  
      /**
       * Post processing flag. If this is set then we will hold on to the
       * processed projects, otherwise they will be dumped.
       */
      private boolean postProcessing = false;
  
      /** Storage for processed projects. */
      private ArrayList reactorProjects = new ArrayList();
  
      /**
       *  Execute the body of the reactor tag.
       *
       * @param output The output sink.
       * @throws Exception If an error occurs while processing the tag.
       */
      public void doTag( XMLOutput output )
          throws Exception
      {
          if ( getBasedir() == null )
          {
              throw new MissingAttributeException( "basedir" );
          }
  
          if ( getGlob() == null && getIncludes() == null )
          {
              throw new MissingAttributeException( "glob|includes" );
          }
  
          String projectIncludes;
          if ( getGlob() != null )
          {
              projectIncludes = getGlob();
          }
          else
          {
              projectIncludes = getIncludes();
          }
  
          //!! Need to think about the root context for the reactor projects.
  
          List projects = MavenUtils.getProjects( getBasedir(),
                                                  projectIncludes,
                                                  getExcludes(),
                                                  getMavenContext().getMavenSession().getRootContext()
);
  
          DependencyResolver dr = new DependencyResolver();
          dr.setProjects( projects );
          List sortedProjects = dr.getSortedDependencies( false );
  
          System.out.println( "Our processing order:" );
          for ( Iterator i = sortedProjects.iterator(); i.hasNext(); )
          {
              Project p = (Project) i.next();
              System.out.println( p.getName() );
          }
  
          for ( Iterator i = sortedProjects.iterator(); i.hasNext(); )
          {
              try
              {
                  // The basedir needs to be set for the project
                  // We just need the descriptor.
  
                  Project project = (Project) i.next();
  
                  System.out.println( "+----------------------------------------" );
                  System.out.println( "| " + getBanner() + " " + project.getName() );
                  System.out.println( "+----------------------------------------" );
  
                  project.verifyDependencies();
                  project.setGoalNames( getGoals() );
  
                  getMavenContext().getMavenSession().attainGoals( project );
  
                  if ( getPostProcessing() )
                  {
                      reactorProjects.add( project );
                  }
                  else
                  {
                      project = null;
                  }
              }
              catch ( Exception e )
              {
                  if ( getIgnoreFailures() )
                  {
                      continue;
                  }
  
                  e.printStackTrace();
                  e.fillInStackTrace();
  
                  throw e;
              }
          }
  
          getMavenContext().getMavenSession().getRootContext().setVariable("reactorProjects",
reactorProjects);
      }
  
      // ------------------------------------------------------------
      // A C C E S S O R S
      // ------------------------------------------------------------
  
      /**
       * Set the postProcessing attribute.
       *
       * @param postProcessing
       */
      public void setPostProcessing( boolean postProcessing )
      {
          this.postProcessing = postProcessing;
      }
  
      /**
       * Get the postProcessing attribute.
       *
       * @return The
       */
      public boolean getPostProcessing()
      {
          return postProcessing;
      }
  
      /**
       * Set the glob used to find projects.
       *
       * @param glob The glob used to find projects.
       */
      public void setGlob( String glob )
      {
          System.out.println("\nDEPRECATION WARNING: use the 'includes' attribute instead
of the 'glob' attribute.\n");
          this.glob = glob;
      }
  
      /**
       * Get the glob used to find projects.
       *
       * @return String The glob.
       */
      public String getGlob()
      {
          return glob;
      }
  
      /**
       * Set the includes used to find projects.
       *
       * @param includes The includes used to find projects.
       */
      public void setIncludes( String includes )
      {
          this.includes = includes;
      }
  
      /**
       * Get the includes used to find projects.
       *
       * @return String The includes.
       */
      public String getIncludes()
      {
          return includes;
      }
  
      /**
       * Set the excludes used to find projects.
       *
       * @param excludes The excludes used to find projects.
       */
      public void setExcludes( String excludes )
      {
          this.excludes = excludes;
      }
  
      /**
       * Get the excludes used to find projects.
       *
       * @return String The excludes.
       */
      public String getExcludes()
      {
          return excludes;
      }
  
      /**
       * Set the banner to be displayed for each project while
       * it is being processed.
       *
       * @param banner The banner to use for each processed project.
       */
      public void setBanner( String banner )
      {
          this.banner = banner;
      }
  
      /**
       * Get the banner to be displayed for project while it
       * is being processed.
       *
       * @return String The banner.
       */
      public String getBanner()
      {
          if ( banner == null )
          {
              return "Processing";
          }
  
          return banner;
      }
  }
  
  
  

Mime
View raw message