1 package org.alfresco.maven.plugin.amp.packaging; 2 3 import org.apache.maven.plugin.MojoExecutionException; 4 import org.apache.maven.plugin.MojoFailureException; 5 import org.alfresco.maven.plugin.amp.util.AmpStructureSerializer; 6 7 import java.io.File; 8 import java.io.IOException; 9 10 /*** 11 * Saves the webapp structure cache. 12 * 13 * @author Stephane Nicoll 14 */ 15 public class SaveAmpStructurePostPackagingTask 16 implements AmpPostPackagingTask 17 { 18 19 private final File targetFile; 20 21 private final AmpStructureSerializer serialier; 22 23 24 public SaveAmpStructurePostPackagingTask( File targetFile ) 25 { 26 this.targetFile = targetFile; 27 this.serialier = new AmpStructureSerializer(); 28 } 29 30 public void performPostPackaging( AmpPackagingContext context ) 31 throws MojoExecutionException, MojoFailureException 32 { 33 if ( targetFile == null ) 34 { 35 context.getLog().debug( "Cache usage is disabled, not saving webapp structure." ); 36 } 37 else 38 { 39 try 40 { 41 serialier.toXml( context.getAmpStructure(), targetFile ); 42 context.getLog().debug( "Cache saved successfully." ); 43 } 44 catch ( IOException e ) 45 { 46 throw new MojoExecutionException( "Could not save webapp structure", e ); 47 } 48 } 49 } 50 }