avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject svn commit: rev 20212 - in avalon/trunk/tools/magic: engine/src/java/org/apache/merlin/magic engine/src/test/org/apache/merlin/magic jar/src/dist prepare prepare/src prepare/src/dist prepare/src/xdocs
Date Sat, 22 May 2004 09:44:50 GMT
Author: niclas
Date: Sat May 22 02:44:49 2004
New Revision: 20212

Added:
   avalon/trunk/tools/magic/engine/src/java/org/apache/merlin/magic/PluginProperties.java
   avalon/trunk/tools/magic/prepare/
   avalon/trunk/tools/magic/prepare/build.properties
   avalon/trunk/tools/magic/prepare/src/
   avalon/trunk/tools/magic/prepare/src/dist/
   avalon/trunk/tools/magic/prepare/src/dist/build.bsh
   avalon/trunk/tools/magic/prepare/src/dist/build.properties
   avalon/trunk/tools/magic/prepare/src/xdocs/
Modified:
   avalon/trunk/tools/magic/engine/src/java/org/apache/merlin/magic/Builder.java
   avalon/trunk/tools/magic/engine/src/java/org/apache/merlin/magic/PluginContext.java
   avalon/trunk/tools/magic/engine/src/java/org/apache/merlin/magic/PluginServiceManager.java
   avalon/trunk/tools/magic/engine/src/test/org/apache/merlin/magic/PluginContextTestCase.java
   avalon/trunk/tools/magic/jar/src/dist/build.bsh
   avalon/trunk/tools/magic/jar/src/dist/build.properties
Log:
Starting to work on the 'prepare' plugin.

Modified: avalon/trunk/tools/magic/engine/src/java/org/apache/merlin/magic/Builder.java
==============================================================================
--- avalon/trunk/tools/magic/engine/src/java/org/apache/merlin/magic/Builder.java	(original)
+++ avalon/trunk/tools/magic/engine/src/java/org/apache/merlin/magic/Builder.java	Sat May
22 02:44:49 2004
@@ -1,8 +1,10 @@
 package org.apache.merlin.magic;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+
 import java.lang.reflect.Method;
-import java.util.Properties;
 
 import org.apache.avalon.framework.logger.ConsoleLogger;
 import org.apache.avalon.framework.logger.LogEnabled;
@@ -21,6 +23,7 @@
     
     public Builder( String[] methods, File projectDir )
     {
+        m_Logger = new ConsoleLogger();
         
         m_CallMethods = new String[ methods.length ];
         for( int i=0 ; i < methods.length ; i++ )
@@ -31,8 +34,6 @@
         m_TempDir = new File( m_SystemDir, "temp" );
         m_TempDir.mkdirs();
         
-        m_Logger = new ConsoleLogger();
-        
         m_Logger.info( " System Directory: " + m_SystemDir );
         m_Logger.info( "Project Directory: " + m_ProjectDir );
     }
@@ -40,13 +41,26 @@
     public void execute()
         throws Exception
     {
-        Properties globalProps = loadGlobalProperties();
+        PluginProperties props = new PluginProperties();
+        
+        // This is included twice, so a reference to other parts
+        // can be obtained in the local project properties file.
+        loadProjectLocalProperties( props );
+        
+        loadGlobalProperties( props );
+        loadMagicSystemProperties( props );
+        loadMagicPluginProperties( props );
+        loadProjectSystemProperties( props );
+        loadProjectLocalProperties( props );
+        loadUserProjectProperties( props );
+        loadUserSystemProperties( props );
+        loadUserHomeProperties( props );
         
         FacadeFactory factory = new FacadeFactory();
         if( factory instanceof LogEnabled )
             ((LogEnabled) factory).enableLogging( m_Logger );
             
-        PluginServiceManager sm = new PluginServiceManager( factory, globalProps );
+        PluginServiceManager sm = new PluginServiceManager( factory, props );
         sm.enableLogging( m_Logger );
         
         for( int i=0 ; i < m_CallMethods.length ; i++ )
@@ -87,22 +101,104 @@
         }
     }
     
