avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon-sandbox/kernel/test/src/test/org/apache/avalon/merlin MerlinEmbeddedTest.java
Date Wed, 26 Nov 2003 00:50:12 GMT
mcconnell    2003/11/25 16:50:12

  Modified:    kernel/impl project.xml
               kernel/impl/src/java/org/apache/avalon/merlin/kernel
                        KernelCriteria.java
               kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl
                        DefaultCriteria.java
               kernel/test/src/test/org/apache/avalon/merlin
                        MerlinEmbeddedTest.java
  Log:
  Sync. with repo.
  
  Revision  Changes    Path
  1.8       +5 -0      avalon-sandbox/kernel/impl/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/kernel/impl/project.xml,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- project.xml	25 Nov 2003 18:57:29 -0000	1.7
  +++ project.xml	26 Nov 2003 00:50:11 -0000	1.8
  @@ -170,6 +170,11 @@
         <artifactId>avalon-util-env</artifactId>
         <version>1.0-dev</version>
       </dependency>
  +    <dependency>
  +      <groupId>avalon-util</groupId>
  +      <artifactId>avalon-util-exception</artifactId>
  +      <version>1.0-dev</version>
  +    </dependency>
   
       <!-- logkit dependecies -->
   
  
  
  
  1.3       +95 -12    avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/KernelCriteria.java
  
  Index: KernelCriteria.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/KernelCriteria.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- KernelCriteria.java	24 Nov 2003 21:26:36 -0000	1.2
  +++ KernelCriteria.java	26 Nov 2003 00:50:12 -0000	1.3
  @@ -64,6 +64,10 @@
    */
   public interface KernelCriteria extends Criteria
   {
  +    File USER_DIR = new File( System.getProperty( "user.dir" ) );
  +    File AVALON_HOME_DIR = new File( USER_DIR, ".avalon" );
  +    File MERLIN_HOME_DIR = new File( USER_DIR, ".merlin" );
  +
      /**
       * Shared application repository root directory.
       */
  @@ -71,7 +75,7 @@
         new Parameter( 
           "avalon.home",
           File.class.getName(),
  -        false );
  +        AVALON_HOME_DIR );
   
      /**
       * Repository parameter descriptor.
  @@ -80,7 +84,7 @@
         new Parameter( 
           "merlin.home",
           File.class.getName(),
  -        false );
  +        MERLIN_HOME_DIR );
   
      /**
       * Repository parameter descriptor.
  @@ -89,7 +93,7 @@
         new Parameter( 
           "merlin.system",
           File.class.getName(),
  -        false );
  +        new File( MERLIN_HOME_DIR, "system" ) );
   
      /**
       * Repository parameter descriptor.
  @@ -98,7 +102,7 @@
         new Parameter( 
           "merlin.config",
           File.class.getName(),
  -        false );
  +        new File( MERLIN_HOME_DIR, "config" ) );
   
      /**
       * Library path parameter descriptor.
  @@ -107,7 +111,7 @@
         new Parameter( 
           "merlin.kernel",
           URL.class.getName(),
  -        false );
  +        null );
   
      /**
       * Home directory parameter descriptor.
  @@ -116,7 +120,7 @@
         new Parameter( 
           "merlin.dir",
           File.class.getName(),
  -        false );
  +        USER_DIR );
   
      /**
       * Base directory parameter descriptor.
  @@ -125,7 +129,7 @@
         new Parameter( 
           "merlin.context",
           File.class.getName(),
  -        false );
  +        new File( USER_DIR, "home" ) );
   
      /**
       * Kernel url parameter descriptor.
  @@ -134,7 +138,7 @@
         new Parameter( 
           "merlin.ext",
           File.class.getName(),
  -        false );
  +        new File( USER_DIR, "ext" ) );
   
      /**
       * Info policy parameter descriptor.
  @@ -143,7 +147,7 @@
         new Parameter( 
           "merlin.info",
           Boolean.class.getName(),
  -        false );
  +        new Boolean( false ) );
   
      /**
       * Debug policy parameter descriptor.
  @@ -152,7 +156,7 @@
         new Parameter( 
           "merlin.debug",
           Boolean.class.getName(),
  -        false );
  +        new Boolean( false ) );
   
      /**
       * Server model parameter descriptor.
  @@ -161,13 +165,14 @@
         new Parameter( 
           "merlin.server",
           Boolean.class.getName(),
  -        false );
  +        new Boolean( false ) );
   
      /**
       * The factory parameters template.
       */
       public static final Parameter[] PARAMS = 
         new Parameter[]{
  +           AVALON_HOME,
              MERLIN_HOME,
              MERLIN_SYSTEM,
              MERLIN_CONFIG,
  @@ -178,5 +183,83 @@
              MERLIN_INFO,
              MERLIN_DEBUG,
              MERLIN_SERVER };
  +
  +   /**
  +    * Return the root directory to the shared repository.
  +    * @return the avalon home root repository directory
  +    */
  +    File getAvalonHomeDirectory();
  +
  +   /**
  +    * Return the root directory to the merlin installation
  +    * @return the merlin home directory
  +    */
  +    File getMerlinHomeDirectory();
  +
  +   /**
  +    * Return the root directory to the merlin system repository
  +    * @return the merlin system repository directory
  +    */
  +    File getMerlinSystemDirectory();
  +
  +   /**
  +    * Return the root directory to the merlin configurations
  +    * @return the merlin configuration directory
  +    */
  +    File getMerlinConfigDirectory();
  +
  +   /**
  +    * Return the url to the kernel confiuration
  +    * @return the kernel configuration url
  +    */
  +    URL getMerlinKernelURL();
  +
  +   /**
  +    * Return the working client directory.
  +    * @return the working directory
  +    */
  +    File getMerlinWorkingDirectory();
  +
  +   /**
  +    * Return the context directory from which relative 
  +    * runtrime home directories will be established for 
  +    * components referencing urn:avalon:home
  +    *
  +    * @return the working directory
  +    */
  +    File getMerlinContextDirectory();
  +
  +   /**
  +    * Return the anchor directory to be used when resolving 
  +    * library declarations in classload specifciations.
  +    *
  +    * @return the jar extension anchor directory
  +    */
  +    File getMerlinExtensionDirectory();
  +
  +   /**
  +    * Return info generation policy.  If TRUE the parameters 
  +    * related to deployment will be listed on startup. 
  +    *
  +    * @return the info policy
  +    */
  +    boolean isInfoEnabled();
  +
  +   /**
  +    * Return debug policy.  If TRUE all logging channels will be 
  +    * set to debug level (useful for debugging).
  +    *
  +    * @return the debug policy
  +    */
  +    boolean isDebugEnabled();
  +
  +   /**
  +    * Return server execution policy.  If TRUE the kernel will 
  +    * continue until explicitly terminated.  If FALSE the kernel
  +    * will initiate decommissioning on completion of deployment.
  +    *
  +    * @return the server execution mode
  +    */
  +    boolean isServerEnabled();
   
   }
  
  
  
  1.7       +154 -26   avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/DefaultCriteria.java
  
  Index: DefaultCriteria.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/DefaultCriteria.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DefaultCriteria.java	25 Nov 2003 18:57:30 -0000	1.6
  +++ DefaultCriteria.java	26 Nov 2003 00:50:12 -0000	1.7
  @@ -50,11 +50,14 @@
   
   package org.apache.avalon.merlin.kernel.impl;
   
  +import java.io.File;
   import java.io.InputStream;
   import java.io.IOException;
  +import java.net.URL;
   import java.util.Enumeration;
   import java.util.Hashtable;
   import java.util.Properties;
  +import java.util.ArrayList;
   import java.util.Map;
   
   import org.apache.avalon.merlin.kernel.KernelCriteria;
  @@ -73,6 +76,7 @@
   
   import org.apache.avalon.util.env.Env;
   import org.apache.avalon.util.env.EnvAccessException;
  +import org.apache.avalon.util.exception.ExceptionHelper;
   
   /**
    * A Criteria is a class holding the values supplied by a user 
  @@ -157,7 +161,7 @@
           // client
           //
   
  -        StringBuffer errors = new StringBuffer();
  +        ArrayList errors = new ArrayList();
           for( int i=0; i<PARAMS.length; i++ )
           {
               Parameter param = PARAMS[i];
  @@ -168,15 +172,159 @@
               }
               catch( Exception re )
               {
  -                final String error = 
  -                  "Unable to set the default value for the property: " + key
  -                  + " due to an enexpected error.";
  -                System.out.println( error );
  -                re.printStackTrace();
  +                errors.add( re );
               }
           }
  +
  +        //
  +        // check for any errors created in the process and dump a 
  +        // notice to System.err
  +        //
  +
  +        if( errors.size() > 0 )
  +        {
  +            Throwable[] throwables = 
  +              (Throwable[]) errors.toArray( new Throwable[0] );
  +            final String report = 
  +              "One or more errors occured while attempting to resolve defaults.";
  +            String message = 
  +              ExceptionHelper.packException( report, throwables, false );
  +            System.err.println( message );
  +        }
  +    }
  +
  +    //--------------------------------------------------------------
  +    // Criteria
  +    //--------------------------------------------------------------
  +
  +   /**
  +    * Return a string representation of the kernel criteria.
  +    * @return the criteria as a string
  +    */
  +    public String toString()
  +    {
  +        return "[merlin: " + getMap() + "]";
  +    }
  +
  +    //--------------------------------------------------------------
  +    // KernelCriteria
  +    //--------------------------------------------------------------
  +
  +   /**
  +    * Return the root directory to the shared repository.
  +    * @return the avalon home root repository directory
  +    */
  +    public File getAvalonHomeDirectory()
  +    {
  +        return (File) getValue( AVALON_HOME );
       }
   
  +   /**
  +    * Return the root directory to the merlin installation
  +    * @return the merlin home directory
  +    */
  +    public File getMerlinHomeDirectory()
  +    {
  +        return (File) getValue( MERLIN_HOME );
  +    }
  +
  +   /**
  +    * Return the root directory to the merlin system repository
  +    * @return the merlin system repository directory
  +    */
  +    public File getMerlinSystemDirectory()
  +    {
  +        return (File) getValue( MERLIN_SYSTEM );
  +    }
  +
  +   /**
  +    * Return the root directory to the merlin configurations
  +    * @return the merlin configuration directory
  +    */
  +    public File getMerlinConfigDirectory()
  +    {
  +        return (File) getValue( MERLIN_CONFIG );
  +    }
  +
  +   /**
  +    * Return the url to the kernel confiuration
  +    * @return the kernel configuration url
  +    */
  +    public URL getMerlinKernelURL()
  +    {
  +        return (URL) getValue( MERLIN_KERNEL );
  +    }
  +
  +   /**
  +    * Return the working client directory.
  +    * @return the working directory
  +    */
  +    public File getMerlinWorkingDirectory()
  +    {
  +        return (File) getValue( MERLIN_DIR );
  +    }
  +
  +   /**
  +    * Return the context directory from which relative 
  +    * runtrime home directories will be established for 
  +    * components referencing urn:avalon:home
  +    *
  +    * @return the working directory
  +    */
  +    public File getMerlinContextDirectory()
  +    {
  +        return (File) getValue( MERLIN_CONTEXT );
  +    }
  +
  +   /**
  +    * Return the anchor directory to be used when resolving 
  +    * library declarations in classload specifciations.
  +    *
  +    * @return the jar extension anchor directory
  +    */
  +    public File getMerlinExtensionDirectory()
  +    {
  +        return (File) getValue( MERLIN_EXT );
  +    }
  +
  +   /**
  +    * Return info generation policy.  If TRUE the parameters 
  +    * related to deployment will be listed on startup. 
  +    *
  +    * @return the info policy
  +    */
  +    public boolean isInfoEnabled()
  +    {
  +        return ((Boolean)getValue( MERLIN_INFO )).booleanValue();
  +    }
  +
  +   /**
  +    * Return debug policy.  If TRUE all logging channels will be 
  +    * set to debug level (useful for debugging).
  +    *
  +    * @return the debug policy
  +    */
  +    public boolean isDebugEnabled()
  +    {
  +        return ((Boolean)getValue( MERLIN_DEBUG )).booleanValue();
  +    }
  +
  +   /**
  +    * Return server execution policy.  If TRUE the kernel will 
  +    * continue until explicitly terminated.  If FALSE the kernel
  +    * will initiate decommissioning on completion of deployment.
  +    *
  +    * @return the server execution mode
  +    */
  +    public boolean isServerEnabled()
  +    {
  +        return ((Boolean)getValue( MERLIN_SERVER )).booleanValue();
  +    }
  +
  +    //--------------------------------------------------------------
  +    // internal
  +    //--------------------------------------------------------------
  +
       private void printProperties( Properties properties, String label )
       {
           System.out.print( "\n------------ " + label.toUpperCase()
  @@ -214,24 +362,6 @@
           if( null != value ) properties.setProperty( key, value );
       }
   
  -    //--------------------------------------------------------------
  -    // Criteria
  -    //--------------------------------------------------------------
  -
  -   /**
  -    * Return the set of parameters backing this criteria.
  -    * @return the parameters
  -    */
  -    public Parameter[] getParameters()
  -    {
  -        return PARAMS;
  -    }
  -
  -    public String toString()
  -    {
  -        return "[merlin: " + getMap() + "]";
  -    }
  -
      /**
       * Read in the static defined properties that contribute to 
       * the default context value establishment.
  @@ -242,8 +372,6 @@
       */
       private Properties getStaticProperties( String path ) throws KernelRuntimeException
       {
  -      
  -        Properties bootstrap = new Properties();
           try
           {
               return Defaults.getStaticProperties( DefaultCriteria.class, path );
  
  
  
  1.3       +12 -20    avalon-sandbox/kernel/test/src/test/org/apache/avalon/merlin/MerlinEmbeddedTest.java
  
  Index: MerlinEmbeddedTest.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/kernel/test/src/test/org/apache/avalon/merlin/MerlinEmbeddedTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MerlinEmbeddedTest.java	24 Nov 2003 21:26:36 -0000	1.2
  +++ MerlinEmbeddedTest.java	26 Nov 2003 00:50:12 -0000	1.3
  @@ -117,30 +117,22 @@
           ClassLoader loader = m_repository.getClassLoader( parent, implementation );
           Class c = loader.loadClass( target.getFactoryClassname() );
           Factory factory = (Factory) c.newInstance();
  -        Criteria criteria = factory.createDefaultCriteria();
  +        Criteria criteria = (Criteria) factory.createDefaultCriteria();
           assertNotNull( "criteria", criteria );
   
           //
  -        // populate the criteria with stuff
  +        // list the supplied default criteria
           //
   
  -        /*
  -        criteria.setValue( 
  -          "merlin.base.dir", 
  -          new File( getBaseDirectory(), "home" ) );
  +        String[] keys = criteria.getKeys();
   
  -        criteria.setValue( 
  -          "merlin.policy.info", 
  -          new Boolean( true ) );
  -
  -        criteria.setValue( 
  -          "merlin.policy.debug", 
  -          new Boolean( true ) );
  -
  -        criteria.setValue( 
  -          "merlin.policy.server", 
  -          new Boolean( false ) );
  -        */
  +        System.out.println( "\n----------- LISTING (in unit test) ------------\n" );
  +        for( int i=0; i<keys.length; i++ )
  +        {
  +            final String key = keys[i];
  +            Object arg = criteria.getValue( key );
  +            System.out.println( "   ${" + key + "} == " + arg );
  +        }
   
           //
           // instantiate the application
  
  
  

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


Mime
View raw message