avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject svn commit: rev 20573 - in avalon/trunk/tools/project/core: . src/main/org/apache/avalon/tools src/main/org/apache/avalon/tools/event src/main/org/apache/avalon/tools/home src/main/org/apache/avalon/tools/project src/main/org/apache/avalon/tools/project/builder src/main/org/apache/avalon/tools/tasks src/test src/test/projects/demo src/test/projects/demo/src/main/org/apache/avalon/demo src/test/projects/sample src/test/projects/sample/src src/test/projects/sample/src/main src/test/projects/sample/src/main/org src/test/projects/sample/src/main/org/apache src/test/projects/sample/src/main/org/apache/avalon src/test/projects/sample/src/main/org/apache/avalon/sample
Date Sat, 29 May 2004 03:54:08 GMT
Author: mcconnell
Date: Fri May 28 20:54:07 2004
New Revision: 20573

Added:
   avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/event/StandardListener.java
   avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/tasks/DeclareTask.java
   avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/tasks/PluginTask.java
   avalon/trunk/tools/project/core/src/test/projects/sample/
   avalon/trunk/tools/project/core/src/test/projects/sample/build.xml
   avalon/trunk/tools/project/core/src/test/projects/sample/src/
   avalon/trunk/tools/project/core/src/test/projects/sample/src/main/
   avalon/trunk/tools/project/core/src/test/projects/sample/src/main/org/
   avalon/trunk/tools/project/core/src/test/projects/sample/src/main/org/apache/
   avalon/trunk/tools/project/core/src/test/projects/sample/src/main/org/apache/avalon/
   avalon/trunk/tools/project/core/src/test/projects/sample/src/main/org/apache/avalon/sample/
   avalon/trunk/tools/project/core/src/test/projects/sample/src/main/org/apache/avalon/sample/Sample.java
   avalon/trunk/tools/project/core/src/test/projects/sample/src/main/org/apache/avalon/sample/StandardSample.java
Removed:
   avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/tasks/XdocTask.java
Modified:
   avalon/trunk/tools/project/core/build.xml
   avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/antlib.xml
   avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/event/AbstractListener.java
   avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/home/Home.java
   avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/home/Repository.java
   avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/project/Info.java
   avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/project/Plugin.java
   avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/project/ProjectTask.java
   avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/project/Resource.java
   avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/project/builder/XMLDefinitionBuilder.java
   avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/tasks/JavacTask.java
   avalon/trunk/tools/project/core/src/test/index.xml
   avalon/trunk/tools/project/core/src/test/projects/demo/build.xml
   avalon/trunk/tools/project/core/src/test/projects/demo/src/main/org/apache/avalon/demo/StandardDemo.java
Log:
Add plugable plugins.

Modified: avalon/trunk/tools/project/core/build.xml
==============================================================================
--- avalon/trunk/tools/project/core/build.xml	(original)
+++ avalon/trunk/tools/project/core/build.xml	Fri May 28 20:54:07 2004
@@ -63,6 +63,7 @@
     <ant dir="${target.test.dir}/projects/gizmo" />
     <ant dir="${target.test.dir}/projects/widget" />
     <ant dir="${target.test.dir}/projects/demo" />
+    <ant dir="${target.test.dir}/projects/sample" />
   </target>
 
   <target name="clean">

Modified: avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/antlib.xml
==============================================================================
--- avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/antlib.xml	(original)
+++ avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/antlib.xml	Fri May 28
20:54:07 2004
@@ -6,6 +6,7 @@
   <taskdef name="javac" classname="org.apache.avalon.tools.tasks.JavacTask"/> 
   <taskdef name="jar" classname="org.apache.avalon.tools.tasks.JarTask"/> 
   <taskdef name="test" classname="org.apache.avalon.tools.tasks.TestTask"/> 
-  <taskdef name="xdoc" classname="org.apache.avalon.tools.tasks.XdocTask"/> 
+  <taskdef name="declare" classname="org.apache.avalon.tools.tasks.DeclareTask"/> 
+  <taskdef name="plugin" classname="org.apache.avalon.tools.tasks.PluginTask"/> 
   <taskdef name="install" classname="org.apache.avalon.tools.tasks.InstallTask"/> 
 </antlib> 

Modified: avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/event/AbstractListener.java
==============================================================================
--- avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/event/AbstractListener.java
(original)
+++ avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/event/AbstractListener.java
Fri May 28 20:54:07 2004
@@ -17,17 +17,8 @@
 
 package org.apache.avalon.tools.event;
 
-import java.io.File;
-import java.io.IOException;
-import java.util.Iterator;
-
-import org.apache.tools.ant.Project;
 import org.apache.tools.ant.BuildEvent;
 import org.apache.tools.ant.BuildListener;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.taskdefs.Sequential;
-
-import org.apache.avalon.tools.home.Home;
 
 /**
  * An abstract build listener. 
@@ -35,15 +26,8 @@
  * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
  * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
  */
