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/06/30 12:10:43 UTC

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

Author: mcconnell
Date: Wed Jun 30 03:10:42 2004
New Revision: 22313

Added:
   avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/BlockTask.java
Modified:
   avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/antlib.xml
   avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Context.java
   avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/AbstractDeliverableTask.java
   avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/DeclareTask.java
   avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JUnitTestTask.java
   avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JarTask.java
   avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JavacTask.java
Log:
Addition of a block task (does automatic creation of the block defintion for standalon and embedded scenarios).

Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/antlib.xml
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/antlib.xml	(original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/antlib.xml	Wed Jun 30 03:10:42 2004
@@ -21,6 +21,7 @@
   <taskdef name="publish" classname="org.apache.avalon.tools.tasks.PublishTask"/> 
   <taskdef name="property" classname="org.apache.avalon.tools.tasks.PropertyTask"/> 
   <taskdef name="replicate" classname="org.apache.avalon.tools.tasks.ReplicateTask"/> 
+  <taskdef name="block" classname="org.apache.avalon.tools.tasks.BlockTask"/> 
   <typedef name="path" classname="org.apache.avalon.tools.model.MagicPath"/> 
 
 </antlib>

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	Wed Jun 30 03:10:42 2004
@@ -43,6 +43,8 @@
 
     public static final String TARGET = "target";
     public static final String BUILD = "build";
+    public static final String CLASSES = "classes";
+    public static final String TEST_CLASSES = "test-classes";
     public static final String TEMP = "temp";
     public static final String TEST = "test";
     public static final String DELIVERABLES = "deliverables";
@@ -51,7 +53,6 @@
     private static final String USER_PROPERTIES = "user.properties";
     private static final String BUILD_PROPERTIES = "build.properties";
 
-
     public static final String SRC_KEY = "project.src";
     public static final String SRC_VALUE = "src";
 
@@ -97,6 +98,8 @@
     private File m_target;
     private File m_build;
     private File m_deliverables;
+    private File m_classes;
+    private File m_testClasses;
     private File m_temp;
     private File m_docs;
     private File m_test;
@@ -137,8 +140,10 @@
         m_target = new File( basedir, TARGET );
         m_build = setBuildPath( BUILD );
         m_deliverables = setBuildPath( DELIVERABLES );
+        m_classes = setBuildPath( CLASSES );
         m_temp = setBuildPath( TEMP );
         m_test = setBuildPath( TEST );
+        m_testClasses = setBuildPath( TEST_CLASSES );
         m_docs = setBuildPath( DOCS );
 
         project.addReference( KEY, this );
@@ -201,6 +206,16 @@
     public File getDeliverablesDirectory()
     {
         return m_deliverables;
+    }
+
+    public File getClassesDirectory()
+    {
+        return m_classes;
+    }
+
+    public File getTestClassesDirectory()
+    {
+        return m_testClasses;
     }
 
     public File getTempDirectory()

Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/AbstractDeliverableTask.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/AbstractDeliverableTask.java	(original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/AbstractDeliverableTask.java	Wed Jun 30 03:10:42 2004
@@ -64,9 +64,10 @@
         }
 
         final String gpg = getProject().getProperty( GPG_EXE_KEY );
+
         if(( null != gpg ) && !"".equals( gpg ) )
         {
-            log( "Creating asc signature using '" + gpg + "']" );
+            log( "Creating asc signature using '" + gpg + "'." );
             final ExecTask execute = (ExecTask) getProject().createTask( "exec" );
 
             execute.setExecutable( gpg );

Added: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/BlockTask.java
==============================================================================
--- (empty file)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/BlockTask.java	Wed Jun 30 03:10:42 2004
@@ -0,0 +1,194 @@
+/* 
+ * 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 org.apache.avalon.tools.model.Definition;
+import org.apache.avalon.tools.model.ResourceRef;
+import org.apache.avalon.tools.model.Info;
+import org.apache.avalon.tools.model.Resource;
+import org.apache.tools.ant.BuildException;
+import org.apache.avalon.tools.model.Plugin.ListenerDef;
+import org.apache.avalon.tools.model.Plugin.TaskDef;
+import org.apache.avalon.tools.model.Plugin;
+import org.apache.avalon.tools.model.Policy;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.FileOutputStream;
+import java.io.File;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * Create meta-data for a block.
+ *
+ * @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 BlockTask extends DeclareTask
+{
+    private static final String BLOCK = "block";
+    private static final String MAIN = "main";
+    private static final String TEST = "test";
+
+    public static class Component
+    {
+        private String m_name;
+        private String m_classname;
+
+        public Component()
+        {
+        }
+
+        public void setName( final String name )
+        {
+            m_name = name;
+        }
+
+        public void setClass( final String classname )
+        {
+            m_classname = classname;
+        }
+
+        public String getName()
+        {
+            return m_name;
+        }
+
+        public String getClassname()
+        {
+            return m_classname;
+        }
+    }
+
+    private String m_target;
+    private String m_container;
+    private List m_components = new ArrayList();
+
+    public void setName( final String name )
+    {
+        m_container = name;
+    }
+
+   /**
+    * Optional attribute indicating that the block is to be generated
+    * as an embedded BLOCK-INF/block.xml into either the MAIN or TEST
+    * classes directory as indicated by the target parameter.
+    */
+    public void setEmbed( final String target )
+    {
+        if( MAIN.equalsIgnoreCase( target ) )
+        {
+            m_target = MAIN;
+        }
+        else if( TEST.equalsIgnoreCase( target ) )
+        {
+            m_target = TEST;
+        }
+        else
+        {
+            final String error = 
+              "Embed policy not recognized (use MAIN or TEST)";
+            throw new BuildException( error );
+        }
+    }
+
+    private String getName( Definition def )
+    {
+        if( null == m_container )
+        {
+            return def.getInfo().getName();
+        }
+        else
+        {
+            return m_container;
+        }
+    }
+
+    protected File getPluginFile()
+    {
+        if( null == m_target )
+        {
+            return super.getPluginFile();
+        }
+        else
+        {
+            File root = getEmbeddedRoot( m_target );
+            File blockinf = new File( root, "BLOCK-INF" );
+            return new File( blockinf, "block.xml" );
+        }
+    }
+
+    private File getEmbeddedRoot( String target )
+    {
+        if( MAIN.equals( m_target ) )
+        {
+            return getContext().getClassesDirectory();
+        }
+        else
+        {
+            return getContext().getTestClassesDirectory();
+        }
+    }
+
+    public Component createComponent()
+    {
+        final Component component = new Component();
+        m_components.add( component );
+        return component;
+    }
+
+    public void init()
+    {
+        super.init();
+        super.setType( BLOCK );
+    }
+
+    protected void writePlugin( final Writer writer, final Definition def )
+        throws IOException
+    {
+        final Info info = def.getInfo();
+
+        writer.write( "\n\n<container name=\"" + getName( def ) + "\">" );
+        writer.write( "\n\n  <classloader>" );
+        boolean standalone = (null == m_target);
+        writeClasspath( writer, def, "    ", standalone );
+        writer.write( "\n  </classloader>" );
+        writer.write( "\n" );
+
+        Component[] components = 
+          (Component[]) m_components.toArray( new Component[0] );
+        for( int i=0; i<components.length; i++ )
+        {
+            Component component = components[i];
+            writeComponent( writer, component );
+        }
+
+        writer.write( "\n</container>\n" );
+    }
+
+    private void writeComponent( final Writer writer, final Component component )
+        throws IOException
+    {
+        writer.write( 
+          "\n  <component name=\"" + component.getName() + "\" class=\""
+          + component.getClassname() + "\"/>\n" );
+    }
+}

Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/DeclareTask.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/DeclareTask.java	(original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/DeclareTask.java	Wed Jun 30 03:10:42 2004
@@ -33,19 +33,25 @@
 import java.io.File;
 import java.io.OutputStreamWriter;
 import java.io.Writer;
-
-
-
+import java.util.List;
+import java.util.ArrayList;
 
 /**
- * Load a plugin.
+ * Create meta-data for 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 SystemTask
 {
-    private static final String TYPE = "plugin";
+    private static final String PLUGIN = "plugin";
+
+    private String m_type = PLUGIN;
+
+    protected void setType( String type )
+    {
+        m_type = type;
+    }
 
     public void execute() throws BuildException 
     {
@@ -55,6 +61,7 @@
         try
         {
             final File file = getPluginFile();
+            file.getParentFile().mkdirs();
             file.createNewFile();
             final OutputStream output = new FileOutputStream( file );
 
@@ -73,32 +80,17 @@
         }
     }
 
-    private File getPluginFile()
+    protected File getPluginFile()
     {
         final File dir = getContext().getDeliverablesDirectory();
-        final File ants = new File( dir, TYPE + "s" );
-        mkDir( ants );
-
+        final File ants = new File( dir, m_type + "s" );
         final Definition def = getHome().getDefinition( getKey() );
         final Info info = def.getInfo();
-        final String filename = getFilename( info );
+        final String filename = info.getShortFilename() + "." + m_type;
         return new File( ants, filename );
     }
 
-    private String getFilename( final Info info )
-    {
-        final String version = info.getVersion();
-        if( null == version )
-        {
-            return info.getName() + "." + TYPE;
-        }
-        else
-        {
-            return info.getName() + "-" + version + "." + TYPE;
-        }
-    }
-
-    public void writePluginDef( final OutputStream output, final Definition def )
+    private void writePluginDef( final OutputStream output, final Definition def )
         throws IOException
     {
         final Writer writer = new OutputStreamWriter( output );
@@ -107,18 +99,7 @@
         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 )
+    protected void writePlugin( final Writer writer, final Definition def )
         throws IOException
     {
         final Info info = def.getInfo();
@@ -131,10 +112,21 @@
             writeTaskDefs( writer, plugin );
             writeListenerDefs( writer, plugin );
         }
-        writeClasspath( writer, def );
+        writeClasspath( writer, def, "  ", true );
         writer.write( "\n</plugin>\n" );
     }
 
+   /**
+    * 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 writeTaskDefs( final Writer writer, final Plugin plugin )
         throws IOException
     {
@@ -185,20 +177,28 @@
         {
             writer.write( "\n    <version>" + version + "</version>" );
         }
-        writer.write( "\n    <type>" + TYPE + "</type>" );
+        writer.write( "\n    <type>" + m_type + "</type>" );
         writer.write( "\n  </info>" );
     }
 
-    private void writeClasspath( final Writer writer, final Definition def )
+   /**
+    * Write the classpath.  If the fag is true, then include this defintion 
+    * in the claspath.
+    */
+    protected void writeClasspath( 
+      final Writer writer, final Definition def, String padding, boolean flag )
         throws IOException
     {
-        writer.write( "\n  <classpath>" );
-        final String pad = "    ";
+        writer.write( "\n" + padding + "<classpath>" );
+        final String pad = padding + "  ";
         final ResourceRef[] resources =
           def.getResourceRefs( Policy.RUNTIME, ResourceRef.ANY, true );
         writeResourceRefs( writer, pad, resources );
-        writeResource( writer, pad, def );
-        writer.write( "\n  </classpath>" );
+        if( flag )
+        {
+            writeResource( writer, pad, def );
+        }
+        writer.write( "\n" + padding + "</classpath>" );
     }
 
     private void writeResourceRefs( 

Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JUnitTestTask.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JUnitTestTask.java	(original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JUnitTestTask.java	Wed Jun 30 03:10:42 2004
@@ -107,7 +107,7 @@
 
         if( src.exists() )
         {
-            final File classes = new File( m_test, "classes" );
+            final File classes = getContext().getTestClassesDirectory();
             mkDir( classes );
 
             final Definition definition = getHome().getDefinition( getKey() );

Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JarTask.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JarTask.java	(original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JarTask.java	Wed Jun 30 03:10:42 2004
@@ -41,7 +41,7 @@
     public void execute() throws BuildException 
     {
         final File classes =
-          getContext().getBuildPath( JavacTask.BUILD_CLASSES_KEY );
+          getContext().getClassesDirectory();
         final File deliverables =
           getContext().getDeliverablesDirectory();
 

Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JavacTask.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JavacTask.java	(original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JavacTask.java	Wed Jun 30 03:10:42 2004
@@ -38,8 +38,6 @@
  */
 public class JavacTask extends SystemTask
 {
-    public static final String BUILD_CLASSES_KEY = "classes";
-    public static final String BUILD_CLASSES_PATH = "classes";
 
     public static final String DEBUG_KEY = "java.compile.debug";
     public static final boolean DEBUG_VALUE = false;
@@ -55,9 +53,6 @@
             final Project project = getProject();
             project.setNewProperty( DEBUG_KEY, "" + DEBUG_VALUE );
             project.setNewProperty( FORK_KEY, "" + FORK_VALUE );
-            getContext().setBuildPath( 
-              BUILD_CLASSES_KEY, 
-              BUILD_CLASSES_PATH );
         }
     }
 
@@ -69,7 +64,7 @@
 
         if( main.exists() )
         {
-            final File classes = getContext().getBuildPath( BUILD_CLASSES_KEY );
+            final File classes = getContext().getClassesDirectory();
             mkDir( classes );
 
             final ResourceRef ref = new ResourceRef( getKey() );

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