001package org.andromda.maven.plugin.andromdapp; 002 003import java.io.File; 004import org.apache.commons.io.FileUtils; 005import org.apache.maven.plugin.MojoExecutionException; 006import org.apache.maven.plugin.MojoFailureException; 007 008/** 009 * Provides the undeployment of applications from a given directory. 010 * 011 * @goal undeploy 012 * @author Chad Brandon 013 */ 014public class UndeployMojo 015 extends AppManagementMojo 016{ 017 /** 018 * @see org.apache.maven.plugin.AbstractMojo#execute() 019 */ 020 public void execute() 021 throws MojoExecutionException, MojoFailureException 022 { 023 if (this.deployLocation.exists() && this.deployLocation.isDirectory()) 024 { 025 try 026 { 027 final File deployFile = this.getDeployFile(); 028 this.getLog().info("Undeploying " + deployFile + " from " + this.deployLocation); 029 if (deployFile.isDirectory()) 030 { 031 FileUtils.deleteDirectory(deployFile); 032 } 033 else 034 { 035 deployFile.delete(); 036 } 037 } 038 catch (final Throwable throwable) 039 { 040 throw new MojoExecutionException("An error occurred while attempting to undeploy artifact", throwable); 041 } 042 } 043 else 044 { 045 this.getLog().warn( 046 "Undeploy did not occur because the specified deployLocation '" + deployLocation + 047 "' does not exist, or is not a directory"); 048 } 049 } 050}