-public class AbstractListener implements BuildListener
+public abstract class AbstractListener implements BuildListener
 {
-    private Home m_home;
-
-    public AbstractListener( Home home )
-    {
-        m_home = home;
-    }
-
     /**
      * Signals that a build has started. This event
      * is fired before any targets have started.
@@ -129,6 +113,5 @@
      */
     public void messageLogged(BuildEvent event)
     {
-    }
-
+    }   
 }

Added: avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/event/StandardListener.java
==============================================================================
--- (empty file)
+++ avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/event/StandardListener.java
Fri May 28 20:54:07 2004
@@ -0,0 +1,100 @@
+/* 
+ * Copyright 2004 Apache Software Foundation
+ * Licensed  under the  Apache License,  Version 2.0  (the "License");
+ * you may not use  this file  except in  compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed  under the  License is distributed on an "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+ * implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.avalon.tools.event;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.BuildEvent;
+import org.apache.tools.ant.BuildListener;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.taskdefs.Sequential;
+
+import org.apache.avalon.tools.home.Home;
+import org.apache.avalon.tools.project.Definition;
+import org.apache.avalon.tools.project.PluginRef;
+import org.apache.avalon.tools.project.Plugin;
+
+/**
+ * An abstract build listener. 
+ *
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
+ * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
+ */
+public class StandardListener extends AbstractListener
+{
+    private static final String BANNER = 
+      "------------------------------------------------------------------------------";
+
+    private Home m_home;
+    private Definition m_definition;
+    private Task m_task;
+
+    public StandardListener( Task task, Home home, Definition definition )
+    {
+        m_home = home;
+        m_definition = definition;
+        m_task = task;
+    }
+
+    /**
+     * Signals that a build has started. This event
+     * is fired before any targets have started.
+     *
+     * @param event An event with any relevant extra information.
+     *              Must not be <code>null</code>.
+     */
+    public void buildStarted(BuildEvent event)
+    {
+        Project project = event.getProject();
+        project.log( "" );
+        project.log( BANNER );
+        getTask().log( "project: " + getDefinition() );
+        getTask().log( "basedir: " + project.getBaseDir() );
+        project.log( BANNER );
+
+        /*
+        PluginRef[] refs = getDefinition().getPluginRefs();
+        for( int i=0; i<refs.length; i++ )
+        {
+            PluginRef ref = refs[i];
+            Plugin plugin = getHome().getPlugin( ref );
+            project.log( "plugin ref: " + plugin );
+        }
+        */
+    }
+
+    private Task getTask()
+    {
+        return m_task;
+    }
+
+    private Home getHome()
+    {
+        return m_home;
+    }
+
+    private Definition getDefinition()
+    {
+        return m_definition;
+    }
+   
+}

Modified: avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/home/Home.java
==============================================================================
--- avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/home/Home.java	(original)
+++ avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/home/Home.java	Fri May
28 20:54:07 2004
@@ -25,6 +25,8 @@
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
+import org.apache.tools.ant.BuildEvent;
+import org.apache.tools.ant.BuildListener;
 import org.apache.tools.ant.ProjectComponent;
 import org.apache.tools.ant.taskdefs.Ant;
 import org.apache.tools.ant.taskdefs.Ant.Reference;
@@ -43,7 +45,6 @@
 import org.w3c.dom.NodeList;
 import org.xml.sax.SAXException;
 
-import org.apache.avalon.tools.event.AbstractListener;
 import org.apache.avalon.tools.project.Definition;
 import org.apache.avalon.tools.project.ProjectRef;
 import org.apache.avalon.tools.project.ResourceRef;
@@ -109,8 +110,6 @@
 
         HOME = this;
  
-        project.addBuildListener( new AbstractListener( this ) );
-
         Element root = ElementHelper.getRootElement( file );
         project.log( "home: " + m_home, Project.MSG_DEBUG );
 
@@ -137,6 +136,7 @@
         //
 
         buildProjectList( projects );
+
     }
 
     private void buildResourceList( Element resources )
