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 namespace XSL document to namespace.xml xdoc format
14   * within the site plugin.
15   *
16   * @phase pre-site
17   * @goal namespace-xsl
18   * @description runs AndroMDA site namespace xsl transformation
19   * @author Vance Karimi
20   */
21  public class NamespaceTransformerMojo
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 namespace.xml
33       *
34       * @parameter expression="${basedir}/src/main/resources/META-INF/andromda/namespace.xml"
35       */
36      private File namespaceDocumentPath;
37  
38      /**
39       * Path to the project namespace transformation XSL
40       */
41      private static final String NAMESPACE_TRANSFORMATION_URI = "META-INF/xsl/namespace.xsl";
42  
43      /** Not used
44       * @parameter expression="${basedir}/src/main/resources/META-INF/xsl/namespace.xsl"
45       */
46      @SuppressWarnings("unused")
47      private File namespaceTransformationPath;
48  
49      /**
50       * Path to the project namespace document output
51       *
52       * @parameter expression="${basedir}/src/site/xdoc/namespace.xml"
53       */
54      private File namespaceOutputPath;
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   N a m e s p a c 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 namespace " + this.namespaceDocumentPath);
85  
86          try
87          {
88              final File namespaceDocumentFile = this.namespaceDocumentPath;
89              if (namespaceDocumentFile.exists() && namespaceDocumentFile.isFile())
90              {
91                  final URL namespaceTransformationUri = ResourceUtils.getResource(NAMESPACE_TRANSFORMATION_URI);
92                  xslTransformer.transform(namespaceDocumentPath.getAbsolutePath(), namespaceTransformationUri, namespaceOutputPath.getAbsolutePath());
93              }
94  
95              this.getLog().info("Transformed namesapce " + this.namespaceOutputPath);
96              this.getLog().info("TRANSFORMING NAMESPACE SUCCESSFUL");
97          }
98          catch (final Throwable throwable)
99          {
100             if (throwable instanceof MojoExecutionException)
101             {
102                 throw (MojoExecutionException)throwable;
103             }
104             throw new MojoExecutionException("An error occurred creating namespace site document '" +
105                 this.project.getArtifactId() + '\'',
106                 ExceptionUtils.getRootCause(throwable));
107         }
108     }
109 
110 }