001package org.andromda.maven.plugin.site; 002 003import java.io.File; 004import java.net.URL; 005import org.andromda.core.common.ResourceUtils; 006import org.apache.commons.lang.exception.ExceptionUtils; 007import org.apache.maven.plugin.AbstractMojo; 008import org.apache.maven.plugin.MojoExecutionException; 009import org.apache.maven.plugin.MojoFailureException; 010import org.apache.maven.project.MavenProject; 011 012/** 013 * Used to perform the transformation of the profile XSL document to profile.xml xdoc format 014 * within the site plugin. 015 * 016 * @phase pre-site 017 * @goal profile-xsl 018 * @description runs AndroMDA site profile xsl transformation 019 * @author Vance Karimi 020 */ 021public class ProfileTransformerMojo 022 extends AbstractMojo 023{ 024 /** 025 * The name of the project injected from pom.xml 026 * 027 * @parameter default-value="${project.name}" 028 */ 029 private String projectName; 030 031 /** 032 * Path to the project profile.xml 033 * 034 * @parameter expression="${basedir}/src/main/resources/META-INF/andromda/profile.xml" 035 */ 036 private File profileDocumentPath; 037 038 /** 039 * Path to the project profile transformation XSL 040 */ 041 private static final String PROFILE_TRANSFORMATION_URI = "META-INF/xsl/profile.xsl"; 042 043 /** Not used. 044 * @parameter expression="${basedir}/src/main/resources/META-INF/xsl/profile.xsl" 045 */ 046 @SuppressWarnings("unused") 047 private File profileTransformationPath; 048 049 /** 050 * Path to the project profile document output 051 * 052 * @parameter expression="${basedir}/src/site/xdoc/profile.xml" 053 */ 054 private File profileOutputPath; 055 056 /** 057 * @parameter expression="${project}" 058 * @required 059 * @readonly 060 */ 061 protected MavenProject project; 062 063 /** 064 * XSL Transformer 065 */ 066 private XslTransformer xslTransformer; 067 068 069 /** 070 * @see org.apache.maven.plugin.Mojo#execute() 071 */ 072 public void execute() 073 throws MojoExecutionException, MojoFailureException 074 { 075 this.getLog().info("-----------------------------------------------------------------------------"); 076 this.getLog().info(" A n d r o M D A S i t e P r o f i l e T r a n s f o r m a t i o n "); 077 this.getLog().info("-----------------------------------------------------------------------------"); 078 079 if (xslTransformer == null) 080 { 081 xslTransformer = new XslTransformer(projectName); 082 } 083 084 this.getLog().info("Transforming profile " + this.profileDocumentPath); 085 086 try 087 { 088 if (this.profileDocumentPath.exists() && this.profileDocumentPath.isFile()) 089 { 090 final URL profileTransformationUrl = ResourceUtils.getResource(PROFILE_TRANSFORMATION_URI); 091 xslTransformer.transform(profileDocumentPath.getAbsolutePath(), profileTransformationUrl, profileOutputPath.getAbsolutePath()); 092 } 093 094 this.getLog().info("Transformation result " + this.profileOutputPath); 095 this.getLog().info("TRANSFORMING PROFILE SUCCESSFUL"); 096 } 097 catch (final Throwable throwable) 098 { 099 if (throwable instanceof MojoExecutionException) 100 { 101 throw (MojoExecutionException)throwable; 102 } 103 throw new MojoExecutionException("An error occurred creating profile site document '" + 104 this.project.getArtifactId() + '\'', 105 ExceptionUtils.getRootCause(throwable)); 106 } 107 } 108}