avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject svn commit: rev 20237 - in avalon/trunk/tools/project: . 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/tasks src/test src/test/plugins src/test/projects/gizmo src/test/projects/gizmo/src src/test/projects/gizmo/src/main src/test/projects/gizmo/src/main/org src/test/projects/gizmo/src/main/org/apache src/test/projects/gizmo/src/main/org/apache/avalon src/test/projects/gizmo/src/main/org/apache/avalon/gizmo
Date Sun, 23 May 2004 07:18:22 GMT
Author: mcconnell
Date: Sun May 23 00:18:21 2004
New Revision: 20237

Added:
   avalon/trunk/tools/project/src/main/org/apache/avalon/tools/event/
   avalon/trunk/tools/project/src/main/org/apache/avalon/tools/event/AbstractListener.java
   avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/
   avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/HomeTask.java
   avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/JavacTask.java
   avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/PrepareTask.java
   avalon/trunk/tools/project/src/test/projects/gizmo/build.properties
   avalon/trunk/tools/project/src/test/projects/gizmo/src/
   avalon/trunk/tools/project/src/test/projects/gizmo/src/main/
   avalon/trunk/tools/project/src/test/projects/gizmo/src/main/org/
   avalon/trunk/tools/project/src/test/projects/gizmo/src/main/org/apache/
   avalon/trunk/tools/project/src/test/projects/gizmo/src/main/org/apache/avalon/
   avalon/trunk/tools/project/src/test/projects/gizmo/src/main/org/apache/avalon/gizmo/
   avalon/trunk/tools/project/src/test/projects/gizmo/src/main/org/apache/avalon/gizmo/Gizmo.java
   avalon/trunk/tools/project/src/test/projects/gizmo/src/main/org/apache/avalon/gizmo/StandardGizmo.java
Removed:
   avalon/trunk/tools/project/src/test/plugins/
Modified:
   avalon/trunk/tools/project/build.xml
   avalon/trunk/tools/project/src/main/org/apache/avalon/tools/antlib.xml
   avalon/trunk/tools/project/src/main/org/apache/avalon/tools/home/Home.java
   avalon/trunk/tools/project/src/main/org/apache/avalon/tools/project/ProjectTask.java
   avalon/trunk/tools/project/src/test/index.xml
   avalon/trunk/tools/project/src/test/projects/gizmo/build.xml
Log:
Catching up with Niclas.

Modified: avalon/trunk/tools/project/build.xml
==============================================================================
--- avalon/trunk/tools/project/build.xml	(original)
+++ avalon/trunk/tools/project/build.xml	Sun May 23 00:18:21 2004
@@ -8,6 +8,8 @@
   <property name="src.main.dir" value="${src}/${src.main}"/>
   <property name="src.test" value="test"/>
   <property name="src.test.dir" value="${src}/${src.test}"/>
+  <property name="src.library" value="library"/>
+  <property name="src.library.dir" value="${src}/${src.library}"/>
 
   <property name="target" value="target"/>
   <property name="target.classes" value="classes"/>
@@ -37,16 +39,28 @@
   </target>
 
   <target name="install" depends="jar">
-    <copy toDir="${ant.home}/lib" 
+    <mkdir dir="${user.home}/.ant/lib"/>
+    <copy toDir="${user.home}/.ant/lib" 
        file="${target}/${toolkit.jar}"/>
   </target>
 
-  <target name="test">
+  <target name="test-prepare">
     <mkdir dir="${target.test.dir}"/>
     <copy toDir="${target.test.dir}">
-      <fileset dir="${src.test.dir}"/>
+      <fileset dir="${src.test.dir}">
+        <exclude name="**/_svn/**"/>
+        <exclude name="**/.svn/**"/>
+      </fileset>
+      <fileset dir="${src}">
+        <include name="${src.library}/**"/>
+        <exclude name="**/_svn/**"/>
+        <exclude name="**/.svn/**"/>
+      </fileset>
     </copy>
