001package org.andromda.maven.plugin.site; 002 003import java.io.File; 004import java.io.FilenameFilter; 005import org.apache.commons.lang.exception.ExceptionUtils; 006import org.apache.maven.plugin.MojoExecutionException; 007import org.apache.maven.plugin.MojoFailureException; 008import org.apache.maven.project.MavenProject; 009 010/** 011 * Goal that copies the required AndroMDA site files to suitable locations preparing 012 * for deployment. 013 * 014 * @phase site 015 * @goal copy-documentation 016 * @description Goal to copy required site files prior to site deployment 017 * @author vancek 018 */ 019public class CopyDocumentationMojo 020 extends AbstractSiteMojo 021{ 022 /** 023 * Path to the mapping source directory containing the mappings 024 * 025 * @parameter expression="${basedir}/../andromda-etc/mappings" 026 */ 027 private File mappingsSourceDirectory; 028 029 /** 030 * Path to the mapping destination directory 031 * 032 * @parameter expression="${project.reporting.outputDirectory}/mappings" 033 */ 034 private File mappingsOutputDirectory; 035 036 /** 037 * Path to the car-rental-system model 038 * 039 * @parameter expression="${basedir}/../samples/car-rental-system/mda/src/main/uml/CarRentalSystem.xml.zip" 040 */ 041 private File carRentalSystemSourcePath; 042 043 /** 044 * Path to the destination directory to copy the car-rental-system model 045 * 046 * @parameter expression="${project.reporting.outputDirectory}" 047 */ 048 private File carRentalSystemOutputDirectory; 049 050 /** 051 * Path to the animal-quiz model 052 * 053 * @parameter expression="${basedir}/../samples/animal-quiz/mda/src/main/uml/AnimalQuiz.xml.zip" 054 */ 055 private File animalQuizSourcePath; 056 057 /** 058 * Path to the destination directory to copy the animal-quiz model 059 * 060 * @parameter expression="${project.reporting.outputDirectory}" 061 */ 062 private File animalQuizOutputDirectory; 063 064 /** 065 * The directory containing the documentation site reporting artifacts 066 * 067 * @parameter expression="${project.reporting.outputDirectory}" 068 */ 069 private File documentationSourceDirectory; 070 071 /** 072 * The documentation output directory used to copy the generated site reporting artifacts 073 * 074 * @parameter expression="${project.reporting.outputDirectory}" 075 */ 076 private File documentationOutputDirectory; 077 078 /** 079 * The name of the project injected from pom.xml. Not used. 080 * 081 * @parameter default-value="${project.name}" 082 */ 083 @SuppressWarnings("unused") 084 private String projectName; 085 086 /** 087 * @parameter expression="${project}" 088 * @required 089 * @readonly 090 */ 091 protected MavenProject project; 092 093 /** 094 * @see org.apache.maven.plugin.Mojo#execute() 095 */ 096 public void execute() 097 throws MojoExecutionException, MojoFailureException 098 { 099 this.getLog().info("-----------------------------------------------------------------------------"); 100 this.getLog().info(" A n d r o M D A S i t e D o c C o p y"); 101 this.getLog().info("-----------------------------------------------------------------------------"); 102 103 this.copyAnimalQuizModel(); 104 this.copyCarRentalSystemModel(); 105 this.copyMappings(); 106 this.copyDocumentationReportArtifacts(); 107 108 this.getLog().info("SITE DOCUMENTATION COPY SUCCESSFUL"); 109 } 110 111 /** 112 * Copy the animal-quiz model for site reference 113 * 114 * @throws MojoExecutionException 115 * @throws MojoFailureException 116 */ 117 private void copyAnimalQuizModel() 118 throws MojoExecutionException, MojoFailureException 119 { 120 try 121 { 122 if (!this.animalQuizSourcePath.exists()) 123 { 124 throw new MojoExecutionException("The animal-quiz model location is invalid"); 125 } 126 127 this.copyFile( 128 this.animalQuizSourcePath, 129 new File( 130 this.animalQuizOutputDirectory, 131 this.animalQuizSourcePath.getName())); 132 } 133 catch (final Throwable throwable) 134 { 135 if (throwable instanceof MojoExecutionException) 136 { 137 throw (MojoExecutionException)throwable; 138 } 139 throw new MojoExecutionException("An error occurred copying the animal-quiz model '" + 140 this.project.getArtifactId() + '\'', 141 ExceptionUtils.getRootCause(throwable)); 142 } 143 } 144 145 /** 146 * Copy the car-rental-system model for site reference 147 * 148 * @throws MojoExecutionException 149 * @throws MojoFailureException 150 */ 151 private void copyCarRentalSystemModel() 152 throws MojoExecutionException, MojoFailureException 153 { 154 try 155 { 156 if (!this.carRentalSystemSourcePath.exists()) 157 { 158 throw new MojoExecutionException("The car-rental-system model location is invalid"); 159 } 160 161 this.copyFile( 162 this.carRentalSystemSourcePath, 163 new File( 164 this.carRentalSystemOutputDirectory, 165 this.carRentalSystemSourcePath.getName())); 166 } 167 catch (final Throwable throwable) 168 { 169 if (throwable instanceof MojoExecutionException) 170 { 171 throw (MojoExecutionException)throwable; 172 } 173 throw new MojoExecutionException("An error occurred copying the car-rental-system model '" + 174 this.project.getArtifactId() + '\'', 175 ExceptionUtils.getRootCause(throwable)); 176 } 177 } 178 179 /** 180 * Copy the mapping files to site documentation location 181 * 182 * @throws MojoExecutionException 183 * @throws MojoFailureException 184 */ 185 private void copyMappings() 186 throws MojoExecutionException, MojoFailureException 187 { 188 try 189 { 190 if (!this.mappingsSourceDirectory.exists()) 191 { 192 throw new MojoExecutionException("Mapping source location is invalid"); 193 } 194 195 final File[] files = this.mappingsSourceDirectory.listFiles(); 196 for (File file : files) 197 { 198 // Ignore SVN dir/files 199 if (!".svn".equalsIgnoreCase(file.getName())) 200 { 201 this.copyFile( 202 file, 203 new File(this.mappingsOutputDirectory, file.getName())); 204 } 205 } 206 } 207 catch (final Throwable throwable) 208 { 209 if (throwable instanceof MojoExecutionException) 210 { 211 throw (MojoExecutionException)throwable; 212 } 213 throw new MojoExecutionException("An error occurred copying mappings '" + 214 this.project.getArtifactId() + '\'', 215 ExceptionUtils.getRootCause(throwable)); 216 } 217 } 218 219 /** 220 * Copy the documentation reporting artifacts 221 * 222 * @throws MojoExecutionException 223 * @throws MojoFailureException 224 */ 225 private void copyDocumentationReportArtifacts() 226 throws MojoExecutionException, MojoFailureException 227 { 228 try 229 { 230 if (!this.documentationSourceDirectory.exists()) 231 { 232 throw new MojoExecutionException("Documentation source location is invalid"); 233 } 234 235 /** 236 * Retrieve a directory listing with a filename filter 237 */ 238 FilenameFilter filter = new FilenameFilter() 239 { 240 final String[] filteredReports = 241 { 242 ".svn", 243 "integration.html", 244 "dependencies.html", 245 "dependency-convergence.html", 246 "issue-tracking.html", 247 "mailing-lists.html", 248 "license.html", 249 "project-summary.html", 250 "team-list.html", 251 "source-repository.html" 252 }; 253 254 public boolean accept(File dir, String name) 255 { 256 boolean accept = true; 257 for (String filteredReport : filteredReports) 258 { 259 if (name.equalsIgnoreCase(filteredReport)) 260 { 261 accept = false; 262 } 263 } 264 return accept; 265 } 266 }; 267 final File[] files = this.documentationSourceDirectory.listFiles(filter); 268 for (File file : files) 269 { 270 this.copyFile( 271 file, 272 new File( 273 this.documentationOutputDirectory, 274 file.getName())); 275 } 276 } 277 catch (final Throwable throwable) 278 { 279 if (throwable instanceof MojoExecutionException) 280 { 281 throw (MojoExecutionException)throwable; 282 } 283 throw new MojoExecutionException("An error occurred copying documentation/reporting artifacts '" + 284 this.project.getArtifactId() + '\'', 285 ExceptionUtils.getRootCause(throwable)); 286 } 287 } 288}