You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@excalibur.apache.org by ha...@apache.org on 2004/07/06 18:58:01 UTC

svn commit: rev 22635 - in excalibur/branches/fortress-experiments/meta/src: java/org/apache/avalon/fortress/tools test test/org test/org/apache test/org/apache/avalon test/org/apache/avalon/fortress test/org/apache/avalon/fortress/tools test/org/apache/avalon/fortress/tools/test testdata testdata/org testdata/org/apache testdata/org/apache/excalibur

Author: hammett
Date: Tue Jul  6 09:58:01 2004
New Revision: 22635

Added:
   excalibur/branches/fortress-experiments/meta/src/test/
   excalibur/branches/fortress-experiments/meta/src/test/org/
   excalibur/branches/fortress-experiments/meta/src/test/org/apache/
   excalibur/branches/fortress-experiments/meta/src/test/org/apache/avalon/
   excalibur/branches/fortress-experiments/meta/src/test/org/apache/avalon/fortress/
   excalibur/branches/fortress-experiments/meta/src/test/org/apache/avalon/fortress/tools/
   excalibur/branches/fortress-experiments/meta/src/test/org/apache/avalon/fortress/tools/test/
   excalibur/branches/fortress-experiments/meta/src/test/org/apache/avalon/fortress/tools/test/ComponentMetaInfoCollectorTestCase.java
   excalibur/branches/fortress-experiments/meta/src/test/org/apache/avalon/fortress/tools/test/ComponentTestCase.java   (contents, props changed)
   excalibur/branches/fortress-experiments/meta/src/test/org/apache/avalon/fortress/tools/test/ServiceTestCase.java   (contents, props changed)
   excalibur/branches/fortress-experiments/meta/src/testdata/
   excalibur/branches/fortress-experiments/meta/src/testdata/org/
   excalibur/branches/fortress-experiments/meta/src/testdata/org/apache/
   excalibur/branches/fortress-experiments/meta/src/testdata/org/apache/excalibur/
   excalibur/branches/fortress-experiments/meta/src/testdata/org/apache/excalibur/DefaultMailService.java   (contents, props changed)
   excalibur/branches/fortress-experiments/meta/src/testdata/org/apache/excalibur/MailService.java   (contents, props changed)
Modified:
   excalibur/branches/fortress-experiments/meta/src/java/org/apache/avalon/fortress/tools/Component.java
   excalibur/branches/fortress-experiments/meta/src/java/org/apache/avalon/fortress/tools/ComponentMetaInfoCollector.java
   excalibur/branches/fortress-experiments/meta/src/java/org/apache/avalon/fortress/tools/Service.java
Log:
Test cases and extended to write .attrs files.

Modified: excalibur/branches/fortress-experiments/meta/src/java/org/apache/avalon/fortress/tools/Component.java
==============================================================================
--- excalibur/branches/fortress-experiments/meta/src/java/org/apache/avalon/fortress/tools/Component.java	(original)
+++ excalibur/branches/fortress-experiments/meta/src/java/org/apache/avalon/fortress/tools/Component.java	Tue Jul  6 09:58:01 2004
@@ -25,6 +25,7 @@
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.PrintWriter;
 import java.util.*;
 
 /**
@@ -33,8 +34,11 @@
  * @author <a href="mailto:dev@avalon.apache.org">The Avalon Team</a>
  * @version CVS $Revision: 1.1 $ $Date: 2004/04/02 08:29:44 $
  */
