ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adammurd...@apache.org
Subject cvs commit: jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/project/test AntTaskTestCase.java ProjectRefTaskTestCase.java ant.ant build.ant projectref-common.ant projectref.ant ant-call.ant
Date Thu, 27 Jun 2002 11:13:09 GMT
adammurdoch    2002/06/27 04:13:08

  Modified:    ant1compat/src/java/org/apache/tools/ant
                        Ant1CompatTargetTask.java
               framework/src/java/org/apache/myrmidon/framework/project
                        AbstractWorkspaceTask.java Resources.properties
               framework/src/test/org/apache/myrmidon/framework
                        AbstractTaskTestCase.java expect-output.ant
               container/src/java/org/apache/myrmidon/components/builder
                        DefaultProjectBuilder.java Resources.properties
               container/src/java/org/apache/myrmidon/components/property
                        XPathPropertyResolver.java
               container/src/java/org/apache/myrmidon/components/workspace
                        DefaultWorkspace.java ProjectEntry.java
                        Resources.properties
               container/src/java/org/apache/myrmidon/interfaces/model
                        Project.java
               container/src/test/org/apache/myrmidon/components/builder/test
                        DefaultProjectBuilderTestCase.java
               antlib/src/java/org/apache/antlib/project DependsTask.java
                        Resources.properties
               antlib/src/test/org/apache/antlib
                        AbstractProjectTestCase.java
               antlib/src/test/org/apache/antlib/project/test ant-call.ant
  Added:       framework/src/java/org/apache/myrmidon/framework/project
                        TargetTask.java
               framework/src/test/org/apache/myrmidon/framework/project/test
                        TargetTaskTestCase.java target.ant
               container/src/java/org/apache/myrmidon/interfaces/workspace
                        ProjectRef.java ProjectRefs.java
               antlib/src/java/org/apache/antlib/project
                        ProjectRefTask.java
               antlib/src/test/org/apache/antlib/project/test
                        AntTaskTestCase.java ProjectRefTaskTestCase.java
                        ant.ant build.ant projectref-common.ant
                        projectref.ant
  Removed:     framework/src/java/org/apache/myrmidon/framework
                        SimpleTargetTask.java
               framework/src/java/org/apache/myrmidon/framework/project
                        AbstractTargetTask.java
               framework/src/test/org/apache/myrmidon/framework
                        TestCaseProjectBuilder.java
               container/src/java/org/apache/myrmidon/interfaces/model
                        ProjectRef.java
               container/src/test/org/apache/myrmidon/components/builder/test
                        bad-project-name.ant
               antlib/src/java/org/apache/antlib/project TargetTask.java
  Log:
  Changes to make project references part of the runtime state for a project,
  rather than part of the static project model:
  
  - Removed all the ProjectRef stuff from Project and DefaultProjectBuilder.
  
  - Added ProjectRefs interface, which tasks use to manage the set of references
    for the current project.  The workspace provides the implementation.
    Changed the tasks that were using the Project object to use this interface.
  
  - Added a <projectref> task, which replaces the <projectref> declarations.
  
  - Moved ProjectRef to interfaces.workspace package.
  
  - Moved all validation of project and target names to DefaultWorkspace, and
    added checking for duplicate target and project ref names.
  
  - Workspace adds a self reference to the current project, using the name
    of the project.
  
  - Squished together AbstractTargetTask, SimpleTargetTask, and TargetTask
    into a single TargetTask that lives in framework.  Removed <simple-target>.
  
  - Added unit tests for <ant>, <projectref>, and <target> tasks.
  
  Revision  Changes    Path
  1.3       +3 -51     jakarta-ant-myrmidon/ant1compat/src/java/org/apache/tools/ant/Ant1CompatTargetTask.java
  
  Index: Ant1CompatTargetTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/ant1compat/src/java/org/apache/tools/ant/Ant1CompatTargetTask.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Ant1CompatTargetTask.java	11 Jun 2002 13:20:14 -0000	1.2
  +++ Ant1CompatTargetTask.java	27 Jun 2002 11:13:07 -0000	1.3
  @@ -7,9 +7,8 @@
    */
   package org.apache.tools.ant;
   
  -import org.apache.myrmidon.framework.project.AbstractTargetTask;
   import org.apache.myrmidon.api.TaskException;
  -import org.apache.myrmidon.api.metadata.ModelElement;
  +import org.apache.myrmidon.framework.project.TargetTask;
   
   /**
    * An Ant1 compatible version of &gt;target/&lt;, which allows
  @@ -17,59 +16,14 @@
    *
    * @author <a href="mailto:darrell@apache.org">Darrell DeBoer</a>
    * @version $Revision$ $Date$
  - *
  - * @todo Extract AbstractTargetTask from TargetTask and move to framework,
  - *       so we can remove dependency between Ant1Compat and Project antlib.
    */
   public class Ant1CompatTargetTask
  -    extends AbstractTargetTask
  +    extends TargetTask
   {
       private String m_ifCondition;
       private String m_unlessCondition;
   
       /**
  -     * Specify the name of target.
  -     *
  -     * @param name the name of the target
  -     * @see #m_name
  -     */
  -    public void setName( final String name )
  -    {
  -        m_name = name;
  -    }
  -
  -    /**
  -     * Specify the list of dependencies for target.
  -     *
  -     * @param depends the list of dependencies for target
  -     * @see #m_dependencies
  -     */
  -    public void setDepends( final String depends )
  -        throws TaskException
  -    {
  -        buildDependsList( depends );
  -    }
  -
  -    /**
  -     * Sets the description of the target.
  -     */
  -    public void setDescription( final String desc )
  -    {
  -        // Ignore
  -    }
  -
  -    /**
  -     * Add a task to the target.
  -     *
  -     * @param task a model representing a task
  -     * @see #m_tasks
  -     */
  -    public void add( final ModelElement task )
  -    {
  -        m_tasks.add( task );
  -    }
  -
  -    /**
        * Add an if condition
        * @param ifCondition the name of a property which must be set
        *                    in order for the target to be executed.
  @@ -89,7 +43,6 @@
           m_unlessCondition = unlessCondition;
       }
   
  -
       /**
        * Checks that the "if" property has been set, and that the "unless"
        * property has not been set before executing the contained tasks.
  @@ -117,5 +70,4 @@
           }
           super.executeContainedTasks();
       }
  -
   }
  
  
  
  1.3       +5 -11     jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/project/AbstractWorkspaceTask.java
  
  Index: AbstractWorkspaceTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/project/AbstractWorkspaceTask.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractWorkspaceTask.java	25 Jun 2002 14:45:55 -0000	1.2
  +++ AbstractWorkspaceTask.java	27 Jun 2002 11:13:07 -0000	1.3
  @@ -11,11 +11,10 @@
   import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.framework.AbstractContainerTask;
  -import org.apache.myrmidon.framework.project.Dependency;
  +import org.apache.myrmidon.interfaces.workspace.ProjectRef;
  +import org.apache.myrmidon.interfaces.workspace.ProjectRefs;
   import org.apache.myrmidon.interfaces.workspace.ProjectDescriptor;
   import org.apache.myrmidon.interfaces.workspace.Workspace;
  -import org.apache.myrmidon.interfaces.model.Project;
  -import org.apache.myrmidon.interfaces.model.ProjectRef;
   
   /**
    * An abstract class used to execute Ant files within same workspace.
  @@ -77,13 +76,8 @@
       protected ProjectDescriptor getProjectDescriptor( final String projectName )
           throws TaskException
       {
  -        final Project project = (Project)getContext().getProperty( Project.KEY );
  -        if( projectName == null )
  -        {
  -            return project.getProjectDescriptor();
  -        }
  -
  -        final ProjectRef projectRef = project.getProjectRef( projectName );
  +        final ProjectRefs projectRefs = (ProjectRefs)getContext().getProperty( ProjectRefs.KEY );
  +        final ProjectRef projectRef = projectRefs.getProjectRef( projectName );
           if( null == projectRef )
           {
               final String message =
  
  
  
  1.2       +1 -1      jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/project/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/project/Resources.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Resources.properties	11 Jun 2002 13:20:15 -0000	1.1
  +++ Resources.properties	27 Jun 2002 11:13:07 -0000	1.2
  @@ -5,4 +5,4 @@
   target.bad-dependency.error=Discovered empty dependency in target "{0}" at {1}.
   
   workspace.exec-depends.notice=Executing dependency: {0}
  -workspace.missing-ref.error=Unable to locate Project Reference "{0}" for dependency "{1}".
  \ No newline at end of file
  +workspace.missing-ref.error=Unable to locate project "{0}".
  \ No newline at end of file
  
  
  
  1.1                  jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/project/TargetTask.java
  
  Index: TargetTask.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.myrmidon.framework.project;
  
  import org.apache.myrmidon.api.TaskException;
  import org.apache.myrmidon.api.metadata.ModelElement;
  import org.apache.myrmidon.framework.project.Dependency;
  import org.apache.myrmidon.framework.project.AbstractWorkspaceTask;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import java.util.ArrayList;
  import java.util.StringTokenizer;
  import java.util.List;
  import java.util.Iterator;
  
  /**
   * An abstract base class for implementing &gt;target&lt; tasks.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @author <a href="mailto:darrell@apache.org">Darrell DeBoer</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/27 11:13:07 $
   *
   * @ant.task name="target"
   */
  public class TargetTask
      extends AbstractWorkspaceTask
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( TargetTask.class );
  
      /**
       * The name of the target.
       */
      private String m_name;
  
      /**
       * The array of ordered tasks which are contained
       * withing Target.
       */
      private final List m_tasks = new ArrayList();
  
      /**
       * The list of dependencies to execute before this target.
       */
      private final List m_dependencies = new ArrayList();
  
      /**
       * The name of target.
       *
       * @param name the name of the target
       * @see #m_name
       */
      public void setName( final String name )
      {
          m_name = name;
      }
  
      /**
       * The description of the target.
       */
      public void setDescription( final String desc )
      {
          // Ignore
      }
  
      /**
       * The list of dependencies for target.
       *
       * @param depends the list of dependencies for target
       * @see #m_dependencies
       */
      public void setDepends( final String depends )
          throws TaskException
      {
          buildDependsList( depends );
      }
  
      /**
       * Adds a nested task to execute.
       */
      public void add( final ModelElement taskModel )
      {
          m_tasks.add( taskModel );
      }
  
      public void execute()
          throws TaskException
      {
          validate();
  
          executeDependencies();
  
          final String message =
              REZ.getString( "target.exec.notice", m_name );
          getContext().verbose( message );
  
          executeContainedTasks();
      }
  
      /**
       * Make sure that the name is not null.
       *
       * @throws TaskException if name has not been set.
       */
      protected void validate()
          throws TaskException
      {
          if( null == m_name )
          {
              final String message =
                  REZ.getString( "target.no-name.error" );
              throw new TaskException( message );
          }
      }
  
      /**
       * Execute depencies of target (if any).
       *
       * @throws TaskException if theres an eror executing dependencies.
       */
      protected void executeDependencies()
          throws TaskException
      {
          Iterator iter = m_dependencies.iterator();
          while( iter.hasNext() )
          {
              Dependency dependency = (Dependency)iter.next();
              executeDependency( dependency );
          }
      }
  
      /**
       * Execute all the tasks contained within target.
       *
       * @throws TaskException if theres an eror executing contained tasks.
       */
      protected void executeContainedTasks()
          throws TaskException
      {
          final ModelElement[] tasks =
              (ModelElement[])m_tasks.toArray( new ModelElement[ m_tasks.size() ] );
  
          for( int i = 0; i < tasks.length; i++ )
          {
              final ModelElement task = tasks[ i ];
  
              final String message =
                  REZ.getString( "target.task-exec.notice",
                                 task.getName() );
              getContext().debug( message );
              executeTask( task );
          }
      }
  
      public String toString()
      {
          return "Target['" + m_name + "]";
      }
  
      /**
       * Utility method to parse a list of dependencies from depends
       * string, adding them to the Dependencies list.
       *
       * @param depends a comma separated string of dependencies
       * @throws TaskException on error
       */
      private void buildDependsList( final String depends )
          throws TaskException
      {
          m_dependencies.clear();
  
          //apply depends attribute
          if( null == depends )
          {
              return;
          }
  
          final String[] elements = split( depends, "," );
  
          for( int i = 0; i < elements.length; i++ )
          {
              final String dependency = elements[ i ].trim();
  
              // Split project->target dependencies
              final int sep = dependency.indexOf( "->" );
              final String projectName;
              final String targetName;
              if( sep != -1 )
              {
                  projectName = dependency.substring( 0, sep );
                  targetName = dependency.substring( sep + 2 );
              }
              else
              {
                  projectName = null;
                  targetName = dependency;
              }
  
              if( targetName.length() == 0 ||
                  ( projectName != null && projectName.length() == 0 ) )
              {
                  final String message =
                      REZ.getString( "target.bad-dependency.error",
                                     getContext().getName(),
                                     getContext().getLocation() );
                  throw new TaskException( message );
              }
  
              m_dependencies.add( new Dependency( projectName, targetName ) );
          }
  
          final String message =
              REZ.getString( "target.depends.notice",
                             m_name,
                             m_dependencies );
          getContext().debug( message );
      }
  
      /**
       * Splits the string on every token into an array of strings.
       *
       * @param string the string
       * @param onToken the token
       * @return the resultant array
       */
      private String[] split( final String string, final String onToken )
      {
          final StringTokenizer tokenizer = new StringTokenizer( string, onToken );
          final String[] result = new String[ tokenizer.countTokens() ];
  
          for( int i = 0; i < result.length; i++ )
          {
              result[ i ] = tokenizer.nextToken();
          }
  
          return result;
      }
  }
  
  
  
  1.3       +2 -10     jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/AbstractTaskTestCase.java
  
  Index: AbstractTaskTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/AbstractTaskTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractTaskTestCase.java	13 Jun 2002 04:24:40 -0000	1.2
  +++ AbstractTaskTestCase.java	27 Jun 2002 11:13:07 -0000	1.3
  @@ -32,14 +32,6 @@
       }
   
       /**
  -     * Returns the project type to use when executing projects.
  -     */
  -    protected String getProjectType()
  -    {
  -        return "simple";
  -    }
  -
  -    /**
        * Executes a target in a project, and asserts that it fails.
        */
       protected void executeTargetExpectError( final File projectFile,
  @@ -175,7 +167,7 @@
   
               final String uri =
                   projectFile.getAbsoluteFile().toURL().toExternalForm();
  -            embeddor.setProjectDescriptor( new ProjectDescriptor( uri, getProjectType() ) );
  +            embeddor.setProjectDescriptor( new ProjectDescriptor( uri, null ) );
               if( props != null )
               {
                   for( Iterator iterator = props.entrySet().iterator(); iterator.hasNext(); )
  
  
  
  1.3       +4 -4      jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/expect-output.ant
  
  Index: expect-output.ant
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/expect-output.ant,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- expect-output.ant	25 Jun 2002 11:19:07 -0000	1.2
  +++ expect-output.ant	27 Jun 2002 11:13:07 -0000	1.3
  @@ -46,16 +46,16 @@
       <target name="nested">
           <expect-output>
               <out>
  -                <simple-target>
  +                <target>
                       <unit-test-log>log message 1</unit-test-log>
                       <unit-test-log>log message 2</unit-test-log>
  -                </simple-target>
  +                </target>
               </out>
               <tasks>
  -                <simple-target name="this is shonky">
  +                <target name="this is shonky">
                       <unit-test-log>log message 1</unit-test-log>
                       <unit-test-log>log message 2</unit-test-log>
  -                </simple-target>
  +                </target>
               </tasks>
           </expect-output>
       </target>
  
  
  
  1.1                  jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/project/test/TargetTaskTestCase.java
  
  Index: TargetTaskTestCase.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.myrmidon.framework.project.test;
  
  import org.apache.myrmidon.framework.AbstractTaskTestCase;
  import java.io.File;
  
  /**
   * Test cases for the <target> task.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/27 11:13:07 $
   */
  public class TargetTaskTestCase
      extends AbstractTaskTestCase
  {
      public TargetTaskTestCase( final String name )
      {
          super( name );
      }
  
      public void testExecution() throws Exception
      {
          final File projectFile = getTestResource( "target.ant" );
          executeTarget( projectFile, "execute-depend" );
          executeTarget( projectFile, "execute-depend-once" );
          executeTarget( projectFile, "depend-cycle" );
          executeTarget( projectFile, "unknown-depend" );
          executeTarget( projectFile, "no-name" );
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/project/test/target.ant
  
  Index: target.ant
  ===================================================================
  <project version="2.0">
      <target name="execute-depend" depends="target1">
          <assert><is-set property="target1"/></assert>
      </target>
  
      <target name="execute-depend-once" depends="target1, target2">
          <assert><is-set property="target1"/></assert>
          <assert><is-set property="target2"/></assert>
      </target>
  
      <target name="target1">
          <assert><not><is-set property="target1"/></not></assert>
          <string-prop name="target1" value="done"/>
      </target>
  
      <target name="target2" depends="target1">
          <assert><not><is-set property="target21"/></not></assert>
          <string-prop name="target2" value="done"/>
      </target>
  
      <target name="depend-cycle">
          <expect-error>
              <exc>Cycle in dependencies for target cycle2.</exc>
              <tasks>
                  <target name="cycle1" depends="cycle2"/>
              </tasks>
          </expect-error>
      </target>
  
      <target name="cycle2" depends="cycle3"/>
      <target name="cycle3" depends="cycle2"/>
  
      <target name="unknown-depend">
          <expect-error>
              <exc>No target named "no-such-target" in project "${myrmidon.project/projectDescriptor/uri}".</exc>
              <tasks>
                  <target name="unknown" depends="no-such-target"/>
              </tasks>
          </expect-error>
      </target>
  
      <target name="no-name">
          <expect-error>
              <exc>Target does not specify the name attribute.</exc>
              <tasks>
                  <target/>
              </tasks>
          </expect-error>
      </target>
  
  </project>
  
  
  1.83      +31 -169   jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/builder/DefaultProjectBuilder.java
  
  Index: DefaultProjectBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/builder/DefaultProjectBuilder.java,v
  retrieving revision 1.82
  retrieving revision 1.83
  diff -u -r1.82 -r1.83
  --- DefaultProjectBuilder.java	27 Jun 2002 05:13:34 -0000	1.82
  +++ DefaultProjectBuilder.java	27 Jun 2002 11:13:07 -0000	1.83
  @@ -8,7 +8,6 @@
   package org.apache.myrmidon.components.builder;
   
   import java.io.File;
  -import java.io.IOException;
   import java.net.MalformedURLException;
   import java.net.URL;
   import java.util.ArrayList;
  @@ -27,10 +26,7 @@
   import org.apache.myrmidon.interfaces.builder.ProjectException;
   import org.apache.myrmidon.interfaces.model.Project;
   import org.apache.myrmidon.interfaces.model.Target;
  -import org.apache.myrmidon.interfaces.property.NameValidator;
  -import org.apache.myrmidon.interfaces.property.NameValidatorManager;
   import org.apache.myrmidon.interfaces.workspace.ProjectDescriptor;
  -import org.apache.myrmidon.interfaces.model.ProjectRef;
   
   /**
    * Default implementation to construct project from a build file.
  @@ -52,12 +48,6 @@
       protected static final String VERSION_ATTRIBUTE = "version";
       private static final Version VERSION = new Version( 2, 0, 0 );
   
  -    private static final int PROJECT_REFERENCES = 0;
  -    private static final int IMPLICIT_TASKS = 1;
  -    private static final int TARGETS = 2;
  -
  -    // Use a name validator with the default rules.
  -    private NameValidator m_nameValidator;
       private ModelBuilder m_modelBuilder;
   
       /**
  @@ -68,16 +58,6 @@
           throws ServiceException
       {
           m_modelBuilder = (ModelBuilder)manager.lookup( ModelBuilder.ROLE );
  -        final NameValidatorManager validatorManager =
  -            (NameValidatorManager)manager.lookup( NameValidatorManager.ROLE );
  -        try
  -        {
  -            m_nameValidator = validatorManager.getValidator( NameValidatorManager.PROJECT_STYLE );
  -        }
  -        catch( final Exception e )
  -        {
  -            throw new ServiceException( e.getMessage(), e );
  -        }
       }
   
       /**
  @@ -85,7 +65,7 @@
        *
        * @param source the source to transform
        * @return the file object
  -     * @throws org.apache.myrmidon.interfaces.builder.ProjectException if malformed source
  +     * @throws ProjectException if malformed source
        */
       private File toFile( final String source )
           throws ProjectException
  @@ -113,7 +93,7 @@
        *
        * @param descriptor the project descriptor
        * @return the create Project object
  -     * @throws org.apache.myrmidon.interfaces.builder.ProjectException if error building project
  +     * @throws ProjectException if error building project
        */
       public Project build( final ProjectDescriptor descriptor )
           throws ProjectException
  @@ -121,13 +101,10 @@
           final File file = toFile( descriptor.getUri() );
           try
           {
  -            // Check for cached project
  +            // Build model for project
               final String systemID = extractURL( file );
               final ModelElement model =
                   getModelBuilder( systemID ).build( systemID );
  -
  -            // Tranform the resulting model
  -            transformProject( model );
               model.makeReadOnly();
   
               verifyTopLevelProject( model );
  @@ -141,26 +118,18 @@
   
               verifyVersion( version );
   
  -            final ArrayList projectRefList = new ArrayList();
               final ArrayList targetList = new ArrayList();
  -            buildTopLevelProject( baseDirectory, model, projectRefList, targetList );
  +            buildTopLevelProject( model, targetList );
   
  -            final ProjectRef[] projectRefs =
  -                (ProjectRef[])projectRefList.toArray( new ProjectRef[ projectRefList.size() ] );
               final Target[] targets =
                   (Target[])targetList.toArray( new Target[ targetList.size() ] );
   
  -            final Project project =
  -                new Project( projectName,
  -                                    description,
  -                                    descriptor,
  -                                    baseDirectory,
  -                                    defaultTarget,
  -                                    projectRefs,
  -                                    targets );
  -            setupLogger( project );
  -
  -            return project;
  +            return new Project( projectName,
  +                                description,
  +                                descriptor,
  +                                baseDirectory,
  +                                defaultTarget,
  +                                targets );
           }
           catch( Exception e )
           {
  @@ -182,14 +151,8 @@
       }
   
       /**
  -     * Transforms the project model.  This implementation does nothing.
  +     * Creates a Target from it's model.
        */
  -    protected void transformProject( final ModelElement model )
  -        throws Exception
  -    {
  -        // Do nothing
  -    }
  -
       protected Target createTarget( final ModelElement originalModel )
       {
           final ModelElement model = createTargetModel( originalModel );
  @@ -198,7 +161,9 @@
           return new Target( name, description, model );
       }
   
  -
  +    /**
  +     * Transforms the model for a target.  This implementation does nothing.
  +     */
       protected ModelElement createTargetModel( final ModelElement model )
       {
           return model;
  @@ -210,7 +175,7 @@
        * on version compliance.
        *
        * @param version the version to check
  -     * @throws org.apache.myrmidon.interfaces.builder.ProjectException if specified version is not compliant
  +     * @throws ProjectException if specified version is not compliant
        */
       private void verifyVersion( final Version version )
           throws ProjectException
  @@ -229,7 +194,7 @@
        * Verify "project" is the name of the top level element.
        *
        * @param model the model to check
  -     * @throws org.apache.myrmidon.interfaces.builder.ProjectException if top level element is not "project"
  +     * @throws ProjectException if top level element is not "project"
        */
       private void verifyTopLevelProject( final ModelElement model )
           throws ProjectException
  @@ -275,39 +240,14 @@
        */
       private String getProjectName( final ModelElement model,
                                      final File file )
  -        throws ProjectException
       {
           String projectName = model.getAttribute( "name" );
  -
           if( projectName == null )
           {
               // Create a name based on the file name.
  -            String fileNameBase = FileUtil.removeExtension( file.getName() );
  -            try
  -            {
  -                projectName = m_nameValidator.makeValidName( fileNameBase );
  -            }
  -            catch( Exception e )
  -            {
  -                String message = REZ.getString( "ant.project-create-name.error" );
  -                throw new ProjectException( message, e );
  -            }
  -        }
  -        else
  -        {
  -            // Make sure the supplied name is valid.
  -            try
  -            {
  -                m_nameValidator.validate( projectName );
  -            }
  -            catch( Exception e )
  -            {
  -                String message = REZ.getString( "ant.project-bad-name.error" );
  -                throw new ProjectException( message, e );
  -            }
  +            projectName = FileUtil.removeExtension( file.getName() );
           }
           return projectName;
  -
       }
   
       /**
  @@ -339,56 +279,29 @@
       /**
        * Handle all top level elements in a project model.
        *
  -     * @param baseDirectory the basedir of project
        * @param model the model
  -     * @throws org.apache.myrmidon.interfaces.builder.ProjectException if an error occurs
  +     * @throws ProjectException if an error occurs
        */
  -    private void buildTopLevelProject( final File baseDirectory,
  -                                       final ModelElement model,
  -                                       final List projectRefs,
  +    private void buildTopLevelProject( final ModelElement model,
                                          final List targets )
           throws Exception
       {
  -        final ModelElement implicit = new ModelElement( "simple-target", model.getLocation() );
  +        final ModelElement implicit = new ModelElement( "target", model.getLocation() );
           implicit.setAttribute( "name", Project.IMPLICIT_TARGET_NAME );
   
           final ModelElement[] children = model.getChildren();
   
  -        int state = PROJECT_REFERENCES;
  +        int pos = 0;
  +        for( ; pos < children.length && ! children[ pos ].getName().equals( "target" ); pos++ )
  +        {
  +            implicit.addChild( children[ pos ] );
  +        }
  +        targets.add( createTarget( implicit ) );
   
  -        for( int i = 0; i < children.length; i++ )
  +        for( ; pos < children.length; pos++ )
           {
  -            final ModelElement element = children[ i ];
  +            final ModelElement element = children[ pos ];
               final String name = element.getName();
  -
  -            if( PROJECT_REFERENCES == state )
  -            {
  -                if( name.equals( "projectref" ) )
  -                {
  -                    final ProjectRef ref = buildProjectRef( baseDirectory, element );
  -                    projectRefs.add( ref );
  -                    continue;
  -                }
  -                else
  -                {
  -                    state = IMPLICIT_TASKS;
  -                }
  -            }
  -
  -            if( IMPLICIT_TASKS == state )
  -            {
  -                //Check for any implicit tasks here
  -                if( !name.equals( "target" ) )
  -                {
  -                    implicit.addChild( element );
  -                    continue;
  -                }
  -                else
  -                {
  -                    state = TARGETS;
  -                }
  -            }
  -
               if( name.equals( "target" ) )
               {
                   targets.add( createTarget( element ) );
  @@ -396,62 +309,11 @@
               else
               {
                   final String message =
  -                    REZ.getString( "ant.unknown-toplevel-element.error", name,
  +                    REZ.getString( "ant.unknown-toplevel-element.error",
  +                                   name,
                                      element.getLocation() );
                   throw new ProjectException( message );
               }
  -        }
  -        targets.add( createTarget( implicit ) );
  -    }
  -
  -    private ProjectRef buildProjectRef( final File baseDirectory,
  -                                        final ModelElement element )
  -        throws ProjectException
  -    {
  -        final String name = element.getAttribute( "name" );
  -        final String location = element.getAttribute( "location" );
  -        final String type = element.getAttribute( "type" );
  -
  -        if( null == name )
  -        {
  -            final String message =
  -                REZ.getString( "ant.projectref-no-name.error",
  -                               element.getLocation() );
  -            throw new ProjectException( message );
  -        }
  -
  -        try
  -        {
  -            m_nameValidator.validate( name );
  -        }
  -        catch( Exception e )
  -        {
  -            final String message =
  -                REZ.getString( "ant.projectref-bad-name.error",
  -                               element.getLocation() );
  -            throw new ProjectException( message, e );
  -        }
  -
  -        if( null == location )
  -        {
  -            final String message =
  -                REZ.getString( "ant.projectref-no-location.error",
  -                               element.getLocation() );
  -            throw new ProjectException( message );
  -        }
  -
  -        // Build the URL of the referenced projects
  -        final File file = FileUtil.resolveFile( baseDirectory, location );
  -        try
  -        {
  -            final String uri = file.getCanonicalFile().toString();
  -            final ProjectDescriptor project =
  -                new ProjectDescriptor( uri, type );
  -            return new ProjectRef( name, project );
  -        }
  -        catch( final IOException ioe )
  -        {
  -            throw new ProjectException( ioe.getMessage(), ioe );
           }
       }
   
  
  
  
  1.17      +0 -13     jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/builder/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/builder/Resources.properties,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- Resources.properties	25 Jun 2002 11:16:47 -0000	1.16
  +++ Resources.properties	27 Jun 2002 11:13:07 -0000	1.17
  @@ -13,11 +13,6 @@
   ant.project-build.error=Could not load project from "{0}".
   ant.no-project-element.error=Project file must be enclosed in project element.
   ant.unknown-toplevel-element.error=Unknown top-level element {0} at {1}.
  -ant.project-bad-name.error=Invalid project name.
  -ant.project-create-name.error=Could not create a name for this project.
  -ant.projectref-no-name.error=Malformed projectref without a name attribute at {0}.
  -ant.projectref-bad-name.error=Projectref with an invalid name attribute at {0}.
  -ant.projectref-no-location.error=Malformed projectref without a location attribute at {0}.
   ant.malformed.version=Project has an invalid version "{0}".
   ant.version-missing.error=Project has no version attribute.
   ant.bad-version.error=Incompatible build file version detected. Expected version {0} but found version {1}.
  @@ -26,15 +21,7 @@
   ant.project-convert.notice=Applying compatibility stylesheet to project file.
   ant.project-convert.error=Error converting build file.
   
  -duplicate-project.error=Can not have two projects referenced in a file with the name {0}.
  -duplicate-target.error=Can not have two targets in a file with the name {0}.
  -
   saxhandler.mixedmodel.error={0}: Cannot mix nested elements and text content.
  -
  -project.unknown-ref.error=Unknown project reference "{0}".
  -project.nobuild-project.error=Could not load referenced project "{0}" with type "{1}".
  -project.unknown-target.error=Unknown target "{0}".
  -project.missing-ref.error=Unable to locate project reference "{0}".
   
   builder.create.error=Error creating Project of type "{0}" at "{1}".
   builder.destroy.error=Error destroying builder of type "{0}".
  
  
  
  1.3       +5 -1      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/property/XPathPropertyResolver.java
  
  Index: XPathPropertyResolver.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/property/XPathPropertyResolver.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XPathPropertyResolver.java	27 Jun 2002 05:13:34 -0000	1.2
  +++ XPathPropertyResolver.java	27 Jun 2002 11:13:08 -0000	1.3
  @@ -38,6 +38,10 @@
        * @param expression the expression to evaluate
        * @param context the set of known properties
        * @return the object retrieved from context
  +     *
  +     * @todo - If more than one value, return a List or Map of them.
  +     * @todo - For some reason DOM nodes get converted to String.  Need to
  +     *         fix this so that the Node object is returned.
        */
       protected Object evaluateExpression( final String expression,
                                            final TaskContext context )
  
  
  
  1.102     +20 -19    jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java
  
  Index: DefaultWorkspace.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java,v
  retrieving revision 1.101
  retrieving revision 1.102
  diff -u -r1.101 -r1.102
  --- DefaultWorkspace.java	25 Jun 2002 14:45:55 -0000	1.101
  +++ DefaultWorkspace.java	27 Jun 2002 11:13:08 -0000	1.102
  @@ -9,7 +9,6 @@
   
   import java.util.HashMap;
   import java.util.Map;
  -import java.util.Iterator;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  @@ -20,7 +19,7 @@
   import org.apache.myrmidon.interfaces.executor.ExecutionFrame;
   import org.apache.myrmidon.interfaces.executor.Executor;
   import org.apache.myrmidon.interfaces.model.Project;
  -import org.apache.myrmidon.interfaces.model.ProjectRef;
  +import org.apache.myrmidon.interfaces.workspace.ProjectRefs;
   import org.apache.myrmidon.interfaces.model.Target;
   import org.apache.myrmidon.interfaces.property.PropertyStore;
   import org.apache.myrmidon.interfaces.workspace.ProjectDescriptor;
  @@ -62,33 +61,32 @@
           throws TaskException
       {
           final ProjectEntry entry = getProjectEntry( descriptor );
  -        final Project project = entry.getProject();
   
           // First execute the implicit target.
           executeTarget( entry, Project.IMPLICIT_TARGET_NAME );
   
           // Now execute the called target.
  -        executeTarget( entry, getTargetName( project, targetName ) );
  +        executeTarget( entry, getTargetName( entry.getProject(), targetName ) );
       }
   
       /**
        * Retrieve target with specified name from project.
        * If no such target exists then throw a TaskException.
        *
  -     * @param project the project
  +     * @param entry the project
        * @param targetName the name of Target to retrieve
        * @return the Target object
        * @throws TaskException if unable to locate target
        */
  -    private Target getTarget( final Project project, final String targetName )
  +    private Target getTarget( final ProjectEntry entry, final String targetName )
           throws TaskException
       {
  -        final Target target = project.getTarget( targetName );
  +        final Target target = entry.getTarget( targetName );
           if( null == target )
           {
               final String message =
                   REZ.getString( "workspace.missing-target.error",
  -                               project.getProjectDescriptor().getUri(),
  +                               entry.getProject().getProjectDescriptor().getUri(),
                                  targetName );
               throw new TaskException( message );
           }
  @@ -108,8 +106,7 @@
                                   final String targetName )
           throws TaskException
       {
  -        final Project project = entry.getProject();
  -        final Target target = getTarget( project, targetName );
  +        final Target target = getTarget( entry, targetName );
           executeTarget( entry, target );
       }
   
  @@ -136,13 +133,8 @@
           try
           {
               final ExecutionFrame childFrame =
  -                frame.createPartition( project.getProjectName(), project.getBaseDirectory() );
  +                frame.createPartition( project.getName(), project.getBaseDirectory() );
               frame.registerService( Workspace.ROLE, this );
  -
  -            final PropertyStore propertyStore =
  -                (PropertyStore)childFrame.lookup( PropertyStore.ROLE );
  -            propertyStore.setProperty( Project.KEY, project );
  -
               return childFrame;
           }
           catch( final Exception e )
  @@ -205,12 +197,21 @@
        * @return the new ProjectEntry
        * @throws TaskException if unable to create entry
        */
  -    private ProjectEntry createProjectEntry( final Project project, final ExecutionFrame frame )
  +    private ProjectEntry createProjectEntry( final Project project,
  +                                             final ExecutionFrame frame )
           throws TaskException
       {
           final ExecutionFrame projectFrame =
               createExecutionFrame( project, frame );
  -        return new ProjectEntry( project, projectFrame );
  +        final ProjectEntry entry = new ProjectEntry( project, projectFrame );
  +
  +        // Set the project entry as a property, so that tasks can get at it
  +        final PropertyStore propertyStore =
  +            (PropertyStore)projectFrame.lookup( PropertyStore.ROLE );
  +        propertyStore.setProperty( Project.KEY, project );
  +        propertyStore.setProperty( ProjectRefs.KEY, entry );
  +
  +        return entry;
       }
   
       /**
  
  
  
  1.15      +158 -4    jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace/ProjectEntry.java
  
  Index: ProjectEntry.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace/ProjectEntry.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ProjectEntry.java	20 Jun 2002 07:06:31 -0000	1.14
  +++ ProjectEntry.java	27 Jun 2002 11:13:08 -0000	1.15
  @@ -9,9 +9,17 @@
   
   import java.util.HashMap;
   import java.util.Map;
  +import java.util.Iterator;
   import org.apache.myrmidon.interfaces.executor.ExecutionFrame;
   import org.apache.myrmidon.interfaces.model.Project;
   import org.apache.myrmidon.interfaces.model.Target;
  +import org.apache.myrmidon.interfaces.workspace.ProjectRef;
  +import org.apache.myrmidon.interfaces.workspace.ProjectRefs;
  +import org.apache.myrmidon.interfaces.property.NameValidatorManager;
  +import org.apache.myrmidon.interfaces.property.NameValidator;
  +import org.apache.myrmidon.api.TaskException;
  +import org.apache.avalon.excalibur.i18n.ResourceManager;
  +import org.apache.avalon.excalibur.i18n.Resources;
   
   /**
    * This contains details for each project that is being executed by a
  @@ -20,21 +28,70 @@
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    * @version $Revision$ $Date$
    */
  -final class ProjectEntry
  +public class ProjectEntry
  +    implements ProjectRefs
   {
  +    private static final Resources REZ =
  +        ResourceManager.getPackageResources( ProjectEntry.class );
  +
       final static String KEY = ProjectEntry.class.getName();
   
  -    private final Project m_project;
       private final ExecutionFrame m_frame;
  +    private final Project m_project;
  +    private final NameValidator m_projectValidator;
  +    private final NameValidator m_targetValidator;
   
       /** Map from Target -> TargetState for that target. */
       private final Map m_targetState = new HashMap();
   
  +    /** Map from target name -> Target. */
  +    private final Map m_targets = new HashMap();
  +
  +    /** Map from project ref name -> ProjectRef. */
  +    private final Map m_projectRefs = new HashMap();
  +
  +    /** Self reference to the project. */
  +    private final ProjectRef m_selfRef;
  +
       public ProjectEntry( final Project project,
  -                         final ExecutionFrame frame )
  +                         final ExecutionFrame frame ) throws TaskException
       {
           m_project = project;
           m_frame = frame;
  +
  +        // Lookup the name validators
  +        try
  +        {
  +            final NameValidatorManager validatorManager = (NameValidatorManager)frame.lookup( NameValidatorManager.ROLE );
  +            m_projectValidator = validatorManager.getValidator( NameValidatorManager.PROJECT_STYLE );
  +            m_targetValidator = validatorManager.getValidator( NameValidatorManager.TARGET_STYLE );
  +        }
  +        catch( final Exception e )
  +        {
  +            throw new TaskException( e.getMessage(), e );
  +        }
  +
  +        // Validate project name
  +        try
  +        {
  +            m_projectValidator.validate( project.getName() );
  +        }
  +        catch( final Exception e )
  +        {
  +            final String message = REZ.getString( "invalid-project-name.error", project.getName() );
  +            throw new TaskException( message, e );
  +        }
  +
  +        // Add the targets.  This validates them
  +        for( Iterator iterator = project.getTargets().values().iterator(); iterator.hasNext(); )
  +        {
  +            final Target target = (Target)iterator.next();
  +            addTarget( target );
  +        }
  +
  +        // Add a reference to self
  +        m_selfRef = new ProjectRef( project.getName(), project.getProjectDescriptor() );
  +        addProjectRef( m_selfRef );
       }
   
       public Project getProject()
  @@ -42,6 +99,98 @@
           return m_project;
       }
   
  +    /**
  +     * Returns a read-only map of all the {@link org.apache.myrmidon.interfaces.workspace.ProjectRef} objects in project.
  +     *
  +     * @return A map from project reference name to {@link org.apache.myrmidon.interfaces.workspace.ProjectRef}.
  +     */
  +    public Map getProjectRefs()
  +    {
  +        return m_projectRefs;
  +    }
  +
  +    /**
  +     * Retrieve a project ref by name.
  +     */
  +    public ProjectRef getProjectRef( final String name )
  +    {
  +        if( name == null )
  +        {
  +            return m_selfRef;
  +        }
  +        return (ProjectRef)m_projectRefs.get( name );
  +    }
  +
  +    /**
  +     * Adds a project reference to this project.
  +     */
  +    public void addProjectRef( final ProjectRef ref )
  +        throws TaskException
  +    {
  +        // Validate reference
  +        final String name = ref.getName();
  +        if( name == null )
  +        {
  +            final String message = REZ.getString( "no-projectref-name.error" );
  +            throw new TaskException( message );
  +        }
  +        try
  +        {
  +            m_projectValidator.validate( name );
  +        }
  +        catch( final Exception e )
  +        {
  +            final String message = REZ.getString( "bad-projectref-name.error", name );
  +            throw new TaskException( message, e );
  +        }
  +        if( m_projectRefs.containsKey( name ) )
  +        {
  +            final String message = REZ.getString( "duplicate-projectrefs.error", name );
  +            throw new TaskException( message );
  +        }
  +        if( ref.getProject().getUri() == null )
  +        {
  +            final String message = REZ.getString( "no-projectref-location.error", name );
  +            throw new TaskException( message );
  +        }
  +
  +        m_projectRefs.put( ref.getName(), ref );
  +    }
  +
  +    /**
  +     * Adds a target to this project.
  +     */
  +    public void addTarget( final Target target )
  +        throws TaskException
  +    {
  +        // Validate target
  +        final String name = target.getName();
  +        if( name == null )
  +        {
  +            final String message = REZ.getString( "no-target-name.error" );
  +            throw new TaskException( message );
  +        }
  +        if( ! name.equals( Project.IMPLICIT_TARGET_NAME ) )
  +        {
  +            try
  +            {
  +                m_targetValidator.validate( name );
  +            }
  +            catch( final Exception e )
  +            {
  +                final String message = REZ.getString( "bad-target-name.error", name );
  +                throw new TaskException( message, e );
  +            }
  +        }
  +        if( m_targets.containsKey( name ) )
  +        {
  +            final String message = REZ.getString( "duplicate-targets.error", name );
  +            throw new TaskException( message );
  +        }
  +
  +        m_targets.put( target.getName(), target );
  +    }
  +
       public ExecutionFrame getFrame()
       {
           return m_frame;
  @@ -60,5 +209,10 @@
       public void setTargetState( final Target target, final TargetState state )
       {
           m_targetState.put( target, state );
  +    }
  +
  +    public Target getTarget( final String targetName )
  +    {
  +        return (Target)m_targets.get( targetName );
       }
   }
  
  
  
  1.18      +8 -0      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace/Resources.properties,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- Resources.properties	25 Jun 2002 11:22:42 -0000	1.17
  +++ Resources.properties	27 Jun 2002 11:13:08 -0000	1.18
  @@ -8,6 +8,14 @@
   target-dependency-cycle.error=Cycle in dependencies for target {0}.
   workspace.missing-target.error=No target named "{1}" in project "{0}".
   
  +invalid-project-name.error=Invalid project name "{0}".
  +no-projectref-name.error=No name specified for project reference.
  +duplicate-projectrefs.error=Multiple project references with name "{0}".
  +bad-projectref-name.error=Invalid project reference name "{0}".
  +no-projectref-location.error=No project location specified for project reference.
  +no-target-name.error=No target name.
  +bad-target-name.error=Invalid target name "{0}".
  +
   #DefaultTaskContext
   unknown-prop.error=Unknown property {0}.
   bad-property.error=Property {0} must have a value of type {1}.
  
  
  
  1.14      +12 -44    jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/model/Project.java
  
  Index: Project.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/model/Project.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Project.java	25 Jun 2002 14:45:55 -0000	1.13
  +++ Project.java	27 Jun 2002 11:13:08 -0000	1.14
  @@ -10,6 +10,7 @@
   import java.io.File;
   import java.util.Map;
   import java.util.HashMap;
  +import java.util.Collections;
   import org.apache.myrmidon.interfaces.workspace.ProjectDescriptor;
   
   /**
  @@ -41,11 +42,6 @@
       private final ProjectDescriptor m_descriptor;
   
       /**
  -     * The set of projectRefs that this Project uses.
  -     */
  -    private final Map m_projectRefs;
  -
  -    /**
        * The set of targets for this project.
        */
       private final Map m_targets;
  @@ -58,7 +54,6 @@
                       final ProjectDescriptor descriptor,
                       final File baseDirectory,
                       final String defaultTarget,
  -                    final ProjectRef[] projectRefs,
                       final Target[] targets )
       {
           super( name, description );
  @@ -80,34 +75,25 @@
           {
               throw new NullPointerException( "baseDirectory" );
           }
  -        if( null == projectRefs )
  -        {
  -            throw new NullPointerException( "projectRefs" );
  -        }
  -        if( null == targets )
  -        {
  -            throw new NullPointerException( "targets" );
  -        }
   
           m_descriptor = descriptor;
           m_baseDirectory = baseDirectory;
           m_defaultTarget = defaultTarget;
   
  -        final HashMap refMap = new HashMap();
  -        for( int i = 0; i < projectRefs.length; i++ )
  +        if( targets != null && targets.length > 0 )
           {
  -            final ProjectRef projectRef = projectRefs[ i ];
  -            refMap.put( projectRef.getName(), projectRef );
  +            final HashMap targetMap = new HashMap();
  +            for( int i = 0; i < targets.length; i++ )
  +            {
  +                final Target target = targets[ i ];
  +                targetMap.put( target.getName(), target );
  +            }
  +            m_targets = targetMap;
           }
  -        m_projectRefs = refMap;
  -
  -        final HashMap targetMap = new HashMap();
  -        for( int i = 0; i < targets.length; i++ )
  +        else
           {
  -            final Target target = targets[ i ];
  -            targetMap.put( target.getName(), target );
  +            m_targets = Collections.EMPTY_MAP;
           }
  -        m_targets = targetMap;
       }
   
       /**
  @@ -148,24 +134,6 @@
       public String getDefaultTargetName()
       {
           return m_defaultTarget;
  -    }
  -
  -    /**
  -     * Returns a read-only map of all the {@link ProjectRef} objects in project.
  -     *
  -     * @return A map from project reference name to {@link ProjectRef}.
  -     */
  -    public Map getProjectRefs()
  -    {
  -        return m_projectRefs;
  -    }
  -
  -    /**
  -     * Retrieve a project ref by name.
  -     */
  -    public ProjectRef getProjectRef( final String name )
  -    {
  -        return (ProjectRef)m_projectRefs.get( name );
       }
   
       /**
  
  
  
  1.3       +1 -1      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/workspace/ProjectRef.java
  
  
  
  
  1.1                  jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/workspace/ProjectRefs.java
  
  Index: ProjectRefs.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.myrmidon.interfaces.workspace;
  
  import java.util.Map;
  import org.apache.myrmidon.api.TaskException;
  
  /**
   * This interface is used by tasks to manage the set of project references
   * for the current project.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/27 11:13:08 $
   */
  public interface ProjectRefs
  {
      String KEY = "myrmidon.projectrefs";
  
      /**
       * Returns a read-only map of all the {@link org.apache.myrmidon.interfaces.workspace.ProjectRef} objects in project.
       *
       * @return A map from project reference name to {@link org.apache.myrmidon.interfaces.workspace.ProjectRef}.
       */
      Map getProjectRefs();
  
      /**
       * Retrieve a project ref by name.
       *
       * @param name The name of the project to get.  Use null for a reference to
       * the current project.
       */
      ProjectRef getProjectRef( final String name );
  
      /**
       * Adds a project ref to the current project.
       */
      void addProjectRef( final ProjectRef ref ) throws TaskException;
  }
  
  
  
  1.25      +5 -41     jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/builder/test/DefaultProjectBuilderTestCase.java
  
  Index: DefaultProjectBuilderTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/builder/test/DefaultProjectBuilderTestCase.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- DefaultProjectBuilderTestCase.java	13 Jun 2002 02:59:26 -0000	1.24
  +++ DefaultProjectBuilderTestCase.java	27 Jun 2002 11:13:08 -0000	1.25
  @@ -16,7 +16,6 @@
   import org.apache.avalon.framework.container.ContainerUtil;
   import org.apache.myrmidon.api.metadata.ModelElement;
   import org.apache.myrmidon.components.AbstractComponentTest;
  -import org.apache.myrmidon.interfaces.model.Project;
   import org.apache.myrmidon.components.builder.DefaultProjectBuilder;
   import org.apache.myrmidon.components.embeddor.DefaultEmbeddor;
   import org.apache.myrmidon.interfaces.builder.ProjectBuilder;
  @@ -25,7 +24,6 @@
   import org.apache.myrmidon.interfaces.model.Project;
   import org.apache.myrmidon.interfaces.model.Target;
   import org.apache.myrmidon.interfaces.workspace.ProjectDescriptor;
  -import org.apache.myrmidon.interfaces.model.ProjectRef;
   
   /**
    * Test cases for {@link DefaultProjectBuilder}.
  @@ -142,8 +140,7 @@
                                   new ProjectDescriptor( uri ),
                                   getTestDirectory(),
                                   "main",
  -                                new ProjectRef[ 0 ],
  -                                createDummyTargets() );
  +                         createDummyTargets() );
   
           assertSameProject( expected, project );
       }
  @@ -193,8 +190,7 @@
                                   new ProjectDescriptor( uri ),
                                   getTestDirectory(),
                                   "main",
  -                                new ProjectRef[ 0 ],
  -                                createDummyTargets() );
  +                         createDummyTargets() );
           assertSameProject( expected, project );
       }
   
  @@ -227,8 +223,7 @@
                                   new ProjectDescriptor( uri ),
                                   baseDir,
                                   "main",
  -                                new ProjectRef[ 0 ],
  -                                createDummyTargets() );
  +                         createDummyTargets() );
           assertSameProject( expected, project );
       }
   
  @@ -255,8 +250,7 @@
                                   new ProjectDescriptor( uri ),
                                   getTestDirectory(),
                                   "some-target",
  -                                new ProjectRef[ 0 ],
  -                                targets );
  +                         targets );
           assertSameProject( expected, project );
       }
   
  @@ -327,35 +321,5 @@
           assertEquals( expected.getProjectName(), project.getProjectName() );
           assertEquals( expected.getBaseDirectory(), project.getBaseDirectory() );
           assertEquals( expected.getDefaultTargetName(), project.getDefaultTargetName() );
  -    }
  -
  -    private void assertSameTarget( final Target expected,
  -                                   final Target actual )
  -    {
  -        assertEquals( expected.getName(), actual.getName() );
  -        assertEquals( expected.getDescription(), actual.getDescription() );
  -    }
  -
  -    /**
  -     * Tests validation of project and target names.
  -     */
  -    public void testNameValidation() throws Exception
  -    {
  -        // Check bad project name
  -        final File badProjectFile = getTestResource( "bad-project-name.ant" );
  -        try
  -        {
  -            build( badProjectFile );
  -            fail();
  -        }
  -        catch( Exception e )
  -        {
  -            final String[] messages =
  -                {
  -                    REZ.getString( "ant.project-build.error", badProjectFile.getAbsolutePath() ),
  -                    REZ.getString( "ant.project-bad-name.error" )
  -                };
  -            assertSameMessage( messages, e );
  -        }
       }
   }
  
  
  
  1.3       +2 -2      jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/DependsTask.java
  
  Index: DependsTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/DependsTask.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DependsTask.java	11 Jun 2002 13:20:15 -0000	1.2
  +++ DependsTask.java	27 Jun 2002 11:13:08 -0000	1.3
  @@ -14,7 +14,7 @@
   import org.apache.myrmidon.framework.project.AbstractWorkspaceTask;
   
   /**
  - * A simple task to task to execute a group of tasks.
  + * Executes a target, if that target has not already been executed.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    * @version $Revision$ $Date$
  
  
  
  1.15      +4 -3      jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/Resources.properties,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Resources.properties	25 Jun 2002 11:15:56 -0000	1.14
  +++ Resources.properties	27 Jun 2002 11:13:08 -0000	1.15
  @@ -1,5 +1,3 @@
  -target.bad-name.error=Target "{0}" has a invalid name.
  -
   depends.no-target.error=No target specified in <depends/> task.
   
   param.noname.error=Missing name from parameter.
  @@ -8,4 +6,7 @@
   
   project.no-project-element.error=Project file must be enclosed in project element.
   
  -antcall.missing-ref.error=Unknown project reference "{0}".
  \ No newline at end of file
  +antcall.missing-ref.error=Unknown project reference "{0}".
  +
  +projectref.no-name.error=No project name specified.
  +projectref.no-location.error=No project location specified.
  \ No newline at end of file
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/ProjectRefTask.java
  
  Index: ProjectRefTask.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.antlib.project;
  
  import java.io.File;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.myrmidon.api.AbstractTask;
  import org.apache.myrmidon.api.TaskException;
  import org.apache.myrmidon.interfaces.workspace.ProjectRef;
  import org.apache.myrmidon.interfaces.workspace.ProjectRefs;
  import org.apache.myrmidon.interfaces.workspace.ProjectDescriptor;
  
  /**
   * A task that adds a project reference to the current project.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/27 11:13:08 $
   *
   * @ant.task name="projectref"
   */
  public class ProjectRefTask
      extends AbstractTask
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( ProjectRefTask.class );
  
      private String m_name;
      private File m_location;
      private String m_type;
  
      /**
       * The name to use to reference the project.
       */
      public void setName( final String name )
      {
          m_name = name;
      }
  
      /**
       * The project file.
       */
      public void setLocation( final File location )
      {
          m_location = location;
      }
  
      /**
       * The project type.
       */
      public void setType( final String type )
      {
          m_type = type;
      }
  
      /**
       * Executes the task.
       */
      public void execute()
          throws TaskException
      {
          if( m_name == null )
          {
              final String message = REZ.getString( "projectref.no-name.error" );
              throw new TaskException( message );
          }
          if( m_location == null )
          {
              final String message = REZ.getString( "projectref.no-location.error" );
              throw new TaskException( message );
          }
  
          final String uri = m_location.getAbsolutePath();
          final ProjectDescriptor descriptor = new ProjectDescriptor( uri, m_type );
          final ProjectRef ref = new ProjectRef( m_name, descriptor );
  
          final ProjectRefs projectRefs = (ProjectRefs)getContext().getProperty( ProjectRefs.KEY );
          projectRefs.addProjectRef( ref );
      }
  }
  
  
  
  1.11      +1 -9      jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/AbstractProjectTestCase.java
  
  Index: AbstractProjectTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/AbstractProjectTestCase.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- AbstractProjectTestCase.java	6 Jun 2002 10:57:03 -0000	1.10
  +++ AbstractProjectTestCase.java	27 Jun 2002 11:13:08 -0000	1.11
  @@ -22,12 +22,4 @@
       {
           super( name );
       }
  -
  -    /**
  -     * Returns the project type to use when executing projects.
  -     */
  -    protected String getProjectType()
  -    {
  -        return null;
  -    }
   }
  
  
  
  1.3       +2 -2      jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/project/test/ant-call.ant
  
  Index: ant-call.ant
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/project/test/ant-call.ant,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ant-call.ant	25 Jun 2002 14:45:54 -0000	1.2
  +++ ant-call.ant	27 Jun 2002 11:13:08 -0000	1.3
  @@ -80,8 +80,8 @@
       <!-- Call an unknown target in a referenced project -->
       <target name="ref-unknown-target">
           <expect-error>
  -            <exc>Execution of target "no-such-target" in project "${myrmidon.project/projectRefs/common/project/uri}" failed.</exc>
  -            <exc>No target named "no-such-target" in project "${myrmidon.project/projectRefs/common/project/uri}".</exc>
  +            <exc>Execution of target "no-such-target" in project "${myrmidon.projectrefs/projectRefs/common/project/uri}" failed.</exc>
  +            <exc>No target named "no-such-target" in project "${myrmidon.projectrefs/projectRefs/common/project/uri}".</exc>
               <tasks>
                   <ant-call project="common" target="no-such-target"/>
               </tasks>
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/project/test/AntTaskTestCase.java
  
  Index: AntTaskTestCase.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.antlib.project.test;
  
  import org.apache.antlib.AbstractProjectTestCase;
  import java.io.File;
  
  /**
   * Test cases for the <ant> task.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/27 11:13:08 $
   */
  public class AntTaskTestCase
      extends AbstractProjectTestCase
  {
      public AntTaskTestCase( final String name )
      {
          super( name );
      }
  
      public void testExecution() throws Exception
      {
          final File projectFile = getTestResource( "ant.ant" );
          executeTarget( projectFile, "default-project" );
          executeTarget( projectFile, "default-target" );
          executeTarget( projectFile, "call-target" );
          executeTarget( projectFile, "unknown-target" );
          executeTarget( projectFile, "unknown-file" );
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/project/test/ProjectRefTaskTestCase.java
  
  Index: ProjectRefTaskTestCase.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.antlib.project.test;
  
  import org.apache.antlib.AbstractProjectTestCase;
  import java.io.File;
  
  /**
   * Test cases for the <projectref> task.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/27 11:13:08 $
   */
  public class ProjectRefTaskTestCase
      extends AbstractProjectTestCase
  {
      public ProjectRefTaskTestCase( final String name )
      {
          super( name );
      }
  
      public void testExecution() throws Exception
      {
          final File projectFile = getTestResource( "projectref.ant" );
          executeTarget( projectFile, "call-ref" );
          executeTarget( projectFile, "project-reuse" );
          executeTarget( projectFile, "target-state" );
          executeTarget( projectFile, "multi-ref" );
          executeTarget( projectFile, "self-ref" );
          executeTarget( projectFile, "no-name" );
          executeTarget( projectFile, "invalid-name" );
          executeTarget( projectFile, "duplicate-name" );
          executeTarget( projectFile, "no-location" );
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/project/test/ant.ant
  
  Index: ant.ant
  ===================================================================
  <project version="2.0">
  
      <target name="default-project">
          <expect-output absolute-path="true">
              <out>
                  <build>
                      <main>
                          <log>The default project.</log>
                      </main>
                  </build>
              </out>
              <tasks>
                  <ant/>
              </tasks>
          </expect-output>
      </target>
  
      <target name="default-target">
          <expect-output absolute-path="true">
              <out>
                  <common-project>
                      <main>
                          <log>common: In default target.</log>
                      </main>
                  </common-project>
              </out>
              <tasks>
                  <ant file="common-project.ant"/>
              </tasks>
          </expect-output>
      </target>
  
      <target name="call-target">
          <expect-output absolute-path="true">
              <out>
                  <common-project>
                      <other-target>
                          <log>common: In other target.</log>
                      </other-target>
                  </common-project>
              </out>
              <tasks>
                  <ant file="common-project.ant" target="other-target"/>
              </tasks>
          </expect-output>
      </target>
  
      <!-- Validation Tests -->
  
      <target name="unknown-target">
          <property name="uri" value="${toURL(myrmidon.project/baseDirectory)}common-project.ant"/>
          <expect-error>
              <exc>Execution of target "no-such-target" in project "${uri}" failed.</exc>
              <exc>No target named "no-such-target" in project "${uri}".</exc>
              <tasks>
                  <ant file="common-project.ant" target="no-such-target"/>
              </tasks>
          </expect-error>
      </target>
  
      <target name="unknown-file">
          <property name="uri" value="${toURL(myrmidon.project/baseDirectory)}no-such-file.ant"/>
          <expect-error>
              <exc>Execution of default target in project "${uri}" failed.</exc>
              <exc>Could not load project "${uri}".</exc>
              <tasks>
                  <ant file="no-such-file.ant"/>
              </tasks>
          </expect-error>
      </target>
  
  </project>
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/project/test/build.ant
  
  Index: build.ant
  ===================================================================
  <project version="2.0">
      <target name="main">
          <log>The default project.</log>
      </target>
  </project>
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/project/test/projectref-common.ant
  
  Index: projectref-common.ant
  ===================================================================
  <project version="2.0">
      <target name="main">
          <log>common: in main target.</log>
      </target>
  
      <target name="target1">
          <assert><not><is-set property="target1"/></not></assert>
          <property name="target1" value="done"/>
      </target>
  
      <target name="check-target1">
          <assert><is-set property="target1"/></assert>
      </target>
  
      <target name="target2">
          <log>In target 2.</log>
      </target>
  </project>
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/project/test/projectref.ant
  
  Index: projectref.ant
  ===================================================================
  <project version="2.0">
      <!-- Add dependency on target in other project -->
      <target name="call-ref">
          <expect-output absolute-path="true">
              <out>
                  <projectref-common>
                      <main>
                          <log>common: in main target.</log>
                      </main>
                  </projectref-common>
              </out>
              <tasks>
                  <projectref name="common" location="projectref-common.ant"/>
                  <depends project="common" target="main"/>
              </tasks>
          </expect-output>
      </target>
  
      <!-- Make sure project is reused. -->
      <target name="project-reuse">
          <projectref name="common" location="projectref-common.ant"/>
          <depends project="common" target="target1"/>
          <depends project="common" target="check-target1"/>
      </target>
  
      <!-- Make sure the same project is used when 2 different references refer to it -->
      <target name="multi-ref">
          <projectref name="ref1" location="projectref-common.ant"/>
          <projectref name="ref2" location="projectref-common.ant"/>
          <depends project="ref1" target="target1"/>
          <depends project="ref2" target="check-target1"/>
      </target>
  
      <!-- Make sure target state is kept -->
      <target name="target-state">
          <expect-output absolute-path="true">
              <out>
                  <projectref-common>
                      <target2>
                          <log>In target 2.</log>
                      </target2>
                  </projectref-common>
              </out>
              <tasks>
                  <projectref name="common" location="projectref-common.ant"/>
                  <depends project="common" target="target2"/>
                  <depends project="common" target="target2"/>
              </tasks>
          </expect-output>
      </target>
  
      <!-- Use the reference to this project -->
      <target name="self-ref">
          <assert><not><is-set property="target1"/></not></assert>
          <depends project="projectref" target="target1"/>
          <assert><is-set property="target1"/></assert>
      </target>
  
      <target name="target1">
          <property name="target1" value="done"/>
      </target>
  
      <!-- Validation tests -->
  
      <!-- Add a reference with no name -->
      <target name="no-name">
          <expect-error>
              <exc>No project name specified.</exc>
              <tasks>
                  <projectref location="some-project.ant"/>
              </tasks>
          </expect-error>
      </target>
  
      <!-- Test duplicate reference names -->
      <target name="duplicate-name">
          <expect-error>
              <exc>Multiple project references with name "ref".</exc>
              <tasks>
                  <projectref name="ref" location="some-project.ant"/>
                  <projectref name="ref" location="some-other-project.ant"/>
              </tasks>
          </expect-error>
      </target>
  
      <!-- Add a reference with an invalid name -->
      <target name="invalid-name">
          <expect-error>
              <exc>Invalid project reference name "??".</exc>
              <tasks>
                  <projectref name="??" location="some-project.ant"/>
              </tasks>
          </expect-error>
      </target>
  
      <!-- Add a reference with no location -->
      <target name="no-location">
          <expect-error>
              <exc>No project location specified.</exc>
              <tasks>
                  <projectref name="someref"/>
              </tasks>
          </expect-error>
      </target>
  
  
  </project>
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message