@@ -148,7 +148,7 @@
         for( int i=0; i<resourceArray.length; i++ )
         {
             Element child = resourceArray[i];
-            Resource resource = XMLDefinitionBuilder.createResource( child );
+            Resource resource = XMLDefinitionBuilder.createResource( this, child );
             String key = resource.getKey();
             m_resources.put( key, resource );
             m_project.log( 
@@ -161,7 +161,7 @@
     {
         if( null == projects ) return;
 
-        Element[] entries = ElementHelper.getChildren( projects, "project" );
+        Element[] entries = ElementHelper.getChildren( projects );
         m_project.log( 
           "projects: " + entries.length, 
           Project.MSG_DEBUG );
@@ -169,7 +169,7 @@
         {
             Element element = entries[i];
             Definition definition = 
-              XMLDefinitionBuilder.createDefinition( m_home, element );
+              XMLDefinitionBuilder.createDefinition( this, element, m_home );
             String key = definition.getKey();
             m_resources.put( key, definition );
             m_project.log( 
@@ -198,6 +198,12 @@
         return m_project;
     }
 
+    public Plugin getPlugin( PluginRef ref )
+      throws BuildException
+    {
+        return (Plugin) getDefinition( ref );
+    }
+
     public Definition getDefinition( ProjectRef ref )
       throws BuildException
     {
@@ -259,7 +265,6 @@
             Definition def = getDefinition( refs[i] );
             getBuildSequence( visited, targets, def );
         }
-        //targets.add( definition );
         return (Definition[]) targets.toArray( new Definition[0] );
     }
 

Modified: avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/home/Repository.java
==============================================================================
--- avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/home/Repository.java
(original)
+++ avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/home/Repository.java
Fri May 28 20:54:07 2004
@@ -21,6 +21,7 @@
 import java.io.IOException;
 import java.io.FileNotFoundException;
 import java.util.Hashtable;
+import java.util.List;
 import java.util.ArrayList;
 import java.net.URL;
 
@@ -91,6 +92,38 @@
         return m_hosts;
     }
 
+    public ResourceRef[] getResourceRefs( Definition def )
+    {
+        ArrayList list = new ArrayList();
+        getResourceRefs( def, list );
+        return (ResourceRef[]) list.toArray( new ResourceRef[0] );
+    }
+
+    public void getResourceRefs( Definition def, List list )
+    {
+        ResourceRef[] refs = def.getResourceRefs();
+        for( int i=0; i<refs.length; i++ )
+        {
+            ResourceRef ref = refs[i];
+            if( !list.contains( ref ) )
+            {
+                list.add( ref );
+            }
+        }
+
+        ProjectRef[] projects = def.getProjectRefs();
+        for( int i=0; i<projects.length; i++ )
+        {
+            ProjectRef ref = projects[i];
+            if( !list.contains( ref ) )
+            {
+                Definition defintion = m_home.getDefinition( ref );
+                getResourceRefs( defintion, list );
+                list.add( ref );
+            }
+        }
+    }
+
     public Path createPath( Project project, Definition def )
       throws BuildException
     {
@@ -203,14 +236,14 @@
         }
     }
 
-    public URL getResource( Project project, Resource resource )
+    public File getResource( Project project, Resource resource )
       throws Exception
     {
         String path = resource.getInfo().getPath();
         File target = new File( getCacheDirectory(), path );
         if( target.exists() ) 
         {
-            return target.toURL();
+            return target;
         }
 
         target.getParentFile().mkdirs();
@@ -231,7 +264,7 @@
         throw new FileNotFoundException( resource.toString() );
     }
 
-    public URL getResource( Project project, String host, Resource resource ) 
+    public File getResource( Project project, String host, Resource resource ) 
       throws Exception
     {
         String path = resource.getInfo().getPath();
@@ -247,7 +280,7 @@
         get.setVerbose( true );
         get.execute();
 
-        return target.toURL();
+        return target;
     }
 
     private FileList getResourceFileList( Project project, Resource resource )

Modified: avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/project/Info.java
==============================================================================
--- avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/project/Info.java	(original)
+++ avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/project/Info.java	Fri
May 28 20:54:07 2004
@@ -17,6 +17,7 @@
 
 package org.apache.avalon.tools.project;
 
+import org.apache.tools.ant.BuildException;
 
 /**
  * Project info.
@@ -26,6 +27,15 @@
  */
 public class Info 
 {
+    public static Info create( String id, String type )
+    {
+        int n = getGroupIndex( id );
+        String group = getGroupFromId( id, n );
+        String name = getNameFromId( id, n );
+        String version = getVersionFromId( id );
+        return new Info( group, name, version, type );
+    }
+
     private String m_name;
     private String m_group;
     private String m_version;
@@ -93,7 +103,7 @@
         return buffer.toString();
     }
 
-    public String toString()
+    public String getURI()
     {
         StringBuffer buffer = new StringBuffer();
         buffer.append( getType() );
@@ -109,6 +119,12 @@
         return buffer.toString();
     }
 
+
+    public String toString()
+    {
+        return getURI();
+    }
+
     public boolean equals( Object other )
     {
         if( other instanceof Info )
@@ -136,4 +152,52 @@
     {
         if( null == object ) throw new NullPointerException( key );
     }
+
+    private static int getGroupIndex( String id )
+    {
+        int n = id.lastIndexOf( "/" );
+        if( n < 0 )
+        {
+            final String error = 
+              "Invalid resource identifier \"" + id + "\". "
+              + "A resource identifier must be in for for [group]/[name]#[version]";
+            throw new BuildException( error );
+        }
+        else
+        {
+            return n;
+        }
+    }
+
+    private static String getGroupFromId( String id, int n )
+    {
+        return id.substring( 0, n );
+    }
+
+    private static String getNameFromId( String id, int n )
+    {
+        int j = id.indexOf( "#" );
+        if( j < 0 )
+        {
+            return id.substring( n+1 );
+        }
+        else
+        {
+            return id.substring( n+1, j );
+        }
+    }
+
+    private static String getVersionFromId( String id )
+    {
+        int j = id.indexOf( "#" );
+        if( j < 0 )
+        {
+            return null;
+        }
+        else
+        {
+            return id.substring( j+1 );
+        }
+    }
+
 }

Modified: avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/project/Plugin.java
==============================================================================
--- avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/project/Plugin.java	(original)
+++ avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/project/Plugin.java	Fri
May 28 20:54:07 2004
@@ -27,15 +27,20 @@
  */
 public class Plugin extends Definition
 {
-    private ProjectRef[] m_projects;
-    private ResourceRef[] m_resources;
-    private File m_basedir;
+    private final TaskDef[] m_tasks;
 
     public Plugin(
       String key, File basedir, Info info, 
-      ResourceRef[] resources, ProjectRef[] projects, PluginRef[] plugins )
+      ResourceRef[] resources, ProjectRef[] projects, PluginRef[] plugins, 
+      TaskDef[] tasks )
     {
         super( key, basedir, info, resources, projects, plugins );
+        m_tasks = tasks;
+    }
+
+    public TaskDef[] getTaskDefs()
+    {
+        return m_tasks;
     }
 
     public boolean equals( Object other )
@@ -45,5 +50,27 @@
             return true;
         }
         return false;
