You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by do...@apache.org on 2002/05/21 09:57:14 UTC

cvs commit: jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project AntCallTask.java

donaldp     02/05/21 00:57:14

  Modified:    container/src/java/org/apache/myrmidon/components/workspace
                        Resources.properties DefaultWorkspace.java
               container/src/java/org/apache/myrmidon/interfaces/oldmodel
                        Project.java
               container/src/java/org/apache/myrmidon/components/builder
                        DefaultProjectBuilder.java DefaultProject.java
               antlib/src/java/org/apache/antlib/project AntCallTask.java
  Log:
  Lazy loading of projects that are traversed by references implemented.
  
  Yea!
  
  Revision  Changes    Path
  1.12      +1 -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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Resources.properties	3 May 2002 06:56:11 -0000	1.11
  +++ Resources.properties	21 May 2002 07:57:13 -0000	1.12
  @@ -6,6 +6,7 @@
   exec-target.notice=Executing project {0}, target {1}.
   exec-task.notice=Executing task {0}.
   target-dependency-cycle.error=Cycle in dependencies for target {0}.
  +workspace.nobuild-project.error=Unable to build project referenced by name "{0}" and located at "{1}". (Reason: {2}).
   
   #DefaultTaskContext
   unknown-prop.error=Unknown property {0}.
  
  
  
  1.66      +60 -8     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.65
  retrieving revision 1.66
  diff -u -r1.65 -r1.66
  --- DefaultWorkspace.java	21 May 2002 05:52:34 -0000	1.65
  +++ DefaultWorkspace.java	21 May 2002 07:57:13 -0000	1.66
  @@ -16,10 +16,12 @@
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.api.metadata.ModelElement;
   import org.apache.myrmidon.interfaces.deployer.Deployer;
  +import org.apache.myrmidon.interfaces.embeddor.Embeddor;
   import org.apache.myrmidon.interfaces.executor.ExecutionFrame;
   import org.apache.myrmidon.interfaces.executor.Executor;
   import org.apache.myrmidon.interfaces.oldmodel.Dependency;
   import org.apache.myrmidon.interfaces.oldmodel.Project;
  +import org.apache.myrmidon.interfaces.oldmodel.ProjectRef;
   import org.apache.myrmidon.interfaces.oldmodel.Target;
   import org.apache.myrmidon.interfaces.type.TypeManager;
   import org.apache.myrmidon.interfaces.workspace.Workspace;
  @@ -28,7 +30,8 @@
    * This is the default implementation of Workspace.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.65 $ $Date: 2002/05/21 05:52:34 $
  + * @version $Revision: 1.66 $ $Date: 2002/05/21 07:57:13 $
  + * @todo Merge m_entries and m_projects
    */
   public class DefaultWorkspace
       extends AbstractLogEnabled
  @@ -45,6 +48,9 @@
       /** A map from Project object -> ProjectEntry for that project. */
       private HashMap m_entries = new HashMap();
   
  +    /** A cach of Project objects. */
  +    private HashMap m_projects = new HashMap();
  +
       /**
        * Execute a target in a particular project.
        * Execute in the project context.
  @@ -92,7 +98,7 @@
           serviceManager.put( Deployer.ROLE, deployer );
   
           //We need to place projects and ProjectManager
  -        //in ComponentManager so as to support project-local call()
  +        //in ServiceManager so as to support project-local call()
           // TODO - add project to properties, not services
           serviceManager.put( Workspace.ROLE, this );
           serviceManager.put( Project.ROLE, project );
  @@ -127,17 +133,62 @@
           return entry;
       }
   
  -    private Project getProject( final String name, final Project project )
  +    private Project getProject( final ExecutionFrame frame,
  +                                final String name,
  +                                final Project project )
           throws TaskException
       {
  -        final Project other = project.getProject( name );
  -        if( null == other )
  +        final ProjectRef projectRef = project.getProjectRef( name );
  +
  +        if( null == projectRef )
           {
  -            //TODO: Fix this so location information included in description
  -            final String message = REZ.getString( "no-project.error", name );
  +            final String message =
  +                REZ.getString( "no-project.error", name );
               throw new TaskException( message );
           }
   
  +        final String uri = projectRef.getUri();
  +        Project other = (Project)m_projects.get( uri );
  +        if( null == other )
  +        {
  +            other = createProject( frame, name, uri );
  +            m_projects.put( uri, other );
  +        }
  +
  +        return other;
  +    }
  +
  +    /**
  +     * Create project referred to by specified name and located
  +     * at specified URI.
  +     *
  +     * @param frame the frme in which to create project
  +     * @param name the name of the project reference
  +     * @param uri the URI of project
  +     * @return the created project
  +     * @throws TaskException if there is an error creating project
  +     */
  +    private Project createProject( final ExecutionFrame frame,
  +                                   final String name,
  +                                   final String uri )
  +        throws TaskException
  +    {
  +        Project other;
  +        try
  +        {
  +            final Embeddor embeddor =
  +                (Embeddor)frame.getServiceManager().lookup( Embeddor.ROLE );
  +            other = embeddor.createProject( uri, null, null );
  +        }
  +        catch( final Exception e )
  +        {
  +            final String message =
  +                REZ.getString( "workspace.nobuild-project.error",
  +                               name,
  +                               uri,
  +                               e );
  +            throw new TaskException( message, e );
  +        }
           return other;
       }
   
  @@ -217,7 +268,8 @@
               if( otherProjectName != null )
               {
                   // Dependency in a referenced project
  -                final Project otherProject = getProject( otherProjectName, project );
  +                final Project otherProject =
  +                    getProject( frame, otherProjectName, project );
                   final ProjectEntry otherEntry = getProjectEntry( otherProject, frame );
                   executeTarget( frame, otherEntry, dependency.getTargetName() );
               }
  
  
  
  1.9       +1 -9      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/oldmodel/Project.java
  
  Index: Project.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/oldmodel/Project.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Project.java	21 May 2002 07:15:21 -0000	1.8
  +++ Project.java	21 May 2002 07:57:14 -0000	1.9
  @@ -16,7 +16,7 @@
    * Implementations may choose to structure it anyway they choose.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.8 $ $Date: 2002/05/21 07:15:21 $
  + * @version $Revision: 1.9 $ $Date: 2002/05/21 07:57:14 $
    */
   public interface Project
       extends Module
  @@ -43,14 +43,6 @@
        * @return the names
        */
       String[] getProjectNames();
  -
  -    /**
  -     * Retrieve project referenced by this project.
  -     *
  -     * @param name the project name
  -     * @return the Project or null if none by that name
  -     */
  -    Project getProject( String name );
   
       /**
        * Retrieve project reference for specified name.
  
  
  
  1.56      +8 -23     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.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- DefaultProjectBuilder.java	21 May 2002 07:15:21 -0000	1.55
  +++ DefaultProjectBuilder.java	21 May 2002 07:57:14 -0000	1.56
  @@ -35,7 +35,7 @@
    * Default implementation to construct project from a build file.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.55 $ $Date: 2002/05/21 07:15:21 $
  + * @version $Revision: 1.56 $ $Date: 2002/05/21 07:57:14 $
    *
    * @ant.type type="project-builder" name="ant2"
    */
  @@ -74,22 +74,16 @@
           throws ProjectException
       {
           final File file = new File( source );
  -        return build( file, new HashMap() );
  +        return build( file );
       }
   
  -    private Project build( final File file, final Map projects )
  +    private Project build( final File file )
           throws ProjectException
       {
           try
           {
               // Check for cached project
               final String systemID = extractURL( file );
  -            final Project result = (Project)projects.get( systemID );
  -            if( null != result )
  -            {
  -                return result;
  -            }
  -
               final ModelElement model = getModelBuilder().build( systemID );
   
               // Tranform the resulting model
  @@ -98,10 +92,9 @@
   
               // Build the project model and add to cache
               final DefaultProject project = buildProject( file, model );
  -            projects.put( systemID, project );
   
               // Build using all top-level attributes
  -            buildTopLevelProject( project, model, projects );
  +            buildTopLevelProject( project, model );
   
               return project;
           }
  @@ -278,8 +271,7 @@
        * @exception ProjectException if an error occurs
        */
       private void buildTopLevelProject( final DefaultProject project,
  -                                       final ModelElement model,
  -                                       final Map projects )
  +                                       final ModelElement model )
           throws Exception
       {
           final ArrayList implicitTaskList = new ArrayList();
  @@ -296,7 +288,7 @@
               {
                   if( name.equals( "projectref" ) )
                   {
  -                    buildProjectRef( project, element, projects );
  +                    buildProjectRef( project, element );
                       continue;
                   }
                   else
  @@ -340,8 +332,7 @@
       }
   
       private void buildProjectRef( final DefaultProject project,
  -                                  final ModelElement element,
  -                                  final Map projects )
  +                                  final ModelElement element )
           throws ProjectException
       {
           final String name = element.getAttribute( "name" );
  @@ -381,7 +372,7 @@
   
           try
           {
  -            final String uri = file.getCanonicalFile().toURL().toExternalForm();
  +            final String uri =  file.getCanonicalFile().toString();
               final ProjectRef ref = new ProjectRef( name, uri );
               project.addProjectRef( ref );
           }
  @@ -389,12 +380,6 @@
           {
               throw new ProjectException( ioe.getMessage(), ioe );
           }
  -
  -        // Locate the referenced project, building it if necessary
  -        final Project other = build( file, projects );
  -
  -        // Add the reference
  -        project.addProject( name, other );
       }
   
       /**
  
  
  
  1.13      +12 -37    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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- DefaultProject.java	21 May 2002 07:15:21 -0000	1.12
  +++ DefaultProject.java	21 May 2002 07:57:14 -0000	1.13
  @@ -24,7 +24,7 @@
    * Default project implementation.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.12 $ $Date: 2002/05/21 07:15:21 $
  + * @version $Revision: 1.13 $ $Date: 2002/05/21 07:57:14 $
    */
   public class DefaultProject
       implements Project, TargetMetaData
  @@ -35,9 +35,6 @@
       ///The project references in this project
       private final HashMap m_references = new HashMap();
   
  -    ///The projects refferred to by this project
  -    private final HashMap m_projects = new HashMap();
  -
       ///The targets contained by this project
       private final HashMap m_targets = new HashMap();
   
  @@ -82,18 +79,7 @@
        */
       public String[] getProjectNames()
       {
  -        return (String[])m_projects.keySet().toArray( new String[ 0 ] );
  -    }
  -
  -    /**
  -     * Retrieve project reffered to by this project.
  -     *
  -     * @param name the project name
  -     * @return the Project or null if none by that name
  -     */
  -    public Project getProject( final String name )
  -    {
  -        return (Project)m_projects.get( name );
  +        return (String[])m_references.keySet().toArray( new String[ 0 ] );
       }
   
       /**
  @@ -191,26 +177,6 @@
       }
   
       /**
  -     * Add a project reference.
  -     *
  -     * @param name the name of target
  -     * @param project the Project
  -     * @exception IllegalArgumentException if project already exists with same name
  -     */
  -    public final void addProject( final String name, final Project project )
  -    {
  -        if( null != m_projects.get( name ) )
  -        {
  -            final String message = REZ.getString( "duplicate-project.error", name );
  -            throw new IllegalArgumentException( message );
  -        }
  -        else
  -        {
  -            m_projects.put( name, project );
  -        }
  -    }
  -
  -    /**
        * Retrieve the name of the Target.
        *
        * @return the name of the Target.
  @@ -277,6 +243,15 @@
   
       public void addProjectRef( final ProjectRef ref )
       {
  -        m_references.put( ref.getName(), ref );
  +        if( null != m_references.get( ref.getName() ) )
  +        {
  +            final String message =
  +                REZ.getString( "duplicate-project.error", ref.getName() );
  +            throw new IllegalArgumentException( message );
  +        }
  +        else
  +        {
  +            m_references.put( ref.getName(), ref );
  +        }
       }
   }
  
  
  
  1.2       +16 -8     jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/AntCallTask.java
  
  Index: AntCallTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/AntCallTask.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AntCallTask.java	3 May 2002 10:34:02 -0000	1.1
  +++ AntCallTask.java	21 May 2002 07:57:14 -0000	1.2
  @@ -11,14 +11,16 @@
   import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.interfaces.oldmodel.Project;
  +import org.apache.myrmidon.interfaces.oldmodel.ProjectRef;
   import org.apache.myrmidon.framework.ExecuteTarget;
  +import java.io.File;
   
   /**
    * A task which executes a target in the current project,
    * or a referenced project.
    *
    * @author <a href="mailto:darrell@apache.org">Darrell DeBoer</a>
  - * @version $Revision: 1.1 $ $Date: 2002/05/03 10:34:02 $
  + * @version $Revision: 1.2 $ $Date: 2002/05/21 07:57:14 $
    * @ant.task name="ant-call"
    */
   public class AntCallTask
  @@ -48,19 +50,25 @@
               (Project)getContext().getService( Project.class );
   
           // By default, use the current project.
  -        Project referencedProject = currentProject;
  -
  -        if( m_project != null )
  +        if( null == m_project )
  +        {
  +            exe.setProject( currentProject );
  +        }
  +        else
           {
  -            referencedProject = currentProject.getProject( m_project );
  -            if( referencedProject == null )
  +            final ProjectRef projectRef = currentProject.getProjectRef( m_project );
  +            if( projectRef == null )
               {
                   final String message =
                       REZ.getString( "antcall.invalid-project.error" );
                   throw new TaskException( message );
               }
  -        }
   
  -        exe.setProject( referencedProject );
  +            //Warning next line will not work in all cases
  +            //We need to assume that all references are to file
  +            //based URIS which is true now but maybe not in the future.
  +            final File file = new File( projectRef.getUri() );
  +            exe.setProjectFile( file, null );
  +        }
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>