-    <ant dir="${target.test.dir}/projects/demo" />
+  </target>
+
+  <target name="test" depends="test-prepare">
+    <ant dir="${target.test.dir}/projects/gizmo" />
   </target>
 
   <target name="clean">

Modified: avalon/trunk/tools/project/src/main/org/apache/avalon/tools/antlib.xml
==============================================================================
--- avalon/trunk/tools/project/src/main/org/apache/avalon/tools/antlib.xml	(original)
+++ avalon/trunk/tools/project/src/main/org/apache/avalon/tools/antlib.xml	Sun May 23 00:18:21
2004
@@ -1,4 +1,7 @@
 <?xml version="1.0"?>
 <antlib xmlns:current="ant:current"> 
-  <typedef name="project" classname="org.apache.avalon.tools.project.ProjectTask"/>

+  <taskdef name="project" classname="org.apache.avalon.tools.project.ProjectTask"/>

+  <typedef name="home" classname="org.apache.avalon.tools.home.Home"/> 
+  <taskdef name="prepare" classname="org.apache.avalon.tools.tasks.PrepareTask"/> 
+  <taskdef name="javac" classname="org.apache.avalon.tools.tasks.JavacTask"/> 
 </antlib> 

Added: avalon/trunk/tools/project/src/main/org/apache/avalon/tools/event/AbstractListener.java
==============================================================================
--- (empty file)
+++ avalon/trunk/tools/project/src/main/org/apache/avalon/tools/event/AbstractListener.java
Sun May 23 00:18:21 2004
@@ -0,0 +1,134 @@
+/* 
+ * 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.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. 
+ *
+ * @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
+{
+    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.
+     *
+     * @param event An event with any relevant extra information.
+     *              Must not be <code>null</code>.
+     */
+    public void buildStarted(BuildEvent event)
+    {
+    }
+
+    /**
+     * Signals that the last target has finished. This event
+     * will still be fired if an error occurred during the build.
+     *
+     * @param event An event with any relevant extra information.
+     *              Must not be <code>null</code>.
+     *
+     * @see BuildEvent#getException()
+     */
+    public void buildFinished(BuildEvent event)
+    {
+    }
+
+    /**
+     * Signals that a target is starting.
+     *
+     * @param event An event with any relevant extra information.
+     *              Must not be <code>null</code>.
+     *
+     * @see BuildEvent#getTarget()
+     */
+    public void targetStarted(BuildEvent event)
+    {
+    }
+
+    /**
+     * Signals that a target has finished. This event will
+     * still be fired if an error occurred during the build.
+     *
+     * @param event An event with any relevant extra information.
+     *              Must not be <code>null</code>.
+     *
+     * @see BuildEvent#getException()
+     */
+    public void targetFinished(BuildEvent event)
+    {
+    }
+
+    /**
+     * Signals that a task is starting.
+     *
+     * @param event An event with any relevant extra information.
+     *              Must not be <code>null</code>.
+     *
+     * @see BuildEvent#getTask()
+     */
+    public void taskStarted(BuildEvent event)
+    {
+    }
+
+    /**
+     * Signals that a task has finished. This event will still
+     * be fired if an error occurred during the build.
+     *
+     * @param event An event with any relevant extra information.
+     *              Must not be <code>null</code>.
+     *
+     * @see BuildEvent#getException()
+     */
+    public void taskFinished(BuildEvent event)
+    {
+    }
+
+    /**
+     * Signals a message logging event.
+     *
+     * @param event An event with any relevant extra information.
+     *              Must not be <code>null</code>.
+     *
+     * @see BuildEvent#getMessage()
+     * @see BuildEvent#getPriority()
+     */
+    public void messageLogged(BuildEvent event)
+    {
+    }
+
+}

