001package org.andromda.maven.plugin.site; 002 003import java.io.File; 004import org.apache.commons.lang.exception.ExceptionUtils; 005import org.apache.maven.plugin.MojoExecutionException; 006import org.apache.maven.plugin.MojoFailureException; 007import org.apache.maven.project.MavenProject; 008 009/** 010 * Goal that unpacks the required AndroMDA site zip packages to suitable locations preparing 011 * for deployment. 012 * 013 * @phase site 014 * @goal unpack-documentation 015 * @description Goal to unpack required site files prior to site deployment 016 * @author vancek 017 */ 018public class UnpackDocumentationMojo 019 extends AbstractSiteMojo 020{ 021 /** 022 * Path to the JMI 1.4 API zip source 023 * 024 * @parameter expression="${basedir}/src/site/resources/resources/jmi-uml1.4.zip" 025 */ 026 private File jmiApiSourcePath; 027 028 /** 029 * Path to the JMI 1.4 API destination extraction directory 030 * 031 * @parameter expression="${basedir}/../../target/site" 032 */ 033 private File jmiApiOutputDirectory; 034 035 /** 036 * Path to the UmlDoc car-rental-sample zip source 037 * 038 * @parameter expression="${basedir}/src/site/resources/resources/car-rental-umldoc.zip" 039 */ 040 private File umlDocCarRentalSampleSourcePath; 041 042 /** 043 * Path to the UmlDoc car-rental-sample extraction directory 044 * 045 * @parameter expression="${basedir}/../../target/site" 046 */ 047 private File umlDocCarRentalSampleOutputDirectory; 048 049 /** 050 * The name of the project injected from pom.xml. Not used. 051 * 052 * @parameter default-value="${project.name}" 053 */ 054 @SuppressWarnings("unused") 055 private String projectName; 056 057 /** 058 * @parameter expression="${project}" 059 * @required 060 * @readonly 061 */ 062 protected MavenProject project; 063 064 /** 065 * @see org.apache.maven.plugin.Mojo#execute() 066 */ 067 public void execute() 068 throws MojoExecutionException, MojoFailureException 069 { 070 this.getLog().info("-----------------------------------------------------------------------------"); 071 this.getLog().info(" A n d r o M D A S i t e D o c U n p a c k"); 072 this.getLog().info("-----------------------------------------------------------------------------"); 073 074 this.unpackUmlDocCarRentalSample(); 075 this.unpackJmiApi(); 076 077 this.getLog().info("SITE DOCUMENTATION UNPACK SUCCESSFUL"); 078 } 079 080 /** 081 * Unpack the JMI 1.4 API 082 * 083 * @throws MojoExecutionException 084 * @throws MojoFailureException 085 */ 086 private void unpackJmiApi() 087 throws MojoExecutionException, MojoFailureException 088 { 089 try 090 { 091 if (!this.jmiApiSourcePath.exists()) 092 { 093 throw new MojoExecutionException("JMI API source location is invalid"); 094 } 095 096 this.unpack( 097 this.jmiApiSourcePath, 098 this.jmiApiOutputDirectory); 099 } 100 catch (final Throwable throwable) 101 { 102 if (throwable instanceof MojoExecutionException) 103 { 104 throw (MojoExecutionException)throwable; 105 } 106 throw new MojoExecutionException("An error occurred unpacking JMI 1.4 API '" + 107 this.project.getArtifactId() + '\'', 108 ExceptionUtils.getRootCause(throwable)); 109 } 110 } 111 112 /** 113 * Unpack the UmlDoc for the car-rental-sample 114 * 115 * @throws MojoExecutionException 116 * @throws MojoFailureException 117 */ 118 private void unpackUmlDocCarRentalSample() 119 throws MojoExecutionException, MojoFailureException 120 { 121 try 122 { 123 if (!this.umlDocCarRentalSampleSourcePath.exists()) 124 { 125 throw new MojoExecutionException("UmlDoc car-rental-sample source location is invalid"); 126 } 127 128 this.unpack( 129 this.umlDocCarRentalSampleSourcePath, 130 this.umlDocCarRentalSampleOutputDirectory); 131 } 132 catch (final Throwable throwable) 133 { 134 if (throwable instanceof MojoExecutionException) 135 { 136 throw (MojoExecutionException)throwable; 137 } 138 throw new MojoExecutionException("An error occurred unpacking UmlDoc for car-rental-sample '" + 139 this.project.getArtifactId() + '\'', 140 ExceptionUtils.getRootCause(throwable)); 141 } 142 } 143}