+    }
+
+    public static class TaskDef
+    {
+        private String m_name;
+        private String m_classname;
+        
+        public TaskDef( String name, String classname )
+        {
+            m_name = name;
+            m_classname = classname;
+        }
+
+        public String getName()
+        {
+            return m_name;
+        }
+
+        public String getClassname()
+        {
+            return m_classname;
+        }
     }
 }

Modified: avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/project/ProjectTask.java
==============================================================================
--- avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/project/ProjectTask.java
(original)
+++ avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/project/ProjectTask.java
Fri May 28 20:54:07 2004
@@ -22,12 +22,15 @@
 
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildEvent;
+import org.apache.tools.ant.BuildListener;
 import org.apache.tools.ant.taskdefs.Property;
 import org.apache.tools.ant.taskdefs.Sequential;
 import org.apache.tools.ant.types.Path;
 
 import org.apache.avalon.tools.home.Home;
 import org.apache.avalon.tools.home.Repository;
+import org.apache.avalon.tools.event.StandardListener;
 
 /**
  * Load the home defintion. 
@@ -37,7 +40,7 @@
  */
 public class ProjectTask extends Sequential
 {
-    private static final String ANT_PROPERTIES = "ant.properties";
+    private static final String USER_PROPERTIES = "user.properties";
     private static final String BUILD_PROPERTIES = "build.properties";
 
     private File m_index;
@@ -87,7 +90,6 @@
         }
     }
 
-
     public void execute() throws BuildException 
     {
         //
@@ -95,7 +97,7 @@
         //
 
         readProperties( 
-          new File( getProject().getBaseDir(), ANT_PROPERTIES ) );
+          new File( getProject().getBaseDir(), USER_PROPERTIES ) );
         readProperties( getPropertiesFile() );
 
         //
@@ -108,6 +110,7 @@
             log( "index: " + m_index, Project.MSG_INFO );
             Home.initialize( getProject(), m_index );
         }
+
         Home home = Home.getHome( getProject() );
 
         //
@@ -116,8 +119,11 @@
         //
 
         Definition definition = home.getDefinition( key );
+        BuildListener listener = new StandardListener( this, home, definition );
+        getProject().addBuildListener( listener );
         setProjectProperties( home, definition );
