You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by ad...@apache.org on 2002/07/02 12:49:18 UTC

cvs commit: jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project AddTargetTask.java

adammurdoch    2002/07/02 03:49:18

  Added:       antlib/src/java/org/apache/antlib/project AddTargetTask.java
  Log:
  Added <add-target> task, which adds a target to the current project.
  
  Revision  Changes    Path
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/AddTargetTask.java
  
  Index: AddTargetTask.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.antlib.project;
  
  import org.apache.myrmidon.api.AbstractTask;
  import org.apache.myrmidon.api.TaskException;
  import org.apache.myrmidon.api.metadata.ModelElement;
  import org.apache.myrmidon.api.metadata.Modeller;
  import org.apache.myrmidon.api.metadata.ModelException;
  import org.apache.myrmidon.framework.ModelElementUtil;
  import org.apache.myrmidon.interfaces.model.Target;
  import org.apache.myrmidon.interfaces.workspace.TargetSet;
  
  /**
   * Adds a target to the current project.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/07/02 10:49:18 $
   *
   * @ant.task name="add-target"
   */
  public class AddTargetTask
      extends AbstractTask
      implements Modeller
  {
      private ModelElement m_model;
  
      /**
       * Pass the object a read-only instance of it's own
       * model.
       *
       * @param model the ModelElement representing object
       * @throws ModelException if there is an error interpreting model
       */
      public void model( final ModelElement model )
          throws ModelException
      {
          m_model = model;
      }
  
      /**
       * Executes the task.
       *
       * @throws TaskException if an error occurs
       */
      public void execute()
          throws TaskException
      {
          // Transform the model, to replace the name
          final ModelElement targetModel = new ModelElement( "target", m_model.getLocation() );
          ModelElementUtil.copyModel( m_model, targetModel );
  
          // Build the target
          final String name = targetModel.getAttribute( "name" );
          final String description = targetModel.getAttribute( "description" );
          final Target target = new Target( name, description, targetModel );
  
          // Add the target
          final TargetSet targetSet = (TargetSet)getContext().getProperty( TargetSet.KEY );
          targetSet.addTarget( target );
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>