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 2003/12/07 05:13:14 UTC

cvs commit: avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/impl Resources.properties

mcconnell    2003/12/06 20:13:14

  Modified:    kernel/cli/src/java/org/apache/avalon/merlin/cli Main.java
                        Resources.properties
               kernel/impl/src/java/org/apache/avalon/merlin/impl
                        Resources.properties
  Log:
  Add plugable implementation support.
  
  Revision  Changes    Path
  1.5       +76 -9     avalon-sandbox/kernel/cli/src/java/org/apache/avalon/merlin/cli/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/kernel/cli/src/java/org/apache/avalon/merlin/cli/Main.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Main.java	7 Dec 2003 03:17:18 -0000	1.4
  +++ Main.java	7 Dec 2003 04:13:14 -0000	1.5
  @@ -99,6 +99,14 @@
       private static Resources REZ =
           ResourceManager.getPackageResources( Main.class );
   
  +    private static final File USER_HOME = 
  +      new File( System.getProperty( "user.home" ) );
  +
  +    private static final File USER_DIR = 
  +      getBaseDirectory();
  +
  +    private static final String MERLIN = "merlin.properties";
  +
       private static Options CL_OPTIONS = buildCommandLineOptions();
   
       private static Options buildCommandLineOptions()
  @@ -131,6 +139,12 @@
              .withDescription( REZ.getString( "cli-language-description" )  )
              .create( "lang" );
   
  +        Option implementation = OptionBuilder
  +           .hasArg()
  +           .withArgName( "artifact" )
  +           .withDescription( REZ.getString( "cli-implementation-description" )  )
  +           .create( "impl" );
  +
           Option home = OptionBuilder
              .hasArg()
              .withArgName( REZ.getString( "directory" ) )
  @@ -186,6 +200,7 @@
           options.addOption( library );
           options.addOption( config );
           options.addOption( kernel );
  +        options.addOption( implementation );
           return options;
       }
   
  @@ -321,8 +336,6 @@
       {
           try
           {
  -            Artifact artifact = getDefaultImplementation();
  -
               //
               // parse the commandline
               //
  @@ -330,6 +343,8 @@
               CommandLineParser parser = new BasicParser();
               CommandLine line = parser.parse( CL_OPTIONS, args );
   
  +            Artifact artifact = getDefaultImplementation( line );
  +
               if( line.hasOption( "version" ) )
               {
                   Main.printVersionInfo( artifact );
  @@ -369,8 +384,31 @@
           }
       }
   
  -    private static Artifact getDefaultImplementation() throws Exception
  +    private static Artifact getDefaultImplementation( CommandLine line ) throws Exception
       {
  +        if( line.hasOption( "impl" ) )
  +        {
  +            String spec = line.getOptionValue( "impl" );
  +            return Artifact.createArtifact( spec );
  +        }
  +
  +        //
  +        // check in ${user.dir}/merlin.properties and ${user.home}/merlin.properties
  +        // for a "merlin.implementation" property and use it if decleared
  +        //
  +
  +        final String key = "merlin.implementation";
  +        String home = getLocalProperties( USER_HOME, MERLIN ).getProperty( key );
  +        String work = getLocalProperties( USER_DIR, MERLIN ).getProperty( key, home);
  +        if( null != work )
  +        {
  +            return Artifact.createArtifact( work );
  +        }
  +
  +        //
  +        // otherwise go with the defaults packaged with the jar file
  +        //
  + 
           Properties properties = createDefaultProperties();
   
           final String group = 
  @@ -386,7 +424,11 @@
       private static Properties createDefaultProperties()
       {
           final String path = "merlin.implementation";
  +        return loadProperties( path );
  +    }
   
  +    private static Properties loadProperties( String path )
  +    {
           try
           {
               Properties properties = new Properties();
  @@ -406,16 +448,15 @@
               final String error = 
                 "Internal error. " 
                 + "Unable to locate the resource: merlin.implementation.";
  -            throw new IllegalStateException( error );
  +            throw new IllegalArgumentException( error );
           }
       }
   
   
       private static void printVersionInfo( Artifact artifact )
       {
  -        System.out.println( "Group: " + artifact.getGroup() ); 
  -        System.out.println( "Product: " + artifact.getName() ); 
  -        System.out.println( "Version: " + artifact.getVersion() );
  +        System.out.println( "Implementation: " 
  +          + artifact.getGroup() + ":" + artifact.getName() + ";" + artifact.getVersion() );
       }
   
       private static void printHelpInfo()
  @@ -502,8 +543,13 @@
           }
       }
   
  -    private File getBaseDirectory()
  +    private static File getBaseDirectory()
       {
  +        final String merlin = System.getProperty( "merlin.dir" );
  +        if( null != merlin )
  +        {
  +            return new File( merlin );
  +        }
           final String base = System.getProperty( "basedir" );
           if( null != base )
           {
  @@ -531,5 +577,26 @@
               }
           }
           return null;
  +    }
  +
  +    private static Properties getLocalProperties( 
  +      File dir, String filename ) 
  +    {
  +        Properties properties = new Properties();
  +        if( null == dir ) return properties;
  +        File file = new File( dir, filename );
  +        if( !file.exists() ) return properties;
  +        try
  +        {
  +            properties.load( new FileInputStream( file ) );
  +            return properties;
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = 
  +              "Unexpected exception while attempting to read properties from: " 
  +              + file + ". Cause: " + e.toString();
  +            throw new IllegalStateException( error );
  +        }
       }
   }
  
  
  
  1.4       +4 -18     avalon-sandbox/kernel/cli/src/java/org/apache/avalon/merlin/cli/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/kernel/cli/src/java/org/apache/avalon/merlin/cli/Resources.properties,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Resources.properties	6 Dec 2003 23:58:59 -0000	1.3
  +++ Resources.properties	7 Dec 2003 04:13:14 -0000	1.4
  @@ -1,28 +1,12 @@
   
  -template-description=Merlin Service Manangement Platform.
  -
  -template-repository-dir=The root directory for the local application repository. This directory will used for the caching of artifacts such as jar files referenced by block include directives and classloader resource references.  If not supplied the default value resolves to ${merlin.home}/repository.
  -
  -template-library-dir=The directory used as the base anchor for resolution of relative path references for jar extension library directory statements in classloader directives. If not supplied the value defaults to the current working directory.
  -
  -template-base-dir=The directory used as the working base directory. Working and temporary directories are created relative to this directory in combination with the component partition name. The default value is the current working directory ${user.dir}.
  -
  -template-kernel-url=A optional url to a kernel configuration.
  -
  -template-info-policy=The info generation policy option. If TRUE a summary listing of the Merlin environment will be generated on system establishment.  This information is generally useful when validating current version information and configuration paths.
  -
  -template-debug-policy=The debug generation policy. If TRUE debug level logging is automatically enabled on all channels (typically only used when debugging an application).
  -
  -template-server-policy=The server mode execution policy. If TRUE the kernel will execute in server mode otherwise components will be decommissioned following deployment.
  -
  -
  -
   url=url
   
   directory=directory
   
   file=file
   
  +artifact=artifact
  +
   cli-help-description=Prints this message.
   
   cli-language-description=A two-letter language code.
  @@ -36,6 +20,8 @@
   cli-install-description=Install a block archive into the local repository.
   
   cli-debug-description=Enables debug mode.
  +
  +cli-implementation-description=An artifact specification that overrides the default implementation.
   
   cli-home-description=A relative or absolute path to a working home directory. If not suppled, the system will default to the current directory.
   
  
  
  
  1.3       +0 -19     avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/impl/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/impl/Resources.properties,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Resources.properties	6 Dec 2003 06:37:44 -0000	1.2
  +++ Resources.properties	7 Dec 2003 04:13:14 -0000	1.3
  @@ -1,25 +1,6 @@
   
   info.listing=Merlin Kernel Environment Listing
   
  -template-description=Merlin Service Manangement Platform.
  -
  -template-repository-dir=The root directory for the local application repository. This directory will used for the caching of artifacts such as jar files referenced by block include directives and classloader resource references.  If not supplied the default value resolves to ${avalon.home}.
  -
  -template-library-dir=The directory used as the base anchor for resolution of relative path references for jar extension library directory statements in classloader directives. If not supplied the value defaults to the current working directory.
  -
  -template-home-dir=The directory used as the current directory. Logging files will be directed to the home directory by default (unless an alternative target is declared within the kernel). The default value is the current working directory ${user.dir}.
  -
  -template-base-dir=The directory used as the working base directory. Working and temporary directories are created relative to this directory in combination with the component partition name. The default value is the current working directory ${user.dir}.
  -
  -template-kernel-url=A optional url to a kernel configuration.
  -
  -template-info-policy=The info generation policy option. If TRUE a summary listing of the Merlin environment will be generated on system establishment.  This information is generally useful when validating current version information and configuration paths.
  -
  -template-debug-policy=The debug generation policy. If TRUE debug level logging is automatically enabled on all channels (typically only used when debugging an application).
  -
  -template-server-policy=The server mode execution policy. If TRUE the kernel will execute in server mode otherwise components will be decommissioned following deployment.
  -
  -
   
   url=url
   
  
  
  

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