avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/ant ComponentVerifierTask.java
Date Sat, 14 Sep 2002 06:24:34 GMT
donaldp     2002/09/13 23:24:34

  Added:       info/src/java/org/apache/avalon/framework/tools/ant
                        ComponentVerifierTask.java
  Log:
  Add an ant task for verifying a Component matches its Info descriptor
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/ant/ComponentVerifierTask.java
  
  Index: ComponentVerifierTask.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.framework.tools.ant;
  
  import org.apache.avalon.framework.info.ComponentInfo;
  import org.apache.avalon.framework.logger.ConsoleLogger;
  import org.apache.avalon.framework.tools.infobuilder.ComponentInfoBuilder;
  import org.apache.avalon.framework.tools.verifier.InfoVerifier;
  import org.apache.tools.ant.AntClassLoader;
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.Task;
  import org.apache.tools.ant.types.Path;
  
  /**
   * Simple task to load a {@link ComponentInfo} descriptor,
   * a component class and verify that the implementation class
   * is compatible with the {@link ComponentInfo}.
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/09/14 06:24:34 $
   */
  public class ComponentVerifierTask
      extends Task
  {
      private Path m_classpath;
      private String m_classname;
  
      public void setClassname( String classname )
      {
          m_classname = classname;
      }
  
      public Path createClasspath()
      {
          if( m_classpath == null )
          {
              m_classpath = new Path( getProject() );
          }
          return m_classpath.createPath();
      }
  
      public void execute()
          throws BuildException
      {
          if( null == m_classname )
          {
              final String message = "User did not specify classname";
              throw new BuildException( message );
          }
          if( null == m_classpath )
          {
              final String message = "User did not specify classpath";
              throw new BuildException( message );
          }
  
          final AntClassLoader classLoader = new AntClassLoader( getProject(), m_classpath
);
  
          final ComponentInfoBuilder builder = new ComponentInfoBuilder();
          builder.enableLogging( new ConsoleLogger() );
  
          final InfoVerifier verifier = new InfoVerifier();
          verifier.enableLogging( new ConsoleLogger() );
  
          try
          {
              final Class implementation =
                  classLoader.loadClass( m_classname );
              final ComponentInfo componentInfo =
                  builder.build( implementation );
              verifier.verifyType( "test",
                                   m_classname,
                                   componentInfo,
                                   implementation );
          }
          catch( final Exception e )
          {
              final String message =
                  "Failed to validate " + m_classname + " due to " + e;
              throw new BuildException( message, e );
          }
      }
  }
  
  
  

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


Mime
View raw message