Modified: avalon/trunk/tools/project/src/main/org/apache/avalon/tools/home/Home.java
==============================================================================
--- avalon/trunk/tools/project/src/main/org/apache/avalon/tools/home/Home.java	(original)
+++ avalon/trunk/tools/project/src/main/org/apache/avalon/tools/home/Home.java	Sun May 23
00:18:21 2004
@@ -25,11 +25,15 @@
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
+import org.apache.tools.ant.ProjectComponent;
+import org.apache.tools.ant.taskdefs.Ant;
+import org.apache.tools.ant.taskdefs.Ant.Reference;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.types.Path;
 import org.apache.tools.ant.util.FileUtils;
 import org.apache.tools.ant.taskdefs.Sequential;
+import org.apache.tools.ant.taskdefs.Property;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -39,7 +43,7 @@
 import org.w3c.dom.NodeList;
 import org.xml.sax.SAXException;
 
-import org.apache.avalon.tools.util.ElementHelper;
+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;
@@ -47,6 +51,7 @@
 import org.apache.avalon.tools.project.PluginRef;
 import org.apache.avalon.tools.project.Plugin;
 import org.apache.avalon.tools.project.builder.XMLDefinitionBuilder;
+import org.apache.avalon.tools.util.ElementHelper;
 
 /**
  *
@@ -55,10 +60,46 @@
  */
 public class Home 
 {
-    private final File m_file;
+    private static Home HOME;
+
+    public static boolean isInitialized()
+    {
+        return null != HOME;
+    }
+
+    public static void initialize( Project project, File index )
+    {
+        if( !isInitialized() )
+        {
+            try
+            {
+                HOME = new Home( project, index );
+            }
+            catch( Throwable e )
+            {
+                final String error =
+                  "Error occured while loading system defintion.";
+                throw new BuildException( error, e );
+            }
+        }
+    }
+
+    public static Home getHome( Project project )
+    {
+        if( !isInitialized() )
+        {
+            final String error =
+              "Home has not been initialized.";
+            throw new BuildException( error );
+        }
+        project.addReference( "urn:avalon.home", HOME );
+        return HOME;
+    }
+
     private final Project m_project;
     private final Repository m_repository;
     private final File m_home;
+    private final File m_file;
 
     private final Hashtable m_resources = new Hashtable();
 
@@ -68,6 +109,10 @@
         m_project = project;
         m_home = file.getParentFile();
 
+        HOME = this;
+ 
+        project.addBuildListener( new AbstractListener( this ) );
+
         Element root = ElementHelper.getRootElement( file );
         project.log( "home: " + m_home, Project.MSG_DEBUG );
 
@@ -109,7 +154,8 @@
             String key = resource.getKey();
             m_resources.put( key, resource );
             m_project.log( 
-              "resource: " + resource + " key=" + key, Project.MSG_DEBUG );
+              "resource: " + resource + " key=" + key, 
+              Project.MSG_DEBUG );
         }
     }
 
@@ -118,7 +164,9 @@
         if( null == projects ) return;
 
         Element[] entries = ElementHelper.getChildren( projects, "project" );
-        m_project.log( "projects: " + entries.length, Project.MSG_DEBUG );
+        m_project.log( 
+          "projects: " + entries.length, 
+          Project.MSG_DEBUG );
         for( int i=0; i<entries.length; i++ )
         {
             Element element = entries[i];
@@ -127,7 +175,8 @@
             String key = definition.getKey();
             m_resources.put( key, definition );
             m_project.log( 
-              "project: " + definition + " key=" + key, Project.MSG_DEBUG );
+              "project: " + definition + " key=" + key, 
+              Project.MSG_DEBUG );
         }
     }
 