-        log( "build: " + definition );
+        listener.buildStarted( new BuildEvent( getProject() ) );
+
         super.execute();
 
         /*

Modified: avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/project/Resource.java
==============================================================================
--- avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/project/Resource.java
(original)
+++ avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/project/Resource.java
Fri May 28 20:54:07 2004
@@ -30,6 +30,11 @@
     private String m_key;
     private Info m_info;
 
+    public Resource( Info info )
+    {
+        this( null, info );
+    }
+
     public Resource( String key, Info info )
     {
         m_key = key;

Modified: avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/project/builder/XMLDefinitionBuilder.java
==============================================================================
--- avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/project/builder/XMLDefinitionBuilder.java
(original)
+++ avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/project/builder/XMLDefinitionBuilder.java
Fri May 28 20:54:07 2004
@@ -34,6 +34,7 @@
 import org.apache.avalon.tools.project.Resource;
 import org.apache.avalon.tools.project.PluginRef;
 import org.apache.avalon.tools.project.Plugin;
+import org.apache.avalon.tools.project.Plugin.TaskDef;
 import org.apache.avalon.tools.project.Policy;
 
 import org.w3c.dom.Element;
@@ -47,7 +48,7 @@
 public class XMLDefinitionBuilder 
 {
 
-    public static Resource createResource( Element element )
+    public static Resource createResource( Home home, Element element )
     {
         Info info = 
           createInfo( ElementHelper.getChild( element, "info" ) );
@@ -55,7 +56,7 @@
         return new Resource( key, info );
     }
 
-    public static Definition createDefinition( File anchor, Element element )
+    public static Definition createDefinition( Home home, Element element, File anchor )
     {
         Info info = 
           createInfo( ElementHelper.getChild( element, "info" ) );
@@ -78,7 +79,37 @@
           createPluginRefs( 
             ElementHelper.getChild( deps, "plugins" ) );
 
-        return new Definition( key, basedir, info, resources, projects, plugins );
+        final String tag = element.getTagName();
+        if( tag.equals( "project" ) )
+        {
+            return new Definition( key, basedir, info, resources, projects, plugins );
+        }
+        else if( tag.equals( "plugin" ) )
+        {
+            TaskDef[] tasks = 
+              getTaskDefs( ElementHelper.getChild( element, "tasks" ) );
+            return new Plugin( key, basedir, info, resources, projects, plugins, tasks );
+        }
+        else
+        {
+            final String error =
+              "Unrecognized project type \"" + tag + "\".";
+            throw new BuildException( error );
+        }
+    }
+
+    public static TaskDef[] getTaskDefs( Element element )
+    {
+        Element[] children = ElementHelper.getChildren( element, "taskdef" );
+        TaskDef[] refs = new TaskDef[ children.length ];
+        for( int i=0; i<children.length; i++ )
+        {
+            Element child = children[i];
+            String name = child.getAttribute( "name" );
+            String classname = child.getAttribute( "class" );
+            refs[i] = new TaskDef( name, classname );
+        }
+        return refs;
     }
 
     private static File getBasedir( File anchor, Element element )
@@ -121,7 +152,7 @@
         return key;
     }
 
-    private static Info createInfo( Element info )
+    public static Info createInfo( Element info )
     {
         String group = 
           ElementHelper.getValue( 

Added: avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/tasks/DeclareTask.java
==============================================================================
--- (empty file)
+++ avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/tasks/DeclareTask.java
Fri May 28 20:54:07 2004
@@ -0,0 +1,245 @@
+/* 
+ * Copyright 2004 Apache Software Foundation
+ * Licensed  under the  Apache License,  Version 2.0  (the "License");
+ * you may not use  this file  except in  compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed  under the  License is distributed on an "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+ * implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.avalon.tools.tasks;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.BuildException;
+
+import org.apache.avalon.tools.home.Home;
+import org.apache.avalon.tools.project.Definition;
+import org.apache.avalon.tools.project.Resource;
+import org.apache.avalon.tools.project.ResourceRef;
+import org.apache.avalon.tools.project.Info;
+import org.apache.avalon.tools.project.Policy;
+import org.apache.avalon.tools.project.Plugin;
+import org.apache.avalon.tools.project.Plugin.TaskDef;
+
+/**
+ * Load a plugin. 
+ *
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
+ * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
+ */
+public class DeclareTask extends DeliverableTask
+{
+    private static final String FILENAME = "plugin.xml";
+
+    public void init() throws BuildException 
+    {
+        super.init();
+    }
+
+    public void execute() throws BuildException 
+    {
+        log( "creating plugin declaration" );
+        final Definition def = getDefinition();
+
+        try
+        {
+            final File file = getPluginFile();
+            file.createNewFile();
+            final OutputStream output = new FileOutputStream( file );
+
+            try
+            {
+                writePluginDef( output, def );
+            }
+            finally
+            {
+                closeStream( output );
+            }
+        }
+        catch( Throwable e )
+        {
+            throw new BuildException( e );
+        }
+    }
+
+    private File getPluginFile()
+    {
+        Project project = getProject();
+        File dir = DeliverableTask.getTargetDeliverablesDirectory( project );
+        File ants = new File( dir, "ants" );
+        createDirectory( ants );
+        Definition def = getDefinition();
+        Info info = def.getInfo();
+        String filename = getFilename( info );
+        return new File( ants, filename );
+    }
+
+    private String getFilename( Info info )
+    {
+        String version = info.getVersion();
+        if( null == version )
+        {
+            return info.getName() + ".ant";
+        }
+        else
+        {
+            return info.getName() + "-" + version + ".ant";
+        }
+    }
+
+    public void writePluginDef( final OutputStream output, final Definition def )
+        throws IOException
+    {
+        final Writer writer = new OutputStreamWriter( output );
+        writeHeader( writer );
+        writePlugin( writer, def );
+        writer.flush();
+    }
+
+   /**
+    * Write the XML header.
+    * @param writer the writer
+     * @throws IOException if unable to write xml
+    */
+    private void writeHeader( final Writer writer )
+        throws IOException
+    {
+        writer.write( "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" );
+    }
+
+    private void writePlugin( final Writer writer, final Definition def )
+        throws IOException
+    {
+        final Info info = def.getInfo();
+
+        writer.write( "\n\n<plugin>" );
+        writeInfo( writer, info );
+        if( def instanceof Plugin )
+        {
+            Plugin plugin = (Plugin) def;
+            writeTaskDefs( writer, plugin );
+        }
+        writeClasspath( writer, def );
+        writer.write( "\n</plugin>\n" );
+    }
+
+    private void writeTaskDefs( final Writer writer, final Plugin plugin )
+        throws IOException
+    {
+        writer.write( "\n  " );
+        writer.write( "<tasks>" );
+        TaskDef[] defs = plugin.getTaskDefs();
+        for( int i=0; i<defs.length; i++ )
+        {
+            TaskDef def = defs[i];
+            writer.write( 
+              "\n    <taskdef name=\"" 
+              + def.getName() 
+              + "\" class=\""
+              + def.getClassname() 
+              + "\"/>" );
+        }
+        writer.write( "\n  </tasks>" );
+    }
+
+    private void writeInfo( final Writer writer, final Info info )
+        throws IOException
+    {
+        final String name = info.getName();
+        final String group = info.getGroup();
+        final String version = info.getVersion();
+        final String type = info.getType();
+
+        writer.write( "\n  <info>" );
+        writer.write( "\n    <name>" + name + "</name>" );
+        writer.write( "\n    <group>" + group + "</group>" );
+        if( null != version )
+        {
+            writer.write( "\n    <version>" + version + "</version>" );
+        }
+        writer.write( "\n    <type>" + type + "</type>" );
+        writer.write( "\n  </info>" );
+    }
+
+    private void writeClasspath( final Writer writer, final Definition def )
+        throws IOException
+    {
+        writer.write( "\n  <classpath>" );
+        final String pad = "    ";
+        ResourceRef[] resources = getHome().getRepository().getResourceRefs( def );
+        writeResourceRefs( writer, pad, resources );
+        writeResource( writer, pad, def );
+        writer.write( "\n  </classpath>" );
+    }
+
+    private void writeResourceRefs( final Writer writer, String pad, final ResourceRef[]
resources )
+        throws IOException
+    {
+        for( int i=0; i<resources.length; i++ )
+        {
+            ResourceRef ref = resources[i];
+            Policy policy = ref.getPolicy();
+            if( policy.isRuntimeEnabled() )
+            {
+                Resource resource = getHome().getResource( ref );
+                writeResource( writer, pad, resource );
+            }
+        }
+    }
+
+    private void writeResource( final Writer writer, String pad, final Resource resource
)
+        throws IOException
+    {
+        Info info = resource.getInfo();
+        String name = info.getName();
+        String group = info.getGroup();
+        String version = info.getVersion();
+        String type = info.getType();
+
+        writer.write( "\n" );
+        writer.write( pad );
+        writer.write( "<" + type + ">" );
+        writer.write( group );
+        writer.write( "/" );
+        writer.write( name );
+
+        if( null != version )
+        {
+            writer.write( "#" );
+            writer.write( version );
+        }
+        writer.write( "</" + type + ">" );
+    }
+
+    private void closeStream( final OutputStream output )
+    {
+        if( null != output )
+        {
+            try
+            {
+                output.close();
+            }
+            catch( IOException e )
+            {
+                // ignore
+            }
+        }
+    }
+
+}

