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 09:36:35 UTC

cvs commit: avalon-sandbox/kernel/cli/src/java/org/apache/avalon/merlin/cli Main.java

mcconnell    2003/12/07 00:36:35

  Modified:    kernel/cli/src/java/org/apache/avalon/merlin/cli Main.java
  Log:
  Update to sync with repo changes.
  
  Revision  Changes    Path
  1.6       +102 -30   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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Main.java	7 Dec 2003 04:13:14 -0000	1.5
  +++ Main.java	7 Dec 2003 08:36:35 -0000	1.6
  @@ -62,6 +62,8 @@
   import java.lang.reflect.Method;
   import java.lang.reflect.InvocationTargetException;
   
  +import javax.naming.directory.Attributes;
  +
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
   
  @@ -72,6 +74,8 @@
   import org.apache.avalon.repository.RepositoryException;
   import org.apache.avalon.repository.main.DefaultInitialContext;
   import org.apache.avalon.repository.main.DefaultBuilder;
  +import org.apache.avalon.repository.meta.ArtifactDescriptor;
  +import org.apache.avalon.repository.util.RepositoryUtils;
   import org.apache.avalon.util.env.Env;
   import org.apache.avalon.util.exception.ExceptionHelper;
   
  @@ -215,8 +219,11 @@
       //----------------------------------------------------------
   
      /**
  -    * Creation of a new kernel cli factory.
  -    * @param factory the repository inital factory
  +    * Creation of a new kernel cli handler.
  +    * @param context the repository inital context
  +    * @param artifact the merlin implementation artifact
  +    * @param line the command line construct
  +    * @exception Exception if an error occurs
       */
       public Main( InitialContext context, Artifact artifact, CommandLine line ) throws Exception
       {
  @@ -332,6 +339,10 @@
           criteria.put( "merlin.deployment", arguments );
       }
   
  +   /**
  +    * Main command line enty point.
  +    * @param args the command line arguments
  +    */
       public static void main( String[] args )
       {
           try
  @@ -344,10 +355,11 @@
               CommandLine line = parser.parse( CL_OPTIONS, args );
   
               Artifact artifact = getDefaultImplementation( line );
  +            File system = getMerlinSystemRepository( line );
   
               if( line.hasOption( "version" ) )
               {
  -                Main.printVersionInfo( artifact );
  +                Main.printVersionInfo( system, artifact );
                   return;     
               }
   
  @@ -369,7 +381,6 @@
               // the real stuff
               //
   
  -            File system = getMerlinSystemRepository( line );
               InitialContext context = 
                  new DefaultInitialContext( system );
               Main main = new Main( context, artifact, line );
  @@ -384,6 +395,13 @@
           }
       }
   
  +   /**
  +    * Resolve the default implementation taking into account 
  +    * command line arguments, local and hom properties, and 
  +    * application defaults.
  +    * @param line the command line construct
  +    * @return the artifact reference
  +    */
       private static Artifact getDefaultImplementation( CommandLine line ) throws Exception
       {
           if( line.hasOption( "impl" ) )
  @@ -421,12 +439,21 @@
           return Artifact.createArtifact( group, name, version );
       }
   
  +   /**
  +    * Load the default implementation properties.
  +    * @return the implementation properties
  +    */
       private static Properties createDefaultProperties()
       {
           final String path = "merlin.implementation";
           return loadProperties( path );
       }
   
  +   /**
  +    * Load a properties file from a supplied resource name.
  +    * @path the resource path
  +    * @return the properties instance
  +    */
       private static Properties loadProperties( String path )
       {
           try
  @@ -452,19 +479,51 @@
           }
       }
   
  -
  -    private static void printVersionInfo( Artifact artifact )
  +   /**
  +    * Print out version information to System.out.  This function is 
  +    * invoked in response to the inclusion of the -version switch on
  +    * the command line.
  +    *
  +    * @param cache the local system cache
  +    * @param artifact the merlin implementation artifact descriptor
  +    */
  +    private static void printVersionInfo( File cache, Artifact artifact )
       {
  -        System.out.println( "Implementation: " 
  -          + artifact.getGroup() + ":" + artifact.getName() + ";" + artifact.getVersion() );
  +        try
  +        {
  +            Attributes attr = RepositoryUtils.getAttributes( cache, artifact );
  +            ArtifactDescriptor desc = new ArtifactDescriptor( attr );
  +            System.out.println( "\n  Implementation: " 
  +              + artifact.getGroup() 
  +              + ":" + artifact.getName() 
  +              + ";" + artifact.getVersion() 
  +              + " (" + desc.getBuild() + ")"
  +            );
  +        }
  +        catch( Throwable e )
  +        {
  +            System.out.println( "\nImplementation: " 
  +              + artifact.getGroup() + ":" + artifact.getName() + ";" + artifact.getVersion() );
  +        }
       }
   
  +   /**
  +    * Print out information to System.out detailing theb help options.
  +    */
       private static void printHelpInfo()
       {
           HelpFormatter formatter = new HelpFormatter();
           formatter.printHelp( "merlin [block]", " ", CL_OPTIONS, "", true );
       }
   
  +   /**
  +    * Return the merlin system repository root directory taking into 
  +    * account the supplied command-line, and merlin.properties files in 
  +    * the current and home directories.
  +    *
  +    * @param line the command line construct
  +    * @return the merlin system root repository directory
  +    */
       private static File getMerlinSystemRepository( CommandLine line )
       {
           if( line.hasOption( "system" ) )
  @@ -478,11 +537,19 @@
           }
       }
   
  +   /**
  +    * Return the merlin home directory.
  +    * @return the merlin install directory
  +    */
       private static File getMerlinHome()
       {
           return new File( getMerlinHomePath() );
       }
   
  +   /**
  +    * Return the merlin home directory path.
  +    * @return the merlin install directory path
  +    */
       private static String getMerlinHomePath()
       {
           try
  @@ -504,16 +571,28 @@
           }
       }
   
  +   /**
  +    * Return the maven repository directory.
  +    * @return the maven repository directory
  +    */
       private static File getMavenRepositoryDirectory()
       {
           return new File( getMavenHomeDirectory(), "repository" );
       }
   
  +   /**
  +    * Return the maven home directory.
  +    * @return the maven home directory
  +    */
       private static File getMavenHomeDirectory()
       {
           return new File( getMavenHome() );
       }
   
  +   /**
  +    * Return the maven home path.
  +    * @return the maven home directory path
  +    */
       private static String getMavenHome()
       {
           try
  @@ -543,6 +622,14 @@
           }
       }
   
  +   /**
  +    * Return the functional base directory.  The implementation looks
  +    * for the ${merlin.dir} system property and if not found, looks for 
  +    * the ${basedir} system property, and as a last resort, returns the 
  +    * JVM ${user.dir} value.
  +    *
  +    * @return the merlin install directory
  +    */
       private static File getBaseDirectory()
       {
           final String merlin = System.getProperty( "merlin.dir" );
  @@ -558,27 +645,12 @@
           return new File( System.getProperty( "user.dir" ) );
       }
   
  -    private static String getArgument( String key, String[] args )
  -    {
  -        for( int i=0; i<args.length; i++ )
  -        {
  -            if( args[i].equals( key ) )
  -            {
  -                if( args.length >= i+1 )
  -                {
  -                    return args[ i+1 ];
  -                }
  -                else
  -                {
  -                    final String error = 
  -                      "Missing CLI value for parameter: " + key;
  -                    throw new IllegalArgumentException( error );
  -                }
  -            }
  -        }
  -        return null;
  -    }
  -
  +   /**
  +    * Return a property file from a fir with a supplied filename.
  +    * @param dir the directory
  +    * @param filename the filename
  +    * @return a possibly empty properties instance
  +    */
       private static Properties getLocalProperties( 
         File dir, String filename ) 
       {
  
  
  

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