@@ -192,56 +241,27 @@
 
     public void build( Definition definition )
     {
-        Definition[] targets = getBuildSequence( definition );
-        m_project.log( "\n  build sequence for definition: " + definition + "\n");
-        for( int i=0; i<targets.length; i++ )
-        {
-            Definition def = targets[i];
-            m_project.log( "   target (" + (i+1) + "): " + def ); 
-        }
-
-        for( int i=0; i<targets.length; i++ )
-        {
-            Definition def = targets[i];
-            buildProject( def );
-        }
-
-        m_project.log( "composite build complete" );
-    }
-
-    private void buildProject( Definition definition )
-    {
-        m_project.log( "\nbuild target: " + definition  );
-        m_project.log( "basedir: " + definition.getBasedir()  );
-
-        Path path = getRepository().createPath( m_project, definition );
-        m_project.log( "compile path: " + path );
-
-        //
-        // here is where we need to launch plugins that will 
-        // result in population of the repository
-        //
-
-        m_project.log( "build complete" );
+        Ant ant = (Ant) m_project.createTask( "ant" );
+        Property property = ant.createProperty();
+        property.setName( "urn:avalon.definition.key" );
+        property.setValue( definition.getKey() );
+        ant.setDir( definition.getBasedir() );
+        ant.setInheritRefs( true );
+        ant.init();
+        ant.execute();
     }
 
-    private Definition[] getBuildSequence( Definition definition )
+    public Definition[] getBuildSequence( Definition definition )
     {
         ArrayList visited = new ArrayList();
         ArrayList targets = new ArrayList();
-        PluginRef[] pluginRefs = definition.getPluginRefs();
-        for( int i=0; i<pluginRefs.length; i++ )
-        {
-            Definition def = getDefinition( pluginRefs[i] );
-            getBuildSequence( visited, targets, def );
-        }
         ProjectRef[] refs = definition.getProjectRefs();
         for( int i=0; i<refs.length; i++ )
         {
             Definition def = getDefinition( refs[i] );
             getBuildSequence( visited, targets, def );
         }
-        targets.add( definition );
+        //targets.add( definition );
         return (Definition[]) targets.toArray( new Definition[0] );
     }
 
@@ -249,21 +269,6 @@
     {
         if( visited.contains( definition ) ) return;
         visited.add( definition );
-
-        PluginRef[] pluginRefs = definition.getPluginRefs();
-        for( int i=0; i<pluginRefs.length; i++ )
-        {
-            Definition plugin = getDefinition( pluginRefs[i] );
-            if( visited.contains( plugin ) )
-            {
-                final String error =
-                  "Recursive reference identified in project: " 
-                     + definition 
-                     + " in plugin " + plugin + ".";
-                throw new BuildException( error );
-            }
-            getBuildSequence( visited, targets, plugin );
-        }
 
         ProjectRef[] refs = definition.getProjectRefs();
         for( int i=0; i<refs.length; i++ )

Modified: avalon/trunk/tools/project/src/main/org/apache/avalon/tools/project/ProjectTask.java
==============================================================================
--- avalon/trunk/tools/project/src/main/org/apache/avalon/tools/project/ProjectTask.java	(original)
+++ avalon/trunk/tools/project/src/main/org/apache/avalon/tools/project/ProjectTask.java	Sun
May 23 00:18:21 2004
@@ -22,6 +22,7 @@
 
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.taskdefs.Property;
 import org.apache.tools.ant.taskdefs.Sequential;
 import org.apache.tools.ant.types.Path;
 
@@ -36,11 +37,11 @@
  */
 public class ProjectTask extends Sequential
 {
-    private File m_index;
+    private static final String BUILD_PROPERTIES = "build.properties";
 
-    private File m_definition;
+    private File m_index;
 
-    private Home m_home;
+    private File m_props;
 
     private String m_key;
 
@@ -64,51 +65,156 @@
         }
     }
 
-    public void execute() throws BuildException 
+    public void setProperties( File file ) throws BuildException
     {
-        //
-        // get the Home defintion
-        //
-
-        File index = getIndex();
-        log( "index: " + index, Project.MSG_INFO );
-        try
+        if( !file.exists() )
         {
-            m_home = new Home( getProject(), index );
+            final String error = 
+              "Properties file [" + file + "] does not exist.";
+            throw new BuildException( error );
         }
-        catch( Throwable e )
+        if( file.isAbsolute() )
         {
-            final String error =
-              "Error occured while loading system defintion.";
-            throw new BuildException( error, e );
+            m_props = getCanonicalFile( file );
         }
+        else
+        {
+            String path = file.toString();
+            File basedir = getProject().getBaseDir();
+            File index = new File( basedir, path );
+            m_props = getCanonicalFile( index );
+        }
+    }
 