Modified: avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/tasks/JavacTask.java
==============================================================================
--- avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/tasks/JavacTask.java
(original)
+++ avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/tasks/JavacTask.java
Fri May 28 20:54:07 2004
@@ -78,6 +78,7 @@
               getHome().getRepository().createPath( 
                 getProject(), getDefinition() );
             compile( src, classes, classpath );
+            copy( src, classes );
         }
     }
 
@@ -105,6 +106,20 @@
         javac.setClasspath( classpath );
         javac.init();
         javac.execute();
+    }
+
+    private void copy( File sources, File classes )
+    {        
+        Copy copy = (Copy) getProject().createTask( "copy" );
+        copy.setTodir( classes );
+
+        FileSet fileset = new FileSet();
+        fileset.setDir( sources );
+        fileset.setIncludes( "**/**" );
+        fileset.setExcludes( "**/_svn/**,**/*.java,**/package.html" );
+        copy.addFileset( fileset );
+        copy.init();
+        copy.execute();
     }
 
     private boolean getDebugProperty()

Added: avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/tasks/PluginTask.java
==============================================================================
--- (empty file)
+++ avalon/trunk/tools/project/core/src/main/org/apache/avalon/tools/tasks/PluginTask.java
Fri May 28 20:54:07 2004
@@ -0,0 +1,164 @@
+/* 
+ * Copyright 2004 Apache Software Foundation
+ * Licensed  under the  Apache License,  Version 2.0  (the "License");
+ * you may not use  this file  except in  compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed  under the  License is distributed on an "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+ * implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.avalon.tools.tasks;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.ComponentHelper;
+import org.apache.tools.ant.taskdefs.Antlib;
+import org.apache.tools.ant.helper.ProjectHelper2;
+import org.apache.tools.ant.UnknownElement;
+
+import org.apache.avalon.tools.home.Home;
+import org.apache.avalon.tools.project.Definition;
+import org.apache.avalon.tools.project.Info;
+import org.apache.avalon.tools.project.Resource;
+import org.apache.avalon.tools.project.Plugin;
+import org.apache.avalon.tools.project.Plugin.TaskDef;
+import org.apache.avalon.tools.project.builder.XMLDefinitionBuilder;
+import org.apache.avalon.tools.util.ElementHelper;
+
+import org.w3c.dom.Element;
+
+/**
+ * Load a plugin. 
+ *
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
+ * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
+ */
+public class PluginTask extends HomeTask
+{
+    private String m_id;
+    private File m_definition;
+    private String m_uri;
+
+    public void setId( String id )
+    {
+        m_id = id;
+    }
+
+    private String getId()
+    {
+        if( null != m_id )
+        {
+            return m_id;
+        }
+        else
+        {
+            final String error = 
+              "Missing plugin id attribute.";
+            throw new BuildException( error );
+        }
+    }
+
+    public void execute() throws BuildException 
+    {
+        try
+        {
+            //
+            // get the xml definition of the plugin
+            //
+
+            String id = getId();
+            Info info = Info.create( id, "ant" );
+            Project project = getProject();
+            Resource resource = new Resource( info );
+            m_definition = getHome().getRepository().getResource( project, resource );
+
+            //
+            // create a utility data object from the defintion
+            //
+
+            AntLibData data = new AntLibData( getProject(), m_definition );
+            ClassLoader classloader = project.createClassLoader( data.getPath() );
+            String uri = data.getInfo().getURI(); 
+
+            //
+            // install the ant task defintions
+            //
+
+            ComponentHelper helper =
+              ComponentHelper.getComponentHelper( project );
+            TaskDef[] defs = data.getTaskDefs();
+            for( int i=0; i<defs.length; i++ )
+            {
+                TaskDef def = defs[i];
+                Class taskClass = classloader.loadClass( def.getClassname() );
+                String name = uri + ":" + def.getName();
+                helper.addTaskDefinition( name, taskClass );
+                log( "Added task definition \"" + name + "\"", Project.MSG_DEBUG );
+            }
+        }
+        catch( Throwable e )
+        {
+            throw new BuildException( e );
+        }
+    }
+
+    private class AntLibData 
+    {
+        private final Info m_info;
+        private final Path m_path = new Path( project );
+        private final TaskDef[] m_tasks;
+
+        public AntLibData( Project project, File file ) throws Exception
+        {
+            Element root = ElementHelper.getRootElement( file );
+            Element infoElement = ElementHelper.getChild( root, "info" );
+            m_info = XMLDefinitionBuilder.createInfo( infoElement );
+            Element tasksElement = ElementHelper.getChild( root, "tasks" );
+            m_tasks = XMLDefinitionBuilder.getTaskDefs( tasksElement );
+
+            Element classpathElement = ElementHelper.getChild( root, "classpath" );
+            Element[] children = ElementHelper.getChildren( classpathElement );
+            for( int i=0; i<children.length; i++ )
+            {
+                Element child = children[i];
+                String value = ElementHelper.getValue( child );
+                String type = child.getTagName();
+                Info info = Info.create( value, type );
+                Resource resource = new Resource( info );
+                File jar = 
+                  getHome().getRepository().getResource( 
+                    project, resource );
+                m_path.createPathElement().setLocation( jar );
+            }
+        }
+
+        public Info getInfo()
+        {
+            return m_info;
+        }
+
+        public TaskDef[] getTaskDefs()
+        {
+            return m_tasks;
+        }
+
+        public Path getPath()
+        {
+            return m_path;
+        }
+    }
+}

