Coverage Report - org.mule.tools.anttasks.MuleDeploy
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleDeploy
0%
0/21
0%
0/4
0
 
 1  
 /*
 2  
 * $Id$
 3  
 * --------------------------------------------------------------------------------------
 4  
 * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
 5  
 *
 6  
 * The software in this package is published under the terms of the CPAL v1.0
 7  
 * license, a copy of which has been included with this distribution in the
 8  
 * LICENSE.txt file.
 9  
 */
 10  
 package org.mule.tools.anttasks;
 11  
 
 12  
 import org.apache.tools.ant.BuildException;
 13  
 import org.apache.tools.ant.Task;
 14  
 import org.apache.tools.ant.util.FileUtils;
 15  
 
 16  
 import java.io.File;
 17  
 import java.io.IOException;
 18  
 import java.text.MessageFormat;
 19  
 
 20  
 /**
 21  
 * Ant task to deploy a Mule application to the MULE_HOME/apps directory.
 22  
 *
 23  
 * XML format
 24  
 *
 25  
 * <taskdef name="muleDeploy" classname="org.mule.tools.anttasks.MuleDeploy"/>
 26  
 *
 27  
 * <muleDeploy applicationFile="file" muleHome="dir"/>
 28  
 *
 29  
 * If muleHome isn't specified, the value of the Ant property dir.mule.home is used.
 30  
 */
 31  0
 public class MuleDeploy extends Task
 32  
 {
 33  
     /** The Ant property containing the default Mule home directory */
 34  
     private static final String MULE_HOME_PROPERTY = "dir.mule.home";
 35  
 
 36  
     /** The application file to install */
 37  
     private File applicationFile;
 38  
 
 39  
     /** The home directory of the mule installation to install the application into */
 40  
     private File muleHome;
 41  
 
 42  
     /**
 43  
 * Specify the Mule application file to install
 44  
 */
 45  
     public void setApplicationFile(File applicationFile)
 46  
     {
 47  0
         this.applicationFile = applicationFile;
 48  0
     }
 49  
 
 50  
     /**
 51  
 * install the application file
 52  
 */
 53  
     @Override
 54  
     public void execute() throws BuildException
 55  
     {
 56  0
         FileChecker checker = new FileChecker(getLocation());
 57  0
         checker.checkFile(applicationFile, "application file", false, false);
 58  0
         File home = getMuleHome();
 59  0
         checker.checkFile(home, "mule home directory", true, false);
 60  0
         File appsDir = new File(home, "apps");
 61  0
         checker.checkFile(appsDir, "mule apps directory", true, true);
 62  
         try
 63  
         {
 64  0
             File destFile = new File(appsDir, applicationFile.getName());
 65  0
             FileUtils.getFileUtils().copyFile(applicationFile, destFile, null, true);
 66  
         }
 67  0
         catch (IOException ex)
 68  
         {
 69  0
             throw new BuildException(
 70  
                 MessageFormat.format("Problem copying Mule application file {0} to {1}", applicationFile, appsDir),
 71  
                 ex, getLocation());
 72  0
         }
 73  0
     }
 74  
 
 75  
     /**
 76  
 * @return the Mule home directory
 77  
 */
 78  
     public File getMuleHome()
 79  
     {
 80  0
         if (muleHome != null)
 81  
         {
 82  0
             return muleHome;
 83  
         }
 84  0
         String home = getProject().getProperty(MULE_HOME_PROPERTY);
 85  0
         return home == null ? null : new File(home);
 86  
     }
 87  
 
 88  
     /**
 89  
 * Specify the Mule home directory
 90  
 */
 91  
     public void setMuleHome(File muleHome)
 92  
     {
 93  0
         this.muleHome = muleHome;
 94  0
     }
 95  
 }
 96