-        Repository repo = m_home.getRepository();
-        File cache = repo.getCacheDirectory();
 
+    public void execute() throws BuildException 
+    {
         //
-        // get the definition for this project
+        // make sure that the build.properties file is loaded
         //
-   
-        log( "project: " + getProject().getName(), Project.MSG_DEBUG );
-        log( "basedir: " + getProject().getBaseDir(), Project.MSG_DEBUG );
 
-        final String key = getKey();
-        Definition definition = m_home.getDefinition( key );
-        Info info = definition.getInfo();
+        Property props = (Property) getProject().createTask( "property" );
+        props.setFile( getPropertiesFile() );
+        props.init();
+        props.execute();
+
+        //
+        // make sure we have a common defintion available
+        //
 
-        log( "name: " + info.getName(), Project.MSG_DEBUG );
-        log( "group: " + info.getGroup(), Project.MSG_DEBUG );
-        log( "version: " + info.getVersion(), Project.MSG_DEBUG );
+        final String key = getKey();
+        if( !Home.isInitialized() )
+        {
+            log( "index: " + m_index, Project.MSG_INFO );
+            Home.initialize( getProject(), m_index );
+        }
+        Home home = Home.getHome( getProject() );
 
         //
-        // Path path = repo.createPath( getProject(), m_home, definition );
-        // log( "path: " + path );
+        // load the defintion for this project
+        // and populate the project with required properties
         //
 
-        m_home.build( definition );
+        Definition definition = home.getDefinition( key );
+        setProjectProperties( home, definition );
+        log( "build: " + definition );
+        super.execute();
+
+        /*
+        if( !Home.isInitialized() )
+        {
+            log( "index: " + m_index, Project.MSG_INFO );
+            Home.initialize( getProject(), m_index );
+            Home home = Home.getHome( getProject() );
+
+            //
+            // log the build sequence
+            //
+
+            Definition definition = home.getDefinition( key );
+            Definition[] targets = home.getBuildSequence( definition );
+            log( "build sequence for definition: " + definition + "\n");
+            for( int i=0; i<targets.length; i++ )
+            {
+                Definition def = targets[i];
+                getProject().log( "   target (" + (i+1) + "): " + def ); 
+            }
+            getProject().log( "" );
+
+            //
+            // execute the build sequence
+            //
+
+            for( int i=0; i<targets.length; i++ )
+            {
+                Definition def = targets[i];
+                home.build( def );
+            }
+
+            setProjectProperties( home, definition );
+        }
+        else
+        {
+            Home home = Home.getHome( getProject() );          
+            Definition definition = home.getDefinition( key );
+            buildProject( home, definition );
+        }
+        */
+    }
 
+    private File getPropertiesFile()
+    {
+        if( null == m_props )
+        {
+            return new File( getProject().getBaseDir(), BUILD_PROPERTIES );
+        }
+        else
+        {
+            return m_props;
+        }
+    }
+
+    private void setProjectProperties( Home home, Definition definition )
+    {
+        File root = home.getHomeDirectory();
+        File lib = new File( root, "library" );
+
+        getProject().setProperty( 
+          "avalon.home", root.toString() );
+        getProject().setProperty( 
+          "avalon.library", lib.toString() );
+
+        getProject().setProperty( 
+          "avalon.project.key", definition.getKey() );
+        getProject().setProperty( 
+          "avalon.project.name", definition.getInfo().getName() );
+        getProject().setProperty( 
+          "avalon.project.group", definition.getInfo().getGroup() );
+        getProject().setProperty( 
+          "avalon.project.version", definition.getInfo().getVersion() );
+    }
+
+    private void buildProject( Home home, Definition definition )
+    {
+        log( "build: " + definition );
+        setProjectProperties( home, definition );
         super.execute();
+    }
+
+    private Home createHome()
+    {
+        File index = getIndex();
+        log( "index: " + index, Project.MSG_INFO );
+        try
+        {
+            return new Home( getProject(), index );
+        }
+        catch( Throwable e )
+        {
+            final String error =
+              "Error occured while loading system defintion.";
+            throw new BuildException( error, e );
+        }
     }
 
     private String getKey()