Modified: avalon/trunk/tools/project/core/src/test/index.xml
==============================================================================
--- avalon/trunk/tools/project/core/src/test/index.xml	(original)
+++ avalon/trunk/tools/project/core/src/test/index.xml	Fri May 28 20:54:07 2004
@@ -55,13 +55,30 @@
 
   <projects>
 
-    <project basedir="projects/demo">
+    <project basedir="projects/sample">
+      <info>
+        <group>demo</group>
+        <name>sample</name>
+        <version>1.0</version>
+        <type>jar</type>
+      </info>
+      <dependencies>
+        <plugins>
+          <pluginref key="demo"/>
+        </plugins>
+      </dependencies>
+    </project>
+
+    <plugin basedir="projects/demo">
       <info>
         <group>demo</group>
         <name>demo</name>
         <version>1.0</version>
         <type>jar</type>
       </info>
+      <tasks>
+        <taskdef name="hello" class="org.apache.avalon.demo.StandardDemo"/>
+      </tasks>
       <dependencies>
         <resources>
           <resourceref key="avalon-framework-api"/>
@@ -71,36 +88,33 @@
           <projectref key="gizmo"/>
         </projects>
       </dependencies>
-    </project>
+    </plugin>
 
-    <project basedir="projects/gizmo">
+    <project basedir="projects/widget">
       <info>
         <group>demo</group>
