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
14
15
16
17
18
19
20
21 public class NamespaceTransformerMojo
22 extends AbstractMojo
23 {
24
25
26
27
28
29 private String projectName;
30
31
32
33
34
35
36 private File namespaceDocumentPath;
37
38
39
40
41 private static final String NAMESPACE_TRANSFORMATION_URI = "META-INF/xsl/namespace.xsl";
42
43
44
45
46 @SuppressWarnings("unused")
47 private File namespaceTransformationPath;
48
49
50
51
52
53
54 private File namespaceOutputPath;
55
56
57
58
59
60
61 protected MavenProject project;
62
63
64
65
66 private XslTransformer xslTransformer;
67
68
69
70
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 }