Added: avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/HomeTask.java
==============================================================================
--- (empty file)
+++ avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/HomeTask.java	Sun May
23 00:18:21 2004
@@ -0,0 +1,75 @@
+/* 
+ * 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 org.apache.tools.ant.Task;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.taskdefs.Property;
+import org.apache.tools.ant.taskdefs.Mkdir;
+
+import org.apache.avalon.tools.home.Home;
+import org.apache.avalon.tools.project.Definition;
+
+/**
+ * Load a goal. 
+ *
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
+ * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
+ */
+public abstract class HomeTask extends Task
+{
+    private Home m_home;
+    private Definition m_definition;
+
+    public void init() throws BuildException 
+    {
+        m_home = Home.getHome( getProject() );
+        String key = getProject().getProperty( "avalon.project.key" );
+        m_definition = m_home.getDefinition( key );
+    }
+
+    public Home getHome()
+    {
+        return m_home;
+    }
+
+    public Definition getDefinition()
+    {
+        return m_definition;
+    }
+
+    public void setProjectProperty( String key, String value )
+    {
+        Property props = (Property) getProject().createTask( "property" );
+        props.setName( key );
+        props.setValue( value );
+        props.init();
+        props.execute();
+    }
+
+    public void createDirectory( File dir )
+    {
+        Mkdir mkdir = (Mkdir) getProject().createTask( "mkdir" );
+        mkdir.setDir( dir );
+        mkdir.init();
+        mkdir.execute();
+    }
+}

