avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject svn commit: rev 21430 - in avalon/trunk/tools/magic/src/main/org/apache/avalon/tools: home project/builder tasks
Date Sat, 19 Jun 2004 00:48:20 GMT
Author: mcconnell
Date: Fri Jun 18 17:48:19 2004
New Revision: 21430

Modified:
   avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/home/Home.java
   avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/project/builder/XMLDefinitionBuilder.java
   avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/HomeTask.java
   avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/InitializeTask.java
Log:
add separation of the notion of system root enabling existance of multiple index.xml defintions
within a system and the importing of one or more index.xml files into other index.xml files

Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/home/Home.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/home/Home.java	(original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/home/Home.java	Fri Jun 18 17:48:19
2004
@@ -94,14 +94,16 @@
     // constructor
     //-------------------------------------------------------------
 
-    public Home( Project project, File index )
+    public Home( Project project, File system, File index )
     {
         setProject( project );
         m_index = index;
         log( "Building system definition." );
+
+        m_system = system;
+
         try
         {
-            m_system = m_index.getParentFile();
             String path = getCachePath( project );
             String hostsPath = project.getProperty( HOSTS_KEY );
             m_main = new Repository( project, m_system, path, hostsPath, this );
@@ -109,18 +111,13 @@
             String docs = getDocsCachePath( project );
             m_docs = new Repository( project, m_system, docs, hostsPath, this );
 
-            Element root = ElementHelper.getRootElement( m_index );
-            final Element resources = ElementHelper.getChild( root, "resources" );
-            final Element projects = ElementHelper.getChild( root, "projects" );
-
             //
             // construct the repository, build the definition of the available 
             // resources and projects used within the system and associate a build
             // listener
             //
 
-            buildResourceList( resources );
-            buildProjectList( projects );
+            buildList( m_index, false );
         }
         catch( Throwable e )
         {
@@ -273,43 +270,65 @@
     // internal
     //-------------------------------------------------------------
 
-    private void buildResourceList( Element resources )
+    private void buildList( File index, boolean remote )
+    {
+        Element root = ElementHelper.getRootElement( index );
+        final Element[] elements = ElementHelper.getChildren( root );
+        File system = index.getParentFile();
+        buildList( system, elements, remote );
+    }
+
+    private void buildList( File system, Element[] children, boolean remote )
     {
-        if( null == resources ) return;
+        if( null == children ) return;
 
-        Element[] resourceArray = ElementHelper.getChildren( resources, "resource" );
-        log( "resources: " + resourceArray.length, Project.MSG_VERBOSE );
-        for( int i=0; i<resourceArray.length; i++ )
-        {
-            Element child = resourceArray[i];
-            Resource resource = XMLDefinitionBuilder.createResource( this, child );
-            String key = resource.getKey();
-            m_resources.put( key, resource );
-            log( 
-              "resource: " + resource + " key=" + key, 
-              Project.MSG_VERBOSE );
+        log( "entry: " + children.length, Project.MSG_VERBOSE );
+        for( int i=0; i<children.length; i++ )
+        {
+            Element element = children[i];
+            final String tag = element.getTagName();
+            if( isaResource( tag ) )
+            {
+                Resource resource = createResource( element, system, remote );
+                String key = resource.getKey();
+                m_resources.put( key, resource );
+                log( 
+                  "resource: " + resource 
+                  + " key=" + key, Project.MSG_VERBOSE );
+            }
+            else if( "import".equals( element.getTagName() ) )
+            { 
+                String path = element.getAttribute( "index" );
+                File index = Context.getFile( system, path );
+                buildList( index, true );
+            }
+            else
+            {
+                final String error =
+                  "Unrecognized element type \"" + tag + "\".";
+                throw new BuildException( error );
+            }
         }
     }
 
-    private void buildProjectList( Element projects )
-    {
-        if( null == projects ) return;
-
-        Element[] entries = ElementHelper.getChildren( projects );
-        log( 
-          "projects: " + entries.length, 
-          Project.MSG_VERBOSE );
-        for( int i=0; i<entries.length; i++ )
-        {
-            Element element = entries[i];
-            Definition definition = 
-              XMLDefinitionBuilder.createDefinition( this, element, m_system );
-            String key = definition.getKey();
-            m_resources.put( key, definition );
-            log( 
-              "project: " + definition + " key=" + key, 
-              Project.MSG_VERBOSE );
+    private Resource createResource( Element element, File system, boolean remote )
+    {
+        if( remote )
+        {
+            return XMLDefinitionBuilder.createResource( this, element );
+        }
+        else
+        {
+            return XMLDefinitionBuilder.createResource( this, element, system );
         }
+    }
+
+    private boolean isaResource( String tag )
+    {
+        return ( 
+          "resource".equals( tag ) 
+          || "project".equals( tag )
+          || "plugin".equals( tag ) );
     }
 
     private File getIndexFile()

Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/project/builder/XMLDefinitionBuilder.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/project/builder/XMLDefinitionBuilder.java
(original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/project/builder/XMLDefinitionBuilder.java
Fri Jun 18 17:48:19 2004
@@ -19,6 +19,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.util.List;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.taskdefs.Sequential;
@@ -46,6 +47,54 @@
  */
 public class XMLDefinitionBuilder 
 {
+    public static Resource createResource( Home home, Element element, File anchor )
+    {
+        final String tag = element.getTagName();
+
+        if( tag.equals( "resource" ) )
+          return createResource( home, element );
+          
+        //
+        // otherwise its a project or plugin defintion
+        // 
+
+        Info info = 
+          createInfo( ElementHelper.getChild( element, "info" ) );
+        String key = getDefinitionKey( element, info );
+
+        File basedir = getBasedir( anchor, element );
+       
+        ResourceRef[] resources = 
+          createResourceRefs( 
+            ElementHelper.getChild( element, "dependencies" ) );
+        
+        ResourceRef[] plugins = 
+          createPluginRefs( 
+            ElementHelper.getChild( element, "plugins" ) );
+
+        if( tag.equals( "project" ) )
+        {
+            return new Definition( 
+              home, key, basedir, info, resources, plugins );
+        }
+        else if( tag.equals( "plugin" ) )
+        {
+            TaskDef[] tasks = 
+              getTaskDefs( ElementHelper.getChild( element, "tasks" ) );
+            ListenerDef[] listeners = 
+              getListenerDefs( 
+                ElementHelper.getChild( element, "listeners" ) );
+            return new Plugin( 
+              home, key, basedir, info, resources, plugins, 
+              tasks, listeners );
+        }
+        else
+        {
+            final String error =
+              "Unrecognized project type \"" + tag + "\".";
+            throw new BuildException( error );
+        }
+    }
 
     public static Resource createResource( Home home, Element element )
     {
@@ -59,7 +108,6 @@
     {
         Info info = 
           createInfo( ElementHelper.getChild( element, "info" ) );
-
         String key = getDefinitionKey( element, info );
 
         File basedir = getBasedir( anchor, element );

Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/HomeTask.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/HomeTask.java	(original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/HomeTask.java	Fri Jun
18 17:48:19 2004
@@ -41,6 +41,8 @@
  */
 public class HomeTask extends ContextualTask
 {
+    public static final String SYSTEM_KEY = "project.system";
+
     private static final String CACHE_DIR_KEY = "project.home.cache.dir";
     private static final String USER_PROPERTIES = "user.properties";
     private static final String BUILD_PROPERTIES = "build.properties";
@@ -55,12 +57,12 @@
             super.init();
             Project project = getProject();
             File index = getIndexFile();
-            File system = index.getParentFile();
+            File system = getSystemHome( project, index );
             setupProperties( project, system );
             if( null == HOME )
             {
-                setupAvalonProperties( project, system );
-                HOME = new Home( project, index );
+                setupSystemProperties( project, system );
+                HOME = new Home( project, system, index );
             }
             project.addReference( Home.KEY, HOME );
             
@@ -70,6 +72,20 @@
         }
     }
 
+    private File getSystemHome( Project project, File index )
+    {
+        String system = project.getProperty( SYSTEM_KEY );
+        if(( null == system ) || "".equals( system ))
+        {
+            return index.getParentFile();
+        }
+        else
+        {
+            File anchor = project.getBaseDir();
+            return Context.getFile( anchor, system );
+        }
+    }
+
     private void setupProperties( Project project, File dir )
     {
         setupUserProperties( project, dir );
@@ -88,7 +104,7 @@
         readProperties( project, build );
     }
 
-    private void setupAvalonProperties( Project project, File dir )
+    private void setupSystemProperties( Project project, File dir )
     {
         File build = Context.getFile( dir, INDEX_PROPERTIES );
         readProperties( project, build );

Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/InitializeTask.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/InitializeTask.java	(original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/InitializeTask.java	Fri
Jun 18 17:48:19 2004
@@ -33,7 +33,7 @@
 import org.apache.avalon.tools.home.Context;
 import org.apache.avalon.tools.project.Definition;
 import org.apache.avalon.tools.project.ResourceRef;
-import org.apache.avalon.tools.project.Plugin;
+import org.apache.avalon.tools.project.Resource;
 
 /**
  * The initialize task loads and plugins that a project
@@ -59,7 +59,7 @@
         for( int i=0; i<refs.length; i++ )
         {
             ResourceRef ref = refs[i];
-            Plugin plugin = getHome().getPlugin( ref );
+            Resource plugin = getHome().getResource( ref );
             String path = "plugin:" + plugin.getInfo().getSpec();
             PluginTask task = new PluginTask();
             task.setTaskName( "plugin" );

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


Mime
View raw message