-        <name>gizmo</name>
+        <name>widget</name>
         <version>1.0</version>
         <type>jar</type>
       </info>
       <dependencies>
-        <resources>
-          <resourceref key="avalon-util-i18n"/>
-        </resources>
-        <plugins>
-          <pluginref key="compile"/>
-        </plugins>
+        <projects>
+          <projectref key="gizmo"/>
+        </projects>
       </dependencies>
     </project>
 
-    <project basedir="projects/widget">
+    <project basedir="projects/gizmo">
       <info>
         <group>demo</group>
-        <name>widget</name>
+        <name>gizmo</name>
         <version>1.0</version>
         <type>jar</type>
       </info>
       <dependencies>
-        <projects>
-          <projectref key="gizmo"/>
-        </projects>
+        <resources>
+          <resourceref key="avalon-util-i18n"/>
+        </resources>
       </dependencies>
     </project>
 

Modified: avalon/trunk/tools/project/core/src/test/projects/demo/build.xml
==============================================================================
--- avalon/trunk/tools/project/core/src/test/projects/demo/build.xml	(original)
+++ avalon/trunk/tools/project/core/src/test/projects/demo/build.xml	Fri May 28 20:54:07 2004
@@ -6,6 +6,7 @@
 
   <x:prepare/>
   <x:javac/>
+  <x:declare/>
   <x:jar/>
   <x:test/>
   <x:install/>

Modified: avalon/trunk/tools/project/core/src/test/projects/demo/src/main/org/apache/avalon/demo/StandardDemo.java
==============================================================================
--- avalon/trunk/tools/project/core/src/test/projects/demo/src/main/org/apache/avalon/demo/StandardDemo.java
(original)
+++ avalon/trunk/tools/project/core/src/test/projects/demo/src/main/org/apache/avalon/demo/StandardDemo.java
Fri May 28 20:54:07 2004
@@ -17,6 +17,9 @@
 
 package org.apache.avalon.demo;
 
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+
 import org.apache.avalon.widget.Widget;
 import org.apache.avalon.widget.StandardWidget;
 import org.apache.avalon.gizmo.Gizmo;
@@ -29,11 +32,17 @@
  * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
  * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
  */
-public class StandardDemo implements Demo 
+public class StandardDemo extends Task implements Demo 
 {
-    public StandardDemo()
+
+    public void init()
     {
         Widget widget = new StandardWidget();
         Gizmo gizmo = new StandardGizmo();
+    }
+
+    public void execute()
+    {
+        log( "hello world!" );
     }
 }

Added: avalon/trunk/tools/project/core/src/test/projects/sample/build.xml
==============================================================================
--- (empty file)
+++ avalon/trunk/tools/project/core/src/test/projects/sample/build.xml	Fri May 28 20:54:07
2004
@@ -0,0 +1,9 @@
+
+<project name="sample" default="" basedir="." 
+    xmlns:x="antlib:org.apache.avalon.tools" xmlns:d="jar:demo/demo#1.0" > 
+
+  <x:project index="../../index.xml"/>
+  <x:plugin id="demo/demo#1.0"/>
+  <d:hello/>
+
+</project>

Added: avalon/trunk/tools/project/core/src/test/projects/sample/src/main/org/apache/avalon/sample/Sample.java
==============================================================================
--- (empty file)
+++ avalon/trunk/tools/project/core/src/test/projects/sample/src/main/org/apache/avalon/sample/Sample.java
Fri May 28 20:54:07 2004
@@ -0,0 +1,29 @@
+/* 
+ * Copyright 2004 Apache Software Foundation
+ * Licensed  under the  Apache License,  Version 2.0  (the "License");
+ * you may not use  this file  except in  compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed  under the  License is distributed on an "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+ * implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.avalon.sample;
+
+
+/**
+ * Sample interface. 
+ *
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
+ * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
+ */
+public interface Sample 
+{
+}

Added: avalon/trunk/tools/project/core/src/test/projects/sample/src/main/org/apache/avalon/sample/StandardSample.java
==============================================================================
--- (empty file)
+++ avalon/trunk/tools/project/core/src/test/projects/sample/src/main/org/apache/avalon/sample/StandardSample.java
Fri May 28 20:54:07 2004
@@ -0,0 +1,31 @@
+/* 
+ * Copyright 2004 Apache Software Foundation
+ * Licensed  under the  Apache License,  Version 2.0  (the "License");
+ * you may not use  this file  except in  compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed  under the  License is distributed on an "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+ * implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.avalon.sample;
+
+/**
+ * Sample demo implementation. 
+ *
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
+ * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
+ */
+public class StandardSample implements Sample 
+{
+    public StandardSample()
+    {
+    }
+}

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message