Added: avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/JavacTask.java
==============================================================================
--- (empty file)
+++ avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/JavacTask.java	Sun May
23 00:18:21 2004
@@ -0,0 +1,127 @@
+/* 
+ * 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 org.apache.tools.ant.Task;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.taskdefs.Copy;
+import org.apache.tools.ant.taskdefs.Javac;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.types.Path;
+
+import org.apache.avalon.tools.home.Home;
+import org.apache.avalon.tools.project.Definition;
+
+/**
+ * Load a goal. 
+ *
+ * @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 JavacTask extends HomeTask
+{
+    public static final String CLASSES_KEY = "avalon.target.classes";
+    public static final String CLASSES_VALUE = "classes";
+
+    public static final String DEBUG_KEY = "java.compile.debug";
+    public static final boolean DEBUG_FLAG = false;
+
+    public static final String FORK_KEY = "java.compile.fork";
+    public static final boolean FORK_FLAG = false;
+
+    public void init() throws BuildException 
+    {
+        super.init();
+        setProjectProperty( CLASSES_KEY, CLASSES_VALUE );
+        setProjectProperty( DEBUG_KEY, "" + DEBUG_FLAG );
+        setProjectProperty( FORK_KEY, "" + FORK_FLAG );
+    }
+
+    public void execute() throws BuildException 
+    {
+        File src = getTargetSrcMainDirectory();
+        if( src.exists() )
+        {
+            File classes = getTargetClassesDirectory();
+            if( !classes.exists() )
+            {
+                log( "creating target classes directory" );
+                createDirectory( classes );
+            }
+            Path classpath = 
+              getHome().getRepository().createPath( 
+                getProject(), getDefinition() );
+            compile( src, classes, classpath );
+        }
+    }
+
+    private File getTargetSrcMainDirectory()
+    {
+        String src = getProject().getProperty( "avalon.target.src.main" );
+        return new File( getProject().getBaseDir(), src );
+    }
+
+    private File getTargetClassesDirectory()
+    {
+        String path = getProject().getProperty( "avalon.target" );
+        File target = new File( getProject().getBaseDir(), path );
+        String classes = getProject().getProperty( "avalon.target.classes" );
+        return new File( target, classes );
+    }
+
+    private void compile( File sources, File classes, Path classpath )
+    {        
+        File basedir = getProject().getBaseDir();
+        Javac javac = (Javac) getProject().createTask( "javac" );
+        Path src = javac.createSrc();
+        Path.PathElement element = src.createPathElement();
+        element.setLocation( sources );
+        javac.setDestdir( classes );
+        javac.setDebug( getDebugProperty() );
+        javac.setFork( getForkProperty() );
+        javac.setClasspath( classpath );
+        javac.init();
+        javac.execute();
+    }
+
+    private boolean getDebugProperty()
+    {
+        return getBooleanProperty( DEBUG_KEY, DEBUG_FLAG );
+    }
+
+    private boolean getForkProperty()
+    {
+        return getBooleanProperty( FORK_KEY, FORK_FLAG );
+    }
+
+    private boolean getBooleanProperty( String key, boolean fallback )
+    {
+        String value = getProject().getProperty( key );
+        if( null == value )
+        {
+            return fallback;
+        }
+        else
+        {
+            return getProject().toBoolean( value );
+        }
+    }
+}

Added: avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/PrepareTask.java
==============================================================================
--- (empty file)
+++ avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/PrepareTask.java	Sun
May 23 00:18:21 2004
@@ -0,0 +1,111 @@
+/* 
+ * 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 org.apache.tools.ant.Task;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.taskdefs.Copy;
+import org.apache.tools.ant.taskdefs.Property;
+import org.apache.tools.ant.types.FileSet;
+
+import org.apache.avalon.tools.home.Home;
+import org.apache.avalon.tools.project.Definition;
+import org.apache.avalon.tools.tasks.HomeTask;
+
+/**
+ * Load a goal. 
+ *
+ * @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 PrepareTask extends HomeTask
+{
+    public static String SRC = "src";
+    public static String TARGET = "target";
+    public static String TARGET_SRC = TARGET + "/src";
+    public static String TARGET_SRC_MAIN = TARGET_SRC + "/main";
+
+    public void init() throws BuildException 
+    {
+        setProjectProperty( "avalon.src", SRC );
+        setProjectProperty( "avalon.target", TARGET );
+        setProjectProperty( "avalon.target.src", TARGET_SRC );
+        setProjectProperty( "avalon.target.src.main", TARGET_SRC_MAIN );
+    }
+
+    public void execute() throws BuildException 
+    {
+        File target = getTargetDirectory();
+        if( !target.exists() )
+        {
+            log( "creating target directory" );
+            createDirectory( target );
+        }
+        File src = getSrcDirectory();
+        if( src.exists() )
+        {
+            copySrcToBuildWithFiltering( target );
+            copySrcToBuildWithoutFiltering( target );
+        }
+    }
+
+    private File getSrcDirectory()
+    {
+        String src = getProject().getProperty( "avalon.src" );
+        return new File( getProject().getBaseDir(), src );
+    }
+
+    private File getTargetDirectory()
+    {
+        String target = getProject().getProperty( "avalon.target" );
+        return new File( getProject().getBaseDir(), target );
+    }
+
+    private void copySrcToBuildWithFiltering( File target )
+    {
+        copySrcToBuild( target, true, "**/*.java,**/*.x*,**/*.properties", "" );
+    }
+
+    private void copySrcToBuildWithoutFiltering( File target )
+    {
+        copySrcToBuild( target, false, "**/*.*", "**/*.java,**/*.x*,**/*.properties" );
+    }
+
+    private void copySrcToBuild( 
+       File target, boolean filtering, String includes, String excludes )
+    {
+        File targetSrc = new File( target, SRC );
+        Copy copy = (Copy) getProject().createTask( "copy" );
+        copy.setTodir( targetSrc );
+        copy.setFiltering( filtering );
+        copy.setOverwrite( false );
+
+        FileSet fileset = new FileSet();
+        fileset.setDir( getSrcDirectory() );
+        fileset.setIncludes( includes );
+        fileset.setExcludes( excludes );
+        copy.addFileset( fileset );
+
+        copy.init();
+        copy.execute();
+    }
+
+}

