ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/builder/test DefaultProjectBuilderTestCase.java
Date Tue, 11 Jun 2002 02:27:50 GMT
donaldp     2002/06/10 19:27:50

  Modified:    container/src/java/org/apache/myrmidon/components/builder
                        DefaultProject.java DefaultProjectBuilder.java
               container/src/test/org/apache/myrmidon/components/builder/test
                        DefaultProjectBuilderTestCase.java
  Log:
  Rework ProjectBuilder so that the data is passed into project via constructor
  
  Revision  Changes    Path
  1.27      +46 -38    jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/builder/DefaultProject.java
  
  Index: DefaultProject.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/builder/DefaultProject.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- DefaultProject.java	11 Jun 2002 01:40:32 -0000	1.26
  +++ DefaultProject.java	11 Jun 2002 02:27:50 -0000	1.27
  @@ -53,49 +53,49 @@
       private final File m_baseDirectory;
   
       /**
  -     * The project references in this project
  +     * The target meta data contained by this project
        */
  -    private final Map m_references = new HashMap();
  +    private final Map m_targetMetaDataSet = new HashMap();
  +
  +    private DefaultTargetMetaData m_metaData;
  +
  +    private final ProjectDescriptor m_descriptor;
   
       /**
  -     * The target meta data contained by this project
  +     * The set of projectRefs that this Project uses.
        */
  -    private final Map m_targets = new HashMap();
  +    private final ProjectRef[] m_projectRefs;
   
       /**
  -     * The targets models by this project
  +     * The set of targets for this project.
        */
  -    private final Map m_models = new HashMap();
  -
  -    private DefaultTargetMetaData m_metaData;
  -    private final ProjectDescriptor m_descriptor;
  +    private final ModelElement[] m_targets;
   
       public DefaultProject( final String name,
                              final ProjectDescriptor descriptor,
                              final File baseDirectory,
  -                           final String defaultTarget )
  +                           final String defaultTarget,
  +                           final ProjectRef[] projectRefs,
  +                           final ModelElement[] targets )
       {
           m_name = name;
           m_descriptor = descriptor;
           m_baseDirectory = baseDirectory;
           m_defaultTarget = defaultTarget;
  +        m_projectRefs = projectRefs;
  +        m_targets = targets;
  +        for( int i = 0; i < m_targets.length; i++ )
  +        {
  +            addTargetMetaData( m_targets[ i ] );
  +        }
       }
   
  -    /**
  -     * Adds a project reference to this project.
  -     */
  -    public void addProjectRef( final ProjectRef ref )
  -    {
  -        m_references.put( ref.getName(), ref );
  -    }
  -
  -    public void addTarget( final ModelElement model )
  +    private void addTargetMetaData( final ModelElement model )
       {
           final String name = model.getAttribute( "name" );
           final String description = model.getAttribute( "description" );
           final DefaultTargetMetaData metaData = new DefaultTargetMetaData( name, description
);
  -        m_targets.put( metaData.getName(), metaData );
  -        m_models.put( metaData.getName(), model );
  +        m_targetMetaDataSet.put( metaData.getName(), metaData );
       }
   
       public ProjectDescriptor getProjectDescriptor()
  @@ -106,17 +106,19 @@
       public ProjectRef getProjectRef( String name )
           throws TaskException
       {
  -        // TODO - this does not handle dependency cycles between projects
  -        final ProjectRef project = (ProjectRef)m_references.get( name );
  -        if( null == project )
  +        for( int i = 0; i < m_projectRefs.length; i++ )
           {
  -            final String message =
  -                REZ.getString( "project.missing-ref.error",
  -                               name );
  -            throw new TaskException( message );
  +            final ProjectRef projectRef = m_projectRefs[ i ];
  +            if( name.equals( projectRef.getName() ) )
  +            {
  +                return projectRef;
  +            }
           }
   
  -        return project;
  +        final String message =
  +            REZ.getString( "project.missing-ref.error",
  +                           name );
  +        throw new TaskException( message );
       }
   
       /**
  @@ -146,7 +148,7 @@
       public final TargetMetaData getTarget( final String targetName )
           throws TaskException
       {
  -        final TargetMetaData target = (TargetMetaData)m_targets.get( targetName );
  +        final TargetMetaData target = (TargetMetaData)m_targetMetaDataSet.get( targetName
);
           if( target == null )
           {
               final String message = REZ.getString( "project.unknown-target.error", targetName
);
  @@ -155,16 +157,22 @@
           return target;
       }
   
  -    public final ModelElement getTargetModel( final String targetName )
  +    public final ModelElement getTargetModel( final String name )
           throws TaskException
       {
  -        final ModelElement target = (ModelElement)m_models.get( targetName );
  -        if( target == null )
  +        for( int i = 0; i < m_targets.length; i++ )
           {
  -            final String message = REZ.getString( "project.unknown-target.error", targetName
);
  -            throw new TaskException( message );
  +            final ModelElement target = m_targets[ i ];
  +            final String candidateName = target.getAttribute( "name", null );
  +            if( name.equals( candidateName ) )
  +            {
  +                return target;
  +            }
           }
  -        return target;
  +
  +        final String message =
  +            REZ.getString( "project.unknown-target.error", name );
  +        throw new TaskException( message );
       }
   
       /**
  @@ -188,7 +196,7 @@
       {
           if( null == m_metaData )
           {
  -            final Collection targets = m_targets.values();
  +            final Collection targets = m_targetMetaDataSet.values();
               final TargetMetaData[] targetMetaDatas =
                   (TargetMetaData[])targets.toArray( new TargetMetaData[ targets.size() ]
);
   
  
  
  
  1.73      +21 -8     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.72
  retrieving revision 1.73
  diff -u -r1.72 -r1.73
  --- DefaultProjectBuilder.java	11 Jun 2002 01:40:32 -0000	1.72
  +++ DefaultProjectBuilder.java	11 Jun 2002 02:27:50 -0000	1.73
  @@ -11,6 +11,8 @@
   import java.io.IOException;
   import java.net.MalformedURLException;
   import java.net.URL;
  +import java.util.ArrayList;
  +import java.util.List;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.avalon.excalibur.io.FileUtil;
  @@ -131,13 +133,23 @@
   
               verifyVersion( version );
   
  -            DefaultProject project =
  +            final ArrayList projectRefList = new ArrayList();
  +            final ArrayList targetList = new ArrayList();
  +            buildTopLevelProject( baseDirectory, model, projectRefList, targetList );
  +
  +            final ProjectRef[] projectRefs =
  +                (ProjectRef[])projectRefList.toArray( new ProjectRef[ projectRefList.size()
] );
  +            final ModelElement[] targets =
  +                (ModelElement[])targetList.toArray( new ModelElement[ targetList.size()
] );
  +
  +            final DefaultProject project =
                   new DefaultProject( projectName,
                                       descriptor,
                                       baseDirectory,
  -                                    defaultTarget );
  +                                    defaultTarget,
  +                                    projectRefs,
  +                                    targets );
               setupLogger( project );
  -            buildTopLevelProject( baseDirectory, model, project );
   
               return project;
           }
  @@ -315,7 +327,8 @@
        */
       private void buildTopLevelProject( final File baseDirectory,
                                          final ModelElement model,
  -                                       final DefaultProject project )
  +                                       final List projectRefs,
  +                                       final List targets )
           throws Exception
       {
           final ModelElement implicit = new ModelElement( "target", model.getLocation() );
  @@ -335,7 +348,7 @@
                   if( name.equals( "projectref" ) )
                   {
                       final ProjectRef ref = buildProjectRef( baseDirectory, element );
  -                    project.addProjectRef( ref );
  +                    projectRefs.add( ref );
                       continue;
                   }
                   else
  @@ -360,7 +373,7 @@
   
               if( name.equals( "target" ) )
               {
  -                project.addTarget( createTargetModel( element ) );
  +                targets.add( createTargetModel( element ) );
               }
               else
               {
  @@ -370,7 +383,7 @@
                   throw new ProjectException( message );
               }
           }
  -        project.addTarget( createTargetModel( implicit ) );
  +        targets.add( createTargetModel( implicit ) );
       }
   
       private ProjectRef buildProjectRef( final File baseDirectory,
  
  
  
  1.17      +39 -18    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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- DefaultProjectBuilderTestCase.java	11 Jun 2002 01:40:32 -0000	1.16
  +++ DefaultProjectBuilderTestCase.java	11 Jun 2002 02:27:50 -0000	1.17
  @@ -10,20 +10,22 @@
   import java.io.File;
   import java.io.IOException;
   import java.net.MalformedURLException;
  +import java.util.ArrayList;
   import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.avalon.excalibur.io.FileUtil;
   import org.apache.avalon.framework.container.ContainerUtil;
  +import org.apache.myrmidon.api.metadata.ModelElement;
   import org.apache.myrmidon.components.AbstractComponentTest;
  -import org.apache.myrmidon.components.embeddor.DefaultEmbeddor;
   import org.apache.myrmidon.components.builder.DefaultProject;
   import org.apache.myrmidon.components.builder.DefaultProjectBuilder;
  +import org.apache.myrmidon.components.embeddor.DefaultEmbeddor;
   import org.apache.myrmidon.interfaces.builder.ProjectBuilder;
   import org.apache.myrmidon.interfaces.builder.ProjectException;
  +import org.apache.myrmidon.interfaces.embeddor.Embeddor;
   import org.apache.myrmidon.interfaces.model.TargetMetaData;
   import org.apache.myrmidon.interfaces.oldmodel.Project;
  -import org.apache.myrmidon.interfaces.embeddor.Embeddor;
   import org.apache.myrmidon.interfaces.workspace.ProjectDescriptor;
  -import org.apache.myrmidon.api.metadata.ModelElement;
  +import org.apache.myrmidon.interfaces.workspace.ProjectRef;
   
   /**
    * Test cases for {@link DefaultProjectBuilder}.
  @@ -138,9 +140,10 @@
               new DefaultProject( getNameFor( projFile ),
                                   new ProjectDescriptor( uri ),
                                   getTestDirectory(),
  -                                "main" );
  -        addTarget( expected, "main" );
  -        addTarget( expected, Project.IMPLICIT_TARGET_NAME );
  +                                "main",
  +                                new ProjectRef[ 0 ],
  +                                createDummyTargets() );
  +
           assertSameProject( expected, project );
       }
   
  @@ -158,12 +161,12 @@
           }
       }
   
  -    private void addTarget( final DefaultProject project,
  +    private void addTarget( final ArrayList targetSet,
                               final String name )
       {
           final ModelElement model = new ModelElement( "target", "" );
           model.setAttribute( "name", name );
  -        project.addTarget( model );
  +        targetSet.add( model );
       }
   
       private String getNameFor( final File projFile )
  @@ -182,16 +185,27 @@
   
           // Compare against expected project
           final String uri = getURIFor( projFile );
  +
           final DefaultProject expected =
               new DefaultProject( "some-project",
                                   new ProjectDescriptor( uri ),
                                   getTestDirectory(),
  -                                "main" );
  -        addTarget( expected, "main" );
  -        addTarget( expected, Project.IMPLICIT_TARGET_NAME );
  +                                "main",
  +                                new ProjectRef[ 0 ],
  +                                createDummyTargets() );
           assertSameProject( expected, project );
       }
   
  +    private ModelElement[] createDummyTargets()
  +    {
  +        final ArrayList targetSet = new ArrayList();
  +        addTarget( targetSet, "main" );
  +        addTarget( targetSet, Project.IMPLICIT_TARGET_NAME );
  +        final ModelElement[] targets =
  +            (ModelElement[])targetSet.toArray( new ModelElement[ targetSet.size() ] );
  +        return targets;
  +    }
  +
       /**
        * Tests setting the base directory.
        */
  @@ -204,13 +218,14 @@
           // Compare against expected project
           final File baseDir = getTestDirectory( "other-base-dir" );
           final String uri = getURIFor( projFile );
  +
           final DefaultProject expected =
               new DefaultProject( getNameFor( projFile ),
                                   new ProjectDescriptor( uri ),
                                   baseDir,
  -                                "main" );
  -        addTarget( expected, "main" );
  -        addTarget( expected, Project.IMPLICIT_TARGET_NAME );
  +                                "main",
  +                                new ProjectRef[ 0 ],
  +                                createDummyTargets() );
           assertSameProject( expected, project );
       }
   
  @@ -225,13 +240,19 @@
   
           // Compare against expected project
           final String uri = getURIFor( projFile );
  +        final ArrayList targetSet = new ArrayList();
  +        addTarget( targetSet, "some-target" );
  +        addTarget( targetSet, Project.IMPLICIT_TARGET_NAME );
  +        final ModelElement[] targets =
  +            (ModelElement[])targetSet.toArray( new ModelElement[ targetSet.size() ] );
  +
           DefaultProject expected =
               new DefaultProject( getNameFor( projFile ),
                                   new ProjectDescriptor( uri ),
                                   getTestDirectory(),
  -                                "some-target" );
  -        addTarget( expected, "some-target" );
  -        addTarget( expected, Project.IMPLICIT_TARGET_NAME );
  +                                "some-target",
  +                                new ProjectRef[ 0 ],
  +                                targets );
           assertSameProject( expected, 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