-    private Properties loadGlobalProperties()
+    protected Logger getLogger()
+    {
+        return m_Logger;
+    }
+    
+    private void loadGlobalProperties( PluginProperties props )
     {
-        Properties props = new Properties();
-        
-        //TODO; Load the various properties;
-        //      $GLOBAL/project.properties
-        //      $GLOBAL/user.properties
-        //  more?  Project and Plugin properties are loaded elsewhere.
         props.put( "magic.home.dir", m_SystemDir.toString() );
         props.put( "magic.plugins.dir", m_PluginsDir.getAbsolutePath() );
         props.put( "magic.repository.dir", new File( m_SystemDir, "repository" ).toString()
);
         props.put( "magic.project.dir", m_ProjectDir.getAbsolutePath() );
         props.put( "magic.temp.dir", m_TempDir.getAbsolutePath() );
-        return props;
     }
     
+    private void loadMagicSystemProperties( PluginProperties props )
+    {
+        File file = new File( m_SystemDir, "build.properties" );
+        if( file.exists() )
+            load( props, file );
+    }
+    
+    private void loadMagicPluginProperties( PluginProperties props )
+    {
+        File[] plugins = m_SystemDir.listFiles();
+        for( int i=0 ; i < plugins.length ; i++ )
+        {
+            File file = new File( plugins[i], "build.properties" );
+            if( file.exists() )
+                load( props, file );
+        }
+    }
+    
+    private void loadProjectSystemProperties( PluginProperties props )
+    {
+        String projSys = props.getProperty( "project.system.dir" );
+        if( projSys == null )
+            return;
+        File dir = new File( projSys );
+        File file = new File( dir, "build.properties" );
+        if( file.exists() )
+            load( props, file );
+    }
+    
+    private void loadProjectLocalProperties( PluginProperties props )
+    {
+        File file = new File( m_ProjectDir, "build.properties" );
+        if( file.exists() )
+            load( props, file );
+    }
+    
+    private void loadUserProjectProperties( PluginProperties props )
+    {
+        File file = new File( m_ProjectDir, "user.properties" );
+        if( file.exists() )
+            load( props, file );
+    }
+    
+    private void loadUserSystemProperties( PluginProperties props )
+    {
+        File file = new File( m_SystemDir, "user.properties" );
+        if( file.exists() )
+            load( props, file );
+    }
+    
+    private void loadUserHomeProperties( PluginProperties props )
+    {
+        File dir = new File( System.getProperty( "user.dir" ) );
+        File file = new File( dir, ".magic.properties" );
+        if( file.exists() )
+            load( props, file );
+    }
+
+    private void load( PluginProperties props, File file )
+    {
+        // TODO: Investigate if java.util.Properties already Buffer,
+        // or we should do it for performance.
+        FileInputStream in = null;
+        try
+        {
+            in = new FileInputStream( file );
+            props.load( in );
+        } catch( IOException e )
+        {
+            getLogger().warn( "Properties file not found: " + file.getAbsolutePath() );
+        } finally
+        {
+            try
+            {
+                if( in != null )
+                    in.close();
+            } catch( IOException e )
+            {
+                // Ignore... Don't think it can happen.
+            }
+        }
+        
+    }
+        
     private File findSystemDir()
     {
         String system = System.getProperty( "magic.system.dir" );

Modified: avalon/trunk/tools/magic/engine/src/java/org/apache/merlin/magic/PluginContext.java
==============================================================================
--- avalon/trunk/tools/magic/engine/src/java/org/apache/merlin/magic/PluginContext.java	(original)
+++ avalon/trunk/tools/magic/engine/src/java/org/apache/merlin/magic/PluginContext.java	Sat
May 22 02:44:49 2004
@@ -1,7 +1,6 @@
 package org.apache.merlin.magic;
 
 import java.io.File;
-import java.util.Properties;
 import java.util.Stack;
 import java.util.StringTokenizer;
 
@@ -16,7 +15,7 @@
 {
     private String m_ProjectName;
     private File m_ProjectDir;
-    private Properties m_ProjectProperties;
+    private PluginProperties m_ProjectProperties;
 
     private String m_PluginClassname;    
     private String m_PluginName;
@@ -29,11 +28,11 @@
     
     PluginContext( File scriptDir )
     {
-        this( "fake", new File( "." ), new Properties(), "fake plugin", 
+        this( "virtual", new File( "." ), new PluginProperties(), "virtual plugin", 
               scriptDir, new File( "." ), new File( "." ) );
     }
     
-    PluginContext( String projectname, File projectDir, Properties projectProps,
+    PluginContext( String projectname, File projectDir, PluginProperties projectProps,
                    String pluginname, File pluginDir, File systemDir, File tempDir )
     {
         m_ProjectName = projectname.trim();
@@ -90,7 +89,7 @@
         return m_ProjectDir;
     }
     
-    public Properties getProjectProperties()
+    public PluginProperties getProjectProperties()
     {
         return m_ProjectProperties;
     }
@@ -127,12 +126,8 @@
     
     public String getProperty( String name )
     {
-        name = name.trim();
         String value = m_ProjectProperties.getProperty( name );
-        if( value == null )
-            return null;
-        value = value.trim();
-        return resolve( value );
+        return value;
     }
     
     public Project getAntProject()
@@ -152,70 +147,6 @@
     
     public String resolve( String value )
     {
-        // optimization for common case.
-        int pos1 = value.indexOf( "${" );
-        if( pos1 < 0 )
-            return value;
-        
-        Stack stack = new Stack();
-        StringTokenizer st = new StringTokenizer( value, "${}", true );
-        
-        while( st.hasMoreTokens() )
-        {
-            String token = st.nextToken();
-            if( token.equals( "}" ) )
-            {
-                String name = (String) stack.pop();
-                String open = (String) stack.pop();
-                if( open.equals( "${" ) )
-                {
-                    String propValue = getProperty( name );
-                    if( propValue == null )
-                        push( stack, "${" + name + "}" );
-                    else
-                        push( stack, propValue );
-                }
-                else
-                {
-                    push( stack, "${" + name + "}" );
-                }
-            }
-            else
-            {
-                if( token.equals( "$" ) )
-                    stack.push( "$" );
-                else
-                {
-                    push( stack, token );
-                }
-            }
-        }
-        String result = "";
-        while( stack.size() > 0 )
-        {
-            result = (String) stack.pop() + result;
-        }
-        return result;
-    }
-    
-    private void push( Stack stack , String value )
-    {
-        if( stack.size() > 0 )
-        {
-	        String data = (String) stack.pop();
-	        if( data.equals( "${" ) )
-	        {
-	            stack.push( data );
-	            stack.push( value );
-	        }
-	        else
-	        {
-	            stack.push( data + value );
-	        }
-        }
-        else
-        {
-            stack.push( value );
-        }
+        return m_ProjectProperties.resolve( value );
     }
 }

Added: avalon/trunk/tools/magic/engine/src/java/org/apache/merlin/magic/PluginProperties.java
==============================================================================
--- (empty file)
+++ avalon/trunk/tools/magic/engine/src/java/org/apache/merlin/magic/PluginProperties.java
Sat May 22 02:44:49 2004
@@ -0,0 +1,96 @@
+package org.apache.merlin.magic;
+
+import java.util.Properties;
+import java.util.Stack;
+import java.util.StringTokenizer;
+
+public class PluginProperties extends Properties
+{
+    public PluginProperties()
+    {
+    }
+    
+    public PluginProperties( Properties content )
+    {
+        super( content );
+    }
+    
+    public String getProperty( String name )
+    {
+        name = name.trim();
+        String value = super.getProperty( name );
+        if( value == null )
+            return null;
+        value = value.trim();
+        return resolve( value );
+    }
+    
+    public String resolve( String value )
+    {
+        // optimization for common case.
+        int pos1 = value.indexOf( "${" );
+        if( pos1 < 0 )
+            return value;
+        
+        Stack stack = new Stack();
+        StringTokenizer st = new StringTokenizer( value, "${}", true );
+        
+        while( st.hasMoreTokens() )
+        {
+            String token = st.nextToken();
+            if( token.equals( "}" ) )
+            {
+                String name = (String) stack.pop();
+                String open = (String) stack.pop();
+                if( open.equals( "${" ) )
+                {
+                    String propValue = getProperty( name );
+                    if( propValue == null )
+                        push( stack, "${" + name + "}" );
+                    else
+                        push( stack, propValue );
+                }
+                else
+                {
+                    push( stack, "${" + name + "}" );
+                }
+            }
+            else
+            {
+                if( token.equals( "$" ) )
+                    stack.push( "$" );
+                else
+                {
+                    push( stack, token );
+                }
+            }
+        }
+        String result = "";
+        while( stack.size() > 0 )
+        {
+            result = (String) stack.pop() + result;
+        }
+        return result;
+    }
+    
+    private void push( Stack stack , String value )
+    {
+        if( stack.size() > 0 )
+        {
+            String data = (String) stack.pop();
+            if( data.equals( "${" ) )
+            {
+                stack.push( data );
+                stack.push( value );
+            }
+            else
+            {
+                stack.push( data + value );
+            }
+        }
+        else
+        {
+            stack.push( value );
+        }
+    }
+}

Modified: avalon/trunk/tools/magic/engine/src/java/org/apache/merlin/magic/PluginServiceManager.java
==============================================================================
--- avalon/trunk/tools/magic/engine/src/java/org/apache/merlin/magic/PluginServiceManager.java
(original)
+++ avalon/trunk/tools/magic/engine/src/java/org/apache/merlin/magic/PluginServiceManager.java
Sat May 22 02:44:49 2004
@@ -5,7 +5,6 @@
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Properties;
 
 import org.apache.avalon.framework.activity.Initializable;
 import org.apache.avalon.framework.context.Contextualizable;
@@ -28,10 +27,10 @@
     private File m_LocalPlugins;
     private File m_TempDir;
 
-    private Properties m_GlobalProperties;
+    private PluginProperties m_GlobalProperties;
     private FacadeFactory m_FacadeFactory;
 
-    PluginServiceManager( FacadeFactory factory, Properties globalprops )
+    PluginServiceManager( FacadeFactory factory, PluginProperties globalprops )
     {
         DUMMY = new Object();
         m_FacadeFactory = factory;
@@ -154,7 +153,7 @@
         if( pluginDir == null )
             throw new ServiceException( "Plugin '" + service + "' is not present in " + m_LocalPlugins
+ "." );
             
-        Properties props = new Properties( m_GlobalProperties );
+        PluginProperties props = new PluginProperties( m_GlobalProperties );
         
         appendProperties( props, pluginDir );
         appendProperties( props, m_ProjectDir );
@@ -174,7 +173,7 @@
         }
     }
     
-    private void appendProperties( Properties props, File dir )
+    private void appendProperties( PluginProperties props, File dir )
         throws ServiceException
     {
         File file = new File( dir, "build.properties" );
@@ -186,7 +185,7 @@
             loadPropertiesFile( props, file );
     }
     
-    private void loadPropertiesFile( Properties props, File file )
+    private void loadPropertiesFile( PluginProperties props, File file )
     {
         FileInputStream fis = null;
         try

Modified: avalon/trunk/tools/magic/engine/src/test/org/apache/merlin/magic/PluginContextTestCase.java
==============================================================================
--- avalon/trunk/tools/magic/engine/src/test/org/apache/merlin/magic/PluginContextTestCase.java
(original)
+++ avalon/trunk/tools/magic/engine/src/test/org/apache/merlin/magic/PluginContextTestCase.java
Sat May 22 02:44:49 2004
@@ -2,7 +2,6 @@
 
 import java.io.File;
 import java.io.InputStream;
-import java.util.Properties;
 
 import junit.framework.TestCase;
 
@@ -27,7 +26,7 @@
         m_ProjectDir = new File( "target/projectdir");
         m_ProjectDir.mkdir();
         
-        Properties projectProps = new Properties();
+        PluginProperties projectProps = new PluginProperties();
         InputStream in = getClass().getResourceAsStream( "test.properties");
         projectProps.load( in );
         

Modified: avalon/trunk/tools/magic/jar/src/dist/build.bsh
==============================================================================
--- avalon/trunk/tools/magic/jar/src/dist/build.bsh	(original)
+++ avalon/trunk/tools/magic/jar/src/dist/build.bsh	Sat May 22 02:44:49 2004
@@ -53,6 +53,9 @@
 
         String destDirName = m_Context.getProperty( "jar.manifest.build.dir" );
         File toDir = new File( destDirName ); 
+        toDir.mkdirs();
+        
+        getLogger().info( "Copying " + srcManifest + " to " + toDir );
         
         Copy copy = (Copy) m_Project.createTask( "copy" );
         copy.setTodir( toDir );

Modified: avalon/trunk/tools/magic/jar/src/dist/build.properties
==============================================================================
--- avalon/trunk/tools/magic/jar/src/dist/build.properties	(original)
+++ avalon/trunk/tools/magic/jar/src/dist/build.properties	Sat May 22 02:44:49 2004
@@ -1,8 +1,8 @@
 
-jar.build.src.dir = target/classes
+jar.build.src.dir = ${prepare.build.src.dir}/classes
 
 jar.filename = ${jar.build.src.dir}/../${project.name}-${project.version}.jar
 
-jar.manifest
+jar.manifest = ${prepare.src.dir}/etc/manifest.MF
 
-jar.manifest.build.dir
\ No newline at end of file
+jar.manifest.build.dir = ${prepare.build.src.dir}/etc
\ No newline at end of file

Added: avalon/trunk/tools/magic/prepare/build.properties
==============================================================================
--- (empty file)
+++ avalon/trunk/tools/magic/prepare/build.properties	Sat May 22 02:44:49 2004
@@ -0,0 +1,2 @@
+ 
+project.name = prepare

Added: avalon/trunk/tools/magic/prepare/src/dist/build.bsh
==============================================================================
--- (empty file)
+++ avalon/trunk/tools/magic/prepare/src/dist/build.bsh	Sat May 22 02:44:49 2004
@@ -0,0 +1,78 @@
+
+import java.io.File;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.apache.merlin.magic.AbstractPlugin;
+import org.apache.merlin.magic.Plugin;
+import org.apache.merlin.magic.PluginContext;
+
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.Contextualizable;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.taskdefs.Copy;
+import org.apache.tools.ant.taskdefs.Javac;
+
+public class JavacPlugin extends AbstractPlugin
+    implements Plugin, Contextualizable
+{
+    private Project m_Project;
+    
+    private boolean m_Initialized = false;
+        
+    public void init()
+    {   
+        if( m_Initialized )
+            return;
+        notifyPreMethod( "init" );
+        copySources();
+        notifyPostMethod( "init" );
+        m_Initialized = true;
+    }
+    
+    private void copySources()
+    {
+        String destdirname = m_Context.getProperty( "prepare.build.src.dir" );
+        File toDir = new File( destdirname ); 
+        String srcdirname = m_Context.getProperty( "prepare.src.dir" );
+        File fromDir = new File( srcdirname ); 
+        toDir.mkdirs();  /* ensure that the directory exists. */
+        
+        copyWithFilter( fromDir, toDir );
+        
+    }
+    
+    private void copyWithFilter( File fromDir, File toDir )
+    {
+        FileSet from = new FileSet();
+        from.setDir( fromDir );
+        from.setIncludes( "**/*" );
+
+        /* Copy with filtering */    
+        Copy copy = (Copy) m_Project.createTask( "copy" );
+        copy.setTodir( toDir );
+        copy.addFileset( from );
+        copy.init();
+        copy.execute();
+    }
+    
+    private void copyWithOutFilter( File fromDir, File toDir )
+    {
+        FileSet from = new FileSet();
+        from.setDir( fromDir );
+        from.setIncludes( "**/*" );
+        
+        /* Copy without filtering */    
+        Copy copy = (Copy) m_Project.createTask( "copy" );
+        copy.setTodir( toDir );
+        copy.addFileset( from );
+        copy.init();
+        copy.execute();
+    }
+}   

Added: avalon/trunk/tools/magic/prepare/src/dist/build.properties
==============================================================================
--- (empty file)
+++ avalon/trunk/tools/magic/prepare/src/dist/build.properties	Sat May 22 02:44:49 2004
@@ -0,0 +1,6 @@
+
+prepare.src.dir = src/
+
+prepare.dest.dir = target/
+
+prepare.build.src.dir = ${prepare.dest.dir}/src/

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


Mime
View raw message