Modified: avalon/trunk/tools/project/src/test/index.xml
==============================================================================
--- avalon/trunk/tools/project/src/test/index.xml	(original)
+++ avalon/trunk/tools/project/src/test/index.xml	Sun May 23 00:18:21 2004
@@ -104,61 +104,6 @@
       </dependencies>
     </project>
 
-    <project basedir="plugins/manager">
-      <info>
-        <group>avalon/magic</group>
-        <name>manager</name>
-        <version>1.0</version>
-        <type>plugin</type>
-      </info>
-      <dependencies>
-        <resources>
-          <resourceref key="avalon-framework-api"/>
-          <resourceref key="avalon-framework-impl"/>
-        </resources>
-      </dependencies>
-    </project>
-
-    <project basedir="plugins/prepare">
-      <info>
-        <group>avalon/magic</group>
-        <name>prepare</name>
-        <version>1.0</version>
-        <type>plugin</type>
-      </info>
-      <dependencies>
-        <resources>
-          <resourceref key="avalon-framework-api"/>
-        </resources>
-        <plugins>
-          <pluginref key="manager"/>
-        </plugins>
-      </dependencies>
-    </project>
-
-    <project basedir="plugins/compile">
-      <info>
-        <group>avalon/magic</group>
-        <name>compile</name>
-        <version>1.0</version>
-        <type>plugin</type>
-      </info>
-      <dependencies>
-        <resources>
-          <resourceref key="avalon-framework-api"/>
-          <resourceref key="avalon-framework-impl"/>
-        </resources>
-        <plugins>
-          <pluginref key="prepare"/>
-        </plugins>
-      </dependencies>
-    </project>
-
   </projects>
-
-
-  <!--
-  Declaration of the local plugins.
-  -->
 
 </system>

Added: avalon/trunk/tools/project/src/test/projects/gizmo/build.properties
==============================================================================
--- (empty file)
+++ avalon/trunk/tools/project/src/test/projects/gizmo/build.properties	Sun May 23 00:18:21
2004
@@ -0,0 +1 @@
+#avalon.target = targetx
\ No newline at end of file

Modified: avalon/trunk/tools/project/src/test/projects/gizmo/build.xml
==============================================================================
--- avalon/trunk/tools/project/src/test/projects/gizmo/build.xml	(original)
+++ avalon/trunk/tools/project/src/test/projects/gizmo/build.xml	Sun May 23 00:18:21 2004
@@ -4,4 +4,8 @@
 
   <x:project index="../../index.xml"/>
 
+  <x:prepare/>
+  <x:javac/>
+
+
 </project>

Added: avalon/trunk/tools/project/src/test/projects/gizmo/src/main/org/apache/avalon/gizmo/Gizmo.java
==============================================================================
--- (empty file)
+++ avalon/trunk/tools/project/src/test/projects/gizmo/src/main/org/apache/avalon/gizmo/Gizmo.java
Sun May 23 00:18:21 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.gizmo;
+
+
+/**
+ * Sample Gizmo 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 Gizmo 
+{
+}

Added: avalon/trunk/tools/project/src/test/projects/gizmo/src/main/org/apache/avalon/gizmo/StandardGizmo.java
==============================================================================
--- (empty file)
+++ avalon/trunk/tools/project/src/test/projects/gizmo/src/main/org/apache/avalon/gizmo/StandardGizmo.java
Sun May 23 00:18:21 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.gizmo;
+
+
+/**
+ * Sample gizmo 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 StandardGizmo implements Gizmo 
+{
+}

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


Mime
View raw message