View Javadoc
1   package org.andromda.maven.plugin.site;
2   
3   import java.io.File;
4   import java.net.URL;
5   import org.andromda.core.common.ResourceUtils;
6   import org.apache.commons.lang.exception.ExceptionUtils;
7   import org.apache.maven.plugin.AbstractMojo;
8   import org.apache.maven.plugin.MojoExecutionException;
9   import org.apache.maven.plugin.MojoFailureException;
10  import org.apache.maven.project.MavenProject;
11  
12  /**
13   * Used to perform the transformation of the profile XSL document to profile.xml xdoc format
14   * within the site plugin.
15   *
16   * @phase pre-site
17   * @goal profile-xsl
18   * @description runs AndroMDA site profile xsl transformation
19   * @author Vance Karimi
20   */
21  public class ProfileTransformerMojo
22      extends AbstractMojo
23  {
24      /**
25       * The name of the project injected from pom.xml
26       *
27       * @parameter default-value="${project.name}"
28       */
29      private String projectName;
30  
31      /**
32       * Path to the project profile.xml
33       *
34       * @parameter expression="${basedir}/src/main/resources/META-INF/andromda/profile.xml"
35       */
36      private File profileDocumentPath;
37  
38      /**
39       * Path to the project profile transformation XSL
40       */
41      private static final String PROFILE_TRANSFORMATION_URI = "META-INF/xsl/profile.xsl";
42  
43      /** Not used.
44       * @parameter expression="${basedir}/src/main/resources/META-INF/xsl/profile.xsl"
45       */
46      @SuppressWarnings("unused")
47      private File profileTransformationPath;
48  
49      /**
50       * Path to the project profile document output
51       *
52       * @parameter expression="${basedir}/src/site/xdoc/profile.xml"
53       */
54      private File profileOutputPath;
55  
56      /**
57       * @parameter expression="${project}"
58       * @required
59       * @readonly
60       */
61      protected MavenProject project;
62  
63      /**
64       * XSL Transformer
65       */
66      private XslTransformer xslTransformer;
67  
68  
69      /**
70       * @see org.apache.maven.plugin.Mojo#execute()
71       */
72      public void execute()
73          throws MojoExecutionException, MojoFailureException
74      {
75          this.getLog().info("-----------------------------------------------------------------------------");
76          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  ");
77          this.getLog().info("-----------------------------------------------------------------------------");
78  
79          if (xslTransformer == null)
80          {
81              xslTransformer = new XslTransformer(projectName);
82          }
83  
84          this.getLog().info("Transforming profile " + this.profileDocumentPath);
85  
86          try
87          {
88              if (this.profileDocumentPath.exists() && this.profileDocumentPath.isFile())
89              {
90                  final URL profileTransformationUrl = ResourceUtils.getResource(PROFILE_TRANSFORMATION_URI);
91                  xslTransformer.transform(profileDocumentPath.getAbsolutePath(), profileTransformationUrl, profileOutputPath.getAbsolutePath());
92              }
93  
94              this.getLog().info("Transformation result " + this.profileOutputPath);
95              this.getLog().info("TRANSFORMING PROFILE SUCCESSFUL");
96          }
97          catch (final Throwable throwable)
98          {
99              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 }