-final class Component
+public final class Component
 {
+    /** The repository of components. */
+    static final Set m_repository = new HashSet();
+    
     private static final String SINGLE_THREADED = "org.apache.avalon.framework.thread.SingleThreaded";
     private static final String THREAD_SAFE = "org.apache.avalon.framework.thread.ThreadSafe";
     private static final String POOLABLE = "org.apache.avalon.excalibur.pool.Poolable";
@@ -55,15 +59,13 @@
 
     private static final String METH_SERVICE = "service";
 
-    /** The repository of components. */
-    static final Set m_repository = new HashSet();
-
     private final JavaClass m_javaClass;
     private final Properties m_attributes;
     private final List m_dependencies;
     private final Vertex m_vertex;
     private final List m_dependencyNames;
     private final List m_serviceNames;
+    private final DocletTag[] m_otherAttributes;
 
     /**
      * Initialize a service with the type name.
@@ -72,7 +74,10 @@
      */
     public Component( final JavaClass javaClass )
     {
-        if ( javaClass == null ) throw new NullPointerException( "javaClass" );
+        if ( javaClass == null ) 
+        {
+            throw new NullPointerException( "javaClass" );
+        } 
 
         m_javaClass = javaClass;
         m_attributes = new Properties();
@@ -80,6 +85,7 @@
         m_vertex = new Vertex( this );
         m_dependencyNames = new ArrayList( 10 );
         m_serviceNames = new ArrayList( 10 );
+        m_otherAttributes = m_javaClass.getTags();
 
         final DocletTag[] tags = javaClass.getTagsByName( TAG_SERVICE );
         for ( int t = 0; t < tags.length; t++ )
@@ -295,29 +301,102 @@
      */
     public void serialize( final File rootDir ) throws IOException
     {
-        final String fileName = getType().replace( '.', '/' ).concat( ".meta" );
-        final String depsName = getType().replace( '.', '/' ).concat( ".deps" );
-        File output = new File( rootDir, fileName );
-        FileOutputStream writer = null;
+        final String type = getType();
+        final String className   = type.substring( type.lastIndexOf('.') + 1 );
+        final String typePackage = type.substring( 0, type.lastIndexOf('.') );
+        final String typePackageDirFormat = typePackage.replace( '.', '/' );
+        
+        final File packageDir = new File( rootDir, typePackageDirFormat );
+        packageDir.mkdirs();
+        
+        writeMetaFile( packageDir, className );
+        writeDepsFile( packageDir, className );
+        writeAttrFile( packageDir, className );
+    }
+
+    private void writeMetaFile( final File packageDir, final String className ) throws IOException
+    {
+        final File output = new File( packageDir, className + ".meta" );
 
+        FileOutputStream writer = null;
+        
         try
         {
             writer = new FileOutputStream( output );
             m_attributes.store( writer, "Meta information for " + getType() );
+        }
+        finally
+        {
+            if ( null != writer )
+            {
+                writer.close();
+            }
+        }
+    }
 
-            if ( m_dependencies.size() > 0 )
+    private void writeDepsFile( final File packageDir, final String className ) throws IOException
+    {
+        if ( m_dependencies.size() == 0 )
+        {
+            return;
+        }
+        
+        final File output = new File( packageDir, className + ".deps" );
+
+        FileOutputStream writer = null;
+        
+        try
+        {
+            writer = new FileOutputStream( output );
+
+            Iterator it = m_dependencies.iterator();
+            while ( it.hasNext() )
+            {
+                Service service = (Service) it.next();
+                String name = service.getType() + "\n";
+                writer.write( name.getBytes() );
+            }
+        }
+        finally
+        {
+            if ( null != writer )
             {
                 writer.close();
-                output = new File( rootDir, depsName );
-                writer = new FileOutputStream( output );
+            }
+        }
+    }
+
+    private void writeAttrFile( final File packageDir, final String className ) throws IOException
+    {
+        final File output = new File( packageDir, className + ".attrs" );
+
+        PrintWriter writer = null;
+        
+        try
+        {
+            writer = new PrintWriter( new FileOutputStream( output ) );
 
-                Iterator it = m_dependencies.iterator();
-                while ( it.hasNext() )
+            for (int i = 0; i < m_otherAttributes.length; i++)
+            {
+                DocletTag tag = m_otherAttributes[i];
+                writer.print( tag.getName() );
+                writer.print( " [" );
+                String[] parameters = tag.getParameters();
+                boolean separator = false;
+                for (int j = 0; j < parameters.length; j++)
                 {
-                    Service service = (Service) it.next();
-                    String name = service.getType() + "\n";
-                    writer.write( name.getBytes() );
+                    String parameter = parameters[j];
+                    writer.print( parameter );
+                    if (!separator)
+                    {
+                        separator = true;
+                    }
+                    else
+                    {
+                        writer.print( ';' );
+                    }
                 }
+                writer.println( ']' );
             }
         }
         finally

Modified: excalibur/branches/fortress-experiments/meta/src/java/org/apache/avalon/fortress/tools/ComponentMetaInfoCollector.java
==============================================================================
--- excalibur/branches/fortress-experiments/meta/src/java/org/apache/avalon/fortress/tools/ComponentMetaInfoCollector.java	(original)
+++ excalibur/branches/fortress-experiments/meta/src/java/org/apache/avalon/fortress/tools/ComponentMetaInfoCollector.java	Tue Jul  6 09:58:01 2004
@@ -246,7 +246,7 @@
         while ( services.hasNext() )
         {
             final Service service = (Service) services.next();
-            log( "Processing service " + service.getType(), Project.MSG_VERBOSE );
+            log( "Processing service " + service.getType(), Project.MSG_INFO );
             try
             {
                 service.serialize( m_destDir );

Modified: excalibur/branches/fortress-experiments/meta/src/java/org/apache/avalon/fortress/tools/Service.java
==============================================================================
--- excalibur/branches/fortress-experiments/meta/src/java/org/apache/avalon/fortress/tools/Service.java	(original)
+++ excalibur/branches/fortress-experiments/meta/src/java/org/apache/avalon/fortress/tools/Service.java	Tue Jul  6 09:58:01 2004
@@ -32,7 +32,7 @@
  * @author <a href="mailto:dev@avalon.apache.org">The Avalon Team</a>
  * @version CVS $Revision: 1.1 $ $Date: 2004/04/02 08:29:44 $
  */
-final class Service
+public final class Service
 {
     private final Set m_components;
 
@@ -62,13 +62,16 @@
     }
 
     /**
-     * Add a component to the service.
+     * Adds a component that implements the service.
      *
      * @param type  the type name for the component
      */
     public void addComponent( final Component type )
     {
-        if ( type == null ) throw new NullPointerException( "type" );
+        if ( type == null ) 
+        {
+            throw new NullPointerException( "type" );
+        } 
 
         m_components.add( type );
     }
@@ -88,7 +91,10 @@
     {
         if ( m_components.isEmpty() ) return;
 
-        final File serviceFile = new File( rootDir, "META-INF/services/" + getType() );
+        final File targetDir = new File( rootDir, "META-INF/services/" );
+        targetDir.mkdirs();
+        
+        final File serviceFile = new File( targetDir, getType() );
         PrintWriter writer = null;
 
         try

Added: excalibur/branches/fortress-experiments/meta/src/test/org/apache/avalon/fortress/tools/test/ComponentMetaInfoCollectorTestCase.java
==============================================================================
--- (empty file)
+++ excalibur/branches/fortress-experiments/meta/src/test/org/apache/avalon/fortress/tools/test/ComponentMetaInfoCollectorTestCase.java	Tue Jul  6 09:58:01 2004
@@ -0,0 +1,155 @@
+/*
+ * Created on 05/07/2004
+ *
+ */
+package org.apache.avalon.fortress.tools.test;
+
+import java.io.File;
+
+import org.apache.avalon.fortress.tools.ComponentMetaInfoCollector;
+import org.apache.tools.ant.BuildEvent;
+import org.apache.tools.ant.BuildListener;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.FileSet;
+
+import junit.framework.TestCase;
+
+/**
+ * Pending
+ * 
+ * @author hammett
+ */
+public class ComponentMetaInfoCollectorTestCase extends TestCase
+{
+    private File m_dest;
+    private File m_source;
+    private Project m_antProject;
+    private LogBuildListener m_log;
+
+    /**
+     * Constructor for ComponentMetaInfoCollectorTestCase.
+     * @param name
+     */
+    public ComponentMetaInfoCollectorTestCase(String name)
+    {
+        super(name);
+    }
+
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        
+        m_log = new LogBuildListener();
+        
+        m_antProject = new Project();
+        m_antProject.addBuildListener( m_log );
+
+        m_dest = new File("./tempfiles");
+        m_source = new File("./src/testdata");
+
+        if (!m_dest.exists())
+        {
+            fail("Directory must exists: " + m_dest.getCanonicalPath() );
+        }
+        
+        if (!m_source.exists())
+        {
+            fail("Directory must exists: " + m_source.getCanonicalPath() );
+        }
+    }
+
+    public void testExecute()
+    {
+        ComponentMetaInfoCollector collector = new ComponentMetaInfoCollector();
+        
+        collector.setProject( m_antProject );
+        collector.addFileset( new DummyFileSet() );
+        collector.setDestDir( m_dest );
+        collector.execute();
+        
+        File metaFile = new File( m_dest, "org/apache/excalibur/DefaultMailService.meta" );
+        File attsFile = new File( m_dest, "org/apache/excalibur/DefaultMailService.attrs" );
+        
+        assertTrue( metaFile.exists() );
+        assertTrue( attsFile.exists() );
+
+        String content = m_log.getLogContent();
+        
+        final String messageExpected = "Writing Info descriptors as property files (.meta).\r\n" +
            "Collecting service information.\r\n" +
            "Processing service MailService\r\n";
+        
+        assertEquals( messageExpected, content );
+    }
+
+    private class DummyFileSet extends FileSet
+    {
+        public DummyFileSet( )
+        {
+        }
+
+        public File getDir(Project project)
+        {
+            return m_source;
+        }
+
+        public DirectoryScanner getDirectoryScanner( Project project )
+        {
+            return new DirectoryScanner()
+            {
+                public String[] getIncludedDirectories()
+                {
+                    return new String[] { "org/apache/excalibur" };
+                }
+
+                public String[] getIncludedFiles()
+                {
+                    return new String[] { "org/apache/excalibur/DefaultMailService.java" };
+                }
+            };
+        }
+    }
+    
+    private class LogBuildListener implements BuildListener
+    {
+        StringBuffer m_log = new StringBuffer(); 
+        
+        public String getLogContent()
+        {
+            return m_log.toString();
+        }
+        
+        ///
+        /// BuildListener implementation
+        /// 
+        
+        public void buildStarted(BuildEvent event)
+        {
+        }
+
+        public void buildFinished(BuildEvent event)
+        {
+        }
+
+        public void targetStarted(BuildEvent event)
+        {
+        }
+
+        public void targetFinished(BuildEvent event)
+        {
+        }
+
+        public void taskStarted(BuildEvent event)
+        {
+        }
+
+        public void taskFinished(BuildEvent event)
+        {
+        }
+
+        public void messageLogged(BuildEvent event)
+        {
+            m_log.append( event.getMessage() );
+            m_log.append( "\r\n" );
+        }
+    }
+}

Added: excalibur/branches/fortress-experiments/meta/src/test/org/apache/avalon/fortress/tools/test/ComponentTestCase.java
==============================================================================
--- (empty file)
+++ excalibur/branches/fortress-experiments/meta/src/test/org/apache/avalon/fortress/tools/test/ComponentTestCase.java	Tue Jul  6 09:58:01 2004
@@ -0,0 +1,79 @@
+/*
+ * Created on 05/07/2004
+ *
+ */
+package org.apache.avalon.fortress.tools.test;
+
+import java.io.File;
+import java.util.Collections;
+
+import junit.framework.TestCase;
+
+import org.apache.avalon.fortress.tools.Component;
+
+import com.thoughtworks.qdox.model.JavaClass;
+
+/**
+ * Pending
+ * 
+ * @author hammett
+ */
+public class ComponentTestCase extends TestCase
+{
+    private static final String COMPONENT_TYPE_NAME = "org.apache.avalon.fortress.tools.ServiceImpl";
+    
+    private Component m_component;
+    private final File m_root = new File("./tempfiles");
+
+    public ComponentTestCase(String name)
+    {
+        super(name);
+    }
+
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        
+        JavaClass model = new JavaClass()
+        {
+            public String getFullyQualifiedName()
+            {
+                return getName();
+            }
+
+            public JavaClass getSuperJavaClass()
+            {
+                return null;
+            }
+        };
+        model.setName( COMPONENT_TYPE_NAME );
+        model.setTags( Collections.EMPTY_LIST );
+        
+        m_component = new Component( model );
+        
+        m_root.mkdirs();
+    }
+
+    protected void tearDown() throws Exception
+    {
+        super.tearDown();
+
+        m_root.delete();
+    }
+
+    public void testGetType()
+    {
+        assertEquals( COMPONENT_TYPE_NAME, m_component.getType() );
+    }
+
+    public void testSerialize() throws Exception
+    {
+        m_component.serialize( m_root );
+        
+        String fileName = COMPONENT_TYPE_NAME.replace( '.', '/' ).concat( ".meta" );
+        
+        File file = new File( m_root, fileName );
+        
+        assertTrue( file.exists() );
+    }
+}
\ No newline at end of file

Added: excalibur/branches/fortress-experiments/meta/src/test/org/apache/avalon/fortress/tools/test/ServiceTestCase.java
==============================================================================
--- (empty file)
+++ excalibur/branches/fortress-experiments/meta/src/test/org/apache/avalon/fortress/tools/test/ServiceTestCase.java	Tue Jul  6 09:58:01 2004
@@ -0,0 +1,91 @@
+/*
+ * Created on 05/07/2004
+ *
+ */
+package org.apache.avalon.fortress.tools.test;
+
+import java.io.File;
+import java.util.Collections;
+
+import org.apache.avalon.fortress.tools.Component;
+import org.apache.avalon.fortress.tools.Service;
+
+import com.thoughtworks.qdox.model.JavaClass;
+
+import junit.framework.TestCase;
+
+/**
+ * Pending
+ * 
+ * @author hammett
+ */
+public class ServiceTestCase extends TestCase
+{
+    private static final String TYPE_NAME = "org.apache.avalon.fortress.tools.Service";
+    private static final String COMPONENT_TYPE_NAME = "org.apache.avalon.fortress.tools.ServiceImpl";
+    
+    private Service m_service;
+    private File m_root;
+
+    public ServiceTestCase(String name)
+    {
+        super(name);
+    }
+
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        
+        m_service = new Service( TYPE_NAME );
+        
+        m_root = new File("./tempfiles");
+        m_root.mkdirs();
+    }
+
+    protected void tearDown() throws Exception
+    {
+        super.tearDown();
+
+        m_root.delete();
+    }
+
+    public void testGetType()
+    {
+        assertEquals( TYPE_NAME, m_service.getType() );
+    }
+
+    public void testAddComponent()
+    {
+        JavaClass model = new JavaClass()
+        {
+            public String getFullyQualifiedName()
+            {
+                return getName();
+            }
+
+            public JavaClass getSuperJavaClass()
+            {
+                return null;
+            }
+        };
+        model.setName( COMPONENT_TYPE_NAME );
+        model.setTags( Collections.EMPTY_LIST );
+        
+        Component component = new Component( model );
+        m_service.addComponent( component );
+        
+        assertNotNull( m_service.getComponents() );
+        assertTrue( m_service.getComponents().hasNext() );
+    }
+
+    public void testSerialize() throws Exception
+    {
+        testAddComponent();
+        
+        m_service.serialize( m_root );
+        
+        File file = new File( m_root, "META-INF/services/" + TYPE_NAME );
+       
+        assertTrue( file.exists() );
+    }
+}

Added: excalibur/branches/fortress-experiments/meta/src/testdata/org/apache/excalibur/DefaultMailService.java
==============================================================================
--- (empty file)
+++ excalibur/branches/fortress-experiments/meta/src/testdata/org/apache/excalibur/DefaultMailService.java	Tue Jul  6 09:58:01 2004
@@ -0,0 +1,31 @@
+/* 
+ * Copyright 2004 The 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.excalibur;
+
+/**
+ * @avalon.component
+ * @avalon.service type=MailService
+ * @x-avalon.info name=mailservice
+ * @x-avalon.lifestyle type=singleton
+ */
+public class DefaultMailService implements MailService
+{
+    public void sendMail( String to, String from, String message )
+    {
+    }
+}
\ No newline at end of file

Added: excalibur/branches/fortress-experiments/meta/src/testdata/org/apache/excalibur/MailService.java
==============================================================================
--- (empty file)
+++ excalibur/branches/fortress-experiments/meta/src/testdata/org/apache/excalibur/MailService.java	Tue Jul  6 09:58:01 2004
@@ -0,0 +1,26 @@
+/* 
+ * Copyright 2004 The 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.excalibur;
+
+/**
+ *
+ */
+public interface MailService
+{
+    void sendMail( String to, String from, String message );
+}
\ No newline at end of file

---------------------------------------------------------------------
To unsubscribe, e-mail: scm-unsubscribe@excalibur.apache.org
For additional commands, e-mail: scm-help@excalibur.apache.org