You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2004/07/04 16:59:48 UTC

svn commit: rev 22573 - in avalon/trunk/tools/magic/src/main/org/apache/avalon/tools: model tasks

Author: mcconnell
Date: Sun Jul  4 07:59:47 2004
New Revision: 22573

Modified:
   avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Context.java
   avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Home.java
   avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Info.java
   avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Magic.java
   avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Resource.java
   avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/XMLDefinitionBuilder.java
   avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/GumpTask.java
   avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/InitializeTask.java
   avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/PluginTask.java
Log:
Add support for internal handling of external gump artifacts by forcing the updating of the magic cache to sync. with the gump supplied external artifact.  Basically we copy the gump artifact into the magic cache using the group, name and version info declared under the magic index.

Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Context.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Context.java	(original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Context.java	Sun Jul  4 07:59:47 2004
@@ -345,24 +345,46 @@
 
     public static File getFile( final File root, final String path )
     {
+        return getFile( root, path, false );
+    }
+
+    public static File getFile( final File root, final String path, boolean create )
+    {
         if( null == path )
         {
             throw new NullPointerException( "path" );
         }
         final File file = new File( path );
-        if( file.isAbsolute() ) return getCanonicalFile( file );
+        if( file.isAbsolute() ) return getCanonicalFile( file, create );
         if( null == root )
         {
             throw new NullPointerException( "root" );
         }
-        return getCanonicalFile( new File( root, path ) );
+        return getCanonicalFile( new File( root, path ), create );
     }
 
     public static File getCanonicalFile( final File file ) throws BuildException
     {
+        return getCanonicalFile( file, false );
+    }
+
+    public static File getCanonicalFile( final File file, boolean create ) throws BuildException
+    {
         try
         {
-            return file.getCanonicalFile();
+            File result = file.getCanonicalFile();
+            if( create )
+            {
+                if( result.isDirectory() )
+                {
+                    result.mkdirs();
+                }
+                else
+                {
+                    result.getParentFile().mkdirs();
+                }
+            }
+            return result;
         }
         catch( IOException ioe )
         {

Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Home.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Home.java	(original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Home.java	Sun Jul  4 07:59:47 2004
@@ -81,7 +81,12 @@
         m_project = project;
         buildList( index );
         int n = m_resources.size();
-        project.log( "count: " + n );
+        project.log( "Resource count: " + n );
+
+        if( null != system.getGumpSignature() )
+        {
+            project.log( "Gump signature: " + system.getGumpSignature() );
+        }
     }
 
     //-------------------------------------------------------------
@@ -106,6 +111,16 @@
     public boolean isaResourceKey( String key )
     {
         return ( null != m_resources.get( key ) );
+    }
+
+    public boolean isGump()
+    {
+        return ( null != getGumpSignature() );
+    }
+
+    public String getGumpSignature()
+    {
+        return m_system.getGumpSignature();
     }
 
     public Repository getRepository()

Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Info.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Info.java	(original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Info.java	Sun Jul  4 07:59:47 2004
@@ -31,7 +31,7 @@
  
     public static final String PROTOCOL = "artifact";
 
-    public static Info create( final String id )
+    public static Info create( Home home, final String id )
     {
         final int i = id.indexOf( ":" );
         if( i<0 )
@@ -42,23 +42,33 @@
         }
         final String protocol = id.substring( 0, i );
         final String spec = id.substring( i+1 );
-        return Info.create( protocol, spec );
+        return Info.create( home, protocol, spec );
     }
 
-    public static Info create( final String type, final String id )
+    public static Info create( Home home, final String type, final String id )
     {
         final int n = getGroupIndex( id );
         final String group = getGroupFromId( id, n );
         final String name = getNameFromId( id, n );
         final String version = getVersionFromId( id );
-        if( SNAPSHOT.equalsIgnoreCase( version ) )
-        {
-            return new Info( group, name, version, type, true );
-        }
-        else
-        {
-            return new Info( group, name, version, type, false );
-        }
+        return Info.create( 
+          home, group, name, version, type, 
+          SNAPSHOT.equalsIgnoreCase( version ) );
+    }
+
+    public static Info create(
+      final Home home, final String group, final String name, final String version, 
+      final String type, boolean snapshot )
+    {
+        //if( home.isGump() ) 
+        //{
+        //    final String sig = home.getGumpSignature();
+        //    return new Info( group, name, sig, type, snapshot );
+        //}
+        //else
+        //{
+            return new Info( group, name, version, type, snapshot );
+        //}
     }
 
     private String m_name;
@@ -67,7 +77,7 @@
     private String m_type;
     private boolean m_snapshot;
 
-    public Info( 
+    private Info( 
       final String group, final String name, final String version, 
       final String type, boolean snapshot )
     {

Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Magic.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Magic.java	(original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Magic.java	Sun Jul  4 07:59:47 2004
@@ -46,6 +46,8 @@
     //-------------------------------------------------------------
 
     public static final String KEY = "magic.home";
+    public static final String GUMP_SRCDIR_KEY = "gump.srcdir";
+    public static final String GUMP_SIGNATURE_KEY = "gump.signature";
 
     public static final String HOSTS_KEY = "magic.hosts";
     public static final String CACHE_KEY = "magic.cache";
@@ -92,10 +94,16 @@
     }
 
     //-------------------------------------------------------------
+    // immutable state
+    //-------------------------------------------------------------
+
+    private final String m_signature;
+    private final File m_system;
+
+    //-------------------------------------------------------------
     // mutable state
     //-------------------------------------------------------------
 
-    private File m_system;
     private Repository m_main;
     private Repository m_docs;
     private Map m_homes = new Hashtable();
@@ -108,7 +116,10 @@
     {
         setProject( project );
 
+        m_signature = project.getProperty( GUMP_SIGNATURE_KEY );
+
         m_system = getSystemDirectory( project );
+
         project.setProperty( KEY, Context.getCanonicalPath( m_system ) );
 
         File user = new File( m_system, "user.properties" );
@@ -164,6 +175,11 @@
     public Repository getDocsRepository()
     {
         return m_docs;
+    }
+
+    public String getGumpSignature()
+    {
+        return m_signature;
     }
 
     public Home getHome( Project project, String value )

Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Resource.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Resource.java	(original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Resource.java	Sun Jul  4 07:59:47 2004
@@ -158,7 +158,7 @@
         {
             final String error = 
               "Resource defintion " + this + " contains a unknown resource reference ["
-                 + ure.getKey() + "] referenced in the project [" + project.getName() + "].";
+                 + ure.getKey() + "].";
             throw new BuildException( error );
         }
     }
@@ -180,12 +180,26 @@
         return (ResourceRef[]) list.toArray( new ResourceRef[0] );
     }
 
-
     public File getArtifact( final Project project )
     {
+        return getArtifact( project, true );
+    }
+
+    public File getArtifact( final Project project, boolean resolve )
+    {
+        //
+        // use classic repository resolution
+        //
+
         final String path = getInfo().getPath();
         final File cache = getHome().getRepository().getCacheDirectory();
         final File target = new File( cache, path );
+
+        if( !resolve )
+        {
+            return target;
+        }
+
         if( target.exists() ) 
         {
             return target;
@@ -193,6 +207,19 @@
         else
         {
             return get( project, target, path );
+        }
+    }
+
+    private String getKeyForResource( Resource resource )
+    {
+        final String alias = resource.getGump().getAlias();
+        if( null != alias ) 
+        {
+            return alias;
+        }
+        else
+        {
+            return resource.getKey();
         }
     }
 

Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/XMLDefinitionBuilder.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/XMLDefinitionBuilder.java	(original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/XMLDefinitionBuilder.java	Sun Jul  4 07:59:47 2004
@@ -32,62 +32,10 @@
  */
 public class XMLDefinitionBuilder 
 {
-    public static Resource createResource( final Home home, final Element element, final File anchor )
-    {
-        final String tag = element.getTagName();
-
-        if( tag.equals( "resource" ) )
-          return createResource( home, element );
-          
-        //
-        // otherwise its a project or plugin defintion
-        // 
-
-        final Info info =
-          createInfo( ElementHelper.getChild( element, "info" ) );
-        final Gump gump =
-          createGump( ElementHelper.getChild( element, "gump" ) );
-        final String key = getDefinitionKey( element, info );
-
-        final String path = element.getAttribute( "basedir" );
-        final File basedir = getBasedir( anchor, path );
-       
-        final ResourceRef[] resources =
-          createResourceRefs( 
-            ElementHelper.getChild( element, "dependencies" ) );
-        
-        final ResourceRef[] plugins =
-          createPluginRefs( 
-            ElementHelper.getChild( element, "plugins" ) );
-
-        if( tag.equals( "project" ) )
-        {
-            return new Definition( 
-              home, key, basedir, path, info, gump, resources, plugins );
-        }
-        else if( tag.equals( "plugin" ) )
-        {
-            final TaskDef[] tasks =
-              getTaskDefs( ElementHelper.getChild( element, "tasks" ) );
-            final ListenerDef[] listeners =
-              getListenerDefs( 
-                ElementHelper.getChild( element, "listeners" ) );
-            return new Plugin( 
-              home, key, basedir, path, info, gump, resources, plugins, 
-              tasks, listeners );
-        }
-        else
-        {
-            final String error =
-              "Unrecognized project type \"" + tag + "\".";
-            throw new BuildException( error );
-        }
-    }
-
     public static Resource createResource( final Home home, final Element element )
     {
         final Info info =
-          createInfo( ElementHelper.getChild( element, "info" ) );
+          createInfo( home, ElementHelper.getChild( element, "info" ) );
         final Gump gump =
           createGump( ElementHelper.getChild( element, "gump" ) );
         final String key = getDefinitionKey( element, info );
@@ -99,10 +47,19 @@
         return new Resource( home, key, info, gump, resources );
     }
 
-    public static Definition createDefinition( final Home home, final Element element, final File anchor )
+    public static Resource createResource( final Home home, final Element element, final File anchor )
     {
+        final String tag = element.getTagName();
+
+        if( tag.equals( "resource" ) )
+          return createResource( home, element );
+          
+        //
+        // otherwise its a project or plugin defintion
+        // 
+
         final Info info =
-          createInfo( ElementHelper.getChild( element, "info" ) );
+          createInfo( home, ElementHelper.getChild( element, "info" ) );
         final Gump gump =
           createGump( ElementHelper.getChild( element, "gump" ) );
         final String key = getDefinitionKey( element, info );
@@ -118,7 +75,6 @@
           createPluginRefs( 
             ElementHelper.getChild( element, "plugins" ) );
 
-        final String tag = element.getTagName();
         if( tag.equals( "project" ) )
         {
             return new Definition( 
@@ -129,9 +85,11 @@
             final TaskDef[] tasks =
               getTaskDefs( ElementHelper.getChild( element, "tasks" ) );
             final ListenerDef[] listeners =
-              getListenerDefs( ElementHelper.getChild( element, "listeners" ) );
+              getListenerDefs( 
+                ElementHelper.getChild( element, "listeners" ) );
             return new Plugin( 
-              home, key, basedir, path, info, gump, resources, plugins, tasks, listeners );
+              home, key, basedir, path, info, gump, resources, plugins, 
+              tasks, listeners );
         }
         else
         {
@@ -207,7 +165,7 @@
         return key;
     }
 
-    public static Info createInfo( final Element info )
+    public static Info createInfo( Home home, final Element info )
     {
         final String group =
           ElementHelper.getValue( 
@@ -221,18 +179,16 @@
         final String type =
           ElementHelper.getValue( 
             ElementHelper.getChild( info, "type" ) );
+        final boolean status = createSnapshotPolicy( info );
+        return Info.create( home, group, name, version, type, status );
+    }
+
+    private static boolean createSnapshotPolicy( final Element info )
+    {
         final String status =
           ElementHelper.getValue( 
             ElementHelper.getChild( info, "status" ) );
-
-        if( Info.SNAPSHOT.equalsIgnoreCase( status ) )
-        {
-            return new Info( group, name, version, type, true );
-        }
-        else
-        {
-            return new Info( group, name, version, type, false );
-        }
+        return Info.SNAPSHOT.equalsIgnoreCase( status );
     }
 
     public static Gump createGump( final Element info )

Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/GumpTask.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/GumpTask.java	(original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/GumpTask.java	Sun Jul  4 07:59:47 2004
@@ -395,8 +395,6 @@
            "\n      <!-- for magic -->" );
         writer.write( 
            "\n      <property name=\"gump.signature\" value=\"@@DATE@@\"/>" );
-        writer.write( 
-           "\n      <property name=\"gump.scrdir\" reference=\"srcdir\"/>" );
 
         boolean flag = false;
         for( int i=0; i<refs.length; i++ )
@@ -469,17 +467,19 @@
 
         String name = definition.getInfo().getName();
         String type = definition.getInfo().getType();
+        String filename = definition.getInfo().getFilename();
+
         if( "jar".equals( type ) || "bar".equals( type ) )
         {
             writer.write( 
               "\n    <jar name=\"" + type + "s/" 
-              + name + "-@@DATE@@.jar\"/>" );
+              + filename + "\"/>" );
         }
         if( "plugin".equals( type ) )
         {
             writer.write( 
               "\n    <jar name=\"jars/" 
-              + name + "-@@DATE@@.jar\"/>" );
+              + filename + "\"/>" );
         }
         else if( "doc".equals( type ) )
         {

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	Sun Jul  4 07:59:47 2004
@@ -17,11 +17,16 @@
 
 package org.apache.avalon.tools.tasks;
 
+import java.io.File;
+
 import org.apache.avalon.tools.model.Definition;
 import org.apache.avalon.tools.model.Resource;
 import org.apache.avalon.tools.model.ResourceRef;
+import org.apache.avalon.tools.model.Policy;
+
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.Copy;
 
 /**
  * The initialize task loads and plugins that a project
@@ -37,6 +42,18 @@
         final Project project = getProject();
 
         //
+        // if the project is running under gump then we need to 
+        // check all of the project dependencies for gump.resource
+        // overriding locations and if necessary - drag them into 
+        // our local cache
+        //
+
+        if( getHome().isGump() )
+        {
+            setupGumpDependencies( project );
+        }
+
+        //
         // if the project declares plugin dependencies then install
         // these now
         //
@@ -55,6 +72,58 @@
             task.setArtifact( path );
             task.init();
             task.execute();
+        }
+    }
+
+    private void setupGumpDependencies( Project project )
+    {
+        log( "Executing gump sanity check." );
+        final String key = getContext().getKey();
+        final Definition def = getHome().getDefinition( key );
+        final ResourceRef[] refs =
+          def.getResourceRefs( getProject(), Policy.ANY, ResourceRef.ANY, true );
+
+        for( int i=0; i<refs.length; i++ )
+        {
+            Resource resource = getHome().getResource( refs[i] );
+            if( !(resource instanceof Definition) )
+            {
+                String gumpKey = "gump.resource." + resource.getKey();
+                String path = project.getProperty( gumpKey );
+                if( null != path )
+                {
+                    updateCache( project, resource, path );
+                }
+                else
+                {
+                    final String warning = 
+                      "Warning - missing property [" + gumpKey + "].";
+                    project.log( warning );
+                }
+            }
+        }
+    }
+
+    private void updateCache( Project project, Resource resource, String path )
+    {
+        File source = new File( path );
+        if( !source.exists() )
+        {
+            final String error = 
+              "Gump source resource override for resource " 
+              + resource + " references the non-existant path [" + path 
+              + "].";
+            throw new BuildException( error );  
+        }
+        else
+        {
+            File destination = resource.getArtifact( project, false );
+            Copy copy = (Copy) project.createTask( "copy" );
+            copy.setFile( source );
+            copy.setTofile( destination );
+            copy.setPreserveLastModified( true );
+            copy.init();
+            copy.execute();
         }
     }
 }

Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/PluginTask.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/PluginTask.java	(original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/PluginTask.java	Sun Jul  4 07:59:47 2004
@@ -74,9 +74,10 @@
             // get the xml definition of the plugin
             //
 
+
             final String id = getArtifactSpec();
+            final Info info = Info.create( getHome(), id );
 
-            final Info info = Info.create( id );
             final Project project = getProject();
             final Resource resource = new Resource( getHome(), info );
             final File file = resource.getArtifact( project );
@@ -224,7 +225,7 @@
         {
             final Element root = ElementHelper.getRootElement( file );
             final Element infoElement = ElementHelper.getChild( root, "info" );
-            m_info = XMLDefinitionBuilder.createInfo( infoElement );
+            m_info = XMLDefinitionBuilder.createInfo( home, infoElement );
             final Element tasksElement = ElementHelper.getChild( root, "tasks" );
             m_tasks = XMLDefinitionBuilder.getTaskDefs( tasksElement );
             final Element listenerElement = ElementHelper.getChild( root, "listeners" );
@@ -238,7 +239,7 @@
                 final String value = ElementHelper.getValue( child );
                 final String type = getArtifactType( value );
                 final String uri = getArtifactURI( value );
-                final Info info = Info.create( type, uri );
+                final Info info = Info.create( home, type, uri );
                 final Resource resource = new Resource( home, info );
                 final File jar = resource.getArtifact( project );
                 m_path.createPathElement().setLocation( jar );

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