Clover coverage report - MetaClass - 1.1
Coverage timestamp: Tue Apr 27 2004 10:46:24 EST
file stats: LOC: 109   Methods: 5
NCLOC: 59   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
AddToPluginSetTask.java 100% 100% 100% 100%
coverage
 1   
 /*
 2   
  * Copyright (C) The MetaClass Group. All rights reserved.
 3   
  *
 4   
  * This software is published under the terms of the Spice
 5   
  * Software License version 1.1, a copy of which has been included
 6   
  * with this distribution in the LICENSE.txt file.
 7   
  */
 8   
 package org.codehaus.metaclass.tools.tasks;
 9   
 
 10   
 import org.apache.tools.ant.BuildException;
 11   
 import org.apache.tools.ant.Project;
 12   
 import org.apache.tools.ant.Task;
 13   
 
 14   
 /**
 15   
  * An ant task to add one plugin set to another.
 16   
  *
 17   
  * @author Peter Donald
 18   
  * @version $Revision: 1.3 $ $Date: 2003/11/29 09:28:02 $
 19   
  */
 20   
 public abstract class AddToPluginSetTask
 21   
     extends Task
 22   
 {
 23   
     /** The rexpected type of plugin. */
 24   
     private Class m_type;
 25   
 
 26   
     /** The PluginSet that will be added to. */
 27   
     private String m_dest;
 28   
 
 29   
     /** The PluginSet that will be added. */
 30   
     private String m_source;
 31   
 
 32   
     /**
 33   
      * Create task.
 34   
      *
 35   
      * @param type the expected type of PluginSet.
 36   
      */
 37  12
     AddToPluginSetTask( final Class type )
 38   
     {
 39  12
         m_type = type;
 40   
     }
 41   
 
 42   
     /**
 43   
      * Set the dest for PluginSet to add to.
 44   
      *
 45   
      * @param dest the dest for PluginSet to add to.
 46   
      */
 47  12
     public void setDest( final String dest )
 48   
     {
 49  12
         m_dest = dest;
 50   
     }
 51   
 
 52   
     /**
 53   
      * Set the id of PluginSet that will be added.
 54   
      *
 55   
      * @param source the id of PluginSet that will be added.
 56   
      */
 57  12
     public void setSource( final String source )
 58   
     {
 59  12
         m_source = source;
 60   
     }
 61   
 
 62   
     /**
 63   
      * Join PluginSets.
 64   
      *
 65   
      * @throws BuildException if bad ids specified
 66   
      */
 67  8
     public void execute()
 68   
         throws BuildException
 69   
     {
 70  8
         validate();
 71  8
         final Object destObject = getProject().getReference( m_dest );
 72  8
         final Object sourceObject = getProject().getReference( m_source );
 73  8
         if( !m_type.isInstance( destObject ) )
 74   
         {
 75  2
             final String message =
 76   
                 "Object referenced by dest is not a " +
 77   
                 m_type.getName();
 78  2
             throw new BuildException( message );
 79   
         }
 80  6
         if( !m_type.isInstance( sourceObject ) )
 81   
         {
 82  2
             final String message =
 83   
                 "Object referenced by source is not a " +
 84   
                 m_type.getName();
 85  2
             throw new BuildException( message );
 86   
         }
 87   
 
 88  4
         final PluginSet base = (PluginSet)destObject;
 89  4
         final PluginSet other = (PluginSet)sourceObject;
 90  4
         log( "Adding " + other + " to " + base, Project.MSG_DEBUG );
 91  4
         base.addPluginSet( other );
 92   
     }
 93   
 
 94   
     /**
 95   
      * Validate correct attributes have been specified.
 96   
      */
 97  12
     void validate()
 98   
     {
 99  12
         if( null == m_dest )
 100   
         {
 101  2
             throw new BuildException( "dest not specified" );
 102   
         }
 103  10
         if( null == m_source )
 104   
         {
 105  2
             throw new BuildException( "source not specified" );
 106   
         }
 107   
     }
 108   
 }
 109